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']); $select='pdf'; } } if ($select!='pdf') { switch ($select) { case 'cancel' : // go back to user list page metaRefresh($_SESSION['lamurl']."templates/lists/listusers.php"); die; break; case 'list' : // refreh to masscreate if (!is_array($accounts)) $accounts = array(); $groups = array(); if (loadfile()) { $_SESSION['group_suffix'] = $_POST['f_group_suffix']; $_SESSION['group_selectprofile'] = $_POST['f_selectgroupprofile']; metaRefresh($_SESSION['lamurl']."templates/masscreate.php?list2"); die; } else { echo $_SESSION['header']; echo ''; echo _('Create new Accounts'); echo ''."\n". ''."\n". ''."\n". ''."\n"; echo ''."\n". '
'."\n". ''. ''."\n"; echo '
'; echo _('Max 400 users allowed. Ignored additional users.'); echo '
'; echo _('Cancel'); echo ''; echo _('Contiune'); echo "
\n"; } break; } // Write HTML-Header and part of Table echo $_SESSION['header']; echo ''; echo _('Create new Accounts'); echo ''."\n". ''."\n". ''."\n". ''."\n"; switch ($select) { case 'create': if ($_SESSION['pointer'] < sizeof($_SESSION['accounts'])) { $refresh = get_cfg_var('max_execution_time')-5; echo ''."\n"; } echo ''."\n". ''."\n". "
"; echo _('Creating users. Please stand by ....'); echo "\n\n"; $stay=true; 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) { $group = LoadGroupProfile($_SESSION['group_selectprofile']); $group->type = 'group'; // load quotas from profile and check if they are valid $values = getquotas('group'); if (isset($group->quota[0])) { // check quotas from profile $i=0; // check quota settings while (isset($group->quota[$i])) { $found = (-1); for ($j=0; $jquota); $j++) if ($values->quota[$j][0]==$group->quota[$i][0]) $found = $j; if ($found==-1) unset($group->quota[$i]); else { $group->quota[$i][1] = $values->quota[$found][1]; $group->quota[$i][5] = $values->quota[$found][5]; $group->quota[$i][4] = $values->quota[$found][4]; $group->quota[$i][8] = $values->quota[$found][8]; $i++; } } $group->quota = array_values($group->quota); } else { // No quotas saved in profile if (is_object($values)) { while (list($key, $val) = each($values)) // Set only defined values if (isset($val)) $group->$key = $val; } } $group->general_username=$_SESSION['accounts'][$_SESSION['pointer']]->general_group; $temp = explode(':', checkid($_SESSION['accounts'][$_SESSION['pointer']])); $_SESSION['accounts'][$_SESSION['pointer']]->general_uidNumber = $temp[0]; $group->general_gecos=$_SESSION['accounts'][$_SESSION['pointer']]->general_group; $group->general_dn=$_SESSION['group_suffix']; $error = creategroup($group); if ($error==1) { $_SESSION['pointer']++; echo ''."\n"; } else { $stay = false; StatusMessage('ERROR', _('Could not create group!'), sprintf (_('Was unable to create %s.'), $_SESSION['accounts'][$row]->general_group)); } } $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']]->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 ''."\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 ''."\n"; echo '
'; sprintf (_('Created group %s.'), $_SESSION['accounts'][$_SESSION['pointer']]->general_group); echo '
'; sprintf (_('Created user %s.'), $_SESSION['accounts'][$_SESSION['pointer']]->general_username); echo '
'; echo _('Please press here if meta-refresh didn\'t work.'); echo '
'; echo "
\n"; } else { echo ''; echo _('All Users have been created'); echo ''."\n".''; echo ''; echo ''; echo ''."\n\n"; 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']); } break; case 'list2': echo ''."\n". ''."\n". ''; for ($i=0; $igeneral_group!='') StatusMessage('INFO', _('Group').' '. $_SESSION['accounts'][$i]->general_group.' '._('not found!'), _('It will be created.')); echo "
\n"; echo "
"; echo _('Confirm List'); echo "\n\n"; echo ''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n"; $end = sizeof($_SESSION['accounts']); for ($row=0; $row<$end; $row++) { // loops for every row echo ''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n"; } $noerrors=true; for ($i=0; $i'; if (!$noerrors) { echo ''."\n"; } if (!$nowarn) { echo ''."\n"; } echo '
'._('row').''. _('Surname'). ''. _('Given name'). ''. _('User name'). ''. _('Primary group'). ''. _('Details'). '' . _('Infos'). '' . _('Warnings'). '' . _('Errors') . '
'.$row.''. $_SESSION['accounts'][$row]->general_surname.''. $_SESSION['accounts'][$row]->general_givenname.''. $_SESSION['accounts'][$row]->general_username.''. $_SESSION['accounts'][$row]->general_group.''. ''._('Show Details.').''; $found=false; for ($i=0; $i'._('Show Infos.').''; echo ''; $found=false; for ($i=0; $i'._('Show Warnings.').''; echo ''; $found=false; for ($i=0; $i'._('Show Errors.').''; echo '
'. _('There are some errors.') . '
'. _('There are some warnings.') . '
'; echo "
"; echo _('Please select page'); echo "\n\n". ''."\n"."
'; if ($noerrors) { echo ''; } echo '
\n
"; break; case 'main': 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']); $_SESSION['pointer']=0; echo ''."\n". ''."\n". "
"; echo _('Mass Creation'); echo "\n\n\n
"; echo _('Please provide a csv-file with the following syntax. Values with * are required:'); echo '
'. ''. ''."\n".''."\n".'\n'."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".'
'."\n"; echo _('Surname').'*,'; echo ''; echo _('Given name').'*,'; echo ''; echo _('Username').'*,'; echo ""; echo _('Primary group').','; echo ''; echo _('Title').','; echo ''; echo _('eMail address').','; echo ''; echo _('Telephone number').','; echo '
'; echo _('Mobile number').','; echo ''; echo _('Fax number').','; echo ''; echo _('Street').','; echo ''; echo _('Postal code').','; echo ''; echo _('Postal address').','; echo ''; echo _('Employee type'); echo '<CR>'; echo '
'; echo "
"; echo _('If Primary group is not given it\'ll used from profile.'); echo "
"; echo _('If Primary group does not exist it will be created.'); echo "
\n"; echo "
"; echo _('Select settings'); echo "\n". '\n\n\n'."\n".''."\n".'\n\n\n'."\n".'\n\n\n'."\n". ''."\n"."
'."\n"; echo _('Select user profile:'); echo ''; echo ""; echo _('Help')."
"; echo _('User suffix'); echo ''._('Help').''. '
'."\n"; echo _("Expand suffix with primary groupname"); echo ''; echo ""; echo _('Help')."
"; echo _('Group suffix'); echo ''._('Help').''. '
'."\n"; echo _('Select group profile'); echo ''; echo ""; echo _('Help')."
"; echo ''; echo _('Select file:'); echo '
'."\n". '
\n
\n"; break; } echo '
'; } function loadfile() { if ($_FILES['userfile']['size']>0) { $OUs = array(); $handle = fopen($_FILES['userfile']['tmp_name'], 'r'); $profile = loadUserProfile($_POST['f_selectprofile']) ; $profile->type = 'user'; $profile->smb_flagsW = 0; // load quotas from profile and check if they are valid $values = getquotas('user'); if (isset($profile->quota[0])) { // check quotas from profile $i=0; // check quota settings while (isset($profile->quota[$i])) { $found = (-1); for ($j=0; $jquota); $j++) if ($values->quota[$j][0]==$profile->quota[$i][0]) $found = $j; if ($found==-1) unset($profile->quota[$i]); else { $profile->quota[$i][1] = $values->quota[$found][1]; $profile->quota[$i][5] = $values->quota[$found][5]; $profile->quota[$i][4] = $values->quota[$found][4]; $profile->quota[$i][8] = $values->quota[$found][8]; $i++; } } $profile->quota = array_values($profile->quota); } else { // No quotas saved in profile 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 $iv = base64_decode($_COOKIE["IV"]); $key = base64_decode($_COOKIE["Key"]); $_SESSION['accounts'][$row] = $profile; $_SESSION['accounts'][$row]->type = 'user'; 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]; if (isset($line_array[3])) $_SESSION['accounts'][$row]->general_group = $line_array[3]; if (isset($line_array[4])) $_SESSION['accounts'][$row]->personal_title = $line_array[4]; if (isset($line_array[5])) $_SESSION['accounts'][$row]->personal_mail = $line_array[5]; if (isset($line_array[6])) $_SESSION['accounts'][$row]->personal_telephoneNumber = $line_array[6]; if (isset($line_array[7])) $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $line_array[7]; if (isset($line_array[8])) $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $line_array[8]; if (isset($line_array[9])) $_SESSION['accounts'][$row]->personal_street = $line_array[9]; 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']) { $_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)) { $attr['objectClass']= 'organizationalUnit'; $attr['ou'] = $_SESSION['accounts'][$row]->general_group; $success = @ldap_add($_SESSION['ldap']->server(), $_SESSION['accounts'][$row]->general_dn, $attr); if ($success) $OUs[] = $_SESSION['accounts'][$row]->general_group; } } else $_SESSION['accounts'][$row]->general_dn = $_POST['f_general_suffix']; $_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 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; $row2general_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])) { // 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)) $_SESSION['accounts'][$row2]->general_username = $_SESSION['accounts'][$row2]->general_username . '2'; else { $i=strlen($_SESSION['accounts'][$row2]->general_username)-1; $mark = false; while (!$mark) { 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'][$row2]->general_username, 0, $i+1); $lastchars = substr($_SESSION['accounts'][$row2]->general_username, $i+1, strlen($_SESSION['accounts'][$row2]->general_username)-$i); $_SESSION['accounts'][$row2]->general_username = $firstchars . (intval($lastchars)+1); } } // 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.')); // 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); } } if ($_FILES['userfile']['size']>0) { fclose($handle); unlink($_FILES['userfile']['tmp_name']); } if ($row2>400) return false; else return true; } ?>