From 764e67de20d6601672d09a41ccdb774ea23332e8 Mon Sep 17 00:00:00 2001 From: Olivier <16240457+TiTidom-RC@users.noreply.github.com> Date: Sun, 27 Oct 2024 22:57:46 +0100 Subject: [PATCH 1/4] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f68c14..a474448 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Example: $commands = [ 'mv -f /tmp/config.yaml /opt/my_app/config.yaml', 'cd /opt/my_app/; sudo make install' -] +]; $outputs = sshmanager::executeCmds($this->getConfiguration('host_id'), $commands); ``` @@ -125,6 +125,8 @@ if you provide a string with a single command then the output will be a string a If your command produce several lines, you will receive line feed `\n` in the output, don't forget to take them into account in your code. +If you prefer an array of strings instead of multilines from the output, you can use the command `$outputsArray = explode("\n", $outputs)` in your code. + #### retrieve remote file tbd. From 9bdc00765d99699e0b14570578df6c86b71cff4e Mon Sep 17 00:00:00 2001 From: Olivier <16240457+TiTidom-RC@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:52:52 +0100 Subject: [PATCH 2/4] Update sshmanager.class.php --- core/class/sshmanager.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/class/sshmanager.class.php b/core/class/sshmanager.class.php index 6fe9f0c..2cf060a 100644 --- a/core/class/sshmanager.class.php +++ b/core/class/sshmanager.class.php @@ -183,6 +183,9 @@ public static function checkSSHConnection($hostId) { return $sshmanager->internalCheckSSHConnection(); } + // TODO Add a timeout option to executeCmds + // TODO Check on timeout if the connection is closed or not, and if not, reset the connection + /** * execute ssh cmd on the remote host provided by hostId * @@ -617,6 +620,7 @@ private function internalExecuteCmd(string $command, $cmdName = '') { if ($exNeedReset) { try { $ssh2->reset(); + log::add(__CLASS__, 'debug', '[' . $this->getName() . '] ' . (!empty($cmdName) ? $cmdName : 'Cmd') . ' :: Reset Connection'); } catch (Exception $ex) { log::add(__CLASS__, 'error', '[' . $this->getName() . '] ' . (!empty($cmdName) ? $cmdName : 'Cmd') . ' Reset Exception :: ' . $ex->getMessage()); From 4b2f690107c79ef965ce8f1e80be9f184640667c Mon Sep 17 00:00:00 2001 From: Olivier <16240457+TiTidom-RC@users.noreply.github.com> Date: Sun, 3 Nov 2024 23:39:18 +0100 Subject: [PATCH 3/4] Update sshmanager.class.php --- core/class/sshmanager.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/class/sshmanager.class.php b/core/class/sshmanager.class.php index 2cf060a..06f7f27 100644 --- a/core/class/sshmanager.class.php +++ b/core/class/sshmanager.class.php @@ -599,6 +599,9 @@ private function internalExecuteCmd(string $command, $cmdName = '') { //TODO: '\n' should be escaped from $result before logging log::add(__CLASS__, 'debug', '[' . $this->getName() . '] ' . (!empty($cmdName) ? $cmdName : 'Cmd') . ' :: ' . str_replace("\r\n", "\\r\\n", $command)); log::add(__CLASS__, 'debug', '[' . $this->getName() . '] ' . (!empty($cmdName) ? $cmdName : 'Cmd') . ' Result :: ' . $result); + } else { + log::add(__CLASS__, 'debug', '[' . $this->getName() . '] ' . (!empty($cmdName) ? $cmdName : 'Cmd') . ' :: ' . str_replace("\r\n", "\\r\\n", $command)); + log::add(__CLASS__, 'debug', '[' . $this->getName() . '] ' . (!empty($cmdName) ? $cmdName : 'Cmd') . ' :: Empty Result'); } } catch (RuntimeException $ex) { log::add(__CLASS__, 'debug', '[' . $this->getName() . '] ' . (!empty($cmdName) ? $cmdName : 'Cmd') . ' :: ' . str_replace("\r\n", "\\r\\n", $command)); From d9abf4f85d05dc3052f02bfcd9c98415f37fdca9 Mon Sep 17 00:00:00 2001 From: Olivier <16240457+TiTidom-RC@users.noreply.github.com> Date: Mon, 4 Nov 2024 00:05:25 +0100 Subject: [PATCH 4/4] todo : empty result to change --- core/class/sshmanager.class.php | 2 ++ plugin_info/info.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/class/sshmanager.class.php b/core/class/sshmanager.class.php index 06f7f27..e2e51ef 100644 --- a/core/class/sshmanager.class.php +++ b/core/class/sshmanager.class.php @@ -594,6 +594,8 @@ private function internalExecuteCmd(string $command, $cmdName = '') { return $result; } + // TODO ATTENTION, une variable qui renvoit 0 est considérée comme vide... A corriger + if (!empty($result)) { $result = trim($result); //TODO: '\n' should be escaped from $result before logging diff --git a/plugin_info/info.json b/plugin_info/info.json index f4d250d..95fa363 100644 --- a/plugin_info/info.json +++ b/plugin_info/info.json @@ -1,7 +1,7 @@ { "id": "sshmanager", "name": "SSH Manager", - "pluginVersion": "1.0.3", + "pluginVersion": "1.0.4", "description": { "fr_FR": "Plugin permettant d'ajouter (manuellement ou à partir de templates) des commandes SSH à executer (manuellement ou automatiquement) sur des équipements distants, et pouvant également être utilisé par d'autres plugin comme passerelle SSH.", "en_US": "Plugin for adding (manually or from templates) SSH commands to be executed (manually or automatically) on remote devices, and which can also be used by other plugins as an SSH gateway.",