From: Andrew Lewis Date: Thu, 1 Sep 2016 15:25:12 +0000 (+0200) Subject: [Feature] Add common way to disable Lua modules X-Git-Tag: 1.4.0~505^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F924%2Fhead;p=thirdparty%2Frspamd.git [Feature] Add common way to disable Lua modules --- diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua index 96a723fe0a..c46e7eeb40 100644 --- a/src/plugins/lua/antivirus.lua +++ b/src/plugins/lua/antivirus.lua @@ -273,6 +273,10 @@ end -- Registration local opts = rspamd_config:get_all_opt('antivirus') if opts and type(opts) == 'table' then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end redis_params = rspamd_parse_redis_server('antivirus') for k, m in pairs(opts) do if type(m) == 'table' and m['type'] then diff --git a/src/plugins/lua/asn.lua b/src/plugins/lua/asn.lua index 25b684dc47..5fab04d8f1 100644 --- a/src/plugins/lua/asn.lua +++ b/src/plugins/lua/asn.lua @@ -74,6 +74,10 @@ end local configure_asn_module = function() local opts = rspamd_config:get_all_opt('asn') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end for k,v in pairs(opts) do options[k] = v end diff --git a/src/plugins/lua/dcc.lua b/src/plugins/lua/dcc.lua index 216139fabd..ae6a3661a8 100644 --- a/src/plugins/lua/dcc.lua +++ b/src/plugins/lua/dcc.lua @@ -116,6 +116,10 @@ end -- Configuration if opts and opts['host'] then + if opts['enabled'] == false then + logger.info('Module is disabled') + return + end rspamd_config:register_symbol({ name = symbol_bulk, callback = check_dcc diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua index fc85c47662..8d04c4fbb9 100644 --- a/src/plugins/lua/dmarc.lua +++ b/src/plugins/lua/dmarc.lua @@ -328,6 +328,11 @@ if not opts or type(opts) ~= 'table' then return end +if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return +end + if opts['symbols'] then for k,_ in pairs(dmarc_symbols) do if opts['symbols'][k] then diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua index 9d9a54d03c..74358d1e21 100644 --- a/src/plugins/lua/emails.lua +++ b/src/plugins/lua/emails.lua @@ -81,6 +81,10 @@ end local opts = rspamd_config:get_all_opt('emails', 'rule') if opts and type(opts) == 'table' then + if opts['enabled'] == false then + logger.info('Module is disabled') + return + end local r = opts['rule'] if r then diff --git a/src/plugins/lua/fann_scores.lua b/src/plugins/lua/fann_scores.lua index c62923521a..cafa5befa7 100644 --- a/src/plugins/lua/fann_scores.lua +++ b/src/plugins/lua/fann_scores.lua @@ -38,6 +38,13 @@ local max_trains = 1000 local max_epoch = 100 local use_settings = false local opts = rspamd_config:get_all_opt("fann_scores") +if not (opts and type(opts) == 'table') then + rspamd_logger.infox('Module is unconfigured') + return +elseif opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return +end local function symbols_to_fann_vector(syms) local learn_data = {} diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua index 957491a56d..5b7d71fc43 100644 --- a/src/plugins/lua/forged_recipients.lua +++ b/src/plugins/lua/forged_recipients.lua @@ -72,6 +72,10 @@ end -- Configuration local opts = rspamd_config:get_all_opt('forged_recipients') if opts then + if opts['enabled'] == false then + logger.info('Module is disabled') + return + end if opts['symbol_rcpt'] or opts['symbol_sender'] then local id = rspamd_config:register_symbol({ callback = check_forged_headers, diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua index 05afaeab68..ddb2da6028 100644 --- a/src/plugins/lua/greylist.lua +++ b/src/plugins/lua/greylist.lua @@ -321,6 +321,10 @@ end local opts = rspamd_config:get_all_opt('greylist') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end if opts['whitelisted_ip'] then whitelisted_ip = rspamd_config:add_radix_map(opts['whitelisted_ip'], 'Greylist whitelist ip map') diff --git a/src/plugins/lua/hfilter.lua b/src/plugins/lua/hfilter.lua index 34a6796415..fad7156071 100644 --- a/src/plugins/lua/hfilter.lua +++ b/src/plugins/lua/hfilter.lua @@ -481,6 +481,10 @@ local symbols_from = { local opts = rspamd_config:get_all_opt('hfilter') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end for k,v in pairs(opts) do config[k] = v end diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua index 6b6ac900a6..12430241b9 100644 --- a/src/plugins/lua/ip_score.lua +++ b/src/plugins/lua/ip_score.lua @@ -317,6 +317,10 @@ end local configure_ip_score_module = function() local opts = rspamd_config:get_all_opt('ip_score') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end for k,v in pairs(opts) do options[k] = v end diff --git a/src/plugins/lua/maillist.lua b/src/plugins/lua/maillist.lua index 42cdc91769..96807cd3de 100644 --- a/src/plugins/lua/maillist.lua +++ b/src/plugins/lua/maillist.lua @@ -270,7 +270,12 @@ end -- Configuration -local opts = rspamd_config:get_all_opt('maillist')if opts then +local opts = rspamd_config:get_all_opt('maillist') +if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end if opts['symbol'] then symbol = opts['symbol'] rspamd_config:register_symbol({ diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index e1b2123f44..c6fb499dff 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -200,6 +200,10 @@ end local opts = rspamd_config:get_all_opt('mime_types') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end for k,v in pairs(opts) do settings[k] = v end diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index f21bc5b117..7cba9fd3a6 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -774,6 +774,10 @@ end -- Registration local opts = rspamd_config:get_all_opt('multimap') if opts and type(opts) == 'table' then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end redis_params = rspamd_parse_redis_server('multimap') for k,m in pairs(opts) do if type(m) == 'table' and m['type'] then diff --git a/src/plugins/lua/once_received.lua b/src/plugins/lua/once_received.lua index 63de22776b..3012205d6d 100644 --- a/src/plugins/lua/once_received.lua +++ b/src/plugins/lua/once_received.lua @@ -142,6 +142,10 @@ end -- Configuration local opts = rspamd_config:get_all_opt('once_received') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end if opts['symbol'] then local symbol = opts['symbol'] diff --git a/src/plugins/lua/phishing.lua b/src/plugins/lua/phishing.lua index ec9b9d2ad7..c4ccfca3ce 100644 --- a/src/plugins/lua/phishing.lua +++ b/src/plugins/lua/phishing.lua @@ -35,6 +35,13 @@ local phishtank_data = {} local rspamd_logger = require "rspamd_logger" local util = require "rspamd_util" local opts = rspamd_config:get_all_opt('phishing') +if not (opts and type(opts) == 'table') then + rspamd_logger.info('Module is unconfigured') + return +elseif opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return +end local function phishing_cb(task) local function check_phishing_map(map, url, symbol) diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index d8e53d4d00..0d3690cb3c 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -442,6 +442,10 @@ end local opts = rspamd_config:get_all_opt('ratelimit') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end local rates = opts['limit'] if rates and type(rates) == 'table' then fun.each(parse_limit, rates) diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index 13563f71bb..d782d1c259 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -385,7 +385,10 @@ end -- Configuration local opts = rspamd_config:get_all_opt('rbl') -if not opts or type(opts) ~= 'table' then +if not (opts and type(opts) == 'table') then + rspamd_logger.info('Module is unconfigured') +elseif opts['enabled'] == false then + rspamd_logger.info('Module is disabled') return end diff --git a/src/plugins/lua/replies.lua b/src/plugins/lua/replies.lua index 360f14ffe6..39eb3705b8 100644 --- a/src/plugins/lua/replies.lua +++ b/src/plugins/lua/replies.lua @@ -109,23 +109,30 @@ end local opts = rspamd_config:get_all_opt('replies') 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') - else - rspamd_config:register_symbol({ - name = 'REPLIES_SET', - type = 'postfilter', - callback = replies_set, - priority = 10 - }) - rspamd_config:register_symbol({ - name = 'REPLIES_CHECK', - type = 'prefilter', - callback = replies_check, - priority = 10 - }) - end + if not (opts and type(opts) == 'table') then + rspamd_logger.info('Module is unconfigured') + return + elseif opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end + redis_params = rspamd_parse_redis_server('replies') + if not redis_params then + rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') + else + rspamd_config:register_symbol({ + name = 'REPLIES_SET', + type = 'postfilter', + callback = replies_set, + priority = 10 + }) + rspamd_config:register_symbol({ + name = 'REPLIES_CHECK', + type = 'prefilter', + callback = replies_check, + priority = 10 + }) + end for k,v in pairs(opts) do settings[k] = v diff --git a/src/plugins/lua/rspamd_update.lua b/src/plugins/lua/rspamd_update.lua index 9af9372638..c4f1a7e987 100644 --- a/src/plugins/lua/rspamd_update.lua +++ b/src/plugins/lua/rspamd_update.lua @@ -125,6 +125,10 @@ end -- Configuration part local section = rspamd_config:get_all_opt("rspamd_update") if section then + if section['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end local trusted_key each(function(k, elt) if k == 'priority' then @@ -153,4 +157,6 @@ if section then end end end, maps) +else + rspamd_logger.infox('Module is unconfigured') end diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index 1b632f747b..e857d7f8ec 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -18,7 +18,14 @@ limitations under the License. -- Settings documentation can be found here: -- https://rspamd.com/doc/configuration/settings.html +local rspamd_logger = require "rspamd_logger" local set_section = rspamd_config:get_all_opt("settings") +if not (set_section and type(set_section) == 'table') then + rspamd_logger.infox('Module is unconfigured') +elseif set_section['enabled'] == false then + rspamd_logger.infox('Module is disabled') + return +end local settings = { [1] = {}, @@ -28,7 +35,6 @@ local settings = { local settings_ids = {} local settings_initialized = false local max_pri = 0 -local rspamd_logger = require "rspamd_logger" local rspamd_ip = require "rspamd_ip" local rspamd_regexp = require "rspamd_regexp" local ucl = require "ucl" diff --git a/src/plugins/lua/spamassassin.lua b/src/plugins/lua/spamassassin.lua index cf17aa2476..533b83864f 100644 --- a/src/plugins/lua/spamassassin.lua +++ b/src/plugins/lua/spamassassin.lua @@ -114,6 +114,12 @@ local sa_lists = { local func_cache = {} local section = rspamd_config:get_all_opt("spamassassin") +if not (section and type(section) == 'table') then + rspamd_logger.info('Module is unconfigured') +elseif section['enabled'] == false then + rspamd_logger.info('Module is disabled') + return +end -- Minimum score to treat symbols as meta local meta_score_alpha = 0.5 diff --git a/src/plugins/lua/trie.lua b/src/plugins/lua/trie.lua index da8bba5602..ca5cbea54c 100644 --- a/src/plugins/lua/trie.lua +++ b/src/plugins/lua/trie.lua @@ -130,6 +130,10 @@ end local opts = rspamd_config:get_all_opt("trie") if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end for sym, opt in pairs(opts) do process_trie_conf(sym, opt) end @@ -168,4 +172,6 @@ if opts then }) end end +else + rspamd_logger.info("Module is disabled") end diff --git a/src/plugins/lua/whitelist.lua b/src/plugins/lua/whitelist.lua index 946e47adfd..b0b00114ec 100644 --- a/src/plugins/lua/whitelist.lua +++ b/src/plugins/lua/whitelist.lua @@ -185,9 +185,16 @@ end local configure_whitelist_module = function() local opts = rspamd_config:get_all_opt('whitelist') if opts then + if opts['enabled'] == false then + rspamd_logger.info('Module is disabled') + return + end for k,v in pairs(opts) do options[k] = v end + else + rspamd_logger.info('Module is unconfigured') + return end if options['rules'] then