From db60c35a722fa58cb1b77630b7f8b1b2abd0a541 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 15 Jun 2021 13:10:07 -0700 Subject: [PATCH] Improved batch upload command information. --- views/default.handlebars | 2 +- webserver.js | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/views/default.handlebars b/views/default.handlebars index 4a1cd113..6e4e4564 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -5094,7 +5094,7 @@ } else if (op == 109) { // Upload files var wintype = false, linuxtype = false, chkNodeIds = getCheckedDevices(); - for (var i in chkNodeIds) { var n = getNodeFromId(chkNodeIds[i]); if (n.agent) { if ((n.agent.id > 0) && (n.agent.id < 5)) { wintype = true; } else { linuxtype = true; } } } + for (var i in chkNodeIds) { var n = getNodeFromId(chkNodeIds[i]); if (n.agent) { if (((n.agent.id > 0) && (n.agent.id < 5)) || (n.agent.id == 34)) { wintype = true; } else { linuxtype = true; } } } var x = "Upload selected files to all selected devices" + '

'; x += '
'; x += ''; diff --git a/webserver.js b/webserver.js index 09261d81..0a55175f 100644 --- a/webserver.js +++ b/webserver.js @@ -3785,9 +3785,28 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { for (var i in cmd.nodeids) { obj.GetNodeWithRights(cmd.domain, cmd.user, cmd.nodeids[i], function (node, rights, visible) { if ((node == null) || ((rights & 8) == 0) || (visible == false)) return; // We don't have remote control rights to this device - var agentPath = ((node.agent.id > 0) && (node.agent.id < 5)) ? cmd.windowsPath : cmd.linuxPath; + var agentPath = (((node.agent.id > 0) && (node.agent.id < 5)) || (node.agent.id == 34)) ? cmd.windowsPath : cmd.linuxPath; if (agentPath == null) return; + // Compute user consent + var consent = 0; + var mesh = obj.meshes[node.meshid]; + if (typeof domain.userconsentflags == 'number') { consent |= domain.userconsentflags; } // Add server required consent flags + if ((mesh != null) && (typeof mesh.consent == 'number')) { consent |= mesh.consent; } // Add device group user consent + if (typeof node.consent == 'number') { consent |= node.consent; } // Add node user consent + if (typeof user.consent == 'number') { consent |= user.consent; } // Add user consent + + // Check if we need to add consent flags because of a user group link + if ((mesh != null) && (user.links != null) && (user.links[mesh._id] == null) && (user.links[node._id] == null)) { + // This user does not have a direct link to the device group or device. Find all user groups the would cause the link. + for (var i in user.links) { + var ugrp = parent.userGroups[i]; + if ((ugrp != null) && (ugrp.consent != null) && (ugrp.links != null) && ((ugrp.links[mesh._id] != null) || (ugrp.links[node._id] != null))) { + consent |= ugrp.consent; // Add user group consent flags + } + } + } + // Event that this operation is being performed. var targets = obj.CreateNodeDispatchTargets(node.meshid, node._id, ['server-users', cmd.user._id]); var msgid = 103; // "Batch upload of {0} file(s) to folder {1}" @@ -3797,7 +3816,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { // Send the agent commands to perform the batch upload operation for (var f in cmd.files) { if (cmd.files[f].name != null) { - const acmd = { action: 'wget', overwrite: cmd.overwrite, createFolder: cmd.createFolder, urlpath: '/agentdownload.ashx?c=' + obj.parent.encodeCookie({ a: 'tmpdl', d: cmd.domain.id, nid: node._id, f: cmd.files[f].target }, obj.parent.loginCookieEncryptionKey), path: obj.path.join(agentPath, cmd.files[f].name), folder: agentPath, servertlshash: tlsCertHash }; + const acmd = { action: 'wget', userid: user._id, username: user.name, realname: user.realname, remoteaddr: req.clientIp, consent: consent, rights: rights, overwrite: cmd.overwrite, createFolder: cmd.createFolder, urlpath: '/agentdownload.ashx?c=' + obj.parent.encodeCookie({ a: 'tmpdl', d: cmd.domain.id, nid: node._id, f: cmd.files[f].target }, obj.parent.loginCookieEncryptionKey), path: obj.path.join(agentPath, cmd.files[f].name), folder: agentPath, servertlshash: tlsCertHash }; var agent = obj.wsagents[node._id]; if (agent != null) { try { agent.send(JSON.stringify(acmd)); } catch (ex) { } } // TODO: Add support for peer servers.