RunCommand now returns an object with stdout, stderr, and return code

feature/node-rewrite
Sven Slootweg 13 years ago
parent 60e9eb60b5
commit 107fd1da97

@ -15,7 +15,7 @@ if(!isset($_CVM)) { die("Unauthorized."); }
class Node extends CPHPDatabaseRecordClass
{
public $ssh = null;
}
?>

@ -26,6 +26,8 @@ class SshConnector extends CPHPBaseClass
public $pubkey = "";
public $keytype = "ssh-rsa";
public $helper = "~/runhelper";
public function RunCommand($command)
{
if($this->connected == false && $this->authenticated == false)
@ -99,12 +101,16 @@ class SshConnector extends CPHPBaseClass
private function DoCommand($command)
{
$command = str_replace("'", "\'", $command);
$command = "{$this->helper} '{$command}'";
$stream = ssh2_exec($this->connection, $command);
stream_set_blocking($stream, true);
$returndata = stream_get_contents($stream);
$returndata = json_decode(stream_get_contents($stream));
fclose($stream);
return $returndata;
}
}

@ -7,5 +7,5 @@ $ssh->host = "cvm-vz.cryto.net";
$ssh->key = "/etc/cvm/key";
$ssh->pubkey = "/etc/cvm/key.pub";
var_dump($ssh->RunCommand("df -h"));
var_dump($ssh->RunCommand("cp derp2 derp"));
?>

Loading…
Cancel
Save