瀏覽代碼

Merge pull request #1921 from jitsi/rayo_filter_subdomains_support

Adds multidomain support to rayo filter module.
master
Aaron van Meerten 7 年之前
父節點
當前提交
45b8693a3e
共有 2 個文件被更改,包括 43 次插入1 次删除
  1. 3
    1
      resources/prosody-plugins/mod_filter_iq_rayo.lua
  2. 40
    0
      resources/prosody-plugins/util.lib.lua

+ 3
- 1
resources/prosody-plugins/mod_filter_iq_rayo.lua 查看文件

@@ -1,6 +1,7 @@
1 1
 local st = require "util.stanza";
2 2
 
3 3
 local token_util = module:require "token/util".new(module);
4
+local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;
4 5
 
5 6
 -- no token configuration but required
6 7
 if token_util == nil then
@@ -30,7 +31,8 @@ module:hook("pre-iq/full", function(event)
30 31
 
31 32
             if token == nil
32 33
                 or roomName == nil
33
-                or not token_util:verify_room(session, roomName) then
34
+                or not token_util:verify_room(
35
+                            session, room_jid_match_rewrite(roomName)) then
34 36
                 module:log("info",
35 37
                     "Filtering stanza dial, stanza:%s", tostring(stanza));
36 38
                 session.send(st.error_reply(stanza, "auth", "forbidden"));

+ 40
- 0
resources/prosody-plugins/util.lib.lua 查看文件

@@ -1,6 +1,45 @@
1 1
 local jid = require "util.jid";
2 2
 local runner, waiter = require "util.async".runner, require "util.async".waiter;
3 3
 
4
+local muc_domain_prefix
5
+    = module:get_option_string("muc_mapper_domain_prefix", "conference");
6
+
7
+-- defaults to module.host, the module that uses the utility
8
+local muc_domain_base
9
+    = module:get_option_string("muc_mapper_domain_base", module.host);
10
+
11
+-- The "real" MUC domain that we are proxying to
12
+local muc_domain = module:get_option_string(
13
+    "muc_mapper_domain", muc_domain_prefix.."."..muc_domain_base);
14
+
15
+local escaped_muc_domain_base = muc_domain_base:gsub("%p", "%%%1");
16
+local escaped_muc_domain_prefix = muc_domain_prefix:gsub("%p", "%%%1");
17
+-- The pattern used to extract the target subdomain
18
+-- (e.g. extract 'foo' from 'foo.muc.example.com')
19
+local target_subdomain_pattern
20
+    = "^"..escaped_muc_domain_prefix..".([^%.]+)%."..escaped_muc_domain_base;
21
+
22
+--- Utility function to check and convert a room JID from
23
+-- virtual room1@muc.foo.example.com to real [foo]room1@muc.example.com
24
+-- @param room_jid the room jid to match and rewrite if needed
25
+-- @return returns room jid [foo]room1@muc.example.com when it has subdomain
26
+-- otherwise room1@muc.example.com(the room_jid value untouched)
27
+local function room_jid_match_rewrite(room_jid)
28
+    local node, host, resource = jid.split(room_jid);
29
+    local target_subdomain = host and host:match(target_subdomain_pattern);
30
+    if not target_subdomain then
31
+        module:log("debug", "No need to rewrite out 'to' %s", room_jid);
32
+        return room_jid;
33
+    end
34
+    -- Ok, rewrite room_jid  address to new format
35
+    local new_node, new_host, new_resource
36
+        = "["..target_subdomain.."]"..node, muc_domain, resource;
37
+    room_jid = jid.join(new_node, new_host, new_resource);
38
+    module:log("debug", "Rewrote to %s", room_jid);
39
+    return room_jid
40
+end
41
+
42
+
4 43
 --- Finds and returns room by its jid
5 44
 -- @param room_jid the room jid to search in the muc component
6 45
 -- @return returns room if found or nil
@@ -37,4 +76,5 @@ end
37 76
 return {
38 77
     get_room_from_jid = get_room_from_jid;
39 78
     wrap_async_run = wrap_async_run;
79
+    room_jid_match_rewrite= room_jid_match_rewrite;
40 80
 };

Loading…
取消
儲存