Improved meshcore Intel AMT handling.

Ylian Saint-Hilaire committed Nov 2, 2020 at 00:44 UTC a905bba83ce12e2b38382ca2eb730fa5c4fe9ef3
5 files changed +95 -171
MeshCentralServer.njsproj
+2 -8
@@ -25,17 +25,16 @@
25 <Compile Include="agents\meshcore.js" />
26 <Compile Include="agents\meshcore.min.js" />
27 <Compile Include="agents\meshinstall-linux.js" />
28 + <Compile Include="agents\modules_meshcmd\amt-apfclient.js" />
29 <Compile Include="agents\modules_meshcmd\amt-ider.js" />
30 <Compile Include="agents\modules_meshcmd\amt-lme.js" />
31 <Compile Include="agents\modules_meshcmd\amt-mei.js" />
32 <Compile Include="agents\modules_meshcmd\amt-redir-duk.js" />
33 <Compile Include="agents\modules_meshcmd\amt-scanner.js" />
33 - <Compile Include="agents\modules_meshcmd\amt-script.js" />
34 <Compile Include="agents\modules_meshcmd\amt-wsman-duk.js" />
35 <Compile Include="agents\modules_meshcmd\amt-wsman.js" />
36 <Compile Include="agents\modules_meshcmd\amt-xml.js" />
37 <Compile Include="agents\modules_meshcmd\amt.js" />
38 - <Compile Include="agents\modules_meshcmd\apfclient.js" />
38 <Compile Include="agents\modules_meshcmd\identifiers.js" />
39 <Compile Include="agents\modules_meshcmd\smbios.js" />
40 <Compile Include="agents\modules_meshcmd\sysinfo.js" />
@@ -53,15 +52,10 @@
52 <Compile Include="agents\modules_meshcmd_min\service-manager.min.js" />
53 <Compile Include="agents\modules_meshcmd_min\smbios.min.js" />
54 <Compile Include="agents\modules_meshcmd_min\user-sessions.min.js" />
55 + <Compile Include="agents\modules_meshcore\amt-apfclient.js" />
56 <Compile Include="agents\modules_meshcore\amt-lme.js" />
57 <Compile Include="agents\modules_meshcore\amt-manage.js" />
58 <Compile Include="agents\modules_meshcore\amt-mei.js" />
59 - <Compile Include="agents\modules_meshcore\amt-scanner.js" />
60 - <Compile Include="agents\modules_meshcore\amt-wsman-duk.js" />
61 - <Compile Include="agents\modules_meshcore\amt-wsman.js" />
62 - <Compile Include="agents\modules_meshcore\amt-xml.js" />
63 - <Compile Include="agents\modules_meshcore\amt.js" />
64 - <Compile Include="agents\modules_meshcore\apfclient.js" />
59 <Compile Include="agents\modules_meshcore\monitor-border.js" />
60 <Compile Include="agents\modules_meshcore\smbios.js" />
61 <Compile Include="agents\modules_meshcore\sysinfo.js" />
agents/meshcore.js
+67 -143
@@ -389,9 +389,27 @@ function createMeshCore(agent) {
389 // MeshAgent JavaScript Core Module. This code is sent to and running on the mesh agent.
390 var meshCoreObj = { action: 'coreinfo', value: (require('MeshAgent').coreHash ? ('MeshCore CRC-' + crc32c(require('MeshAgent').coreHash)) : ('MeshCore v6')), caps: 14, root: require('user-sessions').isRoot() }; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript, 32 = Temporary Agent, 64 = Recovery Agent
391
392 -
392 // Get the operating system description string
394 - try { require('os').name().then(function (v) { meshCoreObj.osdesc = v; }); } catch (e) { }
393 + try { require('os').name().then(function (v) { meshCoreObj.osdesc = v; meshCoreObjChanged(); }); } catch (e) { }
394 +
395 + // Setup logged in user monitoring (THIS IS BROKEN IN WIN7)
396 + try {
397 + var userSession = require('user-sessions');
398 + userSession.on('changed', function onUserSessionChanged() {
399 + userSession.enumerateUsers().then(function (users) {
400 + var u = [], a = users.Active;
401 + for (var i = 0; i < a.length; i++) {
402 + var un = a[i].Domain ? (a[i].Domain + '\\' + a[i].Username) : (a[i].Username);
403 + if (u.indexOf(un) == -1) { u.push(un); } // Only push users in the list once.
404 + }
405 + meshCoreObj.users = u;
406 + meshCoreObjChanged();
407 + });
408 + });
409 + userSession.emit('changed');
410 + //userSession.on('locked', function (user) { sendConsoleText('[' + (user.Domain ? user.Domain + '\\' : '') + user.Username + '] has LOCKED the desktop'); });
411 + //userSession.on('unlocked', function (user) { sendConsoleText('[' + (user.Domain ? user.Domain + '\\' : '') + user.Username + '] has UNLOCKED the desktop'); });
412 + } catch (e) { }
413
414 var meshServerConnectionState = 0;
415 var tunnels = {};
@@ -447,17 +465,10 @@ function createMeshCore(agent) {
465 // Check if this computer supports a desktop
466 try
467 {
450 - if ((process.platform == 'win32') || (process.platform == 'darwin') || (require('monitor-info').kvm_x11_support))
451 - {
452 - meshCoreObj.caps |= 1;
453 - }
454 - else if(process.platform == 'linux' || process.platform == 'freebsd')
455 - {
456 - require('monitor-info').on('kvmSupportDetected', function (value)
457 - {
458 - meshCoreObj.caps |= 1;
459 - mesh.SendCommand(meshCoreObj);
460 - });
468 + if ((process.platform == 'win32') || (process.platform == 'darwin') || (require('monitor-info').kvm_x11_support)) {
469 + meshCoreObj.caps |= 1; meshCoreObjChanged();
470 + } else if (process.platform == 'linux' || process.platform == 'freebsd') {
471 + require('monitor-info').on('kvmSupportDetected', function (value) { meshCoreObj.caps |= 1; meshCoreObjChanged(); });
472 }
473 } catch (e) { }
474 }
@@ -498,31 +509,9 @@ function createMeshCore(agent) {
509 {
510 var amtmodule = require('amt-manage');
511 amt = new amtmodule(mesh, db, false);
501 - amt.on('portBinding_LMS', function (map)
502 - {
503 - var j = { action: 'lmsinfo', value: { ports: map.keys() } };
504 - mesh.SendCommand(j);
505 - });
506 - amt.on('stateChange_LMS', function (v)
507 - {
508 - if (!meshCoreObj.intelamt) { meshCoreObj.intelamt = {}; }
509 - switch(v)
510 - {
511 - case 0:
512 - meshCoreObj.intelamt.microlms = 'DISABLED';
513 - break;
514 - case 1:
515 - meshCoreObj.intelamt.microlms = 'CONNECTING';
516 - break;
517 - case 2:
518 - meshCoreObj.intelamt.microlms = 'CONNECTED';
519 - break;
520 - default:
521 - break;
522 - }
523 - mesh.SendCommand(meshCoreObj);
524 - });
525 - amt.onStateChange = function (state) { if (state == 2) { sendPeriodicServerUpdate(1); } }
512 + amt.on('portBinding_LMS', function (map) { mesh.SendCommand({ action: 'lmsinfo', value: { ports: map.keys() } }); });
513 + amt.on('stateChange_LMS', function (v) { if (!meshCoreObj.intelamt) { meshCoreObj.intelamt = {}; } meshCoreObj.intelamt.microlms = v; meshCoreObjChanged(); }); // 0 = Disabled, 1 = Connecting, 2 = Connected
514 + amt.onStateChange = function (state) { if (state == 2) { sendPeriodicServerUpdate(1); } } // MEI State
515 amt.reset();
516 }
517 }
@@ -2590,7 +2579,7 @@ function createMeshCore(agent) {
2579 var response = null;
2580 switch (cmd) {
2581 case 'help': { // Displays available commands
2593 - var fin = '', f = '', availcommands = 'coreinfo, coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,nwslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,sendcaps,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg';
2582 + var fin = '', f = '', availcommands = 'coreinfo, coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,nwslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg';
2583 if (process.platform == 'win32') { availcommands += ',safemode,wpfhwacceleration,uac'; }
2584 if (amt != null) { availcommands += ',amt,amtconfig,amtevents'; }
2585 if (process.platform != 'freebsd') { availcommands += ',vm';}
@@ -2610,6 +2599,10 @@ function createMeshCore(agent) {
2599 response = JSON.stringify(meshCoreObj, null, 2);
2600 break;
2601 }
2602 + case 'coreinfoupdate': {
2603 + sendPeriodicServerUpdate();
2604 + break;
2605 + }
2606 case 'agentmsg': {
2607 if (args['_'].length == 0) {
2608 response = "Proper usage:\r\n agentmsg add \"[message]\" [iconIndex]\r\n agentmsg remove [index]\r\n agentmsg list"; // Display usage
@@ -3211,26 +3204,6 @@ function createMeshCore(agent) {
3204 }
3205 break;
3206 }
3214 - case 'sendcaps': { // Send capability flags to the server
3215 - if (args['_'].length == 0) {
3216 - response = 'Proper usage: sendcaps (number)'; // Display correct command usage
3217 - } else {
3218 - meshCoreObj.caps = parseInt(args['_'][0]);
3219 - mesh.SendCommand(meshCoreObj);
3220 - response = JSON.stringify(meshCoreObj);
3221 - }
3222 - break;
3223 - }
3224 - case 'sendosdesc': { // Send OS description
3225 - if (args['_'].length > 0) {
3226 - meshCoreObj.osdesc = args['_'][0];
3227 - mesh.SendCommand(meshCoreObj);
3228 - response = JSON.stringify(meshCoreObj);
3229 - } else {
3230 - response = 'Proper usage: sendosdesc [os description]'; // Display correct command usage
3231 - }
3232 - break;
3233 - }
3207 case 'args': { // Displays parsed command arguments
3208 response = 'args ' + objToString(args, 0, ' ', true);
3209 break;
@@ -3669,13 +3642,10 @@ function createMeshCore(agent) {
3642 var oldNodeId = db.Get('OldNodeId');
3643 if (oldNodeId != null) { mesh.SendCommand({ action: 'mc1migration', oldnodeid: oldNodeId }); }
3644
3672 - // Update the server with basic info, logged in users and more.
3673 - mesh.SendCommand(meshCoreObj);
3674 -
3645 // Send SMBios tables if present
3646 if (SMBiosTablesRaw != null) { mesh.SendCommand({ action: 'smbios', value: SMBiosTablesRaw }); }
3647
3678 - // Update the server on more advanced stuff, like Intel ME and Network Settings
3648 + // Update the server on with basic info, logged in users and more advanced stuff, like Intel ME and Network Settings
3649 meInfoStr = null;
3650 sendPeriodicServerUpdate();
3651 if (selfInfoUpdateTimer == null) { selfInfoUpdateTimer = setInterval(sendPeriodicServerUpdate, 1200000); } // 20 minutes
@@ -3710,103 +3680,57 @@ function createMeshCore(agent) {
3680 }
3681
3682 // Called periodically to check if we need to send updates to the server
3713 - function sendPeriodicServerUpdate(flags) {
3683 + function sendPeriodicServerUpdate(flags, force) {
3684 if (meshServerConnectionState == 0) return; // Not connected to server, do nothing.
3685 if (!flags) { flags = 0xFFFFFFFF; }
3686
3717 - if ((flags & 1) && (amt != null)) {
3718 - // If we have a connected MEI, get Intel ME information
3719 - amt.getMeiState(11, function (meinfo) {
3720 - try {
3721 - if (meinfo == null) return;
3722 - var intelamt = {};
3723 - if (amt != null)
3724 - {
3725 - switch(amt.lmsstate)
3726 - {
3727 - case 0: intelamt.microlms = 'DISABLED'; break;
3728 - case 1: intelamt.microlms = 'CONNECTING'; break;
3729 - case 2: intelamt.microlms = 'CONNECTED'; break;
3730 - default: intelamt.microlms = 'unknown'; break;
3731 - }
3732 - }
3733 - var p = false;
3734 - if ((meinfo.Versions != null) && (meinfo.Versions.AMT != null)) { intelamt.ver = meinfo.Versions.AMT; p = true; if (meinfo.Versions.Sku != null) { intelamt.sku = parseInt(meinfo.Versions.Sku); } }
3735 - if (meinfo.ProvisioningState != null) { intelamt.state = meinfo.ProvisioningState; p = true; }
3736 - if (meinfo.Flags != null) { intelamt.flags = meinfo.Flags; p = true; }
3737 - if (meinfo.OsHostname != null) { intelamt.host = meinfo.OsHostname; p = true; }
3738 - if (meinfo.UUID != null) { intelamt.uuid = meinfo.UUID; p = true; }
3739 - if ((meinfo.ProvisioningState == 0) && (meinfo.net0 != null) && (meinfo.net0.enabled == 1)) { // If not activated, look to see if we have wired net working.
3740 - // Not activated and we have wired ethernet, look for the trusted DNS
3741 - var dns = meinfo.DNS;
3742 - if (dns == null) {
3743 - // Trusted DNS not set, let's look for the OS network DNS suffix
3744 - var interfaces = require('os').networkInterfaces();
3745 - for (var i in interfaces) {
3746 - for (var j in interfaces[i]) {
3747 - if ((interfaces[i][j].mac == mestate.net0.mac) && (interfaces[i][j].fqdn != null) && (interfaces[i][j].fqdn != '')) { dns = interfaces[i][j].fqdn; }
3748 - }
3749 - }
3750 - }
3751 - if (intelamt.dns != dns) { intelamt.dns = dns; p = true; }
3752 - } else { if (intelamt.dns != null) { delete intelamt.dns; p = true; } }
3753 - if (p == true) {
3754 - var meInfoStr = JSON.stringify(intelamt);
3755 - if (meInfoStr != lastMeInfo) {
3756 - meshCoreObj.intelamt = intelamt;
3757 - mesh.SendCommand(meshCoreObj);
3758 - lastMeInfo = meInfoStr;
3759 - }
3760 - }
3761 - } catch (e) { }
3687 + // If we have a connected MEI, get Intel ME information
3688 + if ((flags & 1) && (amt != null) && (amt.state == 2)) {
3689 + delete meshCoreObj.intelamt;
3690 + amt.getMeiState(9, function (meinfo) {
3691 + meshCoreObj.intelamt = meinfo;
3692 + meshCoreObj.intelamt.microlms = amt.lmsstate;
3693 + meshCoreObjChanged();
3694 });
3695 }
3696
3765 - if (flags & 2) {
3766 - // Update network information
3767 - sendNetworkUpdateNagle(false);
3768 - }
3697 + // Update network information
3698 + if (flags & 2) { sendNetworkUpdateNagle(false); }
3699
3700 + // Update anti-virus information
3701 if ((flags & 4) && (process.platform == 'win32')) {
3771 - // Update anti-virus information
3702 // Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
3773 - var av, pr;
3774 - try { av = require('win-info').av(); } catch (e) { av = null; } // Antivirus
3775 - //if (process.platform == 'win32') { try { pr = require('win-info').pendingReboot(); } catch (e) { pr = null; } } // Pending reboot
3776 - if ((meshCoreObj.av == null) || (JSON.stringify(meshCoreObj.av) != JSON.stringify(av))) { meshCoreObj.av = av; mesh.SendCommand(meshCoreObj); }
3703 + try { meshCoreObj.av = require('win-info').av(); meshCoreObjChanged(); } catch (e) { av = null; } // Antivirus
3704 + //if (process.platform == 'win32') { try { meshCoreObj.pr = require('win-info').pendingReboot(); meshCoreObjChanged(); } catch (e) { meshCoreObj.pr = null; } } // Pending reboot
3705 + }
3706 +
3707 + // Send available data right now
3708 + if (force) {
3709 + meshCoreObj = sortObjRec(meshCoreObj);
3710 + var x = JSON.stringify(meshCoreObj);
3711 + if (x != LastPeriodicServerUpdate) { LastPeriodicServerUpdate = x; mesh.SendCommand(meshCoreObj); }
3712 }
3713 }
3714
3715 + // Once we are done collecting all the data, send to server if needed
3716 + var LastPeriodicServerUpdate = null;
3717 + var PeriodicServerUpdateNagleTimer = null;
3718 + function meshCoreObjChanged() { if (PeriodicServerUpdateNagleTimer == null) { PeriodicServerUpdateNagleTimer = setTimeout(meshCoreObjChangedEx, 500); } }
3719 + function meshCoreObjChangedEx() {
3720 + PeriodicServerUpdateNagleTimer = null;
3721 + meshCoreObj = sortObjRec(meshCoreObj);
3722 + var x = JSON.stringify(meshCoreObj);
3723 + if (x != LastPeriodicServerUpdate) { LastPeriodicServerUpdate = x; mesh.SendCommand(meshCoreObj); }
3724 + }
3725 +
3726 + function sortObjRec(o) { if (typeof o != 'object') return o; for (var i in o) { if (typeof o[i] == 'object') { o[i] = sortObjRec(o[i]); } } return sortObj(o); }
3727 + function sortObj(o) { return Object.keys(o).sort().reduce(function (result, key) { result[key] = o[key]; return result; }, {}); }
3728 +
3729 // Starting function
3730 obj.start = function () {
3731 // Setup the mesh agent event handlers
3732 mesh.AddCommandHandler(handleServerCommand);
3733 mesh.AddConnectHandler(handleServerConnection);
3785 -
3786 - // Parse input arguments
3787 - //var args = parseArgs(process.argv);
3788 - //console.log(args);
3789 -
3790 - //resetMicroLms();
3791 -
3792 - // Setup logged in user monitoring (THIS IS BROKEN IN WIN7)
3793 - try {
3794 - var userSession = require('user-sessions');
3795 - userSession.on('changed', function onUserSessionChanged() {
3796 - userSession.enumerateUsers().then(function (users) {
3797 - var u = [], a = users.Active;
3798 - for (var i = 0; i < a.length; i++) {
3799 - var un = a[i].Domain ? (a[i].Domain + '\\' + a[i].Username) : (a[i].Username);
3800 - if (u.indexOf(un) == -1) { u.push(un); } // Only push users in the list once.
3801 - }
3802 - meshCoreObj.users = u;
3803 - mesh.SendCommand(meshCoreObj);
3804 - });
3805 - });
3806 - userSession.emit('changed');
3807 - //userSession.on('locked', function (user) { sendConsoleText('[' + (user.Domain ? user.Domain + '\\' : '') + user.Username + '] has LOCKED the desktop'); });
3808 - //userSession.on('unlocked', function (user) { sendConsoleText('[' + (user.Domain ? user.Domain + '\\' : '') + user.Username + '] has UNLOCKED the desktop'); });
3809 - } catch (e) { }
3734 }
3735
3736 obj.stop = function () {
agents/modules_meshcore/amt-lme.js
+3 -2
@@ -17,7 +17,8 @@ limitations under the License.
17 var MemoryStream = require('MemoryStream');
18 var lme_id = 0; // Our next channel identifier
19 var lme_port_offset = 0; // Debug: Set this to "-100" to bind to 16892 & 16893 and IN_ADDRANY. This is for LMS debugging.
20 -var xmlParser = require('amt-xml');
20 +var xmlParser = null;
21 +try { xmlParser = require('amt-xml'); } catch (ex) { }
22
23 // Documented in: https://software.intel.com/sites/manageability/AMT_Implementation_and_Reference_Guide/HTMLDocuments/MPSDocuments/Intel%20AMT%20Port%20Forwarding%20Protocol%20Reference%20Manual.pdf
24 var APF_DISCONNECT = 1;
@@ -302,7 +303,7 @@ function lme_heci(options) {
303 if ((httpData != null) || (channel.data.length >= 8000)) {
304 // Parse the WSMAN
305 var notify = null;
305 - try { notify = xmlParser.ParseWsman(httpData); } catch (e) { }
306 + if (xmlParser != null) { try { notify = xmlParser.ParseWsman(httpData); } catch (e) { } }
307
308 // Event the http data
309 if (notify != null) { this.LMS.emit('notify', notify, channel.options, _lmsNotifyToCode(notify)); }
agents/modules_meshcore/amt-manage.js
+14 -4
@@ -83,12 +83,19 @@ function AmtManager(agent, db, isdebug) {
83
84 // Get Intel MEI State in a flexible way
85 // Flags: 1 = Versions, 2 = OsAdmin, 4 = Hashes, 8 = Network
86 + var getMeiStateCache = {}; // Some MEI calls will only be made once and cached here.
87 obj.getMeiState = function(flags, func) {
88 if ((amtMei == null) || (amtMeiState < 2)) { if (func != null) { func(null); } return; }
89 try {
90 var amtMeiTmpState = { OsHostname: require('os').hostname(), Flags: 0 }; // Flags: 1=EHBC, 2=CCM, 4=ACM
90 - amtMei.getProtocolVersion(function (result) { if (result != null) { amtMeiTmpState.MeiVersion = result; } });
91 - if ((flags & 1) != 0) { amtMei.getVersion(function (result) { if (result) { amtMeiTmpState.Versions = {}; for (var version in result.Versions) { amtMeiTmpState.Versions[result.Versions[version].Description] = result.Versions[version].Version; } } }); }
91 + if (getMeiStateCache.MeiVersion != null) { amtMeiTmpState.MeiVersion = getMeiStateCache.MeiVersion; } else { amtMei.getProtocolVersion(function (result) { if (result != null) { getMeiStateCache.MeiVersion = amtMeiTmpState.MeiVersion = result; } }); }
92 + if ((flags & 1) != 0) {
93 + if (getMeiStateCache.Versions != null) {
94 + amtMeiTmpState.Versions = getMeiStateCache.Versions;
95 + } else {
96 + amtMei.getVersion(function (result) { if (result) { getMeiStateCache.Versions = amtMeiTmpState.Versions = {}; for (var version in result.Versions) { amtMeiTmpState.Versions[result.Versions[version].Description] = result.Versions[version].Version; } } });
97 + }
98 + }
99 amtMei.getProvisioningMode(function (result) { if (result) { amtMeiTmpState.ProvisioningMode = result.mode; } });
100 amtMei.getProvisioningState(function (result) { if (result) { amtMeiTmpState.ProvisioningState = result.state; } }); // 0: "Not Activated (Pre)", 1: "Not Activated (In)", 2: "Activated"
101 amtMei.getEHBCState(function (result) { if ((result != null) && (result.EHBC == true)) { amtMeiTmpState.Flags += 1; } });
@@ -104,7 +111,7 @@ function AmtManager(agent, db, isdebug) {
111 });
112 amtMei.getLanInterfaceSettings(1, function (result) { if (result) { amtMeiTmpState.net1 = result; } });
113 }
107 - amtMei.getUuid(function (result) { if ((result != null) && (result.uuid != null)) { amtMeiTmpState.UUID = result.uuid; } });
114 + if (getMeiStateCache.UUID != null) { amtMeiTmpState.UUID = getMeiStateCache.UUID; } else { amtMei.getUuid(function (result) { if ((result != null) && (result.uuid != null)) { getMeiStateCache.UUID = amtMeiTmpState.UUID = result.uuid; } }); }
115 if ((flags & 2) != 0) { amtMei.getLocalSystemAccount(function (x) { if ((x != null) && x.user && x.pass) { amtMeiTmpState.OsAdmin = { user: x.user, pass: x.pass }; } }); }
116 amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.DnsSuffix = result; } if ((flags & 4) == 0) { if (func != null) { func(amtMeiTmpState); } } });
117 if ((flags & 4) != 0) {
@@ -144,7 +151,10 @@ function AmtManager(agent, db, isdebug) {
151 amtLms.on('connect', function () { amtLmsState = 2; obj.lmsstate = 2; debug("LMS connected"); });
152 amtLms.on('bind', function (map) { obj._mapping = map; obj.emit('portBinding_LMS', map); });
153 amtLms.on('notify', function (data, options, code) { handleAmtNotification(data); });
147 - } catch (e) { amtLmsState = -1; obj.lmsstate = -1; amtLms = null; }
154 + } catch (ex) {
155 + require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "ex: " + ex });
156 + amtLmsState = -1; obj.lmsstate = -1; amtLms = null;
157 + }
158 }
159
160 }
meshagent.js
+9 -14
@@ -1135,7 +1135,6 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1135 case 'coreinfo':
1136 {
1137 // Sent by the agent to update agent information
1138 - // TODO: Check that this does not include outdates Intel AMT information
1138 ChangeAgentCoreInfo(command);
1139 break;
1140 }
@@ -1442,8 +1441,6 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1441 if (device.agent) {
1442 var changes = [], change = 0, log = 0;
1443
1445 - //if (command.users) { console.log(command.users); }
1446 -
1444 // Check if anything changes
1445 if (command.name && (typeof command.name == 'string') && (command.name != device.name)) { change = 1; log = 1; device.name = command.name; changes.push('name'); }
1446 if ((command.caps != null) && (device.agent.core != command.value)) { if ((command.value == null) && (device.agent.core != null)) { delete device.agent.core; } else { device.agent.core = command.value; } change = 1; } // Don't save this as an event to the db.
@@ -1453,18 +1450,16 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1450 if (device.ip != obj.remoteaddr) { device.ip = obj.remoteaddr; change = 1; }
1451 if (command.intelamt) {
1452 if (!device.intelamt) { device.intelamt = {}; }
1456 - if ((command.intelamt.ver != null) && (typeof command.intelamt.ver == 'string') && (command.intelamt.ver.length < 12) && (device.intelamt.ver != command.intelamt.ver)) { changes.push('AMT version'); device.intelamt.ver = command.intelamt.ver; change = 1; log = 1; }
1457 - if ((command.intelamt.sku != null) && (typeof command.intelamt.sku == 'number') && (device.intelamt.sku !== command.intelamt.sku)) { changes.push('AMT SKU'); device.intelamt.sku = command.intelamt.sku; change = 1; log = 1; }
1458 - if ((command.intelamt.state != null) && (typeof command.intelamt.state == 'number') && (device.intelamt.state != command.intelamt.state)) { changes.push('AMT state'); console.log('agent', device.intelamt.state, command.intelamt.state); device.intelamt.state = command.intelamt.state; change = 1; log = 1; }
1459 - if ((command.intelamt.flags != null) && (typeof command.intelamt.flags == 'number') && (device.intelamt.flags != command.intelamt.flags)) {
1460 - if (device.intelamt.flags) { changes.push('AMT flags (' + device.intelamt.flags + ' --> ' + command.intelamt.flags + ')'); } else { changes.push('AMT flags (' + command.intelamt.flags + ')'); }
1461 - device.intelamt.flags = command.intelamt.flags; change = 1; log = 1;
1453 + if ((command.intelamt.Versions != null) && (typeof command.intelamt.Versions == 'object')) {
1454 + if ((command.intelamt.Versions.AMT != null) && (typeof command.intelamt.Versions.AMT == 'string') && (command.intelamt.Versions.AMT.length < 12) && (device.intelamt.ver != command.intelamt.Versions.AMT)) { changes.push('AMT version'); device.intelamt.ver = command.intelamt.Versions.AMT; change = 1; log = 1; }
1455 + if ((command.intelamt.Versions.Sku != null) && (typeof command.intelamt.Versions.Sku == 'string')) { var sku = parseInt(command.intelamt.Versions.Sku); if (device.intelamt.sku !== command.intelamt.sku) { device.intelamt.sku = sku; change = 1; log = 1; } }
1456 + }
1457 + if ((command.intelamt.ProvisioningState != null) && (typeof command.intelamt.ProvisioningState == 'number') && (device.intelamt.state != command.intelamt.ProvisioningState)) { changes.push('AMT state'); device.intelamt.state = command.intelamt.ProvisioningState; change = 1; log = 1; }
1458 + if ((command.intelamt.Flags != null) && (typeof command.intelamt.Flags == 'number') && (device.intelamt.flags != command.intelamt.Flags)) {
1459 + if (device.intelamt.flags) { changes.push('AMT flags (' + device.intelamt.flags + ' --> ' + command.intelamt.Flags + ')'); } else { changes.push('AMT flags (' + command.intelamt.Flags + ')'); }
1460 + device.intelamt.flags = command.intelamt.Flags; change = 1; log = 1;
1461 }
1463 - if ((command.intelamt.realm != null) && (typeof command.intelamt.realm == 'string') && (device.intelamt.realm != command.intelamt.realm)) { changes.push('AMT realm'); device.intelamt.realm = command.intelamt.realm; change = 1; log = 1; }
1464 - //if ((command.intelamt.host != null) && (typeof command.intelamt.host == 'string') && (device.intelamt.host != command.intelamt.host)) { changes.push('AMT host'); device.intelamt.host = command.intelamt.host; change = 1; log = 1; }
1465 - if ((command.intelamt.uuid != null) && (typeof command.intelamt.uuid == 'string') && (device.intelamt.uuid != command.intelamt.uuid)) { changes.push('AMT uuid'); device.intelamt.uuid = command.intelamt.uuid; change = 1; log = 1; }
1466 - if ((command.intelamt.user != null) && (typeof command.intelamt.user == 'string') && (device.intelamt.user != command.intelamt.user)) { changes.push('AMT user'); device.intelamt.user = command.intelamt.user; change = 1; log = 1; }
1467 - if ((command.intelamt.pass != null) && (typeof command.intelamt.pass == 'string') && (device.intelamt.pass != command.intelamt.pass)) { changes.push('AMT pass'); device.intelamt.pass = command.intelamt.pass; change = 1; log = 1; }
1462 + if ((command.intelamt.UUID != null) && (typeof command.intelamt.UUID == 'string') && (device.intelamt.uuid != command.intelamt.UUID)) { changes.push('AMT uuid'); device.intelamt.uuid = command.intelamt.UUID; change = 1; log = 1; }
1463 }
1464 if (command.av) {
1465 if (!device.av) { device.av = []; }