new phpseclib

This commit is contained in:
Roland Gruber 2017-09-16 16:55:21 +02:00
parent 0e251a3244
commit 1411aa4863
3 changed files with 44 additions and 39 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
$Id$ $Id$
@ -64,7 +65,7 @@ class sambaSamAccount extends baseModule implements passwordService {
private $cachedGroupSIDList = null; private $cachedGroupSIDList = null;
/** cache for domain list */ /** cache for domain list */
private $cachedDomainList = null; private $cachedDomainList = null;
/** delimiter for lamdaemon commands */ /** delimiter for remote commands */
private static $SPLIT_DELIMITER = "###x##y##x###"; private static $SPLIT_DELIMITER = "###x##y##x###";
@ -1541,16 +1542,18 @@ class sambaSamAccount extends baseModule implements passwordService {
$return->addElement(new htmlSpacer(null, '10px'), true); $return->addElement(new htmlSpacer(null, '10px'), true);
$homeServerContainer = new htmlTable(); $homeServerContainer = new htmlTable();
$homeServerContainer->colspan = 5; $homeServerContainer->colspan = 5;
// get list of lamdaemon servers // get list of remote servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); $remoteServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { for ($i = 0; $i < sizeof($remoteServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]); $temp = explode(":", $remoteServers[$i]);
$server = $temp[0]; $server = $temp[0];
$label = $temp[0]; $label = $temp[0];
if (isset($temp[1])) { if (isset($temp[1])) {
$label = $temp[1]; $label = $temp[1];
} }
$result = lamdaemon( $remote = new \LAM\REMOTE\Remote();
$remote->connect($server);
$result = $remote->execute(
implode( implode(
self::$SPLIT_DELIMITER, self::$SPLIT_DELIMITER,
array( array(
@ -1558,11 +1561,11 @@ class sambaSamAccount extends baseModule implements passwordService {
"home", "home",
"check", "check",
$this->attributes['sambaProfilePath'][0]) $this->attributes['sambaProfilePath'][0])
), ));
$server); $remote->disconnect();
// lamdaemon results // remote command results
if (is_array($result)) { if (!empty($result)) {
$returnValue = trim($result[0]); $returnValue = trim($result);
if ($returnValue == 'ok') { if ($returnValue == 'ok') {
$homeServerContainer->addElement(new htmlOutputText($label)); $homeServerContainer->addElement(new htmlOutputText($label));
$homeServerContainer->addElement(new htmlSpacer('5px', null)); $homeServerContainer->addElement(new htmlSpacer('5px', null));
@ -1614,13 +1617,15 @@ class sambaSamAccount extends baseModule implements passwordService {
if (empty($uidNumber) || empty($gidNumber)) { if (empty($uidNumber) || empty($gidNumber)) {
return; return;
} }
// get list of lamdaemon servers // get list of remote servers
$lamdaemonServers = explode(";", $_SESSION['config']->get_scriptServers()); $remoteServers = explode(";", $_SESSION['config']->get_scriptServers());
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) { for ($i = 0; $i < sizeof($remoteServers); $i++) {
$temp = explode(":", $lamdaemonServers[$i]); $temp = explode(":", $remoteServers[$i]);
$server = $temp[0]; $server = $temp[0];
if (isset($_POST['form_subpage_' . get_class($this) . '_homedir_create_' . $i])) { 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( implode(
self::$SPLIT_DELIMITER, self::$SPLIT_DELIMITER,
array( array(
@ -1631,22 +1636,22 @@ class sambaSamAccount extends baseModule implements passwordService {
"0".$_SESSION['config']->get_scriptRights(), "0".$_SESSION['config']->get_scriptRights(),
$uidNumber, $uidNumber,
$gidNumber) $gidNumber)
), ));
$server); $remote->disconnect();
// lamdaemon results // remote command results
if (is_array($result)) { if (!empty($result)) {
foreach ($result as $singleresult) { $singleresult = explode(",", $result);
$singleresult = explode(",", $singleresult); if (is_array($singleresult)) {
if (is_array($singleresult)) { if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) { $return[] = $singleresult;
$return[] = $singleresult;
}
} }
} }
} }
} }
elseif (isset($_POST['form_subpage_' . get_class($this) . '_homedir_delete_' . $i])) { 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( implode(
self::$SPLIT_DELIMITER, self::$SPLIT_DELIMITER,
array( array(
@ -1656,16 +1661,14 @@ class sambaSamAccount extends baseModule implements passwordService {
$this->attributes['sambaProfilePath'][0], $this->attributes['sambaProfilePath'][0],
$uidNumber $uidNumber
) )
), ));
$server); $remote->disconnect();
// lamdaemon results // remote command results
if (is_array($result)) { if (!empty($result)) {
foreach ($result as $singleresult) { $singleresult = explode(",", $result);
$singleresult = explode(",", $singleresult); if (is_array($singleresult)) {
if (is_array($singleresult)) { if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) {
if (($singleresult[0] == 'ERROR') || ($singleresult[0] == 'WARN') || ($singleresult[0] == 'INFO')) { $return[] = $singleresult;
$return[] = $singleresult;
}
} }
} }
} }

View File

@ -55,7 +55,6 @@ class Remote {
* *
* @param string $command command to execute * @param string $command command to execute
* @return string output of remote script * @return string output of remote script
*
*/ */
public function execute($command) { public function execute($command) {
if ($this->server == null) { if ($this->server == null) {
@ -68,7 +67,6 @@ class Remote {
* Connects to the given SSH server. * Connects to the given SSH server.
* *
* @param String $server server name (e.g. localhost or localhost,1234) * @param String $server server name (e.g. localhost or localhost,1234)
* @return object handle
*/ */
public function connect($server) { public function connect($server) {
$serverNameParts = explode(",", $server); $serverNameParts = explode(",", $server);
@ -90,6 +88,9 @@ class Remote {
* Closes the connection. * Closes the connection.
*/ */
public function disconnect() { public function disconnect() {
if ($this->server == null) {
return;
}
$this->server->disconnect(); $this->server->disconnect();
} }

View File

@ -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); $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); $container->addElement(new htmlSpacer(null, '10px'), true);
$endMessage = new htmlOutputText(_("Lamdaemon test finished.")); $endMessage = new htmlOutputText(_("Lamdaemon test finished."));