checked mass*.php and removed some bugs.

Sometimes I had some errors while creating users
Maybe I can reproduce this.
This commit is contained in:
katagia 2003-10-22 13:57:32 +00:00
parent 8eb39ade02
commit 1652cbd62a
4 changed files with 566 additions and 476 deletions

View File

@ -533,11 +533,7 @@ function getgrnam($gidNumber) {
while (!isset($return) && isset($_SESSION['groupDN'][$groupDN_local[$i]]['uidNumber'])) {
if ($_SESSION['groupDN'][$groupDN_local[$i]]['uidNumber'] == $gidNumber) {
// We've found the correct entry. Now we need the groupname
// Get end position (',')
$end = strpos($groupDN_local[$i], ',');
// start position is allways 3 (cn=...)
// Get groupname from dn
$return = substr($groupDN_local[$i], 3, $end-3);
$return = $_SESSION['groupDN'][$groupDN_local[$i]]['cn'];
}
// Increase loop-variable if entry wasn't found
else $i++;
@ -703,7 +699,7 @@ function loaduser($dn) {
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
// Set user samba flag
$account_new->smb_flagsW = 0;
$account_new->smb_flagsW = false;
/* Write attributes into $return.
* Some values don't have to be set. These are only loaded if they are set
*/
@ -794,11 +790,11 @@ function loaduser($dn) {
if (isset($attr['sambaDomainName'][0])) $return->smb_domain = $attr['sambaDomainName'][0];
if (isset($attr['sambaNTPassword'][0])) $return->smb_password = $attr['sambaNTPassword'][0];
if (isset($attr['sambaDomainName'][0])) {
if ($_SESSION['config']->samba3=='yes') {
if ($_SESSION['config']->is_samba3()) {
// store smb_domain as samba3domain-Object
$samba3domains = $_SESSION['ldap']->search_domains($_SESSION[config]->get_domainSuffix());
$i=0;
while (!isset($return->smb_domain) && (count($samba3domains)-1<$i)) {
while (!isset($return->smb_domain) && (count($samba3domains)>$i)) {
if ($attr['sambaDomainName'][0] == $samba3domains[$i]->name)
$return->smb_domain = $samba3domains[$i];
else $i++;
@ -808,7 +804,7 @@ function loaduser($dn) {
if (!isset($return->smb_domain)) $return->smb_domain = $attr['sambaDomainName'];
}
if (isset($attr['sambaPrimaryGroupSID'][0])) {
if ($_SESSION['config']->samba3=='yes')
if ($_SESSION['config']->is_samba3())
// store "real" SID if we want to save user as samba3 entry
$return->smb_mapgroup = $attr['sambaPrimaryGroupSID'][0];
// store "calculated" id if we want to save user as samba2.2 entry
@ -835,11 +831,11 @@ function loaduser($dn) {
if (isset($attr['profilePath'][0])) $return->smb_profilePath = $attr['profilePath'][0];
if (isset($attr['userWorkstations'][0])) $return->smb_smbuserworkstations = $attr['userWorkstations'][0];
if (isset($attr['domain'][0])) {
if ($_SESSION['config']->samba3=='yes') {
if ($_SESSION['config']->is_samba3()) {
// store smb_domain as samba3domain-Object
$samba3domains = $_SESSION['ldap']->search_domains($_SESSION[config]->get_domainSuffix());
$i=0;
while (!isset($return->smb_domain) && (count($samba3domains)-1<$i)) {
while (!isset($return->smb_domain) && (count($samba3domains)>$i)) {
if ($attr['domain'][0] == $samba3domains[$i]->name)
$return->smb_domain = $samba3domains[$i];
else $i++;
@ -849,7 +845,7 @@ function loaduser($dn) {
if (!isset($return->smb_domain)) $return->smb_domain = $attr['domain'];
}
if (isset($attr['primaryGroupID'][0])) {
if ($_SESSION['config']->samba3=='yes')
if ($_SESSION['config']->is_samba3())
// store "real" SID if we want to save user as samba3 entry
$return->smb_mapgroup = $return->smb_domain->SID. '-' . (2*$attr['primaryGroupID'][0]+1);
// store "calculated" id if we want to save user as samba2.2 entry
@ -877,8 +873,8 @@ function loadhost($dn) {
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
// Set host samba flags
$return->smb_flagsW = 1;
$return->smb_flagsX = 1;
$return->smb_flagsW = true;
$return->smb_flagsX = true;
// load objectclasses
$i=0;
while (isset($attr['objectClass'][$i])) {
@ -906,11 +902,11 @@ function loadhost($dn) {
// Because the "D"-Flag is ignored for hosts it has been removed
}
if (isset($attr['sambaDomainName'][0])) {
if ($_SESSION['config']->samba3=='yes') {
if ($_SESSION['config']->is_samba3()) {
// store smb_domain as samba3domain-Object
$samba3domains = $_SESSION['ldap']->search_domains($_SESSION[config]->get_domainSuffix());
$i=0;
while (!isset($return->smb_domain) && (count($samba3domains)-1<$i)) {
while (!isset($return->smb_domain) && (count($samba3domains)>$i)) {
if ($attr['sambaDomainName'][0] == $samba3domains[$i]->name)
$return->smb_domain = $samba3domains[$i];
else $i++;
@ -920,7 +916,7 @@ function loadhost($dn) {
if (!isset($return->smb_domain)) $return->smb_domain = $attr['sambaDomainName'];
}
if (isset($attr['sambaPrimaryGroupSID'][0])) {
if ($_SESSION['config']->samba3=='yes')
if ($_SESSION['config']->is_samba3())
// store "real" SID if we want to save user as samba3 entry
$return->smb_mapgroup = $attr['sambaPrimaryGroupSID'][0];
// store "calculated" id if we want to save user as samba2.2 entry
@ -939,11 +935,11 @@ function loadhost($dn) {
// Because the "D"-Flag is ignored for hosts it has been removed
}
if (isset($attr['domain'][0])) {
if ($_SESSION['config']->samba3=='yes') {
if ($_SESSION['config']->is_samba3()) {
// store smb_domain as samba3domain-Object
$samba3domains = $_SESSION['ldap']->search_domains($_SESSION[config]->get_domainSuffix());
$i=0;
while (!isset($return->smb_domain) && (count($samba3domains)-1<$i)) {
while (!isset($return->smb_domain) && (count($samba3domains)>$i)) {
if ($attr['domain'][0] == $samba3domains[$i]->name)
$return->smb_domain = $samba3domains[$i];
else $i++;
@ -953,7 +949,7 @@ function loadhost($dn) {
if (!isset($return->smb_domain)) $return->smb_domain = $attr['domain'];
}
if (isset($attr['primaryGroupID'][0])) {
if ($_SESSION['config']->samba3=='yes')
if ($_SESSION['config']->is_samba3())
// store "real" SID if we want to save user as samba3 entry
$return->smb_mapgroup = $return->smb_domain->SID. '-' . (2*$attr['primaryGroupID'][0]+1);
// store "calculated" id if we want to save user as samba2.2 entry
@ -1009,7 +1005,7 @@ function loadgroup($dn) {
$SID = $temp[0].'-'.$temp[1].'-'.$temp[2].'-'.$temp[3].'-'.$temp[4].'-'.$temp[5].'-'.$temp[6];
$samba3domains = $_SESSION['ldap']->search_domains($_SESSION[config]->get_domainSuffix());
$i=0;
while (!isset($return->smb_domain) && (count($samba3domains)-1<$i)) {
while (!isset($return->smb_domain) && (count($samba3domains)>$i)) {
if ($SID == $samba3domains[$i]->SID)
$return->smb_domain = $samba3domains[$i];
else $i++;
@ -1054,7 +1050,7 @@ function createuser($values) {
$attr['givenName'] = utf8_encode($values->general_givenname);
$attr['sn'] = utf8_encode($values->general_surname);
// values stored in shadowExpire, days since 1.1.1970
$attr['shadowExpire'] = $values->unix_pwdexpire / 86400 ;
if (isset($values->unix_pwdexpire)) $attr['shadowExpire'] = intval($values->unix_pwdexpire / 86400) ;
/* Write unix attributes into $attr array
* Some values don't have to be set. These are only loaded if they are set
@ -1969,7 +1965,8 @@ function creategroup($values) {
*/
if ($values->general_gecos) $attr['description'] = utf8_encode($values->general_gecos);
// Samba 3 attributes
if ($_SESSION['config']->samba3 =='yes') {
// $values->smb_mapgroup is not set if creategroup is called from masscreate.php
if ($_SESSION['config']->is_samba3() && isset($values->smb_mapgroup)) {
$attr['sambaSID'] = $values->smb_mapgroup;
$attr['objectClass'][1] = 'sambaGroupMapping';
$attr['sambaGroupType'] = '2';
@ -2027,7 +2024,7 @@ function modifygroup($values,$values_old) {
if ($values->smb_displayName != $values_old->smb_displayName)
$attr['displayName'] = utf8_encode($values->smb_displayName);
// Samba 3.0 attributes
if ($_SESSION['config']->samba3 =='yes') {
if ($_SESSION['config']->is_samba3()) {
if ($values->smb_mapgroup != $values_old->smb_mapgroup)
$attr['sambaSID'] = $values->smb_mapgroup;
}

View File

@ -226,6 +226,7 @@ switch ($_POST['select']) {
if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $account_new->general_username))
$errors[] = array('ERROR', _('Username'), _('Username contains invalid characters. Valid characters are: a-z, 0-9 and .-_ !'));
// Check if user already exists
// Remove primary group from additional groups if set.
if (isset($account_new->general_groupadd) && in_array($account_new->general_group, $account_new->general_groupadd)) {
for ($i=0; $i<count($account_new->general_groupadd); $i++ )
if ($account_new->general_groupadd[$i] == $account_new->general_group) {
@ -1251,7 +1252,7 @@ switch ($select_local) {
echo _('Windows groupname');
echo '</td>'."\n".'<td><select name="f_smb_mapgroup" >';
// Display if group SID should be mapped to a well kown SID
if ($config_intern->samba3=='yes') {
if ($config_intern->is_samba3()) {
if ( $account_new->smb_mapgroup == $account_new->smb_domain->SID . "-".
(2 * getgid($account_new->general_group) + $values->smb_domain->RIDbase+1)) {
echo '<option selected> ';

View File

@ -23,6 +23,7 @@ $Id$
LDAP Account Manager displays table for creating or modifying accounts in LDAP
*/
// include all needed files
include_once('../lib/account.inc'); // File with custom functions
include_once('../lib/config.inc'); // File with configure-functions
include_once('../lib/ldap.inc'); // LDAP-functions
@ -30,52 +31,81 @@ include_once('../lib/profiles.inc'); // functions to load and save profiles
include_once('../lib/status.inc'); // Return error-message
include_once('../lib/pdf.inc'); // Return a pdf-file
// Start Session
session_save_path('../sess');
@session_start();
// Set correct language, codepages, ....
setlanguage();
/* Save current time in $time. We need $time to check out how
* long masscreate.php is running. To avoid max. execution time
* set in php.ini masscreate.php will create a redirect to
* itself.
*/
$time=time();
/* Startcondition massdetail.php was called from outside or
* from masscreate.php itself via meta refresh
*/
if (count($_POST)==0) {
// Go to page which shows all users
if (isset($_GET['list2'])) $select = 'list2';
// (Continue) to create users
else if (isset($_GET['create'])) $select='create';
// Display mainpage if nothing else should be displayed
else $select='main';
}
else {
/* Check loaded attributed in $_SESSION['accounts'] if file was loaded and
* filesize is bigger as 0.
*/
if ($_POST['tolist'] && ($_FILES['userfile']['size']>0)) $select = 'list';
// Go the corresponding page if button was pressed
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']) {
// Create PDF-File
createUserPDF($_SESSION['accounts']);
$select='pdf';
// Stop script
die;
}
}
if ($select!='pdf') {
switch ($select) {
case 'cancel' : // go back to user list page
/* Select which part of page should be loaded
* cacnel = Go back to listusers.php
* list = Load csv-file. Refresh to list2
*/
case 'cancel' :
// go back to user list page
metaRefresh($_SESSION['lamurl']."templates/lists/listusers.php");
// Stop script
die;
break;
case 'list' : // refreh to masscreate
if (!is_array($accounts)) $accounts = array();
$groups = array();
case 'list' :
if (loadfile()) {
// Do Refresh to masscreate.php itself if csv-file was loaded successfully
$_SESSION['group_suffix'] = $_POST['f_group_suffix'];
$_SESSION['group_selectprofile'] = $_POST['f_selectgroupprofile'];
metaRefresh($_SESSION['lamurl']."templates/masscreate.php?list2");
// Stop script
die;
}
else {
/* Loadfile has returned an error because masscreate.php can only
* handle max 400 new users.
* lam will show an error-page with a notice everything after line
* 400 in csv-file will be ignored
*/
echo $_SESSION['header'];
echo '<html><head><title>';
echo _('Create new Accounts');
echo '</title>'."\n".
'<link rel="stylesheet" type="text/css" href="'.$_SESSION['lamurl'].'style/layout.css">'."\n".
'<link rel="stylesheet" type="text/css" href="../style/layout.css">'."\n".
'<meta http-equiv="pragma" content="no-cache">'."\n".
'<meta http-equiv="cache-control" content="no-cache">'."\n";
echo '</head><body>'."\n".
'<meta http-equiv="cache-control" content="no-cache">'."\n".
'</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
'<table class="masscreate" width="100%">'.
'<tr><td>';
@ -86,11 +116,13 @@ if ($select!='pdf') {
echo '</a></td><td><a href="masscreate.php?list2">';
echo _('Contiune');
echo "</a></td></tr></table>\n";
// Stop script
die;
}
break;
}
// Write HTML-Header and part of Table
// Write HTML-Header
echo $_SESSION['header'];
echo '<html><head><title>';
echo _('Create new Accounts');
@ -98,55 +130,56 @@ if ($select!='pdf') {
'<link rel="stylesheet" type="text/css" href="'.$_SESSION['lamurl'].'style/layout.css">'."\n".
'<meta http-equiv="pragma" content="no-cache">'."\n".
'<meta http-equiv="cache-control" content="no-cache">'."\n";
switch ($select) {
/* Select which part of page should be loaded
* create = Create new users
* list2 = Show page with all users who should be created.
* main = Show startpegae where settings and file can be selected
*/
case 'create':
/* Set Metarefresh to max_execution_time - 5sec
* 5 sec. should be enough to create the current
* user
*/
if ($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) {
$refresh = get_cfg_var('max_execution_time')-5;
echo '<meta http-equiv="refresh" content="'.$refresh.'; URL=masscreate.php?create">'."\n";
}
// Display start of body
echo '</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
"<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Creating users. Please stand by ....');
echo "</b></legend>\n<table border=0 width=\"100%\">\n";
// Keys needed to encrypt passwords from session
$iv = base64_decode($_COOKIE["IV"]);
$key = base64_decode($_COOKIE["Key"]);
$stay=true;
// Stay in loop as long there are still users to create and no error did ocour
while (($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) && $stay) {
if ($_SESSION['accounts'][$_SESSION['pointer']]->general_username!='') {
// Check if Homedir is valid
$_SESSION['accounts'][$_SESSION['pointer']]->general_homedir = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir);
if ($_SESSION['accounts'][$_SESSION['pointer']]->general_username != '')
$_SESSION['accounts'][$_SESSION['pointer']]->general_homedir = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir);
// Set uid number
$temp = explode(':', checkid($_SESSION['accounts'][$_SESSION['pointer']]));
$_SESSION['accounts'][$_SESSION['pointer']]->general_uidNumber = $temp[0];
$_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome);
if (getgid($_SESSION['accounts'][$_SESSION['pointer']]->general_group)==-1) {
// Create group if it doesn't exist yet
$group = LoadGroupProfile($_SESSION['group_selectprofile']);
$group->type = 'group';
// load quotas from profile and check if they are valid
if ($config_intern->scriptServer) {
// load quotas and check if quotas from profile are valid
$values = getquotas('group');
if (isset($group->quota[0])) { // check quotas from profile
if (isset($$group->quota[0])) {
// check quotas from profile
$i=0;
// check quota settings
while (isset($group->quota[$i])) {
// check quota settings, loop for every partition with quotas
while (isset($$group->quota[$i])) {
// search if quotas from profile fit to a real quota
$found = (-1);
for ($j=0; $j<count($values->quota); $j++)
if ($values->quota[$j][0]==$group->quota[$i][0]) $found = $j;
// unset quota from profile if quotas (mointpoint) doesn't exists anymore
if ($found==-1) unset($group->quota[$i]);
else {
// Set missing part in quota-array
$group->quota[$i][1] = $values->quota[$found][1];
$group->quota[$i][5] = $values->quota[$found][5];
$group->quota[$i][4] = $values->quota[$found][4];
@ -154,24 +187,30 @@ if ($select!='pdf') {
$i++;
}
}
// Beautify array, repair index
$group->quota = array_values($group->quota);
}
else { // No quotas saved in profile
// Display quotas for new users (Quota set to 0)
if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values
if (isset($val)) $group->$key = $val;
}
}
}
// Get groupname from current user
$group->general_username=$_SESSION['accounts'][$_SESSION['pointer']]->general_group;
$temp = explode(':', checkid($_SESSION['accounts'][$_SESSION['pointer']]));
$_SESSION['accounts'][$_SESSION['pointer']]->general_uidNumber = $temp[0];
// gid Number
$temp = explode(':', checkid($group));
$group->general_uidNumber = $temp[0];
// Set Gecos to groupname
$group->general_gecos=$_SESSION['accounts'][$_SESSION['pointer']]->general_group;
// Set DN
$group->general_dn=$_SESSION['group_suffix'];
// Create group
$error = creategroup($group);
// Show success or failure-message about group creation
if ($error==1) {
$_SESSION['pointer']++;
echo '<tr><td>';
sprintf (_('Created group %s.'), $_SESSION['accounts'][$_SESSION['pointer']]->general_group);
echo '</td></tr>'."\n";
@ -181,16 +220,26 @@ if ($select!='pdf') {
StatusMessage('ERROR', _('Could not create group!'), sprintf (_('Was unable to create %s.'), $_SESSION['accounts'][$row]->general_group));
}
}
// Check if Homedir is valid
$_SESSION['accounts'][$_SESSION['pointer']]->general_homedir = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir);
if ($_SESSION['accounts'][$_SESSION['pointer']]->general_username != '')
$_SESSION['accounts'][$_SESSION['pointer']]->general_homedir = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->general_homedir);
// Set uid number
$temp = explode(':', checkid($_SESSION['accounts'][$_SESSION['pointer']]));
$_SESSION['accounts'][$_SESSION['pointer']]->general_uidNumber = $temp[0];
$iv = base64_decode($_COOKIE["IV"]);
$key = base64_decode($_COOKIE["Key"]);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_scriptPath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_profilePath);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome = str_replace('$user', $_SESSION['accounts'][$_SESSION['pointer']]->general_username, $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome);
$_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome = str_replace('$group', $_SESSION['accounts'][$_SESSION['pointer']]->general_group, $_SESSION['accounts'][$_SESSION['pointer']]->smb_smbhome);
$_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;
// Only create user if we have at least 5sec time to create the user
if ( (time()-$time)<(get_cfg_var('max_execution_time')-10)) {
$error = createuser($_SESSION['accounts'][$_SESSION['pointer']]);
// Show error or success message
if ($error==1) {
$_SESSION['pointer']++;
echo '<tr><td>';
@ -202,11 +251,11 @@ if ($select!='pdf') {
StatusMessage('ERROR', _('Could not create user!'), sprintf (_('Was unable to create %s.'), $_SESSION['accounts'][$row]->general_username));
}
}
// End loop if we don't have enough time to create user
else $stay=false;
}
else $_SESSION['pointer']++;
}
if (!$stay) {
// Display rest of meta-refreh page if there are still users to create
echo '<tr><td><a href="masscreate.php?create">';
echo _('Please press here if meta-refresh didn\'t work.');
echo '</a></td></tr>'."\n";
@ -215,12 +264,14 @@ if ($select!='pdf') {
echo "</fieldset>\n";
}
else {
// Show success-page
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></table>'."\n</fieldset>\n";
// unset variables
if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']);
if ( isset($_SESSION['errors'])) unset($_SESSION['errors']);
if ( isset($_SESSION['group_suffix'])) unset($_SESSION['group_suffix']);
@ -228,13 +279,13 @@ if ($select!='pdf') {
}
break;
case 'list2':
// Show table with all users
echo '</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
'<table border=0 width="100%">';
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.'));
StatusMessage('INFO', _('Group').' '. $_SESSION['accounts'][$i]->general_group.' '._('not found!'), _('It will be created.'));
echo "</table>\n";
echo "<fieldset class=\"useredit-bright\"><legend class=\"useredit-bright\"><b>";
echo _('Confirm List');
@ -250,16 +301,19 @@ if ($select!='pdf') {
$_SESSION['accounts'][$row]->general_group.'</td>'."\n".'<td>'.
'<a target=_blank href="massdetail.php?row='.$row.'&amp;type=detail">'._('Show Details.').'</a></td>'."\n".'<td>';
$found=false;
// Show infos
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.'&amp;type=info">'._('Show Infos.').'</a>';
echo '</td>'."\n".'<td>';
$found=false;
// Show warnings
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.'&amp;type=warn">'._('Show Warnings.').'</a>';
echo '</td>'."\n".'<td>';
$found=false;
// Show errors
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.'&amp;type=error">'._('Show Errors.').'</a>';
@ -287,11 +341,13 @@ if ($select!='pdf') {
echo '</td></tr>'."\n"."</table>\n</fieldset>";
break;
case 'main':
// Unset old variables
if ( isset($_SESSION['accounts'])) unset($_SESSION['accounts']);
if ( isset($_SESSION['pointer'])) unset($_SESSION['pointer']);
if ( isset($_SESSION['errors'])) unset($_SESSION['errors']);
if ( isset($_SESSION['group_suffix'])) unset($_SESSION['group_suffix']);
if ( isset($_SESSION['group_selectprofile'])) unset($_SESSION['group_selectprofile']);
// Set pointer to 0, first user
$_SESSION['pointer']=0;
echo '</head><body>'."\n".
'<form enctype="multipart/form-data" action="masscreate.php" method="post">'."\n".
@ -340,11 +396,13 @@ if ($select!='pdf') {
'<tr><td>'."\n";
echo _('Select user profile:');
echo '</td><td><select name="f_selectprofile">'."\n";
// Show list with all user profiles
foreach (getUserProfiles() as $profile) echo '<option>' . $profile;
echo '</select>';
echo "</td>\n<td><a href=\"help.php?HelpNumber=421\" target=\"lamhelp\">";
echo _('Help')."</a></td>\n</tr>\n<tr><td>";
echo _('User suffix'); echo '</td><td><select name="f_general_suffix">';
// Show list with all user suffixes
foreach ($_SESSION['ldap']->search_units($_SESSION['config']->get_UserSuffix()) as $suffix)
echo '<option>' . $suffix. '</option>';
echo '</select></td>'."\n".'<td><a href="help.php?HelpNumber=461" target="lamhelp">'._('Help').'</a>'.
@ -354,12 +412,14 @@ if ($select!='pdf') {
echo "</td>\n<td><a href=\"help.php?HelpNumber=422\" target=\"lamhelp\">";
echo _('Help')."</a></td>\n</tr>\n<tr><td>";
echo _('Group suffix'); echo '</td><td><select name="f_group_suffix">';
// Show list with all group suffixes
foreach ($_SESSION['ldap']->search_units($_SESSION['config']->get_GroupSuffix()) as $suffix)
echo '<option>' . $suffix. '</option>';
echo '</select></td>'."\n".'<td><a href="help.php?HelpNumber=423" target="lamhelp">'._('Help').'</a>'.
'</td></tr><tr><td>'."\n";
echo _('Select group profile');
echo '</td><td><select name="f_selectgroupprofile">'."\n";
// Show list with group profiles
foreach (getGroupProfiles() as $profile) echo '<option>' . $profile;
echo '</select>';
echo "</td>\n<td><a href=\"help.php?HelpNumber=458\" target=\"lamhelp\">";
@ -371,30 +431,42 @@ if ($select!='pdf') {
'</td><td></td></tr>'."\n"."</table>\n</fieldset>\n";
break;
}
echo '</form></body></html>';
}
/* Whis function will load a csv-file and
* load all attributes into $_SESSION['accounts'][$row] which
* is an array of account objects
* The csv file is using the following syntax:
*/
function loadfile() {
if ($_FILES['userfile']['size']>0) {
// Array with all OUs from users
$OUs = array();
// fixme **** load all existing OUs in Array
// open csv-file
$handle = fopen($_FILES['userfile']['tmp_name'], 'r');
// Load profile which should be used for all users
$profile = loadUserProfile($_POST['f_selectprofile']) ;
// Set type to user
$profile->type = 'user';
$profile->smb_flagsW = 0;
// load quotas from profile and check if they are valid
if ($config_intern->scriptServer) {
// load quotas and check if quotas from profile are valid
$values = getquotas('user');
if (isset($profile->quota[0])) { // check quotas from profile
if (isset($profile->quota[0])) {
// check quotas from profile
$i=0;
// check quota settings
// check quota settings, loop for every partition with quotas
while (isset($profile->quota[$i])) {
// search if quotas from profile fit to a real quota
$found = (-1);
for ($j=0; $j<count($values->quota); $j++)
if ($values->quota[$j][0]==$profile->quota[$i][0]) $found = $j;
// unset quota from profile if quotas (mointpoint) doesn't exists anymore
if ($found==-1) unset($profile->quota[$i]);
else {
// Set missing part in quota-array
$profile->quota[$i][1] = $values->quota[$found][1];
$profile->quota[$i][5] = $values->quota[$found][5];
$profile->quota[$i][4] = $values->quota[$found][4];
@ -402,20 +474,25 @@ function loadfile() {
$i++;
}
}
// Beautify array, repair index
$profile->quota = array_values($profile->quota);
}
else { // No quotas saved in profile
// Display quotas for new users (Quota set to 0)
if (is_object($values)) {
while (list($key, $val) = each($values)) // Set only defined values
if (isset($val)) $profile->$key = $val;
}
}
for ($row=0; $line_array=fgetcsv($handle,2048); $row++) { // loops for every row
}
// Get keys to en/decrypt passwords
$iv = base64_decode($_COOKIE["IV"]);
$key = base64_decode($_COOKIE["Key"]);
for ($row=0; $line_array=fgetcsv($handle,2048); $row++) {
// loops for every row
// Set corrent user to profile
$_SESSION['accounts'][$row] = $profile;
$_SESSION['accounts'][$row]->type = 'user';
// Load values from file into array
if (isset($line_array[0])) $_SESSION['accounts'][$row]->general_surname = $line_array[0];
if (isset($line_array[1])) $_SESSION['accounts'][$row]->general_givenname = $line_array[1];
if (isset($line_array[2])) $_SESSION['accounts'][$row]->general_username = $line_array[2];
@ -429,8 +506,8 @@ function loadfile() {
if (isset($line_array[10])) $_SESSION['accounts'][$row]->personal_postalCode = $line_array[10];
if (isset($line_array[11])) $_SESSION['accounts'][$row]->personal_postalAddress = $line_array[11];
if (isset($line_array[12])) $_SESSION['accounts'][$row]->personal_employeeType = $line_array[12];
if ($_POST['f_ou_expand']) {
// Expand DN of user with ou=$group
$_SESSION['accounts'][$row]->general_dn = "ou=".$_SESSION['accounts'][$row]->general_group .','. $_POST['f_general_suffix'];
// Create OUs if needed
if (!in_array($_SESSION['accounts'][$row]->general_group, $OUs)) {
@ -440,82 +517,44 @@ function loadfile() {
if ($success) $OUs[] = $_SESSION['accounts'][$row]->general_group;
}
}
// Set DN without uid=$username
else $_SESSION['accounts'][$row]->general_dn = $_POST['f_general_suffix'];
// Create Random Password
$_SESSION['accounts'][$row]->unix_password = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256,
$key, genpasswd(), MCRYPT_MODE_ECB, $iv));
$_SESSION['accounts'][$row]->smb_password=$_SESSION['accounts'][$row]->unix_password;
}
}
// check if account allready exists
for ($i=0; $i<sizeof($_SESSION['accounts']); $i++) { // loops for every row
while ($temp = ldapexists($_SESSION['accounts'][$i])) {
// 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;
}
}
for ($row2=0; $row2<sizeof($_SESSION['accounts']); $row2++) { // loops for every row
// Check for double entries in $_SESSION['accounts']
// Validate cache-array
ldapreload('user');
// Get List with all existing usernames
foreach ($_SESSION['userDN'] as $user_array) $users[] = $user_array['cn'];
for ($row2=0; $row2<sizeof($_SESSION['accounts']); $row2++) {
/* loops for every user
* Check for double entries in $_SESSION['accounts']
* Stop Execution after line 400 because max executiontime would be to close
*/
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])) {
// 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);
// Check if givenname is valid
if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_SESSION['accounts'][$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['accounts'][$row2]->general_surname)) $errors[] = array('ERROR', _('Surname'), _('Surname contains invalid characters'));
if ( ($_SESSION['accounts'][$row2]->general_gecos=='') || ($_SESSION['accounts'][$row2]->general_gecos==' ')) {
$_SESSION['accounts'][$row2]->general_gecos = $_SESSION['accounts'][$row2]->general_givenname . " " . $_SESSION['accounts'][$row2]->general_surname ;
$errors[] = array('INFO', _('Gecos'), _('Inserted sur- and given name in gecos-field.'));
}
if ($_SESSION['accounts'][$row2]->general_group=='') $errors[] = array('ERROR', _('Primary group'), _('No primary group defined!'));
// Check if Username contains only valid characters
if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $_SESSION['accounts'][$row2]->general_username))
$errors[] = array('ERROR', _('Username'), _('Username contains invalid characters. Valid characters are: a-z, 0-9 and .-_ !'));
// Create automatic useraccount with number if original user already exists
// Reset name to original name if new name is in use
while ($temp = ldapexists($_SESSION['accounts'][$row2])) {
// Set all usernames to unique usernames
while (in_array($_SESSION['accounts'][$row2]->general_username, $users)) {
// get last character of username
$lastchar = substr($_SESSION['accounts'][$row2]->general_username, strlen($_SESSION['accounts'][$row2]->general_username)-1, 1);
// Last character is no number
if ( !ereg('^([0-9])+$', $lastchar))
/* Last character is no number. Therefore we only have to
* add "2" to it.
*/
$_SESSION['accounts'][$row2]->general_username = $_SESSION['accounts'][$row2]->general_username . '2';
else {
/* Last character is a number -> we have to increase the number until we've
* found a groupname with trailing number which is not in use.
*
* $i will show us were we have to split groupname so we get a part
* with the groupname and a part with the trailing number
*/
$i=strlen($_SESSION['accounts'][$row2]->general_username)-1;
$mark = false;
// Set $i to the last character which is a number in $account_new->general_username
while (!$mark) {
if (ereg('^([0-9])+$',substr($_SESSION['accounts'][$row2]->general_username, $i, strlen($_SESSION['accounts'][$row2]->general_username)-$i))) $i--;
else $mark=true;
@ -523,38 +562,49 @@ function loadfile() {
// increase last number with one
$firstchars = substr($_SESSION['accounts'][$row2]->general_username, 0, $i+1);
$lastchars = substr($_SESSION['accounts'][$row2]->general_username, $i+1, strlen($_SESSION['accounts'][$row2]->general_username)-$i);
// Put username together
$_SESSION['accounts'][$row2]->general_username = $firstchars . (intval($lastchars)+1);
}
}
// Add uername to array so it's not used again for another user in masscreate
$users[] = $_SESSION['accounts'][$row2]->general_username;
if ($_SESSION['accounts'][$row2]->general_username != $username) $_SESSION['errors'][$row2][] = array('WARN', _('Username'), _('Username in use. Selected next free username.'));
// Check if givenname is valid
if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_SESSION['accounts'][$row2]->general_givenname)) $_SESSION['errors'][$row2][] = array('ERROR', _('Given name'), _('Given name contains invalid characters'));
// Check if surname is valid
if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_SESSION['accounts'][$row2]->general_surname)) $_SESSION['errors'][$row2][] = array('ERROR', _('Surname'), _('Surname contains invalid characters'));
if ( ($_SESSION['accounts'][$row2]->general_gecos=='') || ($_SESSION['accounts'][$row2]->general_gecos==' ')) {
$_SESSION['accounts'][$row2]->general_gecos = $_SESSION['accounts'][$row2]->general_givenname . " " . $_SESSION['accounts'][$row2]->general_surname ;
$_SESSION['errors'][$row2][] = array('INFO', _('Gecos'), _('Inserted sur- and given name in gecos-field.'));
}
$_SESSION['accounts'][$row2]->smb_displayName = $_SESSION['accounts'][$row2]->general_gecos;
if ($_SESSION['accounts'][$row2]->general_group=='') $_SESSION['errors'][$row2][] = array('ERROR', _('Primary group'), _('No primary group defined!'));
// Check if Username contains only valid characters
if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $_SESSION['accounts'][$row2]->general_username))
$_SESSION['errors'][$row2][] = array('ERROR', _('Username'), _('Username contains invalid characters. Valid characters are: a-z, 0-9 and .-_ !'));
// Check if Name-length is OK. minLength=3, maxLength=20
if ( !ereg('.{3,20}', $_SESSION['accounts'][$row2]->general_username)) $errors[] = array('ERROR', _('Name'), _('Name must contain between 3 and 20 characters.'));
if ( !ereg('.{3,20}', $_SESSION['accounts'][$row2]->general_username)) $_SESSION['errors'][$row2][] = array('ERROR', _('Name'), _('Name must contain between 3 and 20 characters.'));
// Check if Name starts with letter
if ( !ereg('^([a-z]|[A-Z]).*$', $_SESSION['accounts'][$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);
$_SESSION['accounts'][$row2]->smb_displayName = $_SESSION['accounts'][$row2]->general_gecos;
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_telephoneNumber)) $errors[] = array('ERROR', _('Telephone number'), _('Please enter a valid telephone number!'));
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_mobileTelephoneNumber)) $errors[] = array('ERROR', _('Mobile number'), _('Please enter a valid mobile number!'));
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$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['accounts'][$row2]->personal_mail)) $errors[] = array('ERROR', _('eMail address'), _('Please enter a valid eMail address!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_street)) $errors[] = array('ERROR', _('Street'), _('Please enter a valid street name!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_postalAddress)) $errors[] = array('ERROR', _('Postal address'), _('Please enter a valid postal address!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_title)) $errors[] = array('ERROR', _('Title'), _('Please enter a valid title!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_employeeType)) $errors[] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z])*$', $_SESSION['accounts']->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);
$_SESSION['errors'][$row2][] = array('ERROR', _('Name'), _('Name contains invalid characters. First character must be a letter'));
// Personal Settings
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_telephoneNumber)) $_SESSION['errors'][$row2][] = array('ERROR', _('Telephone number'), _('Please enter a valid telephone number!'));
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_mobileTelephoneNumber)) $_SESSION['errors'][$row2][] = array('ERROR', _('Mobile number'), _('Please enter a valid mobile number!'));
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_SESSION['accounts'][$row2]->personal_facsimileTelephoneNumber)) $_SESSION['errors'][$row2][] = 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['accounts'][$row2]->personal_mail)) $_SESSION['errors'][$row2][] = array('ERROR', _('eMail address'), _('Please enter a valid eMail address!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_street)) $_SESSION['errors'][$row2][] = array('ERROR', _('Street'), _('Please enter a valid street name!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_postalAddress)) $_SESSION['errors'][$row2][] = array('ERROR', _('Postal address'), _('Please enter a valid postal address!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_title)) $_SESSION['errors'][$row2][] = array('ERROR', _('Title'), _('Please enter a valid title!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_SESSION['accounts'][$row2]->personal_employeeType)) $_SESSION['errors'][$row2][] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!'));
if ( !ereg('^([0-9]|[A-Z]|[a-z])*$', $_SESSION['accounts']->personal_postalCode)) $_SESSION['errors'][$row2][] = array('ERROR', _('Postal code'), _('Please enter a valid postal code!'));
}
}
// Close file if it was opened
if ($_FILES['userfile']['size']>0) {
fclose($handle);
unlink($_FILES['userfile']['tmp_name']);
}
// Return false if more than 400 users were found
if ($row2>400) return false;
else return true;
}

View File

@ -23,6 +23,7 @@ $Id$
LDAP Account Manager displays table for creating or modifying accounts in LDAP
*/
// include all needed files
include_once('../lib/account.inc'); // File with all account-funtions
include_once('../lib/config.inc'); // File with configure-functions
include_once('../lib/profiles.inc'); // functions to load and save profiles
@ -33,30 +34,49 @@ include_once('../lib/ldap.inc'); // LDAP-functions
// Start Session
session_save_path('../sess');
@session_start();
// Set correct language, codepages, ....
setlanguage();
// Print header and part of body
echo '<html><head><title>';
echo _('Create new accounts');
echo '</title>'.
'<link rel="stylesheet" type="text/css" href="../style/layout.css">'.
'<meta http-equiv="pragma" content="no-cache">'.
'<meta http-equiv="cache-control" content="no-cache">'.
'</head><body>'.
'<form enctype="multipart/form-data" action="massdetail.php" method="post">'.
'<table class="massdetail" width="100%">';
// Startcondition massdetail.php was called from masscreate.php
if (isset($_GET)) {
// $row the the position of the useraccount in an array of account-objects
$row = $_GET['row'];
/* $select chooses which kind of page should be displayed
* detail = Show settings which are individuel for every user. These
* settings can be changed
* info = Show all infos about user
* warn = Show all warning about user
* error = Show all errors about user
*/
$select = $_GET['type'];
// Get Copy of current account so we can undo all settings
if ($select=='detail') $_SESSION['accounts_backup'] = $_SESSION['accounts'][$row];
}
if ($_POST) {
// massdetail.php was called from itself
else if (isset($_POST)) {
// $row the the position of the useraccount in an array of account-objects
$row = $_POST['row'];
/* $select chooses which kind of page should be displayed
* detail = Show settings which are individuel for every user. These
* settings can be changed
* info = Show all infos about user
* warn = Show all warning about user
* error = Show all errors about user
*/
$select = $_POST['type'];
}
// Undo-Button was pressed.
if ($_POST['undo']) {
$_SESSION['accounts'][$row] = $_SESSION['accounts_backup'];
$errors2[] = array('INFO', _('Undo'), _('All changes were reseted'));
$select = 'detail';
}
// Apply-Button was pressed.
if ($_POST['apply']) {
// Show Detail-page
$select = 'detail';
// Check if surname is valid
if ( !ereg('^([a-z]|[A-Z]|[-]|[ ]|[ä]|[Ä]|[ö]|[Ö]|[ü]|[Ü]|[ß])+$', $_POST['f_general_surname'])) $errors2[] = array('ERROR', _('Surname'), _('Surname contains invalid characters'));
else $_SESSION['accounts'][$row]->general_surname = $_POST['f_general_surname'];
@ -69,42 +89,54 @@ if ($_POST['apply']) {
else if ( !ereg('^([a-z]|[A-Z]).*$', $_POST['f_general_username']))
$errors2[] = array('ERROR', _('Name'), _('Name contains invalid characters. First character must be a letter'));
else {
// Create Array with all users in ldap and in array
// Validate cache-array
ldapreload('user');
// Get List with all existing usernames
foreach ($_SESSION['userDN'] as $user_array) $users[] = $user_array['cn'];
// Get List with all users in array
foreach ($_SESSION['accounts'] as $user_array) $users[] = $user_array->general_username;
// unset old username in user-array
$users = @array_flip($users);
unset ($users[$_SESSION['accounts'][$row]->general_username]);
$users = array_flip($users);
// Store new username
$_SESSION['accounts'][$row]->general_username = $_POST['f_general_username'];
// Check if user already exists
if (isset($_SESSION['accounts'][$row]->general_groupadd) && in_array($_SESSION['accounts'][$row]->general_group, $_SESSION['accounts'][$row]->general_groupadd)) {
for ($i=0; $i<count($_SESSION['accounts'][$row]->general_groupadd); $i++ )
if ($_SESSION['accounts'][$row]->general_groupadd[$i] == $_SESSION['accounts'][$row]->general_group) {
unset ($_SESSION['accounts'][$row]->general_groupadd[$i]);
$_SESSION['accounts'][$row]->general_groupadd = array_values($_SESSION['accounts'][$row]->general_groupadd);
}
}
// Create automatic useraccount with number if original user already exists
// Reset name to original name if new name is in use
while ($temp = ldapexists($_SESSION['accounts'][$row])) {
// Set all usernames to unique usernames
while (in_array($_SESSION['accounts'][$row2]->general_username, $users)) {
// get last character of username
$lastchar = substr($_SESSION['accounts'][$row]->general_username, strlen($_SESSION['accounts'][$row]->general_username)-1, 1);
$lastchar = substr($_SESSION['accounts'][$row2]->general_username, strlen($_SESSION['accounts'][$row2]->general_username)-1, 1);
// Last character is no number
if ( !ereg('^([0-9])+$', $lastchar))
$_SESSION['accounts'][$row]->general_username = $_SESSION['accounts'][$row]->general_username . '2';
/* Last character is no number. Therefore we only have to
* add "2" to it.
*/
$_SESSION['accounts'][$row2]->general_username = $_SESSION['accounts'][$row2]->general_username . '2';
else {
$i=strlen($_SESSION['accounts'][$row]->general_username)-1;
/* Last character is a number -> we have to increase the number until we've
* found a groupname with trailing number which is not in use.
*
* $i will show us were we have to split groupname so we get a part
* with the groupname and a part with the trailing number
*/
$i=strlen($_SESSION['accounts'][$row2]->general_username)-1;
$mark = false;
// Set $i to the last character which is a number in $account_new->general_username
while (!$mark) {
if (ereg('^([0-9])+$',substr($_SESSION['accounts'][$row]->general_username, $i, strlen($_SESSION['accounts'][$row]->general_username)-$i))) $i--;
if (ereg('^([0-9])+$',substr($_SESSION['accounts'][$row2]->general_username, $i, strlen($_SESSION['accounts'][$row2]->general_username)-$i))) $i--;
else $mark=true;
}
// increase last number with one
$firstchars = substr($_SESSION['accounts'][$row]->general_username, 0, $i+1);
$lastchars = substr($_SESSION['accounts'][$row]->general_username, $i+1, strlen($_SESSION['accounts'][$row]->general_username)-$i);
$_SESSION['accounts'][$row]->general_username = $firstchars . (intval($lastchars)+1);
$firstchars = substr($_SESSION['accounts'][$row2]->general_username, 0, $i+1);
$lastchars = substr($_SESSION['accounts'][$row2]->general_username, $i+1, strlen($_SESSION['accounts'][$row2]->general_username)-$i);
// Put username together
$_SESSION['accounts'][$row2]->general_username = $firstchars . (intval($lastchars)+1);
}
}
// Show warning if lam has changed username
if ($_SESSION['accounts'][$row2]->general_username != $_POST['f_general_username']) $errors2[] = array('WARN', _('Username'), _('Username in use. Selected next free username.'));
}
// check if group is valid
if ($_POST['f_general_group']!='') $_SESSION['accounts'][$row]->general_group = $_POST['f_general_group'];
else $errors2[] = 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 $errors2[] = array('WARN', _('Primary group'), _('Primary group does not exist. Will create group automaticly.'));
// Check personal settings
if ( !ereg('^([0-9]|[A-Z]|[a-z]|[ ]|[.]|[Ä]|[ä]|[Ö]|[ö]|[Ü]|[ü]|[ß])*$', $_POST['f_personal_title'])) $errors2[] = 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'])) $errors2[] = array('ERROR', _('Employee type'), _('Please enter a valid employee type!'));
@ -119,42 +151,53 @@ if ($_POST['apply']) {
else $_SESSION['accounts'][$row]->personal_telephoneNumber = $_POST['f_personal_telephoneNumber'];
if ( !ereg('^(\+)*([0-9]|[ ]|[.]|[(]|[)]|[/])*$', $_POST['f_personal_mobileTelephoneNumber'])) $errors2[] = 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'])) $errors2[] = 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'])) $errors2[] = array('ERROR', _('eMail address'), _('Please enter a valid eMail address!'));
else $_SESSION['accounts'][$row]->personal_mail = $_POST['f_personal_mail'];
}
// Print header and part of body
echo '<html><head><title>';
echo _('Create new accounts');
echo '</title>'.
'<link rel="stylesheet" type="text/css" href="../style/layout.css">'.
'<meta http-equiv="pragma" content="no-cache">'.
'<meta http-equiv="cache-control" content="no-cache">'.
'</head><body>'.
'<form enctype="multipart/form-data" action="massdetail.php" method="post">'.
'<table class="massdetail" width="100%">';
// Store variabled in $_POST
echo '<tr><td><input name="type" type="hidden" value="'.$select.'"></td></tr>';
echo '<tr><td><input name="row" type="hidden" value="'.$row.'"></td></tr>';
if (is_array($errors2)) {
for ($i=0; $i<sizeof($errors2); $i++) {
StatusMessage($errors2[$i][0], $errors2[$i][1], $errors2[$i][2]);
}
}
// Display errir-messages
if (is_array($errors2))
for ($i=0; $i<sizeof($errors2); $i++) StatusMessage($errors2[$i][0], $errors2[$i][1], $errors2[$i][2]);
switch ($select) {
/* $select chooses which kind of page should be displayed
* detail = Show settings which are individuel for every user. These
* settings can be changed
* info = Show all infos about user
* warn = Show all warning about user
* error = Show all errors about user
*/
case 'error':
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]);
}
break;
case 'info':
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]);
}
break;
case 'warn':
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]);
}
break;
case 'detail':
echo '<tr><td>';
@ -232,10 +275,9 @@ switch ($select) {
'</td></tr><br>';
echo '<tr><td><input name="apply" type="submit" value="'; echo _('Apply'); echo '"></td><td></td><td>';
echo '<input name="undo" type="submit" value="'; echo _('Undo'); echo '"></td></tr>';
break;
}
// Print end of HTML-Page
echo '</table></form></body></html>';
?>