Added Intel AMT power actions.

Ylian Saint-Hilaire committed Mar 25, 2021 at 00:17 UTC 7bf0681f5be588d26688a0517e91a6ea6282d967
5 files changed +35 -8
amtmanager.js
+6
@@ -300,6 +300,11 @@ module.exports.CreateAmtManager = function (parent) {
300 if (Array.isArray(event.nodeids)) { for (var i in event.nodeids) { performOneClickRecoveryAction(event.nodeids[i], event.file); } }
301 break;
302 }
303 + case 'amtpoweraction': {
304 + if (event.noact == 1) return; // Take no action on these events. We are likely in peering mode and need to only act when the database signals the change in state.
305 + if (Array.isArray(event.nodeids)) { for (var i in event.nodeids) { performPowerAction(event.nodeids[i], event.actiontype); } }
306 + break;
307 + }
308 case 'changenode': { // React to changes in a device
309 var devices = obj.amtDevices[event.nodeid], rescan = false;
310 if (devices != null) {
@@ -799,6 +804,7 @@ module.exports.CreateAmtManager = function (parent) {
804 var dev = devices[i];
805 // If not LMS, has a AMT stack present and is in connected state, perform power operation.
806 if ((dev.connType != 2) && (dev.state == 1) && (dev.amtstack != null)) {
807 + // Action: 2 = Power on, 8 = Power down, 10 = reset
808 try { dev.amtstack.RequestPowerStateChange(action, performPowerActionResponse); } catch (ex) { }
809 }
810 }
meshuser.js
+12 -5
@@ -3930,7 +3930,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3930 case 'poweraction':
3931 {
3932 if (common.validateArray(command.nodeids, 1) == false) break; // Check nodeid's
3933 - if (common.validateInt(command.actiontype, 2, 4) == false) break; // Check actiontype
3933 + if (common.validateInt(command.actiontype, 2, 310) == false) break; // Check actiontype
3934 for (i in command.nodeids) {
3935 var nodeid = command.nodeids[i];
3936
@@ -3947,10 +3947,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3947 // If this device is connected on MQTT, send a power action.
3948 if (parent.parent.mqttbroker != null) { parent.parent.mqttbroker.publish(node._id, 'powerAction', ['', '', 'poweroff', 'reset', 'sleep'][command.actiontype]); }
3949
3950 - // Get this device and send the power command
3951 - const agent = parent.wsagents[node._id];
3952 - if (agent != null) {
3953 - try { agent.send(JSON.stringify({ action: 'poweraction', actiontype: command.actiontype })); } catch (ex) { }
3950 + if (command.actiontype >= 300) {
3951 + if ((command.actiontype != 302) && (command.actiontype != 308) && (command.actiontype != 310)) return; // Invalid action type.
3952 + // Intel AMT power command, actiontype: 2 = Power on, 8 = Power down, 10 = reset
3953 + parent.parent.DispatchEvent('*', obj, { action: 'amtpoweraction', userid: user._id, username: user.name, nodeids: [node._id], domain: domain.id, nolog: 1, actiontype: command.actiontype - 300 });
3954 + } else {
3955 + if ((command.actiontype < 2) && (command.actiontype > 4)) return; // Invalid action type.
3956 + // Mesh Agent power command, get this device and send the power command
3957 + const agent = parent.wsagents[node._id];
3958 + if (agent != null) {
3959 + try { agent.send(JSON.stringify({ action: 'poweraction', actiontype: command.actiontype })); } catch (ex) { }
3960 + }
3961 }
3962 });
3963
public/styles/style.css
+1 -1
@@ -2385,7 +2385,7 @@ a {
2385 grid-area: deskarea1;
2386 -ms-grid-column: 1;
2387 -ms-grid-row: 1;
2388 - height: 20px;
2388 + height: 24px;
2389 }
2390
2391
views/default-mobile.handlebars
+2 -1
@@ -4861,7 +4861,8 @@
4861 if ((node.intelamt.state == 2) && node.intelamt.flags) { if (node.intelamt.flags & 2) { provisioningMode = (', ' + "Client Control Mode (CCM)"); } else if (node.intelamt.flags & 4) { provisioningMode = (', ' + "Admin Control Mode (ACM)"); } }
4862 x += addDetailItem("Provisioning State", ((node.intelamt.state) ? (provisioningStates[node.intelamt.state]) : ('<i>' + "Unknown" + '</i>')) + provisioningMode, s);
4863 x += addDetailItem("Security", (node.intelamt.tls == 1) ? "Secured using TLS" : "TLS is not setup", s);
4864 - x += addDetailItem("Admin Credentials", (node.intelamt.user == null || node.intelamt.user == '') ? "Not Known" : "Known", s);
4864 + // Check that the Intel AMT user is setup and there is no warnings (1 = invalid credentials, 8 = trying)
4865 + x += addDetailItem("Admin Credentials", ((node.intelamt.user) == null || (node.intelamt.user == '') || ((node.intelamt.warn != null) && ((node.intelamt.warn & 9) != 0))) ? "Not Known" : "Known", s);
4866 if (x != '') { sections.push({ name: "Intel&reg; Active Management Technology (Intel&reg; AMT)", html: x, img: 'amt' }); }
4867 }
4868
views/default.handlebars
+14 -1
@@ -6613,6 +6613,12 @@
6613 if (((currentNode.conn & 1) != 0) && ((rights & 131072) != 0)) { count++; y += '<option value=106>' + "Run Commands" + '</option>'; } // Remote command permission
6614 if ((currentNode.conn != 0) && ((rights & 262144) != 0)) { count++; y += '<option value=4>' + "Sleep" + '</option><option value=3>' + "Reset" + '</option><option value=2>' + "Power off" + '</option>'; }
6615 if ((currentNode.conn & 16) != 0) { count++; y += '<option value=103>' + "Send MQTT Message" + '</option>'; }
6616 + if ((currentNode.intelamt != null) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && (rights == 0xFFFFFFFF)) {
6617 + count++;
6618 + y += '<option value=310>' + "Intel&reg; AMT Reset" + '</option>';
6619 + y += '<option value=302>' + "Intel&reg; AMT Power on" + '</option>';
6620 + y += '<option value=308>' + "Intel&reg; AMT Power off" + '</option>';
6621 + }
6622 if ((getNodeAmtVersion(currentNode) >= 15) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && (rights == 0xFFFFFFFF) && ((features & 0x00000400) == 0)) { count++; y += '<option value=107>' + "Intel&reg; AMT One Click Recovery" + '</option>'; } // CIRA (2) or AMT (4) connected
6623 if (((currentNode.conn & 1) != 0) && ((rights & 32768) != 0)) { count++; y += '<option value=104>' + "Uninstall Agent" + '</option>'; }
6624 y += '</select>';
@@ -6658,6 +6664,12 @@
6664 Q('d3attrib').value = currentNode._id;
6665 setDialogMode(3, "Intel&reg; AMT One Click Recovery", 3, deviceActionOneClickRecovery);
6666 d3init();
6667 + } else if (op == 302) { // Intel AMT power on
6668 + setDialogMode(2, "Intel&reg; AMT Power Operation", 3, function() { meshserver.send({ action: 'poweraction', nodeids: [ currentNode._id ], actiontype: parseInt(op) }); }, "Perform Intel&reg; AMT power on?");
6669 + } else if (op == 308) { // Intel AMT power off
6670 + setDialogMode(2, "Intel&reg; AMT Power Operation", 3, function() { meshserver.send({ action: 'poweraction', nodeids: [ currentNode._id ], actiontype: parseInt(op) }); }, "Perform Intel&reg; AMT power off?");
6671 + } else if (op == 310) { // Intel AMT reset
6672 + setDialogMode(2, "Intel&reg; AMT Power Operation", 3, function() { meshserver.send({ action: 'poweraction', nodeids: [ currentNode._id ], actiontype: parseInt(op) }); }, "Perform Intel&reg; AMT reset?");
6673 } else {
6674 // Power operation
6675 meshserver.send({ action: 'poweraction', nodeids: [ currentNode._id ], actiontype: parseInt(op) });
@@ -9378,7 +9390,8 @@
9390 if ((node.intelamt.state == 2) && node.intelamt.flags) { if (node.intelamt.flags & 2) { provisioningMode = (', ' + "Client Control Mode (CCM)"); } else if (node.intelamt.flags & 4) { provisioningMode = (', ' + "Admin Control Mode (ACM)"); } }
9391 x += addDetailItem("Provisioning State", ((node.intelamt.state)?(provisioningStates[node.intelamt.state]):('<i>' + "Unknown" + '</i>')) + provisioningMode, s);
9392 x += addDetailItem("Security", (node.intelamt.tls == 1)?"Secured using TLS":"TLS is not setup", s);
9381 - x += addDetailItem("Admin Credentials", (node.intelamt.user == null || node.intelamt.user == '')?"Not Known":"Known", s);
9393 + // Check that the Intel AMT user is setup and there is no warnings (1 = invalid credentials, 8 = trying)
9394 + x += addDetailItem("Admin Credentials", ((node.intelamt.user) == null || (node.intelamt.user == '') || ((node.intelamt.warn != null) && ((node.intelamt.warn & 9) != 0)))?"Not Known":"Known", s);
9395 if (x != '') { sections.push({ name: "Intel&reg; Active Management Technology (Intel&reg; AMT)", html: x, img: 'amt64.png' }); }
9396 }
9397