From 856045a3001f35391578de2ab6f0539775b74b02 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 10 Jul 2019 08:24:22 +0200 Subject: [PATCH] . --- composer.json | 3 ++- scripts/lib/ssh.php | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 46af289..98bc97e 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "predis/predis": "^1.1", "zendframework/zend-db": "^2.10", "zendframework/zend-i18n": "^2.9", - "zendframework/zend-i18n-resources": "^2.6" + "zendframework/zend-i18n-resources": "^2.6", + "ext-ssh2": "*" } } diff --git a/scripts/lib/ssh.php b/scripts/lib/ssh.php index 6c6c9ce..7024339 100644 --- a/scripts/lib/ssh.php +++ b/scripts/lib/ssh.php @@ -13,7 +13,7 @@ function getSSHInstance($device = null, $sudo = false) $instance_key = $device . ($sudo ? '_sudo' : ''); - if (!isset($ssh[$instance_key])) { + if (!isset($ssh[$instance_key]) || !is_resource($ssh[$instance_key])) { if (!isset($devices[$device])) { $ssh[$instance_key] = false; } else { @@ -30,20 +30,20 @@ function getSSHInstance($device = null, $sudo = false) } } } - return $ssh[$device]; + return $ssh[$instance_key]; } function sshCommand($command, $device = null, $blocking = true, $sudo = false) { - return sshRunCommand($command, $device, $blocking, $sudo); -// $redis = connectRedis(); -// $queue = $redis->get('ssh_queue'); -// if (!is_array($queue)) { -// $queue = []; -// } -// $queue[] = ['command' => $command, 'device' => $device, 'blocking' => $blocking, 'sudo' => $sudo]; -// $redis->igbset('ssh_queue', $queue); -// $redis->publish('ssh_event', 'handle_queue'); + //return sshRunCommand($command, $device, $blocking, $sudo); + $redis = connectRedis(); + $queue = $redis->get('ssh_queue'); + if (!is_array($queue)) { + $queue = []; + } + $queue[] = ['command' => $command, 'device' => $device, 'blocking' => $blocking, 'sudo' => $sudo]; + $redis->igbset('ssh_queue', $queue); + $redis->publish('ssh_event', 'handle_queue'); } function sshRunCommand($command, $device = null, $blocking = true, $sudo = false) -- 2.39.5