Updated to Express-ws 4.x

This commit is contained in:
Ylian Saint-Hilaire 2018-11-30 21:23:10 -08:00
parent 4f33d8e551
commit e8bcf423ea
6 changed files with 18 additions and 18 deletions

View File

@ -413,7 +413,7 @@ function createMeshCore(agent) {
if (xurl != null) {
var woptions = http.parseUri(xurl);
woptions.rejectUnauthorized = 0;
sendConsoleText(JSON.stringify(woptions));
//sendConsoleText(JSON.stringify(woptions));
var tunnel = http.request(woptions);
tunnel.upgrade = onTunnelUpgrade;
tunnel.onerror = function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); }

View File

@ -127,8 +127,8 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
relayinfo.state = 2;
obj.ws.send('c'); // Send connect to both peers
relayinfo.peer1.ws.send('c');
relayinfo.peer1.ws.resume(); // Release the traffic
relayinfo.peer2.ws.resume(); // Release the traffic
relayinfo.peer1.ws._socket.resume(); // Release the traffic
relayinfo.peer2.ws._socket.resume(); // Release the traffic
relayinfo.peer1.ws.peer = relayinfo.peer2.ws;
relayinfo.peer2.ws.peer = relayinfo.peer1.ws;
@ -143,7 +143,7 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
}
} else {
// Wait for other relay connection
ws.pause(); // Hold traffic until the other connection
ws._socket.pause(); // Hold traffic until the other connection
parent.wsrelays[obj.id] = { peer1: obj, state: 1 };
obj.parent.parent.debug(1, 'Relay holding: ' + obj.id + ' (' + obj.remoteaddr + ') ' + (obj.authenticated ? 'Authenticated' : ''));
@ -163,14 +163,14 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
}
}
ws.flushSink = function () { try { ws.resume(); } catch (e) { } };
ws.flushSink = function () { try { ws._socket.resume(); } catch (e) { } };
// When data is received from the mesh relay web socket
ws.on('message', function (data) {
//console.log(typeof data, data.length);
if (this.peer != null) {
//if (typeof data == 'string') { console.log('Relay: ' + data); } else { console.log('Relay:' + data.length + ' byte(s)'); }
try { this.pause(); this.peer.send(data, ws.flushSink); } catch (e) { }
try { this._socket.pause(); this.peer.send(data, ws.flushSink); } catch (e) { }
}
});

View File

@ -1337,7 +1337,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
try { ws.send(JSON.stringify({ action: 'userinfo', userinfo: userinfo })); } catch (ex) { }
// We are all set, start receiving data
ws.resume();
ws._socket.resume();
} catch (e) { console.log(e); }
// Read entire file and return it in callback function

View File

@ -591,7 +591,7 @@ module.exports.CreateMultiServer = function (parent, args) {
peerTunnel.ws2.on('close', function (req) { peerTunnel.parent.parent.debug(1, 'FTunnel disconnect ' + peerTunnel.serverid); peerTunnel.close(); });
// If a message is received from the peer, Peer ---> Browser (TODO: Pipe this?)
peerTunnel.ws2.on('message', function (msg) { try { peerTunnel.ws2.pause(); peerTunnel.ws1.send(msg, function () { peerTunnel.ws2.resume(); }); } catch (e) { } });
peerTunnel.ws2.on('message', function (msg) { try { peerTunnel.ws2._socket.pause(); peerTunnel.ws1.send(msg, function () { peerTunnel.ws2._socket.resume(); }); } catch (e) { } });
// Register the connection event
peerTunnel.ws2.on('open', function () {
@ -605,11 +605,11 @@ module.exports.CreateMultiServer = function (parent, args) {
if (obj.peerServers[serverid] == null || obj.peerServers[serverid].serverCertHash != serverCertHashHex) { console.log('ERROR: Outer certificate hash mismatch (1). (' + peerTunnel.url + ', ' + peerTunnel.serverid + ').'); peerTunnel.close(); return; }
// Connection accepted, resume the web socket to start the data flow
peerTunnel.ws1.resume();
peerTunnel.ws1._socket.resume();
});
// If a message is received from the browser, Browser ---> Peer
peerTunnel.ws1.on('message', function (msg) { try { peerTunnel.ws1.pause(); peerTunnel.ws2.send(msg, function () { peerTunnel.ws1.resume(); }); } catch (e) { } });
peerTunnel.ws1.on('message', function (msg) { try { peerTunnel.ws1._socket.pause(); peerTunnel.ws2.send(msg, function () { peerTunnel.ws1._socket.resume(); }); } catch (e) { } });
// If error, do nothing
peerTunnel.ws1.on('error', function (err) { peerTunnel.close(); });

View File

@ -1,6 +1,6 @@
{
"name": "meshcentral",
"version": "0.2.3-w",
"version": "0.2.3-x",
"keywords": [
"Remote Management",
"Intel AMT",
@ -34,7 +34,7 @@
"express": "^4.16.4",
"express-handlebars": "^3.0.0",
"express-session": "^1.15.6",
"express-ws": "^3.0.0",
"express-ws": "^4.0.0",
"le-acme-core": "^2.1.4",
"le-store-certbot": "^2.2.1",
"meshcentral": "*",

View File

@ -1184,7 +1184,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
var tlsoptions = { secureProtocol: ((req.query.tls1only == 1) ? 'TLSv1_method' : 'SSLv23_method'), ciphers: 'RSA+AES:!aNULL:!MD5:!DSS', secureOptions: obj.constants.SSL_OP_NO_SSLv2 | obj.constants.SSL_OP_NO_SSLv3 | obj.constants.SSL_OP_NO_COMPRESSION | obj.constants.SSL_OP_CIPHER_SERVER_PREFERENCE, rejectUnauthorized: false, cert: obj.certificates.console.cert, key: obj.certificates.console.key };
var tlsock = new TLSSocket(ser, tlsoptions);
tlsock.on('error', function (err) { Debug(1, "CIRA TLS Connection Error ", err); });
tlsock.on('secureConnect', function () { Debug(2, "CIRA Secure TLS Connection"); ws.resume(); });
tlsock.on('secureConnect', function () { Debug(2, "CIRA Secure TLS Connection"); ws._socket.resume(); });
// Decrypted tunnel from TLS communcation to be forwarded to websocket
tlsock.on('data', function (data) {
@ -1204,7 +1204,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
// Without TLS
ws.forwardclient = parent.mpsserver.SetupCiraChannel(ciraconn, port);
ws.forwardclient.xtls = 0;
ws.resume();
ws._socket.resume();
}
// When data is received from the web socket, forward the data into the associated CIRA cahnnel.
@ -1291,7 +1291,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
ws.forwardclient.setEncoding('binary');
ws.forwardclient.xstate = 0;
ws.forwardclient.forwardwsocket = ws;
ws.resume();
ws._socket.resume();
} else {
// If TLS is going to be used, setup a TLS socket
var tlsoptions = { secureProtocol: ((req.query.tls1only == 1) ? 'TLSv1_method' : 'SSLv23_method'), ciphers: 'RSA+AES:!aNULL:!MD5:!DSS', secureOptions: obj.constants.SSL_OP_NO_SSLv2 | obj.constants.SSL_OP_NO_SSLv3 | obj.constants.SSL_OP_NO_COMPRESSION | obj.constants.SSL_OP_CIPHER_SERVER_PREFERENCE, rejectUnauthorized: false, cert: obj.certificates.console.cert, key: obj.certificates.console.key };
@ -1299,7 +1299,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
// The TLS connection method is the same as TCP, but located a bit differently.
Debug(2, 'TLS connected to ' + node.host + ':' + port + '.');
ws.forwardclient.xstate = 1;
ws.resume();
ws._socket.resume();
});
ws.forwardclient.setEncoding('binary');
ws.forwardclient.xstate = 0;
@ -1337,7 +1337,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
ws.forwardclient.connect(port, node.host, function () {
Debug(1, 'TCP relay connected to ' + node.host + ':' + port + '.');
ws.forwardclient.xstate = 1;
ws.resume();
ws._socket.resume();
});
}
return;
@ -1883,7 +1883,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
function PerformWSSessionAuth(ws, req, noAuthOk, func) {
try {
// Hold this websocket until we are ready.
ws.pause();
ws._socket.pause();
// Check IP filtering and domain
var domain = checkUserIpAddress(ws, req);