Mercurial > prosody-modules
annotate mod_register_url/mod_register_url.lua @ 152:4ca382e8a4c5
mod_extauth: Initial commit.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 15 May 2010 23:05:53 +0500 |
parents | 7dff5fa275f4 |
children | 1f55e844efeb |
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); |