Quellcode durchsuchen

Moderated rooms or subdomains (#6959)

* fix: Fixes using token with no user context.

* feat(moderated): Adds option to add moderated rooms and subdomains.

When a user joins such room or subdomain in order to be a moderator needs to provide a valid jwt token for that room.

* squash: Renames function.

* ref: Removes filtering jicofo setting owners.

This will be disabled on jicofo side and will greatly simplify logic.
Also check the checks to avoid jwt for main domain to access subdomains and the other way around.

* fix: Skips allowners logic for admins.
master
Дамян Минков vor 4 Jahren
Ursprung
Commit
e6dbe65193
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 1
- 1
react/features/base/jwt/middleware.js Datei anzeigen

@@ -141,7 +141,7 @@ function _setJWT(store, next, action) {
141 141
                 action.jwt = jwt;
142 142
                 action.issuer = iss;
143 143
                 if (context) {
144
-                    const user = _user2participant(context.user);
144
+                    const user = _user2participant(context.user || {});
145 145
 
146 146
                     action.callee = context.callee;
147 147
                     action.group = context.group;

+ 62
- 1
resources/prosody-plugins/mod_muc_allowners.lua Datei anzeigen

@@ -1,12 +1,71 @@
1
+local jid = require "util.jid";
2
+local um_is_admin = require "core.usermanager".is_admin;
1 3
 local is_healthcheck_room = module:require "util".is_healthcheck_room;
2 4
 
5
+local moderated_subdomains;
6
+local moderated_rooms;
7
+
8
+local function load_config()
9
+    moderated_subdomains = module:get_option_set("allowners_moderated_subdomains", {})
10
+    moderated_rooms = module:get_option_set("allowners_moderated_rooms", {})
11
+end
12
+load_config();
13
+
14
+local function is_admin(jid)
15
+    return um_is_admin(jid, module.host);
16
+end
17
+
18
+-- Checks whether the jid is moderated, the room name is in moderated_rooms
19
+-- or if the subdomain is in the moderated_subdomains
20
+-- @return returns on of the:
21
+--      -> false
22
+--      -> true, room_name, subdomain
23
+--      -> true, room_name, nil (if no subdomain is used for the room)
24
+local function is_moderated(room_jid)
25
+    local room_node = jid.node(room_jid);
26
+    -- parses bare room address, for multidomain expected format is:
27
+    -- [subdomain]roomName@conference.domain
28
+    local target_subdomain, target_room_name = room_node:match("^%[([^%]]+)%](.+)$");
29
+
30
+    if target_subdomain then
31
+        if moderated_subdomains:contains(target_subdomain) then
32
+            return true, target_room_name, target_subdomain;
33
+        end
34
+    elseif moderated_rooms:contains(room_node) then
35
+        return true, room_node, nil;
36
+    end
37
+
38
+    return false;
39
+end
40
+
3 41
 module:hook("muc-occupant-joined", function (event)
4 42
     local room, occupant = event.room, event.occupant;
5 43
 
6
-    if is_healthcheck_room(room.jid) then
44
+    if is_healthcheck_room(room.jid) or is_admin(occupant.jid) then
7 45
         return;
8 46
     end
9 47
 
48
+    local moderated, room_name, subdomain = is_moderated(room.jid);
49
+    if moderated then
50
+        local session = event.origin;
51
+        local token = session.auth_token;
52
+
53
+        if not token then
54
+            module:log('debug', 'skip allowners for non-auth user subdomain:%s room_name:%s', subdomain, room_name);
55
+            return;
56
+        end
57
+
58
+        if not (room_name == session.jitsi_meet_room) then
59
+            module:log('debug', 'skip allowners for auth user and non matching room name: %s, jwt room name: %s', room_name, session.jitsi_meet_room);
60
+            return;
61
+        end
62
+
63
+        if not (subdomain == session.jitsi_meet_context_group) then
64
+            module:log('debug', 'skip allowners for auth user and non matching room subdomain: %s, jwt subdomain: %s', subdomain, session.jitsi_meet_context_group);
65
+            return;
66
+        end
67
+    end
68
+
10 69
     room:set_affiliation(true, occupant.bare_jid, "owner");
11 70
 end, 2);
12 71
 
@@ -19,3 +78,5 @@ module:hook("muc-occupant-left", function (event)
19 78
 
20 79
     room:set_affiliation(true, occupant.bare_jid, nil);
21 80
 end, 2);
81
+
82
+module:hook_global('config-reloaded', load_config);

Laden…
Abbrechen
Speichern