25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Provide HTTPS URL in CAPTCHA form when listener has 'tls' option (EJAB-1406)

This commit is contained in:
Badlop 2011-02-14 12:58:33 +01:00
parent ca59a7f027
commit f91eb52890

View File

@ -405,13 +405,53 @@ get_prog_name() ->
end. end.
get_url(Str) -> get_url(Str) ->
case ejabberd_config:get_local_option(captcha_host) of CaptchaHost = ejabberd_config:get_local_option(captcha_host),
TransferProt = atom_to_list(get_transfer_protocol(CaptchaHost)),
case CaptchaHost of
Host when is_list(Host) -> Host when is_list(Host) ->
"http://" ++ Host ++ "/captcha/" ++ Str; TransferProt ++ "://" ++ Host ++ "/captcha/" ++ Str;
_ -> _ ->
"http://" ++ ?MYNAME ++ "/captcha/" ++ Str TransferProt ++ "://" ++ ?MYNAME ++ "/captcha/" ++ Str
end. end.
get_transfer_protocol(CaptchaHost) ->
PortNumber = get_port_number_from_captcha_host_option(CaptchaHost),
PortListeners = get_port_listeners(PortNumber),
get_captcha_transfer_protocol(PortListeners).
get_port_number_from_captcha_host_option(CaptchaHost) ->
[_Host, PortString] = string:tokens(CaptchaHost, ":"),
list_to_integer(PortString).
get_port_listeners(PortNumber) ->
AllListeners = ejabberd_config:get_local_option(listen),
lists:filter(
fun({{Port, _Ip, _Netp}, _Module1, _Opts1}) when Port == PortNumber ->
true;
(_) ->
false
end,
AllListeners).
get_captcha_transfer_protocol([]) ->
throw("The port number mentioned in captcha_host is not "
"a ejabberd_http listener with 'captcha' option.");
get_captcha_transfer_protocol([{{_Port, _Ip, tcp}, ejabberd_http, Opts}
| Listeners]) ->
case lists:member(captcha, Opts) of
true ->
case lists:member(tls, Opts) of
true ->
https;
false ->
http
end;
false ->
get_captcha_transfer_protocol(Listeners)
end;
get_captcha_transfer_protocol([_ | Listeners]) ->
get_captcha_transfer_protocol(Listeners).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Function: cmd(Cmd) -> Data | {error, Reason} %% Function: cmd(Cmd) -> Data | {error, Reason}
%% Cmd = string() %% Cmd = string()