]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Read global maps for lua
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 1 Sep 2017 14:09:34 +0000 (15:09 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 1 Sep 2017 14:09:34 +0000 (15:09 +0100)
rules/rspamd.lua

index 3cdd626f9e3584303adfa403099937ae9a7835f4..1c0ddaa8a68a38b83b847581b0440e7bac317e57 100644 (file)
@@ -19,6 +19,7 @@ limitations under the License.
 require "global_functions" ()
 
 config['regexp'] = {}
+rspamd_maps = {} -- Global maps
 
 local local_conf = rspamd_paths['CONFDIR']
 local local_rules = rspamd_paths['RULESDIR']
@@ -36,24 +37,38 @@ dofile(local_rules .. '/forwarding.lua')
 dofile(local_rules .. '/mid.lua')
 
 local function file_exists(filename)
-       local file = io.open(filename)
-       if file then
-               io.close(file)
-               return true
-       else
-               return false
-       end
+  local file = io.open(filename)
+  if file then
+    io.close(file)
+    return true
+  else
+    return false
+  end
 end
 
 if file_exists(local_conf .. '/rspamd.local.lua') then
-       dofile(local_conf .. '/rspamd.local.lua')
+  dofile(local_conf .. '/rspamd.local.lua')
 else
-       -- Legacy lua/rspamd.local.lua
-       if file_exists(local_conf .. '/lua/rspamd.local.lua') then
-               dofile(local_conf .. '/lua/rspamd.local.lua')
-       end
+  -- Legacy lua/rspamd.local.lua
+  if file_exists(local_conf .. '/lua/rspamd.local.lua') then
+    dofile(local_conf .. '/lua/rspamd.local.lua')
+  end
 end
 
 if file_exists(local_rules .. '/rspamd.classifiers.lua') then
-       dofile(local_rules .. '/rspamd.classifiers.lua')
+  dofile(local_rules .. '/rspamd.classifiers.lua')
 end
+
+local rmaps =  rspamd_config:get_all_opt("lua_maps")
+if rmaps and type(rmaps) == 'table' then
+  local rspamd_logger = require "rspamd_logger"
+  for k,v in pairs(rmaps) do
+    local status,map_or_err = pcall(rspamd_config:add_map(v))
+
+    if not status then
+      rspamd_logger.errx(rspamd_config, "cannot add map %s: %s", k, map_or_err)
+    else
+      rspamd_maps[k] = map_or_err
+    end
+  end
+end
\ No newline at end of file