From d77b72be836887ade992cdc52ed1b78092754725 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 17 Dec 2012 21:18:39 +0100 Subject: [PATCH] Check server availability using fsockopen before attempting to actually connect. --- frontend/classes/sshconnector.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/classes/sshconnector.php b/frontend/classes/sshconnector.php index 0e46d3d..643e832 100644 --- a/frontend/classes/sshconnector.php +++ b/frontend/classes/sshconnector.php @@ -78,7 +78,14 @@ class SshConnector extends CPHPBaseClass public function Connect() { - /* TODO: Use fsockopen with a timeout to determine if the node and SSHd are reachable before attempting to connect. */ + $fp = @fsockopen($this->host, $this->port, $errno, $errstr, 3); + + if(!$fp) + { + throw new SshConnectException("Could not connect to {$this->host}:{$this->port}: {$errstr}"); + } + + fclose($fp); $options = array( 'hostkey' => $this->keytype