diff --git a/lam/lib/config.inc b/lam/lib/config.inc index 8c3896c5..89cdf07f 100644 --- a/lam/lib/config.inc +++ b/lam/lib/config.inc @@ -1475,6 +1475,22 @@ class LAMConfig { return $servers; } + /** + * Returns the script server object for the given name. + * + * @param string $serverName server name + * @return RemoteServerConfiguration server + */ + public function getScriptServerByName($serverName) { + $serverList = $this->getConfiguredScriptServers(); + foreach ($serverList as $server) { + if ($serverName === $server->getServer()) { + return $server; + } + } + return null; + } + /** * Sets the servers of the external script * diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 40532731..bf4c6cea 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -708,17 +708,13 @@ class posixAccount extends baseModule implements passwordService { // 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) { - foreach ($lamdaemonServerNames as $server) { - if (!in_array($server, $this->lamdaemonServers)) { + foreach ($lamdaemonServerList as $lamdaemonServer) { + if (!in_array($lamdaemonServer->getServer(), $this->lamdaemonServers)) { continue; } $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -747,9 +743,9 @@ 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])) { - foreach ($lamdaemonServerNames as $server) { + foreach ($lamdaemonServerList as $lamdaemonServer) { $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -774,9 +770,9 @@ 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])) { - foreach ($lamdaemonServerNames as $server) { + foreach ($lamdaemonServerList as $lamdaemonServer) { $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -784,7 +780,7 @@ class posixAccount extends baseModule implements passwordService { $this->attributes['uid'][0], "home", "chgrp", - $this->orig[$homeDirAttr][0], + $this->attributes[$homeDirAttr][0], $this->attributes['uidNumber'][0], $this->attributes['gidNumber'][0]) )); @@ -935,7 +931,7 @@ class posixAccount extends baseModule implements passwordService { foreach ($lamdaemonServers as $lamdaemonServer) { $remote = new \LAM\REMOTE\Remote(); try { - $remote->connect($lamdaemonServer->getServer()); + $remote->connect($lamdaemonServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -1469,10 +1465,9 @@ class posixAccount extends baseModule implements passwordService { $modules = $this->getAccountContainer()->get_type()->getModules(); $homeDirAttr = $this->getHomedirAttrName($modules); for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $server = $lamdaemonServers[$i]->getServer(); if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) { $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServers[$i]); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -1498,7 +1493,7 @@ class posixAccount extends baseModule implements passwordService { } elseif (isset($_POST['form_subpage_' . get_class($this) . '_homedir_delete_' . $i])) { $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServers[$i]); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -1910,10 +1905,9 @@ class posixAccount extends baseModule implements passwordService { // get list of lamdaemon servers $lamdaemonServers = $_SESSION['config']->getConfiguredScriptServers(); for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { - $server = $lamdaemonServers[$i]->getServer(); $label = $lamdaemonServers[$i]->getLabel(); $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServers[$i]); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -2887,7 +2881,8 @@ class posixAccount extends baseModule implements passwordService { $pos = $temp['createHomes'][$temp['counter'] - sizeof($temp['groups'])]; try { $remote = new \LAM\REMOTE\Remote(); - $remote->connect($data[$pos][$ids['posixAccount_createHomeDir']]); + $remoteServer = $_SESSION['config']->getScriptServerByName($data[$pos][$ids['posixAccount_createHomeDir']]); + $remote->connect($remoteServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, diff --git a/lam/lib/modules/quota.inc b/lam/lib/modules/quota.inc index 4c9f8b2f..7ce81b8b 100644 --- a/lam/lib/modules/quota.inc +++ b/lam/lib/modules/quota.inc @@ -174,11 +174,15 @@ class quota extends baseModule { $userName = '+'; if (($this->getAccountContainer() != null) && !$this->getAccountContainer()->isNewAccount) { if ($this->get_scope() == 'user') { - if (!isset($this->attributes['uid'][0])) return; + if (!isset($this->attributes['uid'][0])) { + return; + } $userName = $this->attributes['uid'][0]; } else if ($this->get_scope() == 'group') { - if (!isset($this->attributes['cn'][0])) return; + if (!isset($this->attributes['cn'][0])) { + return; + } $userName = $this->attributes['cn'][0]; } } @@ -188,7 +192,7 @@ class quota extends baseModule { $server = $lamdaemonServer->getServer(); // get quotas $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServer); $quotas = $remote->execute(implode(quota::$SPLIT_DELIMITER, array($userName, "quota", "get", $this->get_scope()))); $remote->disconnect(); if (empty($quotas)) { @@ -289,7 +293,8 @@ class quota extends baseModule { $quotastring .= ',' . $this->getQuotaNumber($this->quota[$server][$i][7]) . ':'; } $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remoteServer = $_SESSION['config']->getScriptServerByName($server); + $remote->connect($remoteServer); $remote->execute(implode(quota::$SPLIT_DELIMITER, array($id, "quota", "set", $this->get_scope(), "$quotastring\n"))); $remote->disconnect(); } @@ -367,7 +372,8 @@ class quota extends baseModule { $i++; } $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remoteServer = $_SESSION['config']->getScriptServerByName($server); + $remote->connect($remoteServer); $remote->execute(implode(quota::$SPLIT_DELIMITER, array($id, "quota", "set", $this->get_scope(), "$quotastring\n"))); $remote->disconnect(); } @@ -528,7 +534,7 @@ class quota extends baseModule { } // Get quotas $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServer); $quotas = $remote->execute(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope()))); $remote->disconnect(); if (empty($quotas)) { @@ -592,7 +598,7 @@ class quota extends baseModule { $id = $this->replaceSpecialChars($server); // Get quotas $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServer); $quotas = $remote->execute(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope()))); $remote->disconnect(); $dirs = explode(":", $quotas); @@ -753,7 +759,7 @@ class quota extends baseModule { $server = $lamdaemonServer->getServer(); // Get quotas $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($lamdaemonServer); $quotas = $remote->execute(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope()))); $remote->disconnect(); $dirs = explode(":", $quotas); @@ -883,7 +889,8 @@ class quota extends baseModule { $quotaString = implode(quota::$SPLIT_DELIMITER, array($name, "quota", "set", $this->get_scope(), $dir . ',' . implode(',', $temp['accounts'][$name][$mountPoints[$m]]) . "\n")); $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remoteServer = $_SESSION['config']->getScriptServerByName($server); + $remote->connect($remoteServer); $result = $remote->execute($quotaString); $remote->disconnect(); if (!empty($result)) { diff --git a/lam/lib/modules/sambaSamAccount.inc b/lam/lib/modules/sambaSamAccount.inc index 603f6d6b..512008aa 100644 --- a/lam/lib/modules/sambaSamAccount.inc +++ b/lam/lib/modules/sambaSamAccount.inc @@ -1545,10 +1545,9 @@ class sambaSamAccount extends baseModule implements passwordService { $remoteServers = $_SESSION['config']->getConfiguredScriptServers(); for ($i = 0; $i < sizeof($remoteServers); $i++) { $remoteServer = $remoteServers[$i]; - $server = $remoteServer->getServer(); $label = $remoteServer->getLabel(); $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($remoteServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -1617,10 +1616,9 @@ class sambaSamAccount extends baseModule implements passwordService { $remoteServers = $_SESSION['config']->getConfiguredScriptServers(); for ($i = 0; $i < sizeof($remoteServers); $i++) { $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); + $remote->connect($remoteServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, @@ -1645,7 +1643,7 @@ class sambaSamAccount extends baseModule implements passwordService { } elseif (isset($_POST['form_subpage_' . get_class($this) . '_homedir_delete_' . $i])) { $remote = new \LAM\REMOTE\Remote(); - $remote->connect($server); + $remote->connect($remoteServer); $result = $remote->execute( implode( self::$SPLIT_DELIMITER, diff --git a/lam/lib/remote.inc b/lam/lib/remote.inc index eb71aa14..f8f23848 100644 --- a/lam/lib/remote.inc +++ b/lam/lib/remote.inc @@ -65,16 +65,20 @@ class Remote { /** * Connects to the given SSH server. * - * @param String $server server name (e.g. localhost or localhost,1234) + * @param RemoteServerConfiguration $server server (e.g. localhost or localhost,1234) */ public function connect($server) { - $serverNameParts = explode(",", $server); + if ($server === null) { + logNewMessage(LOG_ERR, 'No server provided for lamdaemon'); + throw new LAMException(_("Unable to connect to remote server!")); + } + $serverNameParts = explode(",", $server->getServer()); $handle = false; if (sizeof($serverNameParts) > 1) { $handle = @new SSH2($serverNameParts[0], $serverNameParts[1]); } else { - $handle = @new SSH2($server); + $handle = @new SSH2($serverNameParts[0]); } if (!$handle) { throw new LAMException(_("Unable to connect to remote server!")); diff --git a/lam/templates/tests/lamdaemonTest.php b/lam/templates/tests/lamdaemonTest.php index 85d0fc30..63f61359 100644 --- a/lam/templates/tests/lamdaemonTest.php +++ b/lam/templates/tests/lamdaemonTest.php @@ -178,6 +178,7 @@ function testRemoteCommand($command, $stopTest, $remote, $testText, $container) * @param htmlResponsiveRow $container container for HTML output */ function lamRunTestSuite($serverName, $serverTitle, $testQuota, $container) { + $remoteServer = $_SESSION['config']->getScriptServerByName($serverName); $SPLIT_DELIMITER = "###x##y##x###"; $LAMDAEMON_PROTOCOL_VERSION = '5'; $okImage = "../../graphics/pass.png"; @@ -246,7 +247,7 @@ function lamRunTestSuite($serverName, $serverTitle, $testQuota, $container) { $container->add(new htmlOutputText(_("SSH connection")), 10, 4); flush(); try { - $remote->connect($serverName); + $remote->connect($remoteServer); $container->add(new htmlImage($okImage), 2); $container->add(new htmlOutputText(_("SSH connection established.")), 12, 6); }