1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
%%%----------------------------------------------------------------------
%%% File : mod_register_refer.erl
%%% Author : Michael Krause <mk@spline.de>
%%% Purpose : Refer Inband registrations to URL
%%% Created : 20 Oct 2013 by Michael Krause <mk@spline.de>
%%%
%%%
%%% ejabberd, Copyright (C) 2002-2013 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-module(mod_register_refer).
-author('mk@spline.de').
-behaviour(gen_mod).
-export( [ start/2,
stop/1,
stream_feature_register/2,
unauthenticated_iq_register/4 ] ).
-include("ejabberd.hrl").
-include("jlib.hrl").
start(Host, _Opts) ->
ejabberd_hooks:add(c2s_stream_features, Host,
?MODULE, stream_feature_register, 50),
ejabberd_hooks:add(c2s_unauthenticated_iq, Host,
?MODULE, unauthenticated_iq_register, 50).
stop(Host) ->
ejabberd_hooks:delete(c2s_stream_features, Host,
?MODULE, stream_feature_register, 50),
ejabberd_hooks:delete(c2s_unauthenticated_iq, Host,
?MODULE, unauthenticated_iq_register, 50).
stream_feature_register(Acc, _Host) ->
[{xmlelement, "register",
[{"xmlns", ?NS_FEATURE_IQREGISTER}], []} | Acc].
unauthenticated_iq_register(_Acc, Server, #iq{xmlns = ?NS_REGISTER } = IQ, _IP) ->
?INFO_MSG("mod_register_refer: refering unauthenticated_iq_register ", []),
jlib:iq_to_xml( process_iq(IQ, Server) ).
% protocol says, we may send a single instruction stanza to redirect
% TODO handle unregister requests as well?
process_iq(#iq{ lang = Lang } = IQ, Server) ->
case gen_mod:get_module_opt(Server, ?MODULE, url, []) of
[] ->
?WARNING_MSG("mod_register_refer: No URL given, check your ejabberd.cfg",[]),
Url = "https://accounts.spline.de";
[ReferUrl] -> Url = ReferUrl
end,
IQ#iq{type = result,
sub_el = [{xmlelement,"query", [{"xmlns", "jabber:iq:register"}],
[ {xmlelement, "instructions", [],
[{xmlcdata, translate:translate(
Lang,
"Registration is handled at:"
"https://accounts.spline.de" )}]},
{xmlelement, "x", [{"xmlns","jabber:x:oob"}],
[{xmlelement, "url", [],
[{xmlcdata, Url }] }] }
]}]}.
|