diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-03 13:36:32 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-12-03 16:55:30 +0000 |
commit | f5e2a84b6981cc12f06c908f9af277d13e64e7e8 (patch) | |
tree | b86cc3a6ee0803e86d825240986d2b2efa553758 /src/plugins | |
parent | 12d38f08dd70e39bc0848390d6ec4f1f003ec335 (diff) | |
download | rspamd-f5e2a84b6981cc12f06c908f9af277d13e64e7e8.tar.gz rspamd-f5e2a84b6981cc12f06c908f9af277d13e64e7e8.zip |
[Feature] Store plugins state
Diffstat (limited to 'src/plugins')
31 files changed, 101 insertions, 3 deletions
diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua index baa876d4e..6120cb41f 100644 --- a/src/plugins/lua/antivirus.lua +++ b/src/plugins/lua/antivirus.lua @@ -19,6 +19,7 @@ local rspamd_util = require "rspamd_util" local rspamd_regexp = require "rspamd_regexp" local tcp = require "rspamd_tcp" local upstream_list = require "rspamd_upstream_list" +local lua_util = require "lua_util" local redis_params local N = "antivirus" @@ -802,6 +803,7 @@ end local opts = rspamd_config:get_all_opt('antivirus') if opts and type(opts) == 'table' then redis_params = rspamd_parse_redis_server('antivirus') + local has_valid = false for k, m in pairs(opts) do if type(m) == 'table' and m['type'] and m['servers'] then local cb = add_antivirus_rule(k, m) @@ -813,6 +815,7 @@ if opts and type(opts) == 'table' then name = m['symbol'], callback = cb, }) + has_valid = true if type(m['patterns']) == 'table' then if m['patterns'][1] then for _, p in ipairs(m['patterns']) do @@ -856,4 +859,9 @@ if opts and type(opts) == 'table' then end end end + + if not has_valid then + lua_util.disable_module(N, 'config') + end end + diff --git a/src/plugins/lua/arc.lua b/src/plugins/lua/arc.lua index fc101b0f7..46e361f2d 100644 --- a/src/plugins/lua/arc.lua +++ b/src/plugins/lua/arc.lua @@ -555,6 +555,7 @@ end if not (settings.use_redis or settings.path or settings.domain or settings.path_map or settings.selector_map) then rspamd_logger.infox(rspamd_config, 'mandatory parameters missing, disable arc signing') + lua_util.disable_module(N, "fail") return end @@ -562,7 +563,8 @@ if settings.use_redis then redis_params = rspamd_parse_redis_server('arc') if not redis_params then - rspamd_logger.errx(rspamd_config, 'no servers are specified, but module is configured to load keys from redis, disable dkim signing') + rspamd_logger.errx(rspamd_config, 'no servers are specified, but module is configured to load keys from redis, disable arc signing') + lua_util.disable_module(N, "config") return end end diff --git a/src/plugins/lua/asn.lua b/src/plugins/lua/asn.lua index 0d103fc10..a125b99c1 100644 --- a/src/plugins/lua/asn.lua +++ b/src/plugins/lua/asn.lua @@ -17,6 +17,8 @@ limitations under the License. local rspamd_logger = require "rspamd_logger" local rspamd_regexp = require "rspamd_regexp" +local lua_util = require "lua_util" +local N = "asn" if confighelp then return @@ -114,4 +116,6 @@ if configure_asn_module() then type = 'virtual' }) end +else + lua_util.disable_module(N, 'config') end diff --git a/src/plugins/lua/bayes_expiry.lua b/src/plugins/lua/bayes_expiry.lua index 674727e42..d922f3f55 100644 --- a/src/plugins/lua/bayes_expiry.lua +++ b/src/plugins/lua/bayes_expiry.lua @@ -91,7 +91,10 @@ local function configure_bayes_expiry() return true end -if not configure_bayes_expiry() then return end +if not configure_bayes_expiry() then + lutil.disable_module(N, 'config') + return +end local function get_redis_params(ev_base, symbol) local redis_params diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua index cfa066728..84a479b46 100644 --- a/src/plugins/lua/clickhouse.lua +++ b/src/plugins/lua/clickhouse.lua @@ -18,6 +18,7 @@ local rspamd_logger = require 'rspamd_logger' local rspamd_http = require "rspamd_http" local rspamd_lua_utils = require "lua_util" local upstream_list = require "rspamd_upstream_list" +local N = "clickhouse" if confighelp then return @@ -653,6 +654,7 @@ if opts then if not settings['server'] and not settings['servers'] then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') + rspamd_lua_utils.disable_module(N, "config") else settings['from_map'] = rspamd_map_add('clickhouse', 'from_tables', 'regexp', 'clickhouse specific domains') @@ -666,6 +668,7 @@ if opts then if not settings.upstream then rspamd_logger.errx('cannot parse clickhouse address: %s', settings['server'] or settings['servers']) + rspamd_lua_utils.disable_module(N, "config") return end diff --git a/src/plugins/lua/dcc.lua b/src/plugins/lua/dcc.lua index 503dcce7c..131c83d36 100644 --- a/src/plugins/lua/dcc.lua +++ b/src/plugins/lua/dcc.lua @@ -23,6 +23,7 @@ local opts = rspamd_config:get_all_opt(N) local logger = require "rspamd_logger" local tcp = require "rspamd_tcp" local fun = require "fun" +local lua_util = require "lua_util" if confighelp then rspamd_config:add_example(nil, 'dcc', @@ -139,5 +140,6 @@ if opts and opts['host'] then name = symbol_bulk }) else + lua_util.disable_module(N, "config") logger.infox('DCC module not configured'); end diff --git a/src/plugins/lua/dkim_signing.lua b/src/plugins/lua/dkim_signing.lua index 341cddc94..75720df9d 100644 --- a/src/plugins/lua/dkim_signing.lua +++ b/src/plugins/lua/dkim_signing.lua @@ -142,6 +142,7 @@ for k,v in pairs(opts) do end if not (settings.use_redis or settings.path or settings.domain or settings.path_map or settings.selector_map) then rspamd_logger.infox(rspamd_config, 'mandatory parameters missing, disable dkim signing') + lutil.disable_module(N, "config") return end if settings.use_redis then @@ -149,6 +150,7 @@ if settings.use_redis then if not redis_params then rspamd_logger.errx(rspamd_config, 'no servers are specified, but module is configured to load keys from redis, disable dkim signing') + lutil.disable_module(N, "redis") return end end diff --git a/src/plugins/lua/dynamic_conf.lua b/src/plugins/lua/dynamic_conf.lua index 9c017d6c9..0ddad354c 100644 --- a/src/plugins/lua/dynamic_conf.lua +++ b/src/plugins/lua/dynamic_conf.lua @@ -18,6 +18,8 @@ local rspamd_logger = require "rspamd_logger" local redis_params local ucl = require "ucl" local fun = require "fun" +local lua_util = require "lua_util" +local N = "dynamic_conf" if confighelp then return @@ -359,4 +361,5 @@ if redis_params then add_symbol = add_dynamic_symbol, add_action = add_dynamic_action, } + lua_util.disable_module(N, "redis") end diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua index aeb2bc7cd..65e6b433e 100644 --- a/src/plugins/lua/emails.lua +++ b/src/plugins/lua/emails.lua @@ -201,4 +201,6 @@ if #rules > 0 then callback = cb, }) end +else + rspamd_lua_utils.disable_module(N, "conf") end diff --git a/src/plugins/lua/fann_redis.lua b/src/plugins/lua/fann_redis.lua index 3a435c321..2b9b06f28 100644 --- a/src/plugins/lua/fann_redis.lua +++ b/src/plugins/lua/fann_redis.lua @@ -25,11 +25,13 @@ local rspamd_logger = require "rspamd_logger" local rspamd_fann = require "rspamd_fann" local rspamd_util = require "rspamd_util" local rspamd_redis = require "lua_redis" +local lua_util = require "lua_util" local fun = require "fun" local meta_functions = require "meta_functions" local use_torch = false local torch local nn +local N = "fann_redis" if rspamd_config:has_torch() then use_torch = true @@ -1078,12 +1080,14 @@ redis_params = rspamd_parse_redis_server('fann_redis') -- Initialization part if not (opts and type(opts) == 'table') or not redis_params then rspamd_logger.infox(rspamd_config, 'Module is unconfigured') + lua_util.disable_module(N, "redis") return end if not rspamd_fann.is_enabled() then rspamd_logger.errx(rspamd_config, 'fann is not compiled in rspamd, this ' .. 'module is eventually disabled') + lua_util.disable_module(N, "fail") return else local rules = opts['rules'] diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua index 11ab2a2de..9e42f4482 100644 --- a/src/plugins/lua/greylist.lua +++ b/src/plugins/lua/greylist.lua @@ -63,6 +63,7 @@ local rspamd_util = require "rspamd_util" local fun = require "fun" local hash = require "rspamd_cryptobox_hash" local rspamd_lua_utils = require "lua_util" +local N = "greylist" local function data_key(task) local cached = task:get_mempool():get_variable("grey_bodyhash") @@ -426,6 +427,7 @@ if opts then redis_params = rspamd_parse_redis_server('greylist') if not redis_params then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') + rspamd_lua_utils.disable_module(N, "redis") else rspamd_config:register_symbol({ name = 'GREYLIST_SAVE', diff --git a/src/plugins/lua/hfilter.lua b/src/plugins/lua/hfilter.lua index 6f3322ecf..0b8235719 100644 --- a/src/plugins/lua/hfilter.lua +++ b/src/plugins/lua/hfilter.lua @@ -25,6 +25,7 @@ end local rspamd_logger = require "rspamd_logger" local rspamd_regexp = require "rspamd_regexp" +local lua_util = require "lua_util" local rspamc_local_helo = "rspamc.local" local checks_hellohost = [[ /[0-9][.-]?nat/i 5 @@ -623,4 +624,6 @@ end --dumper(symbols_enabled) if #symbols_enabled > 0 then rspamd_config:register_symbols(hfilter, 1.0, "HFILTER", symbols_enabled); +else + lua_util.disable_module(N, "config") end diff --git a/src/plugins/lua/history_redis.lua b/src/plugins/lua/history_redis.lua index 13d6aafe5..a876b46e7 100644 --- a/src/plugins/lua/history_redis.lua +++ b/src/plugins/lua/history_redis.lua @@ -28,9 +28,11 @@ local settings = { local rspamd_logger = require "rspamd_logger" local rspamd_util = require "rspamd_util" +local lua_util = require "lua_util" local fun = require "fun" local ucl = require("ucl") local E = {} +local N = "history_redis" local hostname = rspamd_util.get_hostname() local function process_addr(addr) @@ -216,6 +218,7 @@ if opts then redis_params = rspamd_parse_redis_server('history_redis') if not redis_params then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') + lua_util.disable_module(N, "redis") else rspamd_config:register_symbol({ name = 'HISTORY_SAVE', diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua index e2bd58da5..bd64ba48f 100644 --- a/src/plugins/lua/ip_score.lua +++ b/src/plugins/lua/ip_score.lua @@ -30,6 +30,7 @@ local asn_cc_whitelist = nil local check_authed = false local check_local = false local M = "ip_score" +local N = M local options = { actions = { -- how each action is treated in scoring @@ -388,4 +389,6 @@ if redis_params then name = options['symbol'], callback = ip_score_check, }) +else + rspamd_lua_utils.disable_module(N, "redis") end diff --git a/src/plugins/lua/metadata_exporter.lua b/src/plugins/lua/metadata_exporter.lua index 90ec8a4fd..7d2d53148 100644 --- a/src/plugins/lua/metadata_exporter.lua +++ b/src/plugins/lua/metadata_exporter.lua @@ -688,6 +688,7 @@ end if not next(settings.rules) then rspamd_logger.errx(rspamd_config, 'No rules enabled') + lutil.disable_module(N, "config") end for k, r in pairs(settings.rules) do rspamd_config:register_symbol({ diff --git a/src/plugins/lua/metric_exporter.lua b/src/plugins/lua/metric_exporter.lua index d104c4b9b..efb50d586 100644 --- a/src/plugins/lua/metric_exporter.lua +++ b/src/plugins/lua/metric_exporter.lua @@ -24,6 +24,7 @@ local logger = require "rspamd_logger" local mempool = require "rspamd_mempool" local util = require "rspamd_util" local tcp = require "rspamd_tcp" +local lua_util = require "lua_util" local pool = mempool.create() local settings = { @@ -166,7 +167,10 @@ local function configure_metric_exporter() return backends[be]['configure']() end -if not configure_metric_exporter() then return end +if not configure_metric_exporter() then + lua_util.disable_module(N, "config") + return +end rspamd_config:add_on_load(function (_, ev_base, worker) -- Exit unless we're the first 'controller' worker diff --git a/src/plugins/lua/mid.lua b/src/plugins/lua/mid.lua index 19c85dac0..e1dd9ed5d 100644 --- a/src/plugins/lua/mid.lua +++ b/src/plugins/lua/mid.lua @@ -25,6 +25,8 @@ end local rspamd_logger = require "rspamd_logger" local rspamd_regexp = require "rspamd_regexp" +local lua_util = require "lua_util" +local N = "mid" local settings = { url = '', @@ -97,5 +99,6 @@ if opts then rspamd_config:register_dependency(id, settings['symbol_dkim_allow']) else rspamd_logger.infox(rspamd_config, 'source is not specified, disabling module') + lua_util.disable_module(N, "config") end end diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index 4fa43f09f..a93b5889c 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -20,6 +20,8 @@ end -- This plugin implements mime types checks for mail messages local logger = require "rspamd_logger" +local lua_util = require "lua_util" +local N = "mime_types" local settings = { file = '', symbol_unknown = 'MIME_UNKNOWN', @@ -313,5 +315,7 @@ if opts then name = settings['symbol_bad_extension'], parent = id }) + else + lua_util.disable_module(N, "config") end end diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index 407a943bc..584978453 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -27,6 +27,7 @@ local util = require "rspamd_util" local regexp = require "rspamd_regexp" local rspamd_expression = require "rspamd_expression" local rspamd_ip = require "rspamd_ip" +local lua_util = require "lua_util" local redis_params local fun = require "fun" local N = 'multimap' @@ -1104,4 +1105,8 @@ if opts and type(opts) == 'table' then }) end, fun.filter(function(r) return r['prefilter'] end, rules)) + + if #rules == 0 then + lua_util.disable_module(N, "config") + end end diff --git a/src/plugins/lua/mx_check.lua b/src/plugins/lua/mx_check.lua index 3e43b4a9a..b30f1293b 100644 --- a/src/plugins/lua/mx_check.lua +++ b/src/plugins/lua/mx_check.lua @@ -22,6 +22,8 @@ end local rspamd_logger = require "rspamd_logger" local rspamd_tcp = require "rspamd_tcp" local rspamd_util = require "rspamd_util" +local lua_util = require "lua_util" +local N = "mx_check" local fun = require "fun" local settings = { @@ -268,6 +270,7 @@ if opts then redis_params = rspamd_parse_redis_server('mx_check') if not redis_params then rspamd_logger.errx(rspamd_config, 'no redis servers are specified, disabling module') + lua_util.disable_module(N, "redis") return end for k,v in pairs(opts) do diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index 33c38c4db..f77e2ae76 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -729,6 +729,7 @@ if opts then redis_params = rspamd_parse_redis_server('ratelimit') if not redis_params then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') + lua_util.disable_module(N, "redis") else local s = { type = 'prefilter,nostat', diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index 55f2bffea..59d1de2d5 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -33,6 +33,7 @@ local hash = require 'rspamd_cryptobox_hash' local rspamd_logger = require 'rspamd_logger' local rspamd_util = require 'rspamd_util' local fun = require 'fun' +local lua_util = require 'lua_util' local default_monitored = '1.0.0.127' local symbols = { @@ -417,6 +418,7 @@ end local opts = rspamd_config:get_all_opt(N) if not (opts and type(opts) == 'table') then rspamd_logger.infox(rspamd_config, 'Module is unconfigured') + lua_util.disable_module(N, "config") return end @@ -564,6 +566,11 @@ for key,rbl in pairs(opts['rbls']) do end end)() end + +if #opts.rbls == 0 then + lua_util.disable_module(N, "config") +end + for _, w in pairs(white_symbols) do for _, b in pairs(black_symbols) do local csymbol = 'RBL_COMPOSITE_' .. w .. '_' .. b diff --git a/src/plugins/lua/replies.lua b/src/plugins/lua/replies.lua index 99d13db7b..5c17efa59 100644 --- a/src/plugins/lua/replies.lua +++ b/src/plugins/lua/replies.lua @@ -34,6 +34,8 @@ local settings = { local rspamd_logger = require 'rspamd_logger' local hash = require 'rspamd_cryptobox_hash' +local lua_util = require 'lua_util' +local N = "replies" local function make_key(goop) local h = hash.create() @@ -125,6 +127,7 @@ if opts then redis_params = rspamd_parse_redis_server('replies') if not redis_params then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') + lua_util.disable_module(N, "redis") else rspamd_config:register_symbol({ name = 'REPLIES_SET', diff --git a/src/plugins/lua/reputation.lua b/src/plugins/lua/reputation.lua index 8ff53f09b..e7349e445 100644 --- a/src/plugins/lua/reputation.lua +++ b/src/plugins/lua/reputation.lua @@ -945,4 +945,6 @@ if opts['rules'] then parse_rule(k, v) end end +else + lua_util.disable_module(N, "config") end diff --git a/src/plugins/lua/rspamd_update.lua b/src/plugins/lua/rspamd_update.lua index fa768a0e7..4eadc027a 100644 --- a/src/plugins/lua/rspamd_update.lua +++ b/src/plugins/lua/rspamd_update.lua @@ -25,6 +25,8 @@ local fun = require "fun" local rspamd_logger = require "rspamd_logger" local rspamd_config = rspamd_config local hash = require "rspamd_cryptobox_hash" +local lua_util = require "lua_util" +local N = "rspamd_update" local rspamd_version = rspamd_version local maps = {} @@ -149,4 +151,5 @@ if section then end, maps) else rspamd_logger.infox(rspamd_config, 'Module is unconfigured') + lua_util.disable_module(N, "config") end diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index ab97accb7..649abc51f 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -29,6 +29,7 @@ local rspamd_regexp = require "rspamd_regexp" local rspamd_expression = require "rspamd_expression" local rspamd_trie = require "rspamd_trie" local util = require "rspamd_util" +local lua_util = require "lua_util" local fun = require "fun" -- Known plugins @@ -1647,4 +1648,6 @@ end if has_rules then post_process() +else + lua_util.disable_module(N, "config") end diff --git a/src/plugins/lua/trie.lua b/src/plugins/lua/trie.lua index 2794e80c8..796cd789a 100644 --- a/src/plugins/lua/trie.lua +++ b/src/plugins/lua/trie.lua @@ -24,6 +24,7 @@ local N = 'trie' local rspamd_logger = require "rspamd_logger" local rspamd_trie = require "rspamd_trie" local fun = require "fun" +local lua_util = require "lua_util" local mime_trie local raw_trie @@ -176,4 +177,5 @@ if opts then end else rspamd_logger.infox(rspamd_config, "Module is unconfigured") + lua_util.disable_module(N, "config") end diff --git a/src/plugins/lua/url_redirector.lua b/src/plugins/lua/url_redirector.lua index aefaf2d75..d0984bd15 100644 --- a/src/plugins/lua/url_redirector.lua +++ b/src/plugins/lua/url_redirector.lua @@ -49,6 +49,7 @@ local settings = { local rspamd_logger = require "rspamd_logger" local rspamd_http = require "rspamd_http" local hash = require "rspamd_cryptobox_hash" +local lua_util = require "lua_util" local function cache_url(task, orig_url, url, key, param) local function redis_trim_cb(err, data) @@ -271,11 +272,13 @@ if opts then redis_params = rspamd_parse_redis_server('url_redirector') if not redis_params then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') + lua_util.disable_module(N, "redis") else if rspamd_plugins.surbl then rspamd_plugins.surbl.register_redirect(url_redirector_handler) else rspamd_logger.infox(rspamd_config, 'surbl module is not enabled, disabling module') + lua_util.disable_module(N, "fail") end end end diff --git a/src/plugins/lua/url_reputation.lua b/src/plugins/lua/url_reputation.lua index 5c5dee14e..9dbb40320 100644 --- a/src/plugins/lua/url_reputation.lua +++ b/src/plugins/lua/url_reputation.lua @@ -63,6 +63,7 @@ local scale = { local rspamd_logger = require "rspamd_logger" local rspamd_util = require "rspamd_util" +local lua_util = require "lua_util" -- This function is used for taskless redis requests (to load scripts) local function redis_make_request(ev_base, cfg, key, is_write, callback, command, args) @@ -407,6 +408,7 @@ if not opts then return end redis_params = rspamd_parse_redis_server(N) if not redis_params then rspamd_logger.warnx(rspamd_config, 'no servers are specified, disabling module') + lua_util.disable_module(N, "redis") return end for k, v in pairs(opts) do @@ -427,6 +429,7 @@ for k, v in pairs(opts) do end if settings.threshold < 1 then rspamd_logger.errx(rspamd_config, 'threshold should be >= 1, disabling module') + lua_util.disable_module(N, "config") return end diff --git a/src/plugins/lua/url_tags.lua b/src/plugins/lua/url_tags.lua index 9aa64e1f4..1281cc2fc 100644 --- a/src/plugins/lua/url_tags.lua +++ b/src/plugins/lua/url_tags.lua @@ -35,6 +35,7 @@ local settings = { local rspamd_logger = require "rspamd_logger" local rspamd_util = require "rspamd_util" +local lua_util = require "lua_util" local ucl = require "ucl" -- This function is used for taskless redis requests (to load scripts) @@ -350,6 +351,7 @@ local opts = rspamd_config:get_all_opt(N) if not opts then return end redis_params = rspamd_parse_redis_server(N) if not redis_params then + lua_util.disable_module(N, "redis") rspamd_logger.warnx(rspamd_config, 'no servers are specified, disabling module') return end diff --git a/src/plugins/lua/whitelist.lua b/src/plugins/lua/whitelist.lua index c7d5a498f..815554766 100644 --- a/src/plugins/lua/whitelist.lua +++ b/src/plugins/lua/whitelist.lua @@ -21,6 +21,9 @@ end local rspamd_logger = require "rspamd_logger" local rspamd_util = require "rspamd_util" local fun = require "fun" +local lua_util = require "lua_util" + +local N = "whitelist" local options = { dmarc_allow_symbol = 'DMARC_POLICY_ALLOW', @@ -287,6 +290,8 @@ local configure_whitelist_module = function() end end end, options['rules']) + else + lua_util.disable_module(N, "config") end end |