mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-26 23:25:53 -05:00
Web relay text/event-stream improvement (#4369) and relay disconnect fix.
This commit is contained in:
parent
046dd30786
commit
fe24dccd8c
14
apprelays.js
14
apprelays.js
@ -183,6 +183,10 @@ module.exports.CreateWebRelaySession = function (parent, db, req, args, domain,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tunnel.onNextRequest = function () {
|
||||||
|
parent.parent.debug('webrelay', 'tunnel-onNextRequest');
|
||||||
|
handleNextRequest();
|
||||||
|
}
|
||||||
tunnel.connect(userid, nodeid, addr, port, appid);
|
tunnel.connect(userid, nodeid, addr, port, appid);
|
||||||
tunnel.tunnelId = nextTunnelId++;
|
tunnel.tunnelId = nextTunnelId++;
|
||||||
tunnels[tunnel.tunnelId] = tunnel;
|
tunnels[tunnel.tunnelId] = tunnel;
|
||||||
@ -235,6 +239,7 @@ module.exports.CreateWebRelay = function (parent, db, args, domain) {
|
|||||||
obj.onclose = null;
|
obj.onclose = null;
|
||||||
obj.oncompleted = null;
|
obj.oncompleted = null;
|
||||||
obj.onconnect = null;
|
obj.onconnect = null;
|
||||||
|
obj.onNextRequest = null;
|
||||||
|
|
||||||
// Process a HTTP request
|
// Process a HTTP request
|
||||||
obj.processRequest = function (req, res) {
|
obj.processRequest = function (req, res) {
|
||||||
@ -244,9 +249,6 @@ module.exports.CreateWebRelay = function (parent, db, args, domain) {
|
|||||||
// Check if this is a websocket
|
// Check if this is a websocket
|
||||||
if (req.headers['upgrade'] == 'websocket') { console.log('Attempt to process a websocket in HTTP tunnel method.'); res.end(); return false; }
|
if (req.headers['upgrade'] == 'websocket') { console.log('Attempt to process a websocket in HTTP tunnel method.'); res.end(); return false; }
|
||||||
|
|
||||||
// Check if this is a streaming request
|
|
||||||
if ((req.headers['content-type'] != null) && (req.headers['content-type'].toLowerCase() == 'text/event-stream')) { obj.isStreaming = true; }
|
|
||||||
|
|
||||||
// Construct the HTTP request
|
// Construct the HTTP request
|
||||||
var request = req.method + ' ' + req.url + ' HTTP/' + req.httpVersion + '\r\n';
|
var request = req.method + ' ' + req.url + ' HTTP/' + req.httpVersion + '\r\n';
|
||||||
const blockedHeaders = ['origin', 'cookie', 'upgrade-insecure-requests', 'sec-ch-ua', 'sec-ch-ua-mobile', 'dnt', 'sec-fetch-user', 'sec-ch-ua-platform', 'sec-fetch-site', 'sec-fetch-mode', 'sec-fetch-dest']; // These are headers we do not forward
|
const blockedHeaders = ['origin', 'cookie', 'upgrade-insecure-requests', 'sec-ch-ua', 'sec-ch-ua-mobile', 'dnt', 'sec-fetch-user', 'sec-ch-ua-platform', 'sec-fetch-site', 'sec-fetch-mode', 'sec-fetch-dest']; // These are headers we do not forward
|
||||||
@ -510,6 +512,12 @@ module.exports.CreateWebRelay = function (parent, db, args, domain) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if this is a streaming response
|
||||||
|
if ((obj.socketXHeader['content-type'] != null) && (obj.socketXHeader['content-type'].toLowerCase().indexOf('text/event-stream') >= 0)) {
|
||||||
|
obj.isStreaming = true; // This tunnel is now a streaming tunnel and will not close anytime soon.
|
||||||
|
if (obj.onNextRequest != null) obj.onNextRequest(); // Call this so that any HTTP requests that are waitting for this one to finish get handled by a new tunnel.
|
||||||
|
}
|
||||||
|
|
||||||
// Check if this HTTP request has a body
|
// Check if this HTTP request has a body
|
||||||
if (obj.socketXHeader['content-length'] != null) { obj.socketParseState = 1; }
|
if (obj.socketXHeader['content-length'] != null) { obj.socketParseState = 1; }
|
||||||
if ((obj.socketXHeader['connection'] != null) && (obj.socketXHeader['connection'].toLowerCase() == 'close')) { obj.socketParseState = 1; }
|
if ((obj.socketXHeader['connection'] != null) && (obj.socketXHeader['connection'].toLowerCase() == 'close')) { obj.socketParseState = 1; }
|
||||||
|
@ -296,7 +296,8 @@ var CreateAgentRedirect = function (meshserver, module, serverPublicNamePort, au
|
|||||||
//obj.debug('Agent Redir Socket Stopped');
|
//obj.debug('Agent Redir Socket Stopped');
|
||||||
obj.connectstate = -1;
|
obj.connectstate = -1;
|
||||||
if (obj.socket != null) {
|
if (obj.socket != null) {
|
||||||
try { if (obj.socket.readyState == 1) { obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"close"}'); obj.socket.close(); } } catch (e) { }
|
try { if (obj.socket.readyState == 1) { obj.sendCtrlMsg('{"ctrlChannel":"102938","type":"close"}'); } } catch (ex) { } // If connected, send the close command
|
||||||
|
try { if (obj.socket.readyState <= 1) { obj.socket.close(); } } catch (ex) { } // If connecting or connected, close the websocket
|
||||||
obj.socket = null;
|
obj.socket = null;
|
||||||
}
|
}
|
||||||
obj.xxStateChange(0);
|
obj.xxStateChange(0);
|
||||||
|
@ -9849,12 +9849,13 @@
|
|||||||
|
|
||||||
// Called when the terminal state changes
|
// Called when the terminal state changes
|
||||||
function onTerminalStateChange(xterminal, state) {
|
function onTerminalStateChange(xterminal, state) {
|
||||||
|
if (terminal != xterminal) return;
|
||||||
var xstate = state;
|
var xstate = state;
|
||||||
if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; }
|
if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; }
|
||||||
var str = StatusStrs[xstate];
|
var str = StatusStrs[xstate];
|
||||||
if (xstate == 3) {
|
if (xstate == 3) {
|
||||||
if (terminal.contype == 3) { str += ", SSH"; }
|
if (xterminal.contype == 3) { str += ", SSH"; }
|
||||||
if (terminal.webRtcActive == true) { str += ", WebRTC"; }
|
if (xterminal.webRtcActive == true) { str += ", WebRTC"; }
|
||||||
}
|
}
|
||||||
QH('termstatus', str);
|
QH('termstatus', str);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
@ -9863,17 +9864,16 @@
|
|||||||
QH('termtitle', '');
|
QH('termtitle', '');
|
||||||
QV('termRecordIcon', false);
|
QV('termRecordIcon', false);
|
||||||
if (xterm == null) {
|
if (xterm == null) {
|
||||||
xterminal.m.TermResetScreen();
|
try { xterminal.m.TermResetScreen(); xterminal.m.TermDraw(); } catch (ex) { }
|
||||||
xterminal.m.TermDraw();
|
|
||||||
} else {
|
} else {
|
||||||
xterm.dispose();
|
xterm.dispose();
|
||||||
xterm = xtermfit = null;
|
xterm = xtermfit = null;
|
||||||
}
|
}
|
||||||
if (terminal != null) { terminal.Stop(); terminal = null; }
|
if (xterminal != null) { xterminal.Stop(); terminal = null; }
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (xterminal && (xterminal.serverIsRecording == true)) { QV('termRecordIcon', true); }
|
if (xterminal && (xterminal.serverIsRecording == true)) { QV('termRecordIcon', true); }
|
||||||
terminal.startTime = new Date();
|
xterminal.startTime = new Date();
|
||||||
if (updateSessionTimer == null) { updateSessionTimer = setInterval(updateSessionTime, 1000); }
|
if (updateSessionTimer == null) { updateSessionTimer = setInterval(updateSessionTime, 1000); }
|
||||||
if (xterm != null) { xterm.focus(); }
|
if (xterm != null) { xterm.focus(); }
|
||||||
break;
|
break;
|
||||||
@ -9902,7 +9902,7 @@
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tunnelUpdate(data) { if (typeof data == 'string') { xterm.writeUtf8(data); } else { xterm.writeUtf8(new Uint8Array(data)); } }
|
function tunnelUpdate(data) { if (xterm != null) { if (typeof data == 'string') { xterm.writeUtf8(data); } else { xterm.writeUtf8(new Uint8Array(data)); } } }
|
||||||
|
|
||||||
function sshTunnelAuthDialog(j, func) {
|
function sshTunnelAuthDialog(j, func) {
|
||||||
var x = '';
|
var x = '';
|
||||||
|
Loading…
Reference in New Issue
Block a user