Desktop multiplex improvement.
Ylian Saint-Hilaire committed
Jun 30, 2021 at 10:36 UTC
2ec78f219f5dd98377a6bd036aeab1b678f35e85
1 file changed
+20
-18
meshdesktopmultiplex.js
+20
-18
@@ -921,22 +921,6 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
921
// If there is no authentication, drop this connection
922
if ((obj.id != null) && (obj.user == null) && (obj.ruserid == null)) { try { ws.close(); parent.parent.debug('relay', 'DesktopRelay: Connection with no authentication (' + obj.req.clientIp + ')'); } catch (e) { console.log(e); } return; }
923
924
- // Check if this user has input access on the device
925
- if ((obj.user != null) && (obj.viewOnly == false)) {
926
- obj.viewOnly = true; // Set a view only for now until we figure out otherwise
927
- parent.db.Get(obj.nodeid, function (err, docs) {
928
- if (obj.req == null) return; // This connection was closed.
929
- if (docs.length == 0) { console.log('ERR: Node not found'); try { obj.close(); } catch (e) { } return; } // Disconnect websocket
930
- const node = docs[0];
931
-
932
- // Check if this user has permission to manage this computer
933
- const rights = parent.GetNodeRights(obj.user, node.meshid, node._id);
934
- if ((rights & 0x00000008) == 0) { try { obj.close(); } catch (e) { } return; } // Check MESHRIGHT_ADMIN or MESHRIGHT_REMOTECONTROL
935
- if ((rights != 0xFFFFFFFF) && ((rights & 0x00010000) != 0)) { try { obj.close(); } catch (e) { } return; } // Check MESHRIGHT_NODESKTOP
936
- if ((rights == 0xFFFFFFFF) || ((rights & 0x00000100) == 0)) { obj.viewOnly = false; } // Check MESHRIGHT_REMOTEVIEWONLY
937
- });
938
- }
939
-
924
// Relay session count (we may remove this in the future)
925
obj.relaySessionCounted = true;
926
parent.relaySessionCount++;
@@ -1242,8 +1226,26 @@ function CreateMeshRelayEx2(parent, ws, req, domain, user, cookie) {
1226
}
1227
}
1228
1245
- // If this is not an authenticated session, or the session does not have routing instructions, just go ahead an connect to existing session.
1246
- performRelay(0);
1229
+
1230
+ // Check if this user has input access on the device
1231
+ if ((obj.user != null) && (obj.viewOnly == false)) {
1232
+ obj.viewOnly = true; // Set a view only for now until we figure out otherwise
1233
+ parent.db.Get(obj.nodeid, function (err, docs) {
1234
+ if (obj.req == null) return; // This connection was closed.
1235
+ if (docs.length == 0) { console.log('ERR: Node not found'); try { obj.close(); } catch (e) { } return; } // Disconnect websocket
1236
+ const node = docs[0];
1237
+
1238
+ // Check if this user has permission to manage this computer
1239
+ const rights = parent.GetNodeRights(obj.user, node.meshid, node._id);
1240
+ if ((rights & 0x00000008) == 0) { try { obj.close(); } catch (e) { } return; } // Check MESHRIGHT_ADMIN or MESHRIGHT_REMOTECONTROL
1241
+ if ((rights != 0xFFFFFFFF) && ((rights & 0x00010000) != 0)) { try { obj.close(); } catch (e) { } return; } // Check MESHRIGHT_NODESKTOP
1242
+ if ((rights == 0xFFFFFFFF) || ((rights & 0x00000100) == 0)) { obj.viewOnly = false; } // Check MESHRIGHT_REMOTEVIEWONLY
1243
+ performRelay(0);
1244
+ });
1245
+ } else {
1246
+ // If this is not an authenticated session, or the session does not have routing instructions, just go ahead an connect to existing session.
1247
+ performRelay(0);
1248
+ }
1249
return obj;
1250
};
1251