|
|
@ -28,37 +28,31 @@ class SshConnector extends CPHPBaseClass
|
|
|
|
|
|
|
|
|
|
|
|
public $helper = "~/runhelper";
|
|
|
|
public $helper = "~/runhelper";
|
|
|
|
|
|
|
|
|
|
|
|
public function RunCommand($command)
|
|
|
|
public function RunCommand($command, $throw_exception)
|
|
|
|
{
|
|
|
|
|
|
|
|
if($this->connected == false && $this->authenticated == false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if($this->connected == false && $this->authenticated == false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$this->Connect();
|
|
|
|
$this->Connect();
|
|
|
|
return $this->DoCommand($command);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (SshConnectException $e)
|
|
|
|
|
|
|
|
{
|
|
|
|
return $this->DoCommand($command, $throw_exception);
|
|
|
|
$error = $e->getMessage();
|
|
|
|
|
|
|
|
throw new SshCommandException("Could not run command {$command}: Failed to connect: {$error}");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (SshCommandException $e)
|
|
|
|
catch (SshCommandException $e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$error = $e->getMessage();
|
|
|
|
$error = $e->getMessage();
|
|
|
|
throw new SshCommandException($error);
|
|
|
|
throw new SshCommandException($error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (SshConnectException $e)
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->DoCommand($command);
|
|
|
|
$error = $e->getMessage();
|
|
|
|
|
|
|
|
throw new SshCommandException("Could not run command {$command}: Failed to connect: {$error}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (SshCommandException $e)
|
|
|
|
catch (SshExitException $e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$error = $e->getMessage();
|
|
|
|
$error = $e->getMessage();
|
|
|
|
throw new SshCommandException($error);
|
|
|
|
throw new SshExitException($error);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -99,7 +93,7 @@ class SshConnector extends CPHPBaseClass
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function DoCommand($command)
|
|
|
|
private function DoCommand($command, $throw_exception)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$command = str_replace("'", "\'", $command);
|
|
|
|
$command = str_replace("'", "\'", $command);
|
|
|
|
$command = "{$this->helper} '{$command}'";
|
|
|
|
$command = "{$this->helper} '{$command}'";
|
|
|
|