diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 3664d4b2..f4df4491 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -1,4 +1,5 @@ addElement(new htmlSpacer(null, '10px'), true); $homeServerContainer = new htmlTable(); $homeServerContainer->colspan = 5; - // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); + // get list of remote servers + $remoteServers = explode(";", $_SESSION['config']->get_scriptServers()); + for ($i = 0; $i < sizeof($remoteServers); $i++) { + $temp = explode(":", $remoteServers[$i]); $server = $temp[0]; $label = $temp[0]; if (isset($temp[1])) { $label = $temp[1]; } - $result = lamdaemon( + $remote = new \LAM\REMOTE\Remote(); + $remote->connect($server); + $result = $remote->execute( implode( self::$SPLIT_DELIMITER, array( @@ -1558,11 +1561,11 @@ class sambaSamAccount extends baseModule implements passwordService { "home", "check", $this->attributes['sambaProfilePath'][0]) - ), - $server); - // lamdaemon results - if (is_array($result)) { - $returnValue = trim($result[0]); + )); + $remote->disconnect(); + // remote command results + if (!empty($result)) { + $returnValue = trim($result); if ($returnValue == 'ok') { $homeServerContainer->addElement(new htmlOutputText($label)); $homeServerContainer->addElement(new htmlSpacer('5px', null)); @@ -1614,13 +1617,15 @@ class sambaSamAccount extends baseModule implements passwordService { if (empty($uidNumber) || empty($gidNumber)) { return; } - // get list of lamdaemon servers - $lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); - for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $temp = explode(":", $lamdaemonServers[$i]); + // get list of remote servers + $remoteServers = explode(";", $_SESSION['config']->get_scriptServers()); + for ($i = 0; $i < sizeof($remoteServers); $i++) { + $temp = explode(":", $remoteServers[$i]); $server = $temp[0]; if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) { - $result = lamdaemon( + $remote = new \LAM\REMOTE\Remote(); + $remote->connect($server); + $result = $remote->execute( implode( self::$SPLIT_DELIMITER, array( @@ -1631,22 +1636,22 @@ class sambaSamAccount extends baseModule implements passwordService { "0".$_SESSION['config']->get_scriptRights(), $uidNumber, $gidNumber) - ), - $server); - // lamdaemon results - if (is_array($result)) { - foreach ($result as $singleresult) { - $singleresult = explode(",", $singleresult); - if (is_array($singleresult)) { - if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) { - $return[] = $singleresult; - } + )); + $remote->disconnect(); + // 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; } } } } elseif (isset($_POST['form_subpage_' . get_class($this) . '_homedir_delete_' . $i])) { - $result = lamdaemon( + $remote = new \LAM\REMOTE\Remote(); + $remote->connect($server); + $result = $remote->execute( implode( self::$SPLIT_DELIMITER, array( @@ -1656,16 +1661,14 @@ class sambaSamAccount extends baseModule implements passwordService { $this->attributes['sambaProfilePath'][0], $uidNumber ) - ), - $server); - // lamdaemon results - if (is_array($result)) { - foreach ($result as $singleresult) { - $singleresult = explode(",", $singleresult); - if (is_array($singleresult)) { - if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) { - $return[] = $singleresult; - } + )); + $remote->disconnect(); + // 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; } } } diff --git a/lam/lib/remote.inc b/lam/lib/remote.inc index 6392eedc..e705233a 100644 --- a/lam/lib/remote.inc +++ b/lam/lib/remote.inc @@ -55,7 +55,6 @@ class Remote { * * @param string $command command to execute * @return string output of remote script - * */ public function execute($command) { if ($this->server == null) { @@ -68,7 +67,6 @@ class Remote { * Connects to the given SSH server. * * @param String $server server name (e.g. localhost or localhost,1234) - * @return object handle */ public function connect($server) { $serverNameParts = explode(",", $server); @@ -90,6 +88,9 @@ class Remote { * Closes the connection. */ public function disconnect() { + if ($this->server == null) { + return; + } $this->server->disconnect(); } diff --git a/lam/templates/tests/lamdaemonTest.php b/lam/templates/tests/lamdaemonTest.php index 7169eec8..1a0dbb55 100644 --- a/lam/templates/tests/lamdaemonTest.php +++ b/lam/templates/tests/lamdaemonTest.php @@ -297,6 +297,7 @@ function lamRunTestSuite($serverName, $serverTitle, $testQuota, $container) { $stopTest = lamTestLamdaemon("+" . $SPLIT_DELIMITER . "quota" . $SPLIT_DELIMITER . "get" . $SPLIT_DELIMITER . "user", $stopTest, $remote, _("Lamdaemon: read quotas"), $container); } } + $remote->disconnect(); $container->addElement(new htmlSpacer(null, '10px'), true); $endMessage = new htmlOutputText(_("Lamdaemon test finished."));