Skip to content

Commit

Permalink
Merge pull request #58 from TiTidom-RC/dev
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
TiTidom-RC authored Nov 4, 2024
2 parents 2c8c8f2 + d9abf4f commit 489c0a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```

Expand All @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions core/class/sshmanager.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -591,11 +594,16 @@ 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
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));
Expand All @@ -617,6 +625,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());
Expand Down
2 changes: 1 addition & 1 deletion plugin_info/info.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down

0 comments on commit 489c0a2

Please sign in to comment.