mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-01-24 13:13:13 -05:00
Added support for meshctrl --details, #2933
This commit is contained in:
parent
e9e24e13dc
commit
821464ae08
10
meshctrl.js
10
meshctrl.js
@ -380,6 +380,7 @@ if (args['_'].length == 0) {
|
||||
console.log(" --json - Show result as JSON.");
|
||||
console.log(" --csv - Show result as comma seperated values.");
|
||||
console.log(" --filterid [id,id...] - Show only results for devices with included id.");
|
||||
console.log(" --details - Show all device details.");
|
||||
break;
|
||||
}
|
||||
case 'listusersofdevicegroup': {
|
||||
@ -1110,7 +1111,10 @@ function serverConnect() {
|
||||
case 'listdevicegroups': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
|
||||
case 'listusersofdevicegroup': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
|
||||
case 'listdevices': {
|
||||
if (args.group) {
|
||||
if (args.details) {
|
||||
// Get list of devices with lots of details
|
||||
ws.send(JSON.stringify({ action: 'getDeviceDetails', type: (args.csv)?'csv':'json' }));
|
||||
} else if (args.group) {
|
||||
ws.send(JSON.stringify({ action: 'nodes', meshname: args.group, responseid: 'meshctrl' }));
|
||||
} else if (args.id) {
|
||||
ws.send(JSON.stringify({ action: 'nodes', meshid: args.id, responseid: 'meshctrl' }));
|
||||
@ -2038,6 +2042,10 @@ function serverConnect() {
|
||||
process.exit();
|
||||
break;
|
||||
}
|
||||
case 'getDeviceDetails': {
|
||||
console.log(data.data);
|
||||
process.exit();
|
||||
}
|
||||
default: { break; }
|
||||
}
|
||||
//console.log('Data', data);
|
||||
|
67
meshuser.js
67
meshuser.js
@ -5272,7 +5272,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
break;
|
||||
}
|
||||
case 'getDeviceDetails': {
|
||||
if (common.validateStrArray(command.nodeids, 1) == false) break; // Check nodeids
|
||||
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) {
|
||||
var output = null;
|
||||
@ -6185,6 +6185,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
|
||||
// Return detailed information about an array of nodeid's
|
||||
function getDeviceDetailedInfo(nodeids, type, func) {
|
||||
if (nodeids == null) { getAllDeviceDetailedInfo(type, func); return; }
|
||||
var results = [], resultPendingCount = 0;
|
||||
for (var i in nodeids) {
|
||||
// Fetch the node from the database
|
||||
@ -6222,6 +6223,70 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
}
|
||||
}
|
||||
|
||||
// Return detailed information about all nodes this user has access to
|
||||
function getAllDeviceDetailedInfo(type, func) {
|
||||
// Get all device groups this user has access to
|
||||
var links = parent.GetAllMeshIdWithRights(user);
|
||||
|
||||
// Add any nodes with direct rights or any nodes with user group direct rights
|
||||
var extraids = null;
|
||||
if (obj.user.links != null) {
|
||||
for (var i in obj.user.links) {
|
||||
if (i.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(i); }
|
||||
else if (i.startsWith('ugrp/')) {
|
||||
const g = parent.userGroups[i];
|
||||
if ((g != null) && (g.links != null)) {
|
||||
for (var j in g.links) { if (j.startsWith('node/')) { if (extraids == null) { extraids = []; } extraids.push(j); } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Request a list of all nodes
|
||||
db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, function (err, docs) {
|
||||
if (docs == null) { docs = []; }
|
||||
parent.common.unEscapeAllLinksFieldName(docs);
|
||||
|
||||
var results = [], resultPendingCount = 0;
|
||||
for (i in docs) {
|
||||
// Check device links, if a link points to an unknown user, remove it.
|
||||
parent.cleanDevice(docs[i]);
|
||||
|
||||
// Fetch the node from the database
|
||||
resultPendingCount++;
|
||||
const getNodeFunc = function (node, rights, visible) {
|
||||
if ((node != null) && (visible == true)) {
|
||||
const getNodeSysInfoFunc = function (err, docs) {
|
||||
const getNodeNetInfoFunc = function (err, docs) {
|
||||
var netinfo = null;
|
||||
if ((err == null) && (docs != null) && (docs.length == 1)) { netinfo = docs[0]; }
|
||||
resultPendingCount--;
|
||||
getNodeNetInfoFunc.results.push({ node: parent.CloneSafeNode(getNodeNetInfoFunc.node), sys: getNodeNetInfoFunc.sysinfo, net: netinfo });
|
||||
if (resultPendingCount == 0) { func(getNodeFunc.results, type); }
|
||||
}
|
||||
getNodeNetInfoFunc.results = getNodeSysInfoFunc.results;
|
||||
getNodeNetInfoFunc.nodeid = getNodeSysInfoFunc.nodeid;
|
||||
getNodeNetInfoFunc.node = getNodeSysInfoFunc.node;
|
||||
if ((err == null) && (docs != null) && (docs.length == 1)) { getNodeNetInfoFunc.sysinfo = docs[0]; }
|
||||
|
||||
// Query the database for network information
|
||||
db.Get('if' + getNodeSysInfoFunc.nodeid, getNodeNetInfoFunc);
|
||||
}
|
||||
getNodeSysInfoFunc.results = getNodeFunc.results;
|
||||
getNodeSysInfoFunc.nodeid = getNodeFunc.nodeid;
|
||||
getNodeSysInfoFunc.node = node;
|
||||
|
||||
// Query the database for system information
|
||||
db.Get('si' + getNodeFunc.nodeid, getNodeSysInfoFunc);
|
||||
} else { resultPendingCount--; }
|
||||
if (resultPendingCount == 0) { func(getNodeFunc.results.join('\r\n'), type); }
|
||||
}
|
||||
getNodeFunc.results = results;
|
||||
getNodeFunc.nodeid = docs[i]._id;
|
||||
parent.GetNodeWithRights(domain, user, docs[i]._id, getNodeFunc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Display a notification message for this session only.
|
||||
function displayNotificationMessage(msg, title, tag, titleid, msgid, args) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user