mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-22 12:52:50 +03:00
More device session notification work.
This commit is contained in:
parent
2ca1817065
commit
6431974136
@ -1403,6 +1403,7 @@ function createMeshCore(agent) {
|
||||
if (this.httprequest.desktop.kvm.tunnels != null) {
|
||||
for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } }
|
||||
for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } }
|
||||
try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
|
||||
}
|
||||
|
||||
this.end = function () {
|
||||
@ -1417,6 +1418,7 @@ function createMeshCore(agent) {
|
||||
if (this.httprequest.desktop.kvm.tunnels != null) {
|
||||
for (var i in this.httprequest.desktop.kvm.tunnels) { try { var userid = this.httprequest.desktop.kvm.tunnels[i].httprequest.userid; if (users[userid] == null) { users[userid] = 1; } else { users[userid]++; } } catch (ex) { } }
|
||||
for (var i in this.httprequest.desktop.kvm.tunnels) { try { this.httprequest.desktop.kvm.tunnels[i].write(JSON.stringify({ ctrlChannel: '102938', type: 'metadata', users: users })); } catch (ex) { } }
|
||||
try { mesh.SendCommand({ action: 'sessions', type: 'kvm', value: users }); } catch (ex) { }
|
||||
}
|
||||
|
||||
// Unpipe the web socket
|
||||
|
18
meshagent.js
18
meshagent.js
@ -1327,6 +1327,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'sessions': {
|
||||
// This is a list of sessions provided by the agent
|
||||
if (obj.sessions == null) { obj.sessions = {}; }
|
||||
if (command.type == 'kvm') { obj.sessions.kvm = command.value; }
|
||||
obj.updateSessions();
|
||||
break;
|
||||
}
|
||||
case 'plugin': {
|
||||
if ((parent.parent.pluginHandler == null) || (typeof command.plugin != 'string')) break;
|
||||
try {
|
||||
@ -1350,6 +1357,17 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||
}
|
||||
}
|
||||
|
||||
// Notify update of sessions
|
||||
obj.updateSessions = function () {
|
||||
// Perform some clean up
|
||||
for (var i in obj.sessions) { if (Object.keys(obj.sessions[i]).length == 0) { delete obj.sessions[i]; } }
|
||||
if (Object.keys(obj.sessions).length == 0) { delete obj.sessions; }
|
||||
|
||||
// Event the new sessions, this will notify everyone that agent sessions have changed
|
||||
var event = { etype: 'node', action: 'devicesessions', nodeid: obj.dbNodeKey, domain: domain.id, sessions: obj.sessions, nolog: 1 };
|
||||
parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(obj.dbMeshKey, [obj.dbNodeKey]), obj, event);
|
||||
}
|
||||
|
||||
// Change the current core information string and event it
|
||||
function ChangeAgentCoreInfo(command) {
|
||||
if (obj.agentInfo.capabilities & 0x40) return;
|
||||
|
@ -260,6 +260,9 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
|
||||
obj.startTime = null;
|
||||
}
|
||||
|
||||
// Send an updated list of all peers to all viewers
|
||||
obj.sendSessionMetadata();
|
||||
|
||||
parent.parent.debug('relay', 'DesktopRelay: Disposing desktop multiplexor');
|
||||
}
|
||||
|
||||
@ -307,10 +310,20 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) {
|
||||
// Send the list of all users currently vieweing this session to all viewers and servers
|
||||
obj.sendSessionMetadata = function () {
|
||||
var allUsers = {};
|
||||
for (var i in obj.viewers) { var v = obj.viewers[i]; if ((v.user != null) && (v.user._id != null)) { if (allUsers[v.user._id] == null) { allUsers[v.user._id] = 1; } else { allUsers[v.user._id]++; } } }
|
||||
obj.sendToAllViewers(JSON.stringify({ type: 'metadata', 'ctrlChannel': '102938', users: allUsers, startTime: obj.startTime }));
|
||||
if (obj.viewers != null) {
|
||||
for (var i in obj.viewers) { var v = obj.viewers[i]; if ((v.user != null) && (v.user._id != null)) { if (allUsers[v.user._id] == null) { allUsers[v.user._id] = 1; } else { allUsers[v.user._id]++; } } }
|
||||
obj.sendToAllViewers(JSON.stringify({ type: 'metadata', 'ctrlChannel': '102938', users: allUsers, startTime: obj.startTime }));
|
||||
}
|
||||
|
||||
// TODO: Update the servers
|
||||
// Update the sessions attached the to agent
|
||||
if (obj.nodeid != null) {
|
||||
const xagent = parent.wsagents[obj.nodeid];
|
||||
if (xagent != null) {
|
||||
if (xagent.sessions == null) { xagent.sessions = {}; }
|
||||
xagent.sessions.multidesk = allUsers;
|
||||
xagent.updateSessions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send this command to all viewers
|
||||
|
@ -586,6 +586,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
if (docs[i].userloc != null) { delete docs[i].userloc; }
|
||||
}
|
||||
|
||||
// Add device sessions
|
||||
const xagent = parent.wsagents[docs[i]._id];
|
||||
if ((xagent != null) && (xagent.sessions != null)) { docs[i].sessions = xagent.sessions; }
|
||||
|
||||
r[meshid].push(docs[i]);
|
||||
}
|
||||
try { ws.send(JSON.stringify({ action: 'nodes', responseid: command.responseid, nodes: r, tag: command.tag })); } catch (ex) { }
|
||||
|
@ -784,6 +784,25 @@ NoMeshesPanel img {
|
||||
background-color:#44F;
|
||||
}
|
||||
|
||||
.deviceNotifyLargeDot {
|
||||
text-align:center;
|
||||
position:absolute;
|
||||
right:10px;
|
||||
top:140px;
|
||||
width:40px;
|
||||
height:40px;
|
||||
color:#FFF;
|
||||
padding:2px;
|
||||
background-color:#00F;
|
||||
border-radius:20px;
|
||||
box-shadow: 2px 2px 10px black;
|
||||
cursor:pointer;
|
||||
}
|
||||
|
||||
.deviceNotifyLargeDot:hover {
|
||||
background-color:#44F;
|
||||
}
|
||||
|
||||
#xdevices {
|
||||
max-height: calc(100vh - 242px);
|
||||
overflow-y: auto;
|
||||
|
@ -485,7 +485,8 @@
|
||||
<div id=p10html></div>
|
||||
</td>
|
||||
<td style=width:20px></td>
|
||||
<td style=width:200px;vertical-align:top valign=top>
|
||||
<td style=width:200px;vertical-align:top;position:relative valign=top>
|
||||
<img id="p10deviceNotify" onclick=showDeviceSessions() class=deviceNotifyLargeDot src=images/icon-relay-notify.png width=16 height=16>
|
||||
<a href=# onclick=p10showiconselector()><img id=MainComputerImage></a>
|
||||
<div id=MainComputerState></div>
|
||||
</td>
|
||||
@ -2720,6 +2721,23 @@
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'devicesessions': {
|
||||
// List of sessions for a given device
|
||||
var node = getNodeFromId(message.event.nodeid);
|
||||
if (node == null) break; // Unknown node
|
||||
node.sessions = message.event.sessions;
|
||||
if (node.sessions != null) {
|
||||
for (var i in node.sessions) { if (Object.keys(node.sessions[i]).length == 0) { delete node.sessions[i]; } }
|
||||
if (Object.keys(node.sessions).length == 0) { delete node.sessions; }
|
||||
}
|
||||
masterUpdate(4);
|
||||
if ((currentNode != null) && (currentNode._id == message.event.nodeid)) { gotoDevice(currentNode._id, xxcurrentView, true); }
|
||||
|
||||
// If we are looking at the sessions dialog box for this device now, update it
|
||||
if (xxdialogTag == ('SESSIONS-' + message.event.nodeid)) { showDeviceSessions(message.event.nodeid, true); }
|
||||
|
||||
break;
|
||||
}
|
||||
case 'stopped': { // Server is stopping.
|
||||
// Disconnect
|
||||
//console.log(message.msg);
|
||||
@ -3404,13 +3422,21 @@
|
||||
}
|
||||
|
||||
// Show currently active sessions on this device
|
||||
function showDeviceSessions(nodeid) {
|
||||
if (xxdialogMode) return;
|
||||
var node = getNodeFromId(nodeid), x = '';
|
||||
if (node == null) return;
|
||||
console.log(node.sessions);
|
||||
x += addHtmlValue4("User", '1 session'); // TODO
|
||||
setDialogMode(2, "Sessions - " + EscapeHtml(node.name), 1, null, x, 'SESSIONS-' + nodeid);
|
||||
function showDeviceSessions(nodeid, force) {
|
||||
if (xxdialogMode && !force) return;
|
||||
var node = null, x = '';
|
||||
if (nodeid == null) { node = currentNode; } else { node = getNodeFromId(nodeid); }
|
||||
if ((node == null) || (node.sessions == null)) { setDialogMode(0); return; }
|
||||
for (var i in node.sessions) {
|
||||
if ((i == 'kvm') && (node.sessions.multidesk == null)) {
|
||||
x += '<u>' + "Remote Desktop" + '</u>';
|
||||
for (var j in node.sessions.kvm) { x += addHtmlValue4(getUserName(j), (node.sessions.kvm[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.kvm[j]))); }
|
||||
} else if (i == 'multidesk') {
|
||||
x += '<u>' + "Remote Desktop" + '</u>';
|
||||
for (var j in node.sessions.multidesk) { x += addHtmlValue4(getUserName(j), ((node.sessions.multidesk[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.multidesk[j])))); }
|
||||
}
|
||||
}
|
||||
if (x != '') setDialogMode(2, "Sessions - " + EscapeHtml(node.name), 1, null, x, 'SESSIONS-' + node._id);
|
||||
}
|
||||
|
||||
function toggleCollapseGroup(id, id2, type) {
|
||||
@ -4950,6 +4976,9 @@
|
||||
if (!currentNode || currentNode._id != node._id || refresh == true) {
|
||||
currentNode = node;
|
||||
|
||||
// Device Notification
|
||||
QV('p10deviceNotify', currentNode.sessions != null);
|
||||
|
||||
// Add node name
|
||||
var nname = EscapeHtml(node.name), nnameEx;
|
||||
if (nname.length == 0) { nname = '<i>' + "None" + '</i>'; }
|
||||
@ -12426,6 +12455,7 @@
|
||||
function nobreak(x) { return x.split(' ').join(' '); }
|
||||
function pad2(num) { var s = '00' + num; return s.substr(s.length - 2); }
|
||||
function encodeURIComponentEx(txt) { return encodeURIComponent(txt).replace(/'/g,'%27'); };
|
||||
function getUserName(userid) { if (users && users[userid] != null) return users[userid].name; return userid.split('/')[2]; }
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
Loading…
Reference in New Issue
Block a user