From: Evgeny Khramtsov Date: Fri, 14 Jun 2019 13:06:04 +0000 (+0300) Subject: Introduce option 'captcha_url' X-Git-Tag: 19.08~212 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d85cf7780c76e20b6d7290aa49050161bc352496;p=ejabberd Introduce option 'captcha_url' Option 'captcha_host' is now deprecated in favor of 'captcha_url'. However, it's not replaced automatically at startup, i.e. both options are supported with 'captcha_url' being the preferred one. --- diff --git a/src/ejabberd_captcha.erl b/src/ejabberd_captcha.erl index 2d9a97fe3..e12116385 100644 --- a/src/ejabberd_captcha.erl +++ b/src/ejabberd_captcha.erl @@ -437,23 +437,29 @@ get_prog_name() -> -spec get_url(binary()) -> binary(). get_url(Str) -> + case ejabberd_option:captcha_url() of + undefined -> + URL = parse_captcha_host(), + <>; + URL -> + <> + end. + +-spec parse_captcha_host() -> binary(). +parse_captcha_host() -> CaptchaHost = ejabberd_option:captcha_host(), case str:tokens(CaptchaHost, <<":">>) of - [Host] -> - <<"http://", Host/binary, "/captcha/", Str/binary>>; - [<<"http", _/binary>> = TransferProt, Host] -> - <>; - [Host, PortString] -> - TransferProt = - iolist_to_binary(atom_to_list(get_transfer_protocol(PortString))), - <>; - [TransferProt, Host, PortString] -> - <>; + [Host] -> + <<"http://", Host/binary>>; + [<<"http", _/binary>> = TransferProt, Host] -> + <>; + [Host, PortString] -> + TransferProt = atom_to_binary(get_transfer_protocol(PortString), latin1), + <>; + [TransferProt, Host, PortString] -> + <>; _ -> - <<"http://", (ejabberd_config:get_myname())/binary, "/captcha/", Str/binary>> + <<"http://", (ejabberd_config:get_myname())/binary>> end. get_transfer_protocol(PortString) -> diff --git a/src/ejabberd_config_transformer.erl b/src/ejabberd_config_transformer.erl index 6d0af97fd..d76126e7e 100644 --- a/src/ejabberd_config_transformer.erl +++ b/src/ejabberd_config_transformer.erl @@ -194,6 +194,9 @@ filter(_Host, Opt, Val, _) when Opt == outgoing_s2s_timeout; Opt == s2s_dns_timeout -> warn_huge_timeout(Opt, Val), true; +filter(_Host, captcha_host, _, _) -> + warn_deprecated_option(captcha_host, captcha_url), + true; filter(Host, modules, ModOpts, State) -> NoDialbackHosts = maps:get(remove_s2s_dialback, State, []), ModOpts1 = lists:filter( @@ -443,6 +446,10 @@ warn_replaced_handler(Opt, {Path, Module}) -> "HTTP request handler: \"~s\" -> ~s. ~s", [Opt, Path, Module, adjust_hint()]). +warn_deprecated_option(OldOpt, NewOpt) -> + ?WARNING_MSG("Option '~s' is deprecated. Use option '~s' instead.", + [OldOpt, NewOpt]). + warn_replaced_option(OldOpt, NewOpt) -> ?WARNING_MSG("Option '~s' is deprecated and was automatically " "replaced by '~s'. ~s", diff --git a/src/ejabberd_option.erl b/src/ejabberd_option.erl index c7a24678c..34659f1cc 100644 --- a/src/ejabberd_option.erl +++ b/src/ejabberd_option.erl @@ -29,6 +29,7 @@ -export([captcha_cmd/0]). -export([captcha_host/0]). -export([captcha_limit/0]). +-export([captcha_url/0]). -export([certfiles/0]). -export([cluster_backend/0]). -export([cluster_nodes/0]). @@ -310,6 +311,10 @@ captcha_host() -> captcha_limit() -> ejabberd_config:get_option({captcha_limit, global}). +-spec captcha_url() -> 'undefined' | binary(). +captcha_url() -> + ejabberd_config:get_option({captcha_url, global}). + -spec certfiles() -> 'undefined' | [binary()]. certfiles() -> ejabberd_config:get_option({certfiles, global}). diff --git a/src/ejabberd_options.erl b/src/ejabberd_options.erl index e25cc2e64..013c2155c 100644 --- a/src/ejabberd_options.erl +++ b/src/ejabberd_options.erl @@ -94,6 +94,8 @@ opt_type(captcha_host) -> econf:binary(); opt_type(captcha_limit) -> econf:pos_int(infinity); +opt_type(captcha_url) -> + econf:url(); opt_type(certfiles) -> econf:list(econf:binary()); opt_type(cluster_backend) -> @@ -474,6 +476,7 @@ options() -> {captcha_cmd, undefined}, {captcha_host, <<"">>}, {captcha_limit, infinity}, + {captcha_url, undefined}, {certfiles, undefined}, {cluster_backend, mnesia}, {cluster_nodes, []}, @@ -651,6 +654,7 @@ globals() -> captcha_cmd, captcha_host, captcha_limit, + captcha_url, certfiles, cluster_backend, cluster_nodes,