refactoring

This commit is contained in:
Roland Gruber 2019-11-01 21:01:08 +01:00
parent 22b4da76e9
commit 622a72ef18
1 changed files with 64 additions and 22 deletions

View File

@ -732,11 +732,21 @@ class sambaSamAccount extends baseModule implements passwordService {
else { else {
$this->nopwd = false; $this->nopwd = false;
} }
if (isset($_POST['sambaAcctFlagsS'])) $flag .= "S"; if (isset($_POST['sambaAcctFlagsS'])) {
if (isset($_POST['sambaAcctFlagsH'])) $flag .= "H"; $flag .= "S";
if (isset($_POST['sambaAcctFlagsW'])) $flag .= "W"; }
if (isset($_POST['sambaAcctFlagsU'])) $flag .= "U"; if (isset($_POST['sambaAcctFlagsH'])) {
if (isset($_POST['sambaAcctFlagsL'])) $flag .= "L"; $flag .= "H";
}
if (isset($_POST['sambaAcctFlagsW'])) {
$flag .= "W";
}
if (isset($_POST['sambaAcctFlagsU'])) {
$flag .= "U";
}
if (isset($_POST['sambaAcctFlagsL'])) {
$flag .= "L";
}
// Expand string to fixed length // Expand string to fixed length
$flag = str_pad($flag, 12); $flag = str_pad($flag, 12);
// End character // End character
@ -772,20 +782,28 @@ class sambaSamAccount extends baseModule implements passwordService {
$this->attributes['sambaHomePath'][0] = $_POST['sambaHomePath']; $this->attributes['sambaHomePath'][0] = $_POST['sambaHomePath'];
$this->attributes['sambaHomePath'][0] = str_replace('$user', $attrs['uid'][0], $this->attributes['sambaHomePath'][0]); $this->attributes['sambaHomePath'][0] = str_replace('$user', $attrs['uid'][0], $this->attributes['sambaHomePath'][0]);
$this->attributes['sambaHomePath'][0] = str_replace('$group', $unixGroupName, $this->attributes['sambaHomePath'][0]); $this->attributes['sambaHomePath'][0] = str_replace('$group', $unixGroupName, $this->attributes['sambaHomePath'][0]);
if ($this->attributes['sambaHomePath'][0] != $_POST['sambaHomePath']) $errors[] = $this->messages['homePath'][1]; if ($this->attributes['sambaHomePath'][0] != $_POST['sambaHomePath']) {
$errors[] = $this->messages['homePath'][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'))) {
$errors[] = $this->messages['homePath'][0]; $errors[] = $this->messages['homePath'][0];
} }
} }
if (!$this->isBooleanConfigOptionSet('sambaSamAccount_hideHomeDrive')) { if (!$this->isBooleanConfigOptionSet('sambaSamAccount_hideHomeDrive')) {
if ($_POST['sambaHomeDrive'] == "-") $this->attributes['sambaHomeDrive'][0] = ''; if ($_POST['sambaHomeDrive'] == "-") {
else $this->attributes['sambaHomeDrive'][0] = $_POST['sambaHomeDrive']; $this->attributes['sambaHomeDrive'][0] = '';
}
else {
$this->attributes['sambaHomeDrive'][0] = $_POST['sambaHomeDrive'];
}
} }
if (!$this->isBooleanConfigOptionSet('sambaSamAccount_hideLogonScript')) { if (!$this->isBooleanConfigOptionSet('sambaSamAccount_hideLogonScript')) {
$this->attributes['sambaLogonScript'][0] = $_POST['sambaLogonScript']; $this->attributes['sambaLogonScript'][0] = $_POST['sambaLogonScript'];
$this->attributes['sambaLogonScript'][0] = str_replace('$user', $attrs['uid'][0], $this->attributes['sambaLogonScript'][0]); $this->attributes['sambaLogonScript'][0] = str_replace('$user', $attrs['uid'][0], $this->attributes['sambaLogonScript'][0]);
$this->attributes['sambaLogonScript'][0] = str_replace('$group', $unixGroupName, $this->attributes['sambaLogonScript'][0]); $this->attributes['sambaLogonScript'][0] = str_replace('$group', $unixGroupName, $this->attributes['sambaLogonScript'][0]);
if ($this->attributes['sambaLogonScript'][0] != $_POST['sambaLogonScript']) $errors[] = $this->messages['logonScript'][1]; if ($this->attributes['sambaLogonScript'][0] != $_POST['sambaLogonScript']) {
$errors[] = $this->messages['logonScript'][1];
}
if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript'))) { if ( (!$this->attributes['sambaLogonScript'][0]=='') && (!get_preg($this->attributes['sambaLogonScript'][0], 'logonscript'))) {
$errors[] = $this->messages['logonScript'][0]; $errors[] = $this->messages['logonScript'][0];
} }
@ -794,7 +812,9 @@ class sambaSamAccount extends baseModule implements passwordService {
$this->attributes['sambaProfilePath'][0] = $_POST['sambaProfilePath']; $this->attributes['sambaProfilePath'][0] = $_POST['sambaProfilePath'];
$this->attributes['sambaProfilePath'][0] = str_replace('$user', $attrs['uid'][0], $this->attributes['sambaProfilePath'][0]); $this->attributes['sambaProfilePath'][0] = str_replace('$user', $attrs['uid'][0], $this->attributes['sambaProfilePath'][0]);
$this->attributes['sambaProfilePath'][0] = str_replace('$group', $unixGroupName, $this->attributes['sambaProfilePath'][0]); $this->attributes['sambaProfilePath'][0] = str_replace('$group', $unixGroupName, $this->attributes['sambaProfilePath'][0]);
if ($this->attributes['sambaProfilePath'][0] != $_POST['sambaProfilePath']) $errors[] = $this->messages['profilePath'][1]; if ($this->attributes['sambaProfilePath'][0] != $_POST['sambaProfilePath']) {
$errors[] = $this->messages['profilePath'][1];
}
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'))) {
$errors[] = $this->messages['profilePath'][0]; $errors[] = $this->messages['profilePath'][0];
@ -914,7 +934,9 @@ class sambaSamAccount extends baseModule implements passwordService {
* @return array list of info/error messages * @return array list of info/error messages
*/ */
function process_logonHours() { function process_logonHours() {
if (isset($_POST['form_subpage_sambaSamAccount_attributes_abort'])) return array(); if (isset($_POST['form_subpage_sambaSamAccount_attributes_abort'])) {
return array();
}
// set new logon hours // set new logon hours
$logonHours = ''; $logonHours = '';
for ($i = 0; $i < 24*7; $i++) { for ($i = 0; $i < 24*7; $i++) {
@ -949,13 +971,17 @@ class sambaSamAccount extends baseModule implements passwordService {
$buttonName = $postKeys[$i]; $buttonName = $postKeys[$i];
} }
} }
if (($buttonName == '') || (strpos($buttonName, '_back') !== false)) return array(); if (($buttonName == '') || (strpos($buttonName, '_back') !== false)) {
return array();
}
// get attribute name // get attribute name
$attr = ''; $attr = '';
if (strpos($buttonName, 'sambaKickoffTime') !== false) { if (strpos($buttonName, 'sambaKickoffTime') !== false) {
$attr = 'sambaKickoffTime'; $attr = 'sambaKickoffTime';
} }
if ($attr == '') return array(); if ($attr == '') {
return array();
}
// determine action // determine action
if (strpos($buttonName, '_change') !== false) { if (strpos($buttonName, '_change') !== false) {
// set new time // set new time
@ -1009,7 +1035,9 @@ class sambaSamAccount extends baseModule implements passwordService {
* @return array list of info/error messages * @return array list of info/error messages
*/ */
function process_terminalServer() { function process_terminalServer() {
if (isset($_POST['form_subpage_sambaSamAccount_attributes_abort'])) return array(); if (isset($_POST['form_subpage_sambaSamAccount_attributes_abort'])) {
return array();
}
$mDial = new sambaMungedDial(); $mDial = new sambaMungedDial();
if (isset($this->attributes['sambaMungedDial'][0])) { if (isset($this->attributes['sambaMungedDial'][0])) {
$mDial->load($this->attributes['sambaMungedDial'][0]); $mDial->load($this->attributes['sambaMungedDial'][0]);
@ -1144,11 +1172,15 @@ class sambaSamAccount extends baseModule implements passwordService {
// home drive // home drive
if (!$this->isBooleanConfigOptionSet('sambaSamAccount_hideHomeDrive')) { if (!$this->isBooleanConfigOptionSet('sambaSamAccount_hideHomeDrive')) {
$drives = array('-'); $drives = array('-');
for ($i=90; $i>67; $i--) $drives[] = chr($i).':'; for ($i=90; $i>67; $i--) {
$drives[] = chr($i).':';
}
if (isset($this->attributes['sambaHomeDrive'][0])) { if (isset($this->attributes['sambaHomeDrive'][0])) {
$selected = array ($this->attributes['sambaHomeDrive'][0]); $selected = array ($this->attributes['sambaHomeDrive'][0]);
} }
else $selected = array('-'); else {
$selected = array('-');
}
$return->addElement(new htmlTableExtendedSelect('sambaHomeDrive', $drives, $selected, _('Home drive'), 'homeDrive'), true); $return->addElement(new htmlTableExtendedSelect('sambaHomeDrive', $drives, $selected, _('Home drive'), 'homeDrive'), true);
} }
// home path // home path
@ -1222,7 +1254,9 @@ class sambaSamAccount extends baseModule implements passwordService {
$selected = array('-'); $selected = array('-');
} }
} }
else $selected[] = "-"; else {
$selected[] = "-";
}
$return->addElement(new htmlTableExtendedSelect('sambaSID', $options, $selected, _('Special user'), 'specialUser'), true); $return->addElement(new htmlTableExtendedSelect('sambaSID', $options, $selected, _('Special user'), 'specialUser'), true);
} }
// domain // domain
@ -1403,9 +1437,15 @@ class sambaSamAccount extends baseModule implements passwordService {
$time = $this->attributes[$attr][0]; $time = $this->attributes[$attr][0];
} }
$date = new DateTime('@' . $time, new DateTimeZone('UTC')); $date = new DateTime('@' . $time, new DateTimeZone('UTC'));
for ( $i=1; $i<=31; $i++ ) $mday[] = $i; for ( $i=1; $i<=31; $i++ ) {
for ( $i=1; $i<=12; $i++ ) $mon[] = $i; $mday[] = $i;
for ( $i=2003; $i<=2050; $i++ ) $year[] = $i; }
for ( $i=1; $i<=12; $i++ ) {
$mon[] = $i;
}
for ( $i=2003; $i<=2050; $i++ ) {
$year[] = $i;
}
$return->addElement(new htmlOutputText($text)); $return->addElement(new htmlOutputText($text));
$return->addElement(new htmlSelect('expire_day', $mday, array($date->format('j')))); $return->addElement(new htmlSelect('expire_day', $mday, array($date->format('j'))));
$return->addElement(new htmlSelect('expire_mon', $mon, array($date->format('n')))); $return->addElement(new htmlSelect('expire_mon', $mon, array($date->format('n'))));
@ -1452,7 +1492,9 @@ class sambaSamAccount extends baseModule implements passwordService {
$return->addElement(new htmlTableExtendedInputField(_('Home directory'), 'tsHomeDir', $mDial->ctx['CtxWFHomeDir'], 'tsHomeDir'), true); $return->addElement(new htmlTableExtendedInputField(_('Home directory'), 'tsHomeDir', $mDial->ctx['CtxWFHomeDir'], 'tsHomeDir'), true);
// home drive // home drive
$drives = array(); $drives = array();
for ($i=90; $i>67; $i--) $drives[] = chr($i).':'; for ($i=90; $i>67; $i--) {
$drives[] = chr($i).':';
}
$selTsDrive = array(); $selTsDrive = array();
if (isset($mDial->ctx['CtxWFHomeDirDrive'])) { if (isset($mDial->ctx['CtxWFHomeDirDrive'])) {
$selTsDrive = array($mDial->ctx['CtxWFHomeDirDrive']); $selTsDrive = array($mDial->ctx['CtxWFHomeDirDrive']);