From cb0a14c89a048dda42ef9350d40e782d68b436fb Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Thu, 25 Apr 2019 11:08:32 +0200 Subject: [PATCH] mod_spam_filter: Check whether module is loaded If the API commands are called with 'global' instead of a host name, only run the command for those virtual hosts that actually have the module loaded. --- mod_spam_filter/src/mod_spam_filter.erl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mod_spam_filter/src/mod_spam_filter.erl b/mod_spam_filter/src/mod_spam_filter.erl index 06acd59..8bcda0f 100644 --- a/mod_spam_filter/src/mod_spam_filter.erl +++ b/mod_spam_filter/src/mod_spam_filter.erl @@ -330,7 +330,7 @@ reopen_log() -> lists:foreach(fun(Host) -> Proc = get_proc_name(Host), gen_server:cast(Proc, reopen_log) - end, ejabberd_config:get_myhosts()). + end, get_spam_filter_hosts()). %%-------------------------------------------------------------------- %% Internal functions. @@ -600,6 +600,10 @@ maybe_dump_spam(#message{to = #jid{lserver = LServer}} = Msg) -> get_proc_name(Host) -> gen_mod:get_module_proc(Host, ?MODULE). +-spec get_spam_filter_hosts() -> [binary()]. +get_spam_filter_hosts() -> + [H || H <- ejabberd_config:get_myhosts(), gen_mod:is_loaded(H, ?MODULE)]. + -spec expand_host(binary() | none, binary()) -> binary() | none. expand_host(none, _Host) -> none; @@ -706,7 +710,7 @@ get_commands_spec() -> reload_spam_filter_files(<<"global">>) -> try lists:foreach(fun(Host) -> ok = reload_spam_filter_files(Host) - end, ejabberd_config:get_myhosts()) + end, get_spam_filter_hosts()) catch error:{badmatch, {error, _Reason} = Error} -> Error end; @@ -748,7 +752,7 @@ get_spam_filter_cache(Host) -> expire_spam_filter_cache(<<"global">>, Age) -> try lists:foreach(fun(Host) -> {ok, _} = expire_spam_filter_cache(Host, Age) - end, ejabberd_config:get_myhosts()) of + end, get_spam_filter_hosts()) of ok -> {ok, "Expired cache entries"} catch error:{badmatch, {error, _Reason} = Error} -> @@ -770,7 +774,7 @@ expire_spam_filter_cache(Host, Age) -> drop_from_spam_filter_cache(<<"global">>, JID) -> try lists:foreach(fun(Host) -> {ok, _} = drop_from_spam_filter_cache(Host, JID) - end, ejabberd_config:get_myhosts()) of + end, get_spam_filter_hosts()) of ok -> {ok, "Dropped " ++ binary_to_list(JID) ++ " from caches"} catch error:{badmatch, {error, _Reason} = Error} ->