From 5b6dbececd1c158e8fdb1c2458a2be5528ad38b8 Mon Sep 17 00:00:00 2001 From: Guillaume Mazoyer Date: Sun, 3 Aug 2014 23:55:08 +0200 Subject: Be sure to login and disconnect after each command. --- auth/ssh.php | 8 ++++---- auth/telnet.php | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'auth') diff --git a/auth/ssh.php b/auth/ssh.php index a8a74b9..5fdd489 100644 --- a/auth/ssh.php +++ b/auth/ssh.php @@ -71,17 +71,17 @@ final class SSH extends Authentication { } public function send_command($command) { - if (($this->connection == null) || !$this->connection->isConnected()) { - $this->connect(); - } + $this->connect(); $data = $this->connection->exec($command); + $this->disconnect(); + return $data; } public function disconnect() { - if ($this->connection != null) { + if (($this->connection != null) && $this->connection->isConnected()) { $this->connection->disconnect(); $this->connection = null; } diff --git a/auth/telnet.php b/auth/telnet.php index 628e602..40a8822 100644 --- a/auth/telnet.php +++ b/auth/telnet.php @@ -47,9 +47,7 @@ final class Telnet extends Authentication { } public function send_command($command) { - if ($this->connection == null) { - $this->connect(); - } + $this->connect(); fputs($this->connection, $command."\r\n"); @@ -58,6 +56,8 @@ final class Telnet extends Authentication { $data .= fread($this->connection, 4096); } + $this->disconnect(); + return $data; } -- cgit v1.2.3