# HG changeset patch # User Nicolás Kovac # Date 1424467719 0 # Node ID ca04f75958f7aab6272a3dbe8fcbd673febba5c8 # Parent 247e6e43843ea6298aac75cfa4bafaa629a8e82a mod_muc_restrict_rooms: Some fixes based on Matthew's comments + a few more diff -r 247e6e43843e -r ca04f75958f7 mod_muc_restrict_rooms/mod_muc_restrict_rooms.lua --- a/mod_muc_restrict_rooms/mod_muc_restrict_rooms.lua Fri Feb 20 18:00:56 2015 +0000 +++ b/mod_muc_restrict_rooms/mod_muc_restrict_rooms.lua Fri Feb 20 21:28:39 2015 +0000 @@ -1,4 +1,5 @@ local st = require "util.stanza"; +local jid = require "util.jid"; local nodeprep = require "util.encodings".stringprep.nodeprep; local rooms = module:shared "muc/rooms"; @@ -7,22 +8,21 @@ return; end -local admins = module:get_option_set("admins", {}); local restrict_patterns = module:get_option("muc_restrict_matching", {}); local restrict_excepts = module:get_option_set("muc_restrict_exceptions", {}); -local restrict_allow_admins = module:get_option_set("muc_restrict_allow_admins", false); +local restrict_allow_admins = module:get_option_boolean("muc_restrict_allow_admins", false); local function is_restricted(room, who) -- If admins can join prohibited rooms, we allow them to - if (restrict_allow_admins == true) and (admins:contains(who)) then + if restrict_allow_admins and usermanager.is_admin(who, module.host) then module:log("debug", "Admins are allowed to enter restricted rooms (%s on %s)", who, room) - return false; + return nil; end -- Don't evaluate exceptions - if restrict_excepts:contains(room:lower()) then - module:log("debug", "Room %s is amongst restriction exceptions", room:lower()) - return false; + if restrict_excepts:contains(room) then + module:log("debug", "Room %s is amongst restriction exceptions", room()) + return nil; end -- Evaluate regexps of restricted patterns @@ -44,11 +44,11 @@ end -- Get the room - local room = stanza.attr.from:match("([^@]+)@[^@]+") + local room = jid.split(stanza.attr.from); if not room then return; end -- Get who has tried to join it - local who = stanza.attr.to:match("([^\/]+)\/[^\/]+") + local who = jid.bare(stanza.attr.to) -- Checking whether room is restricted local check_restricted = is_restricted(room, who)