From 8eb5b49ee50129351553dabbc2cb6ae0c8d1b929 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 8 Mar 2021 09:55:18 -0800 Subject: [PATCH] Added batch clear agent core and upload default core. --- meshuser.js | 65 ++++++++++++++++++++++------------------ views/default.handlebars | 33 ++++++++++++++------ 2 files changed, 60 insertions(+), 38 deletions(-) diff --git a/meshuser.js b/meshuser.js index e8545cdc..e0d4b624 100644 --- a/meshuser.js +++ b/meshuser.js @@ -4093,39 +4093,46 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use case 'uploadagentcore': { if (common.validateString(command.type, 1, 40) == false) break; // Check path + if (common.validateArray(command.nodeids, 1) == false) break; // Check nodeid's - // Get the node and the rights for this node - parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) { - if ((node == null) || (((rights & MESHRIGHT_AGENTCONSOLE) == 0) && (user.siteadmin != SITERIGHT_ADMIN))) return; + // Go thru all node identifiers and run the operation + for (var i in command.nodeids) { + var nodeid = command.nodeids[i]; + if (typeof nodeid != 'string') return; - // TODO: If we have peer servers, inform... - //if (parent.parent.multiServer != null) { parent.parent.multiServer.DispatchMessage({ action: 'uploadagentcore', sessionid: ws.sessionId }); } + // Get the node and the rights for this node + parent.GetNodeWithRights(domain, user, nodeid, function (node, rights, visible) { + if ((node == null) || (((rights & MESHRIGHT_AGENTCONSOLE) == 0) && (user.siteadmin != SITERIGHT_ADMIN))) return; - if (command.type == 'default') { - // Send the default core to the agent - parent.parent.updateMeshCore(function () { parent.sendMeshAgentCore(user, domain, node._id, 'default'); }); - } else if (command.type == 'clear') { - // Clear the mesh agent core on the mesh agent - parent.sendMeshAgentCore(user, domain, node._id, 'clear'); - } else if (command.type == 'recovery') { - // Send the recovery core to the agent - parent.sendMeshAgentCore(user, domain, node._id, 'recovery'); - } else if (command.type == 'tiny') { - // Send the tiny core to the agent - parent.sendMeshAgentCore(user, domain, node._id, 'tiny'); - } else if ((command.type == 'custom') && (common.validateString(command.path, 1, 2048) == true)) { - // Send a mesh agent core to the mesh agent - var file = parent.getServerFilePath(user, domain, command.path); - if (file != null) { - fs.readFile(file.fullpath, 'utf8', function (err, data) { - if (err != null) { - data = common.IntToStr(0) + data; // Add the 4 bytes encoding type & flags (Set to 0 for raw) - parent.sendMeshAgentCore(user, domain, node._id, 'custom', data); - } - }); + // TODO: If we have peer servers, inform... + //if (parent.parent.multiServer != null) { parent.parent.multiServer.DispatchMessage({ action: 'uploadagentcore', sessionid: ws.sessionId }); } + + if (command.type == 'default') { + // Send the default core to the agent + parent.parent.updateMeshCore(function () { parent.sendMeshAgentCore(user, domain, node._id, 'default'); }); + } else if (command.type == 'clear') { + // Clear the mesh agent core on the mesh agent + parent.sendMeshAgentCore(user, domain, node._id, 'clear'); + } else if (command.type == 'recovery') { + // Send the recovery core to the agent + parent.sendMeshAgentCore(user, domain, node._id, 'recovery'); + } else if (command.type == 'tiny') { + // Send the tiny core to the agent + parent.sendMeshAgentCore(user, domain, node._id, 'tiny'); + } else if ((command.type == 'custom') && (common.validateString(command.path, 1, 2048) == true)) { + // Send a mesh agent core to the mesh agent + var file = parent.getServerFilePath(user, domain, command.path); + if (file != null) { + fs.readFile(file.fullpath, 'utf8', function (err, data) { + if (err != null) { + data = common.IntToStr(0) + data; // Add the 4 bytes encoding type & flags (Set to 0 for raw) + parent.sendMeshAgentCore(user, domain, node._id, 'custom', data); + } + }); + } } - } - }); + }); + } break; } case 'agentdisconnect': diff --git a/views/default.handlebars b/views/default.handlebars index 235454c9..be36b713 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -4652,7 +4652,12 @@ if ((rights & 4) && ((added & 64) == 0)) { added |= 64; addedOptions += ''; } if ((rights & 8) && ((added & 256) == 0)) { added |= 256; addedOptions += ''; } if ((rights & 32768) && ((added & 128) == 0)) { added |= 128; addedOptions += ''; } - if ((node.agent != null) && (features2 & 0x00000010) && (rights == 0xFFFFFFFF) && ((added & 512) == 0)) { added |= 512; addedOptions += ''; } + if ((node.agent != null) && (features2 & 0x00000010) && (rights == 0xFFFFFFFF) && ((added & 512) == 0)) { + added |= 512; + addedOptions += ''; + addedOptions += ''; + addedOptions += ''; + } } var x = "Select an operation to perform on all selected devices. Actions will be performed only with proper rights." + '

'; @@ -4745,7 +4750,15 @@ } else if (op == 110) { // Force agent update var x = "Force agent update on selected devices?" + '

'; - setDialogMode(2, "Edit Device Tags", 3, d2groupActionFunctionAgentUpdateExec, x); + setDialogMode(2, "For agent update", 3, d2groupActionFunctionAgentUpdateExec, x); + } else if (op == 111) { + // Clear agent core + var x = "Clear agent core on selected devices?" + '

'; + setDialogMode(2, "Clear agent core", 3, d2groupActionFunctionAgentClearCoreExec, x); + } else if (op == 112) { + // Upload default server core + var x = "Upload default server core on selected devices?" + '

'; + setDialogMode(2, "Upload default server core", 3, d2groupActionFunctionAgentDefaultCodeExec, x); } else { // Power operation meshserver.send({ action: 'poweraction', nodeids: getCheckedDevices(), actiontype: parseInt(op) }); @@ -4756,6 +4769,8 @@ function d2batchUploadValidate() { QE('idx_dlgOkButton', (Q('d2uploadinput').files.length != 0) && ((Q('d2winuploadpath') == null) || (Q('d2winuploadpath').value != '')) && ((Q('d2linuxuploadpath') == null) || (Q('d2linuxuploadpath').value != ''))); } function d2batchUploadValidateOk() { Q('d2batchUploadSubmit').click(); } function d2groupActionFunctionAgentUpdateExec() { meshserver.send({ action: 'updateAgents', nodeids: getCheckedDevices() }); } + function d2groupActionFunctionAgentClearCoreExec() { meshserver.send({ action: 'uploadagentcore', nodeids: getCheckedDevices(), type: 'clear' }); } + function d2groupActionFunctionAgentDefaultCodeExec() { meshserver.send({ action: 'uploadagentcore', nodeids: getCheckedDevices(), type: 'default' }); } function d2groupActionFunctionNotifyExec() { var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices(); @@ -9583,8 +9598,8 @@ // Called then user presses the "Change Core" button function p15uploadCore(e) { if (xxdialogMode) return; - if (e.shiftKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'default' }); } // Upload default core - else if (e.altKey == true) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'clear' }); } // Clear the core + if (e.shiftKey == true) { meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'default' }); } // Upload default core + else if (e.altKey == true) { meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'clear' }); } // Clear the core else if (e.ctrlKey == true) { p15uploadCore2(); } // Upload the core from a file else { setDialogMode(2, "Perform Agent Action", 3, p15uploadCoreEx, addHtmlValue("Action", '')); } } @@ -9592,10 +9607,10 @@ function p15uploadCoreEx() { if (Q('d3coreMode').value == 1) { // Upload default core - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'default' }); + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'default' }); } else if (Q('d3coreMode').value == 2) { // Clear the core - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'clear' }); + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'clear' }); } else if (Q('d3coreMode').value == 3) { // Upload file as core p15uploadCore2(); @@ -9607,10 +9622,10 @@ meshserver.send({ action: 'agentdisconnect', nodeid: consoleNode._id, disconnectMode: 2 }); } else if (Q('d3coreMode').value == 6) { // Upload a recovery core - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type:'recovery' }); + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type:'recovery' }); } else if (Q('d3coreMode').value == 7) { // Upload a tiny core - meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type:'tiny' }); + meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type:'tiny' }); } } @@ -9632,7 +9647,7 @@ } else { // Upload server mesh agent code var files = d3getFileSel(); - if (files.length == 1) { meshserver.send({ action: 'uploadagentcore', nodeid: consoleNode._id, type: 'custom', path: d3filetreelocation.join('/') + '/' + files[0] }); } + if (files.length == 1) { meshserver.send({ action: 'uploadagentcore', nodeids: [ consoleNode._id ], type: 'custom', path: d3filetreelocation.join('/') + '/' + files[0] }); } } }