Improved run command dialog box, users can now select a local file.
Ylian Saint-Hilaire committed
Aug 18, 2022 at 22:09 UTC
bb8b5fed821a19d1f90a95d4d5c8f589a1303f99
1 file changed
+37
-11
views/default.handlebars
+37
-11
@@ -5717,26 +5717,55 @@
5717
if (n.agent) { if ((GetNodeRights(n) & 24) == 24) { agenttype = true; } if ((n.agent.id > 0) && (n.agent.id < 5)) { wintype = true; } else { linuxtype = true; } }
5718
}
5719
if ((wintype == true) || (linuxtype == true) || (agenttype == true)) {
5720
- var x = options.title + '<br />';
5720
+ var x = '';
5721
+ if (options.title) { x += options.title + '<br />'; }
5722
x += '<select id=d2cmdtype onclick=d2runCommandValidate() style=width:100%;margin-bottom:4px;margin-top:4px>';
5723
if (wintype == true) { x += '<option value=1>' + "Windows Command Prompt" + '</option><option value=2>' + "Windows PowerShell" + '</option>'; }
5724
if (linuxtype == true) { x += '<option value=3>' + "Linux/BSD/macOS Command Shell" + '</option>'; }
5725
if (agenttype == true) { x += '<option value=4>' + "Agent Console" + '</option>'; } // MESHRIGHT_REMOTECONTROL & MESHRIGHT_AGENTCONSOLE are needed
5726
x += '</select>';
5727
x += '<select id=d2cmduser style=width:100%;margin-bottom:4px><option value=0>' + "Run as agent" + '</option><option value=1>' + "Run as user, agent if no user" + '</option><option value=2>' + "Must run as user" + '</option></select>';
5727
- x += '<textarea id=d2runcmd style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea>';
5728
+ x += '<select id=d2cmdsource onclick=d2runCommandValidate() style=width:100%;margin-bottom:4px><option value=0>' + "Commands from text box" + '</option><option value=1>' + "Commands from file" + '</option>';
5729
+ //if (userinfo.siteadmin & 8) { x += '<option value=2>' + "Commands from file on server" + '</option>'; }
5730
+ x += '</select><textarea id=d2runcmd onkeyup=d2runCommandValidate() style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea>';
5731
+ x += '<div id=d2runfile style=display:none><input id=d2runfileex type=file onchange=d2runCommandValidate() id=d2localFile name=files onchange=d2runCommandValidate() /></div>';
5732
+ x += '<div id=d2runsfile style=display:none>bb</div>';
5733
setDialogMode(2, "Run Commands", 3, d2groupActionFunctionRunCommands, x, options);
5734
Q('d2runcmd').focus();
5730
- //QE('idx_dlgOkButton', true);
5735
d2runCommandValidate();
5736
}
5737
}
5734
- function d2runCommandValidate() { QV('d2cmduser', Q('d2cmdtype').value < 4); }
5738
+ function d2runCommandValidate() {
5739
+ QV('d2cmduser', Q('d2cmdtype').value < 4);
5740
+ QV('d2runcmd', Q('d2cmdsource').value == 0);
5741
+ QV('d2runfile', Q('d2cmdsource').value == 1);
5742
+ QV('d2runsfile', Q('d2cmdsource').value == 2);
5743
+ var ok = false;
5744
+ if (Q('d2cmdsource').value == 0) { if (Q('d2runcmd').value.length > 0) { ok = true; } } // From text box
5745
+ if (Q('d2cmdsource').value == 1) { if (Q('d2runfileex').files.length == 1) { ok = true; } } // From file
5746
+ if (Q('d2cmdsource').value == 2) { ok = false; } // From server file
5747
+ QE('idx_dlgOkButton', ok);
5748
+ }
5749
function d2groupActionFunctionRunCommands(b, options) {
5750
var type = 3;
5751
try { type = parseInt(Q('d2cmdtype').value); } catch (ex) { }
5738
- meshserver.send({ action: 'runcommands', nodeids: options.nodeids, type: type, cmds: Q('d2runcmd').value, runAsUser: parseInt(Q('d2cmduser').value) });
5739
- if (options.func) { options.func(); }
5752
+ var cmd = { action: 'runcommands', nodeids: options.nodeids, type: type, runAsUser: parseInt(Q('d2cmduser').value) };
5753
+ if (Q('d2cmdsource').value == 0) {
5754
+ // From text box
5755
+ cmd.cmds = Q('d2runcmd').value;
5756
+ meshserver.send(cmd);
5757
+ if (options.func) { options.func(); }
5758
+ }
5759
+ if (Q('d2cmdsource').value == 1) {
5760
+ // From file
5761
+ var reader = new FileReader();
5762
+ reader.onload = function (e) { cmd.cmds = e.target.result; meshserver.send(cmd); if (options.func) { options.func(); } }
5763
+ reader.readAsText(Q('d2runfileex').files[0]);
5764
+ }
5765
+ if (Q('d2cmdsource').value == 2) {
5766
+ // From server file
5767
+ cmd.cmds = '';
5768
+ }
5769
}
5770
5771
function onSortSelectChange(skipsave) {
@@ -7179,7 +7208,7 @@
7208
if (((meshrights & (4 + 8 + 64 + 262144)) != 0) && (node.mtype < 3) && ((node.agent == null) || (node.agent.id != 34))) { x += '<input type=button value="' + "Actions" + '" title="' + "Perform power actions on the device" + '" onclick=deviceActionFunction() />'; }
7209
x += '<input type=button value="' + "Notes" + '" title="' + "View notes about this device" + '" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponentEx(node._id) + '") />';
7210
x += '<input type=button value="' + "Log Event" + '" title="' + "Write an event for this device" + '" onclick=writeDeviceEvent("' + encodeURIComponentEx(node._id) + '") />';
7182
- if ((node.mtype == 2) && (connectivity & 1) && (meshrights == 0xFFFFFFFF)) { x += '<input type=button value="' + "Run" + '" title="' + "Run commands on this device" + '" onclick=runDeviceCmd("' + encodeURIComponentEx(node._id) + '") />'; }
7211
+ if ((node.mtype == 2) && (connectivity & 1) && ((meshrights & 131072) != 0)) { x += '<input type=button value="' + "Run" + '" title="' + "Run commands on this device" + '" onclick=runDeviceCmd("' + encodeURIComponentEx(node._id) + '") />'; }
7212
if (node.mtype != 4) {
7213
if ((meshrights & 8) && ((connectivity & 1) || ((node.pmt == 1) && ((features2 & 2) != 0)))) { x += '<input type=button value="' + "Message" + '" title="' + "Display a text message on the remote device" + '" onclick=deviceMessageFunction() />'; }
7214
//if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast title="' + "Display a text message of the remote device" + '" onclick=deviceToastFunction() />'; }
@@ -7639,10 +7668,7 @@
7668
}
7669
7670
// Run commands on current device
7642
- function runDeviceCmd(nodeid) {
7643
- if (xxdialogMode) return;
7644
- d2runCommandDialog({ nodeids: [ decodeURIComponent(nodeid) ], title: "Run commands on this device." });
7645
- }
7671
+ function runDeviceCmd(nodeid) { if (xxdialogMode) return; d2runCommandDialog({ nodeids: [ decodeURIComponent(nodeid) ] }); }
7672
7673
function writeDeviceEvent(nodeid) {
7674
if (xxdialogMode) return;