diff --git a/lam/docs/modules-specification.htm b/lam/docs/modules-specification.htm index 7ea45172..c2944f2a 100644 --- a/lam/docs/modules-specification.htm +++ b/lam/docs/modules-specification.htm @@ -663,6 +663,11 @@ returns an array the array contains status
messages. First Index is the attribute which has triggered a message. Second index is an array containing
status message arrays.
+This function must reset $this->triggered_messages when it wants to +display +status messages. This can be done with $this->triggered_messages = +array();
+


2.2.15. proccess_*
diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index f843c75b..9748bba2 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -57,8 +57,8 @@ class baseModule { /** contains all ldap attributes which are loaded from ldap */ var $orig; - /** contains all error messages wich were triggered*/ - var $errors; + /** contains all messages wich were triggered*/ + var $triggered_messages; /** contains all error messages of a module */ var $messages; diff --git a/lam/lib/modules/account.inc b/lam/lib/modules/account.inc index 01deb503..f67223d8 100644 --- a/lam/lib/modules/account.inc +++ b/lam/lib/modules/account.inc @@ -77,14 +77,6 @@ class account extends baseModule { return array('attributes'); } - /* This function returns all ldap attributes - * which are part of account and returns - * also their values. - */ - function get_attributes() { - return $this->attributes; - } - /* This function loads all attributes into the object * $attr is an array as it's retured from ldap_get_attributes */ @@ -114,7 +106,7 @@ class account extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { // Load attributes $this->attributes['description'][0] = $post['description']; return 0; @@ -124,7 +116,7 @@ class account extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Description') ), 1 => array ( 'kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $this->attributes['description'][0] ), @@ -133,7 +125,7 @@ class account extends baseModule { return $return; } - function display_html_delete($post, $profile=false) { + function display_html_delete($post) { return 0; } diff --git a/lam/lib/modules/inetOrgPerson.inc b/lam/lib/modules/inetOrgPerson.inc index 728611b2..7bb79488 100644 --- a/lam/lib/modules/inetOrgPerson.inc +++ b/lam/lib/modules/inetOrgPerson.inc @@ -258,14 +258,6 @@ class inetOrgPerson extends baseModule { return array('attributes'); } - /* This function returns all ldap attributes - * which are part of inetOrgPerson and returns - * also their values. - */ - function get_attributes() { - return $this->attributes; - } - /* This function loads all attributes into the object * $attr is an array as it's retured from ldap_get_attributes */ @@ -301,7 +293,7 @@ class inetOrgPerson extends baseModule { return 0; } - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { // Load attributes $this->attributes['description'][0] = $post['description']; $this->attributes['sn'][0] = $post['sn']; @@ -320,7 +312,7 @@ class inetOrgPerson extends baseModule { if (isset($this->attributes['host'])) { $host = $post['host']; if (!get_preg($host,'unixhost')) - $errors['host'][] = $this->messages['host'][0]; + $triggered_messages['host'][] = $this->messages['host'][0]; $hosts = explode(" ", $host); $this->attributes['host'] = array(); foreach ($hosts as $host) @@ -328,21 +320,19 @@ class inetOrgPerson extends baseModule { } // Do some regex-checks and return error if attributes are set to wrong values - if (!$profile) { - if ( !get_preg($this->attributes['givenName'][0], 'realname')) $errors['givenName'][] = $this->messages['givenName'][0]; - if ( !get_preg($this->attributes['sn'][0], 'realname')) $errors['sn'][] = $this->messages['surname'][0]; - if ( !get_preg($this->attributes['telephoneNumber'][0], 'telephone')) $errors['telephoneNumber'][] = $this->messages['telephoneNumber'][0]; - if ( !get_preg($this->attributes['mobileTelephoneNumber'][0], 'telephone')) $errors['mobileTelephoneNumber'][] = $this->messages['mobileTelephone'][0]; - if ( !get_preg($this->attributes['facsimileTelephoneNumber'][0], 'telephone')) $errors['facsimileTelephoneNumber'][] = $this->messages['facsimileNumber'][0]; - if ( !get_preg($this->attributes['mail'][0], 'email')) $errors['mail'][] = $this->messages['email'][0]; - if ( !get_preg($this->attributes['street'][0], 'street')) $errors['street'][] = $this->messages['street'][0]; - if ( !get_preg($this->attributes['postalAddress'][0], 'postalAddress')) $errors['postalAdress'][] = $this->messages['postalAddress'][0]; - if ( !get_preg($this->attributes['personal_postalCode'][0], 'postalCode')) $errors['personal_postalCode'][] = $this->messages['postalCode'][0]; - } - if ( !get_preg($this->attributes['title'][0], 'title')) $errors['title'][] = $this->messages['title'][0]; - if ( !get_preg($this->attributes['employeeType'][0], 'employeeType')) $errors['employeeType'][] = $this->messages['employeeType'][0]; + if ( !get_preg($this->attributes['givenName'][0], 'realname')) $triggered_messages['givenName'][] = $this->messages['givenName'][0]; + if ( !get_preg($this->attributes['sn'][0], 'realname')) $triggered_messages['sn'][] = $this->messages['surname'][0]; + if ( !get_preg($this->attributes['telephoneNumber'][0], 'telephone')) $triggered_messages['telephoneNumber'][] = $this->messages['telephoneNumber'][0]; + if ( !get_preg($this->attributes['mobileTelephoneNumber'][0], 'telephone')) $triggered_messages['mobileTelephoneNumber'][] = $this->messages['mobileTelephone'][0]; + if ( !get_preg($this->attributes['facsimileTelephoneNumber'][0], 'telephone')) $triggered_messages['facsimileTelephoneNumber'][] = $this->messages['facsimileNumber'][0]; + if ( !get_preg($this->attributes['mail'][0], 'email')) $triggered_messages['mail'][] = $this->messages['email'][0]; + if ( !get_preg($this->attributes['street'][0], 'street')) $triggered_messages['street'][] = $this->messages['street'][0]; + if ( !get_preg($this->attributes['postalAddress'][0], 'postalAddress')) $triggered_messages['postalAdress'][] = $this->messages['postalAddress'][0]; + if ( !get_preg($this->attributes['personal_postalCode'][0], 'postalCode')) $triggered_messages['personal_postalCode'][] = $this->messages['postalCode'][0]; + if ( !get_preg($this->attributes['title'][0], 'title')) $triggered_messages['title'][] = $this->messages['title'][0]; + if ( !get_preg($this->attributes['employeeType'][0], 'employeeType')) $triggered_messages['employeeType'][] = $this->messages['employeeType'][0]; // Return error-messages - if (is_array($errors)) return $errors; + if (is_array($triggered_messages)) return $triggered_messages; return 0; } @@ -350,7 +340,7 @@ class inetOrgPerson extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Description') ), 1 => array ( 'kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $this->attributes['description'][0] ), @@ -367,54 +357,50 @@ class inetOrgPerson extends baseModule { 1 => array ( 'kind' => 'input', 'name' => 'title', 'type' => 'text', 'size' => '10', 'value' => $this->attributes['title'][0] ), 2 => array ('kind' => 'help', 'value' => 'title')); - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('First name').'*' ), - 1 => array ( 'kind' => 'input', 'name' => 'givenName', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['givenName'][0] ), - 2 => array ('kind' => 'help', 'value' => 'givenName')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Last name').'*' ), - 1 => array ( 'kind' => 'input', 'name' => 'sn', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['sn'][0] ), - 2 => array ('kind' => 'help', 'value' => 'sn')); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('First name').'*' ), + 1 => array ( 'kind' => 'input', 'name' => 'givenName', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['givenName'][0] ), + 2 => array ('kind' => 'help', 'value' => 'givenName')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Last name').'*' ), + 1 => array ( 'kind' => 'input', 'name' => 'sn', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['sn'][0] ), + 2 => array ('kind' => 'help', 'value' => 'sn')); $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Employee type') ), 1 => array ( 'kind' => 'input', 'name' => 'employeeType', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $this->attributes['employeeType'][0] ), 2 => array ('kind' => 'help', 'value' => 'employeeType')); - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Street') ), - 1 => array ( 'kind' => 'input', 'name' => 'street', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['street'][0] ), - 2 => array ('kind' => 'help', 'value' => 'street')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Postal code') ), - 1 => array ( 'kind' => 'input', 'name' => 'postalCode', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['postalCode'][0] ), - 2 => array ('kind' => 'help', 'value' => 'postalCode')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Postal address') ), - 1 => array ( 'kind' => 'input', 'name' => 'postalAddress', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['postalAddress'][0] ), - 2 => array ('kind' => 'help', 'value' => 'postalAddress')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Telephone number') ), - 1 => array ( 'kind' => 'input', 'name' => 'telephoneNumber', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['telephoneNumber'][0] ), - 2 => array ('kind' => 'help', 'value' => 'telephoneNumber')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Mobile number') ), - 1 => array ( 'kind' => 'input', 'name' => 'mobileTelephoneNumber', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['mobileTelephoneNumber'][0] ), - 2 => array ('kind' => 'help', 'value' => 'mobileTelephoneNumber')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Fax number') ), - 1 => array ( 'kind' => 'input', 'name' => 'facsimileTelephoneNumber', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['facsimileTelephoneNumber'][0] ), - 2 => array ('kind' => 'help', 'value' => 'facsimileTelephoneNumber')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('eMail address') ), - 1 => array ( 'kind' => 'input', 'name' => 'mail', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', 'value' => $this->attributes['mail'][0] ), - 2 => array ('kind' => 'help', 'value' => 'mail')); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Street') ), + 1 => array ( 'kind' => 'input', 'name' => 'street', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['street'][0] ), + 2 => array ('kind' => 'help', 'value' => 'street')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Postal code') ), + 1 => array ( 'kind' => 'input', 'name' => 'postalCode', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['postalCode'][0] ), + 2 => array ('kind' => 'help', 'value' => 'postalCode')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Postal address') ), + 1 => array ( 'kind' => 'input', 'name' => 'postalAddress', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['postalAddress'][0] ), + 2 => array ('kind' => 'help', 'value' => 'postalAddress')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Telephone number') ), + 1 => array ( 'kind' => 'input', 'name' => 'telephoneNumber', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['telephoneNumber'][0] ), + 2 => array ('kind' => 'help', 'value' => 'telephoneNumber')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Mobile number') ), + 1 => array ( 'kind' => 'input', 'name' => 'mobileTelephoneNumber', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['mobileTelephoneNumber'][0] ), + 2 => array ('kind' => 'help', 'value' => 'mobileTelephoneNumber')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Fax number') ), + 1 => array ( 'kind' => 'input', 'name' => 'facsimileTelephoneNumber', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['facsimileTelephoneNumber'][0] ), + 2 => array ('kind' => 'help', 'value' => 'facsimileTelephoneNumber')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('eMail address') ), + 1 => array ( 'kind' => 'input', 'name' => 'mail', 'type' => 'text', 'size' => '30', + 'maxlength' => '255', 'value' => $this->attributes['mail'][0] ), + 2 => array ('kind' => 'help', 'value' => 'mail')); return $return; } - function display_html_delete($post, $profile=false) { + function display_html_delete($post) { return 0; } @@ -447,7 +433,7 @@ class inetOrgPerson extends baseModule { * @return array list of error messages if any */ function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) { - $errors = array(); + $triggered_messages = array(); for ($i = 0; $i < sizeof($rawAccounts); $i++) { if (!in_array("inetOrgPerson", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "inetOrgPerson"; // last name @@ -457,7 +443,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['surname'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // first name if (($rawAccounts[$i][$ids['inetOrgPerson_firstName']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_firstName']], 'realname')) { @@ -466,7 +452,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['givenName'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // description if ($rawAccounts[$i][$ids['inetOrgPerson_description']] != "") { @@ -487,7 +473,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['title'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // employee type if (($rawAccounts[$i][$ids['inetOrgPerson_type']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_type']], 'employeeType')) { @@ -496,7 +482,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['employeeType'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // street if (($rawAccounts[$i][$ids['inetOrgPerson_street']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_street']], 'street')) { @@ -505,7 +491,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['street'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // postal code if (($rawAccounts[$i][$ids['inetOrgPerson_postalCode']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_postalCode']], 'postalCode')) { @@ -514,7 +500,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['postalCode'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // postal address if (($rawAccounts[$i][$ids['inetOrgPerson_address']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_address']], 'postalAddress')) { @@ -523,7 +509,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['postalAddress'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // telephone if (($rawAccounts[$i][$ids['inetOrgPerson_telephone']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_telephone']], 'telephone')) { @@ -532,7 +518,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['telephone'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // mobile if (($rawAccounts[$i][$ids['inetOrgPerson_mobile']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_mobile']], 'telephone')) { @@ -541,7 +527,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['mobileTelephone'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // facsimile if (($rawAccounts[$i][$ids['inetOrgPerson_fax']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_fax']], 'telephone')) { @@ -550,7 +536,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['facsimileNumber'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // eMail if (($rawAccounts[$i][$ids['inetOrgPerson_email']] != "") && get_preg($rawAccounts[$i][$ids['inetOrgPerson_email']], 'email')) { @@ -559,7 +545,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['email'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // cn if ($rawAccounts[$i][$ids['inetOrgPerson_cn']] != "") { @@ -569,7 +555,7 @@ class inetOrgPerson extends baseModule { else { $errMsg = $this->messages['email'][1]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } } else { @@ -581,7 +567,7 @@ class inetOrgPerson extends baseModule { } } } - return $errors; + return $triggered_messages; } diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index c312e208..9f24d4fb 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -398,16 +398,6 @@ class posixAccount extends baseModule { return array('attributes', 'group'); } - /* This function returns all ldap attributes - * which are part of posixAccount and returns - * also their values. - */ - function get_attributes() { - $return = $this->attributes; - $return['userPassword'] = $this->userPassword(); - return $return; - } - /* This function loads all attributes into the object * $attr is an array as it's retured from ldap_get_attributes */ @@ -552,210 +542,205 @@ class posixAccount extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { $this->attributes['homeDirectory'][0] = $post['homeDirectory']; $this->attributes['loginShell'][0] = $post['loginShell']; $this->attributes['gecos'][0] = $post['gecos']; if ($post['createhomedir']) $this->createhomedir = true; else $this->createhomedir = false; - - if (!$profile) { - if ($this->orig['uid'][0]!='' && $post['uid']!=$this->attributes['uid'][0]) - $errors['uid'][] = $this->messages['uid'][0]; - if ($this->orig['gidNumber'][0]!='' && $_SESSION['cache']->getgid($post['gidNumber'])!=$this->attributes['gidNumber'][0]) - $errors['gidNumber'][] = $this->dynamic_Message('gidNumber',0); - if ($this->orig['uidNumber'][0]!='' && $post['uidNumber']!=$this->attributes['uidNumber'][0]) - $errors['uidNumber'][] = $this->dynamic_Message('uidNumber',0); - if (isset($post['homeDirectory']) && $this->orig['homeDirectory'][0]!='' && $post['homeDirectory']!=$this->attributes['homeDirectory'][0]) - $errors['homeDirectory'][] = $this->dynamic_Message('homeDirectory',0); - // Load attributes - $this->attributes['uid'][0] = $post['uid']; - $this->attributes['cn'][0] = $this->attributes['uid'][0]; - $this->attributes['uidNumber'][0] = $post['uidNumber']; - $this->attributes['gidNumber'][0] = $_SESSION['cache']->getgid($post['gidNumber']); - // Check if UID is valid. If none value was entered, the next useable value will be inserted - // load min and may uidNumber - if ($_SESSION[$this->base]->type=='user') { - $minID = intval($this->moduleSettings['posixAccount_minUID'][0]); - $maxID = intval($this->moduleSettings['posixAccount_maxUID'][0]); - } - if ($_SESSION[$this->base]->type=='host') { - $minID = intval($this->moduleSettings['posixAccount_minMachine'][0]); - $maxID = intval($this->moduleSettings['posixAccount_maxMachine'][0]); - } - $dn_uids = $_SESSION['cache']->get_cache('uidNumber', 'posixAccount', '*'); - // get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) - if(is_array($dn_uids)) { - foreach ($dn_uids as $uid) $uids[] = $uid[0]; - sort ($uids, SORT_NUMERIC); - } - if ($this->attributes['uidNumber'][0]=='') { - // No id-number given - if ($this->orig['uidNumber'][0]=='') { - // new account -> we have to find a free id-number - if (count($uids)!=0) { - // There are some uids - // Store highest id-number - $id = $uids[count($uids)-1]; - // Return minimum allowed id-number if all found id-numbers are too low - if ($id < $minID) $this->attributes['uidNumber'][0] = $minID; - // Return higesht used id-number + 1 if it's still in valid range - if ($id < $maxID) $this->attributes['uidNumber'][0] = $id+1; - /* If this function is still running we have to fid a free id-number between - * the used id-numbers - */ - $i = intval($minID); - while (in_array($i, $uids)) $i++; - if ($i>$maxID) - $errors['uidNumber'][] = $this->messages['uidNumber'][1]; - else { - $this->attributes['uidNumber'][0] = $i; - $errors['uidNumber'][] = $this->messages['uidNumber'][2]; - } - } - else $this->attributes['uidNumber'][0] = $minID; - // return minimum allowed id-number if no id-numbers are found - } - else $this->attributes['uidNumber'][0] = $this->orig['uidNumber'][0]; - // old account -> return id-number which has been used - } - else { - // Check manual ID - // id-number is out of valid range - if ( ($this->attributes['uidNumber'][0]!=$post['uidNumber']) && ($this->attributes['uidNumber'][0] < $minID || $this->attributes['uidNumber'][0] > $maxID)) $errors['uidNumber'][] = array('ERROR', _('ID-Number'), sprintf(_('Please enter a value between %s and %s!'), $minID, $maxID)); - // $uids is allways an array but not if no entries were found - if (is_array($uids)) { - // id-number is in use and account is a new account - if ((in_array($this->attributes['uidNumber'][0], $uids)) && $this->orig['uidNumber'][0]=='') $errors['uidNumber'][] = array('ERROR', _('ID-Number'), _('ID is already in use')); - // id-number is in use, account is existing account and id-number is not used by itself - if ((in_array($this->attributes['uidNumber'][0], $uids)) && $this->orig['uidNumber'][0]!='' && ($this->orig['uidNumber'][0] != $this->attributes['uidNumber'][0]) ) { - $errors['uidNumber'][] = $this->messages['uidNumber'][3]; - $this->attributes['uidNumber'][0] = $this->orig['uidNumber'][0]; + if ($this->orig['uid'][0]!='' && $post['uid']!=$this->attributes['uid'][0]) + $triggered_messages['uid'][] = $this->messages['uid'][0]; + if ($this->orig['gidNumber'][0]!='' && $_SESSION['cache']->getgid($post['gidNumber'])!=$this->attributes['gidNumber'][0]) + $triggered_messages['gidNumber'][] = $this->dynamic_Message('gidNumber',0); + if ($this->orig['uidNumber'][0]!='' && $post['uidNumber']!=$this->attributes['uidNumber'][0]) + $triggered_messages['uidNumber'][] = $this->dynamic_Message('uidNumber',0); + if (isset($post['homeDirectory']) && $this->orig['homeDirectory'][0]!='' && $post['homeDirectory']!=$this->attributes['homeDirectory'][0]) + $triggered_messages['homeDirectory'][] = $this->dynamic_Message('homeDirectory',0); + // Load attributes + $this->attributes['uid'][0] = $post['uid']; + $this->attributes['cn'][0] = $this->attributes['uid'][0]; + $this->attributes['uidNumber'][0] = $post['uidNumber']; + $this->attributes['gidNumber'][0] = $_SESSION['cache']->getgid($post['gidNumber']); + // Check if UID is valid. If none value was entered, the next useable value will be inserted + // load min and may uidNumber + if ($_SESSION[$this->base]->type=='user') { + $minID = intval($this->moduleSettings['posixAccount_minUID'][0]); + $maxID = intval($this->moduleSettings['posixAccount_maxUID'][0]); + } + if ($_SESSION[$this->base]->type=='host') { + $minID = intval($this->moduleSettings['posixAccount_minMachine'][0]); + $maxID = intval($this->moduleSettings['posixAccount_maxMachine'][0]); + } + $dn_uids = $_SESSION['cache']->get_cache('uidNumber', 'posixAccount', '*'); + // get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) + if(is_array($dn_uids)) { + foreach ($dn_uids as $uid) $uids[] = $uid[0]; + sort ($uids, SORT_NUMERIC); + } + if ($this->attributes['uidNumber'][0]=='') { + // No id-number given + if ($this->orig['uidNumber'][0]=='') { + // new account -> we have to find a free id-number + if (count($uids)!=0) { + // There are some uids + // Store highest id-number + $id = $uids[count($uids)-1]; + // Return minimum allowed id-number if all found id-numbers are too low + if ($id < $minID) $this->attributes['uidNumber'][0] = $minID; + // Return higesht used id-number + 1 if it's still in valid range + if ($id < $maxID) $this->attributes['uidNumber'][0] = $id+1; + /* If this function is still running we have to fid a free id-number between + * the used id-numbers + */ + $i = intval($minID); + while (in_array($i, $uids)) $i++; + if ($i>$maxID) + $triggered_messages['uidNumber'][] = $this->messages['uidNumber'][1]; + else { + $this->attributes['uidNumber'][0] = $i; + $triggered_messages['uidNumber'][] = $this->messages['uidNumber'][2]; } } + else $this->attributes['uidNumber'][0] = $minID; + // return minimum allowed id-number if no id-numbers are found } - if ($_SESSION[$this->base]->type=='user') { - if (($this->attributes['uid'][0] != $post['uid']) && !get_preg($post['uid'], '!upper')) - $errors['uid'][] = $this->messages['uid'][1]; - if ( !get_preg($this->attributes['homeDirectory'][0], 'homeDirectory' )) - $errors['homeDirecotry'][] = $this->messages['homeDirectory'][0]; + else $this->attributes['uidNumber'][0] = $this->orig['uidNumber'][0]; + // old account -> return id-number which has been used + } + else { + // Check manual ID + // id-number is out of valid range + if ( ($this->attributes['uidNumber'][0]!=$post['uidNumber']) && ($this->attributes['uidNumber'][0] < $minID || $this->attributes['uidNumber'][0] > $maxID)) $triggered_messages['uidNumber'][] = array('ERROR', _('ID-Number'), sprintf(_('Please enter a value between %s and %s!'), $minID, $maxID)); + // $uids is allways an array but not if no entries were found + if (is_array($uids)) { + // id-number is in use and account is a new account + if ((in_array($this->attributes['uidNumber'][0], $uids)) && $this->orig['uidNumber'][0]=='') $triggered_messages['uidNumber'][] = array('ERROR', _('ID-Number'), _('ID is already in use')); + // id-number is in use, account is existing account and id-number is not used by itself + if ((in_array($this->attributes['uidNumber'][0], $uids)) && $this->orig['uidNumber'][0]!='' && ($this->orig['uidNumber'][0] != $this->attributes['uidNumber'][0]) ) { + $triggered_messages['uidNumber'][] = $this->messages['uidNumber'][3]; + $this->attributes['uidNumber'][0] = $this->orig['uidNumber'][0]; + } } - + } + if ($_SESSION[$this->base]->type=='user') { + if (($this->attributes['uid'][0] != $post['uid']) && !get_preg($post['uid'], '!upper')) + $triggered_messages['uid'][] = $this->messages['uid'][1]; + if ( !get_preg($this->attributes['homeDirectory'][0], 'homeDirectory' )) + $triggered_messages['homeDirecotry'][] = $this->messages['homeDirectory'][0]; + } if (($post['userPassword_lock'] && $post['userPassword_invalid']) || ($post['userPassword_nopassword'] && $post['userPassword_invalid'])) { - // found invalid password parameter combination - $errors['userPassword'][] = $this->messages['userPassword'][3]; + // found invalid password parameter combination + $triggered_messages['userPassword'][] = $this->messages['userPassword'][3]; + } + else { + if ($post['userPassword_nopassword']) { + $this->userPassword_nopassword=true; + $this->userPassword_invalid=false; + $this->userPassword(''); + $post['userPassword2'] = ''; + if ($post['userPassword_lock']) + $this->userPassword_lock=true; + else $this->userPassword_lock=false; } else { - if ($post['userPassword_nopassword']) { - $this->userPassword_nopassword=true; - $this->userPassword_invalid=false; + $this->userPassword_nopassword=false; + if ($post['userPassword_invalid']) { + $this->userPassword_invalid=true; + $this->userPassword_lock=false; $this->userPassword(''); $post['userPassword2'] = ''; - if ($post['userPassword_lock']) - $this->userPassword_lock=true; - else $this->userPassword_lock=false; } else { - $this->userPassword_nopassword=false; - if ($post['userPassword_invalid']) { - $this->userPassword_invalid=true; - $this->userPassword_lock=false; - $this->userPassword(''); - $post['userPassword2'] = ''; - } + $this->userPassword_invalid=false; + if ($post['genpass']) $this->userPassword(genpasswd()); else { - $this->userPassword_invalid=false; - if ($post['genpass']) $this->userPassword(genpasswd()); - else { - if ($post['userPassword'] != $post['userPassword2']) - $errors['userPassword'][] = $this->messages['userPassword'][0]; - else $this->userPassword($post['userPassword']); - if (!get_preg($this->userPassword(), 'password')) - $errors['userPassword'][] = $this->messages['userPassword'][1]; - } - if ($post['userPassword_lock']) $this->userPassword_lock=true; - else $this->userPassword_lock=false; + if ($post['userPassword'] != $post['userPassword2']) + $triggered_messages['userPassword'][] = $this->messages['userPassword'][0]; + else $this->userPassword($post['userPassword']); + if (!get_preg($this->userPassword(), 'password')) + $triggered_messages['userPassword'][] = $this->messages['userPassword'][1]; } + if ($post['userPassword_lock']) $this->userPassword_lock=true; + else $this->userPassword_lock=false; } - - if ($_SESSION[$this->base]->type=='user') { - $this->attributes['homeDirectory'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0]), $this->attributes['homeDirectory'][0]); - if ($this->attributes['uid'][0] != '') - $this->attributes['homeDirectory'][0] = str_replace('$user', $this->attributes['uid'][0], $this->attributes['homeDirectory'][0]); - if ($this->attributes['homeDirectory'][0] != $post['homeDirectory']) $errors['homeDirecotry'][] = array('INFO', _('Home directory'), _('Replaced $user or $group in homedir.')); - // Check if Username contains only valid characters - if ( !get_preg($this->attributes['uid'][0], 'username') && !$profile) - $errors['uid'][] = $this->messages['uid'][2]; - } - if ($_SESSION[$this->base]->type=='host') { - // Check if Hostname contains only valid characters - if ( !get_preg($this->attributes['uid'][0], 'hostname')) - $errors['uid'][] = $this->messages['uid'][4]; - } - // Create automatic useraccount with number if original user already exists - // Reset name to original name if new name is in use - // Set username back to original name if new username is in use - if ($_SESSION['cache']->in_cache($this->attributes['uid'][0],'uid', '*') && ($this->orig['uid'][0]!='')) - $this->attributes['uid'][0] = $this->orig['uid'][0]; - // Change uid to a new uid until a free uid is found - else - while ($_SESSION['cache']->in_cache($this->attributes['uid'][0], 'uid', '*')) { - if ($_SESSION[$this->base]->type=='host') $this->attributes['uid'][0] = substr($this->attributes['uid'][0], 0, -1); - // get last character of username - $lastchar = substr($this->attributes['uid'][0], strlen($this->attributes['uid'][0])-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. - */ - if ($_SESSION[$this->base]->type=='host') $this->attributes['uid'][0] = $this->attributes['uid'][0] . '2$'; - else $this->attributes['uid'][0] = $this->attributes['uid'][0] . '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($this->attributes['uid'][0])-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($this->attributes['uid'][0], $i, strlen($this->attributes['uid'][0])-$i))) $i--; - else $mark=true; - // increase last number with one - $firstchars = substr($this->attributes['uid'][0], 0, $i+1); - $lastchars = substr($this->attributes['uid'][0], $i+1, strlen($this->attributes['uid'][0])-$i); - // Put username together - if ($_SESSION[$this->base]->type=='host') $this->attributes['uid'][0] = $firstchars . (intval($lastchars)+1)."$"; - else $this->attributes['uid'][0] = $firstchars . (intval($lastchars)+1); - } - } - // Show warning if lam has changed username - if ($this->attributes['uid'][0] != $post['uid']) { - if ($_SESSION[$this->base]->type=='user') - $errors['uid'][] = $this->messages['uid'][5]; - if ($_SESSION[$this->base]->type=='host') - $errors['uid'][] = $this->messages['uid'][6]; - } - if (!get_preg($this->userPassword(), 'password')) - $errors['userPassword'][] = $this->messages['userPassword'][1]; } + if ($_SESSION[$this->base]->type=='user') { + $this->attributes['homeDirectory'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($this->attributes['gidNumber'][0]), $this->attributes['homeDirectory'][0]); + if ($this->attributes['uid'][0] != '') + $this->attributes['homeDirectory'][0] = str_replace('$user', $this->attributes['uid'][0], $this->attributes['homeDirectory'][0]); + if ($this->attributes['homeDirectory'][0] != $post['homeDirectory']) $triggered_messages['homeDirecotry'][] = array('INFO', _('Home directory'), _('Replaced $user or $group in homedir.')); + // Check if Username contains only valid characters + if ( !get_preg($this->attributes['uid'][0], 'username') && !$profile) + $triggered_messages['uid'][] = $this->messages['uid'][2]; + } + if ($_SESSION[$this->base]->type=='host') { + // Check if Hostname contains only valid characters + if ( !get_preg($this->attributes['uid'][0], 'hostname')) + $triggered_messages['uid'][] = $this->messages['uid'][4]; + } + // Create automatic useraccount with number if original user already exists + // Reset name to original name if new name is in use + // Set username back to original name if new username is in use + if ($_SESSION['cache']->in_cache($this->attributes['uid'][0],'uid', '*') && ($this->orig['uid'][0]!='')) + $this->attributes['uid'][0] = $this->orig['uid'][0]; + // Change uid to a new uid until a free uid is found + else + while ($_SESSION['cache']->in_cache($this->attributes['uid'][0], 'uid', '*')) { + if ($_SESSION[$this->base]->type=='host') $this->attributes['uid'][0] = substr($this->attributes['uid'][0], 0, -1); + // get last character of username + $lastchar = substr($this->attributes['uid'][0], strlen($this->attributes['uid'][0])-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. + */ + if ($_SESSION[$this->base]->type=='host') $this->attributes['uid'][0] = $this->attributes['uid'][0] . '2$'; + else $this->attributes['uid'][0] = $this->attributes['uid'][0] . '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($this->attributes['uid'][0])-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($this->attributes['uid'][0], $i, strlen($this->attributes['uid'][0])-$i))) $i--; + else $mark=true; + // increase last number with one + $firstchars = substr($this->attributes['uid'][0], 0, $i+1); + $lastchars = substr($this->attributes['uid'][0], $i+1, strlen($this->attributes['uid'][0])-$i); + // Put username together + if ($_SESSION[$this->base]->type=='host') $this->attributes['uid'][0] = $firstchars . (intval($lastchars)+1)."$"; + else $this->attributes['uid'][0] = $firstchars . (intval($lastchars)+1); + } + } + // Show warning if lam has changed username + if ($this->attributes['uid'][0] != $post['uid']) { + if ($_SESSION[$this->base]->type=='user') + $triggered_messages['uid'][] = $this->messages['uid'][5]; + if ($_SESSION[$this->base]->type=='host') + $triggered_messages['uid'][] = $this->messages['uid'][6]; + } + if (!get_preg($this->userPassword(), 'password')) + $triggered_messages['userPassword'][] = $this->messages['userPassword'][1]; } - // Return error-messages - if (count($errors)!=0) { - $this->errors = $errors; - return $errors; - } - else $this->errors = array(); - // Go to additional group page when no error did ocour and button was pressed - if ($post['addgroup']) return 'group'; - return 0; + // Return error-messages + if (count($triggered_messages)!=0) { + $this->triggered_messages = $triggered_messages; + return $triggered_messages; + } + else $this->triggered_messages = array(); + // Go to additional group page when no error did ocour and button was pressed + if ($post['addgroup']) return 'group'; + return 0; } /* Write variables into object and do some regexp checks */ - function proccess_group($post, $profile=false) { + function proccess_group($post) { do { // X-Or, only one if() can be true if (isset($post['addgroups']) && isset($post['addgroups_button'])) { // Add groups to list // Add new group @@ -769,27 +754,25 @@ class posixAccount extends baseModule { break; } } while(0); - if (isset($post['addgroups_button']) || isset($post['removegroups_button'])) return 'group'; - if ($post['back']) return 'attributes'; - return 0; + if (isset($post['addgroups_button']) || isset($post['removegroups_button'])) return 'group'; + if ($post['back']) return 'attributes'; + return 0; } /* This function will create the html-page * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { $groups = $_SESSION['cache']->findgroups(); // list of all groupnames $shelllist = getshells(); // list of all valid shells - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Username").'*' ), - 1 => array ( 'kind' => 'input', 'name' => 'uid', 'type' => 'text', 'size' => '20', 'maxlength' => '20', 'value' => $this->attributes['uid'][0]), - 2 => array ('kind' => 'help', 'value' => 'uid')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('UID number').'*' ), - 1 => array ( 'kind' => 'input', 'name' => 'uidNumber', 'type' => 'text', 'size' => '6', 'maxlength' => '6', 'value' => $this->attributes['uidNumber'][0]), - 2 => array ('kind' => 'help', 'value' => 'uidNumber')); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Username").'*' ), + 1 => array ( 'kind' => 'input', 'name' => 'uid', 'type' => 'text', 'size' => '20', 'maxlength' => '20', 'value' => $this->attributes['uid'][0]), + 2 => array ('kind' => 'help', 'value' => 'uid')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('UID number').'*' ), + 1 => array ( 'kind' => 'input', 'name' => 'uidNumber', 'type' => 'text', 'size' => '6', 'maxlength' => '6', 'value' => $this->attributes['uidNumber'][0]), + 2 => array ('kind' => 'help', 'value' => 'uidNumber')); $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Gecos') ), 1 => array ( 'kind' => 'input', 'name' => 'gecos', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $this->attributes['gecos'][0]), 2 => array ('kind' => 'help', 'value' => 'gecos')); @@ -799,29 +782,25 @@ class posixAccount extends baseModule { 2 => array ('kind' => 'help', 'value' => 'gidNumber')); if ($_SESSION[$this->base]->type=='user') { - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Additional groups') ), - 1 => array ( 'kind' => 'input', 'name' => 'addgroup', 'type' => 'submit', 'value' => _('Edit groups')), - 2 => array ('kind' => 'help', 'value' => 'addgroup')); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Additional groups') ), + 1 => array ( 'kind' => 'input', 'name' => 'addgroup', 'type' => 'submit', 'value' => _('Edit groups')), + 2 => array ('kind' => 'help', 'value' => 'addgroup')); $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Home directory').'*' ), 1 => array ( 'kind' => 'input', 'name' => 'homeDirectory', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $this->attributes['homeDirectory'][0]), 2 => array ('kind' => 'help', 'value' => 'homeDirectory')); - if (!$profile) { - if ($this->orig['homeDirectory']=='' && isset($_SESSION['config']->scriptPath)) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Create home directory') ), - 1 => array ( 'kind' => 'input', 'name' => 'createhomedir', 'type' => 'checkbox', 'checked' => $this->createhomedir), - 2 => array ('kind' => 'help', 'value' => 'createhomedir')); + if ($this->orig['homeDirectory']=='' && isset($_SESSION['config']->scriptPath)) { + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Create home directory') ), + 1 => array ( 'kind' => 'input', 'name' => 'createhomedir', 'type' => 'checkbox', 'checked' => $this->createhomedir), + 2 => array ('kind' => 'help', 'value' => 'createhomedir')); } - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Password') ), - 1 => array ( 'kind' => 'input', 'name' => 'userPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $this->userPassword()), - 2 => array ( 'kind' => 'input', 'name' => 'genpass', 'type' => 'submit', 'value' => _('Generate password'))); - if ($post['userPassword2']!='') $password2 = $post['userPassword2']; - else $password2 = $this->userPassword(); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), - 1 => array ( 'kind' => 'input', 'name' => 'userPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), - 2 => array ('kind' => 'help', 'value' => 'userPassword')); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Password') ), + 1 => array ( 'kind' => 'input', 'name' => 'userPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $this->userPassword()), + 2 => array ( 'kind' => 'input', 'name' => 'genpass', 'type' => 'submit', 'value' => _('Generate password'))); + if ($post['userPassword2']!='') $password2 = $post['userPassword2']; + else $password2 = $this->userPassword(); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), + 1 => array ( 'kind' => 'input', 'name' => 'userPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), + 2 => array ('kind' => 'help', 'value' => 'userPassword')); $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Set no password') ), 1 => array ( 'kind' => 'input', 'name' => 'userPassword_nopassword', 'type' => 'checkbox', 'checked' => $this->userPassword_nopassword), 2 => array ('kind' => 'help', 'value' => 'userPassword_nopassword')); @@ -837,7 +816,6 @@ class posixAccount extends baseModule { array ($this->attributes['loginShell'][0])), 2 => array ('kind' => 'help', 'value' => 'loginShell')); } - return $return; } function display_html_delete($post) { @@ -849,7 +827,7 @@ class posixAccount extends baseModule { return $return; } - function display_html_group($post, $profile=false) { + function display_html_group($post) { // load list with all groups $dn_groups = $_SESSION['cache']->get_cache('gidNumber', 'posixGroup', 'group'); $DNs = array_keys($dn_groups); @@ -1012,7 +990,7 @@ class posixAccount extends baseModule { * @return array list of error messages if any */ function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) { - $errors = array(); + $triggered_messages = array(); for ($i = 0; $i < sizeof($rawAccounts); $i++) { if (!in_array("posixAccount", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "posixAccount"; // UID @@ -1026,7 +1004,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['uidNumber'][8]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // GID number if (get_preg($rawAccounts[$i][$ids['posixAccount_group']], 'digit')) { @@ -1040,7 +1018,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['gidNumber'][8]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // GECOS // TODO fill default values if (($rawAccounts[$i][$ids['posixAccount_gecos']] != "") && (get_preg($rawAccounts[$i][$ids['posixAccount_gecos']], 'gecos'))) { @@ -1049,7 +1027,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['gecos'][1]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // user specific attributes if ($this->scope == 'user') { @@ -1060,7 +1038,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['username'][1]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // home directory if ($rawAccounts[$i][$ids['posixAccount_homedir']] == "") { @@ -1072,7 +1050,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['homedir'][8]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // login shell if ($rawAccounts[$i][$ids['posixAccount_shell']] == "") { @@ -1084,7 +1062,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['loginshell'][8]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } $pwd_enabled = true; // password enabled/disabled @@ -1098,7 +1076,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['passwordDisabled'][8]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // password if (($rawAccounts[$i][$ids['posixAccount_password']] != "") && (get_preg($rawAccounts[$i][$ids['posixAccount_password']], 'password'))) { @@ -1107,7 +1085,7 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['password'][8]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } } // host specific attributes @@ -1119,13 +1097,13 @@ class posixAccount extends baseModule { else { $errMsg = $this->messages['hostname'][1]; // TODO array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } $partialAccounts[$i]['homeDirectory'] = '/dev/null'; $partialAccounts[$i]['loginShell'] = '/bin/false'; } } - return $errors; + return $triggered_messages; } } diff --git a/lam/lib/modules/posixGroup.inc b/lam/lib/modules/posixGroup.inc index d5a08a2f..7685d7e6 100644 --- a/lam/lib/modules/posixGroup.inc +++ b/lam/lib/modules/posixGroup.inc @@ -53,7 +53,7 @@ class posixGroup extends baseModule { * @return array list of error messages if any */ function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) { - $errors = array(); + $triggered_messages = array(); for ($i = 0; $i < sizeof($rawAccounts); $i++) { if (!in_array("posixGroup", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "posixGroup"; // group name @@ -63,7 +63,7 @@ class posixGroup extends baseModule { else { $errMsg = $this->messages['cn'][3]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // GID if ($rawAccounts[$i][$ids['posixGroup_gid']] == "") { @@ -76,7 +76,7 @@ class posixGroup extends baseModule { else { $errMsg = $this->messages['gidNumber'][8]; array_push($errMsg, array($i)); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } // description (UTF-8, no regex check needed) if ($rawAccounts[$i][$ids['posixGroup_description']] == "") { @@ -93,7 +93,7 @@ class posixGroup extends baseModule { else { $errMsg = $this->messages['memberUID'][0]; array_push($errMsg, $i); - $errors[] =$errMsg; + $triggered_messages[] =$errMsg; } } // password @@ -102,11 +102,11 @@ class posixGroup extends baseModule { $partialAccounts[$i]['userPassword'] = pwd_hash($rawAccounts[$i][$ids['posixGroup_password']], true, $this->moduleSettings['posixAccount_pwdHash'][0]); } else { - $errors[] = $this->messages['userPassword'][1]; + $triggered_messages[] = $this->messages['userPassword'][1]; } } } - return $errors; + return $triggered_messages; } @@ -122,44 +122,39 @@ class posixGroup extends baseModule { * It will output a complete html-table */ function display_html_attributes($post) { - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Groupname").'*' ), - 1 => array ( 'kind' => 'input', 'name' => 'cn', 'type' => 'text', 'size' => '20', 'maxlength' => '20', 'value' => $this->attributes['cn'][0]), - 2 => array ('kind' => 'help', 'value' => 'cn')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('GID number').'*' ), - 1 => array ( 'kind' => 'input', 'name' => 'gidNumber', 'type' => 'text', 'size' => '6', 'maxlength' => '6', 'value' => $this->attributes['gidNumber'][0]), - 2 => array ('kind' => 'help', 'value' => 'gidNumber')); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Groupname").'*' ), + 1 => array ( 'kind' => 'input', 'name' => 'cn', 'type' => 'text', 'size' => '20', 'maxlength' => '20', 'value' => $this->attributes['cn'][0]), + 2 => array ('kind' => 'help', 'value' => 'cn')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('GID number').'*' ), + 1 => array ( 'kind' => 'input', 'name' => 'gidNumber', 'type' => 'text', 'size' => '6', 'maxlength' => '6', 'value' => $this->attributes['gidNumber'][0]), + 2 => array ('kind' => 'help', 'value' => 'gidNumber')); $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Description') ), 1 => array ( 'kind' => 'input', 'name' => 'description', 'type' => 'text', 'size' => '30', 'maxlength' => '255', 'value' => $this->attributes['description'][0]), 2 => array ('kind' => 'help', 'value' => 'description')); - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Group members").'*' ), - 1 => array ( 'kind' => 'input', 'name' => 'adduser', 'type' => 'submit', 'value' => _('Edit groups')), - 2 => array ('kind' => 'help', 'value' => 'adduser')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Password') ), - 1 => array ( 'kind' => 'input', 'name' => 'userPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $this->userPassword()), - 2 => array ( 'kind' => 'input', 'name' => 'genpass', 'type' => 'submit', 'value' => _('Generate password'))); - if ($post['userPassword2']!='') $password2 = $post['userPassword2']; - else $password2 = $this->userPassword(); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), - 1 => array ( 'kind' => 'input', 'name' => 'userPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), - 2 => array ('kind' => 'help', 'value' => 'userPassword')); - } - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Set no password') ), - 1 => array ( 'kind' => 'input', 'name' => 'userPassword_nopassword', 'type' => 'checkbox', 'checked' => $this->userPassword_nopassword), - 2 => array ('kind' => 'help', 'value' => 'userPassword_nopassword')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Invalid password') ), - 1 => array ( 'kind' => 'input', 'name' => 'userPassword_invalid', 'type' => 'checkbox', 'checked' => $this->userPassword_invalid), - 2 => array ('kind' => 'help', 'value' => 'userPassword_invalid')); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Lock password') ), - 1 => array ( 'kind' => 'input', 'name' => 'userPassword_lock', 'type' => 'checkbox', 'checked' => $this->userPassword_lock), - 2 => array ('kind' => 'help', 'value' => 'userPassword_lock')); - if ($this->attributes['gidNumber'][0]!=$this->orig['gidNumber'][0] && $this->orig['gidNumber'][0]!='' && !$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Change GID number of users and hosts') ), - 1 => array ( 'kind' => 'input', 'name' => 'changegids', 'type' => 'checkbox', 'checked' => $this->changegids, 'value' => true), - 2 => array ('kind' => 'help', 'value' => 'changegids')); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Group members").'*' ), + 1 => array ( 'kind' => 'input', 'name' => 'adduser', 'type' => 'submit', 'value' => _('Edit groups')), + 2 => array ('kind' => 'help', 'value' => 'adduser')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Password') ), + 1 => array ( 'kind' => 'input', 'name' => 'userPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $this->userPassword()), + 2 => array ( 'kind' => 'input', 'name' => 'genpass', 'type' => 'submit', 'value' => _('Generate password'))); + if ($post['userPassword2']!='') $password2 = $post['userPassword2']; + else $password2 = $this->userPassword(); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), + 1 => array ( 'kind' => 'input', 'name' => 'userPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), + 2 => array ('kind' => 'help', 'value' => 'userPassword')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Set no password') ), + 1 => array ( 'kind' => 'input', 'name' => 'userPassword_nopassword', 'type' => 'checkbox', 'checked' => $this->userPassword_nopassword), + 2 => array ('kind' => 'help', 'value' => 'userPassword_nopassword')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Invalid password') ), + 1 => array ( 'kind' => 'input', 'name' => 'userPassword_invalid', 'type' => 'checkbox', 'checked' => $this->userPassword_invalid), + 2 => array ('kind' => 'help', 'value' => 'userPassword_invalid')); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Lock password') ), + 1 => array ( 'kind' => 'input', 'name' => 'userPassword_lock', 'type' => 'checkbox', 'checked' => $this->userPassword_lock), + 2 => array ('kind' => 'help', 'value' => 'userPassword_lock')); + if ($this->attributes['gidNumber'][0]!=$this->orig['gidNumber'][0] && $this->orig['gidNumber'][0]!='') + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Change GID number of users and hosts') ), + 1 => array ( 'kind' => 'input', 'name' => 'changegids', 'type' => 'checkbox', 'checked' => $this->changegids, 'value' => true), + 2 => array ('kind' => 'help', 'value' => 'changegids')); return $return; } @@ -170,7 +165,7 @@ class posixGroup extends baseModule { } - function display_html_user($post, $profile=false) { + function display_html_user($post) { // load list with all groups $dn_users = $_SESSION['cache']->get_cache('uid', 'posixAccount', 'user'); if (is_array($dn_users)) { @@ -212,17 +207,6 @@ class posixGroup extends baseModule { } - /** This function returns all ldap attributes - * which are part of posixGroup and returns - * also their values. - */ - function get_attributes() { - $return = $this->attributes; - $return['userPassword'] = $this->userPassword(); - return $return; - } - - /** * Returns meta data that is interpreted by parent class * @@ -457,166 +441,164 @@ class posixGroup extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { $this->attributes['description'][0] = $post['description']; - If (!$profile) { - if (($post['userPassword_lock'] && $post['userPassword_invalid']) || ($post['userPassword_nopassword'] && $post['userPassword_invalid'])) { - // found invalid password parameter combination - $errors['userPassword'][] = $this->messages['userPassword'][3]; + if (($post['userPassword_lock'] && $post['userPassword_invalid']) || ($post['userPassword_nopassword'] && $post['userPassword_invalid'])) { + // found invalid password parameter combination + $triggered_messages['userPassword'][] = $this->messages['userPassword'][3]; + } + else { + if ($post['userPassword_nopassword']) { + $this->userPassword_nopassword=true; + $this->userPassword_invalid=false; + $this->userPassword(''); + $post['userPassword2'] = ''; + if ($post['userPassword_lock']) + $this->userPassword_lock=true; + else $this->userPassword_lock=false; } else { - if ($post['userPassword_nopassword']) { - $this->userPassword_nopassword=true; - $this->userPassword_invalid=false; + $this->userPassword_nopassword=false; + if ($post['userPassword_invalid']) { + $this->userPassword_invalid=true; + $this->userPassword_lock=false; $this->userPassword(''); $post['userPassword2'] = ''; - if ($post['userPassword_lock']) - $this->userPassword_lock=true; + } + else { + $this->userPassword_invalid=false; + if ($post['genpass']) $this->userPassword(genpasswd()); + else { + if ($post['userPassword'] != $post['userPassword2']) + $triggered_messages['userPassword'][] = $this->messages['userPassword'][0]; + else $this->userPassword($post['userPassword']); + if (!get_preg($this->userPassword(), 'password')) + $triggered_messages['userPassword'][] = $this->messages['userPassword'][1]; + } + if ($post['userPassword_lock']) $this->userPassword_lock=true; else $this->userPassword_lock=false; } - else { - $this->userPassword_nopassword=false; - if ($post['userPassword_invalid']) { - $this->userPassword_invalid=true; - $this->userPassword_lock=false; - $this->userPassword(''); - $post['userPassword2'] = ''; - } - else { - $this->userPassword_invalid=false; - if ($post['genpass']) $this->userPassword(genpasswd()); - else { - if ($post['userPassword'] != $post['userPassword2']) - $errors['userPassword'][] = $this->messages['userPassword'][0]; - else $this->userPassword($post['userPassword']); - if (!get_preg($this->userPassword(), 'password')) - $errors['userPassword'][] = $this->messages['userPassword'][1]; - } - if ($post['userPassword_lock']) $this->userPassword_lock=true; - else $this->userPassword_lock=false; - } - } - if ($post['changegids']) $this->changegids=true; - else $this->changegids=false; - if ($this->attributes['gidNumber'][0]!=$post['gidNumber'] || ($this->errors['gidNumber'][0]='ERROR')) { - // Check if GID is valid. If none value was entered, the next useable value will be inserted - // load min and may uidNumber - $minID = intval($this->moduleSettings['posixGroup_minGID'][0]); - $maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]); - $dn_gids = $_SESSION['cache']->get_cache('gidNumber', 'posixGroup', '*'); - // get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) - if(is_array($dn_gids)) { - foreach ($dn_gids as $gid) $gids[] = $gid[0]; - sort ($gids, SORT_NUMERIC); - } - $this->attributes['gidNumber'][0]=$post['gidNumber']; - if ($this->attributes['gidNumber'][0]=='') { - // No id-number given - if ($this->orig['gidNumber'][0]=='') { - // new account -> we have to find a free id-number - if (count($gids)!=0) { - // There are some uids - // Store highest id-number - $id = $gids[count($gids)-1]; - // Return minimum allowed id-number if all found id-numbers are too low - if ($id < $minID) $this->attributes['gidNumber'][0] = $minID; - // Return higesht used id-number + 1 if it's still in valid range - if ($id < $maxID) $this->attributes['gidNumber'][0] = $id+1; - /* If this function is still running we have to fid a free id-number between - * the used id-numbers - */ - $i = intval($minID); - while (in_array($i, $gids)) $i++; - if ($i>$maxID) - $errors['gidNumber'][] = $this->messages['gidNumber'][3]; - else { - $this->attributes['gidNumber'][0] = $i; - $errors['gidNumber'][] = $this->messages['gidNumber'][2]; - } - } - else $this->attributes['gidNumber'][0] = $minID; - // return minimum allowed id-number if no id-numbers are found - } - else $this->attributes['gidNumber'][0] = $this->orig['gidNumber'][0]; - // old account -> return id-number which has been used - } - else { - // Check manual ID - // id-number is out of valid range - if ( ($this->attributes['gidNumber'][0]!=$post['gidNumber']) && ($this->attributes['gidNumber'][0] < $minID || $this->attributes['gidNumber'][0] > $maxID)) $errors['gidNumber'][] = array('ERROR', _('ID-Number'), sprintf(_('Please enter a value between %s and %s!'), $minID, $maxID)); - // $uids is allways an array but not if no entries were found - if (is_array($gids)) { - // id-number is in use and account is a new account - if ((in_array($this->attributes['gidNumber'][0], $gids)) && $this->orig['gidNumber'][0]=='') $errors['gidNumber'][] = array('ERROR', _('ID-Number'), _('ID is already in use')); - // id-number is in use, account is existing account and id-number is not used by itself - if ((in_array($this->attributes['gidNumber'][0], $gids)) && $this->orig['gidNumber'][0]!='' && ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0]) ) { - $errors['gidNumber'][] = $this->messages['gidNumber'][4]; - $this->attributes['gidNumber'][0] = $this->orig['gidNumber'][0]; - } - } - } } - if ($this->attributes['cn'][0]!=$post['cn'] || ($this->errors['cn'][0]='ERROR')) { - $this->attributes['cn'][0] = $post['cn']; - if (($this->attributes['cn'][0] != $post['cn']) && ereg('[A-Z]$', $post['cn'])) - $errors['cn'][] = $this->messages['cn'][0]; - // Check if Groupname contains only valid characters - if ( !get_preg($this->attributes['cn'][0],'groupname')) - $errors['cn'][] = $this->messages['cn'][2]; - // Create automatic useraccount with number if original user already exists - // Reset name to original name if new name is in use - // Set username back to original name if new username is in use - if ($_SESSION['cache']->in_cache($this->attributes['cn'][0],'cn', '*')!=false && ($this->orig['cn'][0]!='')) { - $this->attributes['cn'][0] = $this->orig['cn'][0]; - } - // Change gid to a new gid until a free gid is found - else while ($_SESSION['cache']->in_cache($this->attributes['cn'][0], 'cn', '*')) { - // get last character of username - $lastchar = substr($this->attributes['cn'][0], strlen($this->attributes['cn'][0])-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. - */ - $this->attributes['cn'][0] = $this->attributes['cn'][0] . '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 + if ($post['changegids']) $this->changegids=true; + else $this->changegids=false; + if ($this->attributes['gidNumber'][0]!=$post['gidNumber'] || ($this->triggered_messages['gidNumber'][0]='ERROR')) { + // Check if GID is valid. If none value was entered, the next useable value will be inserted + // load min and may uidNumber + $minID = intval($this->moduleSettings['posixGroup_minGID'][0]); + $maxID = intval($this->moduleSettings['posixGroup_maxGID'][0]); + $dn_gids = $_SESSION['cache']->get_cache('gidNumber', 'posixGroup', '*'); + // get_cache will return an array ( dn1 => array(uidnumber1), dn2 => array(uidnumber2), ... ) + if(is_array($dn_gids)) { + foreach ($dn_gids as $gid) $gids[] = $gid[0]; + sort ($gids, SORT_NUMERIC); + } + $this->attributes['gidNumber'][0]=$post['gidNumber']; + if ($this->attributes['gidNumber'][0]=='') { + // No id-number given + if ($this->orig['gidNumber'][0]=='') { + // new account -> we have to find a free id-number + if (count($gids)!=0) { + // There are some uids + // Store highest id-number + $id = $gids[count($gids)-1]; + // Return minimum allowed id-number if all found id-numbers are too low + if ($id < $minID) $this->attributes['gidNumber'][0] = $minID; + // Return higesht used id-number + 1 if it's still in valid range + if ($id < $maxID) $this->attributes['gidNumber'][0] = $id+1; + /* If this function is still running we have to fid a free id-number between + * the used id-numbers */ - $i=strlen($this->attributes['cn'][0])-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($this->attributes['cn'][0], $i, strlen($this->attributes['cn'][0])-$i))) $i--; - else $mark=true; + $i = intval($minID); + while (in_array($i, $gids)) $i++; + if ($i>$maxID) + $triggered_messages['gidNumber'][] = $this->messages['gidNumber'][3]; + else { + $this->attributes['gidNumber'][0] = $i; + $triggered_messages['gidNumber'][] = $this->messages['gidNumber'][2]; } - // increase last number with one - $firstchars = substr($this->attributes['cn'][0], 0, $i+1); - $lastchars = substr($this->attributes['cn'][0], $i+1, strlen($this->attributes['cn'][0])-$i); - // Put username together - $this->attributes['cn'][0] = $firstchars . (intval($lastchars)+1); + } + else $this->attributes['gidNumber'][0] = $minID; + // return minimum allowed id-number if no id-numbers are found + } + else $this->attributes['gidNumber'][0] = $this->orig['gidNumber'][0]; + // old account -> return id-number which has been used + } + else { + // Check manual ID + // id-number is out of valid range + if ( ($this->attributes['gidNumber'][0]!=$post['gidNumber']) && ($this->attributes['gidNumber'][0] < $minID || $this->attributes['gidNumber'][0] > $maxID)) $triggered_messages['gidNumber'][] = array('ERROR', _('ID-Number'), sprintf(_('Please enter a value between %s and %s!'), $minID, $maxID)); + // $uids is allways an array but not if no entries were found + if (is_array($gids)) { + // id-number is in use and account is a new account + if ((in_array($this->attributes['gidNumber'][0], $gids)) && $this->orig['gidNumber'][0]=='') $triggered_messages['gidNumber'][] = array('ERROR', _('ID-Number'), _('ID is already in use')); + // id-number is in use, account is existing account and id-number is not used by itself + if ((in_array($this->attributes['gidNumber'][0], $gids)) && $this->orig['gidNumber'][0]!='' && ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0]) ) { + $triggered_messages['gidNumber'][] = $this->messages['gidNumber'][4]; + $this->attributes['gidNumber'][0] = $this->orig['gidNumber'][0]; } } - // Show warning if lam has changed username - if ($this->attributes['cn'][0] != $post['cn']) { - $errors['cn'][] = $this->messages['cn'][0]; - } - // show info when gidnumber has changed - if (($this->orig['gidNumber'][0]!=$this->attributes['gidNumber'][0]) && $this->orig['gidNumber'][0]!='' && $post['gidNumber']!=$this->attributes['gidNumber'][0]) - $errors['gidNumber'][] = $this->messages['gidNumber'][0]; } } + if ($this->attributes['cn'][0]!=$post['cn'] || ($this->triggered_messages['cn'][0]='ERROR')) { + $this->attributes['cn'][0] = $post['cn']; + if (($this->attributes['cn'][0] != $post['cn']) && ereg('[A-Z]$', $post['cn'])) + $triggered_messages['cn'][] = $this->messages['cn'][0]; + // Check if Groupname contains only valid characters + if ( !get_preg($this->attributes['cn'][0],'groupname')) + $triggered_messages['cn'][] = $this->messages['cn'][2]; + // Create automatic useraccount with number if original user already exists + // Reset name to original name if new name is in use + // Set username back to original name if new username is in use + if ($_SESSION['cache']->in_cache($this->attributes['cn'][0],'cn', '*')!=false && ($this->orig['cn'][0]!='')) { + $this->attributes['cn'][0] = $this->orig['cn'][0]; + } + // Change gid to a new gid until a free gid is found + else while ($_SESSION['cache']->in_cache($this->attributes['cn'][0], 'cn', '*')) { + // get last character of username + $lastchar = substr($this->attributes['cn'][0], strlen($this->attributes['cn'][0])-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. + */ + $this->attributes['cn'][0] = $this->attributes['cn'][0] . '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($this->attributes['cn'][0])-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($this->attributes['cn'][0], $i, strlen($this->attributes['cn'][0])-$i))) $i--; + else $mark=true; + } + // increase last number with one + $firstchars = substr($this->attributes['cn'][0], 0, $i+1); + $lastchars = substr($this->attributes['cn'][0], $i+1, strlen($this->attributes['cn'][0])-$i); + // Put username together + $this->attributes['cn'][0] = $firstchars . (intval($lastchars)+1); + } + } + // Show warning if lam has changed username + if ($this->attributes['cn'][0] != $post['cn']) { + $triggered_messages['cn'][] = $this->messages['cn'][0]; + } + // show info when gidnumber has changed + if (($this->orig['gidNumber'][0]!=$this->attributes['gidNumber'][0]) && $this->orig['gidNumber'][0]!='' && $post['gidNumber']!=$this->attributes['gidNumber'][0]) + $triggered_messages['gidNumber'][] = $this->messages['gidNumber'][0]; + } } // Return error-messages - if (count($errors)!=0) { - $this->errors = $errors; - return $errors; + if (count($triggered_messages)!=0) { + $this->triggered_messages = $triggered_messages; + return $triggered_messages; } - else $this->errors = array(); + else $this->triggered_messages = array(); // Go to additional group page when no error did ocour and button was pressed if ($post['adduser']) return 'user'; return 0; @@ -625,7 +607,7 @@ class posixGroup extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_user($post, $profile=false) { + function proccess_user($post) { do { // X-Or, only one if() can be true if (isset($post['addusers']) && isset($post['addusers_button'])) { // Add groups to list // Add new user @@ -783,6 +765,7 @@ class posixGroup extends baseModule { else return ''; } } -} + } + ?> diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index 189a5052..811f2ca6 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -252,7 +252,7 @@ class quota extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { // Write all general values into $account_new $i=0; // loop for every mointpoint with quotas @@ -263,22 +263,25 @@ class quota extends baseModule { $this->quota[$i][7] = $post[$i . '_7']; // Check if values are OK and set automatic values. if not error-variable will be set if (!get_preg($this->quota[$i][2], 'digit')) - $errors[$this->quota[$i][2]][] = $this->messages['softblock'][0]; + $triggered_messages[$this->quota[$i][2]][] = $this->messages['softblock'][0]; if (!get_preg($this->quota[$i][3], 'digit')) - $errors[$this->quota[$i][3]][] = $this->messages['hardblock'][0]; + $triggered_messages[$this->quota[$i][3]][] = $this->messages['hardblock'][0]; if (!get_preg($this->quota[$i][6], 'digit')) - $errors[$this->quota[$i][6]][] = $this->messages['softinode'][0]; + $triggered_messages[$this->quota[$i][6]][] = $this->messages['softinode'][0]; if (!get_preg($this->quota[$i][7], 'digit')) - $errors[$this->quota[$i][7]][] = $this->messages['hardinode'][0]; + $triggered_messages[$this->quota[$i][7]][] = $this->messages['hardinode'][0]; if (intval($this->quota[$i][2]) > intval($this->quota[$i][3])) - $errors[$this->quota[$i][2]][] = $this->messages['block_cmp'][0]; + $triggered_messages[$this->quota[$i][2]][] = $this->messages['block_cmp'][0]; if (intval($this->quota[$i][6]) > intval($this->quota[$i][7])) - $errors[$this->quota[$i][6]][] = $this->messages['inode_cmp'][0]; + $triggered_messages[$this->quota[$i][6]][] = $this->messages['inode_cmp'][0]; $i++; } - // Return error-messages - if (is_array($errors)) return $errors; + if (count($triggered_messages)!=0) { + $this->triggered_messages = $triggered_messages; + return $triggered_messages; + } + else $this->triggered_messages = array(); // Go to additional group page when no error did ocour and button was pressed return 0; } @@ -287,7 +290,7 @@ class quota extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Mountpoint') ), 1 => array ( 'kind' => 'text', 'text' => _('Used blocks') ), diff --git a/lam/lib/modules/sambaAccount.inc b/lam/lib/modules/sambaAccount.inc index 3d0f42d7..760a8268 100644 --- a/lam/lib/modules/sambaAccount.inc +++ b/lam/lib/modules/sambaAccount.inc @@ -175,8 +175,8 @@ class sambaAccount extends baseModule { // Array of well known rids var $rids; - /* $attribute['lmPassword'] and ntPassword can't accessed directly because it's enrcypted - * To read / write password function userPassword is needed + /* $attribute['lmPassword'] and $attribute['ntPassword'] can't accessed directly because it's enrcypted + * To read / write password function lmPassword is needed * This function will return the unencrypted password when * called without a variable * If it's called with a new password, the @@ -185,7 +185,9 @@ class sambaAccount extends baseModule { function lmPassword($newpassword=false) { if (is_string($newpassword)) { // Write new password - $this->attributes['lmPassword'][0] = base64_encode($_SESSION['ldap']->encrypt($newpassword)); + if ($newpassword=='') + $this->attributes['lmPassword'][0] = ''; + else $this->attributes['lmPassword'][0] = base64_encode($_SESSION['ldap']->encrypt($newpassword)); return 0; } else { @@ -303,7 +305,7 @@ class sambaAccount extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { $this->attributes['domain'][0] = $post['domain']; // Start character $flag = "["; @@ -320,7 +322,7 @@ class sambaAccount extends baseModule { $flag = $flag. "]"; $this->attributes['acctFlags'][0] = $flag; - if ($_SESSION[$this->base]->type=='host' && !$profile) { + if ($_SESSION[$this->base]->type=='host') { $this->attributes['primaryGroupID'][0] = $this->rids[_('Domain Computers')]; if ($post['ResetSambaPassword']) { // *** fixme. What is the default password? @@ -339,84 +341,86 @@ class sambaAccount extends baseModule { $this->attributes['homeDrive'][0] = $post['homeDrive']; $this->attributes['scriptPath'][0] = stripslashes($post['scriptPath']); $this->attributes['profilePath'][0] = stripslashes($post['profilePath']); - if (!$profile) { - $rids = array_keys($this->rids); - $wrid = false; - for ($i=0; $iattributes['primaryGroupID'][0] = $this->rids[$rids[$i]]; - } + $rids = array_keys($this->rids); + $wrid = false; + for ($i=0; $iattributes['primaryGroupID'][0] = $this->rids[$rids[$i]]; } - if (!$wrid) $this->attributes['primaryGroupID'][0] = ($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]*2)+1001; - - if (isset($post['lmPassword'])) { - if ($post['lmPassword'] != $post['lmPassword2']) { - $errors['lmPassword'][] = $this->messages['lmPassword'][0]; - unset ($post['lmPassword2']); - } - else $this->lmPassword($post['lmPassword']); - } - if ($post['rid']== _('Administrator')) { - $this->attributes['rid'][0] = "500"; - // Do a check if an administrator already exists - if ($_SESSION['cache']->in_cache("500", 'rid', 'user')!=$_SESSION[$this->base]->dn_orig) - $errors['rid'][] = $this->messages['rid'][0]; - } - if ($post['rid']== _('Guest')) { - $this->attributes['rid'][0] = "501"; - // Do a check if an administrator already exists - if ($_SESSION['cache']->in_cache("501", 'rid', 'user')!=$_SESSION[$this->base]->dn_orig) - $errors['rid'][] = $this->messages['rid'][1]; - } - $this->attributes['smbHome'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['smbHome'][0]); - $this->attributes['smbHome'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['smbHome'][0]); - if ($this->attributes['smbHome'][0] != stripslashes($post['smbHome'])) $errors['smbHome'][] = $this->messages['homePath'][1]; - $this->attributes['scriptPath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['scriptPath'][0]); - $this->attributes['scriptPath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['scriptPath'][0]); - if ($this->attributes['scriptPath'][0] != stripslashes($post['scriptPath'])) $errors['scriptPath'][] = $this->messages['logonScript'][1]; - $this->attributes['profilePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['profilePath'][0]); - $this->attributes['profilePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['profilePath'][0]); - if ($this->attributes['profiletPath'][0] != stripslashes($post['profilePath'])) $errors['profilePath'][] = $this->messages['profilePath'][1]; - if ( !get_preg($this->lmPassword(), 'passord')) $errors['lmPassword'][] = $this->messages['lmPassword'][1]; - if ( (!$this->attributes['smbHome'][0]=='') && (!get_preg($this->attributes['smbHome'][0], 'UNC'))) - $errors['smbHome'][] = $this->messages['homedir'][0]; - if ( (!$this->attributes['scriptPath'][0]=='') && (!get_preg($this->attributes['scriptPath'][0], 'logonscript'))) - $errors['scriptPath'][] = $this->messages['logonScript'][0]; - if ( (!$this->attributes['profilePath'][0]=='') && (!get_preg($this->attributes['profilePath'][0], 'UNC'))) - $errors['profilePath'][] = $this->messages['profilePath'][0]; } - else { - $smbHome = str_replace('$user', 'user', $this->attributes['smbHome'][0]); - $smbHome = str_replace('$group', 'group', $smbHome); - $scriptPath = str_replace('$user', 'user', $this->attributes['scriptPath'][0]); - $scriptPath = str_replace('$group', 'group', $scriptPath); - $profilePath = str_replace('$user', 'user', $this->attributes['profilePath'][0]); - $profilePath = str_replace('$group', 'group', $profilePath); - if ( (!$smbHome=='') && (!get_preg($smbHome, 'UNC'))) - $errors['smbHome'][] = $this->messages['homePath'][0]; - if ( (!$scriptPath=='') && (!get_preg($scriptPath, 'logonscript'))) - $errors['scriptPath'][] = $this->messages['logonScript'][0]; - if ( (!$profilePath=='') && (!get_preg('^[/][a-z]([a-z]|[0-9]|[.]|[-]|[_]|[%])*([/][a-z]([a-z]|[0-9]|[.]|[-]|[_]|[%])*)*$', $profilePath)) - && (!get_preg($profilePath, 'UNC'))) - $errors['profilePath'][] = $this->messages['profilePath'][0]; - } - + if (!$wrid) $this->attributes['primaryGroupID'][0] = ($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]*2)+1001; if ($post['useunixpwd']) $this->useunixpwd = true; else $this->useunixpwd = false; + if (isset($post['lmPassword'])) { + if ($post['lmPassword'] != $post['lmPassword2']) { + $triggered_messages['lmPassword'][] = $this->messages['lmPassword'][0]; + unset ($post['lmPassword2']); + } + else { + if ( !get_preg($this->lmPassword(), 'password')) $triggered_messages['lmPassword'][] = $this->messages['lmPassword'][1]; + else $this->lmPassword($post['lmPassword']); + } + } + if ($post['rid']== _('Administrator')) { + $this->attributes['rid'][0] = "500"; + // Do a check if an administrator already exists + if ($_SESSION['cache']->in_cache("500", 'rid', 'user')!=$_SESSION[$this->base]->dn_orig) + $triggered_messages['rid'][] = $this->messages['rid'][0]; + } + if ($post['rid']== _('Guest')) { + $this->attributes['rid'][0] = "501"; + // Do a check if an administrator already exists + if ($_SESSION['cache']->in_cache("501", 'rid', 'user')!=$_SESSION[$this->base]->dn_orig) + $triggered_messages['rid'][] = $this->messages['rid'][1]; + } + $this->attributes['smbHome'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['smbHome'][0]); + $this->attributes['smbHome'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['smbHome'][0]); + if ($this->attributes['smbHome'][0] != stripslashes($post['smbHome'])) $triggered_messages['smbHome'][] = $this->messages['homePath'][1]; + $this->attributes['scriptPath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['scriptPath'][0]); + $this->attributes['scriptPath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['scriptPath'][0]); + if ($this->attributes['scriptPath'][0] != stripslashes($post['scriptPath'])) $triggered_messages['scriptPath'][] = $this->messages['logonScript'][1]; + $this->attributes['profilePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['profilePath'][0]); + $this->attributes['profilePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['profilePath'][0]); + if ($this->attributes['profiletPath'][0] != stripslashes($post['profilePath'])) $triggered_messages['profilePath'][] = $this->messages['profilePath'][1]; + if ( (!$this->attributes['smbHome'][0]=='') && (!get_preg($this->attributes['smbHome'][0], 'UNC'))) + $triggered_messages['smbHome'][] = $this->messages['homedir'][0]; + if ( (!$this->attributes['scriptPath'][0]=='') && (!get_preg($this->attributes['scriptPath'][0], 'logonscript'))) + $triggered_messages['scriptPath'][] = $this->messages['logonScript'][0]; + if ( (!$this->attributes['profilePath'][0]=='') && (!get_preg($this->attributes['profilePath'][0], 'UNC'))) + $triggered_messages['profilePath'][] = $this->messages['profilePath'][0]; + } + else { + $smbHome = str_replace('$user', 'user', $this->attributes['smbHome'][0]); + $smbHome = str_replace('$group', 'group', $smbHome); + $scriptPath = str_replace('$user', 'user', $this->attributes['scriptPath'][0]); + $scriptPath = str_replace('$group', 'group', $scriptPath); + $profilePath = str_replace('$user', 'user', $this->attributes['profilePath'][0]); + $profilePath = str_replace('$group', 'group', $profilePath); + if ( (!$smbHome=='') && (!get_preg($smbHome, 'UNC'))) + $triggered_messages['smbHome'][] = $this->messages['homePath'][0]; + if ( (!$scriptPath=='') && (!get_preg($scriptPath, 'logonscript'))) + $triggered_messages['scriptPath'][] = $this->messages['logonScript'][0]; + if ( (!$profilePath=='') && (!get_preg('^[/][a-z]([a-z]|[0-9]|[.]|[-]|[_]|[%])*([/][a-z]([a-z]|[0-9]|[.]|[-]|[_]|[%])*)*$', $profilePath)) + && (!get_preg($profilePath, 'UNC'))) + $triggered_messages['profilePath'][] = $this->messages['profilePath'][0]; } if ((!$this->attributes['domain'][0]=='') && !get_preg($this->attributes['domain'][0], 'domainname')) - $errors['domain'][] = $this->messages['domain'][0]; + $triggered_messages['domain'][] = $this->messages['domain'][0]; - if (is_array($errors)) return $errors; + if (count($triggered_messages)!=0) { + $this->triggered_messages = $triggered_messages; + return $triggered_messages; + } + else $this->triggered_messages = array(); if ($post['userWorkstations']) return 'userWorkstations'; return 0; } /* Write variables into object and do some regexp checks */ - function proccess_userWorkstations($post, $profile=false) { + function proccess_userWorkstations($post) { // Load attributes if ($_SESSION[$this->base]->type=='user') { do { // X-Or, only one if() can be true @@ -467,7 +471,7 @@ class sambaAccount extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { if ($_SESSION[$this->base]->type=='user') { $canchangedate = getdate($this->attributes['pwdCanChange'][0]); $mustchangedate = getdate($this->attributes['pwdMustChange'][0]); @@ -479,17 +483,13 @@ class sambaAccount extends baseModule { 5 => array ( 'kind' => 'input', 'name' => 'pwdMustChange_s', 'type' => 'hidden', 'value' => $mustchangedate['seconds']), 6 => array ( 'kind' => 'input', 'name' => 'acctFlagsU', 'type' => 'hidden', 'value' => 'true')); - if (!$profile) { - if ($this->attributes['lmPassword'][0] != $this->orig['lmPassword'][0]) $password=$this->lmPassword(); - else if ($this->attributes['lmPassword'][0] != '') $password=$post['lmPassword']; - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Samba password') ), - 1 => array ( 'kind' => 'input', 'name' => 'lmPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password)); - if ($post['lmPassword2']!='') $password2 = $post['lmPassword2']; - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), - 1 => array ( 'kind' => 'input', 'name' => 'lmPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), - 2 => array ('kind' => 'help', 'value' => 'lmPassword')); - } - + if ($post['lmPassword2']!='') $password2 = $post['lmPassword2']; + else $password2 = $this->lmPassword(); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Samba password') ), + 1 => array ( 'kind' => 'input', 'name' => 'lmPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $this->lmPassword())); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), + 1 => array ( 'kind' => 'input', 'name' => 'lmPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), + 2 => array ('kind' => 'help', 'value' => 'lmPassword')); if ($_SESSION[$this->base]->module['posixAccount']->orig['userPassword'][0] != $_SESSION[$this->base]->module['posixAccount']->attributes['userPassword'][0]) { $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Use unix password') ), 1 => array ( 'kind' => 'input', 'name' => 'useunixpwd', 'type' => 'checkbox', 'checked' => $this->useunixpwd, 'value' => true), @@ -546,56 +546,50 @@ class sambaAccount extends baseModule { 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'userWorkstations', 'value' => _('Edit workstations')), 2 => array ( 'kind' => 'help', 'value' => 'userWorkstations' )); - if (!$profile) { - $names = array_keys($this->rids); - $wrid=false; - for ($i=0; $iattributes['primaryGroupID'][0]==$this->rids[$names[$i]]) { - $selected[] = $names[$i]; - $wrid=true; - } - else $options[] = $names[$i]; - } - if ($wrid) $options[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); - else $selected[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Windows group') ), - 1 => array ( 'kind' => 'select', 'name' => 'primaryGroupID', 'options' => $options, 'options_selected' => $selected), - 2 => array ( 'kind' => 'help', 'value' => 'primaryGroupID' )); - // Display if group SID should be mapped to a well kown SID - $wrid=false; - if ($this->attributes['rid'][0]=="500") { - $selected[] = _('Administrator'); + $names = array_keys($this->rids); + $wrid=false; + for ($i=0; $iattributes['primaryGroupID'][0]==$this->rids[$names[$i]]) { + $selected[] = $names[$i]; $wrid=true; } - else $options[] = _('Administrator'); - if ($this->attributes['rid'][0]=="501") { - $selected[] = _('Guest'); - $wrid=true; - } - else $options[] = _('Guest'); - if ($wrid) $options[] = _('Ordinary user'); - else $selected[] = _('Ordinary user'); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Special user') ), - 1 => array ( 'kind' => 'select', 'name' => 'rid', 'options' => $options, 'options_selected' => $selected), - 2 => array ( 'kind' => 'help', 'value' => 'rid' )); + else $options[] = $names[$i]; } - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Domain') ), - 1 => array ( 'kind' => 'input', 'type' => 'text', 'name' => 'domain', 'size' => '20', 'maxlength' => '255', 'value' => $this->attributes['domain'][0]), - 2 => array ( 'kind' => 'help', 'value' => 'domain' )); + if ($wrid) $options[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); + else $selected[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Windows group') ), + 1 => array ( 'kind' => 'select', 'name' => 'primaryGroupID', 'options' => $options, 'options_selected' => $selected), + 2 => array ( 'kind' => 'help', 'value' => 'primaryGroupID' )); + // Display if group SID should be mapped to a well kown SID + $wrid=false; + if ($this->attributes['rid'][0]=="500") { + $selected[] = _('Administrator'); + $wrid=true; + } + else $options[] = _('Administrator'); + if ($this->attributes['rid'][0]=="501") { + $selected[] = _('Guest'); + $wrid=true; + } + else $options[] = _('Guest'); + if ($wrid) $options[] = _('Ordinary user'); + else $selected[] = _('Ordinary user'); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Special user') ), + 1 => array ( 'kind' => 'select', 'name' => 'rid', 'options' => $options, 'options_selected' => $selected), + 2 => array ( 'kind' => 'help', 'value' => 'rid' )); } - + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Domain') ), + 1 => array ( 'kind' => 'input', 'type' => 'text', 'name' => 'domain', 'size' => '20', 'maxlength' => '255', 'value' => $this->attributes['domain'][0]), + 2 => array ( 'kind' => 'help', 'value' => 'domain' )); if ($_SESSION[$this->base]->type=='host') { $return[] = array ( 0 => array ( 'kind' => 'input', 'name' => 'acctFlagsW', 'type' => 'hidden', 'value' => 'true' )); - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Reset password') ), - 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'ResetSambaPassword'), - 2 => array ( 'kind' => 'help', 'value' => 'ResetSambaPassword' )); - } - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Domain') ), - 1 => array ( 'kind' => 'input', 'type' => 'text', 'name' => 'domain', 'size' => '20', 'maxlength' => '255', 'value' => $this->attributes['domain'][0]), - 2 => array ( 'kind' => 'help', 'value' => 'domain' )); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Reset password') ), + 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'ResetSambaPassword'), + 2 => array ( 'kind' => 'help', 'value' => 'ResetSambaPassword' )); } - + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Domain') ), + 1 => array ( 'kind' => 'input', 'type' => 'text', 'name' => 'domain', 'size' => '20', 'maxlength' => '255', 'value' => $this->attributes['domain'][0]), + 2 => array ( 'kind' => 'help', 'value' => 'domain' )); return $return; } diff --git a/lam/lib/modules/sambaGroupMapping.inc b/lam/lib/modules/sambaGroupMapping.inc index 8e730e2d..f6cb1cbe 100644 --- a/lam/lib/modules/sambaGroupMapping.inc +++ b/lam/lib/modules/sambaGroupMapping.inc @@ -81,7 +81,7 @@ class sambaGroupMapping extends baseModule { for ($i = 0; $i < sizeof($domains); $i++) { $nameToRIDBase[$domains[$i]->name] = $domains[$i]->RIDbase; } - $errors = array(); + $triggered_messages = array(); for ($i = 0; $i < sizeof($rawAccounts); $i++) { // group type if ($rawAccounts[$i][$ids['sambaGroupMapping_groupType']] != "") { @@ -94,7 +94,7 @@ class sambaGroupMapping extends baseModule { else { // invalid type $errMsg = $this->messages['groupType'][0]; array_push($errMsg, array($i, implode(", ", array_keys($this->sambaGroupTypes) + $this->sambaGroupTypes))); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } } else { @@ -107,7 +107,7 @@ class sambaGroupMapping extends baseModule { $errMsg = $this->messages['sambaSID'][1]; array_push($errMsg, $rawAccounts[$i][$ids['sambaGroupMapping_domain']]); array_push($errMsg, $i); - $errors[] = $errMsg; + $triggered_messages[] = $errMsg; } else { // RID @@ -130,7 +130,7 @@ class sambaGroupMapping extends baseModule { $partialAccounts[$i]['displayName'] = $rawAccounts[$i][$ids['sambaGroupMapping_name']]; } } - return $errors; + return $triggered_messages; } function delete_attributes($post) { @@ -142,7 +142,7 @@ class sambaGroupMapping extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { // Get Domain SID from name $sambaDomains = search_domains($_SESSION['config']->get_domainSuffix()); // Get Domain-SID from group SID @@ -160,22 +160,20 @@ class sambaGroupMapping extends baseModule { 1 => array ( 'kind' => 'input', 'name' => 'displayName', 'type' => 'text', 'size' => '30', 'maxlength' => '50', 'value' => $this->attributes['displayName'][0]), 2 => array ( 'kind' => 'help', 'value' => 'displayName' )); - if (!$profile) { - $names = array_keys($this->rids); - $wrid=false; - for ($i=0; $iattributes['sambaSID'][0]==$SID."-".$this->rids[$names[$i]]) { - $selected[] = $names[$i]; - $wrid=true; - } - else $options[] = $names[$i]; - } - if ($wrid) $options[] = $_SESSION[$this->base]->module['posixGroup']->attributes['cn'][0]; - else $selected[] = $_SESSION[$this->base]->module['posixGroup']->attributes['cn'][0]; - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Windows group') ), - 1 => array ( 'kind' => 'select', 'name' => 'sambaSID', 'options' => $options, 'options_selected' => $selected), - 2 => array ( 'kind' => 'help', 'value' => 'sambaSID' )); + $names = array_keys($this->rids); + $wrid=false; + for ($i=0; $iattributes['sambaSID'][0]==$SID."-".$this->rids[$names[$i]]) { + $selected[] = $names[$i]; + $wrid=true; + } + else $options[] = $names[$i]; } + if ($wrid) $options[] = $_SESSION[$this->base]->module['posixGroup']->attributes['cn'][0]; + else $selected[] = $_SESSION[$this->base]->module['posixGroup']->attributes['cn'][0]; + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Windows group') ), + 1 => array ( 'kind' => 'select', 'name' => 'sambaSID', 'options' => $options, 'options_selected' => $selected), + 2 => array ( 'kind' => 'help', 'value' => 'sambaSID' )); $names = array_keys($this->sambaGroupTypes); $selected = array( _('Domain Group') ); @@ -371,40 +369,40 @@ class sambaGroupMapping extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { // Save attributes $this->attributes['displayName'][0] = $post['displayName']; $this->attributes['sambaGroupType'][0] = $this->sambaGroupTypes[$post['sambaGroupType']]; - if (!$profile) { - // Get Domain SID from name - $sambaDomains = search_domains($_SESSION['config']->get_domainSuffix()); - for ($i=0; $iname) { - $SID = $sambaDomains[$i]->SID; - $RIDbase = $sambaDomain[$i]->RIDbase; - } - - // Load attributes - $this->attributes['displayName'][0] = $post['displayName']; - - $rids = array_keys($this->rids); - $wrid = false; - for ($i=0; $iattributes['sambaSID'][0] = $SID."-".$this->rids[$rids[$i]]; - // Do a check if special grou pis unique - if ($_SESSION['cache']->in_cache($SID."-".$this->rids[$rids[$i]], 'sambaSID', 'group')) - $errors[] = $this->messages['sambaSID'][0]; - } + // Get Domain SID from name + $sambaDomains = search_domains($_SESSION['config']->get_domainSuffix()); + for ($i=0; $iname) { + $SID = $sambaDomains[$i]->SID; + $RIDbase = $sambaDomain[$i]->RIDbase; + } + // Load attributes + $this->attributes['displayName'][0] = $post['displayName']; + $rids = array_keys($this->rids); + $wrid = false; + for ($i=0; $iattributes['sambaSID'][0] = $SID."-".$this->rids[$rids[$i]]; + // Do a check if special grou pis unique + if ($_SESSION['cache']->in_cache($SID."-".$this->rids[$rids[$i]], 'sambaSID', 'group')) + $triggered_messages[] = $this->messages['sambaSID'][0]; } - if (!$wrid) $this->attributes['sambaSID'][0] = $SID . "-" . ($_SESSION[$this->base]->module['posixGroup']->attributes['gidNumber'][0]*2+$RIDbase+1); } + if (!$wrid) $this->attributes['sambaSID'][0] = $SID . "-" . ($_SESSION[$this->base]->module['posixGroup']->attributes['gidNumber'][0]*2+$RIDbase+1); // Return error-messages - if (is_array($errors)) return $errors; + if (count($triggered_messages)!=0) { + $this->triggered_messages = $triggered_messages; + return $triggered_messages; + } + else $this->triggered_messages = array(); return 0; } diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 03cd0e9f..fa8d4260 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -116,8 +116,8 @@ class sambaSamAccount extends baseModule { var $rids; - /* $attribute['sambaLMPassword'] and sambaNTPassword can't accessed directly because it's enrcypted - * To read / write password function userPassword is needed + /* $attribute['sambaLMPassword'] and $attribute['sambaNTPassword'] can't accessed directly because it's enrcypted + * To read / write password function sambaLMPassword is needed * This function will return the unencrypted password when * called without a variable * If it's called with a new password, the @@ -127,7 +127,7 @@ class sambaSamAccount extends baseModule { if (is_string($newpassword)) { // Write new password if ($newpassword=='') - $this->attributes['userPassword'][0] = ''; + $this->attributes['sambaLMPassword'][0] = ''; else $this->attributes['sambaLMPassword'][0] = base64_encode($_SESSION['ldap']->encrypt($newpassword)); return 0; } @@ -178,17 +178,6 @@ class sambaSamAccount extends baseModule { return false; } - /* This function returns all ldap attributes - * which are part of posixAccount and returns - * also their values. - */ - function get_attributes() { - $return = $this->attributes; - $return['sambaLMPassword'] = $this->sambaLMPassword(); - $return['sambaNTPassword'] = $this->sambaLMPassword(); - return $return; - } - /* This function loads all attributes into the object * $attr is an array as it's retured from ldap_get_attributes */ @@ -267,7 +256,7 @@ class sambaSamAccount extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { // Save attributes $this->attributes['sambaDomainName'][0] = $post['sambaDomainName']; // Get Domain SID from name @@ -321,74 +310,76 @@ class sambaSamAccount extends baseModule { if ($post['useunixpwd']) $this->useunixpwd = true; else $this->useunixpwd = false; - if (isset($post['sambaLMPassword']) && !$profile) { + if (isset($post['sambaLMPassword'])) { if ($post['sambaLMPassword'] != $post['sambaLMPassword2']) { - $errors['sambaLMPassword'][] = $this->messages['sambaLMPassword'][0]; + $triggered_messages['sambaLMPassword'][] = $this->messages['sambaLMPassword'][0]; unset ($post['sambaLMPassword2']); } else { - if ( !get_preg($this->sambaLMPassword(), 'password')) $errors['sambaLMPassword'][] = $this->messages['sambaLMPassword'][1]; + if ( !get_preg($this->sambaLMPassword(), 'password')) $triggered_messages['sambaLMPassword'][] = $this->messages['sambaLMPassword'][1]; else $this->sambaLMPassword($post['sambaLMPassword']); } } - if (!$profile) { - if ($post['sambaSID']== _('Administrator')) { - $this->attributes['sambaSID'][0] = $SID."-500"; - // Do a check if an administrator already exists - if ($_SESSION['cache']->in_cache($SID."-500", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig) - $errors['sambaSID'][] = $this->messages['rid'][0]; - } - else if ($post['sambaSID']== _('Guest')) { - $this->attributes['sambaSID'][0] = $SID."-501"; - // Do a check if an guest already exists - if ($_SESSION['cache']->in_cache($SID."-501", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig) - $errors['sambaSID'][] = $this->messages['rid'][1]; - } - else if ($post['sambaSID']== _('Ordinary user')) { - $this->attributes['sambaSID'][0] = $SID."-". (($_SESSION[$this->base]->module['posixAccount']->attributes['uidNumber'][0]*2)+$RIDbase); + if ($post['sambaSID']== _('Administrator')) { + $this->attributes['sambaSID'][0] = $SID."-500"; + // Do a check if an administrator already exists + if ($_SESSION['cache']->in_cache($SID."-500", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig) + $triggered_messages['sambaSID'][] = $this->messages['rid'][0]; } - // Check values - $this->attributes['sambaHomePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaHomePath'][0]); - $this->attributes['sambaHomePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaHomePath'][0]); - if ($this->attributes['sambaHomePath'][0] != stripslashes($post['sambaHomePath'])) $errors['sambaHomePath'][] = $this->messages['homePath'][1]; - $this->attributes['sambaLogonScript'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaLogonScript'][0]); - $this->attributes['sambaLogonScript'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaLogonScript'][0]); - if ($this->attributes['sambaLogonScript'][0] != stripslashes($post['sambaLogonScript'])) $errors['sambaLogonScript'][] = $this->messages['logonScript'][1]; - $this->attributes['sambaProfilePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaProfilePath'][0]); - $this->attributes['sambaProfilePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaProfilePath'][0]); - if ($this->attributes['sambaProfilePath'][0] != stripslashes($post['sambaProfilePath'])) $errors['sambaProfilePath'][] = $this->messages['profilePath'][1]; - if ( (!$this->attributes['sambaHomePath'][0]=='') && (!get_preg($this->attributes['sambaHomePath'][0], 'UNC'))) - $errors['sambaHomePath'][] = $this->messages['homePath'][0]; - if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript'))) - $errors['sambaScriptPath'][] = $this->messages['logonScript'][0]; - if (!($this->attributes['sambaProfilePath'][0] == '') && - !(get_preg($this->attributes['sambaProfilePath'][0], 'UNC') xor get_preg($this->attributes['sambaProfilePath'][0], 'homeDirectory'))) - $errors['sambaProfilePath'][] = $this->messages['profilePath'][0]; - } - else { - $sambaHomePath = str_replace('$user', 'user', $this->attributes['sambaHomePath'][0]); - $sambaHomePath = str_replace('$group', 'group', $sambaHomePath); - $sambaLogonScript = str_replace('$user', 'user', $this->attributes['sambaLogonScript'][0]); - $sambaLogonScript = str_replace('$group', 'group', $sambaLogonScript); - $sambaProfilePath = str_replace('$user', 'user', $this->attributes['sambaProfilePath'][0]); - $sambaProfilePath = str_replace('$group', 'group', $sambaProfilePath); - if ( (!$this->attributes['sambaHomePath'][0]=='') && (!get_preg($this->attributes['sambaHomePath'][0], 'UNC'))) - $errors[] = $this->messages['homePath'][0]; - if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript'))) - $errors[] = $this->messages['logonScript'][0]; - if ( (!$this->attributes['sambaProfilePath'][0]=='') && (!get_preg($this->attributes['sambaProfilePath'][0], 'UNC')) - && (!get_preg($this->attributes['sambaProfilePath'][0], 'UNC'))) - $errors[] = $this->messages['profilePath'][0]; + else if ($post['sambaSID']== _('Guest')) { + $this->attributes['sambaSID'][0] = $SID."-501"; + // Do a check if an guest already exists + if ($_SESSION['cache']->in_cache($SID."-501", 'sambaSID', 'user')!=$_SESSION[$this->base]->dn_orig) + $triggered_messages['sambaSID'][] = $this->messages['rid'][1]; } + else if ($post['sambaSID']== _('Ordinary user')) { + $this->attributes['sambaSID'][0] = $SID."-". (($_SESSION[$this->base]->module['posixAccount']->attributes['uidNumber'][0]*2)+$RIDbase); } - if (is_array($errors)) return $errors; + // Check values + $this->attributes['sambaHomePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaHomePath'][0]); + $this->attributes['sambaHomePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaHomePath'][0]); + if ($this->attributes['sambaHomePath'][0] != stripslashes($post['sambaHomePath'])) $triggered_messages['sambaHomePath'][] = $this->messages['homePath'][1]; + $this->attributes['sambaLogonScript'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaLogonScript'][0]); + $this->attributes['sambaLogonScript'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaLogonScript'][0]); + if ($this->attributes['sambaLogonScript'][0] != stripslashes($post['sambaLogonScript'])) $triggered_messages['sambaLogonScript'][] = $this->messages['logonScript'][1]; + $this->attributes['sambaProfilePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['uid'][0], $this->attributes['sambaProfilePath'][0]); + $this->attributes['sambaProfilePath'][0] = str_replace('$group', $_SESSION[$this->base]->module['inetOrgPerson']->attributes['gid'][0], $this->attributes['sambaProfilePath'][0]); + if ($this->attributes['sambaProfilePath'][0] != stripslashes($post['sambaProfilePath'])) $triggered_messages['sambaProfilePath'][] = $this->messages['profilePath'][1]; + if ( (!$this->attributes['sambaHomePath'][0]=='') && (!get_preg($this->attributes['sambaHomePath'][0], 'UNC'))) + $triggered_messages['sambaHomePath'][] = $this->messages['homePath'][0]; + if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript'))) + $triggered_messages['sambaScriptPath'][] = $this->messages['logonScript'][0]; + if (!($this->attributes['sambaProfilePath'][0] == '') && + !(get_preg($this->attributes['sambaProfilePath'][0], 'UNC') xor get_preg($this->attributes['sambaProfilePath'][0], 'homeDirectory'))) + $triggered_messages['sambaProfilePath'][] = $this->messages['profilePath'][0]; + } + else { + $sambaHomePath = str_replace('$user', 'user', $this->attributes['sambaHomePath'][0]); + $sambaHomePath = str_replace('$group', 'group', $sambaHomePath); + $sambaLogonScript = str_replace('$user', 'user', $this->attributes['sambaLogonScript'][0]); + $sambaLogonScript = str_replace('$group', 'group', $sambaLogonScript); + $sambaProfilePath = str_replace('$user', 'user', $this->attributes['sambaProfilePath'][0]); + $sambaProfilePath = str_replace('$group', 'group', $sambaProfilePath); + if ( (!$this->attributes['sambaHomePath'][0]=='') && (!get_preg($this->attributes['sambaHomePath'][0], 'UNC'))) + $triggered_messages[] = $this->messages['homePath'][0]; + if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript'))) + $triggered_messages[] = $this->messages['logonScript'][0]; + if ( (!$this->attributes['sambaProfilePath'][0]=='') && (!get_preg($this->attributes['sambaProfilePath'][0], 'UNC')) + && (!get_preg($this->attributes['sambaProfilePath'][0], 'UNC'))) + $triggered_messages[] = $this->messages['profilePath'][0]; + } + if (count($triggered_messages)!=0) { + $this->triggered_messages = $triggered_messages; + return $triggered_messages; + } + else $this->triggered_messages = array(); if ($post['sambaUserWorkstations']) return 'sambaUserWorkstations'; return 0; } /* Write variables into object and do some regexp checks */ - function proccess_sambaUserWorkstations($post, $profile=false) { + function proccess_sambaUserWorkstations($post) { // Load attributes if ($_SESSION[$this->base]->type=='user') { do { // X-Or, only one if() can be true @@ -439,7 +430,7 @@ class sambaSamAccount extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { // Get Domain SID from name $sambaDomains = search_domains($_SESSION['config']->get_domainSuffix()); for ($i=0; $i array ( 'kind' => 'input', 'name' => 'sambaPwdMustChange_m', 'type' => 'hidden', 'value' => $mustchangedate['minutes']), 5 => array ( 'kind' => 'input', 'name' => 'sambaPwdMustChange_s', 'type' => 'hidden', 'value' => $mustchangedate['seconds']), 6 => array ( 'kind' => 'input', 'name' => 'sambaAcctFlagsU', 'type' => 'hidden', 'value' => 'true')); - if (!$profile) { - if ($post['sambaLMPassword2']!='') $password2 = $post['sambaLMPassword2']; - else $password2 = $this->sambaLMPassword(); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Samba password') ), - 1 => array ( 'kind' => 'input', 'name' => 'sambaLMPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $this->sambaLMPassword())); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), - 1 => array ( 'kind' => 'input', 'name' => 'sambaLMPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), - 2 => array ('kind' => 'help', 'value' => 'sambaLMPassword')); - } + if ($post['sambaLMPassword2']!='') $password2 = $post['sambaLMPassword2']; + else $password2 = $this->sambaLMPassword(); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Samba password') ), + 1 => array ( 'kind' => 'input', 'name' => 'sambaLMPassword', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $this->sambaLMPassword())); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Repeat password') ), + 1 => array ( 'kind' => 'input', 'name' => 'sambaLMPassword2', 'type' => 'password', 'size' => '20', 'maxlength' => '255', 'value' => $password2), + 2 => array ('kind' => 'help', 'value' => 'sambaLMPassword')); if ($_SESSION[$this->base]->module['posixAccount']->orig['userPassword'][0] != $_SESSION[$this->base]->module['posixAccount']->attributes['userPassword'][0]) { $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Use unix password') ), 1 => array ( 'kind' => 'input', 'name' => 'useunixpwd', 'type' => 'checkbox', 'checked' => $this->useunixpwd), @@ -523,52 +512,48 @@ class sambaSamAccount extends baseModule { 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'sambaUserWorkstations', 'value' => _('Edit workstations')), 2 => array ( 'kind' => 'help', 'value' => 'sambaUserWorkstations' )); - if (!$profile) { - $names = array_keys($this->rids); - $wrid=false; - for ($i=0; $iattributes['sambaPrimaryGroupSID'][0]==$SID."-".$this->rids[$names[$i]]) { - $selected[] = $names[$i]; - $wrid=true; - } - else $options[] = $names[$i]; - } - if ($wrid) $options[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); - else $selected[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Windows group') ), - 1 => array ( 'kind' => 'select', 'name' => 'sambaPrimaryGroupSID', 'options' => $options, 'options_selected' => $selected), - 2 => array ( 'kind' => 'help', 'value' => 'sambaPrimaryGroupSID' )); - // Display if group SID should be mapped to a well kown SID - $wrid=false; - $options = array(); - $selected = array(); - if ($this->attributes['sambaSID'][0]==$SID."-500") { - $selected[] = _('Administrator'); + $names = array_keys($this->rids); + $wrid=false; + for ($i=0; $iattributes['sambaPrimaryGroupSID'][0]==$SID."-".$this->rids[$names[$i]]) { + $selected[] = $names[$i]; $wrid=true; } - else $options[] = _('Administrator'); - if ($this->attributes['sambaSID'][0]==$SIM."-501") { - $selected[] = _('Guest'); - $wrid=true; - } - else $options[] = _('Guest'); - if ($wrid) $options[] = _('Ordinary user'); - else $selected[] = _('Ordinary user'); - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Special user') ), - 1 => array ( 'kind' => 'select', 'name' => 'sambaSID', 'options' => $options, 'options_selected' => $selected), - 2 => array ( 'kind' => 'help', 'value' => 'sambaSID' )); + else $options[] = $names[$i]; } - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Domain') ), - 1 => array ( 'kind' => 'select', 'name' => 'sambaDomainName', 'options' => $sambaDomainNames, 'options_selected' => array($this->attributes['sambaDomainName'][0])), - 2 => array ( 'kind' => 'help', 'value' => 'sambaDomainName' )); + if ($wrid) $options[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); + else $selected[] = $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Windows group') ), + 1 => array ( 'kind' => 'select', 'name' => 'sambaPrimaryGroupSID', 'options' => $options, 'options_selected' => $selected), + 2 => array ( 'kind' => 'help', 'value' => 'sambaPrimaryGroupSID' )); + // Display if group SID should be mapped to a well kown SID + $wrid=false; + $options = array(); + $selected = array(); + if ($this->attributes['sambaSID'][0]==$SID."-500") { + $selected[] = _('Administrator'); + $wrid=true; + } + else $options[] = _('Administrator'); + if ($this->attributes['sambaSID'][0]==$SIM."-501") { + $selected[] = _('Guest'); + $wrid=true; + } + else $options[] = _('Guest'); + if ($wrid) $options[] = _('Ordinary user'); + else $selected[] = _('Ordinary user'); + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Special user') ), + 1 => array ( 'kind' => 'select', 'name' => 'sambaSID', 'options' => $options, 'options_selected' => $selected), + 2 => array ( 'kind' => 'help', 'value' => 'sambaSID' )); } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Domain') ), + 1 => array ( 'kind' => 'select', 'name' => 'sambaDomainName', 'options' => $sambaDomainNames, 'options_selected' => array($this->attributes['sambaDomainName'][0])), + 2 => array ( 'kind' => 'help', 'value' => 'sambaDomainName' )); if ($_SESSION[$this->base]->type=='host') { $return[] = array ( 0 => array ( 'kind' => 'input', 'name' => 'sambaAcctFlagsW', 'type' => 'hidden', 'value' => 'true' )); - if (!$profile) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Reset password') ), - 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'ResetSambaPassword'), - 2 => array ( 'kind' => 'help', 'value' => 'ResetSambaPassword' )); - } + $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Reset password') ), + 1 => array ( 'kind' => 'input', 'type' => 'submit', 'name' => 'ResetSambaPassword'), + 2 => array ( 'kind' => 'help', 'value' => 'ResetSambaPassword' )); $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _('Domain') ), 1 => array ( 'kind' => 'select', 'name' => 'sambaDomainName', 'options' => $sambaDomainNames, 'options_selected' => $this->attributes['sambaDomainName'][0]), 2 => array ( 'kind' => 'help', 'value' => 'sambaDomainName' )); @@ -584,7 +569,7 @@ class sambaSamAccount extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_sambaUserWorkstations($post, $profile=false) { + function display_html_sambaUserWorkstations($post) { if ($_SESSION[$this->base]->type=='user') { // Get list of all hosts. $result = $_SESSION['cache']->get_cache('uid', 'sambaSamAccount', 'host'); diff --git a/lam/lib/modules/shadowAccount.inc b/lam/lib/modules/shadowAccount.inc index 4532ccff..8c70da9e 100644 --- a/lam/lib/modules/shadowAccount.inc +++ b/lam/lib/modules/shadowAccount.inc @@ -164,14 +164,6 @@ class shadowAccount extends baseModule { return array('attributes'); } - /* This function returns all ldap attributes - * which are part of shadowAccount and returns - * also their values. - */ - function get_attributes() { - return $this->attributes; - } - /* This function loads all attributes into the object * $attr is an array as it's retured from ldap_get_attributes */ @@ -213,7 +205,7 @@ class shadowAccount extends baseModule { /* Write variables into object and do some regexp checks */ - function proccess_attributes($post, $profile=false) { + function proccess_attributes($post) { // Load attributes $this->attributes['shadowMin'][0] = $post['shadowMin']; $this->attributes['shadowMax'][0] = $post['shadowMax']; @@ -222,12 +214,16 @@ class shadowAccount extends baseModule { $this->attributes['shadowExpire'][0] = intval(mktime(10, 0, 0, $post['shadowExpire_mon'], $post['shadowExpire_day'], $post['shadowExpire_yea'])/3600/24); - if ( !get_preg($this->attributes['shadowMin'][0], 'digit')) $errors['shadowMin'][] = $this->messages['shadowMin'][0]; - if ( !get_preg($this->attributes['shadowMax'][0], 'digit')) $errors['shadowMax'][] = $this->messages['shadowMax'][0]; - if ( $this->attributes['shadowMin'][0] > $this->attributes['shadowMax'][0]) $errors['shadowMin'][] = $this->messages['shadow_cmp'][0]; - if ( !get_preg($this->attributes['shadowInactive'][0], 'digit2')) $errors['shadowInactive'][] = $this->messages['inactive'][0]; - if ( !get_preg($this->attributes['shadowWarning'][0], 'digit')) $errors['shadowWarning'][] = $this->messages['shadowWarning'][0]; - if (is_array($errors)) return $errors; + if ( !get_preg($this->attributes['shadowMin'][0], 'digit')) $triggered_messages['shadowMin'][] = $this->messages['shadowMin'][0]; + if ( !get_preg($this->attributes['shadowMax'][0], 'digit')) $triggered_messages['shadowMax'][] = $this->messages['shadowMax'][0]; + if ( $this->attributes['shadowMin'][0] > $this->attributes['shadowMax'][0]) $triggered_messages['shadowMin'][] = $this->messages['shadow_cmp'][0]; + if ( !get_preg($this->attributes['shadowInactive'][0], 'digit2')) $triggered_messages['shadowInactive'][] = $this->messages['inactive'][0]; + if ( !get_preg($this->attributes['shadowWarning'][0], 'digit')) $triggered_messages['shadowWarning'][] = $this->messages['shadowWarning'][0]; + if (count($triggered_messages)!=0) { + $this->triggered_messages = $triggered_messages; + return $triggered_messages; + } + else $this->triggered_messages = array(); return 0; } @@ -235,7 +231,7 @@ class shadowAccount extends baseModule { * to show a page with all attributes. * It will output a complete html-table */ - function display_html_attributes($post, $profile=false) { + function display_html_attributes($post) { // Use dd-mm-yyyy format of date because it's easier to read for humans $date = getdate ($this->attributes['shadowExpire'][0]*3600*24);