annotate mod_register_url/mod_register_url.lua @ 388:75aea9752062

mod_muc_log_http: Generate room calendar page even when there is no log data.
author Waqas Hussain <waqas20@gmail.com>
date Mon, 25 Jul 2011 02:21:40 +0500
parents 1f55e844efeb
children ee28af887507
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
112
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
1 -- Registration Redirect module for Prosody
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
2 --
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
3 -- Redirects IP addresses not in the whitelist to a web page to complete the registration.
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
4
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
5 local st = require "util.stanza";
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
6
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
7 function reg_redirect(event)
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
8 local ip_wl = module:get_option("registration_whitelist") or { "127.0.0.1" };
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
9 local url = module:get_option("registration_url");
368
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
10 local no_wl = module:get_option("no_registration_whitelist") or false;
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
11 if type(no_wl) ~= boolean then no_wl = false end
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
12 local test_ip = false;
112
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
13
368
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
14 if not no_wl then
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
15 for i,ip in ipairs(ip_wl) do
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
16 if event.origin.ip == ip then test_ip = true; end
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
17 break;
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
18 end
112
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
19 end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
20
368
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
21 if not test_ip and url ~= nil or no_wl and url ~= nil then
112
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
22 local reply = st.reply(event.stanza);
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
23 reply:tag("query", {xmlns = "jabber:iq:register"})
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
24 :tag("instructions"):text("Please visit "..url.." to register an account on this server."):up()
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
25 :tag("x", {xmlns = "jabber:x:oob"}):up()
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
26 :tag("url"):text(url):up();
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
27 event.origin.send(reply);
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
28 return true;
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
29 end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
30 end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
31
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
32 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10);