added quota settings for users

This commit is contained in:
Roland Gruber 2003-09-20 08:04:38 +00:00
parent 1011546425
commit 469bba9499
3 changed files with 114 additions and 3 deletions

View File

@ -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);
}

View File

@ -225,6 +225,41 @@ if ($_GET['type'] == "user") {
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
exit;
}
}
}
}
if ($_POST['profname'] && eregi("^[0-9a-z\\-_]+$", $_POST['profname'])) {
$profname = $_POST['profname'];
}
@ -233,13 +268,17 @@ if ($_GET['type'] == "user") {
echo ("<br><br><a href=\"javascript:history.back()\">" . _("Back to Profile Editor") . "</a>");
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 ("<br><p><a href=\"profilemain.php\">" . _("Back to Profile Editor") . "</a></p>");
}
// save host profile
elseif ($_GET['type'] == "host") {
$acct = new account();

View File

@ -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 ("<html><head>\n<title></title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n</head><body><br>\n");
@ -220,8 +225,6 @@ echo ("</table>\n");
echo ("</fieldset>\n");
echo ("<br>");
// Samba part
echo ("<fieldset><legend><b>" . _("Samba account") . "</b></legend>\n");
echo ("<table border=0>\n");
@ -350,6 +353,52 @@ echo ("</table>\n");
echo ("</fieldset>\n");
// Quota settings if script is given
if ($_SESSION['config']->get_scriptPath()) {
echo ("<br>");
echo "<fieldset><legend><b>"._('Quota properties')."</b></legend>\n";
echo "<table border=0>\n";
// description line
echo "<tr>\n";
echo "<td align=\"center\"><b>" . _('Mountpoint') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Soft block limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Hard block limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Soft inode limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "<td align=\"center\"><b>" . _('Hard inode limit') . "</b>&nbsp;&nbsp;</td>\n";
echo "</tr>\n";
// help line
echo "<tr><td align=\"center\"><a href=\"../help.php?HelpNumber=439\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=441\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=442\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=445\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
"<td align=\"center\"><a href=\"../help.php?HelpNumber=446\" target=\"lamhelp\">"._('Help').'</a></td>'."\n".
'</tr>'."\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 "<tr>\n";
echo '<td>' . $acct_q->quota[$i][0] . "<input type=\"hidden\" name=\"f_quota_" . $i . "_0\" value=\"" . $acct_q->quota[$i][0] . "\"></td>\n"; // mountpoint
echo '<td align="center"><input name="f_quota_' . $i . '_2" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][2] . "\"></td>\n"; // blocks soft limit
echo '<td align="center"><input name="f_quota_' . $i . '_3" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][3] . "\"></td>\n"; // blocks hard limit
echo '<td align="center"><input name="f_quota_' . $i . '_6" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][6] . "\"></td>\n"; // inodes soft limit
echo '<td align="center"><input name="f_quota_' . $i . '_7" type="text" size="12" maxlength="20" value="' . $acct_q->quota[$i][7] . "\"></td>\n"; // inodes hard limit
echo "</tr>\n";
}
echo "</table>\n";
// save number of mountpoints
echo "<input type=\"hidden\" name=\"quotacount\" value=\"" . (sizeof($acct_q->quota) - 1) . "\">\n";
echo "</fieldset>\n";
}
echo ("<br><br>\n");
// profile name and submit/abort buttons