Intel AMT power actions permissions improvements, #4159
Ylian Saint-Hilaire committed
Jun 23, 2022 at 12:23 UTC
89c152027f96c7f81d2a13190a485bb0bafe1b39
3 files changed
+15
-37
meshuser.js
+3
-2
@@ -2867,8 +2867,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2867
if ((command.actiontype == 400) && common.validateInt(command.time, 1, 30000)) { routeCommandToNode({ action: 'msg', type: 'console', nodeid: node._id, value: 'flash ' + command.time }, MESHRIGHT_ADMIN, 0); }
2868
if ((command.actiontype == 401) && common.validateInt(command.time, 1, 30000)) { routeCommandToNode({ action: 'msg', type: 'console', nodeid: node._id, value: 'vibrate ' + command.time }, MESHRIGHT_ADMIN, 0); }
2869
} else {
2870
- // Check we have the rights to delete this device
2871
- if ((rights & MESHRIGHT_RESETOFF) == 0) return;
2870
+ // Check we have the rights to perform this operation
2871
+ if ((command.actiontype == 302) && ((rights & MESHRIGHT_WAKEDEVICE) == 0)) return; // This is a Intel AMT power on operation, check if we have WAKE rights
2872
+ if ((command.actiontype != 302) && ((rights & MESHRIGHT_RESETOFF) == 0)) return; // For all other operations, check that we have RESET/OFF rights
2873
2874
// If this device is connected on MQTT, send a power action.
2875
if ((parent.parent.mqttbroker != null) && (command.actiontype >= 0) && (command.actiontype <= 4)) { parent.parent.mqttbroker.publish(node._id, 'powerAction', ['', '', 'poweroff', 'reset', 'sleep'][command.actiontype]); }
views/default-mobile.handlebars
+6
-32
@@ -3541,7 +3541,7 @@
3541
3542
x += '</table><br />';
3543
// Show action button, only show if we have permissions 4, 8, 64
3544
- if (((meshrights & (4 + 8 + 64)) != 0) && (node.mtype < 3)) { x += '<input type=button value="' + "Actions" + '" onclick=deviceActionFunction() />'; }
3544
+ if (((meshrights & (4 + 8 + 64 + 262144)) != 0) && (node.mtype < 3)) { x += '<input type=button value="' + "Actions" + '" onclick=deviceActionFunction() />'; }
3545
x += '<input type=button value="' + "Notes" + '" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
3546
//if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast onclick=deviceToastFunction() />'; }
3547
@@ -3676,35 +3676,6 @@
3676
if (currentDevicePanel == 1) { deskAdjust(); }
3677
}
3678
3679
- /*
3680
- function deviceActionFunction() {
3681
- if (xxdialogMode) return;
3682
- var rights = GetNodeRights(currentNode), count = 0;
3683
- var x = "Select an operation to perform on this device." + '<br /><br />';
3684
- var y = '<select id=d2deviceop style=float:right;width:170px>';
3685
- if ((rights & 64) != 0) { count++; y += '<option value=100>' + "Wake-up" + '</option>'; } // Wake-up permission
3686
- //if (((currentNode.conn & 1) != 0) && ((rights & 131072) != 0)) { count++; y += '<option value=106>' + "Run Commands" + '</option>'; } // Remote command permission
3687
- 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>'; }
3688
- //if ((currentNode.conn & 16) != 0) { count++; y += '<option value=103>' + "Send MQTT Message" + '</option>'; }
3689
- //if (((currentNode.conn & 1) != 0) && ((rights & 32768) != 0)) { count++; y += '<option value=104>' + "Uninstall Agent" + '</option>'; }
3690
- y += '</select>';
3691
- x += addHtmlValue("Operation", y);
3692
- if (count == 0) { x = "No actions currently available for this device."; }
3693
- setDialogMode(2, "Device Action", (count == 0) ? 1 : 3, deviceActionFunctionEx, x);
3694
- }
3695
-
3696
- function deviceActionFunctionEx() {
3697
- var op = Q('d2deviceop').value;
3698
- if (op == 100) {
3699
- // Device wake
3700
- meshserver.send({ action: 'wakedevices', nodeids: [currentNode._id] });
3701
- } else {
3702
- // Power operation
3703
- meshserver.send({ action: 'poweraction', nodeids: [currentNode._id], actiontype: op });
3704
- }
3705
- }
3706
- */
3707
-
3679
function deviceActionFunction() {
3680
if (xxdialogMode) return;
3681
var rights = GetNodeRights(currentNode), count = 0;
@@ -3723,12 +3694,15 @@
3694
//if (((currentNode.conn & 1) != 0) && ((rights & 131072) != 0)) { count++; y += '<option value=106>' + "Run Commands" + '</option>'; } // Remote command permission
3695
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>'; }
3696
//if ((currentNode.conn & 16) != 0) { count++; y += '<option value=103>' + "Send MQTT Message" + '</option>'; }
3726
- if ((currentNode.intelamt != null) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && (rights == 0xFFFFFFFF)) {
3697
+ if ((currentNode.intelamt != null) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && ((rights & 262144) != 0)) {
3698
count++;
3699
y += '<option value=310>' + "Intel® AMT Reset" + '</option>';
3729
- y += '<option value=302>' + "Intel® AMT Power on" + '</option>';
3700
y += '<option value=308>' + "Intel® AMT Power off" + '</option>';
3701
}
3702
+ if ((currentNode.intelamt != null) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && ((rights & 64) != 0)) {
3703
+ count++;
3704
+ y += '<option value=302>' + "Intel® AMT Power on" + '</option>';
3705
+ }
3706
//if ((getNodeAmtVersion(currentNode) >= 15) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && (rights == 0xFFFFFFFF) && ((features & 0x00000400) == 0)) { count++; y += '<option value=107>' + "Intel® AMT One Click Recovery" + '</option>'; } // CIRA (2) or AMT (4) connected
3707
//if (((currentNode.conn & 1) != 0) && ((rights & 32768) != 0)) { count++; y += '<option value=104>' + "Uninstall Agent" + '</option>'; }
3708
}
views/default.handlebars
+6
-3
@@ -7072,7 +7072,7 @@
7072
7073
x += '</table><br />';
7074
// Show action button, only show if we have permissions 4, 8, 64
7075
- if (((meshrights & (4 + 8 + 64)) != 0) && (node.mtype < 3) && ((node.agent == null) || (node.agent.id != 34))) { x += '<input type=button value="' + "Actions" + '" title="' + "Perform power actions on the device" + '" onclick=deviceActionFunction() />'; }
7075
+ if (((meshrights & (4 + 8 + 64 + 262144)) != 0) && (node.mtype < 3) && ((node.agent == null) || (node.agent.id != 34))) { x += '<input type=button value="' + "Actions" + '" title="' + "Perform power actions on the device" + '" onclick=deviceActionFunction() />'; }
7076
x += '<input type=button value="' + "Notes" + '" title="' + "View notes about this device" + '" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponentEx(node._id) + '") />';
7077
x += '<input type=button value="' + "Log Event" + '" title="' + "Write an event for this device" + '" onclick=writeDeviceEvent("' + encodeURIComponentEx(node._id) + '") />';
7078
if (node.mtype != 4) {
@@ -7766,12 +7766,15 @@
7766
if (((currentNode.conn & 1) != 0) && ((rights & 131072) != 0)) { count++; y += '<option value=106>' + "Run Commands" + '</option>'; } // Remote command permission
7767
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>'; }
7768
if ((currentNode.conn & 16) != 0) { count++; y += '<option value=103>' + "Send MQTT Message" + '</option>'; }
7769
- if ((currentNode.intelamt != null) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && (rights == 0xFFFFFFFF)) {
7769
+ if ((currentNode.intelamt != null) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && ((rights & 262144) != 0)) {
7770
count++;
7771
y += '<option value=310>' + "Intel® AMT Reset" + '</option>';
7772
- y += '<option value=302>' + "Intel® AMT Power on" + '</option>';
7772
y += '<option value=308>' + "Intel® AMT Power off" + '</option>';
7773
}
7774
+ if ((currentNode.intelamt != null) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && ((rights & 64) != 0)) {
7775
+ count++;
7776
+ y += '<option value=302>' + "Intel® AMT Power on" + '</option>';
7777
+ }
7778
if ((getNodeAmtVersion(currentNode) >= 15) && (currentNode.intelamt.state == 2) && ((currentNode.conn & 6) != 0) && (rights == 0xFFFFFFFF) && ((features & 0x00000400) == 0)) { count++; y += '<option value=107>' + "Intel® AMT One Click Recovery" + '</option>'; } // CIRA (2) or AMT (4) connected
7779
if (((currentNode.conn & 1) != 0) && ((rights & 32768) != 0)) { count++; y += '<option value=104>' + "Uninstall Agent" + '</option>'; }
7780
}