Skip to content

Commit

Permalink
Merge pull request #61 from TiTidom-RC/dev
Browse files Browse the repository at this point in the history
v1.0.6
  • Loading branch information
TiTidom-RC authored Nov 10, 2024
2 parents 486bbe8 + 3484704 commit 27ab838
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
63 changes: 62 additions & 1 deletion desktop/php/params.sshmanager.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,68 @@
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">{{Clé SSH}}</label>
<label class="col-md-4 control-label">{{Clé SSH}}
<sup><i class="fas fa-play-circle icon_orange tooltips" title="{{Cliquez ici pour formater la clé SSH en blocs de 64 caractères}}" onclick="reformatSSHKey()"></i></sup>
<script>
function reformatSSHKey() {
var sshKeyField = document.querySelector('[data-l2key="<?= sshmanager::CONFIG_SSH_KEY ?>"]');
var sshKey = sshKeyField.value;

// Regular expressions to match the header and footer of the key
var headerRegex = /-----BEGIN [A-Z ]+ KEY-----/;
var footerRegex = /-----END [A-Z ]+ KEY-----/;

// Extract the header and footer of the key
var headerMatch = sshKey.match(headerRegex);
var footerMatch = sshKey.match(footerRegex);

if (headerMatch && footerMatch) {
var header = headerMatch[0];
var footer = footerMatch[0];

// Remove the header and footer from the key and trim it
var keyBody = sshKey.replace(header, "").replace(footer, "").trim();

// Check if the key body is already formatted
var isFormatted = keyBody.split('\n').every(line => line.length <= 64);

if (!isFormatted) {
// Format the key body in blocks of 64 characters
var formattedKeyBody = keyBody.replace(/(.{64})/g, "$1\n");

// Reconstruct the key with header and footer
var formattedKey = header + "\n" + formattedKeyBody + "\n" + footer;

// Update the input field with the formatted key
sshKeyField.value = formattedKey;
jeedomUtils.showAlert({
title: "SSH Manager - Format SSH Key",
message: "Formatage de la clé SSH en blocs de 64 caractères :: OK",
level: 'success',
emptyBefore: false
});
} else {
jeedomUtils.showAlert({
title: "SSH Manager - Format SSH Key",
message: "{{La clé SSH est déjà formatée en blocs de 64 caractères !}}",
level: 'info',
emptyBefore: false
});
console.error("SSH key is already formatted in blocks of 64 characters");
}

} else {
jeedomUtils.showAlert({
title: "SSH Manager - Format SSH Key",
message: "{{Format de la clé SSH invalide !}}",
level: 'warning',
emptyBefore: false
});
console.error("Invalid SSH key format");
}
}
</script>
</label>
<div class="col-md-8">
<textarea class="eqLogicAttr form-control" rows="5" data-l1key="configuration" data-l2key="<?= sshmanager::CONFIG_SSH_KEY ?>" placeholder="{{Saisir la clé SSH}}" wrap="off" spellcheck="false"></textarea>
</div>
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.5",
"pluginVersion": "1.0.6",
"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 27ab838

Please sign in to comment.