aboutsummaryrefslogtreecommitdiffstats
path: root/rules/rspamd.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2017-09-01 15:09:34 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2017-09-01 15:09:34 +0100
commitd4d22517abb0f17f65e579c4bb8d9e784421247d (patch)
tree7c72ab8e3fdced7bcde1908912a93e5a109370ef /rules/rspamd.lua
parent2b872fd3c7cf6b5ca9defd4c7e025cf46816d0ff (diff)
downloadrspamd-d4d22517abb0f17f65e579c4bb8d9e784421247d.tar.gz
rspamd-d4d22517abb0f17f65e579c4bb8d9e784421247d.zip
[Feature] Read global maps for lua
Diffstat (limited to 'rules/rspamd.lua')
-rw-r--r--rules/rspamd.lua41
1 files changed, 28 insertions, 13 deletions
diff --git a/rules/rspamd.lua b/rules/rspamd.lua
index 3cdd626f9..1c0ddaa8a 100644
--- a/rules/rspamd.lua
+++ b/rules/rspamd.lua
@@ -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