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

Added support for captcha feature disability (EJAB-895)

If the option captcha_cmd is set but captcha can't be created:
* show critical error at server start
* hide captcha option in room configuration form
* don't require occupants to fill captcha

SVN Revision: 2101
This commit is contained in:
Badlop 2009-05-26 11:53:58 +00:00
parent 5c00365550
commit 29607291ae
2 changed files with 36 additions and 5 deletions

View File

@ -17,7 +17,7 @@
terminate/2, code_change/3]).
-export([create_captcha/6, build_captcha_html/2, check_captcha/2,
process_reply/1, process/2]).
process_reply/1, process/2, is_feature_available/0]).
-include("jlib.hrl").
-include("ejabberd.hrl").
@ -227,6 +227,7 @@ init([]) ->
[{ram_copies, [node()]},
{attributes, record_info(fields, captcha)}]),
mnesia:add_table_copy(captcha, node(), ram_copies),
check_captcha_setup(),
{ok, #state{}}.
handle_call(_Request, _From, State) ->
@ -359,3 +360,28 @@ return(Port, TRef, Result) ->
end,
catch port_close(Port),
Result.
is_feature_enabled() ->
case get_prog_name() of
"" -> false;
Prog when is_list(Prog) -> true
end.
is_feature_available() ->
case is_feature_enabled() of
false -> false;
true ->
case create_image() of
{ok, _, _, _} -> true;
_Error -> false
end
end.
check_captcha_setup() ->
case is_feature_enabled() andalso not is_feature_available() of
true ->
?CRITICAL_MSG("Captcha is enabled in the option captcha_cmd, "
"but it can't generate images.", []);
false ->
ok
end.

View File

@ -1620,7 +1620,8 @@ check_password(_ServiceAffiliation, Affiliation, Els, From, StateData) ->
end.
check_captcha(Affiliation, From, StateData) ->
case (StateData#state.config)#config.captcha_protected of
case (StateData#state.config)#config.captcha_protected
andalso ejabberd_captcha:is_feature_available() of
true when Affiliation == none ->
case ?DICT:find(From, StateData#state.robots) of
{ok, passed} ->
@ -2838,9 +2839,6 @@ get_config(Lang, StateData, From) ->
?BOOLXFIELD("Make room members-only",
"muc#roomconfig_membersonly",
Config#config.members_only),
?BOOLXFIELD("Make room captcha protected",
"captcha_protected",
Config#config.captcha_protected),
?BOOLXFIELD("Make room moderated",
"muc#roomconfig_moderatedroom",
Config#config.moderated),
@ -2866,6 +2864,13 @@ get_config(Lang, StateData, From) ->
"muc#roomconfig_allowvisitornickchange",
Config#config.allow_visitor_nickchange)
] ++
case ejabberd_captcha:is_feature_available() of
true ->
[?BOOLXFIELD("Make room captcha protected",
"captcha_protected",
Config#config.captcha_protected)];
false -> []
end ++
case mod_muc_log:check_access_log(
StateData#state.server_host, From) of
allow ->