]> granicus.if.org Git - ejabberd/commitdiff
Added support for captcha feature disability (EJAB-895)
authorBadlop <badlop@process-one.net>
Tue, 26 May 2009 11:53:58 +0000 (11:53 +0000)
committerBadlop <badlop@process-one.net>
Tue, 26 May 2009 11:53:58 +0000 (11:53 +0000)
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
src/mod_muc/mod_muc_room.erl

index c509dacefffa77e1029b11cbcb3d8a413ef86288..71a711feead799128a6178f9d0284a687f2674db 100644 (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.
index 8fc9617daca3fbda0589474dac9743698fbf3b51..d110ad2d11a4a09800407c5c64a60437b44899b1 100644 (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 ->