Improved batch upload command information.
Ylian Saint-Hilaire committed
Jun 15, 2021 at 13:10 UTC
db60c35a722fa58cb1b77630b7f8b1b2abd0a541
2 files changed
+22
-3
views/default.handlebars
+1
-1
@@ -5094,7 +5094,7 @@
5094
} else if (op == 109) {
5095
// Upload files
5096
var wintype = false, linuxtype = false, chkNodeIds = getCheckedDevices();
5097
- 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; } } }
5097
+ 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; } } }
5098
var x = "Upload selected files to all selected devices" + '<br /><br />';
5099
x += '<form method=post enctype=multipart/form-data action=uploadfilebatch.ashx target=fileUploadFrame>';
5100
x += '<input type=hidden name=authCookie value=' + authCookie + ' /><input type=hidden name=nodeIds value=' + chkNodeIds.join(',') + ' /><input type=submit id=d2batchUploadSubmit style=display:none />';
webserver.js
+21
-2
@@ -3785,9 +3785,28 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3785
for (var i in cmd.nodeids) {
3786
obj.GetNodeWithRights(cmd.domain, cmd.user, cmd.nodeids[i], function (node, rights, visible) {
3787
if ((node == null) || ((rights & 8) == 0) || (visible == false)) return; // We don't have remote control rights to this device
3788
- var agentPath = ((node.agent.id > 0) && (node.agent.id < 5)) ? cmd.windowsPath : cmd.linuxPath;
3788
+ var agentPath = (((node.agent.id > 0) && (node.agent.id < 5)) || (node.agent.id == 34)) ? cmd.windowsPath : cmd.linuxPath;
3789
if (agentPath == null) return;
3790
3791
+ // Compute user consent
3792
+ var consent = 0;
3793
+ var mesh = obj.meshes[node.meshid];
3794
+ if (typeof domain.userconsentflags == 'number') { consent |= domain.userconsentflags; } // Add server required consent flags
3795
+ if ((mesh != null) && (typeof mesh.consent == 'number')) { consent |= mesh.consent; } // Add device group user consent
3796
+ if (typeof node.consent == 'number') { consent |= node.consent; } // Add node user consent
3797
+ if (typeof user.consent == 'number') { consent |= user.consent; } // Add user consent
3798
+
3799
+ // Check if we need to add consent flags because of a user group link
3800
+ if ((mesh != null) && (user.links != null) && (user.links[mesh._id] == null) && (user.links[node._id] == null)) {
3801
+ // This user does not have a direct link to the device group or device. Find all user groups the would cause the link.
3802
+ for (var i in user.links) {
3803
+ var ugrp = parent.userGroups[i];
3804
+ if ((ugrp != null) && (ugrp.consent != null) && (ugrp.links != null) && ((ugrp.links[mesh._id] != null) || (ugrp.links[node._id] != null))) {
3805
+ consent |= ugrp.consent; // Add user group consent flags
3806
+ }
3807
+ }
3808
+ }
3809
+
3810
// Event that this operation is being performed.
3811
var targets = obj.CreateNodeDispatchTargets(node.meshid, node._id, ['server-users', cmd.user._id]);
3812
var msgid = 103; // "Batch upload of {0} file(s) to folder {1}"
@@ -3797,7 +3816,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3816
// Send the agent commands to perform the batch upload operation
3817
for (var f in cmd.files) {
3818
if (cmd.files[f].name != null) {
3800
- 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 };
3819
+ 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 };
3820
var agent = obj.wsagents[node._id];
3821
if (agent != null) { try { agent.send(JSON.stringify(acmd)); } catch (ex) { } }
3822
// TODO: Add support for peer servers.