More server peering fixes.

Ylian Saint-Hilaire committed Aug 14, 2019 at 16:51 UTC b05a93d8887f1ae91c8d99c13d3054cbf18ae172
4 files changed +10 -8
meshrelay.js
+7 -6
@@ -18,6 +18,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
18 obj.ws = ws;
19 obj.id = req.query.id;
20 obj.user = user;
21 + obj.req = req; // Used in multi-server.js
22
23 // Relay session count (we may remove this in the future)
24 obj.relaySessionCounted = true;
@@ -181,22 +182,22 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
182 parent.parent.fs.open(recFullFilename, 'w', function (err, fd) {
183 if (err != null) {
184 // Unable to record
184 - ws.send('c'); // Send connect to both peers
185 - relayinfo.peer1.ws.send('c');
185 + try { ws.send('c'); } catch (ex) { } // Send connect to both peers
186 + try { relayinfo.peer1.ws.send('c'); } catch (ex) { }
187 } else {
188 // Write the recording file header
189 var firstBlock = JSON.stringify({ magic: 'MeshCentralRelaySession', ver: 1, userid: sessionUser._id, username: sessionUser.name, sessionid: obj.id, ipaddr1: cleanRemoteAddr(ws._socket.remoteAddress), ipaddr2: cleanRemoteAddr(obj.peer.ws._socket.remoteAddress), time: new Date().toLocaleString(), protocol: req.query.p, nodeid: req.query.nodeid });
190 recordingEntry(fd, 1, ((req.query.browser) ? 2 : 0), firstBlock, function () {
191 relayinfo.peer1.ws.logfile = ws.logfile = { fd: fd, lock: false };
191 - ws.send('cr'); // Send connect to both peers, 'cr' indicates the session is being recorded.
192 - relayinfo.peer1.ws.send('cr');
192 + try { ws.send('cr'); } catch (ex) { } // Send connect to both peers, 'cr' indicates the session is being recorded.
193 + try { relayinfo.peer1.ws.send('cr'); } catch (ex) { }
194 });
195 }
196 });
197 } else {
198 // Send session start
198 - ws.send('c'); // Send connect to both peers
199 - relayinfo.peer1.ws.send('c');
199 + try { ws.send('c'); } catch (ex) { } // Send connect to both peers
200 + try { relayinfo.peer1.ws.send('c'); } catch (ex) { }
201 }
202
203 parent.parent.debug(1, 'Relay connected: ' + obj.id + ' (' + cleanRemoteAddr(ws._socket.remoteAddress) + ' --> ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ')');
multiserver.js
+1 -1
@@ -583,7 +583,7 @@ module.exports.CreateMultiServer = function (parent, args) {
583 if (path[0] == '/') path = path.substring(1);
584 if (path.substring(path.length - 11) == '/.websocket') { path = path.substring(0, path.length - 11); }
585 var queryStr = '';
586 - for (var i in req.query) { queryStr += ((queryStr == '') ? '?' : '&') + i + '=' + req.query[i]; }
586 + for (var i in req.query) { if (i.toLowerCase() != 'auth') { queryStr += ((queryStr == '') ? '?' : '&') + i + '=' + req.query[i]; } }
587 if (user != null) { queryStr += ((queryStr == '') ? '?' : '&') + 'auth=' + obj.parent.encodeCookie({ userid: user._id, domainid: user.domain }, cookieKey); }
588 var url = obj.peerConfig.servers[serverid].url + path + queryStr;
589
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.3.9-x",
3 + "version": "0.3.9-y",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
webserver.js
+1
@@ -3192,6 +3192,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3192 } else if ((req.query.auth != null) && (req.query.auth != '')) {
3193 // This is a encrypted cookie authentication
3194 var cookie = obj.parent.decodeCookie(req.query.auth, obj.parent.loginCookieEncryptionKey, 240); // Cookie with 4 hour timeout
3195 + if ((cookie == null) && (obj.parent.multiServer != null)) { cookie = obj.parent.decodeCookie(req.query.auth, obj.parent.serverKey, 240); } // Try the server key
3196 if ((cookie != null) && (obj.users[cookie.userid]) && (cookie.domainid == domain.id)) {
3197 // Valid cookie, we are authenticated
3198 func(ws, req, domain, obj.users[cookie.userid], cookie);