]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add common way to disable Lua modules 924/head
authorAndrew Lewis <nerf@judo.za.org>
Thu, 1 Sep 2016 15:25:12 +0000 (17:25 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 1 Sep 2016 15:25:12 +0000 (17:25 +0200)
23 files changed:
src/plugins/lua/antivirus.lua
src/plugins/lua/asn.lua
src/plugins/lua/dcc.lua
src/plugins/lua/dmarc.lua
src/plugins/lua/emails.lua
src/plugins/lua/fann_scores.lua
src/plugins/lua/forged_recipients.lua
src/plugins/lua/greylist.lua
src/plugins/lua/hfilter.lua
src/plugins/lua/ip_score.lua
src/plugins/lua/maillist.lua
src/plugins/lua/mime_types.lua
src/plugins/lua/multimap.lua
src/plugins/lua/once_received.lua
src/plugins/lua/phishing.lua
src/plugins/lua/ratelimit.lua
src/plugins/lua/rbl.lua
src/plugins/lua/replies.lua
src/plugins/lua/rspamd_update.lua
src/plugins/lua/settings.lua
src/plugins/lua/spamassassin.lua
src/plugins/lua/trie.lua
src/plugins/lua/whitelist.lua

index 96a723fe0a18d0881be1e42bc72bc52ed9c83fe1..c46e7eeb40bc39fb6ae84d1637c8bcbf115f0098 100644 (file)
@@ -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
index 25b684dc47ebd34c9e1aa878549b32c260c135be..5fab04d8f10ee278fb1115b7a170eea8251c8404 100644 (file)
@@ -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
index 216139fabd238d585d1d00a64b395e1b19a19b10..ae6a3661a8193c72e1e1e98669ea314b7f5dfba3 100644 (file)
@@ -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
index fc85c47662e2dbf0ecbd91254cb9cf63447c6eab..8d04c4fbb978ac991e12ea33ffefbdacc9ce8fee 100644 (file)
@@ -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
index 9d9a54d03c2bda3437a28b170705ade2fce99e09..74358d1e21aeed8743f82ff328dc959cdfba919e 100644 (file)
@@ -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
index c62923521a5e263c10f3cd06537b13cea5567760..cafa5befa73a20a9e7ce181ecf97587fb74f6970 100644 (file)
@@ -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 = {}
index 957491a56df4f898a28b738ec07d0b27f28aea6c..5b7d71fc432fa01f5da001c5a24ceb4f75fda475 100644 (file)
@@ -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,
index 05afaeab6875d4245ed6cd15c4b2896de82d233f..ddb2da60285be79e0422288877a7168c212d7cb7 100644 (file)
@@ -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')
index 34a679641581a42d9a1dceee8cd04758548f61d9..fad71560715e238c9fc2b78cbdecf664ca24e136 100644 (file)
@@ -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
index 6b6ac900a6141f57fd028bde9eb94284e85c22f9..12430241b971669e9b08821b1c56f3d78924fc13 100644 (file)
@@ -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
index 42cdc917698d17e9ae81a597850fd971ecf6fe82..96807cd3de459ce6a3b7ca4e33af408b12406d4b 100644 (file)
@@ -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({
index e1b2123f44aea9d91995bf49235df9bb0917af04..c6fb499dffbe95b11ff798f45ea283ec18be7983 100644 (file)
@@ -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
index f21bc5b117ca40ff35e6e27e184d8a98af380fd7..7cba9fd3a63e78a10d6b9ad7aaafa10eed3f38b3 100644 (file)
@@ -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
index 63de22776be059cfe0b64165ca895ff83729daba..3012205d6dcded0137dc82a5facaad683ee9e732 100644 (file)
@@ -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']
 
index ec9b9d2ad7dee9f5af4bcf3ea246112c4b809460..c4ccfca3ce855fb71454ca61ce017a989768fa06 100644 (file)
@@ -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)
index d8e53d4d00ed54c054e3104bb666ee15ab20d2b8..0d3690cb3c95b13e7f05e943ed1015463e60eb52 100644 (file)
@@ -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)
index 13563f71bbde5a28b48fc33c8cec6c72b45fac8c..d782d1c25949668ad8d9740ae6a136a5d5259070 100644 (file)
@@ -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
 
index 360f14ffe640f4d0f9d36b6bb4d8dfc1434ce82f..39eb3705b86d84065ce43db810c31b4114962fd6 100644 (file)
@@ -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
index 9af937263863edb4c524085eea6e814aa25ca8ce..c4f1a7e987e2e661a120a5ac0cf168bc884e2fda 100644 (file)
@@ -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
index 1b632f747b701b3181e438eb03d114f2eddfe51a..e857d7f8ec3db2933779b865963cd2640377131b 100644 (file)
@@ -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"
index cf17aa2476d1e02bc10437ca228dcc6b684dbe24..533b83864fdce64cd25d1eb7de90c241a5b4b4f7 100644 (file)
@@ -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
index da8bba560214c05b4dc28df6584a936e6faace31..ca5cbea54c0bf65039fd472a04ebd31ca69988b2 100644 (file)
@@ -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
index 946e47adfda38b23165604e1606deebd095acdb2..b0b00114ece0a9b234be76a977303f4fd52f3e9a 100644 (file)
@@ -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