Support more captcha_host value formats (EJAB-1418)

This commit is contained in:
Badlop 2011-04-11 19:58:25 +02:00
parent 33745954a9
commit a2d60a1977
2 changed files with 14 additions and 9 deletions

View File

@ -1710,13 +1710,13 @@ The configurable options are:
Full path to a script that generates the image. Full path to a script that generates the image.
The default value is an empty string: \term{""} The default value is an empty string: \term{""}
\titem{\{captcha\_host, ProtocolHostPort\}} \titem{\{captcha\_host, ProtocolHostPort\}}
Host part of the URL sent to the user, ProtocolHostPort is a string with the host, and optionally the Protocol and Port number.
and the port number where ejabberd listens for CAPTCHA requests. It must identify where ejabberd listens for CAPTCHA requests.
The URL sent to the user is formed by: \term{http://Host:Port/captcha/} The URL sent to the user is formed by: \term{Protocol://Host:Port/captcha/}
The default value is: the first hostname configured, and port 5280. The default value is: protocol \term{http}, the first hostname configured, and port \term{80}.
If the port number you specify does not match exactly an ejabberd listener If you specify a port number that does not match exactly an ejabberd listener
(because you are using a reverse proxy or other port-forwarding tool), (because you are using a reverse proxy or other port-forwarding tool),
then specify also the transfer protocol, as seen in the example below. then you must specify the transfer protocol, as seen in the example below.
\end{description} \end{description}
Additionally, an \term{ejabberd\_http} listener must be enabled with the \term{captcha} option. Additionally, an \term{ejabberd\_http} listener must be enabled with the \term{captcha} option.
@ -1729,6 +1729,7 @@ Example configuration:
{captcha_cmd, "/lib/ejabberd/priv/bin/captcha.sh"}. {captcha_cmd, "/lib/ejabberd/priv/bin/captcha.sh"}.
{captcha_host, "example.org:5280"}. {captcha_host, "example.org:5280"}.
%% {captcha_host, "https://example.org:443"}. %% {captcha_host, "https://example.org:443"}.
%% {captcha_host, "http://example.com"}.
{listen, {listen,
[ [

View File

@ -627,13 +627,17 @@ get_prog_name() ->
get_url(Str) -> get_url(Str) ->
CaptchaHost = ejabberd_config:get_local_option(captcha_host), CaptchaHost = ejabberd_config:get_local_option(captcha_host),
case string:tokens(CaptchaHost, ":") of case string:tokens(CaptchaHost, ":") of
[TransferProt, Host, PortString] -> [Host] ->
TransferProt ++ ":" ++ Host ++ ":" ++ PortString ++ "/captcha/" ++ Str; "http://" ++ Host ++ "/captcha/" ++ Str;
["http"++_ = TransferProt, Host] ->
TransferProt ++ ":" ++ Host ++ "/captcha/" ++ Str;
[Host, PortString] -> [Host, PortString] ->
TransferProt = atom_to_list(get_transfer_protocol(PortString)), TransferProt = atom_to_list(get_transfer_protocol(PortString)),
TransferProt ++ "://" ++ Host ++ ":" ++ PortString ++ "/captcha/" ++ Str; TransferProt ++ "://" ++ Host ++ ":" ++ PortString ++ "/captcha/" ++ Str;
[TransferProt, Host, PortString] ->
TransferProt ++ ":" ++ Host ++ ":" ++ PortString ++ "/captcha/" ++ Str;
_ -> _ ->
"http://" ++ ?MYNAME ++ ":5280/captcha/" ++ Str "http://" ++ ?MYNAME ++ "/captcha/" ++ Str
end. end.
get_transfer_protocol(PortString) -> get_transfer_protocol(PortString) ->