MeshCtrl.js fixes and improvements.
Ylian Saint-Hilaire committed
Mar 11, 2021 at 11:51 UTC
eb2eaac7035eef947d4bed2876aed0a06f69c820
1 file changed
+88
-62
meshctrl.js
+88
-62
@@ -1356,9 +1356,10 @@ function serverConnect() {
1356
break;
1357
}
1358
case 'deviceinfo': {
1359
- settings.deviceinfocount = 3;
1360
- ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: args.id, nodeinfo: true, responseid: 'meshctrl' }));
1361
- ws.send(JSON.stringify({ action: 'lastconnect', nodeid: args.id, nodeinfo: true, responseid: 'meshctrl' }));
1359
+ settings.deviceinfocount = 4;
1360
+ ws.send(JSON.stringify({ action: 'nodes' }));
1361
+ ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: args.id, responseid: 'meshctrl' }));
1362
+ ws.send(JSON.stringify({ action: 'lastconnect', nodeid: args.id, responseid: 'meshctrl' }));
1363
ws.send(JSON.stringify({ action: 'getsysinfo', nodeid: args.id, nodeinfo: true, responseid: 'meshctrl' }));
1364
break;
1365
}
@@ -1641,27 +1642,22 @@ function serverConnect() {
1642
}
1643
case 'getsysinfo': { // DEVICEINFO
1644
if (settings.cmd == 'deviceinfo') {
1644
- if (data.result) {
1645
- console.log(data.result);
1646
- process.exit();
1647
- } else {
1648
- settings.sysinfo = data;
1649
- if (--settings.deviceinfocount == 0) { displayDeviceInfo(settings.sysinfo, settings.lastconnect, settings.networking); process.exit(); }
1650
- }
1645
+ settings.sysinfo = (data.result) ? null : data;
1646
+ if (--settings.deviceinfocount == 0) { displayDeviceInfo(settings.sysinfo, settings.lastconnect, settings.networking, settings.nodes); process.exit(); }
1647
}
1648
break;
1649
}
1650
case 'lastconnect': {
1651
if (settings.cmd == 'deviceinfo') {
1656
- settings.lastconnect = (data.result)?null:data;
1657
- if (--settings.deviceinfocount == 0) { displayDeviceInfo(settings.sysinfo, settings.lastconnect, settings.networking); process.exit(); }
1652
+ settings.lastconnect = (data.result) ? null : data;
1653
+ if (--settings.deviceinfocount == 0) { displayDeviceInfo(settings.sysinfo, settings.lastconnect, settings.networking, settings.nodes); process.exit(); }
1654
}
1655
break;
1656
}
1657
case 'getnetworkinfo': {
1658
if (settings.cmd == 'deviceinfo') {
1659
settings.networking = (data.result) ? null : data;
1664
- if (--settings.deviceinfocount == 0) { displayDeviceInfo(settings.sysinfo, settings.lastconnect, settings.networking); process.exit(); }
1660
+ if (--settings.deviceinfocount == 0) { displayDeviceInfo(settings.sysinfo, settings.lastconnect, settings.networking, settings.nodes); process.exit(); }
1661
}
1662
break;
1663
}
@@ -1791,6 +1787,10 @@ function serverConnect() {
1787
break;
1788
}
1789
case 'nodes': {
1790
+ if (settings.cmd == 'deviceinfo') {
1791
+ settings.nodes = (data.result) ? null : data;
1792
+ if (--settings.deviceinfocount == 0) { displayDeviceInfo(settings.sysinfo, settings.lastconnect, settings.networking, settings.nodes); process.exit(); }
1793
+ }
1794
if ((settings.cmd == 'listdevices') && (data.responseid == 'meshctrl')) {
1795
if ((data.result != null) && (data.result != 'ok')) {
1796
console.log(data.result);
@@ -2075,18 +2075,37 @@ function csvFormatArray(x) {
2075
return y.join(',');
2076
}
2077
2078
-function displayDeviceInfo(sysinfo, lastconnect, network) {
2079
- var node = sysinfo.node;
2080
- var hardware = sysinfo.hardware;
2078
+function displayDeviceInfo(sysinfo, lastconnect, network, nodes) {
2079
+ //console.log('displayDeviceInfo', sysinfo, lastconnect, network, nodes);
2080
+
2081
+ // Fetch the node information
2082
+ var node = null;;
2083
+ if (sysinfo != null && (sysinfo.node != null)) {
2084
+ // Node information came with system information
2085
+ node = sysinfo.node;
2086
+ } else {
2087
+ // This device does not have system information, get node information from the nodes list.
2088
+ for (var m in nodes.nodes) {
2089
+ for (var n in nodes.nodes[m]) {
2090
+ if (nodes.nodes[m][n]._id.indexOf(args.id) >= 0) { node = nodes.nodes[m][n]; }
2091
+ }
2092
+ }
2093
+ }
2094
+ if (node == null) {
2095
+ console.log("Invalid device id");
2096
+ process.exit(); return;
2097
+ }
2098
+
2099
var info = {};
2100
2083
- if (network != null) { sysinfo.netif = network.netif; }
2101
+ //if (network != null) { sysinfo.netif = network.netif; }
2102
if (lastconnect != null) { node.lastconnect = lastconnect.time; node.lastaddr = lastconnect.addr; }
2103
if (args.raw) { console.log(JSON.stringify(sysinfo, ' ', 2)); return; }
2104
2105
// General
2106
var output = {}, outputCount = 0;
2089
- if (node.rname) { output["Server Name"] = node.name; outputCount++; }
2107
+ if (node.name) { output["Server Name"] = node.name; outputCount++; }
2108
+ if (node.rname) { output["Computer Name"] = node.rname; outputCount++; }
2109
if (node.host != null) { output["Hostname"] = node.host; outputCount++; }
2110
if (node.ip != null) { output["IP Address"] = node.ip; outputCount++; }
2111
if (node.desc != null) { output["Description"] = node.desc; outputCount++; }
@@ -2106,14 +2125,19 @@ function displayDeviceInfo(sysinfo, lastconnect, network) {
2125
}
2126
output["AntiVirus"] = av; outputCount++;
2127
}
2128
+ if (typeof node.wsc == 'object') {
2129
+ output["WindowsSecurityCenter"] = node.wsc; outputCount++;
2130
+ }
2131
if (outputCount > 0) { info["General"] = output; }
2132
2133
// Operating System
2112
- if ((hardware.windows && hardware.windows.osinfo) || node.osdesc) {
2134
+ var hardware = null;
2135
+ if ((sysinfo != null) && (sysinfo.hardware != null)) { hardware = sysinfo.hardware; }
2136
+ if ((hardware && hardware.windows && hardware.windows.osinfo) || node.osdesc) {
2137
var output = {}, outputCount = 0;
2138
if (node.rname) { output["Name"] = node.rname; outputCount++; }
2139
if (node.osdesc) { output["Version"] = node.osdesc; outputCount++; }
2116
- if (hardware.windows && hardware.windows.osinfo) { var m = hardware.windows.osinfo; if (m.OSArchitecture) { output["Architecture"] = m.OSArchitecture; outputCount++; } }
2140
+ if (hardware && hardware.windows && hardware.windows.osinfo) { var m = hardware.windows.osinfo; if (m.OSArchitecture) { output["Architecture"] = m.OSArchitecture; outputCount++; } }
2141
if (outputCount > 0) { info["Operating System"] = output; }
2142
}
2143
@@ -2180,52 +2204,54 @@ function displayDeviceInfo(sysinfo, lastconnect, network) {
2204
if (outputCount > 0) { info["Intel Active Management Technology (Intel AMT)"] = output; }
2205
}
2206
2183
- if (hardware.identifiers) {
2184
- var output = {}, outputCount = 0, ident = hardware.identifiers;
2185
- // BIOS
2186
- if (ident.bios_vendor) { output["Vendor"] = ident.bios_vendor; outputCount++; }
2187
- if (ident.bios_version) { output["Version"] = ident.bios_version; outputCount++; }
2188
- if (outputCount > 0) { info["BIOS"] = output; }
2189
- output = {}, outputCount = 0;
2190
-
2191
- // Motherboard
2192
- if (ident.board_vendor) { output["Vendor"] = ident.board_vendor; outputCount++; }
2193
- if (ident.board_name) { output["Name"] = ident.board_name; outputCount++; }
2194
- if (ident.board_serial && (ident.board_serial != '')) { output["Serial"] = ident.board_serial; outputCount++; }
2195
- if (ident.board_version) { output["Version"] = ident.board_version; }
2196
- if (ident.product_uuid) { output["Identifier"] = ident.product_uuid; }
2197
- if (ident.cpu_name) { output["CPU"] = ident.cpu_name; }
2198
- if (ident.gpu_name) { for (var i in ident.gpu_name) { output["GPU" + (parseInt(i) + 1)] = ident.gpu_name[i]; } }
2199
- if (outputCount > 0) { info["Motherboard"] = output; }
2200
- }
2207
+ if (hardware != null) {
2208
+ if (hardware.identifiers) {
2209
+ var output = {}, outputCount = 0, ident = hardware.identifiers;
2210
+ // BIOS
2211
+ if (ident.bios_vendor) { output["Vendor"] = ident.bios_vendor; outputCount++; }
2212
+ if (ident.bios_version) { output["Version"] = ident.bios_version; outputCount++; }
2213
+ if (outputCount > 0) { info["BIOS"] = output; }
2214
+ output = {}, outputCount = 0;
2215
2202
- // Memory
2203
- if (hardware.windows) {
2204
- if (hardware.windows.memory) {
2205
- var output = {}, outputCount = 0, minfo = {};
2206
- hardware.windows.memory.sort(function (a, b) { if (a.BankLabel > b.BankLabel) return 1; if (a.BankLabel < b.BankLabel) return -1; return 0; });
2207
- for (var i in hardware.windows.memory) {
2208
- var m = hardware.windows.memory[i], moutput = {}, moutputCount = 0;
2209
- if (m.Capacity) { moutput["Capacity/Speed"] = (m.Capacity / 1024 / 1024) + " Mb, " + m.Speed + " Mhz"; moutputCount++; }
2210
- if (m.PartNumber) { moutput["Part Number"] = ((m.Manufacturer && m.Manufacturer != 'Undefined') ? (m.Manufacturer + ', ') : '') + m.PartNumber; moutputCount++; }
2211
- if (moutputCount > 0) { minfo[m.BankLabel] = moutput; info["Memory"] = minfo; }
2216
+ // Motherboard
2217
+ if (ident.board_vendor) { output["Vendor"] = ident.board_vendor; outputCount++; }
2218
+ if (ident.board_name) { output["Name"] = ident.board_name; outputCount++; }
2219
+ if (ident.board_serial && (ident.board_serial != '')) { output["Serial"] = ident.board_serial; outputCount++; }
2220
+ if (ident.board_version) { output["Version"] = ident.board_version; }
2221
+ if (ident.product_uuid) { output["Identifier"] = ident.product_uuid; }
2222
+ if (ident.cpu_name) { output["CPU"] = ident.cpu_name; }
2223
+ if (ident.gpu_name) { for (var i in ident.gpu_name) { output["GPU" + (parseInt(i) + 1)] = ident.gpu_name[i]; } }
2224
+ if (outputCount > 0) { info["Motherboard"] = output; }
2225
+ }
2226
+
2227
+ // Memory
2228
+ if (hardware.windows) {
2229
+ if (hardware.windows.memory) {
2230
+ var output = {}, outputCount = 0, minfo = {};
2231
+ hardware.windows.memory.sort(function (a, b) { if (a.BankLabel > b.BankLabel) return 1; if (a.BankLabel < b.BankLabel) return -1; return 0; });
2232
+ for (var i in hardware.windows.memory) {
2233
+ var m = hardware.windows.memory[i], moutput = {}, moutputCount = 0;
2234
+ if (m.Capacity) { moutput["Capacity/Speed"] = (m.Capacity / 1024 / 1024) + " Mb, " + m.Speed + " Mhz"; moutputCount++; }
2235
+ if (m.PartNumber) { moutput["Part Number"] = ((m.Manufacturer && m.Manufacturer != 'Undefined') ? (m.Manufacturer + ', ') : '') + m.PartNumber; moutputCount++; }
2236
+ if (moutputCount > 0) { minfo[m.BankLabel] = moutput; info["Memory"] = minfo; }
2237
+ }
2238
}
2239
}
2214
- }
2240
2216
- // Storage
2217
- if (hardware.identifiers && ident.storage_devices) {
2218
- var output = {}, outputCount = 0, minfo = {};
2219
- // Sort Storage
2220
- ident.storage_devices.sort(function (a, b) { if (a.Caption > b.Caption) return 1; if (a.Caption < b.Caption) return -1; return 0; });
2221
- for (var i in ident.storage_devices) {
2222
- var m = ident.storage_devices[i], moutput = {};
2223
- if (m.Size) {
2224
- if (m.Model && (m.Model != m.Caption)) { moutput["Model"] = m.Model; outputCount++; }
2225
- if ((typeof m.Size == 'string') && (parseInt(m.Size) == m.Size)) { m.Size = parseInt(m.Size); }
2226
- if (typeof m.Size == 'number') { moutput["Capacity"] = Math.floor(m.Size / 1024 / 1024) + 'Mb'; outputCount++; }
2227
- if (typeof m.Size == 'string') { moutput["Capacity"] = m.Size; outputCount++; }
2228
- if (moutputCount > 0) { minfo[m.Caption] = moutput; info["Storage"] = minfo; }
2241
+ // Storage
2242
+ if (hardware.identifiers && ident.storage_devices) {
2243
+ var output = {}, outputCount = 0, minfo = {};
2244
+ // Sort Storage
2245
+ ident.storage_devices.sort(function (a, b) { if (a.Caption > b.Caption) return 1; if (a.Caption < b.Caption) return -1; return 0; });
2246
+ for (var i in ident.storage_devices) {
2247
+ var m = ident.storage_devices[i], moutput = {};
2248
+ if (m.Size) {
2249
+ if (m.Model && (m.Model != m.Caption)) { moutput["Model"] = m.Model; outputCount++; }
2250
+ if ((typeof m.Size == 'string') && (parseInt(m.Size) == m.Size)) { m.Size = parseInt(m.Size); }
2251
+ if (typeof m.Size == 'number') { moutput["Capacity"] = Math.floor(m.Size / 1024 / 1024) + 'Mb'; outputCount++; }
2252
+ if (typeof m.Size == 'string') { moutput["Capacity"] = m.Size; outputCount++; }
2253
+ if (moutputCount > 0) { minfo[m.Caption] = moutput; info["Storage"] = minfo; }
2254
+ }
2255
}
2256
}
2257
}