From 353c68cfa6f42402a01b0f039a03a004350757b9 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 26 Dec 2022 10:52:16 +0100 Subject: [PATCH] Add support to define module instead of path to script --- src/ejabberd_captcha.erl | 13 +++++++++++++ src/ejabberd_options_doc.erl | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ejabberd_captcha.erl b/src/ejabberd_captcha.erl index db9a7d009..9db83a430 100644 --- a/src/ejabberd_captcha.erl +++ b/src/ejabberd_captcha.erl @@ -398,6 +398,18 @@ create_image(Limiter, Key) -> {error, image_error()}. do_create_image(Key) -> FileName = get_prog_name(), + case length(string:split(FileName, "/")) == 1 of + true -> + do_create_image(Key, misc:binary_to_atom(FileName)); + false -> + do_create_image(Key, FileName) + end. + +do_create_image(Key, Module) when is_atom(Module) -> + Function = create_image, + erlang:apply(Module, Function, [Key]); + +do_create_image(Key, FileName) when is_binary(FileName) -> Cmd = lists:flatten(io_lib:format("~ts ~ts", [FileName, Key])), case cmd(Cmd) of {ok, @@ -551,6 +563,7 @@ return(Port, TRef, Result) -> is_feature_available() -> case get_prog_name() of Prog when is_binary(Prog) -> true; + MF when is_list(MF) -> true; false -> false end. diff --git a/src/ejabberd_options_doc.erl b/src/ejabberd_options_doc.erl index 2558991b4..9c28418ce 100644 --- a/src/ejabberd_options_doc.erl +++ b/src/ejabberd_options_doc.erl @@ -454,13 +454,14 @@ doc() -> ?T("For server connections, this 'ca_file' option is overridden by the http://../toplevel/#s2s-cafile[s2s_cafile] option."), "" ]}}, {captcha_cmd, - #{value => ?T("Path"), - note => "improved in 21.10", + #{value => ?T("Path | ModuleName"), + note => "improved in 23.xx", desc => ?T("Full path to a script that generates http://../basic/#captcha[CAPTCHA] images. " "@VERSION@ is replaced with ejabberd version number in XX.YY format. " "@SEMVER@ is replaced with ejabberd version number in semver format " "when compiled with Elixir's mix, or XX.YY format otherwise. " + "Alternatively, it can be the name of a module that implements ejabberd CAPTCHA support. " "There is no default value: when this option is not " "set, CAPTCHA functionality is completely disabled."), example =>