fixed some quota issues. Group quotas should be working now

This commit is contained in:
katagia 2003-09-19 10:03:00 +00:00
parent 35ff466d26
commit e14de2e72c
7 changed files with 296 additions and 103 deletions

View File

@ -708,14 +708,7 @@ function loadgroup($dn) { // Will load all needed values from an existing group
} }
if (isset($attr['gidNumber'][0])) $return->general_uidNumber = $attr['gidNumber'][0]; if (isset($attr['gidNumber'][0])) $return->general_uidNumber = $attr['gidNumber'][0];
if (isset($attr['description'][0])) $return->general_gecos = utf8_decode($attr['description'][0]); if (isset($attr['description'][0])) $return->general_gecos = utf8_decode($attr['description'][0]);
if (isset($attr['cn'][0])) { if (isset($attr['cn'][0])) $return->general_username = $attr['cn'][0];
$return->general_username = $attr['cn'][0];
$values = getquotas('group', $attr['cn'][0]);
if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values
if (isset($val)) $return->$key = $val;
}
}
if (isset($attr['sambaSID'][0])) { // Samba3 Samba 2.0 don't have any objects 4 groups if (isset($attr['sambaSID'][0])) { // Samba3 Samba 2.0 don't have any objects 4 groups
$return->smb_mapgroup = $attr['sambaSID'][0]; $return->smb_mapgroup = $attr['sambaSID'][0];
if (isset($attr['displayName'][0])) $return->smb_displayName = utf8_decode($attr['displayName'][0]); if (isset($attr['displayName'][0])) $return->smb_displayName = utf8_decode($attr['displayName'][0]);
@ -726,6 +719,7 @@ function loadgroup($dn) { // Will load all needed values from an existing group
for ($i=0; $i<sizeof($samba3domains); $i++) for ($i=0; $i<sizeof($samba3domains); $i++)
if ($SID == $samba3domains[$i]->SID) $return->smb_domain = $samba3domains[$i]; if ($SID == $samba3domains[$i]->SID) $return->smb_domain = $samba3domains[$i];
} }
// load quotas
if ($_SESSION['config']->scriptServer) { if ($_SESSION['config']->scriptServer) {
$values = getquotas('group',$return->general_username); $values = getquotas('group',$return->general_username);
if (is_object($values)) { if (is_object($values)) {

View File

@ -77,7 +77,7 @@ sub get_fs { # Load mountpoints from mtab if enabled quotas
$quota_usr[$j][3] = $args[$i][3]; $quota_usr[$j][3] = $args[$i][3];
$j++; $j++;
} }
elsif ( $args[$i][3] =~ m/grpquota/ ) { if ( $args[$i][3] =~ m/grpquota/ ) {
$quota_grp[$k][0] = $args[$i][0]; $quota_grp[$k][0] = $args[$i][0];
$quota_grp[$k][1] = $args[$i][1]; $quota_grp[$k][1] = $args[$i][1];
$quota_grp[$k][2] = $args[$i][2]; $quota_grp[$k][2] = $args[$i][2];
@ -151,6 +151,7 @@ if ($found==true) {
get_fs(); # Load list of devices with enabled quotas get_fs(); # Load list of devices with enabled quotas
# Store quota information in array # Store quota information in array
@quota_temp1 = split (':', $vals[6]); @quota_temp1 = split (':', $vals[6]);
$group=0;
$i=0; $i=0;
while ($quota_temp1[$i]) { while ($quota_temp1[$i]) {
$j=0; $j=0;
@ -162,7 +163,7 @@ if ($found==true) {
$i++; $i++;
} }
if ($vals[5] eq 'u') { $group=false; } else { if ($vals[5] eq 'u') { $group=false; } else {
$group=true; $group=1;
@quota_usr = @quota_grp; @quota_usr = @quota_grp;
} }
switch2: { switch2: {
@ -171,7 +172,6 @@ if ($found==true) {
($<, $>) = ($>, $<); # Get root privileges ($<, $>) = ($>, $<); # Get root privileges
while ($quota_usr[$i][0]) { while ($quota_usr[$i][0]) {
$dev = Quota::getqcarg($quota_usr[$i][1]); $dev = Quota::getqcarg($quota_usr[$i][1]);
print "$user[2]\n";
$return = Quota::setqlim($dev,$user[2],0,0,0,0,1,$group); $return = Quota::setqlim($dev,$user[2],0,0,0,0,1,$group);
$i++; $i++;
} }
@ -196,7 +196,7 @@ if ($found==true) {
if ($vals[2]ne'+') { if ($vals[2]ne'+') {
$dev = Quota::getqcarg($quota_usr[$i][1]); $dev = Quota::getqcarg($quota_usr[$i][1]);
@temp = Quota::query($dev,$user[2],$group); @temp = Quota::query($dev,$user[2],$group);
if ($temp[0]) { if ($temp[0]ne'') {
$return = "$quota_usr[$i][1],$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$temp[7]:$return"; $return = "$quota_usr[$i][1],$temp[0],$temp[1],$temp[2],$temp[3],$temp[4],$temp[5],$temp[6],$temp[7]:$return";
} }
else { $return = "$quota_usr[$i][1],0,0,0,0,0,0,0,0:$return"; } else { $return = "$quota_usr[$i][1],0,0,0,0,0,0,0,0:$return"; }

View File

@ -47,12 +47,12 @@ if (isset($_GET['DN'])) {
$_SESSION['account'] ->type = 'group'; $_SESSION['account'] ->type = 'group';
if (isset($_SESSION['account_old'])) unset($_SESSION['account_old']); if (isset($_SESSION['account_old'])) unset($_SESSION['account_old']);
$_SESSION['account_old'] = false; $_SESSION['account_old'] = false;
$values = getquotas('group');
if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values
if (isset($val)) $_SESSION['account']->$key = $val;
}
} }
$values = getquotas($type);
if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values
if (isset($val)) $_SESSION['account']->$key = $val;
}
} }
else if (count($_POST)==0) { // Startcondition. groupedit.php was called from outside else if (count($_POST)==0) { // Startcondition. groupedit.php was called from outside
$_SESSION['account'] = loadGroupProfile('default'); $_SESSION['account'] = loadGroupProfile('default');

View File

@ -53,6 +53,11 @@ if (isset($_GET['DN'])) {
$_SESSION['account']->smb_flagsW = 0; $_SESSION['account']->smb_flagsW = 0;
if (isset($_SESSION['account_old'])) unset($_SESSION['account_old']); if (isset($_SESSION['account_old'])) unset($_SESSION['account_old']);
$_SESSION['account_old'] = false; $_SESSION['account_old'] = false;
$values = getquotas('user');
if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values
if (isset($val)) $_SESSION['account']->$key = $val;
}
} }
} }
else if (count($_POST)==0) { // Startcondition. useredit.php was called from outside else if (count($_POST)==0) { // Startcondition. useredit.php was called from outside
@ -183,7 +188,7 @@ switch ($_POST['select']) { // Select which part of page should be loaded and ch
$select_local = 'unix'; $select_local = 'unix';
} }
// Check if values are OK and set automatic values. if not error-variable will be set // Check if values are OK and set automatic values. if not error-variable will be set
else { // $errors = checkunix($_SESSION['account'], $_SESSION['account']->type); // account.inc else { // account.inc
if ($_SESSION['account']->unix_password != '') { if ($_SESSION['account']->unix_password != '') {
$iv = base64_decode($_COOKIE["IV"]); $iv = base64_decode($_COOKIE["IV"]);
$key = base64_decode($_COOKIE["Key"]); $key = base64_decode($_COOKIE["Key"]);
@ -479,7 +484,7 @@ if ($select_local != 'pdf') {
} }
} }
print_r($_SESSION['account']); // print_r($_SESSION['account']);
// print_r($_POST); // print_r($_POST);
switch ($select_local) { // Select which part of page will be loaded switch ($select_local) { // Select which part of page will be loaded

View File

@ -51,9 +51,7 @@ if ($_POST['backmain'])
} }
echo '</head>'."\n". echo '</head>'."\n".
'<body>'."\n". '<body>'."\n".
'<form action="delete.php" method="post">'."\n". '<form action="delete.php" method="post">'."\n";
'<table class="delete" width="100%">'."\n".
'<tr><td>';
if ($_GET['type']) { if ($_GET['type']) {
$DN2 = explode(";", str_replace("\'", '',$_GET['DN'])); $DN2 = explode(";", str_replace("\'", '',$_GET['DN']));
@ -61,31 +59,66 @@ if ($_GET['type']) {
echo '<input name="DN" type="hidden" value="'.$_GET['DN'].'">'; echo '<input name="DN" type="hidden" value="'.$_GET['DN'].'">';
switch ($_GET['type']) { switch ($_GET['type']) {
case 'user': case 'user':
echo _('Do you really want to delete user(s):'); echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Delete user(s)');
echo "</b></legend>\n";
echo _('<b>Do you really want to delete user(s):</b>');
break; break;
case 'host': case 'host':
echo _('Do you really want to delete host(s):'); echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
echo _('Delete host(s)');
echo "</b></legend>\n";
echo _('<b>Do you really want to delete host(s):</b>');
break; break;
case 'group': case 'group':
echo _('Do you really want to delete group(s):'); echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
echo _('Delete group(s)');
echo "</b></legend>\n";
echo _('<b>Do you really want to delete group(s):</b>');
break; break;
} }
echo '</td></tr>'."\n"; echo "<table border=0 width=\"100%\">\n";
foreach ($DN2 as $dn) echo '<tr><td>'.$dn.'</td></tr>'; foreach ($DN2 as $dn) echo '<tr><td>'.$dn.'</td></tr>';
echo '<tr><td>'; echo "</table>\n";
if (($_GET['type']== user) && $_SESSION['config']->scriptServer) { if (($_GET['type']== user) && $_SESSION['config']->scriptServer) {
echo "<table border=0 width=\"100%\">\n";
echo '<tr><td>';
echo _('Delete also Homedirectories'); echo _('Delete also Homedirectories');
echo '</td>'."\n".'<td><input name="f_rem_home" type="checkbox">'. echo '</td>'."\n".'<td><input name="f_rem_home" type="checkbox">'.
'</td></tr>'."\n".'<tr><td>'; '</td></tr>'."\n";
echo "</table>\n";
} }
echo '<br></td></tr>'."\n".'<tr><td>'.
echo "<br><table border=0 width=\"100%\">\n";
echo '<tr><td>'.
'<input name="delete_no" type="submit" value="'; '<input name="delete_no" type="submit" value="';
echo _('Cancel'); echo '"></td><td></td><td>'. echo _('Cancel'); echo '"></td><td></td><td>'.
'<input name="delete_yes" type="submit" value="'; '<input name="delete_yes" type="submit" value="';
echo _('Commit'); echo '"></td></tr>'; echo _('Commit'); echo '"></td></tr>';
echo "</table></fieldset>\n";
} }
if ($_POST['delete_yes'] && !$_POST['backmain']) { if ($_POST['delete_yes'] && !$_POST['backmain']) {
switch ($_POST['type5']) {
case 'user':
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Deleting user(s)...');
echo "</b></legend>\n";
break;
case 'host':
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
echo _('Deleting host(s)...');
echo "</b></legend>\n";
break;
case 'group':
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
echo _('Deleting group(s)...');
echo "</b></legend>\n";
break;
}
echo "<br><table border=0 width=\"100%\">\n";
$DN2 = explode(";", str_replace("\\", '',str_replace("\'", '',$_POST['DN']))); $DN2 = explode(";", str_replace("\\", '',str_replace("\'", '',$_POST['DN'])));
foreach ($DN2 as $dn) { foreach ($DN2 as $dn) {
echo '<input name="type5" type="hidden" value="'.$_POST['type5'].'">'; echo '<input name="type5" type="hidden" value="'.$_POST['type5'].'">';
@ -136,48 +169,74 @@ if ($_POST['delete_yes'] && !$_POST['backmain']) {
} }
break; break;
} }
if (!$error) echo $dn.' '. _('deleted').'.'; if (!$error) echo "<tr><td><b>$dn ". _('deleted').".</b></td></tr>\n";
else echo $error; else echo "<tr><td><b>$error</b></td></tr>\n";
echo '</td></tr>'."\n".'<tr><td>';
} }
echo "</table><br>\n";
switch ($_POST['type5']) { switch ($_POST['type5']) {
case 'user': case 'user':
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">'. echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
'</td></tr>'."\n";
break; break;
case 'group': case 'group':
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">'. echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">';
'</td></tr>'."\n";
break; break;
case 'host': case 'host':
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">'. echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
'</td></tr>'."\n";
break; break;
} }
echo "</fieldset>\n";
} }
if ($_POST['delete_no']) { if ($_POST['delete_no']) {
echo _('Nothing was deleted').'</td></tr>'; switch ($_POST['type5']) {
case 'user':
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Deleting user(s) canceled.');
echo "</b></legend>\n";
echo _('No user(s) were deleted');
echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to user list'); echo '">';
echo "</fieldset>\n";
break;
case 'host':
echo "<fieldset class=\"hostedit-bright\"><legend class=\"hostedit-bright\"><b>";
echo _('Deleting host(s) canceled.');
echo "</b></legend>\n";
echo _('No host(s) were deleted');
echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to host list'); echo '">';
echo "</fieldset>\n";
break;
case 'group':
echo "<fieldset class=\"groupedit-bright\"><legend class=\"groupedit-bright\"><b>";
echo _('Deleting group(s) canceled.');
echo "</b></legend>\n";
echo _('No group(s) were deleted');
echo "<br>";
echo '<input name="backmain" type="submit" value="'; echo _('Back to group list'); echo '">';
echo "</fieldset>\n";
break;
}
} }
if ($_POST['backmain']) if ($_POST['backmain'])
switch ( $_POST['type5'] ) { switch ( $_POST['type5'] ) {
case 'user' : case 'user' :
echo '<tr><td><a href="lists/listusers.php">'; echo '<a href="lists/listusers.php">';
echo _('Please press here if meta-refresh didn\'t work.'); echo _('Please press here if meta-refresh didn\'t work.');
echo "</a></td></tr>\n"; echo "</a>\n";
break; break;
case 'group' : case 'group' :
echo '<tr><td><a href="lists/listgroup.php">'; echo '<a href="lists/listgroups.php">';
echo _('Please press here if meta-refresh didn\'t work.'); echo _('Please press here if meta-refresh didn\'t work.');
echo "</a></td></tr>\n"; echo "</a>\n";
break; break;
case 'host' : case 'host' :
echo '<tr><td><a href="lists/listhost.php">'; echo '<a href="lists/listhosts.php">';
echo _('Please press here if meta-refresh didn\'t work.'); echo _('Please press here if meta-refresh didn\'t work.');
echo "</a></td></tr>\n"; echo "</a>\n";
break; break;
} }
echo '</table></form></body></html>'."\n"; echo '</form></body></html>'."\n";
?> ?>

View File

@ -355,33 +355,117 @@ function loadfile() {
} }
if ($values->general_username != $return->general_username) $error[] = array('WARN', _('Username'), _('Username in use. Selected next free username.')); if ($values->general_username != $return->general_username) $error[] = array('WARN', _('Username'), _('Username in use. Selected next free username.'));
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error); $_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error);
list($values, $error) = checkglobal($_SESSION['accounts'][$row2], 'user'); // account.inc // Check if Homedir is valid
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error); $_SESSION['account'][$row2]->general_homedir = str_replace('$group', $_SESSION['account'][$row2]->general_group, $_SESSION['account'][$row2]->general_homedir);
if (is_object($values)) { if ($_SESSION['account'][$row2]->general_username != '')
while (list($key, $val) = each($values)) // Set only defined values $_SESSION['account'][$row2]->general_homedir = str_replace('$user', $_SESSION['account'][$row2]->general_username, $_SESSION['account'][$row2]->general_homedir);
if ($val) $_SESSION['accounts'][$row2]->$key = $val; if ( !ereg('^[/]([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|[.]|[-]|[_])*([/]([a-z]|[A-Z])([a-z]|[A-Z]|[0-9]|[.]|[-]|[_])*)*$', $_SESSION['account'][$row2]->general_homedir ))
$_SESSION['accounts'][$row2]->general_uidNumber=""; $errors[] = array('ERROR', _('Home directory'), _('Homedirectory contains invalid characters.'));
// Check if givenname is valid
if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_SESSION['account'][$row2]->general_givenname)) $errors[] = array('ERROR', _('Given name'), _('Given name contains invalid characters'));
// Check if surname is valid
if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_SESSION['account'][$row2]->general_surname)) $errors[] = array('ERROR', _('Surname'), _('Surname contains invalid characters'));
if ( ($_SESSION['account'][$row2]->general_gecos=='') || ($_SESSION['account'][$row2]->general_gecos==' ')) {
$_SESSION['account'][$row2]->general_gecos = $_SESSION['account'][$row2]->general_givenname . " " . $_SESSION['account'][$row2]->general_surname ;
$errors[] = array('INFO', _('Gecos'), _('Inserted sur- and given name in gecos-field.'));
} }
$error = checkunix($_SESSION['accounts'][$row2], 'user'); // account.inc if ($_SESSION['account'][$row2]->general_group=='') $errors[] = array('ERROR', _('Primary group'), _('No primary group defined!'));
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error); // Check if Username contains only valid characters
list($values, $error) = checksamba($_SESSION['accounts'][$row2], 'user'); // account.inc if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $_SESSION['account'][$row2]->general_username))
if (is_object($values)) { $errors[] = array('ERROR', _('Username'), _('Username contains invalid characters. Valid characters are: a-z, 0-9 and .-_ !'));
while (list($key, $val) = each($values)) // Set only defined values // Check if user already exists
if ($val) $_SESSION['accounts'][$row2]->$key = $val; if (isset($_SESSION['account'][$row2]->general_groupadd) && in_array($_SESSION['account'][$row2]->general_group, $_SESSION['account'][$row2]->general_groupadd)) {
for ($i=0; $i<count($_SESSION['account'][$row2]->general_groupadd); $i++ )
if ($_SESSION['account'][$row2]->general_groupadd[$i] == $_SESSION['account'][$row2]->general_group) {
unset ($_SESSION['account'][$row2]->general_groupadd[$i]);
$_SESSION['account'][$row2]->general_groupadd = array_values($_SESSION['account'][$row2]->general_groupadd);
}
} }
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error); // Create automatic useraccount with number if original user already exists
list($values, $error) = checkquota($_SESSION['accounts'][$row2], 'user'); // account.inc // Reset name to original name if new name is in use
if (is_object($values)) { while ($temp = ldapexists($_SESSION['account'][$row2], 'user')) {
while (list($key, $val) = each($values)) // Set only defined values // get last character of username
if ($val) $_SESSION['accounts'][$row2]->$key = $val; $lastchar = substr($_SESSION['account'][$row2]->general_username, strlen($_SESSION['account'][$row2]->general_username)-1, 1);
// Last character is no number
if ( !ereg('^([0-9])+$', $lastchar))
$_SESSION['account'][$row2]->general_username = $_SESSION['account'][$row2]->general_username . '2';
else {
$i=strlen($_SESSION['account'][$row2]->general_username)-1;
$mark = false;
while (!$mark) {
if (ereg('^([0-9])+$',substr($_SESSION['account'][$row2]->general_username, $i, strlen($_SESSION['account'][$row2]->general_username)-$i))) $i--;
else $mark=true;
}
// increase last number with one
$firstchars = substr($_SESSION['account'][$row2]->general_username, 0, $i+1);
$lastchars = substr($_SESSION['account'][$row2]->general_username, $i+1, strlen($_SESSION['account'][$row2]->general_username)-$i);
$_SESSION['account'][$row2]->general_username = $firstchars . (intval($lastchars)+1);
}
} }
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error);
list($values, $error) = checkpersonal($_SESSION['accounts'][$row2], 'user'); // account.inc // Check if UID is valid. If none value was entered, the next useable value will be inserted
if (is_object($values)) { $_SESSION['account'][$row2]->general_uidNumber = checkid($_SESSION['account'][$row2], 'user');
while (list($key, $val) = each($values)) // Set only defined values if (is_string($_SESSION['account'][$row2]->general_uidNumber)) { // true if checkid has returned an error
if ($val) $_SESSION['accounts'][$row2]->$key = $val; $errors[] = array('ERROR', _('ID-Number'), $_SESSION['account'][$row2]->general_uidNumber);
unset($_SESSION['account'][$row2]->general_uidNumber);
} }
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error); // Check if Name-length is OK. minLength=3, maxLength=20
if ( !ereg('.{3,20}', $_SESSION['account'][$row2]->general_username)) $errors[] = array('ERROR', _('Name'), _('Name must contain between 3 and 20 characters.'));
// Check if Name starts with letter
if ( !ereg('^([a-z]|[A-Z]).*$', $_SESSION['account'][$row2]->general_username))
$errors[] = array('ERROR', _('Name'), _('Name contains invalid characters. First character must be a letter'));
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $errors);
if (isset($errors)) unset ($errors);
if ($_SESSION['account'][$row2]->unix_password != '') {
$iv = base64_decode($_COOKIE["IV"]);
$key = base64_decode($_COOKIE["Key"]);
$password = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($_SESSION['account'][$row2]->unix_password), MCRYPT_MODE_ECB, $iv);
$password = str_replace(chr(00), '', $password);
}
if (!ereg('^([a-z]|[A-Z]|[0-9]|[\|]|[\#]|[\*]|[\,]|[\.]|[\;]|[\:]|[\_]|[\-]|[\+]|[\!]|[\%]|[\&]|[\/]|[\?]|[\{]|[\[]|[\(]|[\)]|[\]]|[\}])*$', $password))
$errors[] = array('ERROR', _('Password'), _('Password contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and #*,.;:_-+!$%&/|?{[()]}= !'));
if ( !ereg('^([0-9])*$', $_SESSION['account'][$row2]->unix_pwdminage)) $errors[] = array('ERROR', _('Password minage'), _('Password minage must be are natural number.'));
if ( $_SESSION['account'][$row2]->unix_pwdminage > $_SESSION['account'][$row2]->unix_pwdmaxage ) $errors[] = array('ERROR', _('Password maxage'), _('Password maxage must bigger as Password Minage.'));
if ( !ereg('^([0-9]*)$', $_SESSION['account'][$row2]->unix_pwdmaxage)) $errors[] = array('ERROR', _('Password maxage'), _('Password maxage must be are natural number.'));
if ( !ereg('^(([-][1])|([0-9]*))$', $_SESSION['account'][$row2]->unix_pwdallowlogin))
$errors[] = array('ERROR', _('Password Expire'), _('Password expire must be are natural number or -1.'));
if ( !ereg('^([0-9]*)$', $_SESSION['account'][$row2]->unix_pwdwarn)) $errors[] = array('ERROR', _('Password warn'), _('Password warn must be are natural number.'));
if ((!$_SESSION['account'][$row2]->unix_host=='') && !ereg('^([a-z]|[A-Z]|[0-9]|[.]|[-])+(([,])+([ ])*([a-z]|[A-Z]|[0-9]|[.]|[-])+)*$', $_SESSION['account']->unix_host))
$errors[] = array('ERROR', _('Unix workstations'), _('Unix workstations is invalid.'));
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $errors);
if (isset($errors)) unset ($errors);
$_SESSION['account'][$row2]->smb_displayName = $_SESSION['account'][$row2]->general_gecos;
$i=0;
while ($_SESSION['account'][$row2]->quota[$i][0]) {
// Check if values are OK and set automatic values. if not error-variable will be set
if (!ereg('^([0-9])*$', $_SESSION['account'][$row2]->quota[$i][2]))
$errors[] = array('ERROR', _('Block soft quota'), _('Block soft quota contains invalid characters. Only natural numbers are allowed'));
if (!ereg('^([0-9])*$', $_SESSION['account'][$row2]->quota[$i][3]))
$errors[] = array('ERROR', _('Block hard quota'), _('Block hard quota contains invalid characters. Only natural numbers are allowed'));
if (!ereg('^([0-9])*$', $_SESSION['account'][$row2]->quota[$i][6]))
$errors[] = array('ERROR', _('Inode soft quota'), _('Inode soft quota contains invalid characters. Only natural numbers are allowed'));
if (!ereg('^([0-9])*$', $_SESSION['account'][$row2]->quota[$i][7]))
$errors[] = array('ERROR', _('Inode hard quota'), _('Inode hard quota contains invalid characters. Only natural numbers are allowed'));
$i++;
}
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $errors);
if (isset($errors)) unset ($errors);
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['account'][$row2]->personal_telephoneNumber)) $errors[] = array('ERROR', _('Telephone number'), _('Please enter a valid telephone number!'));
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['account'][$row2]->personal_mobileTelephoneNumber)) $errors[] = array('ERROR', _('Mobile number'), _('Please enter a valid mobile number!'));
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['account'][$row2]->personal_facsimileTelephoneNumber)) $errors[] = array('ERROR', _('Fax number'), _('Please enter a valid fax number!'));
if ( !ereg('^(([0-9]|[A-Z]|[a-z]|[.]|[-]|[_])+[@]([0-9]|[A-Z]|[a-z]|[-])+([.]([0-9]|[A-Z]|[a-z]|[-])+)*)*$', $_SESSION['account'][$row2]->personal_mail)) $errors[] = array('ERROR', _('eMail address'), _('Please enter a valid eMail address!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['account'][$row2]->personal_street)) $errors[] = array('ERROR', _('Street'), _('Please enter a valid street name!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['account'][$row2]->personal_postalAddress)) $errors[] = array('ERROR', _('Postal address'), _('Please enter a valid postal address!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['account'][$row2]->personal_title)) $errors[] = array('ERROR', _('Title'), _('Please enter a valid title!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['account'][$row2]->personal_employeeType)) $errors[] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z])*$', $_SESSION['account']->personal_postalCode)) $errors[] = array('ERROR', _('Postal code'), _('Please enter a valid postal code!'));
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $errors);
if (isset($errors)) unset ($errors);
} }
} }
if ($_FILES['userfile']['size']>0) { if ($_FILES['userfile']['size']>0) {

View File

@ -29,7 +29,6 @@ include_once('../lib/config.inc'); // File with configure-functions
session_save_path('../sess'); session_save_path('../sess');
@session_start(); @session_start();
echo $_SESSION['account'];
echo '<html><head><title>'; echo '<html><head><title>';
echo _('Create new accounts'); echo _('Create new accounts');
echo '</title>'. echo '</title>'.
@ -38,8 +37,7 @@ echo '</title>'.
'<meta http-equiv="cache-control" content="no-cache">'. '<meta http-equiv="cache-control" content="no-cache">'.
'</head><body>'. '</head><body>'.
'<form enctype="multipart/form-data" action="massdetail.php" method="post">'. '<form enctype="multipart/form-data" action="massdetail.php" method="post">'.
'<table class="massdetail" width="100%">'. '<table class="massdetail" width="100%">';
'<tr><td></td></tr>';
if ($_GET) { if ($_GET) {
$row = $_GET['row']; $row = $_GET['row'];
@ -51,51 +49,104 @@ if ($_POST) {
} }
if ($_POST['apply']) { if ($_POST['apply']) {
if ($_POST['f_general_surname']) $_SESSION['accounts'][$row]->general_surname = $_POST['f_general_surname'];
else $_SESSION['accounts'][$row]->general_surname='';
if ($_POST['f_general_givenname']) $_SESSION['accounts'][$row]->general_givenname = $_POST['f_general_givenname']; // Check if surname is valid
else $_SESSION['accounts'][$row]->general_givenname=''; if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_POST['f_general_surname'])) $errors[] = array('ERROR', _('Surname'), _('Surname contains invalid characters'));
if ($_POST['f_general_username']) $_SESSION['accounts'][$row]->general_username = $_POST['f_general_username']; else $_SESSION['accounts'][$row]->general_surname = $_POST['f_general_surname'];
else $_SESSION['accounts'][$row]->general_username=''; // Check if givenname is valid
if ($_POST['f_general_group']) $_SESSION['accounts'][$row]->general_group = $_POST['f_general_group']; if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_POST['f_general_givenname'])) $errors[] = array('ERROR', _('Given name'), _('Given name contains invalid characters'));
else $_SESSION['accounts'][$row]->general_group=''; else $_SESSION['accounts'][$row]->general_givenname = $_POST['f_general_givenname'];
if ($_POST['f_personal_title']) $_SESSION['accounts'][$row]->personal_title = $_POST['f_personal_title']; // Check if username is valid
else $_SESSION['accounts'][$row]->personal_title=''; if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $_POST['f_general_username']))
if ($_POST['f_personal_employeeType']) $_SESSION['accounts'][$row]->personal_employeeType = $_POST['f_personal_employeeType']; $errors[] = array('ERROR', _('Username'), _('Username contains invalid characters. Valid characters are: a-z, 0-9 and .-_ !'));
else $_SESSION['accounts'][$row]->personal_employeeType=''; else {
if ($_POST['f_personal_street']) $_SESSION['accounts'][$row]->personal_street = $_POST['f_personal_street']; $_SESSION['accounts'][$row]->general_username = $_POST['f_general_username'];
else $_SESSION['accounts'][$row]->personal_street=''; // Check if user already exists
if ($_POST['f_personal_postalCode']) $_SESSION['accounts'][$row]->personal_postalCode = $_POST['f_personal_postalCode']; if (isset($_SESSION['account'][$row]->general_groupadd) && in_array($_SESSION['account'][$row]->general_group, $_SESSION['account'][$row]->general_groupadd)) {
else $_SESSION['accounts'][$row]->personal_postalCode=''; for ($i=0; $i<count($_SESSION['account'][$row]->general_groupadd); $i++ )
if ($_POST['f_personal_postalAddress']) $_SESSION['accounts'][$row]->personal_postalAddress = $_POST['f_personal_postalAddress']; if ($_SESSION['account'][$row]->general_groupadd[$i] == $_SESSION['account'][$row]->general_group) {
else $_SESSION['accounts'][$row]->personal_postalAddress=''; unset ($_SESSION['account'][$row]->general_groupadd[$i]);
if ($_POST['f_personal_telephoneNumber']) $_SESSION['accounts'][$row]->personal_telephoneNumber = $_POST['f_personal_telephoneNumber']; $_SESSION['account'][$row]->general_groupadd = array_values($_SESSION['account'][$row]->general_groupadd);
else $_SESSION['accounts'][$row]->personal_telephoneNumber=''; }
if ($_POST['f_personal_mobileTelephoneNumber']) $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $_POST['f_personal_mobileTelephoneNumber']; }
else $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber=''; // Create automatic useraccount with number if original user already exists
if ($_POST['f_personal_facsimileTelephoneNumber']) $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $_POST['f_personal_facsimileTelephoneNumber']; // Reset name to original name if new name is in use
else $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber=''; while ($temp = ldapexists($_SESSION['account'][$row], 'user')) {
if ($_POST['f_personal_mail']) $_SESSION['accounts'][$row]->personal_mail = $_POST['f_personal_mail']; // get last character of username
else $_SESSION['accounts'][$row]->personal_mail=''; $lastchar = substr($_SESSION['account'][$row]->general_username, strlen($_SESSION['account'][$row]->general_username)-1, 1);
// Last character is no number
if ( !ereg('^([0-9])+$', $lastchar))
$_SESSION['account'][$row]->general_username = $_SESSION['account'][$row]->general_username . '2';
else {
$i=strlen($_SESSION['account'][$row]->general_username)-1;
$mark = false;
while (!$mark) {
if (ereg('^([0-9])+$',substr($_SESSION['account'][$row]->general_username, $i, strlen($_SESSION['account'][$row]->general_username)-$i))) $i--;
else $mark=true;
}
// increase last number with one
$firstchars = substr($_SESSION['account'][$row]->general_username, 0, $i+1);
$lastchars = substr($_SESSION['account'][$row]->general_username, $i+1, strlen($_SESSION['account'][$row]->general_username)-$i);
$_SESSION['account'][$row]->general_username = $firstchars . (intval($lastchars)+1);
}
}
}
// check if group is valid
if ($_POST['f_general_group']!='') $_SESSION['accounts'][$row]->general_group = $_POST['f_general_group'];
else $errors[] = array('Error', _('Primary group'), _('No primary group defined.'));
if (in_array($_POST['f_general_group'], findgroups)) $_SESSION['accounts'][$row]->general_group = $_POST['f_general_group'];
else $errors[] = array('Warning', _('Primary group'), _('Primary group does not exist. Will create group automaticly.'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_POST['f_personal_title'])) $errors[] = array('ERROR', _('Title'), _('Please enter a valid title!'));
else $_SESSION['accounts'][$row]->personal_title = $_POST['f_personal_title'];
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_POST['f_personal_employeeType'])) $errors[] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!'));
else $_SESSION['accounts'][$row]->personal_employeeType = $_POST['f_personal_employeeType'];
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_POST['f_personal_street'])) $errors[] = array('ERROR', _('Street'), _('Please enter a valid street name!'));
else $_SESSION['accounts'][$row]->personal_street = $_POST['f_personal_street'];
if ( !ereg('^([0-9]|[A-Z]|[a-z])*$', $_POST['f_personal_postalCode'])) $errors[] = array('ERROR', _('Postal code'), _('Please enter a valid postal code!'));
else $_SESSION['accounts'][$row]->personal_postalCode = $_POST['f_personal_postalCode'];
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_POST['f_personal_postalAddress'])) $errors[] = array('ERROR', _('Postal address'), _('Please enter a valid postal address!'));
else $_SESSION['accounts'][$row]->personal_postalAddress = $_POST['f_personal_postalAddress'];
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_POST['f_personal_telephoneNumber'])) $errors[] = array('ERROR', _('Telephone number'), _('Please enter a valid telephone number!'));
else $_SESSION['accounts'][$row]->personal_telephoneNumber = $_POST['f_personal_telephoneNumber'];
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_POST['f_personal_mobileTelephoneNumber'])) $errors[] = array('ERROR', _('Mobile number'), _('Please enter a valid mobile number!'));
else $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $_POST['f_personal_mobileTelephoneNumber'];
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_POST['f_personal_facsimileTelephoneNumber'])) $errors[] = array('ERROR', _('Fax number'), _('Please enter a valid fax number!'));
else $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $_POST['f_personal_facsimileTelephoneNumber'];
if ( !ereg('^(([0-9]|[A-Z]|[a-z]|[.]|[-]|[_])+[@]([0-9]|[A-Z]|[a-z]|[-])+([.]([0-9]|[A-Z]|[a-z]|[-])+)*)*$', $_POST['f_personal_mail'])) $errors[] = array('ERROR', _('eMail address'), _('Please enter a valid eMail address!'));
else $_SESSION['accounts'][$row]->personal_mail = $_POST['f_personal_mail'];
} }
echo '<tr><td><input name="type" type="hidden" value="'.$select.'">'; echo '<tr><td><input name="type" type="hidden" value="'.$select.'"></td></tr>';
echo '<tr><td><input name="row" type="hidden" value="'.$row.'">'; echo '<tr><td><input name="row" type="hidden" value="'.$row.'"></td></tr>';
if (is_array($errors)) {
for ($i=0; $i<sizeof($errors); $i++) {
StatusMessage($errors[$i][0], $errors[$i][1], $errors[$i][2]);
}
}
switch ($select) { switch ($select) {
case 'error': case 'error':
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++) for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'ERROR') if ($_SESSION['errors'][$row][$i][0] == 'ERROR') {
StatusMessage('ERROR', _('Invalid Value!'), $_SESSION['errors'][$row][$i][2]); StatusMessage('ERROR', _('Invalid Value!'), $_SESSION['errors'][$row][$i][2]);
}
break; break;
case 'info': case 'info':
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++) for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'INFO') if ($_SESSION['errors'][$row][$i][0] == 'INFO') {
StatusMessage('INFO', _('Check values.'), $_SESSION['errors'][$row][$i][2]); StatusMessage('INFO', _('Check values.'), $_SESSION['errors'][$row][$i][2]);
}
break; break;
case 'warn': case 'warn':
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++) for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'WARN') if ($_SESSION['errors'][$row][$i][0] == 'WARN') {
StatusMessage('WARN', _('Check values.'), $_SESSION['errors'][$row][$i][2]); StatusMessage('WARN', _('Check values.'), $_SESSION['errors'][$row][$i][2]);
}
break; break;
case 'detail': case 'detail':
echo '<tr><td>'; echo '<tr><td>';