Adds multidomain support to rayo filter module.
This commit is contained in:
parent
fb556edb9d
commit
360283aa34
|
@ -1,6 +1,7 @@
|
|||
local st = require "util.stanza";
|
||||
|
||||
local token_util = module:require "token/util".new(module);
|
||||
local room_jid_match_rewrite = module:require "util".room_jid_match_rewrite;
|
||||
|
||||
-- no token configuration but required
|
||||
if token_util == nil then
|
||||
|
@ -30,7 +31,8 @@ module:hook("pre-iq/full", function(event)
|
|||
|
||||
if token == nil
|
||||
or roomName == nil
|
||||
or not token_util:verify_room(session, roomName) then
|
||||
or not token_util:verify_room(
|
||||
session, room_jid_match_rewrite(roomName)) then
|
||||
module:log("info",
|
||||
"Filtering stanza dial, stanza:%s", tostring(stanza));
|
||||
session.send(st.error_reply(stanza, "auth", "forbidden"));
|
||||
|
|
|
@ -1,6 +1,45 @@
|
|||
local jid = require "util.jid";
|
||||
local runner, waiter = require "util.async".runner, require "util.async".waiter;
|
||||
|
||||
local muc_domain_prefix
|
||||
= module:get_option_string("muc_mapper_domain_prefix", "conference");
|
||||
|
||||
-- defaults to module.host, the module that uses the utility
|
||||
local muc_domain_base
|
||||
= module:get_option_string("muc_mapper_domain_base", module.host);
|
||||
|
||||
-- The "real" MUC domain that we are proxying to
|
||||
local muc_domain = module:get_option_string(
|
||||
"muc_mapper_domain", muc_domain_prefix.."."..muc_domain_base);
|
||||
|
||||
local escaped_muc_domain_base = muc_domain_base:gsub("%p", "%%%1");
|
||||
local escaped_muc_domain_prefix = muc_domain_prefix:gsub("%p", "%%%1");
|
||||
-- The pattern used to extract the target subdomain
|
||||
-- (e.g. extract 'foo' from 'foo.muc.example.com')
|
||||
local target_subdomain_pattern
|
||||
= "^"..escaped_muc_domain_prefix..".([^%.]+)%."..escaped_muc_domain_base;
|
||||
|
||||
--- Utility function to check and convert a room JID from
|
||||
-- virtual room1@muc.foo.example.com to real [foo]room1@muc.example.com
|
||||
-- @param room_jid the room jid to match and rewrite if needed
|
||||
-- @return returns room jid [foo]room1@muc.example.com when it has subdomain
|
||||
-- otherwise room1@muc.example.com(the room_jid value untouched)
|
||||
local function room_jid_match_rewrite(room_jid)
|
||||
local node, host, resource = jid.split(room_jid);
|
||||
local target_subdomain = host and host:match(target_subdomain_pattern);
|
||||
if not target_subdomain then
|
||||
module:log("debug", "No need to rewrite out 'to' %s", room_jid);
|
||||
return room_jid;
|
||||
end
|
||||
-- Ok, rewrite room_jid address to new format
|
||||
local new_node, new_host, new_resource
|
||||
= "["..target_subdomain.."]"..node, muc_domain, resource;
|
||||
room_jid = jid.join(new_node, new_host, new_resource);
|
||||
module:log("debug", "Rewrote to %s", room_jid);
|
||||
return room_jid
|
||||
end
|
||||
|
||||
|
||||
--- Finds and returns room by its jid
|
||||
-- @param room_jid the room jid to search in the muc component
|
||||
-- @return returns room if found or nil
|
||||
|
@ -37,4 +76,5 @@ end
|
|||
return {
|
||||
get_room_from_jid = get_room_from_jid;
|
||||
wrap_async_run = wrap_async_run;
|
||||
room_jid_match_rewrite= room_jid_match_rewrite;
|
||||
};
|
Loading…
Reference in New Issue