More server peering fixes.

This commit is contained in:
Ylian Saint-Hilaire 2019-08-14 16:51:45 -07:00
parent e120bbae98
commit b05a93d888
4 changed files with 10 additions and 8 deletions

View File

@ -18,6 +18,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
obj.ws = ws;
obj.id = req.query.id;
obj.user = user;
obj.req = req; // Used in multi-server.js
// Relay session count (we may remove this in the future)
obj.relaySessionCounted = true;
@ -181,22 +182,22 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
parent.parent.fs.open(recFullFilename, 'w', function (err, fd) {
if (err != null) {
// Unable to record
ws.send('c'); // Send connect to both peers
relayinfo.peer1.ws.send('c');
try { ws.send('c'); } catch (ex) { } // Send connect to both peers
try { relayinfo.peer1.ws.send('c'); } catch (ex) { }
} else {
// Write the recording file header
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 });
recordingEntry(fd, 1, ((req.query.browser) ? 2 : 0), firstBlock, function () {
relayinfo.peer1.ws.logfile = ws.logfile = { fd: fd, lock: false };
ws.send('cr'); // Send connect to both peers, 'cr' indicates the session is being recorded.
relayinfo.peer1.ws.send('cr');
try { ws.send('cr'); } catch (ex) { } // Send connect to both peers, 'cr' indicates the session is being recorded.
try { relayinfo.peer1.ws.send('cr'); } catch (ex) { }
});
}
});
} else {
// Send session start
ws.send('c'); // Send connect to both peers
relayinfo.peer1.ws.send('c');
try { ws.send('c'); } catch (ex) { } // Send connect to both peers
try { relayinfo.peer1.ws.send('c'); } catch (ex) { }
}
parent.parent.debug(1, 'Relay connected: ' + obj.id + ' (' + cleanRemoteAddr(ws._socket.remoteAddress) + ' --> ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ')');

View File

@ -583,7 +583,7 @@ module.exports.CreateMultiServer = function (parent, args) {
if (path[0] == '/') path = path.substring(1);
if (path.substring(path.length - 11) == '/.websocket') { path = path.substring(0, path.length - 11); }
var queryStr = '';
for (var i in req.query) { queryStr += ((queryStr == '') ? '?' : '&') + i + '=' + req.query[i]; }
for (var i in req.query) { if (i.toLowerCase() != 'auth') { queryStr += ((queryStr == '') ? '?' : '&') + i + '=' + req.query[i]; } }
if (user != null) { queryStr += ((queryStr == '') ? '?' : '&') + 'auth=' + obj.parent.encodeCookie({ userid: user._id, domainid: user.domain }, cookieKey); }
var url = obj.peerConfig.servers[serverid].url + path + queryStr;

View File

@ -1,6 +1,6 @@
{
"name": "meshcentral",
"version": "0.3.9-x",
"version": "0.3.9-y",
"keywords": [
"Remote Management",
"Intel AMT",

View File

@ -3192,6 +3192,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
} else if ((req.query.auth != null) && (req.query.auth != '')) {
// This is a encrypted cookie authentication
var cookie = obj.parent.decodeCookie(req.query.auth, obj.parent.loginCookieEncryptionKey, 240); // Cookie with 4 hour timeout
if ((cookie == null) && (obj.parent.multiServer != null)) { cookie = obj.parent.decodeCookie(req.query.auth, obj.parent.serverKey, 240); } // Try the server key
if ((cookie != null) && (obj.users[cookie.userid]) && (cookie.domainid == domain.id)) {
// Valid cookie, we are authenticated
func(ws, req, domain, obj.users[cookie.userid], cookie);