add lastbootuptime to columns and device powered on event (#5999)

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
Simon Smith 2024-04-07 19:12:01 +01:00 committed by GitHub
parent 31ebb21e0b
commit 548edd13d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 3075 additions and 3070 deletions

View File

@ -1883,85 +1883,48 @@ function getSystemInformation(func) {
if (results.hardware.windows.osinfo) { delete results.hardware.windows.osinfo.Node; } if (results.hardware.windows.osinfo) { delete results.hardware.windows.osinfo.Node; }
if (results.hardware.windows.partitions) { for (var i in results.hardware.windows.partitions) { delete results.hardware.windows.partitions[i].Node; } } if (results.hardware.windows.partitions) { for (var i in results.hardware.windows.partitions) { delete results.hardware.windows.partitions[i].Node; } }
} catch (ex) { } } catch (ex) { }
if (!results.hardware.identifiers['bios_serial']) { if (x.LastBootUpTime) { // detect windows uptime
try { var thedate = {
var values = require('win-wmi').query('ROOT\\CIMV2', "SELECT * FROM Win32_Bios", ['SerialNumber']); year: parseInt(x.LastBootUpTime.substring(0, 4)),
results.hardware.identifiers['bios_serial'] = values[0]['SerialNumber']; month: parseInt(x.LastBootUpTime.substring(4, 6)) - 1, // Months are 0-based in JavaScript (0 - January, 11 - December)
} catch (ex) { } day: parseInt(x.LastBootUpTime.substring(6, 8)),
hours: parseInt(x.LastBootUpTime.substring(8, 10)),
minutes: parseInt(x.LastBootUpTime.substring(10, 12)),
seconds: parseInt(x.LastBootUpTime.substring(12, 14)),
};
var thelastbootuptime = new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds);
meshCoreObj.lastbootuptime = thelastbootuptime.getTime(); // store the last boot up time in coreinfo for columns
meshCoreObjChanged();
var nowtime = new Date();
var differenceInMilliseconds = Math.abs(thelastbootuptime - nowtime);
if (differenceInMilliseconds < 300000) { // computer uptime less than 5 minutes
MeshServerLogEx(159, [thelastbootuptime.toString()], "Device Powered On", null);
} }
if (!results.hardware.identifiers['bios_mode']) {
try {
results.hardware.identifiers['bios_mode'] = 'Legacy';
for (var i in results.hardware.windows.partitions) {
if (results.hardware.windows.partitions[i].Description=='GPT: System') {
results.hardware.identifiers['bios_mode'] = 'UEFI';
}
}
} catch (ex) { results.hardware.identifiers['bios_mode'] = 'Legacy'; }
}
if (!results.hardware.tpm) {
IntToStr = function (v) { return String.fromCharCode((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF); };
try {
var values = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftTpm', "SELECT * FROM Win32_Tpm", ['IsActivated_InitialValue','IsEnabled_InitialValue','IsOwned_InitialValue','ManufacturerId','ManufacturerVersion','SpecVersion']);
if(values[0]) {
results.hardware.tpm = {
SpecVersion: values[0].SpecVersion.split(",")[0],
ManufacturerId: IntToStr(values[0].ManufacturerId).replace(/[^\x00-\x7F]/g, ""),
ManufacturerVersion: values[0].ManufacturerVersion,
IsActivated: values[0].IsActivated_InitialValue,
IsEnabled: values[0].IsEnabled_InitialValue,
IsOwned: values[0].IsOwned_InitialValue,
}
}
} catch (ex) { }
} }
} }
if(results.hardware && results.hardware.linux) { if(results.hardware && results.hardware.linux) {
if (!results.hardware.identifiers['bios_serial']) { if(results.hardware.linux.LastBootUpTime) {
try { var thelastbootuptime = new Date(results.hardware.linux.LastBootUpTime);
if (require('fs').statSync('/sys/class/dmi/id/product_serial').isFile()){ meshCoreObj.lastbootuptime = thelastbootuptime.getTime(); // store the last boot up time in coreinfo for columns
results.hardware.identifiers['bios_serial'] = require('fs').readFileSync('/sys/class/dmi/id/product_serial').toString().trim(); meshCoreObjChanged();
} var nowtime = new Date();
} catch (ex) { } var differenceInMilliseconds = Math.abs(thelastbootuptime - nowtime);
} if (differenceInMilliseconds < 300000) { // computer uptime less than 5 minutes
if (!results.hardware.identifiers['bios_mode']) { MeshServerLogEx(159, [thelastbootuptime.toString()], "Device Powered On", null);
try {
results.hardware.identifiers['bios_mode'] = (require('fs').statSync('/sys/firmware/efi').isDirectory() ? 'UEFI': 'Legacy');
} catch (ex) { results.hardware.identifiers['bios_mode'] = 'Legacy'; }
}
if (!results.hardware.tpm) {
IntToStr = function (v) { return String.fromCharCode((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF); };
try {
if (require('fs').statSync('/sys/class/tpm/tpm0').isDirectory()){
results.hardware.tpm = {
SpecVersion: require('fs').readFileSync('/sys/class/tpm/tpm0/tpm_version_major').toString().trim()
} }
} }
} catch (ex) { }
} }
if(!results.hardware.linux.LastBootUpTime) { if(results.hardware && results.hardware.darwin){
try { if(results.hardware.darwin.LastBootUpTime) {
var child = require('child_process').execFile('/usr/bin/uptime', ['', '-s']); // must include blank value at begining for some reason? var thelastbootuptime = new Date(results.hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); meshCoreObj.lastbootuptime = thelastbootuptime.getTime(); // store the last boot up time in coreinfo for columns
child.stderr.on('data', function () { }); meshCoreObjChanged();
child.waitExit(); var nowtime = new Date();
results.hardware.linux.LastBootUpTime = child.stdout.str.trim(); var differenceInMilliseconds = Math.abs(thelastbootuptime - nowtime);
} catch (ex) { } if (differenceInMilliseconds < 300000) { // computer uptime less than 5 minutes
MeshServerLogEx(159, [thelastbootuptime.toString()], "Device Powered On", null);
} }
} }
if(process.platform=='darwin'){
try {
var child = require('child_process').execFile('/usr/sbin/sysctl', ['', 'kern.boottime']); // must include blank value at begining for some reason?
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.on('data', function () { });
child.waitExit();
const timestampMatch = /\{ sec = (\d+), usec = \d+ \}/.exec(child.stdout.str.trim());
if(!results.hardware.darwin){
results.hardware.darwin = { LastBootUpTime: parseInt(timestampMatch[1]) };
}else{
results.hardware.darwin.LastBootUpTime = parseInt(timestampMatch[1]);
}
} catch (ex) { }
} }
results.hardware.agentvers = process.versions; results.hardware.agentvers = process.versions;
results.hardware.network = { dns: require('os').dns() }; results.hardware.network = { dns: require('os').dns() };

View File

@ -83,17 +83,11 @@ function linux_identifiers()
} }
} else { } else {
var entries = require('fs').readdirSync('/sys/class/dmi/id'); var entries = require('fs').readdirSync('/sys/class/dmi/id');
for(var i in entries) for (var i in entries) {
{ if (require('fs').statSync('/sys/class/dmi/id/' + entries[i]).isFile()) {
if (require('fs').statSync('/sys/class/dmi/id/' + entries[i]).isFile()) try {
{
try
{
ret[entries[i]] = require('fs').readFileSync('/sys/class/dmi/id/' + entries[i]).toString().trim(); ret[entries[i]] = require('fs').readFileSync('/sys/class/dmi/id/' + entries[i]).toString().trim();
} } catch(z) { }
catch(z)
{
}
if (ret[entries[i]] == 'None') { delete ret[entries[i]]; } if (ret[entries[i]] == 'None') { delete ret[entries[i]]; }
} }
} }
@ -343,6 +337,25 @@ function linux_identifiers()
child = null; child = null;
} }
// Linux Last Boot Up Time
try {
child = require('child_process').execFile('/usr/bin/uptime', ['', '-s']); // must include blank value at begining for some reason?
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.on('data', function () { });
child.waitExit();
values.linux.LastBootUpTime = child.stdout.str.trim();
child = null;
} catch (ex) { }
// Linux TPM
try {
if (require('fs').statSync('/sys/class/tpm/tpm0').isDirectory()){
values.tpm = {
SpecVersion: require('fs').readFileSync('/sys/class/tpm/tpm0/tpm_version_major').toString().trim()
}
}
} catch (ex) { }
return (values); return (values);
} }
@ -559,6 +572,23 @@ function windows_identifiers()
} }
try { ret.identifiers.cpu_name = ret.windows.cpu[0].Name; } catch (x) { } try { ret.identifiers.cpu_name = ret.windows.cpu[0].Name; } catch (x) { }
// Windows TPM
IntToStr = function (v) { return String.fromCharCode((v >> 24) & 0xFF, (v >> 16) & 0xFF, (v >> 8) & 0xFF, v & 0xFF); };
try {
values = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftTpm', "SELECT * FROM Win32_Tpm", ['IsActivated_InitialValue','IsEnabled_InitialValue','IsOwned_InitialValue','ManufacturerId','ManufacturerVersion','SpecVersion']);
if(values[0]) {
ret.tpm = {
SpecVersion: values[0].SpecVersion.split(",")[0],
ManufacturerId: IntToStr(values[0].ManufacturerId).replace(/[^\x00-\x7F]/g, ""),
ManufacturerVersion: values[0].ManufacturerVersion,
IsActivated: values[0].IsActivated_InitialValue,
IsEnabled: values[0].IsEnabled_InitialValue,
IsOwned: values[0].IsOwned_InitialValue,
}
}
} catch (ex) { }
return (ret); return (ret);
} }
function macos_identifiers() function macos_identifiers()
@ -674,6 +704,21 @@ function macos_identifiers()
ret.identifiers.storage_devices = devices; ret.identifiers.storage_devices = devices;
} }
// MacOS Last Boot Up Time
try {
child = require('child_process').execFile('/usr/sbin/sysctl', ['', 'kern.boottime']); // must include blank value at begining for some reason?
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.on('data', function () { });
child.waitExit();
const timestampMatch = /\{ sec = (\d+), usec = \d+ \}/.exec(child.stdout.str.trim());
if (!ret.darwin) {
ret.darwin = { LastBootUpTime: parseInt(timestampMatch[1]) };
} else {
ret.darwin.LastBootUpTime = parseInt(timestampMatch[1]);
}
child = null;
} catch (ex) { }
trimIdentifiers(ret.identifiers); trimIdentifiers(ret.identifiers);
child = null; child = null;

View File

@ -1924,6 +1924,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
if (!device.defender) { device.defender = {}; } if (!device.defender) { device.defender = {}; }
if (JSON.stringify(device.defender) != JSON.stringify(command.defender)) { /*changes.push('Defender status');*/ device.defender = command.defender; change = 1; log = 1; } if (JSON.stringify(device.defender) != JSON.stringify(command.defender)) { /*changes.push('Defender status');*/ device.defender = command.defender; change = 1; log = 1; }
} }
if (command.lastbootuptime != null) { // Last Boot Up Time
if (!device.lastbootuptime) { device.lastbootuptime = ""; }
if (device.lastbootuptime != command.lastbootuptime) { /*changes.push('Last Boot Up Time');*/ device.lastbootuptime = command.lastbootuptime; change = 1; log = 1; }
}
// Push Messaging Token // Push Messaging Token
if ((command.pmt != null) && (typeof command.pmt == 'string') && (device.pmt != command.pmt)) { if ((command.pmt != null) && (typeof command.pmt == 'string') && (device.pmt != command.pmt)) {

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
@ -4051,6 +4051,7 @@
x += '<label><input id=d2c11 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('windowsav') >= 0)?' checked':'') + '>' + "Windows AV" + '</label><br />'; x += '<label><input id=d2c11 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('windowsav') >= 0)?' checked':'') + '>' + "Windows AV" + '</label><br />';
x += '<label><input id=d2c12 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('windowsupdate') >= 0)?' checked':'') + '>' + "Windows Update" + '</label><br />'; x += '<label><input id=d2c12 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('windowsupdate') >= 0)?' checked':'') + '>' + "Windows Update" + '</label><br />';
x += '<label><input id=d2c13 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('windowsfirewall') >= 0)?' checked':'') + '>' + "Windows Firewall" + '</label><br />'; x += '<label><input id=d2c13 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('windowsfirewall') >= 0)?' checked':'') + '>' + "Windows Firewall" + '</label><br />';
x += '<label><input id=d2c14 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('lastbootuptime') >= 0)?' checked':'') + '>' + "Last Boot Up Time" + '</label><br />';
x += '<label><input id=d2c1 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('links') >= 0)?' checked':'') + '>' + "MeshCentral Router Links" + '</label><br />'; x += '<label><input id=d2c1 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('links') >= 0)?' checked':'') + '>' + "MeshCentral Router Links" + '</label><br />';
x += '<label><input id=d2c2 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('user') >= 0)?' checked':'') + '>' + "Logged in users" + '</label><br />'; x += '<label><input id=d2c2 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('user') >= 0)?' checked':'') + '>' + "Logged in users" + '</label><br />';
x += '<label><input id=d2c3 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('ip') >= 0)?' checked':'') + '>' + "Agent IP address" + '</label><br />'; x += '<label><input id=d2c3 type=checkbox' + ((deviceViewSettings.devsCols.indexOf('ip') >= 0)?' checked':'') + '>' + "Agent IP address" + '</label><br />';
@ -4076,6 +4077,7 @@
if (Q('d2c11').checked) { cols.push('windowsav'); } if (Q('d2c11').checked) { cols.push('windowsav'); }
if (Q('d2c12').checked) { cols.push('windowsupdate'); } if (Q('d2c12').checked) { cols.push('windowsupdate'); }
if (Q('d2c13').checked) { cols.push('windowsfirewall'); } if (Q('d2c13').checked) { cols.push('windowsfirewall'); }
if (Q('d2c14').checked) { cols.push('lastbootuptime'); }
if (Q('d2c15').checked) { cols.push('amthost'); } if (Q('d2c15').checked) { cols.push('amthost'); }
if (Q('d2c17').checked) { cols.push('amtstate'); } if (Q('d2c17').checked) { cols.push('amtstate'); }
deviceViewSettings.devsCols = cols; deviceViewSettings.devsCols = cols;
@ -4518,6 +4520,7 @@
if (deviceViewSettings.devsCols.indexOf('windowsav') >= 0) { colums += '<th style=color:gray;width:100px>' + "Windows AV"; } if (deviceViewSettings.devsCols.indexOf('windowsav') >= 0) { colums += '<th style=color:gray;width:100px>' + "Windows AV"; }
if (deviceViewSettings.devsCols.indexOf('windowsupdate') >= 0) { colums += '<th style=color:gray;width:120px>' + "Windows Update"; } if (deviceViewSettings.devsCols.indexOf('windowsupdate') >= 0) { colums += '<th style=color:gray;width:120px>' + "Windows Update"; }
if (deviceViewSettings.devsCols.indexOf('windowsfirewall') >= 0) { colums += '<th style=color:gray;width:120px>' + "Windows Firewall"; } if (deviceViewSettings.devsCols.indexOf('windowsfirewall') >= 0) { colums += '<th style=color:gray;width:120px>' + "Windows Firewall"; }
if (deviceViewSettings.devsCols.indexOf('lastbootuptime') >= 0) { colums += '<th style=color:gray;width:120px>' + "Last Boot Up Time"; }
if (deviceViewSettings.devsCols.indexOf('links') >= 0) { colums += '<th style=color:gray;width:120px>' + "Links"; } if (deviceViewSettings.devsCols.indexOf('links') >= 0) { colums += '<th style=color:gray;width:120px>' + "Links"; }
if (deviceViewSettings.devsCols.indexOf('user') >= 0) { colums += '<th style=color:gray;width:120px>' + "User"; } if (deviceViewSettings.devsCols.indexOf('user') >= 0) { colums += '<th style=color:gray;width:120px>' + "User"; }
if (deviceViewSettings.devsCols.indexOf('ip') >= 0) { colums += '<th style=color:gray;width:120px>' + "Address"; } if (deviceViewSettings.devsCols.indexOf('ip') >= 0) { colums += '<th style=color:gray;width:120px>' + "Address"; }
@ -4832,6 +4835,9 @@
if (deviceViewSettings.devsCols.indexOf('windowsfirewall') >= 0) { // Windows Firewall if (deviceViewSettings.devsCols.indexOf('windowsfirewall') >= 0) { // Windows Firewall
r += '<td style=text-align:center>' + ((node.wsc && node.wsc.firewall != null) ? (node.wsc.firewall == 'OK' ? "<span style=color:green>OK</span>" : "<span style=color:red>BAD</span>") : ""); r += '<td style=text-align:center>' + ((node.wsc && node.wsc.firewall != null) ? (node.wsc.firewall == 'OK' ? "<span style=color:green>OK</span>" : "<span style=color:red>BAD</span>") : "");
} }
if (deviceViewSettings.devsCols.indexOf('lastbootuptime') >= 0) { // Last Boot Up Time
r += '<td style=text-align:center;font-size:x-small>' + ((node.lastbootuptime != null) ? printDateTime(new Date(node.lastbootuptime)) : "");
}
if (deviceViewSettings.devsCols.indexOf('links') >= 0) { r += '<td style=text-align:center;font-size:x-small>' + getShortRouterLinks(node); } // Links if (deviceViewSettings.devsCols.indexOf('links') >= 0) { r += '<td style=text-align:center;font-size:x-small>' + getShortRouterLinks(node); } // Links
if (deviceViewSettings.devsCols.indexOf('user') >= 0) { r += '<td style=text-align:center>' + getUserShortStr(node); } // User if (deviceViewSettings.devsCols.indexOf('user') >= 0) { r += '<td style=text-align:center>' + getUserShortStr(node); } // User
if (deviceViewSettings.devsCols.indexOf('ip') >= 0) { var ip = ''; if (node.mtype == 3) { ip = node.host; } else if (node.ip) { ip = node.ip; } r += '<td style=text-align:center>' + ip; } // IP address if (deviceViewSettings.devsCols.indexOf('ip') >= 0) { var ip = ''; if (node.mtype == 3) { ip = node.host; } else if (node.ip) { ip = node.ip; } r += '<td style=text-align:center>' + ip; } // IP address
@ -11928,28 +11934,12 @@
} }
if(hardware.linux && hardware.linux.LastBootUpTime){ if(hardware.linux && hardware.linux.LastBootUpTime){
var lastBootUpTime = new Date(hardware.linux.LastBootUpTime); var lastBootUpTime = new Date(hardware.linux.LastBootUpTime);
var thedate = { const date = printDateTime(lastBootUpTime);
year: lastBootUpTime.getFullYear(),
month: lastBootUpTime.getMonth(),
day: lastBootUpTime.getDate(),
hours: lastBootUpTime.getHours(),
minutes: lastBootUpTime.getMinutes(),
seconds: lastBootUpTime.getSeconds()
};
const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
x += addDetailItem("Last Boot Up Time", date); x += addDetailItem("Last Boot Up Time", date);
} }
if(hardware.darwin && hardware.darwin.LastBootUpTime){ if(hardware.darwin && hardware.darwin.LastBootUpTime){
var lastBootUpTime = new Date(hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct? var lastBootUpTime = new Date(hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
var thedate = { const date = printDateTime(lastBootUpTime);
year: lastBootUpTime.getFullYear(),
month: lastBootUpTime.getMonth(),
day: lastBootUpTime.getDate(),
hours: lastBootUpTime.getHours(),
minutes: lastBootUpTime.getMinutes(),
seconds: lastBootUpTime.getSeconds()
};
const date = printDateTime(new Date(thedate.year, thedate.month, thedate.day, thedate.hours, thedate.minutes, thedate.seconds));
x += addDetailItem("Last Boot Up Time", date); x += addDetailItem("Last Boot Up Time", date);
} }
if (x != '') { sections.push({ name: "Operating System", html: x, img: 'software64.png'}); } if (x != '') { sections.push({ name: "Operating System", html: x, img: 'software64.png'}); }
@ -15044,7 +15034,8 @@
155: "Denied user login from {0}, {1}, {2}", 155: "Denied user login from {0}, {1}, {2}",
156: "Verified messaging account of user {0}", 156: "Verified messaging account of user {0}",
157: "Removed messaging account of user {0}", 157: "Removed messaging account of user {0}",
158: "Displaying alert box, title=\"{0}\", message=\"{1}\"" 158: "Displaying alert box, title=\"{0}\", message=\"{1}\"",
159: "Device Powered On"
}; };
var eventsShortMessageId = { var eventsShortMessageId = {