From b96c88f1b48c3749b0a6719daf91133984067ea7 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 27 Jul 2021 14:49:43 -0700 Subject: [PATCH] Added new device details permission. --- meshuser.js | 8 ++++++-- views/default-mobile.handlebars | 2 +- views/default.handlebars | 11 +++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/meshuser.js b/meshuser.js index fa697afb..bd7e2eba 100644 --- a/meshuser.js +++ b/meshuser.js @@ -51,6 +51,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use const MESHRIGHT_REMOTECOMMAND = 0x00020000; // 131072 const MESHRIGHT_RESETOFF = 0x00040000; // 262144 const MESHRIGHT_GUESTSHARING = 0x00080000; // 524288 + const MESHRIGHT_DEVICEDETAILS = 0x00100000; // ‭1048576‬ const MESHRIGHT_ADMIN = 0xFFFFFFFF; // Site rights @@ -5265,6 +5266,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use if ((common.validateStrArray(command.nodeids, 1) == false) && (command.nodeids != null)) break; // Check nodeids if (common.validateString(command.type, 3, 4) == false) break; // Check type getDeviceDetailedInfo(command.nodeids, command.type, function (results, type) { + // Remove any device system and network information is we do not have details rights to this device + for (var i = 0; i < results.length; i++) { if ((parent.GetNodeRights(user, results[i].node.meshid, results[i].node._id) & MESHRIGHT_DEVICEDETAILS) == 0) { delete results[i].sys; delete results[i].net; } } + var output = null; if (type == 'csv') { try { @@ -5488,7 +5492,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Get the node and the rights for this node parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) { - if (visible == false) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { } return; } + if ((visible == false) || ((rights & MESHRIGHT_DEVICEDETAILS) == 0)) { try { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { } return; } // Get network information about this node db.Get('if' + node._id, function (err, netinfos) { @@ -5513,7 +5517,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Get the node and the rights for this node parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) { - if (visible == false) { try { ws.send(JSON.stringify({ action: 'getsysinfo', nodeid: command.nodeid, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { } return; } + if ((visible == false) || ((rights & MESHRIGHT_DEVICEDETAILS) == 0)) { try { ws.send(JSON.stringify({ action: 'getsysinfo', nodeid: command.nodeid, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { } return; } // Query the database system information db.Get('si' + command.nodeid, function (err, docs) { if ((docs != null) && (docs.length > 0)) { diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index f2970a6b..c34cd1e3 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -3548,7 +3548,7 @@ ) { menus.push({ n: "Terminal", f: 'setupDeviceMenu(5)' }); } if ((currentDevicePanel != 2) && (currentNode != null) && (meshrights & 8) && ((meshrights == 0xFFFFFFFF) || ((meshrights & 1024) == 0)) && ((currentNode.mtype != 1) && (currentNode.agent.caps & 4))) { menus.push({ n: "Files", f: 'setupDeviceMenu(2)' }); } - if ((currentDevicePanel != 3) && (currentNode != null) && (currentNode.mtype != 3)) { menus.push({ n: "Details", f: 'setupDeviceMenu(3)' }); } + if ((currentDevicePanel != 3) && (currentNode != null) && (currentNode.mtype != 3) && ((meshrights & 1048576) != 0)) { menus.push({ n: "Details", f: 'setupDeviceMenu(3)' }); } if ((currentDevicePanel != 4) && (currentNode != null) && (meshrights & 0x00000010) && (currentNode.mtype == 2)) { menus.push({ n: "Console", f: 'setupDeviceMenu(4)' }); } updateFooterMenu(menus); updateCurrentUrl(); diff --git a/views/default.handlebars b/views/default.handlebars index 3bdaf880..76747148 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -6602,7 +6602,7 @@ x += ' ' + "Delete Device" + ''; } x += '
'; - if ((node.agent) && (node.mtype != 3)) x += '' + "Interfaces" + ' '; + if ((node.agent) && (node.mtype != 3) && ((meshrights & 1048576) != 0)) x += '' + "Interfaces" + ' '; if ((features & 0x00008000) && (xxmap != null)) x += '' + "Location" + ' '; if ((node.agent == null) || ((node.agent.id != 14) && (node.agent.id != 34))) { if ((userinfo.siteadmin == 0xFFFFFFFF) || ((userinfo.siteadmin & 128) == 0)) { // Check if we should view tools @@ -6710,7 +6710,7 @@ ); QV('MainDevTerminal', (((node.agent == null) && (node.intelamt != null)) || (node.agent.caps == null) || ((node.agent.caps & 2) != 0) || (node.intelamt && (node.intelamt.state == 2))) && (meshrights & 8) && terminalAccess); QV('MainDevFiles', (node.agent != null) && (node.agent.caps != null) && ((node.agent.caps & 4) != 0) && (meshrights & 8) && fileAccess); - QV('MainDevInfo', (node.mtype != 3)); + QV('MainDevInfo', (node.mtype != 3) & (meshrights & 1048576)); QV('MainDevAmt', (node.intelamt != null) && ((node.intelamt.state == 2) || (node.conn & 2)) && (meshrights & 8) && amtAccess); QV('MainDevConsole', (consoleRights && ((node.agent != null) && (node.agent.caps != null) && ((node.agent.caps & 8) != 0))) && (meshrights & 8)); QV('MainDevPlugins', false); @@ -11546,6 +11546,7 @@ x += '
'; x += '
'; x += '
'; + x += '
'; x += '
'; if (userid == null) { @@ -11622,6 +11623,7 @@ if (urights & 131072) { Q('p20commands').checked = true; } if (urights & 262144) { Q('p20resetoff').checked = true; } if ((urights & 524288) && (serverinfo.guestdevicesharing !== false)) { Q('p20guestshare').checked = true; } + if (urights & 1048576) { Q('p20details').checked = true; } } p20validateAddMeshUserDialog(userid); @@ -11669,6 +11671,7 @@ Q('p20commands').checked = ((devrights & 131072) != 0); Q('p20resetoff').checked = ((devrights & 262144) != 0); if (serverinfo.guestdevicesharing !== false) { Q('p20guestshare').checked = ((devrights & 524288) != 0); } + Q('p20details').checked = ((devrights & 1048576) != 0); ok = (nodeid != ''); } @@ -11749,6 +11752,7 @@ QE('p20uninstall', nc); QE('p20commands', nc); QE('p20resetoff', nc); + QE('p20details', nc); } function p20showAddMeshUserDialogEx(b, t) { @@ -11777,6 +11781,7 @@ if (Q('p20commands').checked == true) meshadmin += 131072; if (Q('p20resetoff').checked == true) meshadmin += 262144; if ((serverinfo.guestdevicesharing !== false) && (Q('p20guestshare').checked == true) && (Q('p20remoteview').checked || (!Q('p20remoteview').checked && !Q('p20remotelimitedinput').checked))) meshadmin += 524288; + if (Q('p20details').checked == true) meshadmin += 1048576; } // Clean up incorrect rights. If Remote Control is not selected, remove flags that don't make sense. @@ -11860,6 +11865,8 @@ if ((meshrights & 32768) != 0) r.push("Uninstall"); if ((meshrights & 131072) != 0) r.push("Commands"); if ((meshrights & 262144) != 0) r.push("Reset/Off"); + if ((meshrights & 524288) != 0) r.push("Sharing"); + if ((meshrights & 1048576) != 0) r.push("Details"); } if (r.length == 0) { r.push("No Rights"); } var uname = xuserid.split('/')[2];