annotate mod_register_url/mod_register_url.lua @ 408:ee28af887507

mod_register_url: minor fix.
author Marco Cirillo <maranda@lightwitch.org>
date Tue, 30 Aug 2011 21:22:47 +0000
parents 1f55e844efeb
children df57fa689415
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");
408
ee28af887507 mod_register_url: minor fix.
Marco Cirillo <maranda@lightwitch.org>
parents: 368
diff changeset
10 local no_wl = module:get_option_boolean("no_registration_whitelist", false);
368
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
11 local test_ip = false;
112
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
12
368
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
13 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
14 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
15 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
16 break;
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
17 end
112
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
18 end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
19
368
1f55e844efeb mod_register_url: added option to specify no whitelististing is employed.
Marco Cirillo <maranda@lightwitch.org>
parents: 113
diff changeset
20 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
21 local reply = st.reply(event.stanza);
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
22 reply:tag("query", {xmlns = "jabber:iq:register"})
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
23 :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
24 :tag("x", {xmlns = "jabber:x:oob"}):up()
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
25 :tag("url"):text(url):up();
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
26 event.origin.send(reply);
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
27 return true;
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
28 end
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
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
31 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10);