Mercurial > prosody-modules
comparison mod_register_redirect/mod_register_redirect.lua @ 442:761b7e1bb7ab
mod_register_redirect: few mistake fixes to make it work.
| author | Marco Cirillo <maranda@lightwitch.org> |
|---|---|
| date | Thu, 22 Sep 2011 16:04:38 +0000 |
| parents | bfc8bc7d77f3 |
| children | 7679b8f6b886 |
comparison
equal
deleted
inserted
replaced
| 441:bfc8bc7d77f3 | 442:761b7e1bb7ab |
|---|---|
| 6 local cman = require "core.configmanager"; | 6 local cman = require "core.configmanager"; |
| 7 | 7 |
| 8 function reg_redirect(event) | 8 function reg_redirect(event) |
| 9 local stanza, origin = event.stanza, event.origin; | 9 local stanza, origin = event.stanza, event.origin; |
| 10 local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" }; | 10 local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" }; |
| 11 local url = module:get_option_string("registration_url" or nil); | 11 local url = module:get_option_string("registration_url", nil); |
| 12 local inst_text = module:get_option_string("registration_text" or nil); | 12 local inst_text = module:get_option_string("registration_text", nil); |
| 13 local oob = module:get_option_boolean("registration_oob" or true); | 13 local oob = module:get_option_boolean("registration_oob", true); |
| 14 local admins_g = cman.get("*", core, "admins"); | 14 local admins_g = cman.get("*", "core", "admins"); |
| 15 local admins_l = cman.get(module:get_host(), core, "admins"); | 15 local admins_l = cman.get(module:get_host(), "core", "admins"); |
| 16 local no_wl = module:get_option_boolean("no_registration_whitelist", false); | 16 local no_wl = module:get_option_boolean("no_registration_whitelist", false); |
| 17 local test_ip = false; | 17 local test_ip = false; |
| 18 | 18 |
| 19 if type(admins_g) ~= "table" then admins_g = nil; end | 19 if type(admins_g) ~= "table" then admins_g = nil; end |
| 20 if type(admins_l) ~= "table" then admins_g = nil; end | 20 if type(admins_l) ~= "table" then admins_l = nil; end |
| 21 | 21 |
| 22 -- perform checks to set default responses and sanity checks. | 22 -- perform checks to set default responses and sanity checks. |
| 23 if not inst_text then | 23 if not inst_text then |
| 24 if url and oob then | 24 if url and oob then |
| 25 if url:match("^%w+[:].*$") then | 25 if url:match("^%w+[:].*$") then |
| 26 if url:match("^(%w+)[:].*$") == "http" or url:match("^(%w+)[:].*$") == "https" then | 26 if url:match("^(%w+)[:].*$") == "http" or url:match("^(%w+)[:].*$") == "https" then |
| 27 inst_text = "Please visit "..url.." to register an account on this server." | 27 inst_text = "Please visit "..url.." to register an account on this server." |
| 28 elseif url:match("^(%w+)[:].*$") == "mailto" then | 28 elseif url:match("^(%w+)[:].*$") == "mailto" then |
| 29 inst_text = "Please send an e-mail at "..url:match("^%w+[:](.*)$").." to register an account on this server." | 29 inst_text = "Please send an e-mail at "..url:match("^%w+[:](.*)$").." to register an account on this server." |
| 30 elseif url:match("^(%w+)[:].*$") == "xmpp" then | 30 elseif url:match("^(%w+)[:].*$") == "xmpp" then |
| 31 inst_text = "Please contact "..module:get_host().." server administrator via xmpp to register an account on this server at: "..url:match("^%w+[:](.*)$") | 31 inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..url:match("^%w+[:](.*)$") |
| 32 else | 32 else |
| 33 module:log("error", "This module supports only http/https, mailto or xmpp as URL formats.") | 33 module:log("error", "This module supports only http/https, mailto or xmpp as URL formats.") |
| 34 module:log("error", "If you want to use personalized instructions without an Out-Of-Band method,") | 34 module:log("error", "If you want to use personalized instructions without an Out-Of-Band method,") |
| 35 module:log("error", "specify: register_oob = false; -- in your configuration along your banner string (register_text).") | 35 module:log("error", "specify: register_oob = false; -- in your configuration along your banner string (register_text).") |
| 36 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); return true -- bouncing request. | 36 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); return true -- bouncing request. |
| 40 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); return true -- bouncing request. | 40 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); return true -- bouncing request. |
| 41 end | 41 end |
| 42 else | 42 else |
| 43 if admins_l then | 43 if admins_l then |
| 44 local ajid; for _,v in ipairs(admins_l) do ajid = v; break; end | 44 local ajid; for _,v in ipairs(admins_l) do ajid = v; break; end |
| 45 inst_text = "Please contact "..module:get_host().." server administrator via xmpp to register an account on this server at: "..ajid | 45 inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..ajid |
| 46 else | 46 else |
| 47 if admins_g then | 47 if admins_g then |
| 48 local ajid; for _,v in ipairs(admins_g) do ajid = v; break; end | 48 local ajid; for _,v in ipairs(admins_g) do ajid = v; break; end |
| 49 inst_text = "Please contact "..module:get_host().." server administrator via xmpp to register an account on this server at: "..ajid | 49 inst_text = "Please contact "..module:get_host().."'s server administrator via xmpp to register an account on this server at: "..ajid |
| 50 else | 50 else |
| 51 module:log("error", "Please be sure to, _at the very least_, configure one server administrator either global or hostwise...") | 51 module:log("error", "Please be sure to, _at the very least_, configure one server administrator either global or hostwise...") |
| 52 module:log("error", "if you want to use this module, or read it's configuration wiki at: http://code.google.com/p/prosody-modules/wiki/mod_register_redirect") | 52 module:log("error", "if you want to use this module, or read it's configuration wiki at: http://code.google.com/p/prosody-modules/wiki/mod_register_redirect") |
| 53 origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request. | 53 origin.send(st.error_reply(stanza, "wait", "internal-server-error")) -- bouncing request. |
| 54 return true; | 54 return true; |
