|
|
@@ -32,7 +32,9 @@ local rspamd_expression = require "rspamd_expression" |
|
|
|
local rspamd_logger = require "rspamd_logger" |
|
|
|
local lua_selectors = require "lua_selectors" |
|
|
|
|
|
|
|
local function gen_cb(expr, act, pool, message, subject, raction, honor, limit, least) |
|
|
|
-- Params table fields: |
|
|
|
-- expr, act, pool, message, subject, raction, honor, limit, flags |
|
|
|
local function gen_cb(params) |
|
|
|
|
|
|
|
local function parse_atom(str) |
|
|
|
local atom = table.concat(fun.totable(fun.take_while(function(c) |
|
|
@@ -57,9 +59,9 @@ local function gen_cb(expr, act, pool, message, subject, raction, honor, limit, |
|
|
|
return 0 |
|
|
|
end |
|
|
|
|
|
|
|
local e, err = rspamd_expression.create(expr, {parse_atom, process_atom}, pool) |
|
|
|
local e, err = rspamd_expression.create(params.expr, {parse_atom, process_atom}, params.pool) |
|
|
|
if err then |
|
|
|
rspamd_logger.errx(rspamd_config, 'Couldnt create expression [%1]: %2', expr, err) |
|
|
|
rspamd_logger.errx(rspamd_config, 'Couldnt create expression [%1]: %2', params.expr, err) |
|
|
|
return |
|
|
|
end |
|
|
|
|
|
|
@@ -89,32 +91,31 @@ local function gen_cb(expr, act, pool, message, subject, raction, honor, limit, |
|
|
|
end |
|
|
|
|
|
|
|
local cact = task:get_metric_action('default') |
|
|
|
if cact == act then |
|
|
|
if params.act and cact == params.act then |
|
|
|
return false |
|
|
|
end |
|
|
|
if honor and honor[cact] then |
|
|
|
if params.honor and params.honor[cact] then |
|
|
|
return false |
|
|
|
elseif raction and not raction[cact] then |
|
|
|
elseif params.raction and not params.raction[cact] then |
|
|
|
return false |
|
|
|
end |
|
|
|
|
|
|
|
local ret = e:process(task) |
|
|
|
if ret > limit then |
|
|
|
if subject then |
|
|
|
task:set_metric_subject(subject) |
|
|
|
if params.limit and ret > params.limit then |
|
|
|
if params.subject then |
|
|
|
task:set_metric_subject(params.subject) |
|
|
|
end |
|
|
|
|
|
|
|
local flags = "" |
|
|
|
if least then flags = "least" end |
|
|
|
local flags = params.flags or "" |
|
|
|
|
|
|
|
if type(message) == 'string' then |
|
|
|
if type(params.message) == 'string' then |
|
|
|
-- process selector expressions in the message |
|
|
|
message = string.gsub(message, '(${(.-)})', process_message_selectors) |
|
|
|
task:set_pre_result(act, message, N, nil, nil, flags) |
|
|
|
local message = string.gsub(params.message, '(${(.-)})', process_message_selectors) |
|
|
|
task:set_pre_result{action = params.act, message = message, module = N, flags = flags} |
|
|
|
else |
|
|
|
task:set_pre_result(act, nil, N, nil, nil, flags) |
|
|
|
task:set_pre_result{action = params.act, module = N, flags = flags} |
|
|
|
end |
|
|
|
return true, act |
|
|
|
return true, params.act |
|
|
|
end |
|
|
|
|
|
|
|
end, e:atoms() |
|
|
@@ -140,7 +141,12 @@ local function configure_module() |
|
|
|
message = (opts.messages or E)[expr] |
|
|
|
end |
|
|
|
if type(expr) == 'string' then |
|
|
|
local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), message, subject) |
|
|
|
-- expr, act, pool, message, subject, raction, honor, limit, flags |
|
|
|
local cb, atoms = gen_cb{expr = expr, |
|
|
|
act = action, |
|
|
|
pool = rspamd_config:get_mempool(), |
|
|
|
message = message, |
|
|
|
subject = subject} |
|
|
|
if cb and atoms then |
|
|
|
local h = rspamd_cryptobox_hash.create() |
|
|
|
h:update(expr) |
|
|
@@ -165,15 +171,22 @@ local function configure_module() |
|
|
|
for name, sett in pairs(opts.rules) do |
|
|
|
local action = sett.action |
|
|
|
local expr = sett.expression |
|
|
|
|
|
|
|
if action and expr then |
|
|
|
local subject = sett.subject |
|
|
|
local message = sett.message |
|
|
|
local lim = sett.limit or 0 |
|
|
|
local least = sett.least or false |
|
|
|
local flags = {} |
|
|
|
if sett.least then table.insert(flags, "least") end |
|
|
|
if sett.process_all then table.insert(flags, "process_all") end |
|
|
|
local raction = lua_util.list_to_hash(sett.require_action) |
|
|
|
local honor = lua_util.list_to_hash(sett.honor_action) |
|
|
|
local cb, atoms = gen_cb(expr, action, rspamd_config:get_mempool(), |
|
|
|
message, subject, raction, honor, lim, least) |
|
|
|
local cb, atoms = gen_cb{expr = expr, |
|
|
|
act = action, |
|
|
|
pool = rspamd_config:get_mempool(), |
|
|
|
message = sett.message, |
|
|
|
subject = sett.subject, |
|
|
|
raction = raction, |
|
|
|
honor = honor, |
|
|
|
limit = sett.limit, |
|
|
|
flags = table.concat(flags, ',')} |
|
|
|
if cb and atoms then |
|
|
|
local t = {} |
|
|
|
if (raction or honor) then |