|
1 -- Register via OOB URL |
|
2 -- Copyright (c) 2018 Daniel Gultsch |
|
3 -- |
|
4 -- This module is MIT/X11 licensed |
|
5 -- |
|
6 |
|
7 local st = require "util.stanza"; |
|
8 local namespace = "http://jabber.org/features/iq-register" |
|
9 local register_stream_feature = st.stanza("register", {xmlns=namespace}):up(); |
|
10 local allow_registration = module:get_option_boolean("allow_registration", false); |
|
11 local registration_url = module:get_option_string("register_oob_url", nil) |
|
12 |
|
13 if allow_registration then |
|
14 module:log("info","obb registration is disabled as long as IBR is allowed. Set `allow_registration` to false") |
|
15 end |
|
16 |
|
17 if not registration_url then |
|
18 module:log("info","registration url not configured. Add `register_oob_url` to prosody.cfg") |
|
19 end |
|
20 |
|
21 local function on_stream_features(event) |
|
22 if not registration_url then |
|
23 return |
|
24 end |
|
25 local session, features = event.origin, event.features; |
|
26 if session.type == "c2s_unauthed" and not allow_registration then |
|
27 features:add_child(register_stream_feature); |
|
28 end |
|
29 end |
|
30 |
|
31 local function on_registration_requested(event) |
|
32 local session, stanza = event.origin, event.stanza |
|
33 if session.type ~= "c2s_unauthed" or stanza.attr.type ~= "get" then |
|
34 return |
|
35 end |
|
36 if not allow_registration and registration_url then |
|
37 local reply = st.reply(stanza) |
|
38 reply:query("jabber:iq:register") |
|
39 :tag("x", {xmlns = "jabber:x:oob"}) |
|
40 :tag("url"):text(registration_url); |
|
41 return session.send(reply) |
|
42 end |
|
43 end |
|
44 |
|
45 module:hook("stream-features", on_stream_features) |
|
46 module:hook("stanza/iq/jabber:iq:register:query", on_registration_requested, 1) |
|
47 |
|
48 -- vim: noexpandtab tabstop=4 shiftwidth=4 |