support only one lamdaemon command at a time
This commit is contained in:
parent
12bc743294
commit
3962852004
|
@ -34,16 +34,16 @@ $Id$
|
|||
/**
|
||||
* Sends commands to lamdaemon script.
|
||||
*
|
||||
* @param array $commands List of command lines
|
||||
* @param array $command command to execute
|
||||
* @param string $server remote server
|
||||
* @return array Output of lamdaemon
|
||||
*
|
||||
*/
|
||||
function lamdaemon($commands, $server) {
|
||||
function lamdaemon($command, $server) {
|
||||
if (!function_exists('ssh2_connect')) {
|
||||
return array('ERROR,' . _('This module requires the PHP ssh2 extension.'));
|
||||
}
|
||||
$commands = implode("\n", $commands) . "\n";
|
||||
$command = $command . "\n";
|
||||
// get username and password of the current lam-admin
|
||||
$credentials = $_SESSION['ldap']->decrypt_login();
|
||||
$serverNameParts = explode(",", $server);
|
||||
|
@ -54,7 +54,7 @@ function lamdaemon($commands, $server) {
|
|||
$handle = @ssh2_connect($server);
|
||||
}
|
||||
if ($handle) {
|
||||
$sr = @ldap_read($_SESSION['ldap']->server(), $credentials[0], "objectClass=posixAccount", array('uid'));
|
||||
$sr = @ldap_read($_SESSION['ldap']->server(), $credentials[0], "objectClass=posixAccount", array('uid'), 0, 0, 0, LDAP_DEREF_NEVER);
|
||||
if (!$sr) {
|
||||
$return = array("ERROR," . _("Your LAM admin user must be a valid Unix account to work with lamdaemon!") . ",");
|
||||
return $return;
|
||||
|
@ -67,10 +67,10 @@ function lamdaemon($commands, $server) {
|
|||
$userName = $entry[0]['uid'][0];
|
||||
if (@ssh2_auth_password($handle, $userName, $credentials[1])) {
|
||||
$shell = ssh2_exec($handle, "sudo " . $_SESSION['config']->get_scriptPath());
|
||||
fwrite($shell, $commands);
|
||||
fwrite($shell, $command);
|
||||
$return = array();
|
||||
$time = time() + (sizeof($commands) * 30);
|
||||
while (sizeof($return) < sizeof($commands)) {
|
||||
$time = time() + 30;
|
||||
while (sizeof($return) < 1) {
|
||||
if ($time < time()) {
|
||||
$return = array("ERROR," . _("Timeout while executing lamdaemon commands!") . ",");
|
||||
return $return;
|
||||
|
|
|
@ -569,7 +569,7 @@ class posixAccount extends baseModule implements passwordService {
|
|||
break;
|
||||
}
|
||||
}
|
||||
$result = lamdaemon(array(implode(posixAccount::$SPLIT_DELIMITER, array($this->attributes['uid'][0], "home", "add", "0".$_SESSION['config']->get_scriptRights()))), $server);
|
||||
$result = lamdaemon(implode(posixAccount::$SPLIT_DELIMITER, array($this->attributes['uid'][0], "home", "add", "0".$_SESSION['config']->get_scriptRights())), $server);
|
||||
// lamdaemon results
|
||||
if (is_array($result)) {
|
||||
foreach ($result as $singleresult) {
|
||||
|
@ -618,7 +618,7 @@ class posixAccount extends baseModule implements passwordService {
|
|||
}
|
||||
// try to delete directory on all servers
|
||||
for ($i = 0; $i < sizeof($lamdaemonServers); $i++) {
|
||||
$result = lamdaemon(array(implode(posixAccount::$SPLIT_DELIMITER, array($this->attributes['uid'][0], "home", "rem"))), $lamdaemonServers[$i]);
|
||||
$result = lamdaemon(implode(posixAccount::$SPLIT_DELIMITER, array($this->attributes['uid'][0], "home", "rem")), $lamdaemonServers[$i]);
|
||||
// lamdaemon results
|
||||
if (is_array($result)) {
|
||||
foreach ($result as $singleresult) {
|
||||
|
@ -1604,7 +1604,7 @@ class posixAccount extends baseModule implements passwordService {
|
|||
// create home directories
|
||||
elseif ($temp['counter'] < (sizeof($temp['groups']) + sizeof($temp['createHomes']))) {
|
||||
$pos = $temp['createHomes'][$temp['counter'] - sizeof($temp['groups'])];
|
||||
$result = lamdaemon(array(implode(posixAccount::$SPLIT_DELIMITER, array($data[$pos][$ids['posixAccount_userName']], "home", "add", "0".$_SESSION['config']->get_scriptRights()))),
|
||||
$result = lamdaemon(implode(posixAccount::$SPLIT_DELIMITER, array($data[$pos][$ids['posixAccount_userName']], "home", "add", "0".$_SESSION['config']->get_scriptRights())),
|
||||
$data[$pos][$ids['posixAccount_createHomeDir']]);
|
||||
$errors = array();
|
||||
if (($result != false) && (sizeof($result) == 1)) {
|
||||
|
|
|
@ -176,7 +176,7 @@ class quota extends baseModule {
|
|||
$temp = explode(":", $lamdaemonServers[$s]);
|
||||
$server = $temp[0];
|
||||
// get quotas
|
||||
$quotas = lamdaemon(array(implode(quota::$SPLIT_DELIMITER, array($userName, "quota", "get", $this->get_scope()))), $server);
|
||||
$quotas = lamdaemon(implode(quota::$SPLIT_DELIMITER, array($userName, "quota", "get", $this->get_scope())), $server);
|
||||
$allQuotas = explode(":", $quotas[0]);
|
||||
array_pop($allQuotas); // remove empty element at the end
|
||||
for ($i = 0; $i < sizeof($allQuotas); $i++) {
|
||||
|
@ -261,7 +261,7 @@ class quota extends baseModule {
|
|||
$quotastring = $quotastring . $this->quota[$server][$i][0] . ',' . $this->quota[$server][$i][2] . ',' . $this->quota[$server][$i][3]
|
||||
. ',' . $this->quota[$server][$i][6] . ',' . $this->quota[$server][$i][7] . ':';
|
||||
}
|
||||
lamdaemon(array(implode(quota::$SPLIT_DELIMITER, array($id, "quota", "set", $this->get_scope(), "$quotastring\n"))), $server);
|
||||
lamdaemon(implode(quota::$SPLIT_DELIMITER, array($id, "quota", "set", $this->get_scope(), "$quotastring\n")), $server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ class quota extends baseModule {
|
|||
$quotastring = $quotastring . $this->quota[$server][$i][0] . ',0,0,0,0:';
|
||||
$i++;
|
||||
}
|
||||
lamdaemon(array(implode(quota::$SPLIT_DELIMITER, array($id, "quota", "set", $this->get_scope(), "$quotastring\n"))), $server);
|
||||
lamdaemon(implode(quota::$SPLIT_DELIMITER, array($id, "quota", "set", $this->get_scope(), "$quotastring\n")), $server);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ class quota extends baseModule {
|
|||
if (isset($temp[1])) $description = $temp[1];
|
||||
|
||||
// Get quotas
|
||||
$quotas = lamdaemon(array(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope()))), $server);
|
||||
$quotas = lamdaemon(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope())), $server);
|
||||
$dirs = explode(":", $quotas[0]);
|
||||
array_pop($dirs); // remove empty element at the end
|
||||
for ($i = 0; $i < sizeof($dirs); $i++) {
|
||||
|
@ -512,7 +512,7 @@ class quota extends baseModule {
|
|||
$server = $temp[0];
|
||||
$id = $this->replaceSpecialChars($server);
|
||||
// Get quotas
|
||||
$quotas = lamdaemon(array(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope()))), $server);
|
||||
$quotas = lamdaemon(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope())), $server);
|
||||
$dirs = explode(":", $quotas[0]);
|
||||
array_pop($dirs); // remove empty element at the end
|
||||
for ($i = 0; $i < sizeof($dirs); $i++) {
|
||||
|
@ -625,7 +625,7 @@ class quota extends baseModule {
|
|||
$temp = explode(":", $lamdaemonServers[$s]);
|
||||
$server = $temp[0];
|
||||
// Get quotas
|
||||
$quotas = lamdaemon(array(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope()))), $server);
|
||||
$quotas = lamdaemon(implode(quota::$SPLIT_DELIMITER, array("+", "quota", "get", $this->get_scope())), $server);
|
||||
$dirs = explode(":", $quotas[0]);
|
||||
array_pop($dirs); // remove empty element at the end
|
||||
for ($i = 0; $i < sizeof($dirs); $i++) {
|
||||
|
@ -745,7 +745,7 @@ class quota extends baseModule {
|
|||
$dir = $mpParts[1];
|
||||
$quotaString = implode(quota::$SPLIT_DELIMITER, array($name, "quota", "set", $this->get_scope(), $dir . ',' .
|
||||
implode(',', $temp['accounts'][$name][$mountPoints[$m]]) . "\n"));
|
||||
$result = lamdaemon(array($quotaString), $server);
|
||||
$result = lamdaemon($quotaString, $server);
|
||||
if (is_array($result)) {
|
||||
for ($i = 0; $i < sizeof($result); $i++) {
|
||||
$parts = explode(",", $result);
|
||||
|
|
Loading…
Reference in New Issue