From 7e59efcee846635364cc0feafb30dda2993d6d64 Mon Sep 17 00:00:00 2001 From: katagia Date: Wed, 9 Jul 2003 16:20:34 +0000 Subject: [PATCH] Fixed massupload and made it more useable --- lam/lib/account.inc | 7 +- lam/templates/masscreate.php | 220 +++++++++++++++++++++++------------ lam/templates/massdetail.php | 185 +++++++++++++++++++++++++++++ 3 files changed, 335 insertions(+), 77 deletions(-) create mode 100644 lam/templates/massdetail.php diff --git a/lam/lib/account.inc b/lam/lib/account.inc index db59ffc4..bfc4c785 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -181,6 +181,7 @@ function checkglobal($values, $type, $values_old=false) { // This functions chec $return->general_gecos = $values->general_givenname . " " . $values->general_surname ; $errors[] = array('INFO', _('Gecos'), _('Inserted sur- and givenname in gecos-field.')); } + if ($values->general_group=='') $errors[] = array('ERROR', _('Primary Group'), _('No primary Group defined!')); // Check if Username contents only valid characters if ( !ereg('^([a-z]|[0-9]|[.]|[-]|[_])*$', $values->general_username)) $errors[] = array('ERROR', _('Username'), _('Username contents invalid characters. Valid characters are: a-z, 0-9 and .-_ !')); @@ -290,7 +291,7 @@ function checkglobal($values, $type, $values_old=false) { // This functions chec if ( !ereg('^[a-z].*$', $values->general_username)) $errors[] = array('ERROR', _('Name'), _('Name contents invalid characters. First character must be a letter')); // Return values and errors - if (!$errors) return array($return, ''); + if (!$errors) return array($return); else return array($return, $errors); } @@ -374,7 +375,7 @@ function checksamba($values, $type) { // This function checks all samba account } else $return->smb_password = ""; // Return values and errors - if (!$errors) return array($return, ''); + if (!$errors) return array($return); else return array($return, $errors); } @@ -401,7 +402,7 @@ function checkquota($values) { // This function checks all quota paramters $i++; } // Return values and errors - if (!$errors) return array($return, ''); + if (!$errors) return array($return); else return array($return, $errors); } diff --git a/lam/templates/masscreate.php b/lam/templates/masscreate.php index ff2b011c..7d857bfc 100644 --- a/lam/templates/masscreate.php +++ b/lam/templates/masscreate.php @@ -35,6 +35,7 @@ session_save_path('../sess'); $time=time(); if ($_POST['tolist'] && ($_FILES['userfile']['size']>0)) $select = 'list'; +if ($_POST['list']) $select = 'list'; if ($_POST['back']) $select = 'main'; if ($_POST['cancel']) $select = 'cancel'; if ($_POST['create']) $select = 'create'; @@ -84,8 +85,10 @@ switch ($select) { case 'main': if ( session_is_registered("accounts")) session_unregister("accounts"); if ( session_is_registered("pointer")) session_unregister("pointer"); + if ( session_is_registered("errors")) session_unregister("errors"); session_register("accounts"); session_register("pointer"); + session_register("errors"); $_SESSION['pointer']=0; $profilelist = getUserProfiles(); echo ''; @@ -105,7 +108,18 @@ switch ($select) { echo ''; - echo ' + echo ''."\n".''; + echo _('Suffix'); echo ''._('Help').' + '; echo _('Select file:'); echo ' @@ -114,94 +128,152 @@ switch ($select) { break; case 'list': if (!is_array($accounts)) $accounts = array(); - $handle = fopen($_FILES['userfile']['tmp_name'], 'r'); $groups = array(); echo ''; echo _('Confirm List'); echo ''; - for ($row=0; $line_array=fgetcsv($handle,2048); $row++) { // loops for every row - $_SESSION['accounts'][$row] = loadUserProfile($_POST['f_selectprofile']) ; - if ($line_array[0]) $_SESSION['accounts'][$row]->general_surname = $line_array[0]; - if ($line_array[1]) $_SESSION['accounts'][$row]->general_givenname = $line_array[1]; - if ($line_array[2]) $_SESSION['accounts'][$row]->general_username = $line_array[2]; - if ($line_array[3]) $_SESSION['accounts'][$row]->general_group = $line_array[3]; - if ($line_array[4]) $_SESSION['accounts'][$row]->personal_title = $line_array[4]; - if ($line_array[5]) $_SESSION['accounts'][$row]->personal_mail = $line_array[5]; - if ($line_array[6]) $_SESSION['accounts'][$row]->personal_telephoneNumber = $line_array[6]; - if ($line_array[7]) $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $line_array[7]; - if ($line_array[8]) $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $line_array[8]; - if ($line_array[9]) $_SESSION['accounts'][$row]->personal_street = $line_array[9]; - if ($line_array[10]) $_SESSION['accounts'][$row]->personal_postalCode = $line_array[10]; - if ($line_array[11]) $_SESSION['accounts'][$row]->personal_postalAddress = $line_array[11]; - if ($line_array[12]) $_SESSION['accounts'][$row]->personal_employeeType = $line_array[12]; - $_SESSION['accounts'][$row]->unix_password=genpasswd(); - $_SESSION['accounts'][$row]->smb_password=genpasswd(); - list($values, $errors) = checkglobal($_SESSION['accounts'][$row], 'user'); // account.inc - if (is_object($values)) { - while (list($key, $val) = each($values)) // Set only defined values - if ($val) $_SESSION['accounts'][$row]->$key = $val; - $_SESSION['accounts'][$row]->general_uidNumber=""; + if ($_FILES['userfile']['size']>0) { + $handle = fopen($_FILES['userfile']['tmp_name'], 'r'); + 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] = loadUserProfile($_POST['f_selectprofile']) ; + $_SESSION['accounts'][$row]->general_dn = $_POST['f_general_suffix']; + if ($line_array[0]) $_SESSION['accounts'][$row]->general_surname = $line_array[0]; + if ($line_array[1]) $_SESSION['accounts'][$row]->general_givenname = $line_array[1]; + if ($line_array[2]) $_SESSION['accounts'][$row]->general_username = $line_array[2]; + if ($line_array[3]) $_SESSION['accounts'][$row]->general_group = $line_array[3]; + if ($line_array[4]) $_SESSION['accounts'][$row]->personal_title = $line_array[4]; + if ($line_array[5]) $_SESSION['accounts'][$row]->personal_mail = $line_array[5]; + if ($line_array[6]) $_SESSION['accounts'][$row]->personal_telephoneNumber = $line_array[6]; + if ($line_array[7]) $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $line_array[7]; + if ($line_array[8]) $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $line_array[8]; + if ($line_array[9]) $_SESSION['accounts'][$row]->personal_street = $line_array[9]; + if ($line_array[10]) $_SESSION['accounts'][$row]->personal_postalCode = $line_array[10]; + if ($line_array[11]) $_SESSION['accounts'][$row]->personal_postalAddress = $line_array[11]; + if ($line_array[12]) $_SESSION['accounts'][$row]->personal_employeeType = $line_array[12]; + $_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; } - if ($errors=='') { - list($values, $errors) = checkpersonal($_SESSION['accounts'][$row], 'user'); // account.inc - if (is_object($values)) { - while (list($key, $val) = each($values)) // Set only defined values - if ($val) $_SESSION['accounts'][$row]->$key = $val; - } - } - if ($errors=='') { - list($values, $errors) = checksamba($_SESSION['accounts'][$row], 'user'); // account.inc - if (is_object($values)) { - while (list($key, $val) = each($values)) // Set only defined values - if ($val) $_SESSION['accounts'][$row]->$key = $val; - } - } - if ($errors=='') { - list($values, $errors) = checkquota($_SESSION['accounts'][$row], 'user'); // account.inc - if (is_object($values)) { - while (list($key, $val) = each($values)) // Set only defined values - if ($val) $_SESSION['accounts'][$row]->$key = $val; - } - } - if ($errors=='') { - list($values, $errors) = checkpersonal($_SESSION['accounts'][$row], 'user'); // account.inc - if (is_object($values)) { - while (list($key, $val) = each($values)) // Set only defined values - if ($val) $_SESSION['accounts'][$row]->$key = $val; - } - } - if (is_array($errors)) - for ($i=0; $igeneral_group)==-1) && (!in_array($_SESSION['accounts'][$row]->general_group, $groups))) $groups[] = $_SESSION['accounts'][$row]->general_group; } + for ($row=0; $row$key = $val; + $_SESSION['accounts'][$row]->general_uidNumber=""; + } + $error = checkunix($_SESSION['accounts'][$row], 'user'); // account.inc + $_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error); + list($values, $error) = checksamba($_SESSION['accounts'][$row], 'user'); // account.inc + if (is_object($values)) { + while (list($key, $val) = each($values)) // Set only defined values + if ($val) $_SESSION['accounts'][$row]->$key = $val; + } + $_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error); + list($values, $error) = checkquota($_SESSION['accounts'][$row], 'user'); // account.inc + if (is_object($values)) { + while (list($key, $val) = each($values)) // Set only defined values + if ($val) $_SESSION['accounts'][$row]->$key = $val; + } + $_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error); + list($values, $error) = checkpersonal($_SESSION['accounts'][$row], 'user'); // account.inc + if (is_object($values)) { + while (list($key, $val) = each($values)) // Set only defined values + if ($val) $_SESSION['accounts'][$row]->$key = $val; + } + $_SESSION['errors'][$row] = array_merge($_SESSION['errors'][$row], $error); + } for ($i=0; $igeneral_group._(' not found!'), _('It will be created.')); - fclose($handle); - unlink($_FILES['userfile']['tmp_name']); + 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) { + fclose($handle); + unlink($_FILES['userfile']['tmp_name']); + } echo ''._('row').''. _('Surname'). ''. _('Givenname'). ''. _('Username'). ''. _('Primary Group'). ''. - _('Title'). ''. _('Mail Address'). ''. _('Telephonenumber'). ''. _('Mobiletelephonenumber') - . ''. _('Facsimiletelephonenumber'). ''. _('Street'). ''. _('Postal Code') - . ''. _('Postal Address'). ''. _('Employee Type') .''; + _('Details'). '' . _('Warnings'). '' . _('Errors') . ''; for ($row=0; $row'.$row.''. $_SESSION['accounts'][$row]->general_surname.''. $_SESSION['accounts'][$row]->general_givenname.''. $_SESSION['accounts'][$row]->general_username.''. - $_SESSION['accounts'][$row]->general_group.''. - $_SESSION['accounts'][$row]->personal_title.''. - $_SESSION['accounts'][$row]->personal_mail.''. - $_SESSION['accounts'][$row]->personal_telephoneNumber.''. - $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber.''. - $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber.''. - $_SESSION['accounts'][$row]->personal_street.''. - $_SESSION['accounts'][$row]->personal_postalCode.''. - $_SESSION['accounts'][$row]->personal_postalAddress.''. - $_SESSION['accounts'][$row]->personal_employeeType.''; + $_SESSION['accounts'][$row]->general_group.' + '._('Show Details.').''; + for ($i=$row+1; $igeneral_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 allready in use. Selected next free username.')); + $found=false; + for ($i=0; $i'._('Show Warnings.').''; + echo ''; + $found=false; + for ($i=0; $i'._('Show Errors.').''; + echo ''; + } - echo ''; + $noerrors=true; + for ($i=0; $i'; + if (!$noerrors) { echo ''. _('There are some errors!!') . ''; } + if (!$nowarn) { echo ''. _('There are some warnings.') . ''; } + echo '
+ '; break; case 'create': $stay=true; diff --git a/lam/templates/massdetail.php b/lam/templates/massdetail.php new file mode 100644 index 00000000..042dcc11 --- /dev/null +++ b/lam/templates/massdetail.php @@ -0,0 +1,185 @@ + + '; +echo _('Create new Accounts'); +echo ' + + + + + + +
'; echo ''; - echo ''; + echo ''; + if ($noerrors) { echo ''; } + echo '
+ '; + +if ($_GET) { + $row = $_GET['row']; + $select = $_GET['type']; + } +if ($_POST) { + $row = $_POST['row']; + $select = $_POST['type']; + } + +if ($_POST['apply']) { + if ($_POST['f_general_surname']) $_SESSION['accounts'][$row]->general_surname = $_POST['f_general_surname']; + else $_SESSION['accounts'][$row]->general_surname=''; + if ($_POST['f_general_givenname']) $_SESSION['accounts'][$row]->general_givenname = $_POST['f_general_givenname']; + else $_SESSION['accounts'][$row]->general_givenname=''; + if ($_POST['f_general_username']) $_SESSION['accounts'][$row]->general_username = $_POST['f_general_username']; + else $_SESSION['accounts'][$row]->general_username=''; + if ($_POST['f_general_group']) $_SESSION['accounts'][$row]->general_group = $_POST['f_general_group']; + else $_SESSION['accounts'][$row]->general_group=''; + if ($_POST['f_personal_title']) $_SESSION['accounts'][$row]->personal_title = $_POST['f_personal_title']; + else $_SESSION['accounts'][$row]->personal_title=''; + if ($_POST['f_personal_employeeType']) $_SESSION['accounts'][$row]->personal_employeeType = $_POST['f_personal_employeeType']; + else $_SESSION['accounts'][$row]->personal_employeeType=''; + if ($_POST['f_personal_street']) $_SESSION['accounts'][$row]->personal_street = $_POST['f_personal_street']; + else $_SESSION['accounts'][$row]->personal_street=''; + if ($_POST['f_personal_postalCode']) $_SESSION['accounts'][$row]->personal_postalCode = $_POST['f_personal_postalCode']; + else $_SESSION['accounts'][$row]->personal_postalCode=''; + if ($_POST['f_personal_postalAddress']) $_SESSION['accounts'][$row]->personal_postalAddress = $_POST['f_personal_postalAddress']; + else $_SESSION['accounts'][$row]->personal_postalAddress=''; + if ($_POST['f_personal_telephoneNumber']) $_SESSION['accounts'][$row]->personal_telephoneNumber = $_POST['f_personal_telephoneNumber']; + else $_SESSION['accounts'][$row]->personal_telephoneNumber=''; + if ($_POST['f_personal_mobileTelephoneNumber']) $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber = $_POST['f_personal_mobileTelephoneNumber']; + else $_SESSION['accounts'][$row]->personal_mobileTelephoneNumber=''; + if ($_POST['f_personal_facsimileTelephoneNumber']) $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber = $_POST['f_personal_facsimileTelephoneNumber']; + else $_SESSION['accounts'][$row]->personal_facsimileTelephoneNumber=''; + if ($_POST['f_personal_mail']) $_SESSION['accounts'][$row]->personal_mail = $_POST['f_personal_mail']; + else $_SESSION['accounts'][$row]->personal_mail=''; + } + +echo ''."\n".''."\n".''."\n".''."\n".''."\n".'\n'."\n".'\n'."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".''."\n".'
'; + echo ''; + + break; + } + + +echo '
'; +echo '
'; +switch ($select) { + case 'error': + for ($i=0; $i'; + echo _('Surname*'); + echo ' + + + '._('Help').' +
'; + echo _('Given name*'); + echo ' + + + '._('Help').' +
'; + echo _('Username*'); + echo "". + ' + + '._('Help').' +
'; + echo _('Primary Group*'); + echo "". + ' + + '._('Help').' +
'; + echo _('Title'); + echo ' + '; + echo $_SESSION['account']->general_surname . ' ' . $_SESSION['account']->general_givenname . ' + '._('Help').' +
'; + echo _('Employee Type'); + echo ' + + + '._('Help').' +
'; + echo _('Street'); + echo ' + + + '._('Help').' +
'; + echo _('Postal code'); + echo ' + + + '._('Help').' +
'; + echo _('Postal address'); + echo ' + + + '._('Help').' +
'; + echo _('Telephone Number'); + echo ' + + + '._('Help').' +
'; + echo _('Mobile Phonenumber'); + echo ' + + + '._('Help').' +
'; + echo _('Facsimile Number'); + echo ' + + + '._('Help').' +
'; + echo _('eMail Address'); + echo ' + + + '._('Help').' +
'; + echo '
'; +?>