Added handler function for getsysinfo
Noah Zalev committed
Jul 13, 2021 at 18:13 UTC
f0d2581b2df68bc5daa44f26e33edbffdea8ed75
1 file changed
+26
-28
meshuser.js
+26
-28
@@ -788,34 +788,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
788
});
789
break;
790
}
791
- case 'getsysinfo':
792
- {
793
- if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check the nodeid
794
- if (command.nodeid.indexOf('/') == -1) { command.nodeid = 'node/' + domain.id + '/' + command.nodeid; }
795
- if ((command.nodeid.split('/').length != 3) || (command.nodeid.split('/')[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
796
-
797
- // Get the node and the rights for this node
798
- parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
799
- 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; }
800
- // Query the database system information
801
- db.Get('si' + command.nodeid, function (err, docs) {
802
- if ((docs != null) && (docs.length > 0)) {
803
- var doc = docs[0];
804
- doc.action = 'getsysinfo';
805
- doc.nodeid = node._id;
806
- doc.tag = command.tag;
807
- delete doc.type;
808
- delete doc.domain;
809
- delete doc._id;
810
- if (command.nodeinfo === true) { doc.node = node; doc.rights = rights; }
811
- try { ws.send(JSON.stringify(doc)); } catch (ex) { }
812
- } else {
813
- try { ws.send(JSON.stringify({ action: 'getsysinfo', nodeid: node._id, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { }
814
- }
815
- });
816
- });
817
- break;
818
- }
791
case 'files':
792
{
793
// Send the full list of server files to the browser app
@@ -5475,6 +5447,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5447
5448
const serverCommands = {
5449
'getnetworkinfo': serverCommandGetNetworkInfo,
5450
+ 'getsysinfo': serverCommandGetSysInfo,
5451
'lastconnect': serverCommandLastConnect,
5452
'serverconsole': serverCommandServerConsole
5453
};
@@ -5556,6 +5529,31 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5529
});
5530
}
5531
5532
+ function serverCommandGetSysInfo(command) {
5533
+ if (!validNodeIdAndDomain(command)) return;
5534
+
5535
+ // Get the node and the rights for this node
5536
+ parent.GetNodeWithRights(domain, user, command.nodeid, function (node, rights, visible) {
5537
+ 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; }
5538
+ // Query the database system information
5539
+ db.Get('si' + command.nodeid, function (err, docs) {
5540
+ if ((docs != null) && (docs.length > 0)) {
5541
+ var doc = docs[0];
5542
+ doc.action = 'getsysinfo';
5543
+ doc.nodeid = node._id;
5544
+ doc.tag = command.tag;
5545
+ delete doc.type;
5546
+ delete doc.domain;
5547
+ delete doc._id;
5548
+ if (command.nodeinfo === true) { doc.node = node; doc.rights = rights; }
5549
+ try { ws.send(JSON.stringify(doc)); } catch (ex) { }
5550
+ } else {
5551
+ try { ws.send(JSON.stringify({ action: 'getsysinfo', nodeid: node._id, tag: command.tag, noinfo: true, result: 'Invalid device id' })); } catch (ex) { }
5552
+ }
5553
+ });
5554
+ });
5555
+ }
5556
+
5557
function serverCommandLastConnect(command) {
5558
if (!validNodeIdAndDomain(command)) return;
5559