Device download improvements.
Ylian Saint-Hilaire committed
Aug 26, 2020 at 18:55 UTC
c33d18207bcc488a13a869ff803c43c76298581a
2 files changed
+23
-4
meshdevicefile.js
+21
-2
@@ -33,6 +33,25 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us
33
obj.relaySessionCounted = true;
34
parent.relaySessionCount++;
35
36
+ // Mesh Rights
37
+ const MESHRIGHT_EDITMESH = 1;
38
+ const MESHRIGHT_MANAGEUSERS = 2;
39
+ const MESHRIGHT_MANAGECOMPUTERS = 4;
40
+ const MESHRIGHT_REMOTECONTROL = 8;
41
+ const MESHRIGHT_AGENTCONSOLE = 16;
42
+ const MESHRIGHT_SERVERFILES = 32;
43
+ const MESHRIGHT_WAKEDEVICE = 64;
44
+ const MESHRIGHT_SETNOTES = 128;
45
+ const MESHRIGHT_REMOTEVIEW = 256;
46
+
47
+ // Site rights
48
+ const SITERIGHT_SERVERBACKUP = 1;
49
+ const SITERIGHT_MANAGEUSERS = 2;
50
+ const SITERIGHT_SERVERRESTORE = 4;
51
+ const SITERIGHT_FILEACCESS = 8;
52
+ const SITERIGHT_SERVERUPDATE = 16;
53
+ const SITERIGHT_LOCKED = 32;
54
+
55
// Clean a IPv6 address that encodes a IPv4 address
56
function cleanRemoteAddr(addr) { if (addr.startsWith('::ffff:')) { return addr.substring(7); } else { return addr; } }
57
@@ -67,7 +86,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us
86
// Check if we have permission to send a message to that node
87
rights = parent.GetNodeRights(user, agent.dbMeshKey, agent.dbNodeKey);
88
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
89
+ if ((rights != null) && (mesh != null) || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control
90
command.rights = rights; // Add user rights flags to the message
91
if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent
92
if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
@@ -85,7 +104,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us
104
// Check if we have permission to send a message to that node
105
rights = parent.GetNodeRights(user, routing.meshid, command.nodeid);
106
mesh = parent.meshes[routing.meshid];
88
- if (rights != null || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
107
+ if (rights != null || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control
108
command.rights = rights; // Add user rights flags to the message
109
if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent
110
if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
meshrelay.js
+2
-2
@@ -95,7 +95,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
95
// Check if we have permission to send a message to that node
96
rights = parent.GetNodeRights(user, agent.dbMeshKey, agent.dbNodeKey);
97
mesh = parent.meshes[agent.dbMeshKey];
98
- if ((rights != null) && (mesh != null) || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
98
+ if ((rights != null) && (mesh != null) || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) {
99
if (ws.sessionId) { command.sessionid = ws.sessionId; } // Set the session id, required for responses.
100
command.rights = rights; // Add user rights flags to the message
101
if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent
@@ -114,7 +114,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
114
// Check if we have permission to send a message to that node
115
rights = parent.GetNodeRights(user, routing.meshid, command.nodeid);
116
mesh = parent.meshes[routing.meshid];
117
- if (rights != null || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
117
+ if (rights != null || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) {
118
if (ws.sessionId) { command.fromSessionid = ws.sessionId; } // Set the session id, required for responses.
119
command.rights = rights; // Add user rights flags to the message
120
if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent