Added support for meshctrl --details, #2933
Ylian Saint-Hilaire committed
Jul 24, 2021 at 11:28 UTC
821464ae08b538917b4ec76eb5f78444e37fedd1
2 files changed
+75
-2
meshctrl.js
+9
-1
@@ -380,6 +380,7 @@ if (args['_'].length == 0) {
380
console.log(" --json - Show result as JSON.");
381
console.log(" --csv - Show result as comma seperated values.");
382
console.log(" --filterid [id,id...] - Show only results for devices with included id.");
383
+ console.log(" --details - Show all device details.");
384
break;
385
}
386
case 'listusersofdevicegroup': {
@@ -1110,7 +1111,10 @@ function serverConnect() {
1111
case 'listdevicegroups': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
1112
case 'listusersofdevicegroup': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
1113
case 'listdevices': {
1113
- if (args.group) {
1114
+ if (args.details) {
1115
+ // Get list of devices with lots of details
1116
+ ws.send(JSON.stringify({ action: 'getDeviceDetails', type: (args.csv)?'csv':'json' }));
1117
+ } else if (args.group) {
1118
ws.send(JSON.stringify({ action: 'nodes', meshname: args.group, responseid: 'meshctrl' }));
1119
} else if (args.id) {
1120
ws.send(JSON.stringify({ action: 'nodes', meshid: args.id, responseid: 'meshctrl' }));
@@ -2038,6 +2042,10 @@ function serverConnect() {
2042
process.exit();
2043
break;
2044
}
2045
+ case 'getDeviceDetails': {
2046
+ console.log(data.data);
2047
+ process.exit();
2048
+ }
2049
default: { break; }
2050
}
2051
//console.log('Data', data);
meshuser.js
+66
-1
@@ -5272,7 +5272,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5272
break;
5273
}
5274
case 'getDeviceDetails': {
5275
- if (common.validateStrArray(command.nodeids, 1) == false) break; // Check nodeids
5275
+ if ((common.validateStrArray(command.nodeids, 1) == false) && (command.nodeids != null)) break; // Check nodeids
5276
if (common.validateString(command.type, 3, 4) == false) break; // Check type
5277
getDeviceDetailedInfo(command.nodeids, command.type, function (results, type) {
5278
var output = null;
@@ -6185,6 +6185,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6185
6186
// Return detailed information about an array of nodeid's
6187
function getDeviceDetailedInfo(nodeids, type, func) {
6188
+ if (nodeids == null) { getAllDeviceDetailedInfo(type, func); return; }
6189
var results = [], resultPendingCount = 0;
6190
for (var i in nodeids) {
6191
// Fetch the node from the database
@@ -6222,6 +6223,70 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6223
}
6224
}
6225
6226
+ // Return detailed information about all nodes this user has access to
6227
+ function getAllDeviceDetailedInfo(type, func) {
6228
+ // Get all device groups this user has access to
6229
+ var links = parent.GetAllMeshIdWithRights(user);
6230
+
6231
+ // Add any nodes with direct rights or any nodes with user group direct rights
6232
+ var extraids = null;
6233
+ if (obj.user.links != null) {
6234
+ for (var i in obj.user.links) {
6235
+ if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); }
6236
+ else if (i.startsWith('ugrp/')) {
6237
+ const g = parent.userGroups[i];
6238
+ if ((g != null) && (g.links != null)) {
6239
+ for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } }
6240
+ }
6241
+ }
6242
+ }
6243
+ }
6244
+
6245
+ // Request a list of all nodes
6246
+ db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, function (err, docs) {
6247
+ if (docs == null) { docs = []; }
6248
+ parent.common.unEscapeAllLinksFieldName(docs);
6249
+
6250
+ var results = [], resultPendingCount = 0;
6251
+ for (i in docs) {
6252
+ // Check device links, if a link points to an unknown user, remove it.
6253
+ parent.cleanDevice(docs[i]);
6254
+
6255
+ // Fetch the node from the database
6256
+ resultPendingCount++;
6257
+ const getNodeFunc = function (node, rights, visible) {
6258
+ if ((node != null) && (visible == true)) {
6259
+ const getNodeSysInfoFunc = function (err, docs) {
6260
+ const getNodeNetInfoFunc = function (err, docs) {
6261
+ var netinfo = null;
6262
+ if ((err == null) && (docs != null) && (docs.length == 1)) { netinfo = docs[0]; }
6263
+ resultPendingCount--;
6264
+ getNodeNetInfoFunc.results.push({ node: parent.CloneSafeNode(getNodeNetInfoFunc.node), sys: getNodeNetInfoFunc.sysinfo, net: netinfo });
6265
+ if (resultPendingCount == 0) { func(getNodeFunc.results, type); }
6266
+ }
6267
+ getNodeNetInfoFunc.results = getNodeSysInfoFunc.results;
6268
+ getNodeNetInfoFunc.nodeid = getNodeSysInfoFunc.nodeid;
6269
+ getNodeNetInfoFunc.node = getNodeSysInfoFunc.node;
6270
+ if ((err == null) && (docs != null) && (docs.length == 1)) { getNodeNetInfoFunc.sysinfo = docs[0]; }
6271
+
6272
+ // Query the database for network information
6273
+ db.Get('if' + getNodeSysInfoFunc.nodeid, getNodeNetInfoFunc);
6274
+ }
6275
+ getNodeSysInfoFunc.results = getNodeFunc.results;
6276
+ getNodeSysInfoFunc.nodeid = getNodeFunc.nodeid;
6277
+ getNodeSysInfoFunc.node = node;
6278
+
6279
+ // Query the database for system information
6280
+ db.Get('si' + getNodeFunc.nodeid, getNodeSysInfoFunc);
6281
+ } else { resultPendingCount--; }
6282
+ if (resultPendingCount == 0) { func(getNodeFunc.results.join('\r\n'), type); }
6283
+ }
6284
+ getNodeFunc.results = results;
6285
+ getNodeFunc.nodeid = docs[i]._id;
6286
+ parent.GetNodeWithRights(domain, user, docs[i]._id, getNodeFunc);
6287
+ }
6288
+ });
6289
+ }
6290
6291
// Display a notification message for this session only.
6292
function displayNotificationMessage(msg, title, tag, titleid, msgid, args) {