summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2009-05-26 11:53:58 +0000
committerBadlop <badlop@process-one.net>2009-05-26 11:53:58 +0000
commit29607291ae9d9e53da552c5d6ad4ac68b6809b3b (patch)
tree53266a9b79664bb9671a0567aadb20cb48d08a3f
parentAdd label in captcha form. Improve translatable strings in captcha and muc room. (diff)
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
-rw-r--r--src/ejabberd_captcha.erl28
-rw-r--r--src/mod_muc/mod_muc_room.erl13
2 files changed, 36 insertions, 5 deletions
diff --git a/src/ejabberd_captcha.erl b/src/ejabberd_captcha.erl
index c509dace..71a711fe 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 8fc9617d..d110ad2d 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 ->