From 29607291ae9d9e53da552c5d6ad4ac68b6809b3b Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 26 May 2009 11:53:58 +0000 Subject: [PATCH] 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 --- src/ejabberd_captcha.erl | 28 +++++++++++++++++++++++++++- src/mod_muc/mod_muc_room.erl | 13 +++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/ejabberd_captcha.erl b/src/ejabberd_captcha.erl index c509dacef..71a711fee 100644 --- a/src/ejabberd_captcha.erl +++ b/src/ejabberd_captcha.erl @@ -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. diff --git a/src/mod_muc/mod_muc_room.erl b/src/mod_muc/mod_muc_room.erl index 8fc9617da..d110ad2d1 100644 --- a/src/mod_muc/mod_muc_room.erl +++ b/src/mod_muc/mod_muc_room.erl @@ -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 -> -- 2.40.0