From 3e50b0bdab71ecd1fca567496db54a57a92e32cf Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Tue, 28 Apr 2020 11:36:04 -0700 Subject: [PATCH 1/3] Fixed unhandled exception that can occur when you close privacy bar --- agents/meshcore.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index b0617a58..b791ff4a 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1395,13 +1395,26 @@ function createMeshCore(agent) { --this.desktop.kvm.connectionCount; // Unpipe the web socket - this.unpipe(this.httprequest.desktop.kvm); - this.httprequest.desktop.kvm.unpipe(this); + try + { + this.unpipe(this.httprequest.desktop.kvm); + this.httprequest.desktop.kvm.unpipe(this); + } + catch(xx) + { + } // Unpipe the WebRTC channel if needed (This will also be done when the WebRTC channel ends). - if (this.rtcchannel) { - this.rtcchannel.unpipe(this.httprequest.desktop.kvm); - this.httprequest.desktop.kvm.unpipe(this.rtcchannel); + if (this.rtcchannel) + { + try + { + this.rtcchannel.unpipe(this.httprequest.desktop.kvm); + this.httprequest.desktop.kvm.unpipe(this.rtcchannel); + } + catch(xx) + { + } } // Place wallpaper back if needed @@ -1944,9 +1957,15 @@ function createMeshCore(agent) { this.websocket.rtcchannel.on('end', function () { // The WebRTC channel closed, unpipe the KVM now. This is also done when the web socket closes. //sendConsoleText('Tunnel #' + this.websocket.tunnel.index + ' WebRTC data channel closed'); - if (this.websocket.desktop && this.websocket.desktop.kvm) { - this.unpipe(this.websocket.desktop.kvm); - this.websocket.httprequest.desktop.kvm.unpipe(this); + if (this.websocket.desktop && this.websocket.desktop.kvm) + { + try + { + this.unpipe(this.websocket.desktop.kvm); + this.websocket.httprequest.desktop.kvm.unpipe(this); + } + catch (xx) + { } } }); this.websocket.write('{\"ctrlChannel\":\"102938\",\"type\":\"webrtc0\"}'); // Indicate we are ready for WebRTC switch-over. From 604ce474681805cd923c1473c0755bbb448d536e Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Tue, 28 Apr 2020 12:09:08 -0700 Subject: [PATCH 2/3] Updated, so if terminal or kvm is cancelled berfore consent is granted, consent request is dismissed, if supported --- agents/meshcore.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index b791ff4a..d56ee192 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1330,11 +1330,14 @@ function createMeshCore(agent) { var pr = require('message-box').create('MeshCentral', that.httprequest.username + " requesting Terminal Access. Grant access?", 30); pr.ws = that; that.pause(); + that._consentpromise = pr; + that.prependOnceListener('end', function () { if (this._consentpromise && this._consentpromise.close) { this._consentpromise.close(); } }); pr.then( function () { // Success + this.ws._consentpromise = null; MeshServerLog("Starting remote terminal after local user accepted (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest); this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null })); if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 2)) @@ -1347,6 +1350,7 @@ function createMeshCore(agent) { function (e) { // User Consent Denied/Failed + this.ws._consentpromise = null; MeshServerLog("Failed to start remote terminal after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest); this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() })); this.ws.end(); @@ -1469,17 +1473,21 @@ function createMeshCore(agent) { } // Perform notification if needed. Toast messages may not be supported on all platforms. - if (this.httprequest.consent && (this.httprequest.consent & 8)) { + if (this.httprequest.consent && (this.httprequest.consent & 8)) + { // User Consent Prompt is required // Send a console message back using the console channel, "\n" is supported. this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: "Waiting for user to grant access..." })); var pr = require('message-box').create('MeshCentral', this.httprequest.username + " requesting KVM Access. Grant access?", 30); pr.ws = this; this.pause(); - + this._consentpromise = pr; + this.prependOnceListener('end', function () { if (this._consentpromise && this._consentpromise.close) { this._consentpromise.close(); }}); pr.then( - function () { + function () + { // Success + this.ws._consentpromise = null; MeshServerLog("Starting remote desktop after local user accepted (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest); this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null })); if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1)) { @@ -1515,8 +1523,10 @@ function createMeshCore(agent) { this.ws.httprequest.desktop.kvm.pipe(this.ws, { dataTypeSkip: 1 }); this.ws.resume(); }, - function (e) { + function (e) + { // User Consent Denied/Failed + this.ws._consentpromise = null; MeshServerLog("Failed to start remote desktop after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest); this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() })); }); From ce58d71328724493faa6d3f0ff4aa3446ca00d97 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Tue, 28 Apr 2020 12:15:36 -0700 Subject: [PATCH 3/3] updated user consent for file access, so if request is cancelled, consent request is cancelled too, if supported. --- agents/meshcore.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index d56ee192..941d6512 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1589,10 +1589,13 @@ function createMeshCore(agent) { var pr = require('message-box').create('MeshCentral', this.httprequest.username + " requesting remote file access. Grant access?", 30); pr.ws = this; this.pause(); - + this._consentpromise = pr; + this.prependOnceListener('end', function () { if (this._consentpromise && this._consentpromise.close) { this._consentpromise.close(); } }); pr.then( - function () { + function () + { // Success + this.ws._consentpromise = null; MeshServerLog("Starting remote files after local user accepted (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest); this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null })); if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 4)) { @@ -1601,8 +1604,10 @@ function createMeshCore(agent) { } this.ws.resume(); }, - function (e) { + function (e) + { // User Consent Denied/Failed + this.ws._consentpromise = null; MeshServerLog("Failed to start remote files after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest); this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() })); });