fix getDeviceDetails asking for all devices not including lastconnect #6833
Signed-off-by: si458 <simonsmith5521@gmail.com>
si458 committed
Mar 3, 2025 at 14:13 UTC
9398afd07e371ce035c7a68cc55642f4f95db21e
1 file changed
+259
-250
meshuser.js
+259
-250
@@ -5076,286 +5076,295 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5076
case 'getDeviceDetails': {
5077
if ((common.validateStrArray(command.nodeids, 1) == false) && (command.nodeids != null)) break; // Check nodeids
5078
if (common.validateString(command.type, 3, 4) == false) break; // Check type
5079
+
5080
+ const links = parent.GetAllMeshIdWithRights(user);
5081
+ const extraids = getUserExtraIds();
5082
+ db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, obj.deviceSkip, obj.deviceLimit, function (err, docs) {
5083
+ if (docs == null) return;
5084
+ const ids = [];
5085
+ if (command.nodeids != null) {
5086
+ // Create a list of node ids and query them for last device connection time
5087
+ for (var i in command.nodeids) { ids.push('lc' + command.nodeids[i]); }
5088
+ } else {
5089
+ // Create a list of node ids for this user and query them for last device connection time
5090
+ for (var i in docs) { ids.push('lc' + docs[i]._id); }
5091
+ }
5092
+ db.GetAllIdsOfType(ids, domain.id, 'lastconnect', function (err, docs) {
5093
+ const lastConnects = {};
5094
+ if (docs != null) { for (var i in docs) { lastConnects[docs[i]._id] = docs[i]; } }
5095
5080
- // Create a list of node ids and query them for last device connection time
5081
- const ids = []
5082
- for (var i in command.nodeids) { ids.push('lc' + command.nodeids[i]); }
5083
- db.GetAllIdsOfType(ids, domain.id, 'lastconnect', function (err, docs) {
5084
- const lastConnects = {};
5085
- if (docs != null) { for (var i in docs) { lastConnects[docs[i]._id] = docs[i]; } }
5086
-
5087
- getDeviceDetailedInfo(command.nodeids, command.type, function (results, type) {
5088
- for (var i = 0; i < results.length; i++) {
5089
- // Remove any device system and network information is we do not have details rights to this device
5090
- if ((parent.GetNodeRights(user, results[i].node.meshid, results[i].node._id) & MESHRIGHT_DEVICEDETAILS) == 0) {
5091
- delete results[i].sys; delete results[i].net;
5092
- }
5093
-
5094
- // Merge any last connection information
5095
- const lc = lastConnects['lc' + results[i].node._id];
5096
- if (lc != null) { delete lc._id; delete lc.type; delete lc.meshid; delete lc.domain; results[i].lastConnect = lc; }
5097
-
5098
- // Remove any connectivity and power state information, that should not be in the database anyway.
5099
- // TODO: Find why these are sometimes saved in the db.
5100
- if (results[i].node.conn != null) { delete results[i].node.conn; }
5101
- if (results[i].node.pwr != null) { delete results[i].node.pwr; }
5102
- if (results[i].node.agct != null) { delete results[i].node.agct; }
5103
- if (results[i].node.cict != null) { delete results[i].node.cict; }
5104
-
5105
- // Add the connection state
5106
- var state = parent.parent.GetConnectivityState(results[i].node._id);
5107
- if (state) {
5108
- results[i].node.conn = state.connectivity;
5109
- results[i].node.pwr = state.powerState;
5110
- if ((state.connectivity & 1) != 0) { var agent = parent.wsagents[results[i].node._id]; if (agent != null) { results[i].node.agct = agent.connectTime; } }
5096
+ getDeviceDetailedInfo(command.nodeids, command.type, function (results, type) {
5097
+ for (var i = 0; i < results.length; i++) {
5098
+ // Remove any device system and network information is we do not have details rights to this device
5099
+ if ((parent.GetNodeRights(user, results[i].node.meshid, results[i].node._id) & MESHRIGHT_DEVICEDETAILS) == 0) {
5100
+ delete results[i].sys; delete results[i].net;
5101
+ }
5102
5112
- // Use the connection time of the CIRA/Relay connection
5113
- if ((state.connectivity & 2) != 0) {
5114
- var ciraConnection = parent.parent.mpsserver.GetConnectionToNode(results[i].node._id, null, true);
5115
- if ((ciraConnection != null) && (ciraConnection.tag != null)) { results[i].node.cict = ciraConnection.tag.connectTime; }
5103
+ // Merge any last connection information
5104
+ const lc = lastConnects['lc' + results[i].node._id];
5105
+ if (lc != null) { delete lc._id; delete lc.type; delete lc.meshid; delete lc.domain; results[i].lastConnect = lc; }
5106
+
5107
+ // Remove any connectivity and power state information, that should not be in the database anyway.
5108
+ // TODO: Find why these are sometimes saved in the db.
5109
+ if (results[i].node.conn != null) { delete results[i].node.conn; }
5110
+ if (results[i].node.pwr != null) { delete results[i].node.pwr; }
5111
+ if (results[i].node.agct != null) { delete results[i].node.agct; }
5112
+ if (results[i].node.cict != null) { delete results[i].node.cict; }
5113
+
5114
+ // Add the connection state
5115
+ var state = parent.parent.GetConnectivityState(results[i].node._id);
5116
+ if (state) {
5117
+ results[i].node.conn = state.connectivity;
5118
+ results[i].node.pwr = state.powerState;
5119
+ if ((state.connectivity & 1) != 0) { var agent = parent.wsagents[results[i].node._id]; if (agent != null) { results[i].node.agct = agent.connectTime; } }
5120
+
5121
+ // Use the connection time of the CIRA/Relay connection
5122
+ if ((state.connectivity & 2) != 0) {
5123
+ var ciraConnection = parent.parent.mpsserver.GetConnectionToNode(results[i].node._id, null, true);
5124
+ if ((ciraConnection != null) && (ciraConnection.tag != null)) { results[i].node.cict = ciraConnection.tag.connectTime; }
5125
+ }
5126
}
5127
+
5128
}
5118
-
5119
- }
5120
-
5121
- var output = null;
5122
- if (type == 'csv') {
5123
- try {
5124
- // Create the CSV file
5125
- output = 'id,name,rname,host,icon,ip,osdesc,groupname,av,update,firewall,bitlocker,avdetails,tags,lastbootuptime,cpu,osbuild,biosDate,biosVendor,biosVersion,biosSerial,biosMode,boardName,boardVendor,boardVersion,productUuid,tpmversion,tpmmanufacturer,tpmmanufacturerversion,tpmisactivated,tpmisenabled,tpmisowned,totalMemory,agentOpenSSL,agentCommitDate,agentCommitHash,agentCompileTime,netIfCount,macs,addresses,lastConnectTime,lastConnectAddr\r\n';
5126
- for (var i = 0; i < results.length; i++) {
5127
- const nodeinfo = results[i];
5129
5129
- // Node information
5130
- if (nodeinfo.node != null) {
5131
- const n = nodeinfo.node;
5132
- output += csvClean(n._id) + ',' + csvClean(n.name) + ',' + csvClean(n.rname ? n.rname : '') + ',' + csvClean(n.host ? n.host : '') + ',' + (n.icon ? n.icon : 1) + ',' + (n.ip ? n.ip : '') + ',' + (n.osdesc ? csvClean(n.osdesc) : '') + ',' + csvClean(parent.meshes[n.meshid].name);
5133
- if (typeof n.wsc == 'object') {
5134
- output += ',' + csvClean(n.wsc.antiVirus ? n.wsc.antiVirus : '') + ',' + csvClean(n.wsc.autoUpdate ? n.wsc.autoUpdate : '') + ',' + csvClean(n.wsc.firewall ? n.wsc.firewall : '')
5135
- } else { output += ',,,'; }
5136
- if (typeof n.volumes == 'object') {
5137
- var bitlockerdetails = '', firstbitlocker = true;
5138
- for (var a in n.volumes) { if (typeof n.volumes[a].protectionStatus !== 'undefined') { if (firstbitlocker) { firstbitlocker = false; } else { bitlockerdetails += '|'; } bitlockerdetails += a + '/' + n.volumes[a].volumeStatus; } }
5139
- output += ',' + csvClean(bitlockerdetails);
5130
+ var output = null;
5131
+ if (type == 'csv') {
5132
+ try {
5133
+ // Create the CSV file
5134
+ output = 'id,name,rname,host,icon,ip,osdesc,groupname,av,update,firewall,bitlocker,avdetails,tags,lastbootuptime,cpu,osbuild,biosDate,biosVendor,biosVersion,biosSerial,biosMode,boardName,boardVendor,boardVersion,productUuid,tpmversion,tpmmanufacturer,tpmmanufacturerversion,tpmisactivated,tpmisenabled,tpmisowned,totalMemory,agentOpenSSL,agentCommitDate,agentCommitHash,agentCompileTime,netIfCount,macs,addresses,lastConnectTime,lastConnectAddr\r\n';
5135
+ for (var i = 0; i < results.length; i++) {
5136
+ const nodeinfo = results[i];
5137
+
5138
+ // Node information
5139
+ if (nodeinfo.node != null) {
5140
+ const n = nodeinfo.node;
5141
+ output += csvClean(n._id) + ',' + csvClean(n.name) + ',' + csvClean(n.rname ? n.rname : '') + ',' + csvClean(n.host ? n.host : '') + ',' + (n.icon ? n.icon : 1) + ',' + (n.ip ? n.ip : '') + ',' + (n.osdesc ? csvClean(n.osdesc) : '') + ',' + csvClean(parent.meshes[n.meshid].name);
5142
+ if (typeof n.wsc == 'object') {
5143
+ output += ',' + csvClean(n.wsc.antiVirus ? n.wsc.antiVirus : '') + ',' + csvClean(n.wsc.autoUpdate ? n.wsc.autoUpdate : '') + ',' + csvClean(n.wsc.firewall ? n.wsc.firewall : '')
5144
+ } else { output += ',,,'; }
5145
+ if (typeof n.volumes == 'object') {
5146
+ var bitlockerdetails = '', firstbitlocker = true;
5147
+ for (var a in n.volumes) { if (typeof n.volumes[a].protectionStatus !== 'undefined') { if (firstbitlocker) { firstbitlocker = false; } else { bitlockerdetails += '|'; } bitlockerdetails += a + '/' + n.volumes[a].volumeStatus; } }
5148
+ output += ',' + csvClean(bitlockerdetails);
5149
+ } else {
5150
+ output += ',';
5151
+ }
5152
+ if (typeof n.av == 'object') {
5153
+ var avdetails = '', firstav = true;
5154
+ for (var a in n.av) { if (typeof n.av[a].product == 'string') { if (firstav) { firstav = false; } else { avdetails += '|'; } avdetails += (n.av[a].product + '/' + ((n.av[a].enabled) ? 'enabled' : 'disabled') + '/' + ((n.av[a].updated) ? 'updated' : 'notupdated')); } }
5155
+ output += ',' + csvClean(avdetails);
5156
+ } else {
5157
+ output += ',';
5158
+ }
5159
+ if (typeof n.tags == 'object') {
5160
+ var tagsdetails = '', firsttags = true;
5161
+ for (var a in n.tags) { if (firsttags) { firsttags = false; } else { tagsdetails += '|'; } tagsdetails += n.tags[a]; }
5162
+ output += ',' + csvClean(tagsdetails);
5163
+ } else {
5164
+ output += ',';
5165
+ }
5166
+ if (typeof n.lastbootuptime == 'number') { output += ',' + n.lastbootuptime; } else { output += ','; }
5167
} else {
5141
- output += ',';
5168
+ output += ',,,,,,,,,,,,,,,,,,,,';
5169
}
5143
- if (typeof n.av == 'object') {
5144
- var avdetails = '', firstav = true;
5145
- for (var a in n.av) { if (typeof n.av[a].product == 'string') { if (firstav) { firstav = false; } else { avdetails += '|'; } avdetails += (n.av[a].product + '/' + ((n.av[a].enabled) ? 'enabled' : 'disabled') + '/' + ((n.av[a].updated) ? 'updated' : 'notupdated')); } }
5146
- output += ',' + csvClean(avdetails);
5147
- } else {
5170
+
5171
+ // System infomation
5172
+ if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.windows)) {
5173
+ // Windows
5174
output += ',';
5149
- }
5150
- if (typeof n.tags == 'object') {
5151
- var tagsdetails = '', firsttags = true;
5152
- for (var a in n.tags) { if (firsttags) { firsttags = false; } else { tagsdetails += '|'; } tagsdetails += n.tags[a]; }
5153
- output += ',' + csvClean(tagsdetails);
5154
- } else {
5175
+ 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); }
5176
output += ',';
5156
- }
5157
- if (typeof n.lastbootuptime == 'number') { output += ',' + n.lastbootuptime; } else { output += ','; }
5158
- } else {
5159
- output += ',,,,,,,,,,,,,,,,,,,,';
5160
- }
5161
-
5162
- // System infomation
5163
- if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.windows)) {
5164
- // Windows
5165
- output += ',';
5166
- 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); }
5167
- output += ',';
5168
- if (nodeinfo.sys.hardware.windows.osinfo && (nodeinfo.sys.hardware.windows.osinfo.BuildNumber)) { output += csvClean(nodeinfo.sys.hardware.windows.osinfo.BuildNumber); }
5169
- output += ',';
5170
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_date)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_date); }
5171
- output += ',';
5172
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_vendor)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_vendor); }
5173
- output += ',';
5174
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_version)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_version); }
5175
- output += ',';
5176
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_serial)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_serial); }
5177
- output += ',';
5178
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_mode)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_mode); }
5179
- output += ',';
5180
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_name)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_name); }
5181
- output += ',';
5182
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_vendor)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_vendor); }
5183
- output += ',';
5184
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_version)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_version); }
5185
- output += ',';
5186
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.identifiers.product_uuid); }
5187
- output += ',';
5188
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.SpecVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.SpecVersion); }
5189
- output += ',';
5190
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerId) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerId); }
5191
- output += ',';
5192
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerVersion); }
5193
- output += ',';
5194
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsActivated) { output += csvClean(nodeinfo.sys.hardware.tpm.IsActivated ? 'true' : 'false'); }
5195
- output += ',';
5196
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsEnabled) { output += csvClean(nodeinfo.sys.hardware.tpm.IsEnabled ? 'true' : 'false'); }
5197
- output += ',';
5198
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsOwned) { output += csvClean(nodeinfo.sys.hardware.tpm.IsOwned ? 'true' : 'false'); }
5199
- output += ',';
5200
- if (nodeinfo.sys.hardware.windows.memory) {
5201
- var totalMemory = 0;
5202
- for (var j in nodeinfo.sys.hardware.windows.memory) {
5203
- if (nodeinfo.sys.hardware.windows.memory[j].Capacity) {
5204
- if (typeof nodeinfo.sys.hardware.windows.memory[j].Capacity == 'number') { totalMemory += nodeinfo.sys.hardware.windows.memory[j].Capacity; }
5205
- if (typeof nodeinfo.sys.hardware.windows.memory[j].Capacity == 'string') { totalMemory += parseInt(nodeinfo.sys.hardware.windows.memory[j].Capacity); }
5177
+ if (nodeinfo.sys.hardware.windows.osinfo && (nodeinfo.sys.hardware.windows.osinfo.BuildNumber)) { output += csvClean(nodeinfo.sys.hardware.windows.osinfo.BuildNumber); }
5178
+ output += ',';
5179
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_date)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_date); }
5180
+ output += ',';
5181
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_vendor)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_vendor); }
5182
+ output += ',';
5183
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_version)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_version); }
5184
+ output += ',';
5185
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_serial)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_serial); }
5186
+ output += ',';
5187
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_mode)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_mode); }
5188
+ output += ',';
5189
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_name)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_name); }
5190
+ output += ',';
5191
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_vendor)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_vendor); }
5192
+ output += ',';
5193
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.board_version)) { output += csvClean(nodeinfo.sys.hardware.identifiers.board_version); }
5194
+ output += ',';
5195
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.identifiers.product_uuid); }
5196
+ output += ',';
5197
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.SpecVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.SpecVersion); }
5198
+ output += ',';
5199
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerId) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerId); }
5200
+ output += ',';
5201
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerVersion); }
5202
+ output += ',';
5203
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsActivated) { output += csvClean(nodeinfo.sys.hardware.tpm.IsActivated ? 'true' : 'false'); }
5204
+ output += ',';
5205
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsEnabled) { output += csvClean(nodeinfo.sys.hardware.tpm.IsEnabled ? 'true' : 'false'); }
5206
+ output += ',';
5207
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsOwned) { output += csvClean(nodeinfo.sys.hardware.tpm.IsOwned ? 'true' : 'false'); }
5208
+ output += ',';
5209
+ if (nodeinfo.sys.hardware.windows.memory) {
5210
+ var totalMemory = 0;
5211
+ for (var j in nodeinfo.sys.hardware.windows.memory) {
5212
+ if (nodeinfo.sys.hardware.windows.memory[j].Capacity) {
5213
+ if (typeof nodeinfo.sys.hardware.windows.memory[j].Capacity == 'number') { totalMemory += nodeinfo.sys.hardware.windows.memory[j].Capacity; }
5214
+ if (typeof nodeinfo.sys.hardware.windows.memory[j].Capacity == 'string') { totalMemory += parseInt(nodeinfo.sys.hardware.windows.memory[j].Capacity); }
5215
+ }
5216
}
5217
+ output += csvClean('' + totalMemory);
5218
}
5208
- output += csvClean('' + totalMemory);
5209
- }
5210
- } else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.mobile)) {
5211
- // Mobile
5212
- output += ',';
5213
- output += ',';
5214
- output += ',';
5215
- output += ',';
5216
- output += ',';
5217
- if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.bootloader)) { output += csvClean(nodeinfo.sys.hardware.mobile.bootloader); }
5218
- output += ',';
5219
- output += ',';
5220
- output += ',';
5221
- if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.model)) { output += csvClean(nodeinfo.sys.hardware.mobile.model); }
5222
- output += ',';
5223
- if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.brand)) { output += csvClean(nodeinfo.sys.hardware.mobile.brand); }
5224
- output += ',';
5225
- output += ',';
5226
- if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.id)) { output += csvClean(nodeinfo.sys.hardware.mobile.id); }
5227
- output += ',';
5228
- output += ',';
5229
- output += ',';
5230
- output += ',';
5231
- output += ',';
5232
- output += ',';
5233
- output += ',';
5234
- } else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.linux)) {
5235
- // Linux
5236
- output += ',';
5237
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.cpu_name)) { output += csvClean(nodeinfo.sys.hardware.identifiers.cpu_name); }
5238
- output += ',,';
5239
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_date)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_date); }
5240
- output += ',';
5241
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_vendor)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_vendor); }
5242
- output += ',';
5243
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_version)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_version); }
5244
- output += ',';
5245
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.product_serial)) { output += csvClean(nodeinfo.sys.hardware.linux.product_serial); }
5246
- else if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_serial)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_serial); }
5247
- output += ',';
5248
- if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_mode)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_mode); }
5249
- output += ',';
5250
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_name)) { output += csvClean(nodeinfo.sys.hardware.linux.board_name); }
5251
- output += ',';
5252
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_vendor)) { output += csvClean(nodeinfo.sys.hardware.linux.board_vendor); }
5253
- output += ',';
5254
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_version)) { output += csvClean(nodeinfo.sys.hardware.linux.board_version); }
5255
- output += ',';
5256
- if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.linux.product_uuid); }
5257
- output += ',';
5258
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.SpecVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.SpecVersion); }
5259
- output += ',';
5260
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerId) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerId); }
5261
- output += ',';
5262
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerVersion); }
5263
- output += ',';
5264
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsActivated) { output += csvClean(nodeinfo.sys.hardware.tpm.IsActivated ? 'true' : 'false'); }
5265
- output += ',';
5266
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsEnabled) { output += csvClean(nodeinfo.sys.hardware.tpm.IsEnabled ? 'true' : 'false'); }
5267
- output += ',';
5268
- if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsOwned) { output += csvClean(nodeinfo.sys.hardware.tpm.IsOwned ? 'true' : 'false'); }
5269
- output += ',';
5270
- if (nodeinfo.sys.hardware.linux.memory) {
5271
- if (nodeinfo.sys.hardware.linux.memory.Memory_Device) {
5272
- var totalMemory = 0;
5273
- for (var j in nodeinfo.sys.hardware.linux.memory.Memory_Device) {
5274
- if (nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size) {
5275
- if (typeof nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size == 'number') { totalMemory += nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size; }
5276
- if (typeof nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size == 'string') { totalMemory += parseInt(nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size); }
5219
+ } else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.mobile)) {
5220
+ // Mobile
5221
+ output += ',';
5222
+ output += ',';
5223
+ output += ',';
5224
+ output += ',';
5225
+ output += ',';
5226
+ if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.bootloader)) { output += csvClean(nodeinfo.sys.hardware.mobile.bootloader); }
5227
+ output += ',';
5228
+ output += ',';
5229
+ output += ',';
5230
+ if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.model)) { output += csvClean(nodeinfo.sys.hardware.mobile.model); }
5231
+ output += ',';
5232
+ if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.brand)) { output += csvClean(nodeinfo.sys.hardware.mobile.brand); }
5233
+ output += ',';
5234
+ output += ',';
5235
+ if (nodeinfo.sys.hardware.mobile && (nodeinfo.sys.hardware.mobile.id)) { output += csvClean(nodeinfo.sys.hardware.mobile.id); }
5236
+ output += ',';
5237
+ output += ',';
5238
+ output += ',';
5239
+ output += ',';
5240
+ output += ',';
5241
+ output += ',';
5242
+ output += ',';
5243
+ } else if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.linux)) {
5244
+ // Linux
5245
+ output += ',';
5246
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.cpu_name)) { output += csvClean(nodeinfo.sys.hardware.identifiers.cpu_name); }
5247
+ output += ',,';
5248
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_date)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_date); }
5249
+ output += ',';
5250
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_vendor)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_vendor); }
5251
+ output += ',';
5252
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.bios_version)) { output += csvClean(nodeinfo.sys.hardware.linux.bios_version); }
5253
+ output += ',';
5254
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.product_serial)) { output += csvClean(nodeinfo.sys.hardware.linux.product_serial); }
5255
+ else if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_serial)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_serial); }
5256
+ output += ',';
5257
+ if (nodeinfo.sys.hardware.identifiers && (nodeinfo.sys.hardware.identifiers.bios_mode)) { output += csvClean(nodeinfo.sys.hardware.identifiers.bios_mode); }
5258
+ output += ',';
5259
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_name)) { output += csvClean(nodeinfo.sys.hardware.linux.board_name); }
5260
+ output += ',';
5261
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_vendor)) { output += csvClean(nodeinfo.sys.hardware.linux.board_vendor); }
5262
+ output += ',';
5263
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.board_version)) { output += csvClean(nodeinfo.sys.hardware.linux.board_version); }
5264
+ output += ',';
5265
+ if (nodeinfo.sys.hardware.linux && (nodeinfo.sys.hardware.linux.product_uuid)) { output += csvClean(nodeinfo.sys.hardware.linux.product_uuid); }
5266
+ output += ',';
5267
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.SpecVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.SpecVersion); }
5268
+ output += ',';
5269
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerId) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerId); }
5270
+ output += ',';
5271
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.ManufacturerVersion) { output += csvClean(nodeinfo.sys.hardware.tpm.ManufacturerVersion); }
5272
+ output += ',';
5273
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsActivated) { output += csvClean(nodeinfo.sys.hardware.tpm.IsActivated ? 'true' : 'false'); }
5274
+ output += ',';
5275
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsEnabled) { output += csvClean(nodeinfo.sys.hardware.tpm.IsEnabled ? 'true' : 'false'); }
5276
+ output += ',';
5277
+ if (nodeinfo.sys.hardware.tpm && nodeinfo.sys.hardware.tpm.IsOwned) { output += csvClean(nodeinfo.sys.hardware.tpm.IsOwned ? 'true' : 'false'); }
5278
+ output += ',';
5279
+ if (nodeinfo.sys.hardware.linux.memory) {
5280
+ if (nodeinfo.sys.hardware.linux.memory.Memory_Device) {
5281
+ var totalMemory = 0;
5282
+ for (var j in nodeinfo.sys.hardware.linux.memory.Memory_Device) {
5283
+ if (nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size) {
5284
+ if (typeof nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size == 'number') { totalMemory += nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size; }
5285
+ if (typeof nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size == 'string') { totalMemory += parseInt(nodeinfo.sys.hardware.linux.memory.Memory_Device[j].Size); }
5286
+ }
5287
}
5288
+ output += csvClean('' + (totalMemory * Math.pow(1024, 3)));
5289
}
5279
- output += csvClean('' + (totalMemory * Math.pow(1024, 3)));
5290
}
5291
+ } else {
5292
+ output += ',,,,,,,,,,,,,,,,,,';
5293
}
5282
- } else {
5283
- output += ',,,,,,,,,,,,,,,,,,';
5284
- }
5294
5286
- // Agent information
5287
- if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.agentvers)) {
5288
- output += ',';
5289
- if (nodeinfo.sys.hardware.agentvers.openssl) { output += csvClean(nodeinfo.sys.hardware.agentvers.openssl); }
5290
- output += ',';
5291
- if (nodeinfo.sys.hardware.agentvers.commitDate) { output += csvClean(nodeinfo.sys.hardware.agentvers.commitDate); }
5292
- output += ',';
5293
- if (nodeinfo.sys.hardware.agentvers.commitHash) { output += csvClean(nodeinfo.sys.hardware.agentvers.commitHash); }
5294
- output += ',';
5295
- if (nodeinfo.sys.hardware.agentvers.compileTime) { output += csvClean(nodeinfo.sys.hardware.agentvers.compileTime); }
5296
- } else {
5297
- output += ',,,,';
5298
- }
5295
+ // Agent information
5296
+ if ((nodeinfo.sys) && (nodeinfo.sys.hardware) && (nodeinfo.sys.hardware.agentvers)) {
5297
+ output += ',';
5298
+ if (nodeinfo.sys.hardware.agentvers.openssl) { output += csvClean(nodeinfo.sys.hardware.agentvers.openssl); }
5299
+ output += ',';
5300
+ if (nodeinfo.sys.hardware.agentvers.commitDate) { output += csvClean(nodeinfo.sys.hardware.agentvers.commitDate); }
5301
+ output += ',';
5302
+ if (nodeinfo.sys.hardware.agentvers.commitHash) { output += csvClean(nodeinfo.sys.hardware.agentvers.commitHash); }
5303
+ output += ',';
5304
+ if (nodeinfo.sys.hardware.agentvers.compileTime) { output += csvClean(nodeinfo.sys.hardware.agentvers.compileTime); }
5305
+ } else {
5306
+ output += ',,,,';
5307
+ }
5308
5300
- // Network interfaces
5301
- if ((nodeinfo.net) && (nodeinfo.net.netif2)) {
5302
- output += ',';
5303
- output += Object.keys(nodeinfo.net.netif2).length; // Interface count
5304
- var macs = [], addresses = [];
5305
- for (var j in nodeinfo.net.netif2) {
5306
- if (Array.isArray(nodeinfo.net.netif2[j])) {
5307
- for (var k = 0; k < nodeinfo.net.netif2[j].length; k++) {
5308
- if (typeof nodeinfo.net.netif2[j][k].mac == 'string') { macs.push(nodeinfo.net.netif2[j][k].mac); }
5309
- if (typeof nodeinfo.net.netif2[j][k].address == 'string') { addresses.push(nodeinfo.net.netif2[j][k].address); }
5309
+ // Network interfaces
5310
+ if ((nodeinfo.net) && (nodeinfo.net.netif2)) {
5311
+ output += ',';
5312
+ output += Object.keys(nodeinfo.net.netif2).length; // Interface count
5313
+ var macs = [], addresses = [];
5314
+ for (var j in nodeinfo.net.netif2) {
5315
+ if (Array.isArray(nodeinfo.net.netif2[j])) {
5316
+ for (var k = 0; k < nodeinfo.net.netif2[j].length; k++) {
5317
+ if (typeof nodeinfo.net.netif2[j][k].mac == 'string') { macs.push(nodeinfo.net.netif2[j][k].mac); }
5318
+ if (typeof nodeinfo.net.netif2[j][k].address == 'string') { addresses.push(nodeinfo.net.netif2[j][k].address); }
5319
+ }
5320
}
5321
}
5322
+ output += ',';
5323
+ output += csvClean(macs.join(' ')); // MACS
5324
+ output += ',';
5325
+ output += csvClean(addresses.join(' ')); // Addresses
5326
+ } else {
5327
+ output += ',,,';
5328
}
5313
- output += ',';
5314
- output += csvClean(macs.join(' ')); // MACS
5315
- output += ',';
5316
- output += csvClean(addresses.join(' ')); // Addresses
5317
- } else {
5318
- output += ',,,';
5319
- }
5329
5321
- // Last connection information
5322
- if (nodeinfo.lastConnect) {
5323
- output += ',';
5324
- if (nodeinfo.lastConnect.time) {
5325
- // Last connection time
5326
- if ((typeof command.l == 'string') && (typeof command.tz == 'string')) {
5327
- output += csvClean(new Date(nodeinfo.lastConnect.time).toLocaleString(command.l, { timeZone: command.tz }))
5328
- } else {
5329
- output += nodeinfo.lastConnect.time;
5330
+ // Last connection information
5331
+ if (nodeinfo.lastConnect) {
5332
+ output += ',';
5333
+ if (nodeinfo.lastConnect.time) {
5334
+ // Last connection time
5335
+ if ((typeof command.l == 'string') && (typeof command.tz == 'string')) {
5336
+ output += csvClean(new Date(nodeinfo.lastConnect.time).toLocaleString(command.l, { timeZone: command.tz }))
5337
+ } else {
5338
+ output += nodeinfo.lastConnect.time;
5339
+ }
5340
}
5341
+ output += ',';
5342
+ if (typeof nodeinfo.lastConnect.addr == 'string') { output += csvClean(nodeinfo.lastConnect.addr); } // Last connection address and port
5343
+ } else {
5344
+ output += ',,';
5345
}
5332
- output += ',';
5333
- if (typeof nodeinfo.lastConnect.addr == 'string') { output += csvClean(nodeinfo.lastConnect.addr); } // Last connection address and port
5334
- } else {
5335
- output += ',,';
5346
+
5347
+ output += '\r\n';
5348
}
5349
+ } catch (ex) { console.log(ex); }
5350
+ } else {
5351
+ // Create the JSON file
5352
5338
- output += '\r\n';
5353
+ // Add the device group name to each device
5354
+ for (var i = 0; i < results.length; i++) {
5355
+ const nodeinfo = results[i];
5356
+ if (nodeinfo.node) {
5357
+ const mesh = parent.meshes[nodeinfo.node.meshid];
5358
+ if (mesh) { results[i].node.groupname = mesh.name; }
5359
+ }
5360
}
5340
- } catch (ex) { console.log(ex); }
5341
- } else {
5342
- // Create the JSON file
5361
5344
- // Add the device group name to each device
5345
- for (var i = 0; i < results.length; i++) {
5346
- const nodeinfo = results[i];
5347
- if (nodeinfo.node) {
5348
- const mesh = parent.meshes[nodeinfo.node.meshid];
5349
- if (mesh) { results[i].node.groupname = mesh.name; }
5350
- }
5362
+ output = JSON.stringify(results, null, 2);
5363
}
5352
-
5353
- output = JSON.stringify(results, null, 2);
5354
- }
5355
- try { ws.send(JSON.stringify({ action: 'getDeviceDetails', data: output, type: type })); } catch (ex) { }
5364
+ try { ws.send(JSON.stringify({ action: 'getDeviceDetails', data: output, type: type })); } catch (ex) { }
5365
+ });
5366
});
5367
});
5358
-
5368
break;
5369
}
5370
case 'endDesktopMultiplex': {