Added support for device stream downloads.
Ylian Saint-Hilaire committed
Aug 26, 2020 at 18:42 UTC
e744813598cffff8172b7ba3e422c0ce8d1aa569
6 files changed
+325
-9
MeshCentralServer.njsproj
+2
-1
@@ -107,6 +107,7 @@
107
<Compile Include="meshctrl.js" />
108
<Compile Include="meshdesktopmultiplex.js" />
109
<Compile Include="meshmail.js" />
110
+ <Compile Include="meshrelay.js" />
111
<Compile Include="meshsms.js" />
112
<Compile Include="meshscanner.js" />
113
<Compile Include="certoperations.js" />
@@ -115,7 +116,7 @@
116
<Compile Include="interceptor.js" />
117
<Compile Include="meshcentral.js" />
118
<Compile Include="meshagent.js" />
118
- <Compile Include="meshrelay.js" />
119
+ <Compile Include="meshdevicefile.js" />
120
<Compile Include="meshuser.js" />
121
<Compile Include="mpsserver.js" />
122
<Compile Include="mqttbroker.js" />
agents/meshcore.js
+23
-7
@@ -1239,7 +1239,7 @@ function createMeshCore(agent) {
1239
}
1240
1241
// Sent tunnel statistics to the server, only send this if compression was used.
1242
- if (this.bytesSent_uncompressed.toString() != this.bytesSent_actual.toString()) {
1242
+ if ((this.bytesSent_uncompressed) && (this.bytesSent_uncompressed.toString() != this.bytesSent_actual.toString())) {
1243
mesh.SendCommand({
1244
action: 'tunnelCloseStats',
1245
url: tunnel.url,
@@ -1256,7 +1256,7 @@ function createMeshCore(agent) {
1256
}
1257
1258
//sendConsoleText("Tunnel #" + this.httprequest.index + " closed. Sent -> " + this.bytesSent_uncompressed + ' bytes (uncompressed), ' + this.bytesSent_actual + ' bytes (actual), ' + this.bytesSent_ratio + '% compression', this.httprequest.sessionid);
1259
- delete tunnels[this.httprequest.index];
1259
+ if (this.httprequest.index) { delete tunnels[this.httprequest.index]; }
1260
1261
/*
1262
// Close the watcher if required
@@ -1269,7 +1269,7 @@ function createMeshCore(agent) {
1269
1270
// If there is a upload or download active on this connection, close the file
1271
if (this.httprequest.uploadFile) { fs.closeSync(this.httprequest.uploadFile); delete this.httprequest.uploadFile; delete this.httprequest.uploadFileid; delete this.httprequest.uploadFilePath; }
1272
- if (this.httprequest.downloadFile) { fs.closeSync(this.httprequest.downloadFile); delete this.httprequest.downloadFile; }
1272
+ if (this.httprequest.downloadFile) { delete this.httprequest.downloadFile; }
1273
1274
// Clean up WebRTC
1275
if (this.webrtc != null) {
@@ -1311,12 +1311,29 @@ function createMeshCore(agent) {
1311
else
1312
{
1313
// Handle tunnel data
1314
- if (this.httprequest.protocol == 0) { // 1 = Terminal (admin), 2 = Desktop, 5 = Files, 6 = PowerShell (admin), 7 = Plugin Data Exchange, 8 = Terminal (user), 9 = PowerShell (user)
1314
+ if (this.httprequest.protocol == 0) { // 1 = Terminal (admin), 2 = Desktop, 5 = Files, 6 = PowerShell (admin), 7 = Plugin Data Exchange, 8 = Terminal (user), 9 = PowerShell (user), 10 = FileTransfer
1315
// Take a look at the protocol
1316
if ((data.length > 3) && (data[0] == '{')) { onTunnelControlData(data, this); return; }
1317
this.httprequest.protocol = parseInt(data);
1318
if (typeof this.httprequest.protocol != 'number') { this.httprequest.protocol = 0; }
1319
- if ((this.httprequest.protocol == 1) || (this.httprequest.protocol == 6) || (this.httprequest.protocol == 8) || (this.httprequest.protocol == 9))
1319
+ if (this.httprequest.protocol == 10) {
1320
+ //
1321
+ // Basic file transfer
1322
+ //
1323
+ var stats = null;
1324
+ try { stats = require('fs').statSync(this.httprequest.xoptions.file) } catch (e) { }
1325
+ try { if (stats) { this.httprequest.downloadFile = fs.createReadStream(this.httprequest.xoptions.file, { flags: 'rbN' }); } } catch (e) { }
1326
+ if (this.httprequest.downloadFile) {
1327
+ sendConsoleText('BasicFileTransfer, ok, ' + this.httprequest.xoptions.file + ', ' + JSON.stringify(stats));
1328
+ this.write(JSON.stringify({ op: 'ok', size: stats.size }));
1329
+ this.httprequest.downloadFile.pipe(this);
1330
+ this.httprequest.downloadFile.end = function () { }
1331
+ } else {
1332
+ sendConsoleText('BasicFileTransfer, cancel, ' + this.httprequest.xoptions.file);
1333
+ this.write(JSON.stringify({ op: 'cancel' }));
1334
+ }
1335
+ }
1336
+ else if ((this.httprequest.protocol == 1) || (this.httprequest.protocol == 6) || (this.httprequest.protocol == 8) || (this.httprequest.protocol == 9))
1337
{
1338
//
1339
// Remote Terminal
@@ -1808,8 +1825,7 @@ function createMeshCore(agent) {
1825
MeshServerLog("Failed to start remote desktop after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
1826
this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
1827
});
1811
- }
1812
- else {
1828
+ } else {
1829
// User Consent Prompt is not required
1830
if (this.httprequest.consent && (this.httprequest.consent & 1)) {
1831
// User Notifications is required
meshctrl.js
+1
@@ -1066,6 +1066,7 @@ function serverConnect() {
1066
if (settings.cmd == 'showevents') { console.log(data); return; }
1067
switch (data.action) {
1068
case 'serverinfo': { // SERVERINFO
1069
+ console.log(data);
1070
settings.currentDomain = data.serverinfo.domain;
1071
if (settings.cmd == 'serverinfo') {
1072
if (args.json) {
meshdevicefile.js
new
+266
@@ -0,0 +1,266 @@
1
+/**
2
+* @description MeshCentral device file download relay module
3
+* @author Ylian Saint-Hilaire
4
+* @copyright Intel Corporation 2018-2020
5
+* @license Apache-2.0
6
+* @version v0.0.1
7
+*/
8
+
9
+/*jslint node: true */
10
+/*jshint node: true */
11
+/*jshint strict:false */
12
+/*jshint -W097 */
13
+/*jshint esversion: 6 */
14
+"use strict";
15
+
16
+module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, user, meshid, nodeid) {
17
+ var obj = {};
18
+ obj.ws = ws;
19
+ obj.res = res;
20
+ obj.user = user;
21
+ obj.ruserid = null;
22
+ obj.req = req; // Used in multi-server.js
23
+ obj.id = req.query.id;
24
+ obj.file = req.query.f;
25
+
26
+ // Check relay authentication
27
+ if ((user == null) && (obj.req.query != null) && (obj.req.query.rauth != null)) {
28
+ const rcookie = parent.parent.decodeCookie(obj.req.query.rauth, parent.parent.loginCookieEncryptionKey, 240); // Cookie with 4 hour timeout
29
+ if (rcookie.ruserid != null) { obj.ruserid = rcookie.ruserid; }
30
+ }
31
+
32
+ // Relay session count (we may remove this in the future)
33
+ obj.relaySessionCounted = true;
34
+ parent.relaySessionCount++;
35
+
36
+ // Clean a IPv6 address that encodes a IPv4 address
37
+ function cleanRemoteAddr(addr) { if (addr.startsWith('::ffff:')) { return addr.substring(7); } else { return addr; } }
38
+
39
+ // Disconnect
40
+ obj.close = function (arg) {
41
+ if (obj.ws != null) {
42
+ if ((arg == 1) || (arg == null)) { try { obj.ws.close(); parent.parent.debug('relay', 'FileRelay: Soft disconnect (' + obj.req.clientIp + ')'); } catch (ex) { console.log(e); } } // Soft close, close the websocket
43
+ if (arg == 2) { try { obj.ws._socket._parent.end(); parent.parent.debug('relay', 'FileRelay: Hard disconnect (' + obj.req.clientIp + ')'); } catch (ex) { console.log(e); } } // Hard close, close the TCP socket
44
+ } else if (obj.res != null) {
45
+ try { res.sendStatus(404); } catch (ex) { }
46
+ }
47
+
48
+ // Aggressive cleanup
49
+ delete obj.ws;
50
+ delete obj.res;
51
+ delete obj.peer;
52
+ };
53
+
54
+ // If there is no authentication, drop this connection
55
+ if ((obj.id == null) || ((obj.user == null) && (obj.ruserid == null))) { try { obj.close(); parent.parent.debug('relay', 'FileRelay: Connection with no authentication (' + obj.req.clientIp + ')'); } catch (e) { console.log(e); } return; }
56
+
57
+ obj.sendAgentMessage = function (command, user, domainid) {
58
+ var rights, mesh;
59
+ if (command.nodeid == null) return false;
60
+ var splitnodeid = command.nodeid.split('/');
61
+ // Check that we are in the same domain and the user has rights over this node.
62
+ if ((splitnodeid[0] == 'node') && (splitnodeid[1] == domainid)) {
63
+ // Get the user object
64
+ // See if the node is connected
65
+ var agent = parent.wsagents[command.nodeid];
66
+ if (agent != null) {
67
+ // Check if we have permission to send a message to that node
68
+ rights = parent.GetNodeRights(user, agent.dbMeshKey, agent.dbNodeKey);
69
+ mesh = parent.meshes[agent.dbMeshKey];
70
+ if ((rights != null) && (mesh != null) || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
71
+ command.rights = rights; // Add user rights flags to the message
72
+ if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent
73
+ if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
74
+ command.username = user.name; // Add user name
75
+ command.realname = user.realname; // Add real name
76
+ if (typeof domain.desktopprivacybartext == 'string') { command.privacybartext = domain.desktopprivacybartext; } // Privacy bar text
77
+ delete command.nodeid; // Remove the nodeid since it's implyed.
78
+ agent.send(JSON.stringify(command));
79
+ return true;
80
+ }
81
+ } else {
82
+ // Check if a peer server is connected to this agent
83
+ var routing = parent.parent.GetRoutingServerId(command.nodeid, 1); // 1 = MeshAgent routing type
84
+ if (routing != null) {
85
+ // Check if we have permission to send a message to that node
86
+ rights = parent.GetNodeRights(user, routing.meshid, command.nodeid);
87
+ mesh = parent.meshes[routing.meshid];
88
+ if (rights != null || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
89
+ command.rights = rights; // Add user rights flags to the message
90
+ if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent
91
+ if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
92
+ command.username = user.name; // Add user name
93
+ command.realname = user.realname; // Add real name
94
+ if (typeof domain.desktopprivacybartext == 'string') { command.privacybartext = domain.desktopprivacybartext; } // Privacy bar text
95
+ parent.parent.multiServer.DispatchMessageSingleServer(command, routing.serverid);
96
+ return true;
97
+ }
98
+ }
99
+ }
100
+ }
101
+ return false;
102
+ };
103
+
104
+ function performRelay() {
105
+ if (obj.id == null) { try { obj.close(); } catch (e) { } return null; } // Attempt to connect without id, drop this.
106
+ if (obj.ws != null) { obj.ws._socket.setKeepAlive(true, 240000); } // Set TCP keep alive
107
+
108
+ // Check the peer connection status
109
+ {
110
+ var relayinfo = parent.wsrelays[obj.id];
111
+ if (relayinfo) {
112
+ if (relayinfo.state == 1) {
113
+
114
+ // Check that at least one connection is authenticated
115
+ if ((obj.authenticated != true) && (relayinfo.peer1.authenticated != true)) {
116
+ if (ws) { ws.close(); }
117
+ parent.parent.debug('relay', 'FileRelay without-auth: ' + obj.id + ' (' + obj.req.clientIp + ')');
118
+ delete obj.id;
119
+ delete obj.ws;
120
+ delete obj.peer;
121
+ return null;
122
+ }
123
+
124
+ // Connect to peer
125
+ obj.peer = relayinfo.peer1;
126
+ obj.peer.peer = obj;
127
+ relayinfo.peer2 = obj;
128
+ relayinfo.state = 2;
129
+
130
+ // Remove the timeout
131
+ if (relayinfo.timeout) { clearTimeout(relayinfo.timeout); delete relayinfo.timeout; }
132
+
133
+ var agentws = null, file = null;
134
+ if (relayinfo.peer1.ws) { relayinfo.peer1.ws.res = relayinfo.peer2.res; relayinfo.peer1.ws.res = relayinfo.peer2.res; relayinfo.peer1.ws.file = relayinfo.peer2.file; agentws = relayinfo.peer1.ws; file = relayinfo.peer2.file; }
135
+ if (relayinfo.peer2.ws) { relayinfo.peer2.ws.res = relayinfo.peer1.res; relayinfo.peer2.ws.res = relayinfo.peer1.res; relayinfo.peer2.ws.file = relayinfo.peer1.file; agentws = relayinfo.peer2.ws; file = relayinfo.peer1.file; }
136
+ agentws._socket.resume(); // Release the traffic
137
+ try { agentws.send('c'); } catch (ex) { } // Send connect to agent
138
+ try { agentws.send(JSON.stringify({ type: 'options', file: file })); } catch (ex) { } // Send options to agent
139
+ try { agentws.send('10'); } catch (ex) { } // Send file transfer protocol to agent
140
+
141
+ parent.parent.debug('relay', 'FileRelay connected: ' + obj.id + ' (' + obj.req.clientIp + ' --> ' + obj.peer.req.clientIp + ')');
142
+
143
+ // Log the connection
144
+ if (sessionUser != null) {
145
+ var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: sessionUser._id, username: sessionUser.name, msg: "Started file transfer session" + ' \"' + obj.id + '\" from ' + obj.peer.req.clientIp + ' to ' + req.clientIp, protocol: req.query.p, nodeid: req.query.nodeid };
146
+ parent.parent.DispatchEvent(['*', sessionUser._id], obj, event);
147
+ }
148
+ } else {
149
+ // Connected already, drop this connection.
150
+ if (obj.ws) { obj.ws.close(); }
151
+ parent.parent.debug('relay', 'FileRelay duplicate: ' + obj.id + ' (' + obj.req.clientIp + ')');
152
+ delete obj.id;
153
+ delete obj.ws;
154
+ delete obj.peer;
155
+ return null;
156
+ }
157
+ } else {
158
+ // Wait for other relay connection
159
+ parent.wsrelays[obj.id] = { peer1: obj, state: 1, timeout: setTimeout(closeBothSides, 30000) };
160
+ parent.parent.debug('relay', 'FileRelay holding: ' + obj.id + ' (' + obj.req.clientIp + ') ' + (obj.authenticated ? 'Authenticated' : ''));
161
+
162
+ // Check if a peer server has this connection
163
+ if (parent.parent.multiServer != null) {
164
+ var rsession = parent.wsPeerRelays[obj.id];
165
+ if ((rsession != null) && (rsession.serverId > parent.parent.serverId)) {
166
+ // We must initiate the connection to the peer
167
+ parent.parent.multiServer.createPeerRelay(ws, req, rsession.serverId, obj.req.session.userid);
168
+ delete parent.wsrelays[obj.id];
169
+ } else {
170
+ // Send message to other peers that we have this connection
171
+ parent.parent.multiServer.DispatchMessage(JSON.stringify({ action: 'relay', id: obj.id }));
172
+ }
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ // Websocket handling
179
+ if (obj.ws != null) {
180
+ // When data is received from the mesh relay web socket
181
+ obj.ws.on('message', function (data) {
182
+ if (typeof data == 'string') {
183
+ var cmd = null;
184
+ try { cmd = JSON.parse(data); } catch (ex) { }
185
+ if ((cmd == null) || (typeof cmd.op == 'string')) {
186
+ if (cmd.op == 'ok') {
187
+ if (typeof cmd.size == 'number') {
188
+ this.res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename="' + require('path').basename(this.file) + '"', 'Content-Length': cmd.size });
189
+ } else {
190
+ this.res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'application/octet-stream', 'Content-Disposition': 'attachment; filename="' + require('path').basename(this.file) + '"' });
191
+ }
192
+ } else {
193
+ try { this.res.sendStatus(401); } catch (ex) { }
194
+ }
195
+ }
196
+ } else {
197
+ var unpause = function unpauseFunc(err) { try { unpauseFunc.s.resume(); } catch (ex) { } }
198
+ unpause.s = this._socket;
199
+ this._socket.pause();
200
+ try { this.res.write(data, unpause); } catch (ex) { }
201
+ }
202
+ });
203
+
204
+ // If error, close both sides of the relay.
205
+ obj.ws.on('error', function (err) {
206
+ parent.relaySessionErrorCount++;
207
+ //console.log('FileRelay error from ' + obj.req.clientIp + ', ' + err.toString().split('\r')[0] + '.');
208
+ closeBothSides();
209
+ });
210
+
211
+ // If the relay web socket is closed, close both sides.
212
+ obj.ws.on('close', function (req) { closeBothSides(); });
213
+ }
214
+
215
+ // Close both our side and the peer side.
216
+ function closeBothSides() {
217
+ if (obj.relaySessionCounted) { parent.relaySessionCount--; delete obj.relaySessionCounted; }
218
+
219
+ if (obj.id != null) {
220
+ var relayinfo = parent.wsrelays[obj.id];
221
+ if (relayinfo != null) {
222
+ if (relayinfo.state == 2) {
223
+ var peer = (relayinfo.peer1 == obj) ? relayinfo.peer2 : relayinfo.peer1;
224
+
225
+ // Disconnect the peer
226
+ try { if (peer.relaySessionCounted) { parent.relaySessionCount--; delete peer.relaySessionCounted; } } catch (ex) { console.log(ex); }
227
+ parent.parent.debug('relay', 'FileRelay disconnect: ' + obj.id + ' (' + obj.req.clientIp + ' --> ' + peer.req.clientIp + ')');
228
+ if (peer.ws) { try { peer.ws.close(); } catch (e) { } try { peer.ws._socket._parent.end(); } catch (e) { } }
229
+ if (peer.res) { try { peer.res.end(); } catch (ex) { } }
230
+
231
+ // Aggressive peer cleanup
232
+ delete peer.id;
233
+ delete peer.ws;
234
+ delete peer.res;
235
+ delete peer.peer;
236
+ } else {
237
+ parent.parent.debug('relay', 'FileRelay disconnect: ' + obj.id + ' (' + obj.req.clientIp + ')');
238
+ }
239
+
240
+ if (obj.ws) { try { obj.ws.close(); } catch (ex) { } }
241
+ if (obj.res) { try { obj.res.end(); } catch (ex) { } }
242
+ delete parent.wsrelays[obj.id];
243
+ }
244
+ }
245
+
246
+ // Aggressive cleanup
247
+ delete obj.id;
248
+ delete obj.ws;
249
+ delete obj.res;
250
+ delete obj.peer;
251
+ }
252
+
253
+ // Mark this relay session as authenticated if this is the user end.
254
+ obj.authenticated = (user != null);
255
+ if (obj.authenticated) {
256
+ // Send connection request to agent
257
+ const rcookie = parent.parent.encodeCookie({ ruserid: user._id }, parent.parent.loginCookieEncryptionKey);
258
+ const command = { nodeid: nodeid, action: 'msg', type: 'tunnel', userid: user._id, value: '*/devicefile.ashx?id=' + obj.id + '&rauth=' + rcookie, soptions: {} };
259
+ parent.parent.debug('relay', 'FileRelay: Sending agent tunnel command: ' + JSON.stringify(command));
260
+ if (obj.sendAgentMessage(command, user, domain.id) == false) { delete obj.id; parent.parent.debug('relay', 'FileRelay: Unable to contact this agent (' + obj.req.clientIp + ')'); }
261
+ }
262
+
263
+ // If this is not an authenticated session, or the session does not have routing instructions, just go ahead an connect to existing session.
264
+ performRelay();
265
+ return obj;
266
+};
views/default.handlebars
+6
-1
@@ -7874,7 +7874,12 @@
7874
h = '<div class=filelist file=999><input file=999 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value=\'' + f.nx + '\'> <span style=float:right title="' + title + '">' + right + '</span><span><div class=fileIcon' + f.t + ' onclick=p13folderset("' + encodeURIComponentEx(f.nx) + '")></div><a href=# style=cursor:pointer onclick=\'return p13folderset("' + encodeURIComponentEx(f.nx) + '")\'>' + shortname + '</a></span></div>';
7875
} else {
7876
var link = shortname;
7877
- if (f.s > 0) { link = '<a href=# style=cursor:pointer onclick="return p13downloadfile(\'' + encodeURIComponentEx(newlinkpath + '/' + name) + '\',\'' + encodeURIComponentEx(name) + '\',' + f.s + ')">' + shortname + '</a>'; }
7877
+ if (f.s > 0) {
7878
+ // Local link
7879
+ //link = '<a href=# style=cursor:pointer onclick="return p13downloadfile(\'' + encodeURIComponentEx(newlinkpath + '/' + name) + '\',\'' + encodeURIComponentEx(name) + '\',' + f.s + ')">' + shortname + '</a>';
7880
+ // Server link
7881
+ link = '<a href="devicefile.ashx?c=' + authCookie + '&m=' + currentNode.meshid.split('/')[2] + '&n=' + currentNode._id.split('/')[2] + '&f=' + encodeURIComponentEx(newlinkpath + '/' + name) + '" download style=cursor:pointer">' + shortname + '</a>';
7882
+ }
7883
h = '<div id=fileEntry cmenu=filesContextMenu fileIndex=' + i + ' class=filelist file=3><input file=3 style=float:left name=fd class=fcb type=checkbox onchange=p13setActions() value=\'' + f.nx + '\'> <span class=fsize>' + fdatestr + '</span><span style=float:right>' + EscapeHtml(fsize) + '</span><span><div class=fileIcon' + f.t + '></div>' + link + '</span></div>';
7884
}
7885
webserver.js
+27
@@ -57,6 +57,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
57
obj.express = require('express');
58
obj.meshAgentHandler = require('./meshagent.js');
59
obj.meshRelayHandler = require('./meshrelay.js');
60
+ obj.meshDeviceFileHandler = require('./meshdevicefile.js');
61
obj.meshDesktopMultiplexHandler = require('./meshdesktopmultiplex.js');
62
obj.meshIderHandler = require('./amt/amt-ider.js');
63
obj.meshUserHandler = require('./meshuser.js');
@@ -2786,6 +2787,30 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2787
}
2788
}
2789
2790
+ // Handle device file request
2791
+ function handleDeviceFile(req, res) {
2792
+ const domain = checkUserIpAddress(req, res);
2793
+ if (domain == null) { return; }
2794
+ if ((req.query.c == null) || (req.query.m == null) || (req.query.n == null) || (req.query.f == null)) { res.sendStatus(404); return; }
2795
+
2796
+ // Check the inbound desktop sharing cookie
2797
+ var c = obj.parent.decodeCookie(req.query.c, obj.parent.loginCookieEncryptionKey, 60); // 60 minute timeout
2798
+ if ((c == null) || (c.domainid !== domain.id)) { res.sendStatus(404); return; }
2799
+
2800
+ // Check userid
2801
+ const user = obj.users[c.userid];
2802
+ if ((c == user)) { res.sendStatus(404); return; }
2803
+
2804
+ // Check if this user has permission to manage this computer
2805
+ const meshid = 'mesh/' + domain.id + '/' + req.query.m;
2806
+ const nodeid = 'node/' + domain.id + '/' + req.query.n;
2807
+ if ((obj.GetNodeRights(c.userid, meshid, nodeid) & MESHRIGHT_REMOTECONTROL) == 0) { res.sendStatus(404); return; }
2808
+
2809
+ // All good, start the file transfer
2810
+ req.query.id = getRandomLowerCase(12);
2811
+ obj.meshDeviceFileHandler.CreateMeshDeviceFile(obj, null, res, req, domain, user, meshid, nodeid);
2812
+ }
2813
+
2814
// Handle logo request
2815
function handleLogoRequest(req, res) {
2816
const domain = checkUserIpAddress(req, res);
@@ -4677,6 +4702,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4702
obj.app.ws(url + 'webrelay.ashx', function (ws, req) { PerformWSSessionAuth(ws, req, false, handleRelayWebSocket); });
4703
obj.app.ws(url + 'webider.ashx', function (ws, req) { PerformWSSessionAuth(ws, req, false, function (ws1, req1, domain, user, cookie) { obj.meshIderHandler.CreateAmtIderSession(obj, obj.db, ws1, req1, obj.args, domain, user); }); });
4704
obj.app.ws(url + 'control.ashx', function (ws, req) { PerformWSSessionAuth(ws, req, false, function (ws1, req1, domain, user, cookie) { obj.meshUserHandler.CreateMeshUser(obj, obj.db, ws1, req1, obj.args, domain, user); }); });
4705
+ obj.app.ws(url + 'devicefile.ashx', function (ws, req) { obj.meshDeviceFileHandler.CreateMeshDeviceFile(obj, ws, null, req, domain); });
4706
+ obj.app.get(url + 'devicefile.ashx', handleDeviceFile);
4707
obj.app.get(url + 'logo.png', handleLogoRequest);
4708
obj.app.post(url + 'translations', handleTranslationsRequest);
4709
obj.app.get(url + 'welcome.jpg', handleWelcomeImageRequest);