changeset 1100:aa93cf0b1242

mod_register_redirect: cleanup a bit.
author Marco Cirillo <maranda@lightwitch.org>
date Mon, 08 Jul 2013 00:43:20 +0200
parents 754c15641369
children 479df3e0b012
files mod_register_redirect/mod_register_redirect.lua
diffstat 1 files changed, 12 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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