# HG changeset patch # User Marco Cirillo # Date 1373237000 -7200 # Node ID aa93cf0b1242e3dc28f45d9460b73be159b3e2be # Parent 754c15641369db59b17e8a703c6b672bb5bd6fd7 mod_register_redirect: cleanup a bit. diff -r 754c15641369 -r aa93cf0b1242 mod_register_redirect/mod_register_redirect.lua --- a/mod_register_redirect/mod_register_redirect.lua Mon Jul 01 23:06:00 2013 +0200 +++ b/mod_register_redirect/mod_register_redirect.lua Mon Jul 08 00:43:20 2013 +0200 @@ -8,19 +8,21 @@ local st = require "util.stanza" local cman = configmanager +local ip_wl = module:get_option_set("registration_whitelist", { "127.0.0.1" }) +local url = module:get_option_string("registration_url", nil) +local inst_text = module:get_option_string("registration_text", nil) +local oob = module:get_option_boolean("registration_oob", true) +local admins_g = cman.get("*", "core", "admins") +local admins_l = cman.get(module:get_host(), "core", "admins") +local no_wl = module:get_option_boolean("no_registration_whitelist", false) + +if type(admins_g) ~= "table" then admins_g = nil end +if type(admins_l) ~= "table" then admins_l = nil end + function reg_redirect(event) local stanza, origin = event.stanza, event.origin - local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" } - local url = module:get_option_string("registration_url", nil) - local inst_text = module:get_option_string("registration_text", nil) - local oob = module:get_option_boolean("registration_oob", true) - local admins_g = cman.get("*", "core", "admins") - local admins_l = cman.get(module:get_host(), "core", "admins") - local no_wl = module:get_option_boolean("no_registration_whitelist", false) - local test_ip = false - if type(admins_g) ~= "table" then admins_g = nil end - if type(admins_l) ~= "table" then admins_l = nil end + if not no_wl and ip_wl:contains(origin.ip) then return; end -- perform checks to set default responses and sanity checks. if not inst_text then @@ -64,13 +66,6 @@ end end - if not no_wl then - for i,ip in ipairs(ip_wl) do - if origin.ip == ip then test_ip = true end - break - end - end - -- Prepare replies. local reply = st.reply(event.stanza) if oob then