# quota-lib.pl # Common functions for quota management. do '../web-lib.pl'; &init_config(); do '../ui-lib.pl'; if ($gconfig{'os_type'} =~ /^\S+\-linux$/) { do "linux-lib.pl"; } else { do "$gconfig{'os_type'}-lib.pl"; } if ($module_info{'usermin'}) { &switch_to_remote_user(); } else { %access = &get_module_acl(); &foreign_require("mount", "mount-lib.pl"); } $email_cmd = "$module_config_directory/email.pl"; # list_filesystems() # Returns a list of details of local filesystems on which quotas are supported # directory device type options quotacan quotanow sub list_filesystems { local $f; local @mtab = &mount::list_mounted(); foreach $f (&mount::list_mounts()) { $fmap{$f->[0],$f->[1]} = $f; } map { $_->[4] = "a_can($_, $fmap{$_->[0],$_->[1]}) } @mtab; map { $_->[5] = "a_now($_, $fmap{$_->[0],$_->[1]}) } @mtab; return grep { $_->[4] } @mtab; } # parse_options(type, options) # Convert an options string for some filesystem into the associative # array %options sub parse_options { local($_); undef(%options); if ($_[0] ne "-") { foreach (split(/,/, $_[0])) { if (/^([^=]+)=(.*)$/) { $options{$1} = $2; } else { $options{$_} = ""; } } } } # user_quota(user, filesystem) # Returns an array of ublocks, sblocks, hblocks, ufiles, sfiles, hfiles # for some user, or an empty array if no quota has been assigned sub user_quota { local (%user, $n, $i); $n = &filesystem_users($_[1]); for($i=0; $i<$n; $i++) { if ($user{$i,'user'} eq $_[0]) { return ( $user{$i,'ublocks'}, $user{$i,'sblocks'}, $user{$i,'hblocks'}, $user{$i,'ufiles'}, $user{$i,'sfiles'}, $user{$i,'hfiles'} ); } } return (); } # group_quota(group, filesystem) # Returns an array of ublocks, sblocks, hblocks, ufiles, sfiles, hfiles # for some group, or an empty array if no quota has been assigned sub group_quota { local (%group, $n, $i); $n = &filesystem_groups($_[1]); for($i=0; $i<$n; $i++) { if ($group{$i,'group'} eq $_[0]) { return ( $group{$i,'ublocks'}, $group{$i,'sblocks'}, $group{$i,'hblocks'}, $group{$i,'ufiles'}, $group{$i,'sfiles'}, $group{$i,'hfiles'} ); } } return (); } # edit_user_quota(user, filesys, sblocks, hblocks, sfiles, hfiles) # Sets the disk quota for some user sub edit_user_quota { if ($config{'user_setquota_command'} && &has_command((split(/\s+/, $config{'user_setquota_command'}))[0])) { # Use quota setting command local $cmd = $config{'user_setquota_command'}." ".quotemeta($_[0])." ". int($_[2])." ".int($_[3])." ".int($_[4])." ".int($_[5]). " ".quotemeta($_[1]); local $out = &backquote_logged("$cmd 2>&1 ".&html_escape($out)."") if ($?); } else { # Call the quota editor $ENV{'EDITOR'} = $ENV{'VISUAL'} = "$module_root_directory/edquota.pl"; $ENV{'QUOTA_USER'} = $_[0]; $ENV{'QUOTA_FILESYS'} = $_[1]; $ENV{'QUOTA_SBLOCKS'} = $_[2]; $ENV{'QUOTA_HBLOCKS'} = $_[3]; $ENV{'QUOTA_SFILES'} = $_[4]; $ENV{'QUOTA_HFILES'} = $_[5]; local $user = $_[0]; if ($edquota_use_ids) { # Use UID instead of username if ($user =~ /^#(\d+)$/) { $user = $1; } else { local $uid = getpwnam($user); $user = $uid if (defined($uid)); } } &system_logged("$config{'user_edquota_command'} ". quotemeta($user)." >/dev/null 2>&1"); } } # edit_group_quota(group, filesys, sblocks, hblocks, sfiles, hfiles) # Sets the disk quota for some group sub edit_group_quota { if ($config{'group_setquota_command'} && &has_command((split(/\s+/, $config{'group_setquota_command'}))[0])) { # Use quota setting command local $cmd = $config{'group_setquota_command'}." ".quotemeta($_[0])." ". int($_[2])." ".int($_[3])." ".int($_[4])." ".int($_[5]). " ".quotemeta($_[1]); local $out = &backquote_logged("$cmd 2>&1 ".&html_escape($out)."") if ($?); } else { # Call the editor $ENV{'EDITOR'} = $ENV{'VISUAL'} = "$module_root_directory/edquota.pl"; $ENV{'QUOTA_USER'} = $_[0]; $ENV{'QUOTA_FILESYS'} = $_[1]; $ENV{'QUOTA_SBLOCKS'} = $_[2]; $ENV{'QUOTA_HBLOCKS'} = $_[3]; $ENV{'QUOTA_SFILES'} = $_[4]; $ENV{'QUOTA_HFILES'} = $_[5]; local $group = $_[0]; if ($edquota_use_ids) { # Use GID instead of group name if ($group =~ /^#(\d+)$/) { $group = $1; } else { local $gid = getgrnam($group); $group = $gid if (defined($gid)); } } &system_logged("$config{'group_edquota_command'} ". quotemeta($group)." >/dev/null 2>&1"); } } # edit_user_grace(filesystem, btime, bunits, ftime, funits) # Change the grace times for blocks and files on some filesystem sub edit_user_grace { $ENV{'EDITOR'} = $ENV{'VISUAL'} = "$module_root_directory/edgrace.pl"; $ENV{'QUOTA_FILESYS'} = $_[0]; $ENV{'QUOTA_BTIME'} = $_[1]; $ENV{'QUOTA_BUNITS'} = $_[2]; $ENV{'QUOTA_FTIME'} = $_[3]; $ENV{'QUOTA_FUNITS'} = $_[4]; &system_logged($config{'user_grace_command'}); } # edit_group_grace(filesystem, btime, bunits, ftime, funits) # Change the grace times for blocks and files on some filesystem sub edit_group_grace { $ENV{'EDITOR'} = $ENV{'VISUAL'} = "$module_root_directory/edgrace.pl"; $ENV{'QUOTA_FILESYS'} = $_[0]; $ENV{'QUOTA_BTIME'} = $_[1]; $ENV{'QUOTA_BUNITS'} = $_[2]; $ENV{'QUOTA_FTIME'} = $_[3]; $ENV{'QUOTA_FUNITS'} = $_[4]; &system_logged($config{'group_grace_command'}); } # quota_input(name, value, [blocksize]) # Prints an input for selecting a quota or unlimited, in a table sub quota_input { print "