Mercurial > prosody-modules
annotate mod_register_url/mod_register_url.lua @ 412:8963f4026f3a
mod_s2s_never_encrypt_blacklist: first commit.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Fri, 02 Sep 2011 22:51:28 +0000 |
parents | df57fa689415 |
children |
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) |
409
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
8 local stanza, origin = event.stanza, event.origin; |
112
d1168a454107
mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
9 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
|
10 local url = module:get_option("registration_url"); |
408
ee28af887507
mod_register_url: minor fix.
Marco Cirillo <maranda@lightwitch.org>
parents:
368
diff
changeset
|
11 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
|
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 |
409
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
16 if origin.ip == ip then test_ip = true; end |
368
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 |
409
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
21 if stanza.attr.type == "get" then |
112
d1168a454107
mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
22 local reply = st.reply(event.stanza); |
409
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
23 reply:query("jabber:iq:register") |
112
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() |
409
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
25 :tag("x", {xmlns = "jabber:x:oob"}) |
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
26 :tag("url"):text(url); |
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
27 origin.send(reply); |
112
d1168a454107
mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
28 return true; |
409
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
29 else |
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
30 origin.send(st.error_reply(stanza, "cancel", "not-authorized")) |
df57fa689415
mod_register_url: code refactor, clean, all the rest (thanks Zash ;))
Marco Cirillo <maranda@lightwitch.org>
parents:
408
diff
changeset
|
31 return true |
112
d1168a454107
mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
32 end |
d1168a454107
mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
33 end |
d1168a454107
mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
34 |
d1168a454107
mod_regredirect: initial commit.
Marco Cirillo <maranda@lightwitch.org>
parents:
diff
changeset
|
35 module:hook("stanza/iq/jabber:iq:register:query", reg_redirect, 10); |