mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-03 18:05:58 -05:00
Added detailed device export
This commit is contained in:
parent
fac154ac76
commit
4aebddd1e1
163
meshuser.js
163
meshuser.js
@ -5550,8 +5550,127 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
parent.parent.DispatchEvent('*', obj, { action: 'oneclickrecovery', userid: user._id, username: user.name, nodeids: [node._id], domain: domain.id, nolog: 1, file: file.fullpath });
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'getDeviceDetails': {
|
||||
if (common.validateStrArray(command.nodeids, 1) == false) 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;
|
||||
if (type == 'csv') {
|
||||
try {
|
||||
// Create the CSV file
|
||||
output = 'id,name,rname,host,icon,ip,osdesc,groupname,cpu,osbuild,biosDate,biosVendor,biosVersion,boardName,boardVendor,boardVersion,productUuid,agentOpenSSL,agentCommitDate,agentCommitHash,agentCompileTime,netIfCount,macs,addresses\r\n';
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
const nodeinfo = results[i];
|
||||
|
||||
//console.log(command, file);
|
||||
// Node information
|
||||
if (nodeinfo.node != null) {
|
||||
const n = nodeinfo.node;
|
||||
output += csvClean(n._id) + ',' + csvClean(n.name) + ',' + csvClean(n.rname ? n.rname : '') + ',' + csvClean(n.host ? n.host : '') + ',' + n.icon + ',' + (n.ip ? n.ip : '') + ',' + (n.osdesc ? csvClean(n.osdesc) : '') + ',' + csvClean(parent.meshes[n.meshid].name);
|
||||
} else {
|
||||
output += ',,,,,,,';
|
||||
}
|
||||
|
||||
// System infomation
|
||||
if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.windows) && (nodeinfo.sys.hardware.windows)) {
|
||||
// Windows
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.windows.cpu && (nodeinfo.sys.hardware.windows.cpu.length > 0) && (typeof nodeinfo.sys.hardware.windows.cpu[0].Name == 'string')) { output += csvClean(nodeinfo.sys.hardware.windows.cpu[0].Name); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.windows.osinfo && (nodeinfo.sys.hardware.windows.osinfo.BuildNumber)) { output += csvClean(nodeinfo.sys.hardware.windows.osinfo.BuildNumber); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_date)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_date); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_vendor)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_vendor); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_version)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_version); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_name)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_name); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_vendor)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_vendor); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_version)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_version); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.identifiers.product_uuid); }
|
||||
} else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.mobile)) {
|
||||
// Mobile
|
||||
output += ',';
|
||||
output += ',';
|
||||
output += ',';
|
||||
output += ',';
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.bootloader)) { output += csvClean(nodeinfo.sys.hardware.mobile.bootloader); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.model)) { output += csvClean(nodeinfo.sys.hardware.mobile.model); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.brand)) { output += csvClean(nodeinfo.sys.hardware.mobile.brand); }
|
||||
output += ',';
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.id)) { output += csvClean(nodeinfo.sys.hardware.mobile.id); }
|
||||
} else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.windows) && (nodeinfo.sys.hardware.linux)) {
|
||||
// Linux
|
||||
output += ',';
|
||||
output += ',';
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_date)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_date); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_vendor)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_vendor); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_version)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_version); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_name)) { output += csvClean(nodeinfo.sys.hardware.linux.board_name); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_vendor)) { output += csvClean(nodeinfo.sys.hardware.linux.board_vendor); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_version)) { output += csvClean(nodeinfo.sys.hardware.linux.board_version); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.linux.product_uuid); }
|
||||
} else {
|
||||
output += ',,,,,,,,,';
|
||||
}
|
||||
|
||||
// Agent information
|
||||
if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.agentvers)) {
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.agentvers.openssl) { output += csvClean(nodeinfo.sys.hardware.agentvers.openssl); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.agentvers.commitDate) { output += csvClean(nodeinfo.sys.hardware.agentvers.commitDate); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.agentvers.commitHash) { output += csvClean(nodeinfo.sys.hardware.agentvers.commitHash); }
|
||||
output += ',';
|
||||
if (nodeinfo.sys.hardware.agentvers.compileTime) { output += csvClean(nodeinfo.sys.hardware.agentvers.compileTime); }
|
||||
} else {
|
||||
output += ',,,,';
|
||||
}
|
||||
|
||||
// Network interfaces
|
||||
if ((nodeinfo.net) && (nodeinfo.net.netif2)) {
|
||||
output += ',';
|
||||
output += Object.keys(nodeinfo.net.netif2).length; // Interface count
|
||||
var macs = [], addresses = [];
|
||||
for (var j in nodeinfo.net.netif2) {
|
||||
if (Array.isArray(nodeinfo.net.netif2[j])) {
|
||||
for (var k = 0; k < nodeinfo.net.netif2[j].length; k++) {
|
||||
if (typeof nodeinfo.net.netif2[j][k].mac == 'string') { macs.push(nodeinfo.net.netif2[j][k].mac); }
|
||||
if (typeof nodeinfo.net.netif2[j][k].address == 'string') { addresses.push(nodeinfo.net.netif2[j][k].address); }
|
||||
}
|
||||
}
|
||||
}
|
||||
output += ',';
|
||||
output += csvClean(macs.join(' ')); // MACS
|
||||
output += ',';
|
||||
output += csvClean(addresses.join(' ')); // Addresses
|
||||
} else {
|
||||
output += ',,,';
|
||||
}
|
||||
|
||||
output += '\r\n';
|
||||
}
|
||||
} catch (ex) { console.log(ex); }
|
||||
} else { output = JSON.stringify(results, null, 2); }
|
||||
try { ws.send(JSON.stringify({ action: 'getDeviceDetails', data: output, type: type })); } catch (ex) { }
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -5562,6 +5681,48 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
}
|
||||
}
|
||||
|
||||
function csvClean(s) { return '\"' + s.split('\"').join('').split(',').join('').split('\r').join('').split('\n').join('') + '\"'; }
|
||||
|
||||
// Return detailed information about an array of nodeid's
|
||||
function getDeviceDetailedInfo(nodeids, type, func) {
|
||||
var results = [], resultPendingCount = 0;
|
||||
for (var i in nodeids) {
|
||||
// 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 = nodeids[i];
|
||||
parent.GetNodeWithRights(domain, user, nodeids[i], getNodeFunc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Display a notification message for this session only.
|
||||
function displayNotificationMessage(msg, title, tag, titleid, msgid, args) {
|
||||
ws.send(JSON.stringify({ 'action': 'msg', 'type': 'notify', id: Math.random(), 'value': msg, 'title': title, 'userid': user._id, 'username': user.name, 'tag': tag, 'titleid': titleid, 'msgid': msgid, 'args': args }));
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3323,6 +3323,11 @@
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'getDeviceDetails':{
|
||||
console.log(message);
|
||||
saveAs(new Blob([message.data], { type: 'application/octet-stream' }), "devicelist" + '.' + message.type);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
//console.log('Unknown message.action', message.action);
|
||||
break;
|
||||
@ -4959,23 +4964,36 @@
|
||||
var x = "Download the list of devices with one of the file formats below." + '<br /><br />';
|
||||
x += addHtmlValue("CSV Format", '<a href=# style=cursor:pointer onclick=\'return p2downloadDeviceInfoCSV()\'>' + "devicelist.csv" + '</a>');
|
||||
x += addHtmlValue("JSON Format", '<a href=# style=cursor:pointer onclick=\'return p2downloadDeviceInfoJSON()\'>' + "devicelist.json" + '</a>');
|
||||
x += '<div style=margin-top:8px><label><input type=checkbox id=d2DevInfoDetailsCheck />' + "Include device details" + '</label></div>';
|
||||
setDialogMode(2, "Device Information Export", 1, null, x);
|
||||
}
|
||||
|
||||
function p2downloadDeviceInfoCSV() {
|
||||
var csv = "id, name, rname, host, icon, ip, osdesc, state, groupname, conn, pwr" + '\r\n', chkNodeIds = getCheckedDevices(), r = [];
|
||||
var chkNodeIds = getCheckedDevices();
|
||||
if (Q('d2DevInfoDetailsCheck').checked) {
|
||||
meshserver.send({ action: 'getDeviceDetails', nodeids: chkNodeIds, type: 'csv' }); // With details
|
||||
} else {
|
||||
// Without details
|
||||
var csv = "id, name, rname, host, icon, ip, osdesc, state, groupname, conn, pwr" + '\r\n', r = [];
|
||||
for (var i in chkNodeIds) {
|
||||
var n = getNodeFromId(chkNodeIds[i]);
|
||||
csv += '"' + n._id.split(',').join('') + '","' + n.name.split(',').join('') + '","' + (n.rname?(n.rname.split(',').join('')):'') + '","' + (n.host?(n.host.split(',').join('')):'') + '","' + n.icon + '","' + (n.ip?n.ip:'') + '","' + (n.osdesc?(n.osdesc.split(',').join('')):'') + '","' + n.state + '","' + meshes[n.meshid].name.split(',').join('') + '","' + (n.conn?n.conn:'') + '","' + (n.pwr?n.pwr:'') + '"\r\n';
|
||||
}
|
||||
saveAs(new Blob([csv], { type: 'application/octet-stream' }), "devicelist.csv");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function p2downloadDeviceInfoJSON() {
|
||||
var chkNodeIds = getCheckedDevices(), r = [];
|
||||
var chkNodeIds = getCheckedDevices();
|
||||
if (Q('d2DevInfoDetailsCheck').checked) {
|
||||
meshserver.send({ action: 'getDeviceDetails', nodeids: chkNodeIds, type: 'json' }); // With details
|
||||
} else {
|
||||
// Without details
|
||||
var r = [];
|
||||
for (var i in chkNodeIds) { r.push(getNodeFromId(chkNodeIds[i])); }
|
||||
saveAs(new Blob([JSON.stringify(r, null, 2)], { type: 'application/octet-stream' }), "devicelist.json");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user