Selaa lähdekoodia

Fix lua plugins.

tags/1.0.0
Vsevolod Stakhov 9 vuotta sitten
vanhempi
commit
2830e7e3ea

+ 3
- 5
src/plugins/lua/emails.lua Näytä tiedosto

@@ -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

+ 4
- 3
src/plugins/lua/forged_recipients.lua Näytä tiedosto

@@ -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

+ 4
- 13
src/plugins/lua/multimap.lua Näytä tiedosto

@@ -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

+ 9
- 12
src/plugins/lua/once_received.lua Näytä tiedosto

@@ -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

+ 33
- 37
src/plugins/lua/phishing.lua Näytä tiedosto

@@ -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

+ 5
- 4
src/plugins/lua/rbl.lua Näytä tiedosto

@@ -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)

+ 9
- 4
src/plugins/lua/trie.lua Näytä tiedosto

@@ -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

Loading…
Peruuta
Tallenna