From 99067091de90ce360d1e9a78af0538adbbfd268a Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 26 Aug 2020 18:55:32 -0700 Subject: [PATCH] Device download improvements. --- meshdevicefile.js | 23 +++++++++++++++++++++-- meshrelay.js | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/meshdevicefile.js b/meshdevicefile.js index 5ea25b1d..75dc1f6a 100644 --- a/meshdevicefile.js +++ b/meshdevicefile.js @@ -33,6 +33,25 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us obj.relaySessionCounted = true; parent.relaySessionCount++; + // Mesh Rights + const MESHRIGHT_EDITMESH = 1; + const MESHRIGHT_MANAGEUSERS = 2; + const MESHRIGHT_MANAGECOMPUTERS = 4; + const MESHRIGHT_REMOTECONTROL = 8; + const MESHRIGHT_AGENTCONSOLE = 16; + const MESHRIGHT_SERVERFILES = 32; + const MESHRIGHT_WAKEDEVICE = 64; + const MESHRIGHT_SETNOTES = 128; + const MESHRIGHT_REMOTEVIEW = 256; + + // Site rights + const SITERIGHT_SERVERBACKUP = 1; + const SITERIGHT_MANAGEUSERS = 2; + const SITERIGHT_SERVERRESTORE = 4; + const SITERIGHT_FILEACCESS = 8; + const SITERIGHT_SERVERUPDATE = 16; + const SITERIGHT_LOCKED = 32; + // Clean a IPv6 address that encodes a IPv4 address function cleanRemoteAddr(addr) { if (addr.startsWith('::ffff:')) { return addr.substring(7); } else { return addr; } } @@ -67,7 +86,7 @@ module.exports.CreateMeshDeviceFile = function (parent, ws, res, req, domain, us // Check if we have permission to send a message to that node rights = parent.GetNodeRights(user, agent.dbMeshKey, agent.dbNodeKey); mesh = parent.meshes[agent.dbMeshKey]; - if ((rights != null) && (mesh != null) || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking + if ((rights != null) && (mesh != null) || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control command.rights = rights; // Add user rights flags to the message if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent 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 // Check if we have permission to send a message to that node rights = parent.GetNodeRights(user, routing.meshid, command.nodeid); mesh = parent.meshes[routing.meshid]; - if (rights != null || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking + if (rights != null || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { // 8 is device remote control command.rights = rights; // Add user rights flags to the message if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags diff --git a/meshrelay.js b/meshrelay.js index 786572c0..79b9109b 100644 --- a/meshrelay.js +++ b/meshrelay.js @@ -95,7 +95,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie // Check if we have permission to send a message to that node rights = parent.GetNodeRights(user, agent.dbMeshKey, agent.dbNodeKey); mesh = parent.meshes[agent.dbMeshKey]; - if ((rights != null) && (mesh != null) || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking + if ((rights != null) && (mesh != null) || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { if (ws.sessionId) { command.sessionid = ws.sessionId; } // Set the session id, required for responses. command.rights = rights; // Add user rights flags to the message 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 // Check if we have permission to send a message to that node rights = parent.GetNodeRights(user, routing.meshid, command.nodeid); mesh = parent.meshes[routing.meshid]; - if (rights != null || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking + if (rights != null || ((rights & MESHRIGHT_REMOTECONTROL) != 0)) { if (ws.sessionId) { command.fromSessionid = ws.sessionId; } // Set the session id, required for responses. command.rights = rights; // Add user rights flags to the message if (typeof command.consent == 'number') { command.consent = command.consent | mesh.consent; } else { command.consent = mesh.consent; } // Add user consent