From 3b637ad389f72e43f1b3cf00bec5764e0b7b982c Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 26 Apr 2021 19:01:40 -0700 Subject: [PATCH] Fixed meshctrl.js shell when ping/pong are active. --- agents/meshcore.js | 4 ++-- meshctrl.js | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index a2d31975..580f2707 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1610,7 +1610,7 @@ function onTunnelClosed() { function onTunnelSendOk() { /*sendConsoleText("Tunnel #" + this.index + " SendOK.", this.sessionid);*/ } function onTunnelData(data) { //console.log("OnTunnelData"); - sendConsoleText('OnTunnelData, ' + data.length + ', ' + typeof data + ', ' + data); + //sendConsoleText('OnTunnelData, ' + data.length + ', ' + typeof data + ', ' + data); // If this is upload data, save it to file if ((this.httprequest.uploadFile) && (typeof data == 'object') && (data[0] != 123)) { @@ -2547,7 +2547,7 @@ function onTunnelControlData(data, ws) { if (ws == null) { ws = this; } if (typeof data == 'string') { try { obj = JSON.parse(data); } catch (e) { sendConsoleText('Invalid control JSON: ' + data); return; } } else if (typeof data == 'object') { obj = data; } else { return; } - sendConsoleText('onTunnelControlData(' + ws.httprequest.protocol + '): ' + JSON.stringify(data)); + //sendConsoleText('onTunnelControlData(' + ws.httprequest.protocol + '): ' + JSON.stringify(data)); //console.log('onTunnelControlData: ' + JSON.stringify(data)); switch (obj.type) { diff --git a/meshctrl.js b/meshctrl.js index ead1759b..2685933e 100644 --- a/meshctrl.js +++ b/meshctrl.js @@ -1968,6 +1968,12 @@ function connectTunnel(url) { settings.tunnelws.on('message', function (rawdata) { var data = rawdata.toString(); if (settings.tunnelwsstate == 1) { + // If the incoming text looks exactly like a control command, ignore it. + if ((typeof data == 'string') && (data.startsWith('{"ctrlChannel":"102938","type":"'))) { + var ctrlCmd = null; + try { ctrlCmd = JSON.parse(data); } catch (ex) { } + if ((ctrlCmd != null) && (ctrlCmd.ctrlChannel == '102938') && (ctrlCmd.type != null)) return; // This is a control command, like ping/pong. Ignore it. + } process.stdout.write(data); } else if (settings.tunnelwsstate == 0) { if (data == 'c') { console.log('Connected.'); } else if (data == 'cr') { console.log('Connected, session is being recorded.'); } else return;