Added session disconnection log for desktop multiplex, #3437

Ylian Saint-Hilaire committed Jan 10, 2022 at 15:28 UTC 42137aa1d1fb084d7729660f408b7e022f60faf1
3 files changed +20 -2
agents/meshcore.js
+5 -1
@@ -1069,7 +1069,11 @@ function handleServerCommand(data) {
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; }
1072 - if (disconnect) { if (tunnels[i].s != null) { tunnels[i].s.end(); } else { tunnels[i].end(); } }
1072 + if (disconnect) {
1073 + if (tunnels[i].s != null) { tunnels[i].s.end(); } else { tunnels[i].end(); }
1074 +
1075 + // TODO: Log tunnel disconnection
1076 + }
1077 }
1078 }
1079 break;
meshuser.js
+10
@@ -4848,6 +4848,16 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4848 if ((viewer.user._id == command.xuserid) && (viewer.guestName == command.guestname)) { viewersToClose.push(viewer); } // Only close viewers that match the userid and guestname if present.
4849 }
4850 for (var i = 0; i < viewersToClose.length; i++) { viewersToClose[i].close(); } // Close any viewers we need closed.
4851 +
4852 + // Log the desktop session disconnection
4853 + var targets = ['*', user._id, command.xuserid];
4854 + const splitxuser = command.xuserid.split('/');
4855 + var xusername = splitxuser[2];
4856 + if (command.guestname != null) { xusername += '/' + command.guestname; }
4857 + 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 };
4858 + if (command.guestname != null) { event.guestname = command.guestname; }
4859 + 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.
4860 + parent.parent.DispatchEvent(targets, obj, event);
4861 });
4862
4863 break;
views/default.handlebars
+5 -1
@@ -13354,7 +13354,11 @@
13354 130: "User notifications changed",
13355 131: "Added device share {0} with unlimited time.",
13356 132: "Turn on.",
13357 - 133: "Turn off."
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}"
13362 };
13363
13364 // Highlights the device being hovered