]> granicus.if.org Git - ejabberd/commitdiff
Introduce option 'captcha_url'
authorEvgeny Khramtsov <ekhramtsov@process-one.net>
Fri, 14 Jun 2019 13:06:04 +0000 (16:06 +0300)
committerEvgeny Khramtsov <ekhramtsov@process-one.net>
Fri, 14 Jun 2019 13:06:04 +0000 (16:06 +0300)
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.

src/ejabberd_captcha.erl
src/ejabberd_config_transformer.erl
src/ejabberd_option.erl
src/ejabberd_options.erl

index 2d9a97fe32c068ec1429c7e93ca7343249d6b8ab..e121163858a41d58259fbb014db3e275579630fb 100644 (file)
@@ -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/binary, "/captcha/", Str/binary>>;
+       URL ->
+           <<URL/binary, $/, Str/binary>>
+    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] ->
-         <<TransferProt/binary, ":", Host/binary, "/captcha/",
-           Str/binary>>;
-      [Host, PortString] ->
-         TransferProt =
-             iolist_to_binary(atom_to_list(get_transfer_protocol(PortString))),
-         <<TransferProt/binary, "://", Host/binary, ":",
-           PortString/binary, "/captcha/", Str/binary>>;
-      [TransferProt, Host, PortString] ->
-         <<TransferProt/binary, ":", Host/binary, ":",
-           PortString/binary, "/captcha/", Str/binary>>;
+       [Host] ->
+           <<"http://", Host/binary>>;
+       [<<"http", _/binary>> = TransferProt, Host] ->
+           <<TransferProt/binary, ":", Host/binary>>;
+       [Host, PortString] ->
+           TransferProt = atom_to_binary(get_transfer_protocol(PortString), latin1),
+           <<TransferProt/binary, "://", Host/binary, ":", PortString/binary>>;
+       [TransferProt, Host, PortString] ->
+           <<TransferProt/binary, ":", Host/binary, ":", PortString/binary>>;
       _ ->
-         <<"http://", (ejabberd_config:get_myname())/binary, "/captcha/", Str/binary>>
+           <<"http://", (ejabberd_config:get_myname())/binary>>
     end.
 
 get_transfer_protocol(PortString) ->
index 6d0af97fdc19e6d568a0a7a4ce18b6aa19d6109b..d76126e7e153e16acb870c8ad55ccf53018a8155 100644 (file)
@@ -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",
index c7a24678c6bc67656c6e6dfc7d7de9730d4e79f0..34659f1cc42cc45fe04e8eb458c215cd6aafd47a 100644 (file)
@@ -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}).
index e25cc2e6405a4d3385ca63040deaf170961e22dc..013c2155cfaa6c05536ef79ba2d092db18367f56 100644 (file)
@@ -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,