From 9df9de0922611e92e9f9bb201bdc82ac8c8adf6c Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Wed, 7 Oct 2020 12:44:50 -0700 Subject: [PATCH] AMT manager improvements. --- amtmanager.js | 31 ++++++++++++++++++------------- views/default-mobile.handlebars | 2 +- views/default.handlebars | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/amtmanager.js b/amtmanager.js index 07260ab0..812b755f 100644 --- a/amtmanager.js +++ b/amtmanager.js @@ -40,20 +40,25 @@ module.exports.CreateAmtManager = function(parent) { // Handle server events obj.HandleEvent = function (source, event, ids, id) { - if (event.action != 'nodeconnect') return; - if ((event.conn & 14) != 0) { // connectType: Bitmask, 1 = MeshAgent, 2 = Intel AMT CIRA, 4 = Intel AMT local, 8 = Intel AMT Relay, 16 = MQTT - // We have an OOB connection to Intel AMT, update our information - var dev = obj.amtDevices[event.nodeid]; - if (dev == null) { obj.amtDevices[event.nodeid] = dev = { conn: event.conn }; fetchIntelAmtInformation(event.nodeid); } else { dev.conn = event.conn; } - } else if (((event.conn & 1) != 0) && (parent.webserver != null)) { - // We have an agent connection without OOB, check if this agent supports Intel AMT - var agent = parent.webserver.wsagents[event.nodeid]; - if ((agent == null) || (agent.agentInfo == null) || (parent.meshAgentsArchitectureNumbers[agent.agentInfo.agentId].amt == false)) { removeDevice(event.nodeid); return; } - var dev = obj.amtDevices[event.nodeid]; - if (dev == null) { obj.amtDevices[event.nodeid] = dev = { conn: event.conn }; fetchIntelAmtInformation(event.nodeid); } else { dev.conn = event.conn; } - } else { - removeDevice(event.nodeid); + // React to nodes connecting and disconnecting + if (event.action == 'nodeconnect') { + if ((event.conn & 14) != 0) { // connectType: Bitmask, 1 = MeshAgent, 2 = Intel AMT CIRA, 4 = Intel AMT local, 8 = Intel AMT Relay, 16 = MQTT + // We have an OOB connection to Intel AMT, update our information + var dev = obj.amtDevices[event.nodeid]; + if (dev == null) { obj.amtDevices[event.nodeid] = dev = { conn: event.conn }; fetchIntelAmtInformation(event.nodeid); } else { dev.conn = event.conn; } + } else if (((event.conn & 1) != 0) && (parent.webserver != null)) { + // We have an agent connection without OOB, check if this agent supports Intel AMT + var agent = parent.webserver.wsagents[event.nodeid]; + if ((agent == null) || (agent.agentInfo == null) || (parent.meshAgentsArchitectureNumbers[agent.agentInfo.agentId].amt == false)) { removeDevice(event.nodeid); return; } + var dev = obj.amtDevices[event.nodeid]; + if (dev == null) { obj.amtDevices[event.nodeid] = dev = { conn: event.conn }; fetchIntelAmtInformation(event.nodeid); } else { dev.conn = event.conn; } + } else { + removeDevice(event.nodeid); + } } + + // React to node being removed + if (event.action == 'removenode') { removeDevice(event.nodeid); } } // Remove a device diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars index fa47a02a..1aff4d7d 100644 --- a/views/default-mobile.handlebars +++ b/views/default-mobile.handlebars @@ -1472,7 +1472,7 @@ } case 'ifchange': { // Network interface changed for a device, if we are currently viewing this device, ask for an update. - if (currentNode._id == message.event.nodeid) { meshserver.send({ action: 'getnetworkinfo', nodeid: currentNode._id }); } + if ((currentNode != null) && (currentNode._id == message.event.nodeid)) { meshserver.send({ action: 'getnetworkinfo', nodeid: currentNode._id }); } break; } case 'devicesessions': { diff --git a/views/default.handlebars b/views/default.handlebars index 0c49f443..2e4da2f9 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -2955,7 +2955,7 @@ } case 'ifchange': { // Network interface changed for a device, if we are currently viewing this device, ask for an update. - if (currentNode._id == message.event.nodeid) { meshserver.send({ action: 'getnetworkinfo', nodeid: currentNode._id }); } + if ((currentNode != null) && (currentNode._id == message.event.nodeid)) { meshserver.send({ action: 'getnetworkinfo', nodeid: currentNode._id }); } break; } case 'devicesessions': {