Added session disconnection log entries, #3437
Ylian Saint-Hilaire committed
Jan 10, 2022 at 17:42 UTC
c14aba06d42a25d6d7ccd5c761a7e83985ab9d0c
4 files changed
+20
-12
agents/meshcore.js
+11
-7
@@ -602,6 +602,7 @@ function MeshServerLogEx(id, args, msg, state) {
602
var msg = { action: 'log', msgid: id, msgArgs: args, msg: msg };
603
if (state) {
604
if (state.userid) { msg.userid = state.userid; }
605
+ if (state.xuserid) { msg.xuserid = state.xuserid; }
606
if (state.username) { msg.username = state.username; }
607
if (state.sessionid) { msg.sessionid = state.sessionid; }
608
if (state.remoteaddr) { msg.remoteaddr = state.remoteaddr; }
@@ -1063,16 +1064,19 @@ function handleServerCommand(data) {
1064
if ((data.rights != 4294967295) && (data.xuserid != data.userid)) return; // This command requires full admin rights on the device or user self-closes it's own sessions
1065
for (var i in tunnels) {
1066
if ((tunnels[i].userid == data.xuserid) && (tunnels[i].guestname == data.guestname)) {
1066
- var disconnect = false;
1067
- if ((data.protocol == 'kvm') && (tunnels[i].protocol == 2)) { disconnect = true; }
1068
- else if ((data.protocol == 'terminal') && (tunnels[i].protocol == 1)) { disconnect = true; }
1069
- else if ((data.protocol == 'files') && (tunnels[i].protocol == 5)) { disconnect = true; }
1070
- else if ((data.protocol == 'tcp') && (tunnels[i].tcpport != null)) { disconnect = true; }
1071
- else if ((data.protocol == 'udp') && (tunnels[i].udpport != null)) { disconnect = true; }
1067
+ var disconnect = false, msgid = 0;
1068
+ if ((data.protocol == 'kvm') && (tunnels[i].protocol == 2)) { msgid = 134; disconnect = true; }
1069
+ else if ((data.protocol == 'terminal') && (tunnels[i].protocol == 1)) { msgid = 135; disconnect = true; }
1070
+ else if ((data.protocol == 'files') && (tunnels[i].protocol == 5)) { msgid = 136; disconnect = true; }
1071
+ else if ((data.protocol == 'tcp') && (tunnels[i].tcpport != null)) { msgid = 137; disconnect = true; }
1072
+ else if ((data.protocol == 'udp') && (tunnels[i].udpport != null)) { msgid = 137; disconnect = true; }
1073
if (disconnect) {
1074
if (tunnels[i].s != null) { tunnels[i].s.end(); } else { tunnels[i].end(); }
1075
1075
- // TODO: Log tunnel disconnection
1076
+ // Log tunnel disconnection
1077
+ var xusername = data.xuserid.split('/')[2];
1078
+ if (data.guestname != null) { xusername += '/' + guestname; }
1079
+ MeshServerLogEx(msgid, [xusername], "Forcibly disconnected session of user: " + xusername, data);
1080
}
1081
}
1082
}
meshagent.js
+4
@@ -1355,6 +1355,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1355
var loguser = parent.users[command.userid];
1356
if (loguser) { event.userid = command.userid; event.username = loguser.name; targets.push(command.userid); }
1357
}
1358
+ if (typeof command.xuserid == 'string') {
1359
+ var xloguser = parent.users[command.xuserid];
1360
+ if (xloguser) { targets.push(command.xuserid); }
1361
+ }
1362
if ((typeof command.sessionid == 'string') && (command.sessionid.length < 500)) { event.sessionid = command.sessionid; }
1363
parent.parent.DispatchEvent(targets, obj, event);
1364
}
meshuser.js
+1
-1
@@ -4686,7 +4686,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4686
const splitxuser = command.xuserid.split('/');
4687
var xusername = splitxuser[2];
4688
if (command.guestname != null) { xusername += '/' + command.guestname; }
4689
- var event = { etype: 'user', userid: user._id, username: user.name, nodeid: command.nodeid, xuserid: command.xuserid, action: 'endsession', msgid: 134, msgArgs: [xusername], msg: 'Disconnected desktop session of user ' + xusername, domain: domain.id };
4689
+ var event = { etype: 'user', userid: user._id, username: user.name, nodeid: command.nodeid, xuserid: command.xuserid, action: 'endsession', msgid: 134, msgArgs: [xusername], msg: 'Forcibly disconnected desktop session of user ' + xusername, domain: domain.id };
4690
if (command.guestname != null) { event.guestname = command.guestname; }
4691
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
4692
parent.parent.DispatchEvent(targets, obj, event);
views/default.handlebars
+4
-4
@@ -13355,10 +13355,10 @@
13355
131: "Added device share {0} with unlimited time.",
13356
132: "Turn on.",
13357
133: "Turn off.",
13358
- 134: "Disconnected desktop session of user {0}",
13359
- 135: "Disconnected terminal session of user {0}",
13360
- 136: "Disconnected files session of user {0}",
13361
- 137: "Disconnected routing session of user {0}"
13358
+ 134: "Forcibly disconnected desktop session of user {0}",
13359
+ 135: "Forcibly disconnected terminal session of user {0}",
13360
+ 136: "Forcibly disconnected files session of user {0}",
13361
+ 137: "Forcibly disconnected routing session of user {0}"
13362
};
13363
13364
// Highlights the device being hovered