Improved device session notification.
Ylian Saint-Hilaire committed
May 12, 2020 at 00:01 UTC
2b4336e2224c8bf8020d192c1cfdf646ec885318
4 files changed
+40
-2
agents/meshcore.js
+27
@@ -304,6 +304,7 @@ function createMeshCore(agent) {
304
var nextTunnelIndex = 1;
305
var amtPolicy = null;
306
var apftunnel = null;
307
+ var tunnelUserCount = { terminal: {}, files: {} }; // List of userid->count sessions for terminal and files.
308
309
// Add to the server event log
310
function MeshServerLog(msg, state) {
@@ -1154,6 +1155,12 @@ function createMeshCore(agent) {
1155
this.httprequest.tpromise = new prom(function (res, rej) { this._res = res; this._rej = rej; });
1156
1157
this.end = function () {
1158
+ // Remove the terminal session to the count to update the server
1159
+ if (this.httprequest.userid != null) {
1160
+ if (tunnelUserCount.terminal[this.httprequest.userid] != null) { tunnelUserCount.terminal[this.httprequest.userid]--; if (tunnelUserCount.terminal[this.httprequest.userid] <= 0) { delete tunnelUserCount.terminal[this.httprequest.userid]; } }
1161
+ try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (ex) { }
1162
+ }
1163
+
1164
if (process.platform == 'win32') {
1165
// Unpipe the web socket
1166
this.unpipe(this.httprequest._term);
@@ -1315,6 +1322,12 @@ function createMeshCore(agent) {
1322
this.httprequest.tpromise._res();
1323
}
1324
1325
+ // Add the terminal session to the count to update the server
1326
+ if (this.httprequest.userid != null) {
1327
+ if (tunnelUserCount.terminal[this.httprequest.userid] == null) { tunnelUserCount.terminal[this.httprequest.userid] = 1; } else { tunnelUserCount.terminal[this.httprequest.userid]++; }
1328
+ try { mesh.SendCommand({ action: 'sessions', type: 'terminal', value: tunnelUserCount.terminal }); } catch (ex) { }
1329
+ }
1330
+
1331
this.httprequest.tpromise.that = this;
1332
this.httprequest.tpromise.then(function ()
1333
{
@@ -1664,6 +1677,20 @@ function createMeshCore(agent) {
1677
if (cmd.action == undefined) { return; }
1678
//sendConsoleText('CMD: ' + JSON.stringify(cmd));
1679
1680
+ // Add the files session to the count to update the server
1681
+ if (this.httprequest.userid != null) {
1682
+ if (tunnelUserCount.files[this.httprequest.userid] == null) { tunnelUserCount.files[this.httprequest.userid] = 1; } else { tunnelUserCount.files[this.httprequest.userid]++; }
1683
+ try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (ex) { }
1684
+ }
1685
+
1686
+ this.end = function () {
1687
+ // Remove the files session from the count to update the server
1688
+ if (this.httprequest.userid != null) {
1689
+ if (tunnelUserCount.files[this.httprequest.userid] != null) { tunnelUserCount.files[this.httprequest.userid]--; if (tunnelUserCount.files[this.httprequest.userid] <= 0) { delete tunnelUserCount.files[this.httprequest.userid]; } }
1690
+ try { mesh.SendCommand({ action: 'sessions', type: 'files', value: tunnelUserCount.files }); } catch (ex) { }
1691
+ }
1692
+ };
1693
+
1694
if ((cmd.path != null) && (process.platform != 'win32') && (cmd.path[0] != '/')) { cmd.path = '/' + cmd.path; } // Add '/' to paths on non-windows
1695
//console.log(objToString(cmd, 0, ' '));
1696
switch (cmd.action) {
meshagent.js
+2
@@ -1331,6 +1331,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1331
// This is a list of sessions provided by the agent
1332
if (obj.sessions == null) { obj.sessions = {}; }
1333
if (command.type == 'kvm') { obj.sessions.kvm = command.value; }
1334
+ else if (command.type == 'terminal') { obj.sessions.terminal = command.value; }
1335
+ else if (command.type == 'files') { obj.sessions.files = command.value; }
1336
obj.updateSessions();
1337
break;
1338
}
meshcentral.js
+1
-1
@@ -129,7 +129,7 @@ function CreateMeshCentralServer(config, args) {
129
try { require('./pass').hash('test', function () { }, 0); } catch (e) { console.log('Old version of node, must upgrade.'); return; } // TODO: Not sure if this test works or not.
130
131
// Check for invalid arguments
132
- var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'rediraliasport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'listuserids', 'showusergroups', 'shownodes', 'showmeshes', 'showevents', 'showsmbios', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'xinstall', 'xuninstall', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'dbmerge', 'dbencryptkey', 'selfupdate', 'tlsoffload', 'userallowedip', 'userblockedip', 'swarmallowedip', 'agentallowedip', 'agentblockedip', 'fastcert', 'swarmport', 'logintoken', 'logintokenkey', 'logintokengen', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore', 'dblistconfigfiles', 'dbshowconfigfile', 'dbpushconfigfiles', 'dbpullconfigfiles', 'dbdeleteconfigfiles', 'vaultpushconfigfiles', 'vaultpullconfigfiles', 'vaultdeleteconfigfiles', 'configkey', 'loadconfigfromdb', 'npmpath', 'memorytracking', 'serverid', 'recordencryptionrecode', 'vault', 'token', 'unsealkey', 'name', 'log', 'dbstats', 'translate', 'createaccount', 'resetaccount', 'pass', 'adminaccount', 'domain', 'email'];
132
+ var validArguments = ['_', 'notls', 'user', 'port', 'aliasport', 'mpsport', 'mpsaliasport', 'redirport', 'rediraliasport', 'cert', 'mpscert', 'deletedomain', 'deletedefaultdomain', 'showall', 'showusers', 'listuserids', 'showusergroups', 'shownodes', 'showmeshes', 'showevents', 'showsmbios', 'showpower', 'clearpower', 'showiplocations', 'help', 'exactports', 'xinstall', 'xuninstall', 'install', 'uninstall', 'start', 'stop', 'restart', 'debug', 'filespath', 'datapath', 'noagentupdate', 'launch', 'noserverbackup', 'mongodb', 'mongodbcol', 'wanonly', 'lanonly', 'nousers', 'mpspass', 'ciralocalfqdn', 'dbexport', 'dbexportmin', 'dbimport', 'dbmerge', 'dbencryptkey', 'selfupdate', 'tlsoffload', 'userallowedip', 'userblockedip', 'swarmallowedip', 'agentallowedip', 'agentblockedip', 'fastcert', 'swarmport', 'logintoken', 'logintokenkey', 'logintokengen', 'mailtokengen', 'admin', 'unadmin', 'sessionkey', 'sessiontime', 'minify', 'minifycore', 'dblistconfigfiles', 'dbshowconfigfile', 'dbpushconfigfiles', 'dbpullconfigfiles', 'dbdeleteconfigfiles', 'vaultpushconfigfiles', 'vaultpullconfigfiles', 'vaultdeleteconfigfiles', 'configkey', 'loadconfigfromdb', 'npmpath', 'memorytracking', 'serverid', 'recordencryptionrecode', 'vault', 'token', 'unsealkey', 'name', 'log', 'dbstats', 'translate', 'createaccount', 'resetaccount', 'pass', 'adminaccount', 'domain', 'email'];
133
for (var arg in obj.args) { obj.args[arg.toLocaleLowerCase()] = obj.args[arg]; if (validArguments.indexOf(arg.toLocaleLowerCase()) == -1) { console.log('Invalid argument "' + arg + '", use --help.'); return; } }
134
if (obj.args.mongodb == true) { console.log('Must specify: --mongodb [connectionstring] \r\nSee https://docs.mongodb.com/manual/reference/connection-string/ for MongoDB connection string.'); return; }
135
for (i in obj.config.settings) { obj.args[i] = obj.config.settings[i]; } // Place all settings into arguments, arguments have already been placed into settings so arguments take precedence.
views/default.handlebars
+10
-1
@@ -2643,6 +2643,9 @@
2643
node.pwr = message.event.pwr;
2644
node.lastconnect = Date.now();
2645
2646
+ // Clear sesssion information if needed
2647
+ if ((node.conn & 1) == 0) { delete node.sessions; }
2648
+
2649
// Web page update
2650
masterUpdate(1 | 4 | 16);
2651
refreshDevice(node._id);
@@ -3434,9 +3437,15 @@
3437
} else if (i == 'multidesk') {
3438
x += '<u>' + "Remote Desktop" + '</u>';
3439
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])))); }
3440
+ } else if (i == 'terminal') {
3441
+ x += '<u>' + "Terminal" + '</u>';
3442
+ for (var j in node.sessions.terminal) { x += addHtmlValue4(getUserName(j), ((node.sessions.terminal[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.terminal[j])))); }
3443
+ } else if (i == 'files') {
3444
+ x += '<u>' + "Files" + '</u>';
3445
+ for (var j in node.sessions.files) { x += addHtmlValue4(getUserName(j), ((node.sessions.files[j] == 1)?"1 session":nobreak(format("{0} sessions", node.sessions.files[j])))); }
3446
}
3447
}
3439
- if (x != '') setDialogMode(2, "Sessions - " + EscapeHtml(node.name), 1, null, x, 'SESSIONS-' + node._id);
3448
+ if (x != '') setDialogMode(2, "Sessions" + ' - ' + EscapeHtml(node.name), 1, null, x, 'SESSIONS-' + node._id);
3449
}
3450
3451
function toggleCollapseGroup(id, id2, type) {