improved upload

This commit is contained in:
katagia 2003-08-28 18:37:27 +00:00
parent f53e55d32e
commit 02c85867c0
3 changed files with 323 additions and 272 deletions

View File

@ -1686,9 +1686,9 @@ function creategroup($values) { // Will create the LDAP-Group
$attr['gidNumber'] = $values->general_uidNumber; $attr['gidNumber'] = $values->general_uidNumber;
$attr['description'] = $values->general_gecos; $attr['description'] = $values->general_gecos;
if ($values->general_memeberUid) $attr['memberUid'] = $values->general_memberUid; if ($values->general_memeberUid) $attr['memberUid'] = $values->general_memberUid;
if ($_SESSION['config']->samba3 =='yes') { if ($_SESSION['config']->samba3 =='yes' && (isset($values->smb_mapgroup))) {
$attr['objectClass'][1] = 'sambaGroupMapping';
$attr['sambaSID'] = $values->smb_mapgroup; $attr['sambaSID'] = $values->smb_mapgroup;
$attr['objectClass'][1] = 'sambaGroupMapping';
$attr['sambaGroupType'] = '2'; $attr['sambaGroupType'] = '2';
if ($values->general_gecos) $attr['displayName'] = $values->general_gecos; if ($values->general_gecos) $attr['displayName'] = $values->general_gecos;
} }

View File

@ -35,100 +35,239 @@ session_save_path('../sess');
setlanguage(); setlanguage();
$time=time(); $time=time();
if ($_POST['tolist'] && ($_FILES['userfile']['size']>0)) $select = 'list'; if (count($_POST)==0) {
if ($_POST['list']) $select = 'list'; if (isset($_GET['list2'])) $select = 'list2';
if ($_POST['back']) $select = 'main'; else if (isset($_GET['create'])) $select='create';
if ($_POST['cancel']) $select = 'cancel'; else $select='main';
if ($_POST['create']) $select = 'create'; }
if ($_POST['pdf']) { else {
if ($_POST['tolist'] && ($_FILES['userfile']['size']>0)) $select = 'list';
else if ($_POST['list2']) $select = 'list2';
else if ($_POST['back']) $select = 'main';
else if ($_POST['cancel']) $select = 'cancel';
else if ($_POST['create']) $select = 'create';
else if ($_POST['pdf']) {
createUserPDF($_SESSION['accounts']); createUserPDF($_SESSION['accounts']);
$select='pdf'; $select='pdf';
} }
if (!$select && !$_SESSION['pointer']) $select='main'; }
if (!$select && $_SESSION['pointer']) $select='create';
if ($select!='pdf') { if ($select!='pdf') {
// Write HTML-Header and part of Table // Write HTML-Header and part of Table
echo $_SESSION['header']; echo $_SESSION['header'];
echo '<html><head><title>'; echo '<html><head><title>';
echo _('Create new Accounts'); echo _('Create new Accounts');
echo '</title>'. echo '</title>'."\n".
'<link rel="stylesheet" type="text/css" href="../style/layout.css">'. '<link rel="stylesheet" type="text/css" href="../style/layout.css">'."\n".
'<meta http-equiv="pragma" content="no-cache">'. '<meta http-equiv="pragma" content="no-cache">'."\n".
'<meta http-equiv="cache-control" content="no-cache">'; '<meta http-equiv="cache-control" content="no-cache">'."\n";
} switch ($select) {
switch ($select) {
case 'cancel': case 'cancel':
if ( isset($_SESSION['accounts'])) unset($_SESSION['accounts']); if ( isset($_SESSION['accounts'])) unset($_SESSION['accounts']);
if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']); if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']);
if ( isset($_SESSION['errors'])) unset($_SESSION['errors']); if ( isset($_SESSION['errors'])) unset($_SESSION['errors']);
echo '<meta http-equiv="refresh" content="1; URL=lists/listusers.php">'; echo '<meta http-equiv="refresh" content="1; URL=lists/listusers.php">'."\n".
'</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
'<table class="masscreate" width="100%">'.
'<tr><td></td></tr>'."\n";
break; break;
case 'create': case 'create':
if ($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) { if ($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) {
$refresh = get_cfg_var('max_execution_time')-5; $refresh = get_cfg_var('max_execution_time')-5;
echo '<meta http-equiv="refresh" content="'.$refresh.'; URL=masscreate.php">'; echo '<meta http-equiv="refresh" content="'.$refresh.'; URL=masscreate.php?create">'."\n";
}
echo '</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
'<table class="masscreate" width="100%">'.
'<tr><td></td></tr>'."\n";
echo '<tr><td>';
echo _('Creating users. Please stand by.');
echo '</td></tr>'."\n";
$stay=true;
while (($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) && $stay) {
if ($_SESSION['accounts'][$_SESSION['pointer']]->general_username!='') {
if (getgid($_SESSION['accounts'][$_SESSION['pointer']]->general_group)==-1) {
$group = new account();
$group->general_username=$_SESSION['accounts'][$_SESSION['pointer']]->general_group;
$group->general_uidNumber=checkid($_SESSION['accounts'][$_SESSION['pointer']], 'group');
$group->general_gecos=$_SESSION['accounts'][$_SESSION['pointer']]->general_group;
$group->general_dn=$_SESSION['config']->get_GroupSuffix();
creategroup($group);
}
$_SESSION['accounts'][$_SESSION['pointer']]->general_uidNumber = checkid($_SESSION['accounts'][$_SESSION['pointer']], 'user');
$iv = base64_decode($_COOKIE["IV"]);
$key = base64_decode($_COOKIE["Key"]);
$_SESSION['accounts'][$_SESSION['pointer']]->unix_password = base64_encode(mcrypt_encrypt(
MCRYPT_RIJNDAEL_256, $key, genpasswd(), MCRYPT_MODE_ECB, $iv));
$_SESSION['accounts'][$_SESSION['pointer']]->smb_password = $_SESSION['accounts'][$_SESSION['pointer']]->unix_password;
if ( (time()-$time)<(get_cfg_var('max_execution_time')-10)) {
$error = createuser($_SESSION['accounts'][$_SESSION['pointer']]);
if ($error==1) {
$_SESSION['pointer']++;
echo '<tr><td>';
sprintf (_('Created user %s.'), $_SESSION['accounts'][$_SESSION['pointer']]->general_username);
echo '</td></tr>'."\n";
}
else {
$stay = false;
StatusMessage('ERROR', _('Could not create user!'), sprintf (_('Was unable to create %s.'), $_SESSION['accounts'][$row]->general_username));
}
}
else $stay=false;
}
else $_SESSION['pointer']++;
}
if (!$stay) {
echo '<tr><td><a href="masscreate.php?create">';
echo _('Please press here if meta-refresh didn\'t work.');
echo '</a></td></tr>'."\n";
echo '<tr><td><input name="cancel" type="submit" value="'; echo _('Cancel');
echo '"></td></tr>';
}
else {
echo '<tr><td>';
echo _('All Users have been created');
echo '</td></tr>'."\n".'<tr><td>';
echo '<tr><td><input name="cancel" type="submit" value="'; echo _('User list'); echo '">';
echo '</td><td></td><td><input name="pdf" type="submit" value="'; echo _('Create PDF file'); echo '">';
echo '</td></tr>'."\n";
if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']);
if ( isset($_SESSION['errors'])) unset($_SESSION['errors']);
} }
break; break;
case 'list':
if (!is_array($accounts)) $accounts = array();
$groups = array();
if (loadfile()) {
echo '<meta http-equiv="refresh" content="2; URL=masscreate.php?list2">'."\n".
'</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
'<table class="masscreate" width="100%">'.
'<tr><td><a href="masscreate.php?list2">';
echo _('Please press here if meta-refresh didn\'t work.');
echo "</a></td></tr>\n";
} }
else {
if ($select!='pdf') { //echo '<meta http-equiv="refresh" content="2; URL=masscreate.php?list2">'."\n".
echo '</head><body>'. echo '</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'; '<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
echo '<table class="masscreate" width="100%">'. '<table class="masscreate" width="100%">'.
'<tr><td></td></tr>'; '<tr><td>';
echo _('Max 400 users allowed. Ignored additional users.');
echo '</td></tr>'."\n";
echo '<tr><td><a href="lists/listusers.php">';
echo _('Cancel');
echo '</a></td><td><a href="masscreate.php?list2">';
echo _('Contiune');
echo "</a></td></tr>\n";
} }
break;
switch ($select) { case 'list2':
echo '</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
'<table class="masscreate" width="100%">'.
'<tr><td></td></tr>'."\n".
'<tr><td>';
echo _('Confirm List');
echo '</td></tr>'."\n";
for ($i=0; $i<sizeof($groups); $i++)
if ($_SESSION['accounts'][$i]->general_group!='')
StatusMessage('INFO', _('Group').' '.
$_SESSION['accounts'][$i]->general_group.' '._('not found!'), _('It will be created.'));
echo '<tr><td>'._('row').'</td>'."\n".'<td>'. _('Surname'). '</td>'."\n".'<td>'. _('Given name'). '</td>'."\n".'<td>'. _('User name'). '</td>'."\n".'<td>'. _('Primary group'). '</td>'."\n".'<td>'.
_('Details'). '</td>'."\n".'<td>' . _('Infos'). '</td>'."\n".'<td>' . _('Warnings'). '</td>'."\n".'<td>' . _('Errors') . '</td>'."\n".'</tr>'."\n";
if (!isset($_SESSION['rowstart'])) $_SESSION['rowstart'] = 0;
//if (sizeof($_SESSION['accounts'])<($_SESSION['rowstart']+10)) $end = sizeof($_SESSION['accounts']);
// else $end = $_SESSION['rowstart']+10;
$end = sizeof($_SESSION['accounts']);
for ($row=0; $row<$end; $row++) { // loops for every row
echo '<tr><td>'.$row.'</td>'."\n".'<td>'.
$_SESSION['accounts'][$row]->general_surname.'</td>'."\n".'<td>'.
$_SESSION['accounts'][$row]->general_givenname.'</td>'."\n".'<td>'.
$_SESSION['accounts'][$row]->general_username.'</td>'."\n".'<td>'.
$_SESSION['accounts'][$row]->general_group.'</td>'."\n".'<td>'.
'<a target=_blank href="massdetail.php?row='.$row.'&type=detail">'._('Show Details.').'</a></td>'."\n".'<td>';
$found=false;
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'INFO') $found=true;
if ($found) echo '<a target="massdetail" href="massdetail.php?row='.$row.'&type=info">'._('Show Infos.').'</a>';
echo '</td>'."\n".'<td>';
$found=false;
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'WARN') $found=true;
if ($found) echo '<a target="massdetail" href="massdetail.php?row='.$row.'&type=warn">'._('Show Warnings.').'</a>';
echo '</td>'."\n".'<td>';
$found=false;
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'ERROR') $found=true;
if ($found) echo '<a target="massdetail" href="massdetail.php?row='.$row.'&type=error">'._('Show Errors.').'</a>';
echo '</td></tr>'."\n";
}
$noerrors=true;
for ($i=0; $i<sizeof($_SESSION['errors']); $i++)
for ($j=0; $j<sizeof($_SESSION['errors'][$i]); $j++)
if ($_SESSION['errors'][$i][$j][0] == 'ERROR') $noerrors=false;
$nowarn=true;
for ($i=0; $i<sizeof($_SESSION['errors']); $i++)
for ($j=0; $j<sizeof($_SESSION['errors'][$i]); $j++)
if ($_SESSION['errors'][$i][$j][0] == 'WARN') $nowarn=false;
echo '<br>';
if (!$noerrors) { echo '<tr><td>'. _('There are some errors.') . '</td></tr>'."\n"; }
if (!$nowarn) { echo '<tr><td>'. _('There are some warnings.') . '</td></tr>'."\n"; }
echo '</table><br><table class="masscreate" width="100%">'.
'<tr><td><input name="back" type="submit" value="'; echo _('Back');
echo '"></td><td><input name="cancel" type="submit" value="'; echo _('Cancel');
echo '"></td><td><input name="list2" type="submit" value="'; echo _('Refresh'); echo '">';
if ($noerrors) { echo '</td><td><input name="create" type="submit" value="'; echo _('Create'); echo '">'; }
echo '</td></tr>'."\n";
break;
case 'main': case 'main':
if ( isset($_SESSION['accounts'])) unset($_SESSION['accounts']); if ( isset($_SESSION['accounts'])) unset($_SESSION['accounts']);
if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']); if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']);
if ( isset($_SESSION['errors'])) unset($_SESSION['errors']); if ( isset($_SESSION['errors'])) unset($_SESSION['errors']);
$_SESSION['pointer']=0; $_SESSION['pointer']=0;
$profilelist = getUserProfiles(); $profilelist = getUserProfiles();
echo '<tr><td><input name="select" type="hidden" value="main">'; echo '</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
'<table class="masscreate" width="100%">'.
'<tr><td></td></tr>'."\n".
'<tr><td><input name="select" type="hidden" value="main">';
echo _('Mass Creation'); echo _('Mass Creation');
echo '</td></tr><tr><td>'; echo '</td></tr><tr><td>'."\n";
echo _('Please provide a csv-file with the following syntax. Values with * are required:'); echo _('Please provide a csv-file with the following syntax. Values with * are required:');
echo '</td></tr><tr><td>'; echo '</td></tr><tr><td>'."\n";
echo _('Surname*,Givenname*,Username*,PrimaryGroup,Title,Mail,telephonenumber,'); echo _('Surname*,Givenname*,Username*,PrimaryGroup,Title,Mail,telephonenumber,');
echo '</td></tr><tr><td>'; echo '</td></tr><tr><td>'."\n";
echo _('mobileTelephoneNumber,facsimileNumber,street,postalCode,postalAddress,'); echo _('mobileTelephoneNumber,facsimileNumber,street,postalCode,postalAddress,');
echo '</td></tr><tr><td>'; echo '</td></tr><tr><td>'."\n";
echo _('employeeType. If Primary group is not given it\'ll used from profile.'); echo _('employeeType. If Primary group is not given it\'ll used from profile.');
echo '</td></tr><tr><td>'; echo '</td></tr><tr><td>'."\n";
echo _('If PrimaryGroup does not exist it will be created.'); echo _('If PrimaryGroup does not exist it will be created.');
echo '</td></tr><tr><td>'; echo '</td></tr><tr><td>'."\n";
echo _('Select Profile:'); echo _('Select Profile:');
echo '</td><td><select name="f_selectprofile">'; echo '</td><td><select name="f_selectprofile">'."\n";
foreach ($profilelist as $profile) echo '<option>' . $profile; foreach ($profilelist as $profile) echo '<option>' . $profile;
echo '</select>'; echo '</select>'.
echo '</td></tr>'."\n".'<tr><td>'; '</td></tr>'."\n".'<tr><td>';
echo _('Suffix'); echo '</td><td><select name="f_general_suffix">'; echo _('Suffix'); echo '</td><td><select name="f_general_suffix">';
foreach ($_SESSION['ldap']->search_units($_SESSION['config']->get_UserSuffix()) as $suffix) { foreach ($_SESSION['ldap']->search_units($_SESSION['config']->get_UserSuffix()) as $suffix)
if ($_POST['f_general_suffix']) { echo '<option>' . $suffix. '</option>';
if ($_POST['f_general_suffix'] == $suffix) echo '</select></td>'."\n".'<td><a href="help.php?HelpNumber=461" target="lamhelp">'._('Help').'</a>'.
echo '<option selected>' . $suffix. '</option>'; '</td></tr><tr><td>'."\n".
else echo '<option>' . $suffix. '</option>';
}
else echo '<option>' . $suffix. '</option>';
}
echo '</select></td><td><a href="help.php?HelpNumber=461" target="lamhelp">'._('Help').'</a>'.
'</td></tr><tr><td>'.
'<input type="hidden" name="MAX_FILE_SIZE" value="100000">'; '<input type="hidden" name="MAX_FILE_SIZE" value="100000">';
echo _('Select file:'); echo _('Select file:');
echo '</td><td><input name="userfile" type="file"></td></tr>'. echo '</td><td><input name="userfile" type="file"></td></tr>'."\n".
'<tr><td><input name="tolist" type="submit" value="'; echo _('Commit'); echo '">'; '<tr><td><input name="tolist" type="submit" value="'; echo _('Commit'); echo '">'."\n".
echo '</td></tr>'; '</td></tr>'."\n";
break; break;
case 'list': }
if (!is_array($accounts)) $accounts = array(); echo '</table></form></body></html>';
$groups = array(); }
echo '<tr><td>';
echo _('Confirm List');
echo '</td></tr>';
function loadfile() {
if ($_FILES['userfile']['size']>0) { if ($_FILES['userfile']['size']>0) {
$handle = fopen($_FILES['userfile']['tmp_name'], 'r'); $handle = fopen($_FILES['userfile']['tmp_name'], 'r');
$profile = loadUserProfile($_POST['f_selectprofile']) ; $profile = loadUserProfile($_POST['f_selectprofile']) ;
@ -155,165 +294,72 @@ switch ($select) {
$_SESSION['accounts'][$row]->smb_password=$_SESSION['accounts'][$row]->unix_password; $_SESSION['accounts'][$row]->smb_password=$_SESSION['accounts'][$row]->unix_password;
} }
} }
for ($row=0; $row<sizeof($_SESSION['accounts']); $row++) { // loops for every row for ($row2=0; $row2<sizeof($_SESSION['accounts']); $row2++) { // loops for every row
list($values, $_SESSION['errors'][$row]) = checkglobal($_SESSION['accounts'][$row], 'user'); // account.inc // Check for double entries in $_SESSION['accounts']
if ($row2<401) {
for ($i=$row2+1; $i<sizeof($_SESSION['accounts']); $i++ ) {
if ($_SESSION['accounts'][$row2]->general_username == $_SESSION['accounts'][$i]->general_username) { // Found user with same name
// get last character of username
if (!is_numeric($_SESSION['accounts'][$i]->general_username{strlen($_SESSION['accounts'][$i]->general_username)-1}))
$_SESSION['accounts'][$i]->general_username = $_SESSION['accounts'][$i]->general_username . '2';
else {
// Get interger-end of string hello456 -> hello + 456
$start = strlen($_SESSION['accounts'][$i]->general_username)-1;
while (is_numeric(substr($_SESSION['accounts'][$i]->general_username, $start))) $start--;
// Increse rusultung number
$first = substr($_SESSION['accounts'][$i]->general_username, 0, $start+1);
$second = intval(substr($_SESSION['accounts'][$i]->general_username, $start+1))+1;
$_SESSION['accounts'][$i]->general_username = $first . $second;
}
while ($temp = ldapexists($_SESSION['accounts'][$i], 'user')) {
// Get interger-end of string hello456 -> hello + 456
$start = strlen($_SESSION['accounts'][$i]->general_username)-1;
while (is_numeric(substr($_SESSION['accounts'][$i]->general_username, $start))) $start--;
// Increse rusultung number
$first = substr($_SESSION['accounts'][$i]->general_username, 0, $start+1);
$second = intval(substr($_SESSION['accounts'][$i]->general_username, $start+1))+1;
$_SESSION['accounts'][$i]->general_username = $first . $second;
}
}
}
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);
list($values, $error) = checkglobal($_SESSION['accounts'][$row2], 'user'); // account.inc
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error);
if (is_object($values)) { if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values while (list($key, $val) = each($values)) // Set only defined values
if ($val) $_SESSION['accounts'][$row]->$key = $val; if ($val) $_SESSION['accounts'][$row2]->$key = $val;
$_SESSION['accounts'][$row]->general_uidNumber=""; $_SESSION['accounts'][$row2]->general_uidNumber="";
} }
$error = checkunix($_SESSION['accounts'][$row], 'user'); // account.inc $error = checkunix($_SESSION['accounts'][$row2], 'user'); // account.inc
$_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error); $_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error);
list($values, $error) = checksamba($_SESSION['accounts'][$row], 'user'); // account.inc list($values, $error) = checksamba($_SESSION['accounts'][$row2], 'user'); // account.inc
if (is_object($values)) { if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values while (list($key, $val) = each($values)) // Set only defined values
if ($val) $_SESSION['accounts'][$row]->$key = $val; if ($val) $_SESSION['accounts'][$row2]->$key = $val;
} }
$_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error); $_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error);
list($values, $error) = checkquota($_SESSION['accounts'][$row], 'user'); // account.inc list($values, $error) = checkquota($_SESSION['accounts'][$row2], 'user'); // account.inc
if (is_object($values)) { if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values while (list($key, $val) = each($values)) // Set only defined values
if ($val) $_SESSION['accounts'][$row]->$key = $val; if ($val) $_SESSION['accounts'][$row2]->$key = $val;
} }
$_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error); $_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error);
list($values, $error) = checkpersonal($_SESSION['accounts'][$row], 'user'); // account.inc list($values, $error) = checkpersonal($_SESSION['accounts'][$row2], 'user'); // account.inc
if (is_object($values)) { if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values while (list($key, $val) = each($values)) // Set only defined values
if ($val) $_SESSION['accounts'][$row]->$key = $val; if ($val) $_SESSION['accounts'][$row2]->$key = $val;
}
$_SESSION['errors'][$row2] = array_merge($_SESSION['errors'][$row2], $error);
} }
$_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error);
} }
for ($i=0; $i<sizeof($groups); $i++)
if ($_SESSION['accounts'][$i]->general_group!='')
StatusMessage('INFO', _('Group').' '.
$_SESSION['accounts'][$i]->general_group.' '._('not found!'), _('It will be created.'));
if ($_FILES['userfile']['size']>0) { if ($_FILES['userfile']['size']>0) {
fclose($handle); fclose($handle);
unlink($_FILES['userfile']['tmp_name']); unlink($_FILES['userfile']['tmp_name']);
} }
echo '<tr><td>'._('row').'</td><td>'. _('Surname'). '</td><td>'. _('Given name'). '</td><td>'. _('User name'). '</td><td>'. _('Primary group'). '</td><td>'. if ($row2>400) return false;
_('Details'). '</td><td>' . _('Warnings'). '</td><td>' . _('Errors') . '</td></tr>'; else return true;
for ($row=0; $row<sizeof($_SESSION['accounts']); $row++) { // loops for every row
echo '<tr><td>'.$row.'</td><td>'.
$_SESSION['accounts'][$row]->general_surname.'</td><td>'.
$_SESSION['accounts'][$row]->general_givenname.'</td><td>'.
$_SESSION['accounts'][$row]->general_username.'</td><td>'.
$_SESSION['accounts'][$row]->general_group.'</td><td>'.
'<a target=_blank href="massdetail.php?row='.$row.'&type=detail">'._('Show Details.').'</a></td><td>';
for ($i=$row+1; $i<sizeof($_SESSION['accounts']); $i++ ) {
if ($_SESSION['accounts'][$row]->general_username == $_SESSION['accounts'][$i]->general_username) { // Found user with same name
// Set Info
$_SESSION['errors'][$i][] = array('INFO', _('Warning'), _('Username in use. Selected next free username'));
// get last character of username
$lastchar = substr($_SESSION['accounts'][$i]->general_username, strlen($_SESSION['accounts'][$i]->general_username)-1, 1);
// Last character is no number
if ( !ereg('^([0-9])+$', $lastchar))
$_SESSION['accounts'][$i]->general_username = $_SESSION['accounts'][$i]->general_username . '2';
else {
$j=strlen($_SESSION['accounts'][$i]->general_username)-1;
$mark = false;
while (!$mark) {
if (ereg('^([0-9])+$',substr($_SESSION['accounts'][$i]->general_username, $j, strlen($_SESSION['accounts'][$i]->general_username)-$j))) $j--;
else $mark=true;
}
// increase last number with one
$firstchars = substr($_SESSION['accounts'][$i]->general_username, 0, $j+1);
$lastchars = substr($_SESSION['accounts'][$i]->general_username, $j+1, strlen($_SESSION['accounts'][$i]->general_username)-$j);
$_SESSION['accounts'][$i]->general_username = $firstchars . (intval($lastchars)+1);
}
while ($temp = ldapexists($_SESSION['accounts'][$i], 'user')) {
// get last character of username
$lastchar = substr($_SESSION['accounts'][$i]->general_username, strlen($_SESSION['accounts'][$i]->general_username)-1, 1);
// Last character is no number
if ( !ereg('^([0-9])+$', $lastchar))
$_SESSION['accounts'][$i]->general_username = $_SESSION['accounts'][$i]->general_username . '2';
else {
$j=strlen($_SESSION['accounts'][$i]->general_username)-1;
$mark = false;
while (!$mark) {
if (ereg('^([0-9])+$',substr($_SESSION['accounts'][$i]->general_username, $j, strlen($_SESSION['accounts'][$i]->general_username)-$j))) $i--;
else $mark=true;
}
// increase last number with one
$firstchars = substr($_SESSION['accounts'][$i]->general_username, 0, $j+1);
$lastchars = substr($_SESSION['accounts'][$i]->general_username, $j+1, strlen($_SESSION['accounts'][$i]->general_username)-$j);
$_SESSION['accounts'][$i]->general_username = $firstchars . (intval($lastchars)+1);
}
}
}
}
if ($values->general_username != $return->general_username) $errors[] = array('WARN', _('Username'), _('Username in use. Selected next free username.'));
$found=false;
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'INFO') $found=true;
if ($found) echo '<a target="massdetail" href="massdetail.php?row='.$row.'&type=warn">'._('Show Warnings.').'</a>';
echo '</td><td>';
$found=false;
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'ERROR') $found=true;
if ($found) echo '<a target="massdetail" href="massdetail.php?row='.$row.'&type=error">'._('Show Errors.').'</a>';
echo '</td></tr>';
}
$noerrors=true;
for ($i=0; $i<sizeof($_SESSION['errors']); $i++)
for ($j=0; $j<sizeof($_SESSION['errors'][$i]); $j++)
if ($_SESSION['errors'][$i][$j][0] == 'ERROR') $noerrors=false;
$nowarn=true;
for ($i=0; $i<sizeof($_SESSION['errors']); $i++)
for ($j=0; $j<sizeof($_SESSION['errors'][$i]); $j++)
if ($_SESSION['errors'][$i][$j][0] == 'INFO') $nowarn=false;
echo '<br>';
if (!$noerrors) { echo '<tr><td>'. _('There are some errors.') . '</td></tr>'; }
if (!$nowarn) { echo '<tr><td>'. _('There are some warnings.') . '</td></tr>'; }
echo '</table><br><table class="masscreate" width="100%">'.
'<tr><td><input name="back" type="submit" value="'; echo _('Back'); echo '">';
echo '</td><td><input name="cancel" type="submit" value="'; echo _('Cancel'); echo '">';
echo '</td><td><input name="list" type="submit" value="'; echo _('Refresh'); echo '">';
if ($noerrors) { echo '</td><td><input name="create" type="submit" value="'; echo _('Create'); echo '">'; }
echo '</td></tr>';
break;
case 'create':
$stay=true;
while (($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) && $stay) {
if (getgid($_SESSION['accounts'][$_SESSION['pointer']]->general_group)==-1) {
$group = new account();
$group->general_username=$_SESSION['accounts'][$_SESSION['pointer']]->general_group;
$group->general_uidNumber=checkid($_SESSION['accounts'][$_SESSION['pointer']], 'group');
$group->general_gecos=$_SESSION['accounts'][$_SESSION['pointer']]->general_group;
creategroup($group);
}
$_SESSION['accounts'][$_SESSION['pointer']]->general_uidNumber = checkid($_SESSION['accounts'][$_SESSION['pointer']], 'user');
$iv = base64_decode($_COOKIE["IV"]);
$key = base64_decode($_COOKIE["Key"]);
$_SESSION['accounts'][$_SESSION['pointer']]->unix_password = base64_encode(mcrypt_encrypt(
MCRYPT_RIJNDAEL_256, $key, genpasswd(), MCRYPT_MODE_ECB, $iv));
$_SESSION['accounts'][$_SESSION['pointer']]->smb_password = $_SESSION['accounts'][$_SESSION['pointer']]->unix_password;
if ( (time()-$time)<(get_cfg_var('max_execution_time')-10)) {
$error = createuser($_SESSION['accounts'][$_SESSION['pointer']]);
if ($error==1) $_SESSION['pointer']++;
else {
$stay = false;
StatusMessage('ERROR', _('Could not create user!'), sprintf (_('Was unable to create %s.'), $_SESSION['accounts'][$row]->general_username));
}
}
else $stay=false;
}
if (!$stay) { echo '<tr><td><input name="cancel" type="submit" value="'; echo _('Cancel'); echo '">'.
'<td>'._('Please wait until all users are created if no error is shown.').'</td></tr>'; }
else {
echo '<tr><td>';
echo _('All Users have been created');
echo '</td></tr><tr><td>';
echo '<tr><td><input name="cancel" type="submit" value="'; echo _('User list'); echo '">';
echo '</td><td></td><td><input name="pdf" type="submit" value="'; echo _('Create PDF file'); echo '">';
echo '</td></tr>';
if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']);
if ( isset($_SESSION['errors'])) unset($_SESSION['errors']);
}
break;
} }
if ($select!='pdf') echo '</table></form></body></html>';
?> ?>

View File

@ -87,11 +87,16 @@ switch ($select) {
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 'warn': 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':
for ($i=0; $i<sizeof($_SESSION['errors'][$row]); $i++)
if ($_SESSION['errors'][$row][$i][0] == 'WARN')
StatusMessage('WARN', _('Check values.'), $_SESSION['errors'][$row][$i][2]);
break;
case 'detail': case 'detail':
echo '<tr><td>'; echo '<tr><td>';
echo _('Surname').'*'; echo _('Surname').'*';