diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-05-28 12:59:13 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-05-28 12:59:13 +0100 |
commit | 2830e7e3eaa30f68d4556cbf4f4e489a00547368 (patch) | |
tree | 84334b5597069530f4f866c0f67f5a75d60359c2 | |
parent | 5645cc20de577a60111b42ac15a8c931391307fc (diff) | |
download | rspamd-2830e7e3eaa30f68d4556cbf4f4e489a00547368.tar.gz rspamd-2830e7e3eaa30f68d4556cbf4f4e489a00547368.zip |
Fix lua plugins.
-rw-r--r-- | src/plugins/lua/emails.lua | 8 | ||||
-rw-r--r-- | src/plugins/lua/forged_recipients.lua | 7 | ||||
-rw-r--r-- | src/plugins/lua/multimap.lua | 17 | ||||
-rw-r--r-- | src/plugins/lua/once_received.lua | 21 | ||||
-rw-r--r-- | src/plugins/lua/phishing.lua | 70 | ||||
-rw-r--r-- | src/plugins/lua/rbl.lua | 9 | ||||
-rw-r--r-- | src/plugins/lua/trie.lua | 13 |
7 files changed, 67 insertions, 78 deletions
diff --git a/src/plugins/lua/emails.lua b/src/plugins/lua/emails.lua index 1dc1a0c97..7df5262d0 100644 --- a/src/plugins/lua/emails.lua +++ b/src/plugins/lua/emails.lua @@ -113,7 +113,6 @@ if opts and type(opts) == 'table' then logger.err('incomplete rule') else table.insert(rules, rule) - rspamd_config:register_virtual_symbol(rule['symbol'], 1.0) end end end @@ -121,9 +120,8 @@ end if table.maxn(rules) > 0 then -- add fake symbol to check all maps inside a single callback - if type(rspamd_config.get_api_version) ~= 'nil' then - rspamd_config:register_callback_symbol('EMAILS', 1.0, check_emails) - else - rspamd_config:register_symbol('EMAILS', 1.0, check_emails) + local id = rspamd_config:register_callback_symbol(1.0, check_emails) + for _,rule in ipairs(rules) do + rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id) end end diff --git a/src/plugins/lua/forged_recipients.lua b/src/plugins/lua/forged_recipients.lua index 6c553aa04..170c2cd53 100644 --- a/src/plugins/lua/forged_recipients.lua +++ b/src/plugins/lua/forged_recipients.lua @@ -84,14 +84,15 @@ end local opts = rspamd_config:get_all_opt('forged_recipients') if opts then if opts['symbol_rcpt'] or opts['symbol_sender'] then + local id = rspamd_config:register_callback_symbol(1.0, + check_forged_headers) if opts['symbol_rcpt'] then symbol_rcpt = opts['symbol_rcpt'] - rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, check_forged_headers) + rspamd_config:register_virtual_symbol(symbol_rcpt, 1.0, id) end if opts['symbol_sender'] then symbol_sender = opts['symbol_sender'] - rspamd_config:register_virtual_symbol(symbol_sender, 1.0) + rspamd_config:register_virtual_symbol(symbol_sender, 1.0, id) end - rspamd_config:register_callback_symbol('FORGED_RECIPIENTS', 1.0, check_forged_headers) end end
\ No newline at end of file diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index c7908ea9b..d9c9dd099 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -164,12 +164,6 @@ local function add_multimap_rule(key, newrule) end -- Registration -if type(rspamd_config.get_api_version) ~= 'nil' then - if rspamd_config:get_api_version() >= 1 then - rspamd_config:register_module_option('multimap', 'rule', 'string') - end -end - local opts = rspamd_config:get_all_opt('multimap') if opts and type(opts) == 'table' then for k,m in pairs(opts) do @@ -179,9 +173,6 @@ if opts and type(opts) == 'table' then rspamd_logger.err('cannot add rule: "'..k..'"') else table.insert(rules, rule) - if type(rspamd_config.get_api_version) ~= 'nil' then - rspamd_config:register_virtual_symbol(rule['symbol'], 1.0) - end end else rspamd_logger.err('parameter ' .. k .. ' is invalid, must be an object') @@ -189,10 +180,10 @@ if opts and type(opts) == 'table' then end -- add fake symbol to check all maps inside a single callback if type(rspamd_config.get_api_version) ~= 'nil' then - if rspamd_config.get_api_version() >= 4 then - rspamd_config:register_callback_symbol_priority('MULTIMAP', 1.0, -1, check_multimap) - else - rspamd_config:register_callback_symbol('MULTIMAP', 1.0, check_multimap) + local id = rspamd_config:register_callback_symbol_priority(1.0, -1, + check_multimap) + for i,rule in ipairs(rules) do + rspamd_config:register_virtual_symbol(rule['symbol'], 1.0, id) end end end diff --git a/src/plugins/lua/once_received.lua b/src/plugins/lua/once_received.lua index 80ef8cf29..7cbdacf50 100644 --- a/src/plugins/lua/once_received.lua +++ b/src/plugins/lua/once_received.lua @@ -124,31 +124,28 @@ end -- Configuration local opts = rspamd_config:get_all_opt('once_received') if opts then - if opts['symbol'] then - local symbol = opts['symbol'] + if opts['symbol'] then + local symbol = opts['symbol'] - for n,v in pairs(opts) do + local id = rspamd_config:register_symbol(symbol, 1.0, check_quantity_received) + + for n,v in pairs(opts) do if n == 'symbol_strict' then symbol_strict = v - if type(rspamd_config.get_api_version) ~= 'nil' then - rspamd_config:register_virtual_symbol(symbol_strict, 1.0) - end + rspamd_config:register_virtual_symbol(symbol_strict, 1.0, id) elseif n == 'bad_host' then if type(v) == 'string' then - bad_hosts[1] = v + bad_hosts[1] = v else bad_hosts = v end elseif n == 'good_host' then if type(v) == 'string' then - good_hosts[1] = v + good_hosts[1] = v else good_hosts = v end - end end - - -- Register symbol's callback - rspamd_config:register_symbol(symbol, 1.0, check_quantity_received) + end end end diff --git a/src/plugins/lua/phishing.lua b/src/plugins/lua/phishing.lua index 78d3b2099..a96977d05 100644 --- a/src/plugins/lua/phishing.lua +++ b/src/plugins/lua/phishing.lua @@ -32,7 +32,7 @@ local domains = nil local strict_domains = {} local rspamd_logger = require "rspamd_logger" -function phishing_cb (task) +local function phishing_cb(task) local urls = task:get_urls(); if urls then @@ -79,41 +79,37 @@ end local opts = rspamd_config:get_all_opt('phishing') if opts then - if opts['symbol'] then - symbol = opts['symbol'] - - -- Register symbol's callback - rspamd_config:register_symbol(symbol, 1.0, 'phishing_cb') + if opts['symbol'] then + symbol = opts['symbol'] + -- Register symbol's callback + local id = rspamd_config:register_symbol(symbol, 1.0, phishing_cb) + if opts['domains'] and type(opt['domains']) == 'string' then + domains = rspamd_config:add_hash_map (opts['domains']) end - if opts['domains'] and type(opt['domains']) == 'string' then - domains = rspamd_config:add_hash_map (opts['domains']) - end - if opts['strict_domains'] then - local sd = {} - if type(opts['strict_domains']) == 'table' then - sd = opts['strict_domains'] - else - sd[1] = opts['strict_domains'] - end - for _,d in ipairs(sd) do - local s, _ = string.find(d, ':[^:]+$') - if s then - local sym = string.sub(d, s + 1, -1) - local map = string.sub(d, 1, s - 1) - if type(rspamd_config.get_api_version) ~= 'nil' then - rspamd_config:register_virtual_symbol(sym, 1) - end - local rmap = rspamd_config:add_hash_map (map, 'Phishing strict domains map') - if rmap then - local rule = {symbol = sym, map = rmap} - table.insert(strict_domains, rule) - else - rspamd_logger.info('cannot add map: ' .. map .. ' for symbol: ' .. sym) - end - else - rspamd_logger.info('strict_domains option must be in format <map>:<symbol>') - end - end - end - -- If no symbol defined, do not register this module + if opts['strict_domains'] then + local sd = {} + if type(opts['strict_domains']) == 'table' then + sd = opts['strict_domains'] + else + sd[1] = opts['strict_domains'] + end + for _,d in ipairs(sd) do + local s, _ = string.find(d, ':[^:]+$') + if s then + local sym = string.sub(d, s + 1, -1) + local map = string.sub(d, 1, s - 1) + rspamd_config:register_virtual_symbol(sym, 1, id) + local rmap = rspamd_config:add_hash_map (map, 'Phishing strict domains map') + if rmap then + local rule = {symbol = sym, map = rmap} + table.insert(strict_domains, rule) + else + rspamd_logger.info('cannot add map: ' .. map .. ' for symbol: ' .. sym) + end + else + rspamd_logger.info('strict_domains option must be in format <map>:<symbol>') + end + end + end + end end diff --git a/src/plugins/lua/rbl.lua b/src/plugins/lua/rbl.lua index eddb4c77b..cceb00449 100644 --- a/src/plugins/lua/rbl.lua +++ b/src/plugins/lua/rbl.lua @@ -342,6 +342,8 @@ end local white_symbols = {} local black_symbols = {} +local id = rspamd_config:register_callback_symbol_priority(1.0, 0, rbl_cb) + for key,rbl in pairs(opts['rbls']) do for default, default_v in pairs(default_defaults) do if(rbl[default_v[2]] == nil) then @@ -351,7 +353,7 @@ for key,rbl in pairs(opts['rbls']) do if type(rbl['returncodes']) == 'table' then for s,_ in pairs(rbl['returncodes']) do if type(rspamd_config.get_api_version) ~= 'nil' then - rspamd_config:register_virtual_symbol(s, 1) + rspamd_config:register_virtual_symbol(s, 1, id) if(rbl['is_whitelist']) then table.insert(white_symbols, s) else @@ -364,7 +366,7 @@ for key,rbl in pairs(opts['rbls']) do rbl['symbol'] = key end if type(rspamd_config.get_api_version) ~= 'nil' and rbl['symbol'] then - rspamd_config:register_virtual_symbol(rbl['symbol'], 1) + rspamd_config:register_virtual_symbol(rbl['symbol'], 1, id) if(rbl['is_whitelist']) then table.insert(white_symbols, rbl['symbol']) else @@ -380,7 +382,6 @@ for _, w in pairs(white_symbols) do csymbol = 'RBL_COMPOSITE_' .. w .. '_' .. b rspamd_config:set_metric_symbol(csymbol, 0, 'Autogenerated composite') rspamd_config:add_composite(csymbol, w .. ' & ' .. b) - rspamd_config:register_virtual_symbol(csymbol, 1) + rspamd_config:register_virtual_symbol(csymbol, 1, id) end end -rspamd_config:register_callback_symbol_priority('RBL', 1.0, 0, rbl_cb) diff --git a/src/plugins/lua/trie.lua b/src/plugins/lua/trie.lua index 279fc2d67..d41d12b5d 100644 --- a/src/plugins/lua/trie.lua +++ b/src/plugins/lua/trie.lua @@ -128,8 +128,6 @@ local function process_trie_conf(symbol, cf) process_single_pattern(pat, symbol, cf) end, cf['patterns']) end - - rspamd_config:register_virtual_symbol(symbol, 1.0) end local opts = rspamd_config:get_all_opt("trie") @@ -147,10 +145,17 @@ if opts then mime_trie = rspamd_trie.create(mime_patterns) rspamd_logger.infox('registered mime search trie from %1 patterns', #mime_patterns) end - + + local id = -1 if mime_trie or raw_trie then - rspamd_config:register_callback_symbol('TRIE', 1.0, tries_callback) + id = rspamd_config:register_callback_symbol('TRIE', 1.0, tries_callback) else rspamd_logger.err('no tries defined') end + + if id ~= -1 then + for sym, opt in pairs(opts) do + rspamd_config:register_virtual_symbol(sym, 1.0, id) + end + end end |