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").
[{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) ->
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.
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} ->
?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),
"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 ->