always show operating system section and LastBootUpTime fix

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Sep 15, 2024 at 23:02 UTC 7172d1f7017384f0e26f64f11b0c7e1eaf86c996
3 files changed +118 -111
agents/modules_meshcore/computer-identifiers.js
+12 -1
@@ -364,7 +364,18 @@ function linux_identifiers()
364 child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
365 child.stderr.on('data', function () { });
366 child.waitExit();
367 - values.linux.LastBootUpTime = child.stdout.str.trim();
367 + var regex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/;
368 + if (regex.test(child.stdout.str.trim())) {
369 + values.linux.LastBootUpTime = child.stdout.str.trim();
370 + } else {
371 + child = require('child_process').execFile('/bin/sh', ['sh']);
372 + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
373 + child.stdin.write('date -d "@$(( $(date +%s) - $(awk \'{print int($1)}\' /proc/uptime) ))" "+%Y-%m-%d %H:%M:%S"\nexit\n');
374 + child.waitExit();
375 + if (regex.test(child.stdout.str.trim())) {
376 + values.linux.LastBootUpTime = child.stdout.str.trim();
377 + }
378 + }
379 child = null;
380 } catch (ex) { }
381
views/default-mobile.handlebars
+75 -77
@@ -6152,92 +6152,90 @@
6152 var sections = [], s = {};
6153
6154 // Operating System
6155 - if ((hardware.windows && hardware.windows.osinfo) || node.osdesc) {
6156 - var x = '';
6157 - if (node.rname) { x += addDetailItem("Name", EscapeHtml(node.rname), s); }
6158 - if (node.osdesc) { x += addDetailItem("Version", EscapeHtml(node.osdesc), s); }
6159 - if (hardware.windows && hardware.windows.osinfo) {
6160 - var m = hardware.windows.osinfo;
6161 - if (m.OSArchitecture) {
6162 - if (m.OSArchitecture.startsWith('32')) { x += addDetailItem("Architecture", "32-bit", s); }
6163 - else if (m.OSArchitecture.startsWith('64')) { x += addDetailItem("Architecture", "64-bit", s); }
6164 - else { x += addDetailItem("Architecture", EscapeHtml(m.OSArchitecture), s); }
6165 - }
6166 - if(m.LastBootUpTime){
6167 - var thedate = {
6168 - year: parseInt(m.LastBootUpTime.substring(0, 4)),
6169 - month: parseInt(m.LastBootUpTime.substring(4, 6)) - 1, // Months are 0-based in JavaScript (0 - January, 11 - December)
6170 - day: parseInt(m.LastBootUpTime.substring(6, 8)),
6171 - hours: parseInt(m.LastBootUpTime.substring(8, 10)),
6172 - minutes: parseInt(m.LastBootUpTime.substring(10, 12)),
6173 - seconds: parseInt(m.LastBootUpTime.substring(12, 14)),
6174 - };
6175 - const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
6176 - x += addDetailItem("Last Boot Up Time", date);
6177 - }
6178 - }
6179 - if(hardware.linux && hardware.linux.LastBootUpTime){
6180 - var lastBootUpTime = new Date(hardware.linux.LastBootUpTime);
6181 - var thedate = {
6182 - year: lastBootUpTime.getFullYear(),
6183 - month: lastBootUpTime.getMonth(),
6184 - day: lastBootUpTime.getDate(),
6185 - hours: lastBootUpTime.getHours(),
6186 - minutes: lastBootUpTime.getMinutes(),
6187 - seconds: lastBootUpTime.getSeconds()
6188 - };
6189 - const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
6190 - x += addDetailItem("Last Boot Up Time", date);
6191 - }
6192 - if(hardware.darwin && hardware.darwin.LastBootUpTime){
6193 - var lastBootUpTime = new Date(hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
6155 + var x = '';
6156 + if (node.rname) { x += addDetailItem("Name", EscapeHtml(node.rname), s); }
6157 + if (node.osdesc) { x += addDetailItem("Version", EscapeHtml(node.osdesc), s); }
6158 + if (hardware.windows && hardware.windows.osinfo) {
6159 + var m = hardware.windows.osinfo;
6160 + if (m.OSArchitecture) {
6161 + if (m.OSArchitecture.startsWith('32')) { x += addDetailItem("Architecture", "32-bit", s); }
6162 + else if (m.OSArchitecture.startsWith('64')) { x += addDetailItem("Architecture", "64-bit", s); }
6163 + else { x += addDetailItem("Architecture", EscapeHtml(m.OSArchitecture), s); }
6164 + }
6165 + if(m.LastBootUpTime){
6166 var thedate = {
6195 - year: lastBootUpTime.getFullYear(),
6196 - month: lastBootUpTime.getMonth(),
6197 - day: lastBootUpTime.getDate(),
6198 - hours: lastBootUpTime.getHours(),
6199 - minutes: lastBootUpTime.getMinutes(),
6200 - seconds: lastBootUpTime.getSeconds()
6167 + year: parseInt(m.LastBootUpTime.substring(0, 4)),
6168 + month: parseInt(m.LastBootUpTime.substring(4, 6)) - 1, // Months are 0-based in JavaScript (0 - January, 11 - December)
6169 + day: parseInt(m.LastBootUpTime.substring(6, 8)),
6170 + hours: parseInt(m.LastBootUpTime.substring(8, 10)),
6171 + minutes: parseInt(m.LastBootUpTime.substring(10, 12)),
6172 + seconds: parseInt(m.LastBootUpTime.substring(12, 14)),
6173 };
6174 const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
6175 x += addDetailItem("Last Boot Up Time", date);
6176 }
6205 -
6206 - // Windows Security Central
6207 - if (node.wsc) {
6208 - var y = [];
6209 - if (node.wsc.antiVirus != null) { if (node.wsc.antiVirus == 'OK') { y.push("AV" + ' - <span style=color:green>' + "OK" + '</span>'); } else { y.push("AV" + ' - <span style=color:red>' + "BAD" + '</span>'); } }
6210 - if (node.wsc.autoUpdate != null) { if (node.wsc.autoUpdate == 'OK') { y.push("Update" + ' - <span style=color:green>' + "OK" + '</span>'); } else { y.push("Update" + ' - <span style=color:red>' + "BAD" + '</span>'); } }
6211 - if (node.wsc.firewall != null) { if (node.wsc.firewall == 'OK') { y.push("Firewall" + ' - <span style=color:green>' + "OK" + '</span>'); } else { y.push("Firewall" + ' - <span style=color:red>' + "BAD" + '</span>'); } }
6212 - x += addDetailItem("Windows Security", y.join(', '));
6213 - }
6214 -
6215 - // Defender for Windows Server
6216 - if(node.defender && !node.wsc) {
6217 - var y = [];
6218 - if (node.defender.RealTimeProtection != null) { if (node.defender.RealTimeProtection == true) { y.push("RealTimeProtection" + ' - <span style=color:green>' + "On" + '</span>'); } else { y.push("RealTimeProtection" + ' - <span style=color:red>' + "Off" + '</span>'); } }
6219 - if (node.defender.TamperProtected != null) { if (node.defender.TamperProtected == true) { y.push("TamperProtection" + ' - <span style=color:green>' + "On" + '</span>'); } else { y.push("TamperProtection" + ' - <span style=color:red>' + "Off" + '</span>'); } }
6220 - x += addDetailItem("Windows Defender", y.join(', '));
6221 - }
6222 -
6223 - // Antivirus
6224 - if (node.av && node.av.length > 0) {
6225 - var y = [];
6226 - for (var i in node.av) {
6227 - if (node.av[i].product) {
6228 - var avx = EscapeHtml(node.av[i].product);
6229 - if (node.av[i].enabled !== true) { avx += ' - <span style=color:red>' + "Disabled" + '</span>'; }
6230 - if (node.av[i].updated !== true) { avx += ' - <span style=color:red>' + "Out of date" + '</span>'; }
6231 - if ((node.av[i].enabled == true) && (node.av[i].updated == true)) { avx += ' - <span style=color:green>' + "OK" + '</span>'; }
6232 - y.push(avx);
6233 - }
6177 + }
6178 + if(hardware.linux && hardware.linux.LastBootUpTime){
6179 + var lastBootUpTime = new Date(hardware.linux.LastBootUpTime);
6180 + var thedate = {
6181 + year: lastBootUpTime.getFullYear(),
6182 + month: lastBootUpTime.getMonth(),
6183 + day: lastBootUpTime.getDate(),
6184 + hours: lastBootUpTime.getHours(),
6185 + minutes: lastBootUpTime.getMinutes(),
6186 + seconds: lastBootUpTime.getSeconds()
6187 + };
6188 + const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
6189 + x += addDetailItem("Last Boot Up Time", date);
6190 + }
6191 + if(hardware.darwin && hardware.darwin.LastBootUpTime){
6192 + var lastBootUpTime = new Date(hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
6193 + var thedate = {
6194 + year: lastBootUpTime.getFullYear(),
6195 + month: lastBootUpTime.getMonth(),
6196 + day: lastBootUpTime.getDate(),
6197 + hours: lastBootUpTime.getHours(),
6198 + minutes: lastBootUpTime.getMinutes(),
6199 + seconds: lastBootUpTime.getSeconds()
6200 + };
6201 + const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
6202 + x += addDetailItem("Last Boot Up Time", date);
6203 + }
6204 +
6205 + // Windows Security Central
6206 + if (node.wsc) {
6207 + var y = [];
6208 + if (node.wsc.antiVirus != null) { if (node.wsc.antiVirus == 'OK') { y.push("AV" + ' - <span style=color:green>' + "OK" + '</span>'); } else { y.push("AV" + ' - <span style=color:red>' + "BAD" + '</span>'); } }
6209 + if (node.wsc.autoUpdate != null) { if (node.wsc.autoUpdate == 'OK') { y.push("Update" + ' - <span style=color:green>' + "OK" + '</span>'); } else { y.push("Update" + ' - <span style=color:red>' + "BAD" + '</span>'); } }
6210 + if (node.wsc.firewall != null) { if (node.wsc.firewall == 'OK') { y.push("Firewall" + ' - <span style=color:green>' + "OK" + '</span>'); } else { y.push("Firewall" + ' - <span style=color:red>' + "BAD" + '</span>'); } }
6211 + x += addDetailItem("Windows Security", y.join(', '));
6212 + }
6213 +
6214 + // Defender for Windows Server
6215 + if(node.defender && !node.wsc) {
6216 + var y = [];
6217 + if (node.defender.RealTimeProtection != null) { if (node.defender.RealTimeProtection == true) { y.push("RealTimeProtection" + ' - <span style=color:green>' + "On" + '</span>'); } else { y.push("RealTimeProtection" + ' - <span style=color:red>' + "Off" + '</span>'); } }
6218 + if (node.defender.TamperProtected != null) { if (node.defender.TamperProtected == true) { y.push("TamperProtection" + ' - <span style=color:green>' + "On" + '</span>'); } else { y.push("TamperProtection" + ' - <span style=color:red>' + "Off" + '</span>'); } }
6219 + x += addDetailItem("Windows Defender", y.join(', '));
6220 + }
6221 +
6222 + // Antivirus
6223 + if (node.av && node.av.length > 0) {
6224 + var y = [];
6225 + for (var i in node.av) {
6226 + if (node.av[i].product) {
6227 + var avx = EscapeHtml(node.av[i].product);
6228 + if (node.av[i].enabled !== true) { avx += ' - <span style=color:red>' + "Disabled" + '</span>'; }
6229 + if (node.av[i].updated !== true) { avx += ' - <span style=color:red>' + "Out of date" + '</span>'; }
6230 + if ((node.av[i].enabled == true) && (node.av[i].updated == true)) { avx += ' - <span style=color:green>' + "OK" + '</span>'; }
6231 + y.push(avx);
6232 }
6235 - x += addDetailItem("Antivirus", y.join('<br />'));
6233 }
6237 -
6238 - if (x != '') { sections.push({ name: "Operating System", html: x, img: 'software' }); }
6234 + x += addDetailItem("Antivirus", y.join('<br />'));
6235 }
6236
6237 + if (x != '') { sections.push({ name: "Operating System", html: x, img: 'software' }); }
6238 +
6239 // MeshAgent
6240 if (node.agent) {
6241 var x = '';
views/default.handlebars
+31 -33
@@ -12018,42 +12018,40 @@
12018 var sections = [], s = {};
12019
12020 // Operating System
12021 - if ((hardware.windows && hardware.windows.osinfo) || node.osdesc) {
12022 - var x = '';
12023 - if (node.rname) { x += addDetailItem("Name", EscapeHtml(node.rname), s); }
12024 - if (node.osdesc) { x += addDetailItem("Version", EscapeHtml(node.osdesc), s); }
12025 - if (hardware.windows && hardware.windows.osinfo) {
12026 - var m = hardware.windows.osinfo;
12027 - if (m.OSArchitecture) {
12028 - if (m.OSArchitecture.startsWith('32')) { x += addDetailItem("Architecture", "32-bit", s); }
12029 - else if (m.OSArchitecture.startsWith('64')) { x += addDetailItem("Architecture", "64-bit", s); }
12030 - else { x += addDetailItem("Architecture", EscapeHtml(m.OSArchitecture), s); }
12031 - }
12032 - if(m.LastBootUpTime){
12033 - var thedate = {
12034 - year: parseInt(m.LastBootUpTime.substring(0, 4)),
12035 - month: parseInt(m.LastBootUpTime.substring(4, 6)) - 1, // Months are 0-based in JavaScript (0 - January, 11 - December)
12036 - day: parseInt(m.LastBootUpTime.substring(6, 8)),
12037 - hours: parseInt(m.LastBootUpTime.substring(8, 10)),
12038 - minutes: parseInt(m.LastBootUpTime.substring(10, 12)),
12039 - seconds: parseInt(m.LastBootUpTime.substring(12, 14)),
12040 - };
12041 - const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
12042 - x += addDetailItem("Last Boot Up Time", date);
12043 - }
12044 - }
12045 - if(hardware.linux && hardware.linux.LastBootUpTime){
12046 - var lastBootUpTime = new Date(hardware.linux.LastBootUpTime);
12047 - const date = printDateTime(lastBootUpTime);
12048 - x += addDetailItem("Last Boot Up Time", date);
12049 - }
12050 - if(hardware.darwin && hardware.darwin.LastBootUpTime){
12051 - var lastBootUpTime = new Date(hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
12052 - const date = printDateTime(lastBootUpTime);
12021 + var x = '';
12022 + if (node.rname) { x += addDetailItem("Name", EscapeHtml(node.rname), s); }
12023 + if (node.osdesc) { x += addDetailItem("Version", EscapeHtml(node.osdesc), s); }
12024 + if (hardware.windows && hardware.windows.osinfo) {
12025 + var m = hardware.windows.osinfo;
12026 + if (m.OSArchitecture) {
12027 + if (m.OSArchitecture.startsWith('32')) { x += addDetailItem("Architecture", "32-bit", s); }
12028 + else if (m.OSArchitecture.startsWith('64')) { x += addDetailItem("Architecture", "64-bit", s); }
12029 + else { x += addDetailItem("Architecture", EscapeHtml(m.OSArchitecture), s); }
12030 + }
12031 + if(m.LastBootUpTime){
12032 + var thedate = {
12033 + year: parseInt(m.LastBootUpTime.substring(0, 4)),
12034 + month: parseInt(m.LastBootUpTime.substring(4, 6)) - 1, // Months are 0-based in JavaScript (0 - January, 11 - December)
12035 + day: parseInt(m.LastBootUpTime.substring(6, 8)),
12036 + hours: parseInt(m.LastBootUpTime.substring(8, 10)),
12037 + minutes: parseInt(m.LastBootUpTime.substring(10, 12)),
12038 + seconds: parseInt(m.LastBootUpTime.substring(12, 14)),
12039 + };
12040 + const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
12041 x += addDetailItem("Last Boot Up Time", date);
12042 }
12055 - if (x != '') { sections.push({ name: "Operating System", html: x, img: 'software64.png'}); }
12043 }
12044 + if(hardware.linux && hardware.linux.LastBootUpTime){
12045 + var lastBootUpTime = new Date(hardware.linux.LastBootUpTime);
12046 + const date = printDateTime(lastBootUpTime);
12047 + x += addDetailItem("Last Boot Up Time", date);
12048 + }
12049 + if(hardware.darwin && hardware.darwin.LastBootUpTime){
12050 + var lastBootUpTime = new Date(hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
12051 + const date = printDateTime(lastBootUpTime);
12052 + x += addDetailItem("Last Boot Up Time", date);
12053 + }
12054 + if (x != '') { sections.push({ name: "Operating System", html: x, img: 'software64.png'}); }
12055
12056 // MeshAgent
12057 if (node.agent) {