fix remoteaddr null in consent disconnect #6290
Signed-off-by: si458 <simonsmith5521@gmail.com>
si458 committed
Aug 27, 2024 at 10:46 UTC
e1e59953f48acc176b18da9c40f6c640b7950839
1 file changed
+23
-14
agents/meshcore.js
+23
-14
@@ -2616,11 +2616,14 @@ function kvm_tunnel_consentpromise_closehandler()
2616
2617
function kvm_consentpromise_rejected(e)
2618
{
2619
- // User Consent Denied/Failed
2620
- this.ws._consentpromise = null;
2621
- MeshServerLogEx(34, null, "Failed to start remote desktop after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2622
- this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
2623
- this.ws = null;
2619
+ if (this.ws) {
2620
+ if(this.ws.httprequest){ // User Consent Denied
2621
+ MeshServerLogEx(34, null, "Failed to start remote desktop after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2622
+ } else { } // Connection was closed server side, maybe log some messages somewhere?
2623
+ this.ws._consentpromise = null;
2624
+ this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
2625
+ this.ws = null;
2626
+ } else { } // no websocket, maybe log some messages somewhere?
2627
}
2628
function kvm_consentpromise_resolved(always)
2629
{
@@ -2715,11 +2718,14 @@ function files_consentpromise_resolved(always)
2718
}
2719
function files_consentpromise_rejected(e)
2720
{
2718
- // User Consent Denied/Failed
2719
- this.ws._consentpromise = null;
2720
- MeshServerLogEx(41, null, "Failed to start remote files after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2721
- this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
2722
- this.ws = null;
2721
+ if (this.ws) {
2722
+ if(this.ws.httprequest){ // User Consent Denied
2723
+ MeshServerLogEx(41, null, "Failed to start remote files after local user rejected (" + this.ws.httprequest.remoteaddr + ")", this.ws.httprequest);
2724
+ } else { } // Connection was closed server side, maybe log some messages somewhere?
2725
+ this.ws._consentpromise = null;
2726
+ this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
2727
+ this.ws = null;
2728
+ } else { } // no websocket, maybe log some messages somewhere?
2729
}
2730
function files_tunnel_endhandler()
2731
{
@@ -2867,10 +2873,13 @@ function onTunnelData(data)
2873
this.retPromise._res();
2874
},
2875
function (e) {
2870
- // Denied
2871
- MeshServerLogEx(28, null, "Local user rejected remote terminal request (" + this.retPromise.that.httprequest.remoteaddr + ")", this.retPromise.that.httprequest);
2872
- this.retPromise.that.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
2873
- this.retPromise._consent = null;
2876
+ if (this.retPromise.that) {
2877
+ if(this.retPromise.that.httprequest){ // User Consent Denied
2878
+ MeshServerLogEx(28, null, "Local user rejected remote terminal request (" + this.retPromise.that.httprequest.remoteaddr + ")", this.retPromise.that.httprequest);
2879
+ } else { } // Connection was closed server side, maybe log some messages somewhere?
2880
+ this.retPromise._consent = null;
2881
+ this.retPromise.that.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString(), msgid: 2 }));
2882
+ } else { } // no websocket, maybe log some messages somewhere?
2883
this.retPromise._rej(e.toString());
2884
});
2885
}