Fixed user session counts
Ylian Saint-Hilaire committed
Nov 6, 2018 at 19:41 UTC
046bc1e963257f51f99cb7c2eb9c80038bc80a84
6 files changed
+17
-15
meshuser.js
+5
-5
@@ -81,9 +81,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
81
if (user == null) { try { obj.ws.close(); } catch (e) { } return; }
82
83
// Associate this websocket session with the web session
84
- //req.session.ws = obj.ws;
85
- //req.session.ws.userid = req.session.userid;
86
- //req.session.ws.domainid = domain.id;
84
+ obj.ws.userid = req.session.userid;
85
+ obj.ws.domainid = domain.id;
86
87
// Add this web socket session to session list
88
obj.ws.sessionId = user._id + '/' + ('' + Math.random()).substring(2);
@@ -102,7 +101,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
101
obj.ws.HandleEvent = function (source, event) {
102
if (!event.domain || event.domain == obj.domain.id) {
103
try {
105
- if (event == 'close') { req.session.destroy(); obj.close(); }
104
+ if (event == 'close') { try { delete req.session; } catch (ex) { } obj.close(); }
105
else if (event == 'resubscribe') { user.subscriptions = obj.parent.subscribe(user._id, ws); }
106
else if (event == 'updatefiles') { updateUserFiles(user, ws, domain); }
107
else { ws.send(JSON.stringify({ action: 'event', event: event })); }
@@ -1137,7 +1136,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1136
case 'close':
1137
{
1138
// Close the web socket session
1140
- if (obj.req.session && obj.req.session.ws && obj.req.session.ws == ws) delete obj.req.session.ws;
1139
+ console.log('CLOSING1');
1140
+ if (obj.req.session && obj.req.session.ws && obj.req.session.ws == ws) { console.log('CLOSING2'); delete obj.req.session.ws; }
1141
try { ws.close(); } catch (e) { }
1142
break;
1143
}
mpsserver.js
+2
-2
@@ -26,7 +26,7 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
26
const tls = require("tls");
27
const MAX_IDLE = 90000; // 90 seconds max idle time, higher than the typical KEEP-ALIVE periode of 60 seconds
28
29
- if (obj.args.tlsoffload) {
29
+ if (obj.args.mpstlsoffload) {
30
obj.server = net.createServer(onConnection);
31
} else {
32
obj.server = tls.createServer({ key: certificates.mps.key, cert: certificates.mps.cert, requestCert: true, rejectUnauthorized: false }, onConnection);
@@ -99,7 +99,7 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
99
};
100
101
function onConnection(socket) {
102
- if (obj.args.tlsoffload) {
102
+ if (obj.args.mpstlsoffload) {
103
socket.tag = { first: true, clientCert: null, accumulator: "", activetunnels: 0, boundPorts: [], socket: socket, host: null, nextchannelid: 4, channels: {}, nextsourceport: 0 };
104
} else {
105
socket.tag = { first: true, clientCert: socket.getPeerCertificate(true), accumulator: "", activetunnels: 0, boundPorts: [], socket: socket, host: null, nextchannelid: 4, channels: {}, nextsourceport: 0 };
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.2.2-s",
3
+ "version": "0.2.2-t",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
sample-config.json
+3
-1
@@ -16,7 +16,9 @@
16
"_ClickOnce": false,
17
"_SelfUpdate": true,
18
"_UserAllowedIP": "127.0.0.1,::1,192.168.0.100",
19
- "_LocalDiscovery": { "name": "Local server name", "info": "Information about this server" }
19
+ "_LocalDiscovery": { "name": "Local server name", "info": "Information about this server" },
20
+ "_TlsOffload": true,
21
+ "_MpsTlsOffload": true
22
},
23
"_domains": {
24
"": {
views/default.handlebars
+1
-1
@@ -2101,7 +2101,7 @@
2101
if (serverinfo != null) { x += addHtmlValue('MPS Server', '<input style=width:230px readonly value="' + EscapeHtml(serverinfo.mpsname) + ':' + serverinfo.mpsport + '" />'); }
2102
x += "</div>";
2103
2104
- // Setup CIRA with certificate authentication (Really difficult, only is allowed)
2104
+ // Setup CIRA with certificate authentication (Really difficult, only if TLS offload is not used)
2105
if ((features & 16) == 0) {
2106
x += "<div id=dlgAddCira2 style=display:none>To add a new Intel® AMT device to device group \"" + EscapeHtml(mesh.name) + "\" with CIRA, load the following certificate as trusted root within Intel AMT, authenticate using a client certificate with the following common name and connect to the following server.<br /><br />";
2107
x += addHtmlValue('Root Certificate', '<a href="MeshServerRootCert.cer" target="_blank">Root Certificate File</a>');
webserver.js
+5
-5
@@ -709,8 +709,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
709
}
710
}
711
712
- // If a user is logged in, serve the default app, otherwise server the login app.
713
- if (req.session && req.session.userid) {
712
+ // If a user exists and is logged in, serve the default app, otherwise server the login app.
713
+ if (req.session && req.session.userid && obj.users[req.session.userid]) {
714
+ var user = obj.users[req.session.userid];
715
if (req.session.domainid != domain.id) { req.session = null; res.redirect(domain.url); return; } // Check is the session is for the correct domain
716
var viewmode = 1;
717
if (req.session.viewmode) {
@@ -727,16 +728,15 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
728
currentNode = 'node/' + domain.id + '/' + req.query.node;
729
}
730
var logoutcontrol = '';
730
- if (obj.args.nousers != true) { logoutcontrol = 'Welcome ' + obj.users[req.session.userid].name + '.'; }
731
+ if (obj.args.nousers != true) { logoutcontrol = 'Welcome ' + user.name + '.'; }
732
733
// Give the web page a list of supported server features
734
features = 0;
734
- user = obj.users[req.session.userid];
735
if (obj.args.wanonly == true) { features += 1; } // WAN-only mode
736
if (obj.args.lanonly == true) { features += 2; } // LAN-only mode
737
if (obj.args.nousers == true) { features += 4; } // Single user mode
738
if (domain.userQuota == -1) { features += 8; } // No server files mode
739
- if (obj.args.tlsoffload) { features += 16; } // No mutual-auth CIRA
739
+ if (obj.args.mpstlsoffload) { features += 16; } // No mutual-auth CIRA
740
if ((parent.config != null) && (parent.config.settings != null) && (parent.config.settings.allowframing == true)) { features += 32; } // Allow site within iframe
741
if ((obj.parent.mailserver != null) && (obj.parent.certificates.CommonName != null) && (obj.parent.certificates.CommonName != 'un-configured') && (obj.args.lanonly != true)) { features += 64; } // Email invites
742
if (obj.args.webrtc == true) { features += 128; } // Enable WebRTC (Default false for now)