diff --git a/lam/docs/manual-sources/chapter-installation.xml b/lam/docs/manual-sources/chapter-installation.xml index 45961773..f133529b 100644 --- a/lam/docs/manual-sources/chapter-installation.xml +++ b/lam/docs/manual-sources/chapter-installation.xml @@ -332,6 +332,20 @@ https://hub.docker.com/r/ldapaccountmanager/lampro + + Configuration files + + All configuration files are stored in: + + + + /etc/ldap-account-manager + + + + /var/lib/ldap-account-manager + +
diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 9d4c3109..8c3896c5 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -1,5 +1,6 @@ scriptServer; } + /** + * Returns the list of configureed servers. + * + * @return RemoteServerConfiguration[] servers + */ + public function getConfiguredScriptServers() { + $servers = array(); + if (empty($this->scriptServer)) { + return $servers; + } + $serverChunks = explode(';', $this->scriptServer); + foreach ($serverChunks as $serverChunk) { + if (empty($serverChunk)) { + continue; + } + $serverSettings = explode(':', $serverChunk); + $serverName = $serverSettings[0]; + $serverLabel = isset($serverSettings[1]) ? $serverSettings[1] : null; + $serverHomedirPrefix = isset($serverSettings[2]) ? $serverSettings[2] : null; + $servers[] = new RemoteServerConfiguration($serverName, $serverLabel, $serverHomedirPrefix); + } + return $servers; + } + /** * Sets the servers of the external script * @@ -1470,21 +1495,25 @@ class LAMConfig { // Explode name and IP, if a name exists if (preg_match("/:/", $arr_value)) { $arr_value_explode = explode(":", $arr_value); - $ip = $arr_value_explode[1]; $servername = $arr_value_explode[0]; + $label = $arr_value_explode[1]; + $homedirPrefix = isset($arr_value_explode[2]) ? $arr_value_explode[2] : ''; } else { - $ip = $arr_value; - $servername = ""; + $servername = $arr_value; + $label = ''; + $homedirPrefix = ''; } - if (isset($ip) && is_string($ip) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $ip)) { - // Check if the IP has a server name - if (!empty($servername)) { - $valid_ips[] = $servername.":".$ip; + if (isset($servername) && is_string($servername) && preg_match("/^[a-z0-9-]+(\\.[a-z0-9-]+)*(,[0-9]+)?$/i", $servername)) { + $serverData = array($servername); + if (!empty($label)) { + $serverData[] = $label; } - else { - $valid_ips[] = $ip; + if (!empty($homedirPrefix)) { + $serverData[] = $homedirPrefix; } + $serverChunk = implode(':', $serverData); + $valid_ips[] = $serverChunk; } else { // wrong format @@ -1492,7 +1521,7 @@ class LAMConfig { } } // Check that the array is not empty - if ($array_string > 0) { + if (!empty($array_string)) { $this->scriptServer = implode(";", $valid_ips); return true; } @@ -2585,7 +2614,7 @@ class LAMCfgMain { * @return boolean true if file was readable */ private function reload() { - if (is_file($this->conffile) == True) { + if (is_file($this->conffile)) { $file = @fopen($this->conffile, "r"); if (!$file) { return false; // abort if file is not readable diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 692a9c72..40532731 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -199,6 +199,11 @@ class posixAccount extends baseModule implements passwordService { $return['upload_preDepends'] = array('inetOrgPerson'); // user specific upload options if (($this->get_scope() == 'user') && isLoggedIn()) { + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); + $lamdaemonOptions = array(); + foreach ($lamdaemonServers as $lamdaemonServer) { + $lamdaemonOptions[] = $lamdaemonServer->getServer(); + } $return['upload_columns'] = array( array( 'name' => 'posixAccount_userName', @@ -239,7 +244,7 @@ class posixAccount extends baseModule implements passwordService { 'description' => _('Create home directory'), 'help' => 'createhomedir', 'example' => 'localhost', - 'values' => $_SESSION['config']->get_scriptServers() + 'values' => implode(', ', $lamdaemonOptions) ), array( 'name' => 'posixAccount_shell', @@ -702,18 +707,14 @@ class posixAccount extends baseModule implements passwordService { $messages = array_merge($messages, $this->setExopPassword($this->moduleSettings)); // create home directories if needed $homeDirAttr = $this->getHomedirAttrName($modules); + $lamdaemonServerList = $_SESSION['config']->getConfiguredScriptServers(); + $lamdaemonServerNames = array(); + foreach ($lamdaemonServerList as $lamdaemonServer) { + $lamdaemonServerNames[] = $lamdaemonServer->getServer(); + } if (sizeof($this->lamdaemonServers) > 0) { - $server = null; - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - $server = $temp[0]; - if (isset($temp[1])) { - if (!in_array($temp[1], $this->lamdaemonServers)) { - continue; - } - } - elseif (!in_array($temp[0], $this->lamdaemonServers)) { + foreach ($lamdaemonServerNames as $server) { + if (!in_array($server, $this->lamdaemonServers)) { continue; } $remote = new \LAM\REMOTE\Remote(); @@ -746,13 +747,7 @@ class posixAccount extends baseModule implements passwordService { // move home directory if needed if (!empty($this->orig[$homeDirAttr][0]) && !empty($this->attributes[$homeDirAttr][0]) && ($this->orig[$homeDirAttr][0] != $this->attributes[$homeDirAttr][0])) { - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - if (empty($lamdaemonServers[$i])) { - continue; - } - $temp = explode(":", $lamdaemonServers[$i]); - $server = $temp[0]; + foreach ($lamdaemonServerNames as $server) { $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); $result = $remote->execute( @@ -779,13 +774,7 @@ class posixAccount extends baseModule implements passwordService { // set new group on homedirectory if (!empty($this->orig[$homeDirAttr][0]) && !empty($this->attributes[$homeDirAttr][0]) && ($this->orig['gidNumber'][0] != $this->attributes['gidNumber'][0])) { - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - if (empty($lamdaemonServers[$i])) { - continue; - } - $temp = explode(":", $lamdaemonServers[$i]); - $server = $temp[0]; + foreach ($lamdaemonServerNames as $server) { $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); $result = $remote->execute( @@ -941,16 +930,12 @@ class posixAccount extends baseModule implements passwordService { $modules = $this->getAccountContainer()->get_type()->getModules(); $homeDirAttr = $this->getHomedirAttrName($modules); // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - $lamdaemonServers[$i] = $temp[0]; - } + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); // try to delete directory on all servers - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { + foreach ($lamdaemonServers as $lamdaemonServer) { $remote = new \LAM\REMOTE\Remote(); try { - $remote->connect($lamdaemonServers[$i]); + $remote->connect($lamdaemonServer->getServer()); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -1036,7 +1021,9 @@ class posixAccount extends baseModule implements passwordService { $this->attributes['loginShell'][0] = $_POST['loginShell']; } if (!$this->isBooleanConfigOptionSet('posixAccount_' . $typeId . '_hidegecos')) { - if (isset($_POST['gecos'])) $this->attributes['gecos'][0] = $_POST['gecos']; + if (isset($_POST['gecos'])) { + $this->attributes['gecos'][0] = $_POST['gecos']; + } } if (isset($this->orig['uid'][0]) && ($this->orig['uid'][0] != '') && (trim($_POST['uid']) != $this->attributes['uid'][0])) { $errors[] = $this->messages['uid'][0]; @@ -1067,16 +1054,11 @@ class posixAccount extends baseModule implements passwordService { $errors[] = $errorMessage; } // get list of DNS names or IPs - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - if (isset($temp[1])) $lamdaemonServers[$i] = $temp[1]; - else $lamdaemonServers[$i] = $temp[0]; - } + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); $this->lamdaemonServers = array(); for ($h = 0; $h < sizeof($lamdaemonServers); $h++) { if (isset($_POST['createhomedir_' . $h]) && ($_POST['createhomedir_' . $h] = 'on')) { - $this->lamdaemonServers[] = $lamdaemonServers[$h]; + $this->lamdaemonServers[] = $lamdaemonServers[$h]->getServer(); } } if (isset($_POST['homeDirectory'])) { @@ -1483,12 +1465,11 @@ class posixAccount extends baseModule implements passwordService { function process_homedir() { $return = array(); // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); $modules = $this->getAccountContainer()->get_type()->getModules(); $homeDirAttr = $this->getHomedirAttrName($modules); for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - $server = $temp[0]; + $server = $lamdaemonServers[$i]->getServer(); if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) { $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); @@ -1676,21 +1657,12 @@ class posixAccount extends baseModule implements passwordService { if (($_SESSION['config']->get_scriptPath() != null) && ($_SESSION['config']->get_scriptPath() != '')) { if ($this->getAccountContainer()->isNewAccount) { // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - if (isset($temp[1])) { - $lamdaemonServers[$i] = $temp[1]; - } - else { - $lamdaemonServers[$i] = $temp[0]; - } - } + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); $homeDirLabel = new htmlOutputText(_('Create home directory')); $return->addLabel($homeDirLabel); $homeServerContainer = new htmlTable(); for ($h = 0; $h < sizeof($lamdaemonServers); $h++) { - $homeServerContainer->addElement(new htmlTableExtendedInputCheckbox('createhomedir_' . $h, in_array($lamdaemonServers[$h], $this->lamdaemonServers), $lamdaemonServers[$h], null, false)); + $homeServerContainer->addElement(new htmlTableExtendedInputCheckbox('createhomedir_' . $h, in_array($lamdaemonServers[$h], $this->lamdaemonServers), $lamdaemonServers[$h]->getLabel(), null, false)); if ($h === 0) { $homeDirHelp = new htmlHelpLink('createhomedir'); $homeServerContainer->addElement($homeDirHelp); @@ -1936,14 +1908,10 @@ class posixAccount extends baseModule implements passwordService { $return->addField(new htmlOutputText($this->attributes[$homeDirAttr][0])); $return->addVerticalSpacer('2rem'); // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - $server = $temp[0]; - $label = $temp[0]; - if (isset($temp[1])) { - $label = $temp[1]; - } + $server = $lamdaemonServers[$i]->getServer(); + $label = $lamdaemonServers[$i]->getLabel(); $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); $result = $remote->execute( @@ -2036,14 +2004,11 @@ class posixAccount extends baseModule implements passwordService { // lamdaemon settings if ($_SESSION['config']->get_scriptPath() != null) { $return->add(new htmlSubTitle(_('Create home directory')), 12); - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - if (isset($temp[1])) $lamdaemonServers[$i] = $temp[1]; - else $lamdaemonServers[$i] = $temp[0]; - } + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); for ($h = 0; $h < sizeof($lamdaemonServers); $h++) { - $return->add(new htmlResponsiveInputCheckbox('posixAccount_createHomedir_' . $h, in_array($lamdaemonServers[$h], $this->lamdaemonServers), $lamdaemonServers[$h], 'createhomedir', false), 12); + $server = $lamdaemonServers[$h]->getServer(); + $label = $lamdaemonServers[$h]->getLabel(); + $return->add(new htmlResponsiveInputCheckbox('posixAccount_createHomedir_' . $h, in_array($server, $this->lamdaemonServers), $label, 'createhomedir', false), 12); } } } @@ -2090,16 +2055,11 @@ class posixAccount extends baseModule implements passwordService { } // lamdaemon if (($this->get_scope() == 'user') && $this->getAccountContainer()->isNewAccount) { - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); - if (isset($temp[1])) $lamdaemonServers[$i] = $temp[1]; - else $lamdaemonServers[$i] = $temp[0]; - } + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); $this->lamdaemonServers = array(); for ($h = 0; $h < sizeof($lamdaemonServers); $h++) { if (isset($profile['posixAccount_createHomedir_' . $h][0]) && ($profile['posixAccount_createHomedir_' . $h][0] == 'true')) { - $this->lamdaemonServers[] = $lamdaemonServers[$h]; + $this->lamdaemonServers[] = $lamdaemonServers[$h]->getServer(); } } } diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index 6b8aa72a..4c9f8b2f 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -183,10 +183,9 @@ class quota extends baseModule { } } // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - $server = $temp[0]; + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); + foreach ($lamdaemonServers as $lamdaemonServer) { + $server = $lamdaemonServer->getServer(); // get quotas $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); @@ -277,14 +276,6 @@ class quota extends baseModule { $id = $this->getCn(); } // get list of lamdaemon servers - $serverDescriptions = array(); - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - if (isset($temp[1])) { - $serverDescriptions[$temp[0]] = $temp[1]; - } - } $servers = array_keys($this->quota); for ($q = 0; $q < sizeof($servers); $q++) { $server = $servers[$q]; @@ -366,14 +357,6 @@ class quota extends baseModule { $id = $this->getCn(); } // get list of lamdaemon servers - $serverDescriptions = array(); - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - if (isset($temp[1])) { - $serverDescriptions[$temp[0]] = $temp[1]; - } - } $servers = array_keys($this->quota); for ($q = 0; $q < sizeof($servers); $q++) { $server = $servers[$q]; @@ -403,14 +386,6 @@ class quota extends baseModule { } $errors = array(); // get list of lamdaemon servers - $serverDescriptions = array(); - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - if (isset($temp[1])) { - $serverDescriptions[$temp[0]] = $temp[1]; - } - } $servers = array_keys($this->quota); for ($q = 0; $q < sizeof($servers); $q++) { $server = $servers[$q]; @@ -467,19 +442,17 @@ class quota extends baseModule { } // get list of lamdaemon servers $serverDescriptions = array(); - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - if (isset($temp[1])) { - $serverDescriptions[$temp[0]] = $temp[1]; - } + $lamdaemonServer = $lamdaemonServers[$s]; + $serverDescriptions[$lamdaemonServer->getServer()] = $lamdaemonServer->getLabel(); } $servers = array_keys($this->quota); for ($q = 0; $q < sizeof($servers); $q++) { $server = $servers[$q]; $id = $this->replaceSpecialChars($server); $title = $server; - if (isset($serverDescriptions[$server])) { + if ($serverDescriptions[$server] != $server) { $title = $serverDescriptions[$server] . " (" . $server . ")"; } $return->add(new htmlSubTitle($title), 12); @@ -544,15 +517,14 @@ class quota extends baseModule { $return = new htmlResponsiveRow(); $optionsAvailable = false; // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); try { - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - $server = $temp[0]; + foreach ($lamdaemonServers as $lamdaemonServer) { + $server = $lamdaemonServer->getServer(); $id = $this->replaceSpecialChars($server); - $description = $temp[0]; - if (isset($temp[1])) { - $description = $temp[1] . ' (' . $temp[0] . ')'; + $description = $lamdaemonServer->getLabel(); + if ($description != $server) { + $description = $description . ' (' . $server . ')'; } // Get quotas $remote = new \LAM\REMOTE\Remote(); @@ -614,10 +586,9 @@ class quota extends baseModule { function check_profileOptions($options, $typeId) { $return = array(); // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - $server = $temp[0]; + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); + foreach ($lamdaemonServers as $lamdaemonServer) { + $server = $lamdaemonServer->getServer(); $id = $this->replaceSpecialChars($server); // Get quotas $remote = new \LAM\REMOTE\Remote(); @@ -717,13 +688,12 @@ class quota extends baseModule { if (sizeof($this->quota) > 0) { $pdfTable = new PDFTable(); // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - $server = $temp[0]; - $description = $server; - if (isset($temp[1])) { - $description = $temp[1] . " (" . $server . ")"; + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); + foreach ($lamdaemonServers as $lamdaemonServer) { + $server = $lamdaemonServer->getServer(); + $description = $lamdaemonServer->getLabel(); + if ($description != $server) { + $description = $description . " (" . $server . ")"; } if (!isset($this->quota[$server]) || (sizeof($this->quota[$server]) < 1)) { continue; @@ -778,10 +748,9 @@ class quota extends baseModule { $return = array(); if (sizeof($this->quota) > 0) { // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($s = 0; $s < sizeof($lamdaemonServers); $s++) { - $temp = explode(":", $lamdaemonServers[$s]); - $server = $temp[0]; + $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); + foreach ($lamdaemonServers as $lamdaemonServer) { + $server = $lamdaemonServer->getServer(); // Get quotas $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 93acf298..603f6d6b 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -1370,7 +1370,7 @@ class sambaSamAccount extends baseModule implements passwordService { elseif ($hr >= 24*7) { $hr = $hr - 24*7; } - $checkbox = new htmlInputCheckbox('lh_' . $hr, $hour[$hr] ? true : false); + $checkbox = new htmlInputCheckbox('lh_' . $hr, $hour[$hr]); $checkbox->alignment = htmlTable::ALIGN_CENTER; $boxes[$i % 24][floor($i/24)] = $checkbox; } @@ -1542,14 +1542,11 @@ class sambaSamAccount extends baseModule implements passwordService { $homeServerContainer = new htmlTable(); $homeServerContainer->colspan = 5; // get list of remote servers - $remoteServers = explode(";", $_SESSION['config']->get_scriptServers()); + $remoteServers = $_SESSION['config']->getConfiguredScriptServers(); for ($i = 0; $i < sizeof($remoteServers); $i++) { - $temp = explode(":", $remoteServers[$i]); - $server = $temp[0]; - $label = $temp[0]; - if (isset($temp[1])) { - $label = $temp[1]; - } + $remoteServer = $remoteServers[$i]; + $server = $remoteServer->getServer(); + $label = $remoteServer->getLabel(); $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); $result = $remote->execute( @@ -1617,10 +1614,10 @@ class sambaSamAccount extends baseModule implements passwordService { return; } // get list of remote servers - $remoteServers = explode(";", $_SESSION['config']->get_scriptServers()); + $remoteServers = $_SESSION['config']->getConfiguredScriptServers(); for ($i = 0; $i < sizeof($remoteServers); $i++) { - $temp = explode(":", $remoteServers[$i]); - $server = $temp[0]; + $remoteServer = $remoteServers[$i]; + $server = $remoteServer->getServer(); if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) { $remote = new \LAM\REMOTE\Remote(); $remote->connect($server); @@ -1640,10 +1637,9 @@ class sambaSamAccount extends baseModule implements passwordService { // remote command results if (!empty($result)) { $singleresult = explode(",", $result); - if (is_array($singleresult)) { - if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) { - $return[] = $singleresult; - } + if (is_array($singleresult) + && (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO'))) { + $return[] = $singleresult; } } } @@ -1665,10 +1661,9 @@ class sambaSamAccount extends baseModule implements passwordService { // remote command results if (!empty($result)) { $singleresult = explode(",", $result); - if (is_array($singleresult)) { - if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) { - $return[] = $singleresult; - } + if (is_array($singleresult) + && (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO'))) { + $return[] = $singleresult; } } } diff --git a/lam/lib/modules/sambaSamAccount/sambaMungedDial.inc b/lam/lib/modules/sambaSamAccount/sambaMungedDial.inc index cdc2ba9f..f618b06f 100644 --- a/lam/lib/modules/sambaSamAccount/sambaMungedDial.inc +++ b/lam/lib/modules/sambaSamAccount/sambaMungedDial.inc @@ -261,7 +261,7 @@ class sambaMungedDial } $ctxField=""; - if($this->old_behavior==true) { + if($this->old_behavior) { $ctxField= substr(base64_decode($munge), (strlen(SAMBA_MUNGEDDIAL_FILEHEADER_OLD)) / 2); } else { $ctxField= substr(base64_decode($munge), (strlen(SAMBA_MUNGEDDIAL_FILEHEADER)+4) / 2); @@ -445,7 +445,7 @@ class sambaMungedDial */ function getShadow () { - if($this->old_behavior==true) { + if($this->old_behavior) { $result= substr($this->ctx['CtxCfgFlags1'], 1, 1); } else { $result= substr($this->ctx['CtxShadow'], 1, 1); @@ -457,7 +457,7 @@ class sambaMungedDial function setShadow ($checked, $value) { if ($checked) { - if($this->old_behavior==true) { + if($this->old_behavior) { // We need to reset the old setting $this->ctx['CtxCfgFlags1'][1]= sprintf('%1X', $value); } diff --git a/lam/lib/remote.inc b/lam/lib/remote.inc index 9190d7fd..eb71aa14 100644 --- a/lam/lib/remote.inc +++ b/lam/lib/remote.inc @@ -174,4 +174,63 @@ class Remote { } +/** + * Server configuration. + * + * @author Roland Gruber + */ +class RemoteServerConfiguration { + + private $server; + private $label; + private $homeDirPrefix; + + /** + * Constructor + * + * @param string $server server DNS name + * @param string $label label for GUI + * @param string $homeDirPrefix prefix for home directories + */ + public function __construct($server, $label, $homeDirPrefix) { + $this->server = $server; + $this->label = $label; + if (empty($label)) { + $this->label = $server; + } + $this->homeDirPrefix = $homeDirPrefix; + if (empty($homeDirPrefix)) { + $this->homeDirPrefix = ''; + } + } + + /** + * Returns the server's DNS name. + * + * @return string server name + */ + public function getServer() { + return $this->server; + } + + /** + * Returns a descriptive label. + * + * @return string label + */ + public function getLabel() { + return $this->label; + } + + /** + * Returns the prefix for user home directories. + * + * @return string prefix for user home directories + */ + public function getHomeDirPrefix() { + return $this->homeDirPrefix; + } + +} + ?> diff --git a/lam/templates/config/confmodules.php b/lam/templates/config/confmodules.php index 4e615ce4..36533657 100644 --- a/lam/templates/config/confmodules.php +++ b/lam/templates/config/confmodules.php @@ -329,7 +329,7 @@ function checkInput() { } // check dependencies $depends = check_module_depends($selected, getModulesDependencies($scope)); - if ($depends != false) { + if ($depends !== false) { for ($i = 0; $i < sizeof($depends); $i++) { $errors[] = array('ERROR', $type->getAlias(), _("Unsolved dependency:") . ' ' . $depends[$i][0] . " (" . $depends[$i][1] . ")"); @@ -337,7 +337,7 @@ function checkInput() { } // check conflicts $conflicts = check_module_conflicts($selected, getModulesDependencies($scope)); - if ($conflicts != false) { + if ($conflicts !== false) { for ($i = 0; $i < sizeof($conflicts); $i++) { $errors[] = array('ERROR', $type->getAlias(), _("Conflicting module:") . ' ' . $conflicts[$i][0] . " (" . $conflicts[$i][1] . ")"); diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index 81772268..efd7251e 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -28,7 +28,7 @@ window.lam = window.lam || {}; */ function list_click(box) { var cbox = document.getElementsByName(box)[0]; - if (cbox.checked == true) { + if (cbox.checked) { cbox.checked = false; } else { @@ -383,8 +383,10 @@ function equalWidth(elementIDs) { // no action if invalid width value (e.g. because of hidden tab) return; } - for (var i = 0; i < elementIDs.length; ++i) { - jQuery(elementIDs[i]).css({'width': maxWidth - (jQuery(elementIDs[i]).outerWidth() - jQuery(elementIDs[i]).width())}); + for (var elementId = 0; elementId < elementIDs.length; ++elementId) { + jQuery(elementIDs[elementId]).css({ + 'width': maxWidth - (jQuery(elementIDs[elementId]).outerWidth() - jQuery(elementIDs[elementId]).width()) + }); } } @@ -400,8 +402,10 @@ function equalHeight(elementIDs) { max = jQuery(elementIDs[i]).height(); } } - for (var i = 0; i < elementIDs.length; ++i) { - jQuery(elementIDs[i]).css({'height': max - (jQuery(elementIDs[i]).outerHeight() - jQuery(elementIDs[i]).height())}); + for (var elementId = 0; elementId < elementIDs.length; ++elementId) { + jQuery(elementIDs[elementId]).css({ + 'height': max - (jQuery(elementIDs[elementId]).outerHeight() - jQuery(elementIDs[elementId]).height()) + }); } } @@ -567,7 +571,7 @@ function checkPasswordStrength(fieldID, ajaxURL, tokenName, tokenValue) { */ function checkPasswordStrengthHandleReply(data, fieldID) { var field = jQuery('#' + fieldID); - if (data.result == true) { + if (data.result === true) { field.removeClass('markFail'); field.addClass('markOk'); field.prop('title', ''); @@ -601,11 +605,11 @@ function updateModulePositions(id, oldPos, newPos) { positions[newPos] = save; } if (newPos < oldPos) { - var save = positions[oldPos]; - for (var i = oldPos; i > newPos; i--) { - positions[i] = positions[i - 1]; + var oldPosition = positions[oldPos]; + for (var position = oldPos; position > newPos; position--) { + positions[position] = positions[position - 1]; } - positions[newPos] = save; + positions[newPos] = oldPosition; } jQuery('#' + id).val(positions.join(',')); } diff --git a/lam/templates/tests/lamdaemonTest.php b/lam/templates/tests/lamdaemonTest.php index f69043af..85d0fc30 100644 --- a/lam/templates/tests/lamdaemonTest.php +++ b/lam/templates/tests/lamdaemonTest.php @@ -15,7 +15,7 @@ use \htmlResponsiveRow; /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2006 - 2018 Roland Gruber + Copyright (C) 2006 - 2019 Roland Gruber This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,7 +51,9 @@ startSecureSession(); enforceUserIsLoggedIn(); // die if no write access -if (!checkIfWriteAccessIsAllowed()) die(); +if (!checkIfWriteAccessIsAllowed()) { + die(); +} checkIfToolIsActive('toolTests'); @@ -64,33 +66,31 @@ echo "
\n"; $container = new htmlResponsiveRow(); $container->add(new htmlTitle(_("Lamdaemon test")), 12); -$servers = explode(";", $_SESSION['config']->get_scriptServers()); +$servers = $_SESSION['config']->getConfiguredScriptServers(); $serverIDs = array(); $serverTitles = array(); -for ($i = 0; $i < sizeof($servers); $i++) { - $serverParts = explode(":", $servers[$i]); - $serverName = $serverParts[0]; - $title = $serverName; - if (isset($serverParts[1])) { - $title = $serverParts[1] . " (" . $serverName . ")"; +foreach ($servers as $server) { + $serverName = $server->getServer(); + $label = $server->getLabel(); + if ($label !== $serverName) { + $label = $label . " (" . $serverName . ")"; } $serverIDs[] = $serverName; - $serverTitles[$serverName] = $title; + $serverTitles[$serverName] = $label; } if (isset($_POST['runTest'])) { lamRunTestSuite($_POST['server'], $serverTitles[$_POST['server']] , isset($_POST['checkQuotas']), $container); } -else if ((sizeof($servers) > 0) && isset($servers[0]) && ($servers[0] != '')) { +elseif (!empty($servers)) { $serverOptions = array(); - for ($i = 0; $i < sizeof($servers); $i++) { - $servers[$i] = explode(":", $servers[$i]); - $serverName = $servers[$i][0]; - $title = $serverName; - if (isset($servers[$i][1])) { - $title = $servers[$i][1] . " (" . $serverName . ")"; + foreach ($servers as $server) { + $serverName = $server->getServer(); + $label = $server->getLabel(); + if ($label !== $serverName) { + $label = $label . " (" . $serverName . ")"; } - $serverOptions[$title] = $serverName; + $serverOptions[$label] = $serverName; } $serverSelect = new htmlResponsiveSelect('server', $serverOptions, array(), _("Server")); $serverSelect->setHasDescriptiveElements(true); @@ -245,7 +245,6 @@ function lamRunTestSuite($serverName, $serverTitle, $testQuota, $container) { if (!$stopTest) { $container->add(new htmlOutputText(_("SSH connection")), 10, 4); flush(); - $sshOk = false; try { $remote->connect($serverName); $container->add(new htmlImage($okImage), 2); diff --git a/lam/tests/lib/LAMConfigTest.php b/lam/tests/lib/LAMConfigTest.php index 58e94bf5..6d0c2738 100644 --- a/lam/tests/lib/LAMConfigTest.php +++ b/lam/tests/lib/LAMConfigTest.php @@ -279,12 +279,34 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase { public function testscriptServers() { $this->assertFalse($this->lAMConfig->set_scriptServers(';;..')); $val = 'server;server'; - $this->lAMConfig->set_scriptServers($val); + $this->assertTrue($this->lAMConfig->set_scriptServers($val)); $this->assertEquals($val, $this->lAMConfig->get_scriptServers()); $this->doSave(); $this->assertEquals($val, $this->lAMConfig->get_scriptServers()); } + /** + * Tests LAMConfig->getConfiguredScriptServers(). + */ + public function testGetConfiguredScriptServers() { + $val = 'server1;server2:label2;server3:label3:/prefix'; + $this->assertTrue($this->lAMConfig->set_scriptServers($val)); + $servers = $this->lAMConfig->getConfiguredScriptServers(); + $this->assertEquals(3, sizeof($servers)); + $this->doSave(); + $servers = $this->lAMConfig->getConfiguredScriptServers(); + $this->assertEquals(3, sizeof($servers)); + $this->assertEquals('server1', $servers[0]->getServer()); + $this->assertEquals('server2', $servers[1]->getServer()); + $this->assertEquals('server3', $servers[2]->getServer()); + $this->assertEquals('server1', $servers[0]->getLabel()); + $this->assertEquals('label2', $servers[1]->getLabel()); + $this->assertEquals('label3', $servers[2]->getLabel()); + $this->assertEquals('', $servers[0]->getHomeDirPrefix()); + $this->assertEquals('', $servers[1]->getHomeDirPrefix()); + $this->assertEquals('/prefix', $servers[2]->getHomeDirPrefix()); + } + /** * Tests LAMConfig->get_scriptRights() and LAMConfig->set_scriptRights() */