%%%---------------------------------------------------------------------- %%% File : mod_register_refer.erl %%% Author : Michael Krause %%% Purpose : Refer Inband registrations to URL %%% Created : 20 Oct 2013 by Michael Krause %%% %%% %%% 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 }] }] } ]}]}.