add lastbootuptime to columns and device powered on event (#5999)
Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
parent
31ebb21e0b
commit
548edd13d6
|
@ -1883,86 +1883,49 @@ function getSystemInformation(func) {
|
|||
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; } }
|
||||
} catch (ex) { }
|
||||
if (!results.hardware.identifiers['bios_serial']) {
|
||||
try {
|
||||
var values = require('win-wmi').query('ROOT\\CIMV2', "SELECT * FROM Win32_Bios", ['SerialNumber']);
|
||||
results.hardware.identifiers['bios_serial'] = values[0]['SerialNumber'];
|
||||
} catch (ex) { }
|
||||
}
|
||||
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 (x.LastBootUpTime) { // detect windows uptime
|
||||
var thedate = {
|
||||
year: parseInt(x.LastBootUpTime.substring(0, 4)),
|
||||
month: parseInt(x.LastBootUpTime.substring(4, 6)) - 1, // Months are 0-based in JavaScript (0 - January, 11 - December)
|
||||
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 && results.hardware.linux) {
|
||||
if (!results.hardware.identifiers['bios_serial']) {
|
||||
try {
|
||||
if (require('fs').statSync('/sys/class/dmi/id/product_serial').isFile()){
|
||||
results.hardware.identifiers['bios_serial'] = require('fs').readFileSync('/sys/class/dmi/id/product_serial').toString().trim();
|
||||
}
|
||||
} catch (ex) { }
|
||||
}
|
||||
if (!results.hardware.identifiers['bios_mode']) {
|
||||
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) {
|
||||
try {
|
||||
var 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();
|
||||
results.hardware.linux.LastBootUpTime = child.stdout.str.trim();
|
||||
} catch (ex) { }
|
||||
}
|
||||
}
|
||||
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]);
|
||||
if(results.hardware.linux.LastBootUpTime) {
|
||||
var thelastbootuptime = new Date(results.hardware.linux.LastBootUpTime);
|
||||
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);
|
||||
}
|
||||
} catch (ex) { }
|
||||
}
|
||||
}
|
||||
if(results.hardware && results.hardware.darwin){
|
||||
if(results.hardware.darwin.LastBootUpTime) {
|
||||
var thelastbootuptime = new Date(results.hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
results.hardware.agentvers = process.versions;
|
||||
results.hardware.network = { dns: require('os').dns() };
|
||||
replaceSpacesWithUnderscoresRec(results);
|
||||
|
|
|
@ -70,31 +70,25 @@ function linux_identifiers()
|
|||
var values = {};
|
||||
|
||||
if (!require('fs').existsSync('/sys/class/dmi/id')) {
|
||||
if(require('fs').existsSync('/sys/firmware/devicetree/base/model')){
|
||||
if(require('fs').readFileSync('/sys/firmware/devicetree/base/model').toString().trim().startsWith('Raspberry')){
|
||||
if (require('fs').existsSync('/sys/firmware/devicetree/base/model')) {
|
||||
if (require('fs').readFileSync('/sys/firmware/devicetree/base/model').toString().trim().startsWith('Raspberry')) {
|
||||
identifiers['board_vendor'] = 'Raspberry Pi';
|
||||
identifiers['board_name'] = require('fs').readFileSync('/sys/firmware/devicetree/base/model').toString().trim();
|
||||
identifiers['board_serial'] = require('fs').readFileSync('/sys/firmware/devicetree/base/serial-number').toString().trim();
|
||||
}else{
|
||||
} else {
|
||||
throw('Unknown board');
|
||||
}
|
||||
}else {
|
||||
} else {
|
||||
throw ('this platform does not have DMI statistics');
|
||||
}
|
||||
} else {
|
||||
var entries = require('fs').readdirSync('/sys/class/dmi/id');
|
||||
for(var i in entries)
|
||||
{
|
||||
if (require('fs').statSync('/sys/class/dmi/id/' + entries[i]).isFile())
|
||||
{
|
||||
try
|
||||
{
|
||||
for (var i in entries) {
|
||||
if (require('fs').statSync('/sys/class/dmi/id/' + entries[i]).isFile()) {
|
||||
try {
|
||||
ret[entries[i]] = require('fs').readFileSync('/sys/class/dmi/id/' + entries[i]).toString().trim();
|
||||
}
|
||||
catch(z)
|
||||
{
|
||||
}
|
||||
if (ret[entries[i]] == 'None') { delete ret[entries[i]];}
|
||||
} catch(z) { }
|
||||
if (ret[entries[i]] == 'None') { delete ret[entries[i]]; }
|
||||
}
|
||||
}
|
||||
entries = null;
|
||||
|
@ -343,6 +337,25 @@ function linux_identifiers()
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -559,6 +572,23 @@ function windows_identifiers()
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
function macos_identifiers()
|
||||
|
@ -674,6 +704,21 @@ function macos_identifiers()
|
|||
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);
|
||||
|
||||
child = null;
|
||||
|
|
|
@ -1924,6 +1924,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
|||
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 (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
|
||||
if ((command.pmt != null) && (typeof command.pmt == 'string') && (device.pmt != command.pmt)) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<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=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=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=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 />';
|
||||
|
@ -4076,6 +4077,7 @@
|
|||
if (Q('d2c11').checked) { cols.push('windowsav'); }
|
||||
if (Q('d2c12').checked) { cols.push('windowsupdate'); }
|
||||
if (Q('d2c13').checked) { cols.push('windowsfirewall'); }
|
||||
if (Q('d2c14').checked) { cols.push('lastbootuptime'); }
|
||||
if (Q('d2c15').checked) { cols.push('amthost'); }
|
||||
if (Q('d2c17').checked) { cols.push('amtstate'); }
|
||||
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('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('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('user') >= 0) { colums += '<th style=color:gray;width:120px>' + "User"; }
|
||||
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
|
||||
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('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
|
||||
|
@ -11928,28 +11934,12 @@
|
|||
}
|
||||
if(hardware.linux && hardware.linux.LastBootUpTime){
|
||||
var lastBootUpTime = new Date(hardware.linux.LastBootUpTime);
|
||||
var thedate = {
|
||||
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));
|
||||
const date = printDateTime(lastBootUpTime);
|
||||
x += addDetailItem("Last Boot Up Time", date);
|
||||
}
|
||||
if(hardware.darwin && hardware.darwin.LastBootUpTime){
|
||||
var lastBootUpTime = new Date(hardware.darwin.LastBootUpTime * 1000); // must times by 1000 even tho timestamp is correct?
|
||||
var thedate = {
|
||||
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));
|
||||
const date = printDateTime(lastBootUpTime);
|
||||
x += addDetailItem("Last Boot Up Time", date);
|
||||
}
|
||||
if (x != '') { sections.push({ name: "Operating System", html: x, img: 'software64.png'}); }
|
||||
|
@ -15044,7 +15034,8 @@
|
|||
155: "Denied user login from {0}, {1}, {2}",
|
||||
156: "Verified 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 = {
|
||||
|
|
Loading…
Reference in New Issue