mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-24 06:05:53 -05:00
Added IP-KVM port status tracking.
This commit is contained in:
parent
79e9745231
commit
448aeec6e7
39
meshipkvm.js
39
meshipkvm.js
@ -9,12 +9,11 @@
|
||||
function CreateIPKVMManager(parent) {
|
||||
const obj = {};
|
||||
const managedGroups = {} // meshid --> Manager
|
||||
const managedPorts = {} // nodeid --> PortInfo
|
||||
obj.managedPorts = {} // nodeid --> PortInfo
|
||||
|
||||
// Subscribe for mesh creation events
|
||||
parent.AddEventDispatch(['server-createmesh', 'server-deletemesh'], obj);
|
||||
obj.HandleEvent = function (source, event, ids, id) {
|
||||
console.log();
|
||||
if ((event != null) && (event.action == 'createmesh') && (event.mtype == 4)) {
|
||||
// Start managing this new device group
|
||||
startManagement(parent.webserver.meshes[event.meshid]);
|
||||
@ -54,7 +53,7 @@ function CreateIPKVMManager(parent) {
|
||||
for (var i = 0; i < manager.ports.length; i++) {
|
||||
const port = manager.ports[i];
|
||||
const nodeid = generateIpKvmNodeId(manager.meshid, port.PortId, manager.domainid);
|
||||
delete managedPorts[nodeid]; // Remove the managed port
|
||||
delete obj.managedPorts[nodeid]; // Remove the managed port
|
||||
}
|
||||
|
||||
// Remove the manager
|
||||
@ -65,11 +64,13 @@ function CreateIPKVMManager(parent) {
|
||||
|
||||
// Called when a KVM device changes state
|
||||
function onStateChanged(sender, state) {
|
||||
/*
|
||||
console.log('State: ' + ['Disconnected', 'Connecting', 'Connected'][state]);
|
||||
if (state == 2) {
|
||||
console.log('DeviceModel:', sender.deviceModel);
|
||||
console.log('FirmwareVersion:', sender.firmwareVersion);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Called when a KVM device changes state
|
||||
@ -78,8 +79,8 @@ function CreateIPKVMManager(parent) {
|
||||
const port = sender.ports[updatedPorts[i]];
|
||||
const nodeid = generateIpKvmNodeId(sender.meshid, port.PortId, sender.domainid);
|
||||
if ((port.Status == 1) && (port.Class == 'KVM')) {
|
||||
console.log(port.PortNumber + ', ' + port.PortId + ', ' + port.Name + ', ' + port.Type + ', ' + ((port.StatAvailable == 0) ? 'Idle' : 'Connected'));
|
||||
if ((managedPorts[nodeid] == null) || (managedPorts[nodeid].name != port.Name)) {
|
||||
//console.log(port.PortNumber + ', ' + port.PortId + ', ' + port.Name + ', ' + port.Type + ', ' + ((port.StatAvailable == 0) ? 'Idle' : 'Connected'));
|
||||
if ((obj.managedPorts[nodeid] == null) || (obj.managedPorts[nodeid].name != port.Name)) {
|
||||
parent.db.Get(nodeid, function (err, nodes) {
|
||||
if ((err != null) || (nodes == null)) return;
|
||||
const mesh = parent.webserver.meshes[sender.meshid];
|
||||
@ -104,26 +105,34 @@ function CreateIPKVMManager(parent) {
|
||||
}
|
||||
|
||||
// Set the connectivity state if needed
|
||||
if (managedPorts[nodeid] == null) {
|
||||
if (obj.managedPorts[nodeid] == null) {
|
||||
parent.SetConnectivityState(sender.meshid, nodeid, Date.now(), 1, 1, null, null);
|
||||
managedPorts[nodeid] = { name: port.Name, busy: false };
|
||||
obj.managedPorts[nodeid] = { name: port.Name };
|
||||
}
|
||||
|
||||
// Update busy state
|
||||
const portInfo = managedPorts[nodeid];
|
||||
if (portInfo.busy != (port.StatAvailable != 0)) {
|
||||
console.log('Busy state', (port.StatAvailable != 0));
|
||||
const portInfo = obj.managedPorts[nodeid];
|
||||
if ((portInfo.sessions != null) != (port.StatAvailable != 0)) {
|
||||
if (port.StatAvailable != 0) { portInfo.sessions = { kvm: { 'busy': 1 } } } else { delete portInfo.sessions; }
|
||||
|
||||
// Event the new sessions, this will notify everyone that agent sessions have changed
|
||||
var event = { etype: 'node', action: 'devicesessions', nodeid: nodeid, domain: sender.domainid, sessions: portInfo.sessions, nolog: 1 };
|
||||
parent.DispatchEvent(parent.webserver.CreateMeshDispatchTargets(sender.meshid, [nodeid]), obj, event);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Update busy state
|
||||
const portInfo = managedPorts[nodeid];
|
||||
if (portInfo.busy != (port.StatAvailable != 0)) {
|
||||
console.log('Busy state', (port.StatAvailable != 0));
|
||||
const portInfo = obj.managedPorts[nodeid];
|
||||
if ((portInfo.sessions != null) != (port.StatAvailable != 0)) {
|
||||
if (port.StatAvailable != 0) { portInfo.sessions = { kvm: { 'busy': 1 } } } else { delete portInfo.sessions; }
|
||||
|
||||
// Event the new sessions, this will notify everyone that agent sessions have changed
|
||||
var event = { etype: 'node', action: 'devicesessions', nodeid: nodeid, domain: sender.domainid, sessions: portInfo.sessions, nolog: 1 };
|
||||
parent.DispatchEvent(parent.webserver.CreateMeshDispatchTargets(sender.meshid, [nodeid]), obj, event);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (managedPorts[nodeid] != null) {
|
||||
if (obj.managedPorts[nodeid] != null) {
|
||||
// This port is no longer connected
|
||||
parent.ClearConnectivityState(sender.meshid, nodeid, 1, null, null);
|
||||
|
||||
@ -141,7 +150,7 @@ function CreateIPKVMManager(parent) {
|
||||
}
|
||||
|
||||
// Remove the managed port
|
||||
delete managedPorts[nodeid];
|
||||
delete obj.managedPorts[nodeid];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -816,6 +816,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
const xagent = parent.wsagents[docs[i]._id];
|
||||
if ((xagent != null) && (xagent.sessions != null)) { docs[i].sessions = xagent.sessions; }
|
||||
|
||||
// Add IP-KVM sessions
|
||||
if (parent.parent.ipKvmManager != null) {
|
||||
const xipkvmport = parent.parent.ipKvmManager.managedPorts[docs[i]._id];
|
||||
if ((xipkvmport != null) && (xipkvmport.sessions != null)) { docs[i].sessions = xipkvmport.sessions; }
|
||||
}
|
||||
|
||||
r[meshid].push(docs[i]);
|
||||
}
|
||||
try { ws.send(JSON.stringify({ action: 'nodes', responseid: command.responseid, nodes: r, tag: command.tag })); } catch (ex) { }
|
||||
|
@ -3136,9 +3136,13 @@
|
||||
if ((i == 'kvm') && (node.sessions.multidesk == null)) {
|
||||
x += '<u>' + "Remote Desktop" + '</u>';
|
||||
for (var j in node.sessions.kvm) {
|
||||
var trash = '';
|
||||
if ((j == userinfo._id) || (GetNodeRights(node) == 0xFFFFFFFF)) { trash = ' <a href=# onclick=\'return endDeviceSession("kvm", "' + encodeURIComponentEx(node._id) + '", "' + encodeURIComponentEx(j) + '")\' title="' + "Disconnect this session" + '" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
|
||||
x += addHtmlValue4(getUserName(j), ((node.sessions.kvm[j] == 1) ? "1 session" : nobreak(format("{0} sessions", node.sessions.kvm[j]))) + trash);
|
||||
if (j.startsWith('user/')) {
|
||||
var trash = '';
|
||||
if ((j == userinfo._id) || (GetNodeRights(node) == 0xFFFFFFFF)) { trash = ' <a href=# onclick=\'return endDeviceSession("kvm", "' + encodeURIComponentEx(node._id) + '", "' + encodeURIComponentEx(j) + '")\' title="' + "Disconnect this session" + '" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
|
||||
x += addHtmlValue4(getUserName(j), ((node.sessions.kvm[j] == 1) ? "1 session" : nobreak(format("{0} sessions", node.sessions.kvm[j]))) + trash);
|
||||
} else if (j == 'busy') {
|
||||
x += addHtmlValue2("Device is busy", ((node.sessions.kvm[j] == 1) ? "1 session" : nobreak(format("{0} sessions", node.sessions.kvm[j]))));
|
||||
}
|
||||
}
|
||||
} else if (i == 'multidesk') {
|
||||
x += '<u>' + "Remote Desktop" + '</u>';
|
||||
@ -3218,7 +3222,7 @@
|
||||
var states = [];
|
||||
if (node.state > 0 && node.state < powerStatetable.length) state.push(powerStatetable[node.state]);
|
||||
if (node.conn) {
|
||||
if ((node.conn & 1) != 0) { if (node.mtype == 4) { states.push('<span>' + ((node.mtype == 4)?"IP-KVM":"Agent") + '</span>'); } else { states.push('<span>' + "IP KVM" + '</span>'); } }
|
||||
if ((node.conn & 1) != 0) { states.push('<span>' + ((node.mtype == 4)?"IP-KVM":"Agent") + '</span>'); }
|
||||
if ((node.conn & 2) != 0) { states.push('<span>' + "CIRA" + '</span>'); }
|
||||
else if ((node.conn & 4) != 0) { states.push('<span>' + "Intel® AMT" + '</span>'); }
|
||||
if ((node.conn & 8) != 0) { states.push('<span>' + "Relay" + '</span>'); }
|
||||
@ -3514,7 +3518,7 @@
|
||||
|
||||
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() />'; }
|
||||
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) + '") />';
|
||||
//if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast onclick=deviceToastFunction() />'; }
|
||||
|
||||
@ -3542,7 +3546,7 @@
|
||||
// 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 += ((mesh.mtype == 4) ? "IP-KVM" : "Mesh Agent"); }
|
||||
if ((connectivity & 1) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += ((node.mtype == 4) ? "IP-KVM" : "Mesh Agent"); }
|
||||
if ((connectivity & 2) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += "Intel® AMT connected"; }
|
||||
else if ((connectivity & 4) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += "Intel® AMT detected"; }
|
||||
if ((connectivity & 16) != 0) { if (powerstate.length > 0) { powerstate += ', '; } powerstate += "MQTT channel connected"; }
|
||||
|
@ -3994,7 +3994,7 @@
|
||||
else if ((sort == 3) || (sort == 4)) { collapseName = 'tag:**xx**xx*TaG*xx**xx**'; }
|
||||
var collapsed = (sort != 3) & (sort != 4) & CollapsedGroups[collapseName];
|
||||
r += '<tr name=xxdevice2 colname=DevxCol' + collapseName + ' style=height:20px' + (collapsed?';display:none':'') + ' id=xv2' + node._id + '></tr>';
|
||||
} else if (((view == 3) || (view == 5)) && (node.conn & 1) && (((meshrights & 8) || (meshrights & 256)) != 0) && ((node.agent.caps & 1) != 0)) { // Check if we have rights and agent is capable of KVM.
|
||||
} else if (((view == 3) || (view == 5)) && (node.conn & 1) && (((meshrights & 8) || (meshrights & 256)) != 0) && (node.agent) && ((node.agent.caps & 1) != 0)) { // Check if we have rights and agent is capable of KVM.
|
||||
// Draw the device (TODO: See if we can replace this with a standin in the future)
|
||||
if ((Object.keys(checkedNodeids).length == 0) || checkedNodeids[node._id]) {
|
||||
r += updateDeviceViewHtml(view, null, node);
|
||||
@ -4494,9 +4494,13 @@
|
||||
if ((i == 'kvm') && (node.sessions.multidesk == null)) {
|
||||
x += '<u>' + "Remote Desktop" + '</u>';
|
||||
for (var j in node.sessions.kvm) {
|
||||
var trash = '';
|
||||
if ((j == userinfo._id) || (GetNodeRights(node) == 0xFFFFFFFF)) { trash = ' <a href=# onclick=\'return endDeviceSession("kvm", "' + encodeURIComponentEx(node._id) + '", "' + encodeURIComponentEx(j) + '")\' title="' + "Disconnect this session" + '" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
|
||||
x += addHtmlValue2(getUserName(j), ((node.sessions.kvm[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.kvm[j]))) + trash);
|
||||
if (j.startsWith('user/')) {
|
||||
var trash = '';
|
||||
if (((j == userinfo._id) || (GetNodeRights(node) == 0xFFFFFFFF))) { trash = ' <a href=# onclick=\'return endDeviceSession("kvm", "' + encodeURIComponentEx(node._id) + '", "' + encodeURIComponentEx(j) + '")\' title="' + "Disconnect this session" + '" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>'; }
|
||||
x += addHtmlValue2(getUserName(j), ((node.sessions.kvm[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.kvm[j]))) + trash);
|
||||
} else if (j == 'busy') {
|
||||
x += addHtmlValue2("Device is busy", ((node.sessions.kvm[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.kvm[j]))));
|
||||
}
|
||||
}
|
||||
} else if (i == 'multidesk') {
|
||||
x += '<u>' + "Remote Desktop" + '</u>';
|
||||
|
Loading…
Reference in New Issue
Block a user