Added last connection time and address to device details export.

This commit is contained in:
Ylian Saint-Hilaire 2021-07-30 18:06:26 -07:00
parent d7e41d8366
commit bc316b01ae
3 changed files with 176 additions and 137 deletions

View File

@ -410,7 +410,7 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, mpsConn
// We got a chunk with all of the data, handle the chunck now.
var data = obj.socketAccumulator.substring(clen + 2, clen + 2 + csize);
obj.socketAccumulator = obj.socketAccumulator.substring(clen + 2 + csize + 2);
obj.socketData += data;
try { obj.socketData += data; } catch (ex) { console.log(ex, typeof data, data.length); }
}
if (csize == 0) {
//obj.Debug("xxOnSocketData DONE: (" + obj.socketData.length + "): " + obj.socketData);

View File

@ -5265,15 +5265,31 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
case 'getDeviceDetails': {
if ((common.validateStrArray(command.nodeids, 1) == false) && (command.nodeids != null)) break; // Check nodeids
if (common.validateString(command.type, 3, 4) == false) break; // Check type
// Create a list of node ids and query them for last device connection time
const ids = []
for (var i in command.nodeids) { ids.push('lc' + command.nodeids[i]); }
db.GetAllIdsOfType(ids, domain.id, 'lastconnect', function (err, docs) {
const lastConnects = {};
if (docs != null) { for (var i in docs) { lastConnects[docs[i]._id] = docs[i]; } }
getDeviceDetailedInfo(command.nodeids, command.type, function (results, type) {
for (var i = 0; i < results.length; i++) {
// Remove any device system and network information is we do not have details rights to this device
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; } }
if ((parent.GetNodeRights(user, results[i].node.meshid, results[i].node._id) & MESHRIGHT_DEVICEDETAILS) == 0) {
delete results[i].sys; delete results[i].net;
}
// Merge any last connection information
const lc = lastConnects['lc' + results[i].node._id];
if (lc != null) { delete lc._id; delete lc.type; delete lc.domain; results[i].lastConnect = lc; }
}
var output = null;
if (type == 'csv') {
try {
// Create the CSV file
output = 'id,name,rname,host,icon,ip,osdesc,groupname,av,update,firewall,avdetails,cpu,osbuild,biosDate,biosVendor,biosVersion,boardName,boardVendor,boardVersion,productUuid,agentOpenSSL,agentCommitDate,agentCommitHash,agentCompileTime,netIfCount,macs,addresses\r\n';
output = 'id,name,rname,host,icon,ip,osdesc,groupname,av,update,firewall,avdetails,cpu,osbuild,biosDate,biosVendor,biosVersion,boardName,boardVendor,boardVersion,productUuid,agentOpenSSL,agentCommitDate,agentCommitHash,agentCompileTime,netIfCount,macs,addresses,lastConnectTime,lastConnectAddr\r\n';
for (var i = 0; i < results.length; i++) {
const nodeinfo = results[i];
@ -5387,6 +5403,23 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
output += ',,,';
}
// Last connection information
if (nodeinfo.lastConnect) {
output += ',';
if (nodeinfo.lastConnect.time) {
// Last connection time
if ((typeof command.l == 'string') && (typeof command.tz == 'string')) {
output += csvClean(new Date(nodeinfo.lastConnect.time).toLocaleString(command.l, { timeZone: command.tz }))
} else {
output += nodeinfo.lastConnect.time;
}
}
output += ',';
if (typeof nodeinfo.lastConnect.addr == 'string') { output += csvClean(nodeinfo.lastConnect.addr); } // Last connection address and port
} else {
output += ',,';
}
output += '\r\n';
}
} catch (ex) { console.log(ex); }
@ -5406,6 +5439,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
try { ws.send(JSON.stringify({ action: 'getDeviceDetails', data: output, type: type })); } catch (ex) { }
});
});
break;
}
default: {

View File

@ -5227,7 +5227,9 @@
function p2downloadDeviceInfoCSV() {
var chkNodeIds = getCheckedDevices();
if (Q('d2DevInfoDetailsCheck').checked) {
meshserver.send({ action: 'getDeviceDetails', nodeids: chkNodeIds, type: 'csv' }); // With details
var tz = null;
try { tz = Intl.DateTimeFormat().resolvedOptions().timeZone; } catch (ex) {}
meshserver.send({ action: 'getDeviceDetails', nodeids: chkNodeIds, tz: tz, tf: new Date().getTimezoneOffset(), l: getLang(), type: 'csv' }); // With details
} else {
// Without details
var csv = "id, name, rname, host, icon, ip, osdesc, state, groupname, conn, pwr, av, update, firewall, avdetails" + '\r\n', r = [];
@ -5268,7 +5270,9 @@
function p2downloadDeviceInfoJSON() {
var chkNodeIds = getCheckedDevices();
if (Q('d2DevInfoDetailsCheck').checked) {
meshserver.send({ action: 'getDeviceDetails', nodeids: chkNodeIds, type: 'json' }); // With details
var tz = null;
try { tz = Intl.DateTimeFormat().resolvedOptions().timeZone; } catch (ex) {}
meshserver.send({ action: 'getDeviceDetails', nodeids: chkNodeIds, tz: tz, tf: new Date().getTimezoneOffset(), l: getLang(), type: 'json' }); // With details
} else {
// Without details
var r = [];