From 292ce6e12bf0414d941ec4d4f42774e6326454e5 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 20 Mar 2014 14:04:52 +0000 Subject: [PATCH] Fix SSH CommandPipe transport. Did anyone ever test this? --- .../Commandpipe/Transport/SecureShell.php | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php b/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php index 713657ed3..cc51a5180 100644 --- a/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php +++ b/library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php @@ -29,9 +29,9 @@ namespace Icinga\Protocol\Commandpipe\Transport; -use \RuntimeException; -use \Zend_Config; -use \Icinga\Logger\Logger; +use RuntimeException; +use Zend_Config; +use Icinga\Logger\Logger; /** * Command pipe transport class that uses ssh for connecting to a remote filesystem with the icinga.cmd pipe @@ -103,24 +103,18 @@ class SecureShell implements Transport $this->path ); $hostConnector = $this->user ? $this->user . "@" . $this->host : $this->host; - exec( - 'ssh -o BatchMode=yes -o KbdInteractiveAuthentication=no' - . $hostConnector.' -p'.$this->port.' "echo \'['. time() .'] ' - . escapeshellcmd( - $command - ) - . '\' > '.$this->path.'" > /dev/null 2> /dev/null & ', - $output, - $retCode + $command = escapeshellarg('['. time() .'] ' . $command); + $sshCommand = sprintf( + 'ssh -o BatchMode=yes -o KbdInteractiveAuthentication=no %s -p %d' + . ' "echo %s > %s" 2>&1', + $hostConnector, + $this->port, + $command, + $this->path ); - Logger::debug( - 'ssh '.$hostConnector.' -p'.$this->port.' "echo \'['. time() .'] ' - . escapeshellcmd( - $command - ) - . '\' > '.$this->path.'"' - ); - Logger::debug("Return code %s: %s ", $retCode, $output); + + exec($sshCommand, $output, $retCode); + Logger::debug("Command '%s' exited with %d: %s", $sshCommand, $retCode, $output); if ($retCode != 0) { $msg = 'Could not send command to remote Icinga host: '