]> _ Git - tortuga-home.git/commitdiff
.
authorVincent <vincent@enhydra.fr>
Wed, 10 Jul 2019 06:24:22 +0000 (08:24 +0200)
committerVincent <vincent@enhydra.fr>
Wed, 10 Jul 2019 06:24:22 +0000 (08:24 +0200)
composer.json
scripts/lib/ssh.php

index 46af28978c417f7a1ad6d281f146c320361f36ae..98bc97eb8097d147e5bd39d46fc26b3308b412e8 100644 (file)
@@ -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": "*"
   }
 }
index 6c6c9ce499fdb9fe5c92356a7fdf99366c444ae9..7024339bf1ce2f39be6a9e716760ee016078bd20 100644 (file)
@@ -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)