annotate mod_register_url/mod_register_url.lua @ 127:6c454d7208ae

mod_s2s_idle_timeout: Close idle connections after s2s_idle_timeout seconds, default 300s
author Matthew Wild <mwild1@gmail.com>
date Thu, 28 Jan 2010 17:40:29 +0000
parents 7dff5fa275f4
children 1f55e844efeb
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");
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
10 local test_ip;
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
11
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
12 for i,ip in ipairs(ip_wl) do
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
13 if event.origin.ip == ip then test_ip = true; end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
14 break;
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
15 end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
16
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
17 if not test_ip and url ~= nil then
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
18 local reply = st.reply(event.stanza);
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
19 reply:tag("query", {xmlns = "jabber:iq:register"})
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
20 :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
21 :tag("x", {xmlns = "jabber:x:oob"}):up()
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
22 :tag("url"):text(url):up();
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
23 event.origin.send(reply);
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
24 return true;
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
25 end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
26 end
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
27
d1168a454107 mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff changeset
28 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10);