Added new device details permission.
Ylian Saint-Hilaire committed
Jul 27, 2021 at 14:49 UTC
b96c88f1b48c3749b0a6719daf91133984067ea7
3 files changed
+16
-5
meshuser.js
+6
-2
@@ -51,6 +51,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
51
const MESHRIGHT_REMOTECOMMAND = 0x00020000; // 131072
52
const MESHRIGHT_RESETOFF = 0x00040000; // 262144
53
const MESHRIGHT_GUESTSHARING = 0x00080000; // 524288
54
+ const MESHRIGHT_DEVICEDETAILS = 0x00100000; // 1048576
55
const MESHRIGHT_ADMIN = 0xFFFFFFFF;
56
57
// Site rights
@@ -5265,6 +5266,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5266
if ((common.validateStrArray(command.nodeids, 1) == false) && (command.nodeids != null)) break; // Check nodeids
5267
if (common.validateString(command.type, 3, 4) == false) break; // Check type
5268
getDeviceDetailedInfo(command.nodeids, command.type, function (results, type) {
5269
+ // Remove any device system and network information is we do not have details rights to this device
5270
+ 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; } }
5271
+
5272
var output = null;
5273
if (type == 'csv') {
5274
try {
@@ -5488,7 +5492,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5492
5493
// Get the node and the rights for this node
5494
parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
5491
- 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; }
5495
+ 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; }
5496
5497
// Get network information about this node
5498
db.Get('if' + node._id, function (err, netinfos) {
@@ -5513,7 +5517,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5517
5518
// Get the node and the rights for this node
5519
parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
5516
- 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; }
5520
+ 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; }
5521
// Query the database system information
5522
db.Get('si' + command.nodeid, function (err, docs) {
5523
if ((docs != null) && (docs.length > 0)) {
views/default-mobile.handlebars
+1
-1
@@ -3548,7 +3548,7 @@
3548
) { menus.push({ n: "Terminal", f: 'setupDeviceMenu(5)' }); }
3549
3550
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)' }); }
3551
- if ((currentDevicePanel != 3) && (currentNode != null) && (currentNode.mtype != 3)) { menus.push({ n: "Details", f: 'setupDeviceMenu(3)' }); }
3551
+ if ((currentDevicePanel != 3) && (currentNode != null) && (currentNode.mtype != 3) && ((meshrights & 1048576) != 0)) { menus.push({ n: "Details", f: 'setupDeviceMenu(3)' }); }
3552
if ((currentDevicePanel != 4) && (currentNode != null) && (meshrights & 0x00000010) && (currentNode.mtype == 2)) { menus.push({ n: "Console", f: 'setupDeviceMenu(4)' }); }
3553
updateFooterMenu(menus);
3554
updateCurrentUrl();
views/default.handlebars
+9
-2
@@ -6602,7 +6602,7 @@
6602
x += ' <a href=# onclick=p10showDeleteNodeDialog("' + node._id + '") title="' + "Remove this device" + '">' + "Delete Device" + '</a>';
6603
}
6604
x += '</div><div class="p10html3left">';
6605
- if ((node.agent) && (node.mtype != 3)) x += '<a href=# onclick=p10showNodeNetInfoDialog("' + node._id + '") title="' + "Show device network interface information" + '">' + "Interfaces" + '</a> ';
6605
+ if ((node.agent) && (node.mtype != 3) && ((meshrights & 1048576) != 0)) x += '<a href=# onclick=p10showNodeNetInfoDialog("' + node._id + '") title="' + "Show device network interface information" + '">' + "Interfaces" + '</a> ';
6606
if ((features & 0x00008000) && (xxmap != null)) x += '<a href=# onclick=p10showNodeLocationDialog("' + node._id + '") title="' + "Show device locations information" + '">' + "Location" + '</a> ';
6607
if ((node.agent == null) || ((node.agent.id != 14) && (node.agent.id != 34))) {
6608
if ((userinfo.siteadmin == 0xFFFFFFFF) || ((userinfo.siteadmin & 128) == 0)) { // Check if we should view tools
@@ -6710,7 +6710,7 @@
6710
);
6711
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);
6712
QV('MainDevFiles', (node.agent != null) && (node.agent.caps != null) && ((node.agent.caps & 4) != 0) && (meshrights & 8) && fileAccess);
6713
- QV('MainDevInfo', (node.mtype != 3));
6713
+ QV('MainDevInfo', (node.mtype != 3) & (meshrights & 1048576));
6714
QV('MainDevAmt', (node.intelamt != null) && ((node.intelamt.state == 2) || (node.conn & 2)) && (meshrights & 8) && amtAccess);
6715
QV('MainDevConsole', (consoleRights && ((node.agent != null) && (node.agent.caps != null) && ((node.agent.caps & 8) != 0))) && (meshrights & 8));
6716
QV('MainDevPlugins', false);
@@ -11546,6 +11546,7 @@
11546
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20uninstall>' + "Uninstall Agent / Delete Device" + '</label><br>';
11547
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20commands>' + "Remote Commands" + '</label><br>';
11548
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20resetoff>' + "Reset / Power Off" + '</label><br>';
11549
+ x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20details>' + "Device Details" + '</label><br>';
11550
x += '</div>';
11551
11552
if (userid == null) {
@@ -11622,6 +11623,7 @@
11623
if (urights & 131072) { Q('p20commands').checked = true; }
11624
if (urights & 262144) { Q('p20resetoff').checked = true; }
11625
if ((urights & 524288) && (serverinfo.guestdevicesharing !== false)) { Q('p20guestshare').checked = true; }
11626
+ if (urights & 1048576) { Q('p20details').checked = true; }
11627
}
11628
11629
p20validateAddMeshUserDialog(userid);
@@ -11669,6 +11671,7 @@
11671
Q('p20commands').checked = ((devrights & 131072) != 0);
11672
Q('p20resetoff').checked = ((devrights & 262144) != 0);
11673
if (serverinfo.guestdevicesharing !== false) { Q('p20guestshare').checked = ((devrights & 524288) != 0); }
11674
+ Q('p20details').checked = ((devrights & 1048576) != 0);
11675
ok = (nodeid != '');
11676
}
11677
@@ -11749,6 +11752,7 @@
11752
QE('p20uninstall', nc);
11753
QE('p20commands', nc);
11754
QE('p20resetoff', nc);
11755
+ QE('p20details', nc);
11756
}
11757
11758
function p20showAddMeshUserDialogEx(b, t) {
@@ -11777,6 +11781,7 @@
11781
if (Q('p20commands').checked == true) meshadmin += 131072;
11782
if (Q('p20resetoff').checked == true) meshadmin += 262144;
11783
if ((serverinfo.guestdevicesharing !== false) && (Q('p20guestshare').checked == true) && (Q('p20remoteview').checked || (!Q('p20remoteview').checked && !Q('p20remotelimitedinput').checked))) meshadmin += 524288;
11784
+ if (Q('p20details').checked == true) meshadmin += 1048576;
11785
}
11786
11787
// Clean up incorrect rights. If Remote Control is not selected, remove flags that don't make sense.
@@ -11860,6 +11865,8 @@
11865
if ((meshrights & 32768) != 0) r.push("Uninstall");
11866
if ((meshrights & 131072) != 0) r.push("Commands");
11867
if ((meshrights & 262144) != 0) r.push("Reset/Off");
11868
+ if ((meshrights & 524288) != 0) r.push("Sharing");
11869
+ if ((meshrights & 1048576) != 0) r.push("Details");
11870
}
11871
if (r.length == 0) { r.push("No Rights"); }
11872
var uname = xuserid.split('/')[2];