]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Use standard utility to get check_local/authed
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 4 Sep 2020 15:33:12 +0000 (16:33 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 4 Sep 2020 15:33:12 +0000 (16:33 +0100)
src/plugins/lua/asn.lua
src/plugins/lua/greylist.lua
src/plugins/lua/hfilter.lua
src/plugins/lua/once_received.lua
src/plugins/lua/spamtrap.lua
src/plugins/lua/whitelist.lua

index 4c7d73dbacbdbb77d1a1ab8bde941ce8dd6769bc..f641ac53cab2fb49ed29412ba2dc240119774563 100644 (file)
@@ -110,6 +110,12 @@ local configure_asn_module = function()
       options[k] = v
     end
   end
+
+  local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+      false, true)
+  options.check_local = auth_and_local_conf[1]
+  options.check_authed = auth_and_local_conf[2]
+
   if options['provider_type'] == 'rspamd' then
     if not options['provider_info'] and options['provider_info']['ip4'] and
         options['provider_info']['ip6'] then
index 152788175195cdcc058f0fa381f620cca885aa55..807859bff031b38f16042eef1ce87b1e3b164cc4 100644 (file)
@@ -83,6 +83,7 @@ local settings = {
 local rspamd_logger = require "rspamd_logger"
 local rspamd_util = require "rspamd_util"
 local lua_redis = require "lua_redis"
+local lua_util = require "lua_util"
 local fun = require "fun"
 local hash = require "rspamd_cryptobox_hash"
 local rspamd_lua_utils = require "lua_util"
@@ -464,6 +465,11 @@ if opts then
     end
   end
 
+  local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+      false, false)
+  settings.check_local = auth_and_local_conf[1]
+  settings.check_authed = auth_and_local_conf[2]
+
   if settings['greylist_min_score'] then
     settings['greylist_min_score'] = tonumber(settings['greylist_min_score'])
   else
index 962b302ba21dbc1e1d45c3bea6684df60fcdee35..9179f63b80425896f08c5a9811bbe5b8d8d9c0e4 100644 (file)
@@ -568,24 +568,10 @@ local symbols_from = {
   "HFILTER_FROM_BOUNCE"
 }
 
-local function try_opts(where)
-  local ret = false
-  local opts = rspamd_config:get_all_opt(where)
-  if type(opts) == 'table' then
-    if type(opts['check_local']) == 'boolean' then
-      check_local = opts['check_local']
-      ret = true
-    end
-    if type(opts['check_authed']) == 'boolean' then
-      check_authed = opts['check_authed']
-      ret = true
-    end
-  end
-
-  return ret
-end
-
-if not try_opts(N) then try_opts('options') end
+local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+    false, false)
+check_local = auth_and_local_conf[1]
+check_authed = auth_and_local_conf[2]
 
 local opts = rspamd_config:get_all_opt('hfilter')
 if opts then
index 4f1e67c72ea0343c6e3d53732690abe465336a77..11e880cc5d8d7f102eeccea426b4d51ccb367fac 100644 (file)
@@ -31,6 +31,7 @@ local good_hosts = {}
 local whitelist = nil
 
 local rspamd_logger = require "rspamd_logger"
+local lua_util = require "lua_util"
 local fun = require "fun"
 local N = 'once_received'
 
@@ -156,24 +157,10 @@ local function check_quantity_received (task)
   end
 end
 
-local function try_opts(where)
-  local ret = false
-  local opts = rspamd_config:get_all_opt(where)
-  if type(opts) == 'table' then
-    if type(opts['check_local']) == 'boolean' then
-      check_local = opts['check_local']
-      ret = true
-    end
-    if type(opts['check_authed']) == 'boolean' then
-      check_authed = opts['check_authed']
-      ret = true
-    end
-  end
-
-  return ret
-end
-
-if not try_opts(N) then try_opts('options') end
+local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+    false, false)
+check_local = auth_and_local_conf[1]
+check_authed = auth_and_local_conf[2]
 
 -- Configuration
 local opts = rspamd_config:get_all_opt(N)
index fbe748db2af10124907f26cf6dd92ebfc03147d7..0b7a5bd9f0382c89f50d5849574c5a256fafd055 100644 (file)
@@ -135,22 +135,6 @@ local function spamtrap_cb(task)
 end
 
 -- Module setup
-local function try_opts(where)
-  local ret = false
-  local opts = rspamd_config:get_all_opt(where)
-  if type(opts) == 'table' then
-    if type(opts['check_local']) == 'boolean' then
-      check_local = opts['check_local']
-      ret = true
-    end
-    if type(opts['check_authed']) == 'boolean' then
-      check_authed = opts['check_authed']
-      ret = true
-    end
-  end
-
-  return ret
-end
 
 local opts = rspamd_config:get_all_opt('spamtrap')
 if not (opts and type(opts) == 'table') then
@@ -158,7 +142,11 @@ if not (opts and type(opts) == 'table') then
   return
 end
 
-if not try_opts(M) then try_opts('options') end
+
+local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, 'spamtrap',
+    false, false)
+check_local = auth_and_local_conf[1]
+check_authed = auth_and_local_conf[2]
 
 if opts then
   for k,v in pairs(opts) do
index ab04577b0edc344c4b792c7dc337915364680d96..24b154c944458a0035ff2954345b5a07f865d095 100644 (file)
@@ -322,24 +322,10 @@ local configure_whitelist_module = function()
       options[k] = v
     end
 
-    local function try_opts(where)
-      local ret = false
-      local test_opts = rspamd_config:get_all_opt(where)
-      if type(test_opts) == 'table' then
-        if type(test_opts.check_local) == 'boolean' then
-          options.check_local = test_opts.check_local
-          ret = true
-        end
-        if type(test_opts.check_authed) == 'boolean' then
-          options.check_authed = test_opts.check_authed
-          ret = true
-        end
-      end
-
-      return ret
-    end
-
-    if not try_opts(N) then try_opts('options') end
+    local auth_and_local_conf = lua_util.config_check_local_or_authed(rspamd_config, N,
+        false, false)
+    options.check_local = auth_and_local_conf[1]
+    options.check_authed = auth_and_local_conf[2]
   else
     rspamd_logger.infox(rspamd_config, 'Module is unconfigured')
     return