Added batch clear agent core and upload default core.

Ylian Saint-Hilaire committed Mar 8, 2021 at 09:55 UTC 8eb5b49ee50129351553dabbc2cb6ae0c8d1b929
2 files changed +61 -39
meshuser.js
+37 -30
@@ -4093,39 +4093,46 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4093 case 'uploadagentcore':
4094 {
4095 if (common.validateString(command.type, 1, 40) == false) break; // Check path
4096 + if (common.validateArray(command.nodeids, 1) == false) break; // Check nodeid's
4097
4097 - // Get the node and the rights for this node
4098 - parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
4099 - if ((node == null) || (((rights & MESHRIGHT_AGENTCONSOLE) == 0) && (user.siteadmin != SITERIGHT_ADMIN))) return;
4098 + // Go thru all node identifiers and run the operation
4099 + for (var i in command.nodeids) {
4100 + var nodeid = command.nodeids[i];
4101 + if (typeof nodeid != 'string') return;
4102
4101 - // TODO: If we have peer servers, inform...
4102 - //if (parent.parent.multiServer != null) { parent.parent.multiServer.DispatchMessage({ action: 'uploadagentcore', sessionid: ws.sessionId }); }
4103 -
4104 - if (command.type == 'default') {
4105 - // Send the default core to the agent
4106 - parent.parent.updateMeshCore(function () { parent.sendMeshAgentCore(user, domain, node._id, 'default'); });
4107 - } else if (command.type == 'clear') {
4108 - // Clear the mesh agent core on the mesh agent
4109 - parent.sendMeshAgentCore(user, domain, node._id, 'clear');
4110 - } else if (command.type == 'recovery') {
4111 - // Send the recovery core to the agent
4112 - parent.sendMeshAgentCore(user, domain, node._id, 'recovery');
4113 - } else if (command.type == 'tiny') {
4114 - // Send the tiny core to the agent
4115 - parent.sendMeshAgentCore(user, domain, node._id, 'tiny');
4116 - } else if ((command.type == 'custom') && (common.validateString(command.path, 1, 2048) == true)) {
4117 - // Send a mesh agent core to the mesh agent
4118 - var file = parent.getServerFilePath(user, domain, command.path);
4119 - if (file != null) {
4120 - fs.readFile(file.fullpath, 'utf8', function (err, data) {
4121 - if (err != null) {
4122 - data = common.IntToStr(0) + data; // Add the 4 bytes encoding type & flags (Set to 0 for raw)
4123 - parent.sendMeshAgentCore(user, domain, node._id, 'custom', data);
4124 - }
4125 - });
4103 + // Get the node and the rights for this node
4104 + parent.GetNodeWithRights(domain, user, nodeid, function (node, rights, visible) {
4105 + if ((node == null) || (((rights & MESHRIGHT_AGENTCONSOLE) == 0) && (user.siteadmin != SITERIGHT_ADMIN))) return;
4106 +
4107 + // TODO: If we have peer servers, inform...
4108 + //if (parent.parent.multiServer != null) { parent.parent.multiServer.DispatchMessage({ action: 'uploadagentcore', sessionid: ws.sessionId }); }
4109 +
4110 + if (command.type == 'default') {
4111 + // Send the default core to the agent
4112 + parent.parent.updateMeshCore(function () { parent.sendMeshAgentCore(user, domain, node._id, 'default'); });
4113 + } else if (command.type == 'clear') {
4114 + // Clear the mesh agent core on the mesh agent
4115 + parent.sendMeshAgentCore(user, domain, node._id, 'clear');
4116 + } else if (command.type == 'recovery') {
4117 + // Send the recovery core to the agent
4118 + parent.sendMeshAgentCore(user, domain, node._id, 'recovery');
4119 + } else if (command.type == 'tiny') {
4120 + // Send the tiny core to the agent
4121 + parent.sendMeshAgentCore(user, domain, node._id, 'tiny');
4122 + } else if ((command.type == 'custom') && (common.validateString(command.path, 1, 2048) == true)) {
4123 + // Send a mesh agent core to the mesh agent
4124 + var file = parent.getServerFilePath(user, domain, command.path);
4125 + if (file != null) {
4126 + fs.readFile(file.fullpath, 'utf8', function (err, data) {
4127 + if (err != null) {
4128 + data = common.IntToStr(0) + data; // Add the 4 bytes encoding type & flags (Set to 0 for raw)
4129 + parent.sendMeshAgentCore(user, domain, node._id, 'custom', data);
4130 + }
4131 + });
4132 + }
4133 }
4127 - }
4128 - });
4134 + });
4135 + }
4136 break;
4137 }
4138 case 'agentdisconnect':
views/default.handlebars
+24 -9
@@ -4652,7 +4652,12 @@
4652 if ((rights & 4) && ((added & 64) == 0)) { added |= 64; addedOptions += '<option value=107>' + "Edit tags" + '</option>'; }
4653 if ((rights & 8) && ((added & 256) == 0)) { added |= 256; addedOptions += '<option value=109>' + "Upload files" + '</option>'; }
4654 if ((rights & 32768) && ((added & 128) == 0)) { added |= 128; addedOptions += '<option value=101>' + "Delete devices" + '</option>'; }
4655 - if ((node.agent != null) && (features2 & 0x00000010) && (rights == 0xFFFFFFFF) && ((added & 512) == 0)) { added |= 512; addedOptions += '<option value=110>' + "Force agent update" + '</option>'; }
4655 + if ((node.agent != null) && (features2 & 0x00000010) && (rights == 0xFFFFFFFF) && ((added & 512) == 0)) {
4656 + added |= 512;
4657 + addedOptions += '<option value=110>' + "Force agent update" + '</option>';
4658 + addedOptions += '<option value=111>' + "Clear agent core" + '</option>';
4659 + addedOptions += '<option value=112>' + "Upload default server core" + '</option>';
4660 + }
4661 }
4662
4663 var x = "Select an operation to perform on all selected devices. Actions will be performed only with proper rights." + '<br /><br />';
@@ -4745,7 +4750,15 @@
4750 } else if (op == 110) {
4751 // Force agent update
4752 var x = "Force agent update on selected devices?" + '<br /><br />';
4748 - setDialogMode(2, "Edit Device Tags", 3, d2groupActionFunctionAgentUpdateExec, x);
4753 + setDialogMode(2, "For agent update", 3, d2groupActionFunctionAgentUpdateExec, x);
4754 + } else if (op == 111) {
4755 + // Clear agent core
4756 + var x = "Clear agent core on selected devices?" + '<br /><br />';
4757 + setDialogMode(2, "Clear agent core", 3, d2groupActionFunctionAgentClearCoreExec, x);
4758 + } else if (op == 112) {
4759 + // Upload default server core
4760 + var x = "Upload default server core on selected devices?" + '<br /><br />';
4761 + setDialogMode(2, "Upload default server core", 3, d2groupActionFunctionAgentDefaultCodeExec, x);
4762 } else {
4763 // Power operation
4764 meshserver.send({ action: 'poweraction', nodeids: getCheckedDevices(), actiontype: parseInt(op) });
@@ -4756,6 +4769,8 @@
4769 function d2batchUploadValidate() { QE('idx_dlgOkButton', (Q('d2uploadinput').files.length != 0) && ((Q('d2winuploadpath') == null) || (Q('d2winuploadpath').value != '')) && ((Q('d2linuxuploadpath') == null) || (Q('d2linuxuploadpath').value != ''))); }
4770 function d2batchUploadValidateOk() { Q('d2batchUploadSubmit').click(); }
4771 function d2groupActionFunctionAgentUpdateExec() { meshserver.send({ action: 'updateAgents', nodeids: getCheckedDevices() }); }
4772 + function d2groupActionFunctionAgentClearCoreExec() { meshserver.send({ action: 'uploadagentcore', nodeids: getCheckedDevices(), type: 'clear' }); }
4773 + function d2groupActionFunctionAgentDefaultCodeExec() { meshserver.send({ action: 'uploadagentcore', nodeids: getCheckedDevices(), type: 'default' }); }
4774
4775 function d2groupActionFunctionNotifyExec() {
4776 var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices();
@@ -9583,8 +9598,8 @@
9598 // Called then user presses the "Change Core" button
9599 function p15uploadCore(e) {
9600 if (xxdialogMode) return;
9586 - if (e.shiftKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'default' }); } // Upload default core
9587 - else if (e.altKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'clear' }); } // Clear the core
9601 + if (e.shiftKey == true) { meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'default' }); } // Upload default core
9602 + else if (e.altKey == true) { meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'clear' }); } // Clear the core
9603 else if (e.ctrlKey == true) { p15uploadCore2(); } // Upload the core from a file
9604 else { setDialogMode(2, "Perform Agent Action", 3, p15uploadCoreEx, addHtmlValue("Action", '<select id=d3coreMode style=width:230px><option value=1>' + "Upload default server core" + '</option><option value=2>' + "Clear the core" + '</option><option value=6>' + "Upload recovery core" + '</option><option value=7>' + "Upload tiny core" + '</option><option value=3>' + "Upload a core file" + '</option><option value=4>' + "Soft disconnect agent" + '</option><option value=5>' + "Hard disconnect agent" + '</option></select>')); }
9605 }
@@ -9592,10 +9607,10 @@
9607 function p15uploadCoreEx() {
9608 if (Q('d3coreMode').value == 1) {
9609 // Upload default core
9595 - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'default' });
9610 + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'default' });
9611 } else if (Q('d3coreMode').value == 2) {
9612 // Clear the core
9598 - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'clear' });
9613 + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'clear' });
9614 } else if (Q('d3coreMode').value == 3) {
9615 // Upload file as core
9616 p15uploadCore2();
@@ -9607,10 +9622,10 @@
9622 meshserver.send({ action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 2 });
9623 } else if (Q('d3coreMode').value == 6) {
9624 // Upload a recovery core
9610 - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type:'recovery' });
9625 + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type:'recovery' });
9626 } else if (Q('d3coreMode').value == 7) {
9627 // Upload a tiny core
9613 - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type:'tiny' });
9628 + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type:'tiny' });
9629 }
9630 }
9631
@@ -9632,7 +9647,7 @@
9647 } else {
9648 // Upload server mesh agent code
9649 var files = d3getFileSel();
9635 - if (files.length == 1) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'custom', path: d3filetreelocation.join('/') + '/' + files[0] }); }
9650 + if (files.length == 1) { meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'custom', path: d3filetreelocation.join('/') + '/' + files[0] }); }
9651 }
9652 }
9653