initial commit of file from CVS for e-smith-quota on Wed 12 Jul 09:07:49 BST 2023
This commit is contained in:
227
root/etc/e-smith/events/actions/user-modify-quota
Normal file
227
root/etc/e-smith/events/actions/user-modify-quota
Normal file
@@ -0,0 +1,227 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# copyright (C) 2002 Mitel Networks Corporation
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Technical support for this program is available from Mitel Networks
|
||||
# Please visit our web site www.mitel.com/sme/ for details.
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
package esmith;
|
||||
|
||||
use strict;
|
||||
use Errno;
|
||||
use Quota;
|
||||
use esmith::AccountsDB;
|
||||
|
||||
my $accounts = esmith::AccountsDB->open;
|
||||
|
||||
my @users = ();
|
||||
|
||||
my $event = $ARGV [0];
|
||||
if ($event eq "bootstrap-console-save")
|
||||
{
|
||||
# For bootstrap-console-save, make sure that quota entries are
|
||||
# set for each user
|
||||
@users = $accounts->users;
|
||||
}
|
||||
else
|
||||
{
|
||||
# Otherwise just set quota for the named user.
|
||||
my $userName = $ARGV [1];
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Check the Unix account
|
||||
#------------------------------------------------------------
|
||||
|
||||
|
||||
=begin testing
|
||||
|
||||
use esmith::TestUtils qw(simulate_perl_program);
|
||||
my $exit = simulate_perl_program($Original_File, 'wibble-event',
|
||||
'user_that_doesnt_exist');
|
||||
is( $exit, 255 * 256, 'non-existent user - exit code' );
|
||||
like( $@, qr{^Account "user_that_doesnt_exist" is not a user account},
|
||||
' failure message');
|
||||
|
||||
|
||||
$exit = simulate_perl_program($Original_File, 'wibble-event' );
|
||||
is( $exit, 255 * 256, 'forgotten user - exit code' );
|
||||
like( $@, qr{^Username argument missing},
|
||||
' failure message');
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
die "Username argument missing.\n" unless defined ($userName);
|
||||
|
||||
my $user = $accounts->get($userName);
|
||||
|
||||
if( !$user or $user->prop('type') ne 'user' )
|
||||
{
|
||||
die qq{Account "$userName" is not a user account; modify } .
|
||||
"user quota failed.\n";
|
||||
}
|
||||
@users = ($user);
|
||||
}
|
||||
|
||||
|
||||
=begin testing
|
||||
|
||||
my $a_tmp = '50-e-smith-quota/accounts.conf';
|
||||
$ENV{ESMITH_ACCOUNT_DB} = $a_tmp;
|
||||
|
||||
END { unlink $a_tmp };
|
||||
|
||||
open(TMP, ">$a_tmp") || die $!;
|
||||
print TMP <<'OUT';
|
||||
root=system|Gid|0|Uid|0
|
||||
server-manager=url
|
||||
server-manual=url
|
||||
shared=system|Gid|500|Visible|internal
|
||||
shutdown=system
|
||||
slocate=system|Gid|21
|
||||
user_quota=user|Gid|1000|Uid|1000|MaxBlocksSoftLim|10000|MaxBlocks|20000|MaxFilesSoftLim|1000|MaxFiles|2000
|
||||
user_partial=user|Gid|1001|Uid|1001|MaxBlocksSoftLim|123456|MaxFiles|321
|
||||
user_no_quota=user|Gid|1002|Uid|1002
|
||||
OUT
|
||||
close TMP;
|
||||
|
||||
# Quota properties in the order setqlim likes.
|
||||
my @QProps = qw(MaxBlocksSoftLim MaxBlocks MaxFilesSoftLim MaxFiles);
|
||||
my %curr_quota = (
|
||||
1000 => { MaxFilesSoftLim => 100 },
|
||||
1001 => { MaxBlocks => 30000, MaxBlocksSoftLim => 20000 },
|
||||
1002 => { MaxFiles => 2 },
|
||||
);
|
||||
|
||||
# What we expect the new quotas to be
|
||||
my %expect_quotas = (
|
||||
1000 => { MaxBlocksSoftLim => 10000, MaxBlocks => 20000,
|
||||
MaxFilesSoftLim => 1000, MaxFiles => 2000 },
|
||||
1001 => { MaxBlocksSoftLim => 123456, MaxBlocks => 30000,
|
||||
MaxFilesSoftLim => 0, MaxFiles => 321 },
|
||||
1002 => { MaxBlocksSoftLim => 0, MaxBlocks => 0,
|
||||
MaxFilesSoftLim => 0, MaxFiles => 2 },
|
||||
);
|
||||
|
||||
|
||||
{
|
||||
# Since these users don't really exist, we have to fool getpwnam
|
||||
# into using the Uid from the dummy accounts DB.
|
||||
no warnings 'once';
|
||||
local *CORE::GLOBAL::getpwnam = sub {
|
||||
esmith::AccountsDB->open->get($_[0])->prop('Uid');
|
||||
};
|
||||
|
||||
|
||||
# Override the Quota query and set functions since
|
||||
# 1) these users probably don't exist
|
||||
# 2) if they did, we don't want to screw with their quotas
|
||||
# 3) we need to know how each Quota function is called
|
||||
use Quota;
|
||||
no warnings 'redefine';
|
||||
|
||||
my %query;
|
||||
sub Quota::query {
|
||||
my($dev, $uid, $isgrp) = @_;
|
||||
$query{$uid} = { isgrp => $isgrp };
|
||||
return (0,
|
||||
$curr_quota{$uid}{MaxBlocksSoftLim} || 0,
|
||||
$curr_quota{$uid}{MaxBlocks} || 0,
|
||||
0,
|
||||
0,
|
||||
$curr_quota{$uid}{MaxFilesSoftLim} || 0,
|
||||
$curr_quota{$uid}{MaxFiles} || 0,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
my %set_quota = ();
|
||||
sub Quota::setqlim {
|
||||
my($dev, $uid) = (shift, shift);
|
||||
my(@limits) = splice(@_, 0, 4);
|
||||
my($tlo) = shift;
|
||||
|
||||
my %limits = ();
|
||||
@limits{@QProps} = @limits;
|
||||
$set_quota{$uid}{limits} = \%limits;
|
||||
$set_quota{$uid}{tlo} = $tlo;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$_STDOUT_ = '';
|
||||
$_STDERR_ = '';
|
||||
my $exit = simulate_perl_program($Original_File, 'bootstrap-console-save');
|
||||
is( $exit, 0, 'bootstrap-console-save - exit code' );
|
||||
is( $_STDOUT_, '' );
|
||||
is( $_STDERR_, '' );
|
||||
is( $@, '' );
|
||||
|
||||
is_deeply( [sort keys %set_quota], [sort qw(1000 1001 1002)] );
|
||||
foreach my $uid (keys %set_quota)
|
||||
{
|
||||
is_deeply( $set_quota{$uid}{limits}, $expect_quotas{$uid},
|
||||
"setqlim for $uid");
|
||||
}
|
||||
}
|
||||
|
||||
=end testing
|
||||
|
||||
=cut
|
||||
|
||||
|
||||
# Quota properties in the order setqlim likes.
|
||||
my @QProps = qw(MaxBlocksSoftLim MaxBlocks MaxFilesSoftLim MaxFiles);
|
||||
|
||||
foreach my $user (@users)
|
||||
{
|
||||
my $userName = $user->key;
|
||||
my $uid = getpwnam($userName);
|
||||
die qq{Could not get uid for user named "$userName"\n} unless $uid;
|
||||
|
||||
my(%uquota, %curr_quota);
|
||||
foreach my $qprop (@QProps)
|
||||
{
|
||||
$uquota{$qprop} = $user->prop($qprop);
|
||||
}
|
||||
|
||||
# Get a $dev value appropriate for use in Quota::query call.
|
||||
my $dev = Quota::getqcarg("/home/e-smith/files");
|
||||
|
||||
# Get current quota settings.
|
||||
@curr_quota{@QProps} = (Quota::query($dev, $uid, 0))[1,2,5,6];
|
||||
|
||||
if( !defined $curr_quota{MaxBlocks} ) # Quota::query failed
|
||||
{
|
||||
warn "Cannot query your quota for '$userName' on '$dev'\n";
|
||||
warn "Quota error (are you using NFS?): ", Quota::strerr(), "\n";
|
||||
next;
|
||||
}
|
||||
|
||||
# Keep old values unless there are values defined in the account record
|
||||
foreach my $qprop (@QProps)
|
||||
{
|
||||
$uquota{$qprop} = $curr_quota{$qprop}
|
||||
unless defined $uquota{$qprop};
|
||||
}
|
||||
|
||||
# Set the new quota
|
||||
Quota::setqlim($dev, $uid, @uquota{@QProps}, 0);
|
||||
}
|
130
root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/quota
Normal file
130
root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/quota
Normal file
@@ -0,0 +1,130 @@
|
||||
<lexicon lang="en-us">
|
||||
<entry>
|
||||
<base>FORM_TITLE</base>
|
||||
<trans>Create, modify, or remove user account quotas</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>UNABLE_TO_OPEN_ACCOUNTS</base>
|
||||
<trans>Unable to open accounts db</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>QUOTA_DESC</base>
|
||||
<trans>
|
||||
<![CDATA[
|
||||
<p>You can set filesystem quotas for users on your system by clicking
|
||||
the "Modify" button next to the user you wish to update.
|
||||
|
||||
<p>If the user exceeds the "Limit with grace period", warnings will be
|
||||
generated. If this limit is exceeded for longer than a week or if the
|
||||
"Absolute limit" is reached, the user will be unable to store any more
|
||||
files or receive any more e-mail.
|
||||
|
||||
<p>A setting of '0' for either limit disables that limit for the
|
||||
corresponding user.
|
||||
|
||||
<p>The disk space for each user includes the user's home directory,
|
||||
e-mail, and any files owned by the user in information bays.
|
||||
]]>
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CURRENT_USAGE_AND_SETTINGS</base>
|
||||
<trans>Current Quota Usage and Settings</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>LIMIT_WITH_GRACE</base>
|
||||
<trans>Limit with grace period</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>LIMIT_WITH_GRACE_MB</base>
|
||||
<trans>Limit with grace period (MB)</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ABS_LIMIT</base>
|
||||
<trans>Absolute limit</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ABS_LIMIT_MB</base>
|
||||
<trans>Absolute limit (MB)</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CURRENT_USAGE</base>
|
||||
<trans>Current usage (MB)</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>COULD_NOT_GET_UID</base>
|
||||
<trans>Could not determine the uid for user: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_NO_SUCH_ACCT</base>
|
||||
<trans>Error: there is no account named: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_NOT_A_USER_ACCT</base>
|
||||
<trans>Error: the account is not a user account: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ACCOUNT_IS_TYPE</base>
|
||||
<trans>It is an account of type: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>MODIFY_USER_TITLE</base>
|
||||
<trans>Modify user quota limits</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>USER</base>
|
||||
<trans>User: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>CURRENTLY_HAS</base>
|
||||
<trans>currently has: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>FILES</base>
|
||||
<trans>files</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>OCCUPYING</base>
|
||||
<trans>occupying: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>MEGABYTES</base>
|
||||
<trans>megabytes</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>INSTRUCTIONS</base>
|
||||
<trans>
|
||||
Enter the quota with optional unit suffix of 'K' for kilobytes, 'M' for megabytes,
|
||||
'G' for gigabytes or 'T' for terabytes.
|
||||
Entries with no suffix are assumed to be in megabytes. A setting of '0'
|
||||
for either limit disables that limit for the corresponding user.
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>SOFT_VAL_MUST_BE_NUMBER</base>
|
||||
<trans>Error: limit with grace period must be a number, optionally followed by one of the unit suffixes K, M, G, or T.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>HARD_VAL_MUST_BE_NUMBER</base>
|
||||
<trans>Error: absolute limit must be a number, optionally followed by one of the unit suffixes K, M, G, or T.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_HARD_LT_SOFT</base>
|
||||
<trans>
|
||||
Error: absolute limit must be greater than limit with grace time.
|
||||
</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>ERR_MODIFYING</base>
|
||||
<trans>Error occurred while modifying user.</trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>SUCCESSFULLY_MODIFIED</base>
|
||||
<trans>Successfully modified quota for user account: </trans>
|
||||
</entry>
|
||||
<entry>
|
||||
<base>Quotas</base>
|
||||
<trans>Quotas</trans>
|
||||
</entry>
|
||||
</lexicon>
|
||||
|
11
root/etc/e-smith/templates/etc/fstab/50EnableQuotas
Normal file
11
root/etc/e-smith/templates/etc/fstab/50EnableQuotas
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
# Change defaults => usrquota,grpquota for / file system
|
||||
@lines = map {
|
||||
/\s\/\s+ext[234]\s+defaults\s/ && s/defaults/usrquota,grpquota/;
|
||||
/^\/dev\/main\/.*\s+ext[234]\s+defaults\s/ && s/defaults/usrquota,grpquota/;
|
||||
/\s\/\s+xfs\s+defaults\s/ && s/defaults/uquota,gquota/;
|
||||
/^\/dev\/main\/.*\s+xfs\s+defaults\s/ && s/defaults/uquota,gquota/;
|
||||
$_
|
||||
} @lines;
|
||||
"";
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
{
|
||||
use esmith::I18N;
|
||||
use Locale::gettext;
|
||||
|
||||
my $i18n = new esmith::I18N;
|
||||
$i18n->setLocale('adminQuotaSummary.tmpl');
|
||||
|
||||
my $domain = $conf->get_value("DomainName") || "localhost";
|
||||
my $systemName = $conf->get_value("SystemName") || "SME Server";
|
||||
|
||||
$OUT .= "To: ".gettext("System Administrator")." <admin\@${domain}>\n";
|
||||
$OUT .= "From: \"".
|
||||
gettext("Automated quota report").
|
||||
"\" <do-not-reply\@${domain}>\n";
|
||||
$OUT .= "Subject: ".
|
||||
gettext("One or more users have exceeded their disk quota").
|
||||
"\n";
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# Over quota users:
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
$OUT .= gettext("The following users have exceeded their disk quota on the server called").
|
||||
" \"$systemName\" ".gettext("All values are in megabytes.");
|
||||
$OUT .= "\n";
|
||||
|
||||
$OUT .= sprintf("%-20s%+8s%+28s%+19s",
|
||||
gettext("Account"),
|
||||
gettext("Usage"),
|
||||
gettext("Limit with grace period"),
|
||||
gettext("Absolute limit")
|
||||
) . "\n";
|
||||
$OUT .= "-"x75 . "\n";;
|
||||
|
||||
foreach my $user (sort keys %usersOverQuota)
|
||||
{
|
||||
$OUT .= sprintf("%-20s%8.2f%28.2f%19.2f",
|
||||
$user,
|
||||
$usersOverQuota{$user}{usage},
|
||||
$usersOverQuota{$user}{softQuota},
|
||||
$usersOverQuota{$user}{hardQuota}
|
||||
) . "\n";
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
{
|
||||
use esmith::I18N;
|
||||
use Locale::gettext;
|
||||
|
||||
my $i18n = new esmith::I18N;
|
||||
$i18n->setLocale('userOverQuota.tmpl');
|
||||
|
||||
my $domain = $conf->get_value("DomainName") || "localhost";
|
||||
my $systemName = $conf->get_value("SystemName") || "SME Server";
|
||||
|
||||
my $gracePeriodEnds = localtime($data{gracePeriod});
|
||||
|
||||
$OUT .= "To: $data{fullname} <$data{username}\@${domain}>\n";
|
||||
$OUT .= "From: \"".
|
||||
gettext("Automated quota report").
|
||||
"\" <do-not-reply\@${domain}>\n";
|
||||
$OUT .= "Subject: ".gettext("You have exceeded your disk quota")."\n";
|
||||
|
||||
$OUT .= gettext("Your current disk usage:").
|
||||
" $data{usage} ".gettext("Mb")."\n";
|
||||
$OUT .= gettext("Your maximum usage:").
|
||||
($data{hardQuota} == 0 ? gettext(" no limit set") :
|
||||
" $data{hardQuota} ".gettext("Mb"))."\n";
|
||||
$OUT .= gettext("Warnings start at:").
|
||||
" $data{softQuota} ".gettext("Mb")."\n";
|
||||
$OUT .= gettext("Grace period ends:")." $gracePeriodEnds\n";
|
||||
$OUT .= gettext("System name:")." $systemName\n\n";
|
||||
|
||||
$OUT .= gettext("You are currently using more disk space than you have been allotted. You have until the Grace Period above to remove files so that you no longer exceed the warning level. At no time will you be permitted to store more than the maximum usage indicated above. This disk allocation includes all your e-mail, including unread e-mail.");
|
||||
|
||||
}
|
0
root/etc/e-smith/tests/50-e-smith-quota/.dummy
Normal file
0
root/etc/e-smith/tests/50-e-smith-quota/.dummy
Normal file
49
root/etc/e-smith/web/functions/quota
Normal file
49
root/etc/e-smith/web/functions/quota
Normal file
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/perl -wT
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# heading : Collaboration
|
||||
# description : Quotas
|
||||
# navigation : 2000 2300
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# copyright (C) 2002 Mitel Networks Corporation
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Technical support for this program is available from Mitel Networks
|
||||
# Please visit our web site www.e-smith.com for details.
|
||||
#----------------------------------------------------------------------
|
||||
use strict;
|
||||
use esmith::FormMagick::Panel::quota;
|
||||
|
||||
my $panel = esmith::FormMagick::Panel::quota->new();
|
||||
$panel->display();
|
||||
|
||||
__DATA__
|
||||
<form title="FORM_TITLE" header="/etc/e-smith/web/common/head.tmpl"
|
||||
footer="/etc/e-smith/web/common/foot.tmpl">
|
||||
|
||||
<page name="Initial" pre-event="print_status_message">
|
||||
<subroutine src="showInitial()"/>
|
||||
</page>
|
||||
<page name="Modify" pre-event="turn_off_buttons"
|
||||
post-event="performModifyUser">
|
||||
<title>MODIFY_USER_TITLE</title>
|
||||
<subroutine src="modifyUser()"/>
|
||||
<subroutine src="print_button('SAVE')"/>
|
||||
</page>
|
||||
|
||||
</form>
|
Reference in New Issue
Block a user