From 469bba949952f9c66d855cb696c79cbd4939a502 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 20 Sep 2003 08:04:38 +0000 Subject: [PATCH] added quota settings for users --- lam/lib/profiles.inc | 23 ++++++++++ lam/templates/profedit/profilecreate.php | 41 +++++++++++++++++- lam/templates/profedit/profileuser.php | 53 +++++++++++++++++++++++- 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/lam/lib/profiles.inc b/lam/lib/profiles.inc index 0fb1b655..71781b5d 100644 --- a/lam/lib/profiles.inc +++ b/lam/lib/profiles.inc @@ -197,6 +197,21 @@ function loadUserProfile($profile) { else $acc->smb_domain = chop(substr($line, 12, strlen($line)-12)); continue; } + if (substr($line, 0, 7) == "quota: ") { + $acc->quota = chop(substr($line, 7, strlen($line)-7)); + // split mountpoints + $acc->quota = explode(";", $acc->quota); + // split attributes + for ($i = 0; $i < sizeof($acc->quota); $i++) { + $temp = explode(",", $acc->quota[$i]); + $acc->quota[$i] = array(); + $acc->quota[$i][0] = $temp[0]; + $acc->quota[$i][2] = $temp[1]; + $acc->quota[$i][3] = $temp[2]; + $acc->quota[$i][6] = $temp[3]; + $acc->quota[$i][7] = $temp[4]; + } + } } fclose($file); } @@ -321,6 +336,14 @@ function saveUserProfile($account, $profile) { if (isset($account->smb_smbuserworkstations)) fputs($file, "smb_smbuserworkstations: " . $account->smb_smbuserworkstations . "\n"); if (isset($account->smb_smbhome)) fputs($file, "smb_smbhome: " . $smbhome . "\n"); if (isset($account->smb_domain)) fputs($file, "smb_domain: " . $account->smb_domain . "\n"); + if (isset($account->quota)) { + // convert array to string + for ($i = 0; $i < sizeof($account->quota); $i++) { + $account->quota[$i] = implode(",", $account->quota[$i]); + } + $temp = implode(";", $account->quota); + fputs($file, "quota: " . $temp . "\n"); + } // close file fclose($file); } diff --git a/lam/templates/profedit/profilecreate.php b/lam/templates/profedit/profilecreate.php index f8bf7ce0..ba166dcf 100644 --- a/lam/templates/profedit/profilecreate.php +++ b/lam/templates/profedit/profilecreate.php @@ -225,6 +225,41 @@ if ($_GET['type'] == "user") { echo ("

" . _("Back to Profile Editor") . ""); exit; } + + // check quota settings if script is given + if ($_SESSION['config']->get_scriptPath()) { + if ($_POST['quotacount'] && ($_POST['quotacount'] > 0)) { + for ($i = 0; $i < $_POST['quotacount']; $i++) { + $acct->quota[$i][0] = $_POST['f_quota_'.$i.'_0']; + $acct->quota[$i][2] = $_POST['f_quota_'.$i.'_2']; + $acct->quota[$i][3] = $_POST['f_quota_'.$i.'_3']; + $acct->quota[$i][6] = $_POST['f_quota_'.$i.'_6']; + $acct->quota[$i][7] = $_POST['f_quota_'.$i.'_7']; + // Check if values are OK + if (!ereg('^([0-9])*$', $acct->quota[$i][2])) { + StatusMessage('ERROR', _('Block soft quota'), _('Block soft quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + if (!ereg('^([0-9])*$', $acct->quota[$i][3])) { + StatusMessage('ERROR', _('Block hard quota'), _('Block hard quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + if (!ereg('^([0-9])*$', $acct->quota[$i][6])) { + StatusMessage('ERROR', _('Inode soft quota'), _('Inode soft quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + if (!ereg('^([0-9])*$', $acct->quota[$i][7])) { + StatusMessage('ERROR', _('Inode hard quota'), _('Inode hard quota contains invalid characters. Only natural numbers are allowed')); + echo ("

" . _("Back to Profile Editor") . ""); + exit; + } + } + } + } + if ($_POST['profname'] && eregi("^[0-9a-z\\-_]+$", $_POST['profname'])) { $profname = $_POST['profname']; } @@ -233,13 +268,17 @@ if ($_GET['type'] == "user") { echo ("

" . _("Back to Profile Editor") . ""); exit; } + // save profile if (saveUserProfile($acct, $profname)) { - echo StatusMessage("INFO", _("Profile was saved."), $profname); + StatusMessage("INFO", _("Profile was saved."), $profname); } + else StatusMessage("ERROR", _("Unable to save profile!"), $profname); + echo ("

" . _("Back to Profile Editor") . "

"); } + // save host profile elseif ($_GET['type'] == "host") { $acct = new account(); diff --git a/lam/templates/profedit/profileuser.php b/lam/templates/profedit/profileuser.php index 06691d91..6b7d87d0 100644 --- a/lam/templates/profedit/profileuser.php +++ b/lam/templates/profedit/profileuser.php @@ -40,6 +40,11 @@ if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) { exit; } +// load quota list +if ($_SESSION['config']->get_scriptPath()) { + $acct_q = getquotas("user"); +} + // print header echo $_SESSION['header']; echo ("\n\n\n
\n"); @@ -220,8 +225,6 @@ echo ("\n"); echo ("\n"); echo ("
"); - - // Samba part echo ("
" . _("Samba account") . "\n"); echo ("\n"); @@ -350,6 +353,52 @@ echo ("
\n"); echo ("
\n"); +// Quota settings if script is given +if ($_SESSION['config']->get_scriptPath()) { + echo ("
"); + echo "
"._('Quota properties')."\n"; + echo "\n"; + // description line + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + // help line + echo "'."\n". + "'."\n". + "'."\n". + "'."\n". + "'."\n". + ''."\n"; + // quota settings + for ($i = 0; $i < (sizeof($acct_q->quota) - 1); $i++) { + // load values from profile + for ($k = 0; $k < sizeof($acct->quota); $k++) { + // check for equal mountpoints + if ($acct->quota[$k][0] == $acct_q->quota[$i][0]) { + $acct_q->quota[$i][2] = $acct->quota[$i][2]; + $acct_q->quota[$i][3] = $acct->quota[$i][3]; + $acct_q->quota[$i][6] = $acct->quota[$i][6]; + $acct_q->quota[$i][7] = $acct->quota[$i][7]; + } + } + echo "\n"; + echo '\n"; // mountpoint + echo '\n"; // blocks soft limit + echo '\n"; // blocks hard limit + echo '\n"; // inodes soft limit + echo '\n"; // inodes hard limit + echo "\n"; + } + echo "
" . _('Mountpoint') . "  " . _('Soft block limit') . "  " . _('Hard block limit') . "  " . _('Soft inode limit') . "  " . _('Hard inode limit') . "  
"._('Help').'"._('Help').'"._('Help').'"._('Help').'"._('Help').'
' . $acct_q->quota[$i][0] . "quota[$i][0] . "\">
\n"; + // save number of mountpoints + echo "quota) - 1) . "\">\n"; + echo "
\n"; +} + echo ("

\n"); // profile name and submit/abort buttons