Improved MEI/SMBios in meshcore.js
Ylian Saint-Hilaire committed
Sep 27, 2018 at 16:17 UTC
8d45bcdde92e419f760421b7b6e1a5438ee812a3
4 files changed
+78
-57
agents/meshcore.js
+60
-53
@@ -73,7 +73,6 @@ function createMeshCore(agent) {
73
var fs = require('fs');
74
var rtc = require('ILibWebRTC');
75
var processManager = require('process-manager');
76
- var SMBiosTables = require('smbios');
76
var amtMei = null, amtLms = null, amtLmsState = 0;
77
var amtMeiConnected = 0, amtMeiTmpState = null;
78
var wifiScannerLib = null;
@@ -81,7 +80,25 @@ function createMeshCore(agent) {
80
var networkMonitor = null;
81
var amtscanner = null;
82
var nextTunnelIndex = 1;
84
-
83
+
84
+ // If we are running in Duktape, agent will be null
85
+ if (agent == null) {
86
+ // Running in native agent, Import libraries
87
+ db = require('SimpleDataStore').Shared();
88
+ sha = require('SHA256Stream');
89
+ mesh = require('MeshAgent');
90
+ childProcess = require('child_process');
91
+ if (mesh.hasKVM == 1) { // if the agent is compiled with KVM support
92
+ // Check if this computer supports a desktop
93
+ try { if ((process.platform == 'win32') || (process.platform == 'darwin') || (require('monitor-info').kvm_x11_support)) { obj.meshCoreCapabilities |= 1; } } catch (ex) { }
94
+ }
95
+ } else {
96
+ // Running in nodejs
97
+ obj.meshCoreInfo += '-NodeJS';
98
+ obj.meshCoreCapabilities = 8;
99
+ mesh = agent.getMeshApi();
100
+ }
101
+
102
// Get the operating system description string
103
var osDesc = null;
104
try { require('os').name().then(function (v) { osDesc = v; if (mesh.isControlChannelConnected) { mesh.SendCommand({ "action": "coreinfo", "value": obj.meshCoreInfo, "osdesc": osDesc }); } }); } catch (ex) { }
@@ -118,15 +135,29 @@ function createMeshCore(agent) {
135
amtscanner = new AMTScannerModule();
136
//amtscanner.on('found', function (data) { if (typeof data != 'string') { data = JSON.stringify(data, null, " "); } sendConsoleText(data); });
137
} catch (ex) { amtscanner = null; }
121
-
122
- // Try to load up the MEI module
123
- try {
124
- var amtMeiLib = require('amt-mei');
125
- amtMei = new amtMeiLib();
126
- amtMei.on('error', function (e) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; });
127
- amtMeiConnected = 2;
128
- sendPeriodicServerUpdate(1);
129
- } catch (ex) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; }
138
+
139
+ // Fetch the SMBios Tables
140
+ var SMBiosTables = null;
141
+ var SMBiosTablesRaw = null;
142
+ require('smbios').get(function (data) {
143
+ if (data != null) {
144
+ SMBiosTablesRaw = data;
145
+ SMBiosTables = require('smbios').parse(data)
146
+ if (mesh.isControlChannelConnected) { mesh.SendCommand({ "action": "smbios", "value": SMBiosTablesRaw }); }
147
+
148
+ // If SMBios tables say that AMT is present, try to connect MEI
149
+ if (SMBiosTables.amtInfo && (SMBiosTables.amtInfo.AMT == true)) {
150
+ // Try to load up the MEI module
151
+ try {
152
+ var amtMeiLib = require('amt-mei');
153
+ amtMei = new amtMeiLib();
154
+ amtMei.on('error', function (e) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; });
155
+ amtMeiConnected = 2;
156
+ sendPeriodicServerUpdate(1);
157
+ } catch (ex) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; }
158
+ }
159
+ }
160
+ });
161
162
// Try to load up the WIFI scanner
163
try {
@@ -135,24 +166,6 @@ function createMeshCore(agent) {
166
wifiScanner.on('accessPoint', function (data) { sendConsoleText(JSON.stringify(data)); });
167
} catch (ex) { wifiScannerLib = null; wifiScanner = null; }
168
138
- // If we are running in Duktape, agent will be null
139
- if (agent == null) {
140
- // Running in native agent, Import libraries
141
- db = require('SimpleDataStore').Shared();
142
- sha = require('SHA256Stream');
143
- mesh = require('MeshAgent');
144
- childProcess = require('child_process');
145
- if (mesh.hasKVM == 1) { // if the agent is compiled with KVM support
146
- // Check if this computer supports a desktop
147
- try { if ((process.platform == 'win32') || (process.platform == 'darwin') || (require('monitor-info').kvm_x11_support)) { obj.meshCoreCapabilities |= 1; } } catch (ex) { }
148
- }
149
- } else {
150
- // Running in nodejs
151
- obj.meshCoreInfo += '-NodeJS';
152
- obj.meshCoreCapabilities = 8;
153
- mesh = agent.getMeshApi();
154
- }
155
-
169
// Get our location (lat/long) using our public IP address
170
var getIpLocationDataExInProgress = false;
171
var getIpLocationDataExCounts = [0, 0];
@@ -972,31 +985,22 @@ function createMeshCore(agent) {
985
break;
986
}
987
case 'smbios': {
975
- if (SMBiosTables != null) {
976
- SMBiosTables.get(function (data) {
977
- if (data == null) { sendConsoleText('Unable to get SM BIOS data.', sessionid); return; }
978
- sendConsoleText(objToString(SMBiosTables.parse(data), 0, ' ', true), sessionid);
979
- });
980
- } else { response = 'SM BIOS module not available.'; }
988
+ if (SMBiosTables == null) { response = 'SMBios tables not available.'; } else { response = objToString(SMBiosTables, 0, ' ', true); }
989
break;
990
}
991
case 'rawsmbios': {
984
- if (SMBiosTables != null) {
985
- SMBiosTables.get(function (data) {
986
- if (data == null) { sendConsoleText('Unable to get SM BIOS data.', sessionid); return; }
987
- var out = '';
988
- for (var i in data) {
989
- var header = false;
990
- for (var j in data[i]) {
991
- if (data[i][j].length > 0) {
992
- if (header == false) { out += ('Table type #' + i + ((SMBiosTables.smTableTypes[i] == null) ? '' : (', ' + SMBiosTables.smTableTypes[i]))) + '\r\n'; header = true; }
993
- out += (' ' + data[i][j].toString('hex')) + '\r\n';
994
- }
992
+ if (SMBiosTablesRaw == null) { response = 'SMBios tables not available.'; } else {
993
+ response = '';
994
+ for (var i in SMBiosTablesRaw) {
995
+ var header = false;
996
+ for (var j in SMBiosTablesRaw[i]) {
997
+ if (SMBiosTablesRaw[i][j].length > 0) {
998
+ if (header == false) { response += ('Table type #' + i + ((require('smbios').smTableTypes[i] == null) ? '' : (', ' + require('smbios').smTableTypes[i]))) + '\r\n'; header = true; }
999
+ response += (' ' + SMBiosTablesRaw[i][j].toString('hex')) + '\r\n';
1000
}
1001
}
997
- sendConsoleText(out, sessionid);
998
- });
999
- } else { response = 'SM BIOS module not available.'; }
1002
+ }
1003
+ }
1004
break;
1005
}
1006
case 'eval': { // Eval JavaScript
@@ -1358,11 +1362,14 @@ function createMeshCore(agent) {
1362
var oldNodeId = db.Get('OldNodeId');
1363
if (oldNodeId != null) { mesh.SendCommand({ action: 'mc1migration', oldnodeid: oldNodeId }); }
1364
1361
- // Update the server wtih basic info
1365
+ // Update the server with basic info
1366
var r = { "action": "coreinfo", "value": obj.meshCoreInfo, "caps": obj.meshCoreCapabilities };
1367
if (osDesc != null) { r.osdesc = osDesc; }
1368
mesh.SendCommand(r);
1369
1370
+ // Send SMBios tables if present
1371
+ if (SMBiosTablesRaw != null) { mesh.SendCommand({ "action": "smbios", "value": SMBiosTablesRaw }); }
1372
+
1373
// Update list of logged in users
1374
if (obj.loggedInUsers != null) { mesh.SendCommand({ "action": "coreinfo", "v": { "users": obj.loggedInUsers } }); }
1375
@@ -1422,9 +1429,9 @@ function createMeshCore(agent) {
1429
try {
1430
amtMeiTmpState = { Flags: 0 }; // Flags: 1=EHBC, 2=CCM, 4=ACM
1431
amtMei.getProtocolVersion(function (result) { if (result != null) { amtMeiTmpState.MeiVersion = result; } });
1425
- amtMei.getVersion(function (val) { amtMeiTmpState.Versions = {}; for (var version in val.Versions) { amtMeiTmpState.Versions[val.Versions[version].Description] = val.Versions[version].Version; } });
1426
- amtMei.getProvisioningMode(function (result) { amtMeiTmpState.ProvisioningMode = result.mode; });
1427
- amtMei.getProvisioningState(function (result) { amtMeiTmpState.ProvisioningState = result.state; });
1432
+ amtMei.getVersion(function (result) { if (result) { amtMeiTmpState.Versions = {}; for (var version in result.Versions) { amtMeiTmpState.Versions[result.Versions[version].Description] = result.Versions[version].Version; } } });
1433
+ amtMei.getProvisioningMode(function (result) { if (result) { amtMeiTmpState.ProvisioningMode = result.mode; } });
1434
+ amtMei.getProvisioningState(function (result) { if (result) { amtMeiTmpState.ProvisioningState = result.state; } });
1435
amtMei.getEHBCState(function (result) { if ((result != null) && (result.EHBC == true)) { amtMeiTmpState.Flags += 1; } });
1436
amtMei.getControlMode(function (result) { if (result != null) { if (result.controlMode == 1) { amtMeiTmpState.Flags += 2; } if (result.controlMode == 2) { amtMeiTmpState.Flags += 4; } } });
1437
amtMei.getUuid(function (result) { if ((result != null) && (result.uuid != null)) { amtMeiTmpState.UUID = result.uuid; } });
db.js
+5
-3
@@ -129,9 +129,11 @@ module.exports.CreateDB = function (parent) {
129
obj.file.count({ type: 'user' }, function (err, userCount) {
130
obj.file.count({ type: 'ifinfo' }, function (err, nodeInterfaceCount) {
131
obj.file.count({ type: 'note' }, function (err, noteCount) {
132
- obj.file.count({ type: 'lastconnect' }, function (err, nodeLastConnectCount) {
133
- obj.file.count({ }, function (err, totalCount) {
134
- func({ nodes: nodeCount, meshes: meshCount, powerEvents: powerCount, users: userCount, nodeInterfaces: nodeInterfaceCount, notes: noteCount, connectEvent: nodeLastConnectCount, total: totalCount });
132
+ obj.file.count({ type: 'smbios' }, function (err, nodeSmbiosCount) {
133
+ obj.file.count({ type: 'lastconnect' }, function (err, nodeLastConnectCount) {
134
+ obj.file.count({ }, function (err, totalCount) {
135
+ func({ nodes: nodeCount, meshes: meshCount, powerEvents: powerCount, users: userCount, nodeInterfaces: nodeInterfaceCount, notes: noteCount, connectEvent: nodeLastConnectCount, smbios: nodeSmbiosCount, total: totalCount });
136
+ });
137
});
138
});
139
});
meshagent.js
+11
@@ -69,6 +69,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
69
obj.db.Remove('if' + obj.dbNodeKey); // Remove interface information
70
obj.db.Remove('nt' + obj.dbNodeKey); // Remove notes
71
obj.db.Remove('lc' + obj.dbNodeKey); // Remove last connect time
72
+ obj.db.Remove('sm' + obj.dbNodeKey); // Remove SMBios data
73
obj.db.RemoveNode(obj.dbNodeKey); // Remove all entries with node:id
74
75
// Event node deletion
@@ -522,6 +523,16 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
523
{
524
// Sent by the agent to update agent information
525
ChangeAgentCoreInfo(command);
526
+ break;
527
+ }
528
+ case 'smbios':
529
+ {
530
+ // The RAW SMBios table of this computer
531
+ obj.db.Set({ _id: 'sm' + obj.dbNodeKey, type: 'smbios', domain: domain.id, time: Date.now(), smbios: command.value });
532
+
533
+ // Event the node interface information change (This is a lot of traffic, probably don't need this).
534
+ //obj.parent.parent.DispatchEvent(['*', obj.meshid], obj, { action: 'smBiosChange', nodeid: obj.dbNodeKey, domain: domain.id, smbios: command.value, nolog: 1 });
535
+
536
break;
537
}
538
case 'netinfo':
meshuser.js
+2
-1
@@ -131,7 +131,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
131
if (obj.parent.parent.platform != 'win32') { stats.cpuavg = os.loadavg(); } // else { stats.cpuavg = [ 0.2435345, 0.523234234, 0.6435345345 ]; }
132
var serverStats = { "User Accounts": Object.keys(obj.parent.users).length, "Device Groups": Object.keys(obj.parent.meshes).length, "Connected Agents": Object.keys(obj.parent.wsagents).length, "Connected Users": Object.keys(obj.parent.wssessions2).length };
133
if (obj.parent.parent.mpsserver != null) { serverStats['Connected Intel® AMT'] = Object.keys(obj.parent.parent.mpsserver.ciraConnections).length; }
134
- stats.values = { "Server State": serverStats, "Database": { "Records": data.total, "Users": data.users, "Device Groups": data.meshes, "Devices": data.nodes, "Device NetInfo": data.nodeInterfaces, "Device Power Event": data.powerEvents, "Notes": data.notes, "Connection Records": data.connectEvents } }
134
+ stats.values = { "Server State": serverStats, "Database": { "Records": data.total, "Users": data.users, "Device Groups": data.meshes, "Devices": data.nodes, "Device NetInfo": data.nodeInterfaces, "Device Power Event": data.powerEvents, "Notes": data.notes, "Connection Records": data.connectEvents, "SMBios": data.smbios } }
135
try { ws.send(JSON.stringify(stats)); } catch (ex) { }
136
});
137
}
@@ -865,6 +865,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
865
obj.db.Remove('if' + node._id); // Remove interface information
866
obj.db.Remove('nt' + node._id); // Remove notes
867
obj.db.Remove('lc' + node._id); // Remove last connect time
868
+ obj.db.Remove('sm' + node._id); // Remove SMBios data
869
obj.db.RemoveNode(node._id); // Remove all entries with node:id
870
871
// Event node deletion