fixed error handling

This commit is contained in:
Roland Gruber 2006-05-18 08:30:22 +00:00
parent 09ce3a98c2
commit d135ac54a2
1 changed files with 41 additions and 44 deletions

View File

@ -548,6 +548,7 @@ class sambaSamAccount extends baseModule {
* @return array list of info/error messages * @return array list of info/error messages
*/ */
function process_attributes(&$post) { function process_attributes(&$post) {
$errors = array();
$sambaDomains = search_domains(); $sambaDomains = search_domains();
if (sizeof($sambaDomains) == 0) { if (sizeof($sambaDomains) == 0) {
return array(array(array("ERROR", _('No Samba 3 domains found in LDAP! Please create one first.')))); return array(array(array("ERROR", _('No Samba 3 domains found in LDAP! Please create one first.'))));
@ -595,7 +596,7 @@ class sambaSamAccount extends baseModule {
// display name // display name
$this->attributes['displayName'][0] = $post['displayName']; $this->attributes['displayName'][0] = $post['displayName'];
if (!($this->attributes['displayName'][0] == '') && !(get_preg($this->attributes['displayName'][0], 'realname'))) { if (!($this->attributes['displayName'][0] == '') && !(get_preg($this->attributes['displayName'][0], 'realname'))) {
$triggered_messages['displayName'][] = $this->messages['displayName'][1]; $errors['displayName'][] = $this->messages['displayName'][1];
} }
// host attributes // host attributes
@ -659,11 +660,11 @@ class sambaSamAccount extends baseModule {
else $this->useunixpwd = false; else $this->useunixpwd = false;
if (!$this->useunixpwd && isset($post['sambaLMPassword']) && ($post['sambaLMPassword'] != '')) { if (!$this->useunixpwd && isset($post['sambaLMPassword']) && ($post['sambaLMPassword'] != '')) {
if ($post['sambaLMPassword'] != $post['sambaLMPassword2']) { if ($post['sambaLMPassword'] != $post['sambaLMPassword2']) {
$triggered_messages['sambaLMPassword'][] = $this->messages['sambaLMPassword'][0]; $errors['sambaLMPassword'][] = $this->messages['sambaLMPassword'][0];
unset ($post['sambaLMPassword2']); unset ($post['sambaLMPassword2']);
} }
else { else {
if (!get_preg($post['sambaLMPassword'], 'password')) $triggered_messages['sambaLMPassword'][] = $this->messages['sambaLMPassword'][1]; if (!get_preg($post['sambaLMPassword'], 'password')) $errors['sambaLMPassword'][] = $this->messages['sambaLMPassword'][1];
else { else {
$this->attributes['sambaLMPassword'][0] = lmPassword($post['sambaLMPassword']); $this->attributes['sambaLMPassword'][0] = lmPassword($post['sambaLMPassword']);
$this->attributes['sambaNTPassword'][0] = ntPassword($post['sambaLMPassword']); $this->attributes['sambaNTPassword'][0] = ntPassword($post['sambaLMPassword']);
@ -687,31 +688,27 @@ class sambaSamAccount extends baseModule {
// Check values // Check values
$this->attributes['sambaHomePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0], $this->attributes['sambaHomePath'][0]); $this->attributes['sambaHomePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0], $this->attributes['sambaHomePath'][0]);
$this->attributes['sambaHomePath'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]), $this->attributes['sambaHomePath'][0]); $this->attributes['sambaHomePath'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]), $this->attributes['sambaHomePath'][0]);
if ($this->attributes['sambaHomePath'][0] != $post['sambaHomePath']) $triggered_messages['sambaHomePath'][] = $this->messages['homePath'][1]; if ($this->attributes['sambaHomePath'][0] != $post['sambaHomePath']) $errors['sambaHomePath'][] = $this->messages['homePath'][1];
$this->attributes['sambaLogonScript'][0] = str_replace('$user', $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0], $this->attributes['sambaLogonScript'][0]); $this->attributes['sambaLogonScript'][0] = str_replace('$user', $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0], $this->attributes['sambaLogonScript'][0]);
$this->attributes['sambaLogonScript'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]), $this->attributes['sambaLogonScript'][0]); $this->attributes['sambaLogonScript'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]), $this->attributes['sambaLogonScript'][0]);
if ($this->attributes['sambaLogonScript'][0] != $post['sambaLogonScript']) $triggered_messages['sambaLogonScript'][] = $this->messages['logonScript'][1]; if ($this->attributes['sambaLogonScript'][0] != $post['sambaLogonScript']) $errors['sambaLogonScript'][] = $this->messages['logonScript'][1];
$this->attributes['sambaProfilePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0], $this->attributes['sambaProfilePath'][0]); $this->attributes['sambaProfilePath'][0] = str_replace('$user', $_SESSION[$this->base]->module['posixAccount']->attributes['uid'][0], $this->attributes['sambaProfilePath'][0]);
$this->attributes['sambaProfilePath'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]), $this->attributes['sambaProfilePath'][0]); $this->attributes['sambaProfilePath'][0] = str_replace('$group', $_SESSION['cache']->getgrnam($_SESSION[$this->base]->module['posixAccount']->attributes['gidNumber'][0]), $this->attributes['sambaProfilePath'][0]);
if ($this->attributes['sambaProfilePath'][0] != $post['sambaProfilePath']) $triggered_messages['sambaProfilePath'][] = $this->messages['profilePath'][1]; if ($this->attributes['sambaProfilePath'][0] != $post['sambaProfilePath']) $errors['sambaProfilePath'][] = $this->messages['profilePath'][1];
if ( (!$this->attributes['sambaHomePath'][0]=='') && (!get_preg($this->attributes['sambaHomePath'][0], 'UNC'))) if ( (!$this->attributes['sambaHomePath'][0]=='') && (!get_preg($this->attributes['sambaHomePath'][0], 'UNC')))
$triggered_messages['sambaHomePath'][] = $this->messages['homePath'][0]; $errors['sambaHomePath'][] = $this->messages['homePath'][0];
if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript'))) if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript')))
$triggered_messages['sambaScriptPath'][] = $this->messages['logonScript'][0]; $errors['sambaScriptPath'][] = $this->messages['logonScript'][0];
if (!($this->attributes['sambaProfilePath'][0] == '') && if (!($this->attributes['sambaProfilePath'][0] == '') &&
!(get_preg($this->attributes['sambaProfilePath'][0], 'UNC') xor get_preg($this->attributes['sambaProfilePath'][0], 'homeDirectory'))) !(get_preg($this->attributes['sambaProfilePath'][0], 'UNC') xor get_preg($this->attributes['sambaProfilePath'][0], 'homeDirectory')))
$triggered_messages['sambaProfilePath'][] = $this->messages['profilePath'][0]; $errors['sambaProfilePath'][] = $this->messages['profilePath'][0];
} }
else { // host else { // host
if (!$this->attributes['sambaSID'][0]) { if (!$this->attributes['sambaSID'][0]) {
$this->attributes['sambaSID'][0] = $SID."-". (($_SESSION[$this->base]->module['posixAccount']->attributes['uidNumber'][0]*2)+$RIDbase); $this->attributes['sambaSID'][0] = $SID."-". (($_SESSION[$this->base]->module['posixAccount']->attributes['uidNumber'][0]*2)+$RIDbase);
} }
} }
if (count($triggered_messages)!=0) { return $errors;
$this->triggered_messages = $triggered_messages;
return $triggered_messages;
}
else $this->triggered_messages = array();
} }
/** /**
@ -721,7 +718,7 @@ class sambaSamAccount extends baseModule {
* @param array $post HTTP-POST values * @param array $post HTTP-POST values
* @return array list of info/error messages * @return array list of info/error messages
*/ */
function process_sambaUserWorkstations(&$post) { function process_sambaUserWorkstations($post) {
// Load attributes // Load attributes
if ($_SESSION[$this->base]->type=='user') { if ($_SESSION[$this->base]->type=='user') {
if (isset($post['availableSambaUserWorkstations']) && isset($post['sambaUserWorkstations_add'])) { // Add workstations to list if (isset($post['availableSambaUserWorkstations']) && isset($post['sambaUserWorkstations_add'])) { // Add workstations to list
@ -771,7 +768,7 @@ class sambaSamAccount extends baseModule {
* @param array $post HTTP-POST values * @param array $post HTTP-POST values
* @return array list of info/error messages * @return array list of info/error messages
*/ */
function process_logonHours(&$post) { function process_logonHours($post) {
if ($post['form_subpage_sambaSamAccount_attributes_abort']) return; if ($post['form_subpage_sambaSamAccount_attributes_abort']) return;
// set new logon hours // set new logon hours
$logonHours = ''; $logonHours = '';
@ -795,12 +792,12 @@ class sambaSamAccount extends baseModule {
* to show a page with all attributes. * to show a page with all attributes.
* It will output a complete html-table * It will output a complete html-table
*/ */
function display_html_attributes(&$post) { function display_html_attributes($post) {
// Get Domain SID from user SID // Get Domain SID from user SID
$sambaDomains = search_domains(); $sambaDomains = search_domains();
if (sizeof($sambaDomains) == 0) { if (sizeof($sambaDomains) == 0) {
StatusMessage("ERROR", _('No Samba 3 domains found in LDAP! Please create one first.'), ''); StatusMessage("ERROR", _('No Samba 3 domains found in LDAP! Please create one first.'), '');
return; return array();
} }
if ($this->attributes['sambaSID'][0]!='') { if ($this->attributes['sambaSID'][0]!='') {
$domainSID = substr($this->attributes['sambaSID'][0], 0, strrpos($this->attributes['sambaSID'][0], "-")); $domainSID = substr($this->attributes['sambaSID'][0], 0, strrpos($this->attributes['sambaSID'][0], "-"));
@ -971,7 +968,7 @@ class sambaSamAccount extends baseModule {
* to show a page with all attributes. * to show a page with all attributes.
* It will output a complete html-table * It will output a complete html-table
*/ */
function display_html_sambaUserWorkstations(&$post) { function display_html_sambaUserWorkstations($post) {
if ($_SESSION[$this->base]->type=='user') { if ($_SESSION[$this->base]->type=='user') {
// Get list of all hosts. // Get list of all hosts.
$result = $_SESSION['cache']->get_cache('uid', 'sambaSamAccount', 'host'); $result = $_SESSION['cache']->get_cache('uid', 'sambaSamAccount', 'host');
@ -1006,7 +1003,7 @@ class sambaSamAccount extends baseModule {
* @param array $post HTTP POST variables * @param array $post HTTP POST variables
* @return array meta HTML code * @return array meta HTML code
*/ */
function display_html_logonHours(&$post) { function display_html_logonHours($post) {
$timeZone = 0; $timeZone = 0;
if (isset($this->moduleSettings['sambaSamAccount_timeZone']) && is_array($this->moduleSettings['sambaSamAccount_timeZone'])) { if (isset($this->moduleSettings['sambaSamAccount_timeZone']) && is_array($this->moduleSettings['sambaSamAccount_timeZone'])) {
$timeZone = $this->moduleSettings['sambaSamAccount_timeZone'][0]; $timeZone = $this->moduleSettings['sambaSamAccount_timeZone'][0];
@ -1306,7 +1303,7 @@ class sambaSamAccount extends baseModule {
* @return array list of error messages if any * @return array list of error messages if any
*/ */
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) { function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
$triggered_messages = array(); $errors = array();
// get list of Samba 3 domains // get list of Samba 3 domains
$domains = search_domains(); $domains = search_domains();
// get list of Unix groups and their sambaSID + gidNumber // get list of Unix groups and their sambaSID + gidNumber
@ -1332,7 +1329,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['displayName'][0]; $errMsg = $this->messages['displayName'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// password // password
@ -1340,7 +1337,7 @@ class sambaSamAccount extends baseModule {
if (!get_preg($rawAccounts[$i][$ids['sambaSamAccount_password']], 'password')) { if (!get_preg($rawAccounts[$i][$ids['sambaSamAccount_password']], 'password')) {
$errMsg = $this->messages['sambaLMPassword'][2]; $errMsg = $this->messages['sambaLMPassword'][2];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
// use Unix password // use Unix password
if ($rawAccounts[$i][$ids['sambaSamAccount_pwdUnix']] == "") { // default: use Unix if ($rawAccounts[$i][$ids['sambaSamAccount_pwdUnix']] == "") { // default: use Unix
@ -1360,7 +1357,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['pwdUnix'][0]; $errMsg = $this->messages['pwdUnix'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
// use no password // use no password
if ($rawAccounts[$i][$ids['sambaSamAccount_noPassword']] != "") { if ($rawAccounts[$i][$ids['sambaSamAccount_noPassword']] != "") {
@ -1373,7 +1370,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['noPassword'][0]; $errMsg = $this->messages['noPassword'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// account flags // account flags
@ -1389,7 +1386,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['noExpire'][0]; $errMsg = $this->messages['noExpire'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// account is deactivated // account is deactivated
@ -1402,7 +1399,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['deactivated'][0]; $errMsg = $this->messages['deactivated'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// set flags // set flags
@ -1425,7 +1422,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['pwdCanChange'][0]; $errMsg = $this->messages['pwdCanChange'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// passsword must be changed // passsword must be changed
@ -1438,7 +1435,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['pwdMustChange'][0]; $errMsg = $this->messages['pwdMustChange'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// expiration date // expiration date
@ -1451,7 +1448,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['expireDate'][0]; $errMsg = $this->messages['expireDate'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// home drive // home drive
@ -1462,7 +1459,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['homeDrive'][0]; $errMsg = $this->messages['homeDrive'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// home path // home path
@ -1473,7 +1470,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['homePath'][2]; $errMsg = $this->messages['homePath'][2];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// profile path // profile path
@ -1484,7 +1481,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['profilePath'][2]; $errMsg = $this->messages['profilePath'][2];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// logon script // logon script
@ -1495,7 +1492,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['logonScript'][2]; $errMsg = $this->messages['logonScript'][2];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// workstations // workstations
@ -1506,7 +1503,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['workstations'][1]; $errMsg = $this->messages['workstations'][1];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
// domain // domain
@ -1524,7 +1521,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['domain'][0]; $errMsg = $this->messages['domain'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
// group // group
if ($rawAccounts[$i][$ids['sambaSamAccount_group']] != "") { if ($rawAccounts[$i][$ids['sambaSamAccount_group']] != "") {
@ -1545,7 +1542,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['group'][0]; $errMsg = $this->messages['group'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
else { else {
@ -1563,7 +1560,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['rid'][2]; $errMsg = $this->messages['rid'][2];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
else { else {
@ -1578,7 +1575,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['logonHours'][1]; $errMsg = $this->messages['logonHours'][1];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
else { else {
@ -1605,7 +1602,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['domain'][0]; $errMsg = $this->messages['domain'][0];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
// RID // RID
if ($rawAccounts[$i][$ids['sambaSamAccount_rid']] != "") { if ($rawAccounts[$i][$ids['sambaSamAccount_rid']] != "") {
@ -1615,7 +1612,7 @@ class sambaSamAccount extends baseModule {
else { else {
$errMsg = $this->messages['rid'][3]; $errMsg = $this->messages['rid'][3];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$triggered_messages[] = $errMsg; $errors[] = $errMsg;
} }
} }
else { else {
@ -1629,7 +1626,7 @@ class sambaSamAccount extends baseModule {
$partialAccounts[$i]['sambaAcctFlags'] = "[W ]"; $partialAccounts[$i]['sambaAcctFlags'] = "[W ]";
} }
} }
return $triggered_messages; return $errors;
} }
} }