diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-09-02 13:44:04 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-09-02 13:44:04 +0100 |
commit | dc3fd1d5f97aa70c8c0429ea4958792031b4976a (patch) | |
tree | ba64e2d875199e2faf145915edadcc6732cc3163 /src/plugins | |
parent | d3f6d9088865aa2605e1c084861a6aa3e44ea154 (diff) | |
download | rspamd-dc3fd1d5f97aa70c8c0429ea4958792031b4976a.tar.gz rspamd-dc3fd1d5f97aa70c8c0429ea4958792031b4976a.zip |
[Feature] Allow to use global lua maps in settings
Issue: #1802
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/lua/settings.lua | 74 |
1 files changed, 43 insertions, 31 deletions
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index 7d28f2545..4562b8361 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -23,6 +23,7 @@ end -- https://rspamd.com/doc/configuration/settings.html local rspamd_logger = require "rspamd_logger" +local rspamd_maps = require "maps" local redis_params local settings = {} @@ -105,17 +106,17 @@ local function check_settings(task) local function check_addr_setting(rule, addr) local function check_specific_addr(elt) if rule['name'] then - if rule['name']:lower() == elt['addr']:lower() then + if rspamd_maps.rspamd_maybe_check_map(rule['name'], elt['addr']) then return true end end if rule['user'] then - if rule['user']:lower() == elt['user']:lower() then + if rspamd_maps.rspamd_maybe_check_map(rule['user'], elt['user']) then return true end end if rule['domain'] and elt['domain'] then - if rule['domain']:lower() == elt['domain']:lower() then + if rspamd_maps.rspamd_maybe_check_map(rule['domain'], elt['domain']) then return true end end @@ -137,13 +138,19 @@ local function check_settings(task) end local function check_ip_setting(rule, ip) - if rule[2] ~= 0 then - local nip = ip:apply_mask(rule[2]) - if nip and nip:to_string() == rule[1]:to_string() then + if not rule[2] then + if rspamd_maps.rspamd_maybe_check_map(rule[1], ip:to_string()) then + return true + end + else + if rule[2] ~= 0 then + local nip = ip:apply_mask(rule[2]) + if nip and nip:to_string() == rule[1]:to_string() then + return true + end + elseif ip:to_string() == rule[1]:to_string() then return true end - elseif ip:to_string() == rule[1]:to_string() then - return true end return false @@ -376,8 +383,8 @@ local function process_settings_table(tbl) out[1] = res out[2] = 0 else - rspamd_logger.errx(rspamd_config, "bad IP address: " .. ip) - return nil + -- It can still be a map + out[1] = res end else local res = rspamd_ip.from_string(string.sub(ip, 1, slash - 1)) @@ -405,29 +412,34 @@ local function process_settings_table(tbl) table.insert(out, process_addr(v)) end elseif type(addr) == "string" then - local start = string.sub(addr, 1, 1) - if start == '/' then - -- It is a regexp - local re = rspamd_regexp.create(addr) - if re then - out['regexp'] = re - else - rspamd_logger.errx(rspamd_config, "bad regexp: " .. addr) - return nil - end - - elseif start == '@' then - -- It is a domain if form @domain - out['domain'] = string.sub(addr, 2) + if string.sub(addr, 1, 4) == "map:" then + -- It is map, don't apply any extra logic + out['name'] = addr else - -- Check user@domain parts - local at = string.find(addr, '@') - if at then - -- It is full address - out['name'] = addr + local start = string.sub(addr, 1, 1) + if start == '/' then + -- It is a regexp + local re = rspamd_regexp.create(addr) + if re then + out['regexp'] = re + else + rspamd_logger.errx(rspamd_config, "bad regexp: " .. addr) + return nil + end + + elseif start == '@' then + -- It is a domain if form @domain + out['domain'] = string.sub(addr, 2) else - -- It is a user - out['user'] = addr + -- Check user@domain parts + local at = string.find(addr, '@') + if at then + -- It is full address + out['name'] = addr + else + -- It is a user + out['user'] = addr + end end end else |