1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Completed work on WebPowerSwitch support.

This commit is contained in:
Ylian Saint-Hilaire 2021-12-14 14:42:45 -08:00
parent 1567594ef3
commit ad3dc5fbed
5 changed files with 125 additions and 37 deletions

View file

@ -3214,15 +3214,15 @@
return false;
}
var powerStatetable = ['', "Powered", "Sleep", "Sleep", "Sleep", "Hibernating", "Power off", "Present"];
var powerStateStrings = ['', "Powered", "Sleeping", "Sleeping", "Deep Sleep", "Hibernating", "Soft-Off", "Present"];
var powerStateStrings2 = ['', "Device is powered", "Device is in sleep state (S1)", "Device is in sleep state (S2)", "Device is in deep sleep state (S3)", "Device is hibernating (S4)", "Device is in soft-off state (S5)", "Device is present, but power state cannot be determined"];
var powerStatetable = ['', "Powered", "Sleep", "Sleep", "Sleep", "Hibernating", "Power off", "Present", "Off"];
var powerStateStrings = ['', "Powered", "Sleeping", "Sleeping", "Deep Sleep", "Hibernating", "Soft-Off", "Present", "Off"];
var powerStateStrings2 = ['', "Device is powered", "Device is in sleep state (S1)", "Device is in sleep state (S2)", "Device is in deep sleep state (S3)", "Device is hibernating (S4)", "Device is in soft-off state (S5)", "Device is present, but power state cannot be determined", "The device is powered off"];
var powerColorTable = ['#00000000', 'black', 'blue', 'blue', 'lightblue', 'blueviolet', 'darkgreen', 'lightseagreen', 'lightseagreen'];
function NodeStateStr(node) {
var states = [];
if (node.state > 0 && node.state < powerStatetable.length) state.push(powerStatetable[node.state]);
if (node.conn) {
if ((node.conn & 1) != 0) { states.push('<span>' + ((node.mtype == 4)?"IP-KVM":"Agent") + '</span>'); }
if ((node.conn & 1) != 0) { states.push('<span>' + ((node.mtype == 4) ? ((node.porttype == 'PDU') ? "Switch" : "IP-KVM") : "Agent") + '</span>'); }
if ((node.conn & 2) != 0) { states.push('<span>' + "CIRA" + '</span>'); }
else if ((node.conn & 4) != 0) { states.push('<span>' + "Intel&reg; AMT" + '</span>'); }
if ((node.conn & 8) != 0) { states.push('<span>' + "Relay" + '</span>'); }
@ -3382,8 +3382,8 @@
// IP-KVM information
if (node.mtype == 4) {
if (node.portnum) { x += addDeviceAttribute("Port Number", node.portnum); }
if (node.porttype) { x += addDeviceAttribute("Port Type", node.porttype); }
if (node.portnum != null) { x += addDeviceAttribute("Port Number", node.portnum); }
if (node.porttype != null) { x += addDeviceAttribute("Port Type", node.porttype); }
}
// Attribute: Mesh Agent
@ -3486,7 +3486,7 @@
var connectivity = node.conn;
if (connectivity && connectivity > 1) {
var cstate = [];
if ((node.conn & 1) != 0) cstate.push('<span>' + ((node.mtype == 4) ? "IP-KVM" : "Agent") + '</span>');
if ((node.conn & 1) != 0) cstate.push('<span>' + ((node.mtype == 4) ? ((node.porttype == 'PDU') ? "Switch" : "IP-KVM") : "Agent") + '</span>');
if ((node.conn & 2) != 0) cstate.push('<span>' + "Intel&reg; AMT CIRA" + '</span>');
else if ((node.conn & 4) != 0) cstate.push('<span>' + "Intel&reg; AMT" + '</span>');
if ((node.conn & 8) != 0) cstate.push('<span>' + "Agent Relay" + '</span>');
@ -3519,9 +3519,21 @@
x += '</table><br />';
// Show action button, only show if we have permissions 4, 8, 64
if (((meshrights & (4 + 8 + 64)) != 0) && (node.mtype < 3)) { x += '<input type=button value="' + "Actions" + '" onclick=deviceActionFunction() />'; }
x += '<input type=button value=Notes onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
x += '<input type=button value="' + "Notes" + '" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
//if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast onclick=deviceToastFunction() />'; }
if ((node.mtype == 4) && (meshrights & 8) && (connectivity & 1)) {
if (node.porttype == 'PDU') {
if (node.pwr == 1) {
x += '<input type=button value="' + "Turn off" + '" title="' + "Turn off" + '" onclick=setIpPduState(0) />';
} else if (node.pwr == 8) {
x += '<input type=button value="' + "Turn on" + '" title="' + "Turn on" + '" onclick=setIpPduState(1) />';
}
} else {
x += '<input type=button value="' + "Remote Control" + '" title="' + "Remote Control" + '" onclick=openIpKvmRemoteControl("' + encodeURIComponentEx(node._id) + '") />';
}
}
QH('p10html', x);
// If we are looking at a local non-windows device, enable terminal and files capability.
@ -3546,11 +3558,11 @@
// Set the node power state
var powerstate = PowerStateStr(node.state);
//if (node.state == 0) { powerstate = 'Unknown State'; }
if ((connectivity & 1) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += ((node.mtype == 4) ? "IP-KVM" : "Mesh Agent"); }
if ((connectivity & 1) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += ((node.mtype == 4) ? ((node.porttype == 'PDU') ? "Switch" : "IP-KVM") : "Mesh Agent"); }
if ((connectivity & 2) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += "Intel&reg; AMT connected"; }
else if ((connectivity & 4) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += "Intel&reg; AMT detected"; }
if ((connectivity & 16) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += "MQTT channel connected"; }
if ((node.pwr > 1) && (node.pwr != 7)) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += powerStateStrings[node.pwr]; }
if ((node.porttype == 'PDU') || ((node.pwr > 1) && (node.pwr != 7))) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += powerStateStrings[node.pwr]; }
QH('MainComputerState', '<span style=font-size:12px>' + powerstate + '</span>');
// Set the node icon
@ -3585,6 +3597,20 @@
if (xxcurrentView == 10) { setupDeviceMenu(); }
}
function setIpPduState(op) {
if (op == 0) {
setDialogMode(2, "Power Operation", 3, function () { meshserver.send({ action: 'poweraction', nodeids: [currentNode._id], actiontype: 2 }); }, "Perform power off?"); // Turn off
} else {
setDialogMode(2, "Power Operation", 3, function () { meshserver.send({ action: 'wakedevices', nodeids: [currentNode._id] }); }, "Perform power on?"); // Turn on
}
}
function openIpKvmRemoteControl(nodeid) {
if (xxdialogMode) return;
var nid = decodeURIComponent(nodeid).split('/')[2];
safeNewWindow('/ipkvm.ashx/' + nid + '/', 'ipkvm:' + nid);
}
function deviceToastFunction() {
if (xxdialogMode) return;
setDialogMode(2, "Device Toast", 3, deviceToastFunctionEx, '<textarea id=d2devToast style=width:100%;height:80px;resize:none;overflow-y:scroll></textarea>');
@ -5956,7 +5982,7 @@
x += addHtmlValue("Username", currentMesh.kvm.user);
}
x += '<br><input type=button value=Notes onclick=showNotes(false,"' + encodeURIComponent(currentMesh._id) + '") />';
x += '<br><input type=button value="' + "Notes" + '" onclick=showNotes(false,"' + encodeURIComponent(currentMesh._id) + '") />';
x += '<br style=clear:both><br>';
var currentMeshLinks = currentMesh.links[userinfo._id];