Mercurial > prosody-modules
comparison mod_register_redirect/mod_register_redirect.lua @ 1100:aa93cf0b1242
mod_register_redirect: cleanup a bit.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Mon, 08 Jul 2013 00:43:20 +0200 |
parents | 7d1d3ca31d03 |
children | 7dbde05b48a9 |
comparison
equal
deleted
inserted
replaced
1099:754c15641369 | 1100:aa93cf0b1242 |
---|---|
6 -- Redirects IP addresses not in the whitelist to a web page or another method to complete the registration. | 6 -- Redirects IP addresses not in the whitelist to a web page or another method to complete the registration. |
7 | 7 |
8 local st = require "util.stanza" | 8 local st = require "util.stanza" |
9 local cman = configmanager | 9 local cman = configmanager |
10 | 10 |
11 local ip_wl = module:get_option_set("registration_whitelist", { "127.0.0.1" }) | |
12 local url = module:get_option_string("registration_url", nil) | |
13 local inst_text = module:get_option_string("registration_text", nil) | |
14 local oob = module:get_option_boolean("registration_oob", true) | |
15 local admins_g = cman.get("*", "core", "admins") | |
16 local admins_l = cman.get(module:get_host(), "core", "admins") | |
17 local no_wl = module:get_option_boolean("no_registration_whitelist", false) | |
18 | |
19 if type(admins_g) ~= "table" then admins_g = nil end | |
20 if type(admins_l) ~= "table" then admins_l = nil end | |
21 | |
11 function reg_redirect(event) | 22 function reg_redirect(event) |
12 local stanza, origin = event.stanza, event.origin | 23 local stanza, origin = event.stanza, event.origin |
13 local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" } | |
14 local url = module:get_option_string("registration_url", nil) | |
15 local inst_text = module:get_option_string("registration_text", nil) | |
16 local oob = module:get_option_boolean("registration_oob", true) | |
17 local admins_g = cman.get("*", "core", "admins") | |
18 local admins_l = cman.get(module:get_host(), "core", "admins") | |
19 local no_wl = module:get_option_boolean("no_registration_whitelist", false) | |
20 local test_ip = false | |
21 | 24 |
22 if type(admins_g) ~= "table" then admins_g = nil end | 25 if not no_wl and ip_wl:contains(origin.ip) then return; end |
23 if type(admins_l) ~= "table" then admins_l = nil end | |
24 | 26 |
25 -- perform checks to set default responses and sanity checks. | 27 -- perform checks to set default responses and sanity checks. |
26 if not inst_text then | 28 if not inst_text then |
27 if url and oob then | 29 if url and oob then |
28 if url:match("^%w+[:].*$") then | 30 if url:match("^%w+[:].*$") then |
62 module:log("error", "Please check your configuration, the URL specified is not valid.") | 64 module:log("error", "Please check your configuration, the URL specified is not valid.") |
63 return origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request. | 65 return origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request. |
64 end | 66 end |
65 end | 67 end |
66 | 68 |
67 if not no_wl then | |
68 for i,ip in ipairs(ip_wl) do | |
69 if origin.ip == ip then test_ip = true end | |
70 break | |
71 end | |
72 end | |
73 | |
74 -- Prepare replies. | 69 -- Prepare replies. |
75 local reply = st.reply(event.stanza) | 70 local reply = st.reply(event.stanza) |
76 if oob then | 71 if oob then |
77 reply:query("jabber:iq:register") | 72 reply:query("jabber:iq:register") |
78 :tag("instructions"):text(inst_text):up() | 73 :tag("instructions"):text(inst_text):up() |