Browse Source

[Feature] Use verdict instead of the plain action in plugins

tags/1.8.1
Vsevolod Stakhov 5 years ago
parent
commit
01ef5c03a6
3 changed files with 41 additions and 44 deletions
  1. 6
    6
      src/plugins/lua/clustering.lua
  2. 7
    4
      src/plugins/lua/ratelimit.lua
  3. 28
    34
      src/plugins/lua/reputation.lua

+ 6
- 6
src/plugins/lua/clustering.lua View File

@@ -186,18 +186,18 @@ local function clusterting_filter_cb(task, rule)
end

local function clusterting_idempotent_cb(task, rule)
local action = task:get_action()
local verdict = lua_util.get_task_verdict(task)
local score

if action == 'no action' then
if verdict == 'ham' then
score = rule.ham_mult
elseif action == 'reject' then
elseif verdict == 'spam' then
score = rule.spam_mult
elseif action == 'add header' or action == 'rewrite subject' then
elseif verdict == 'junk' then
score = rule.junk_mult
else
rspamd_logger.debugm(N, task, 'skip rule %s, action=%s',
rule.name, action)
rspamd_logger.debugm(N, task, 'skip rule %s, verdict=%s',
rule.name, verdict)
return
end


+ 7
- 4
src/plugins/lua/ratelimit.lua View File

@@ -596,7 +596,7 @@ local function ratelimit_update_cb(task)
return
end

local is_spam = not (task:get_metric_action() == 'no action')
local verdict = lua_util.get_task_verdict(task)

-- Update each bucket
for k, v in pairs(prefixes) do
@@ -615,12 +615,15 @@ local function ratelimit_update_cb(task)
end
local now = rspamd_util.get_time()
now = lua_util.round(now * 1000.0) -- Get milliseconds
local mult_burst = bucket.ham_factor_burst or 1.0
local mult_rate = bucket.ham_factor_burst or 1.0
local mult_burst = 1.0
local mult_rate = 1.0

if is_spam then
if verdict == 'spam' or verdict == 'junk' then
mult_burst = bucket.spam_factor_burst or 1.0
mult_rate = bucket.spam_factor_rate or 1.0
elseif verdict == 'ham' then
mult_burst = bucket.ham_factor_burst or 1.0
mult_rate = bucket.ham_factor_rate or 1.0
end

lua_redis.exec_redis_script(bucket_update_id,

+ 28
- 34
src/plugins/lua/reputation.lua View File

@@ -38,10 +38,9 @@ local redis_params = nil
local default_expiry = 864000 -- 10 day by default

local keymap_schema = ts.shape{
['reject'] = ts.string,
['add header'] = ts.string,
['rewrite subject'] = ts.string,
['no action'] = ts.string
['spam'] = ts.string,
['junk'] = ts.string,
['ham'] = ts.string,
}

-- Get reputation from ham/spam/probable hits
@@ -165,14 +164,14 @@ local function dkim_reputation_filter(task, rule)
end

local function dkim_reputation_idempotent(task, rule)
local action = task:get_metric_action()
local verdict = lua_util.get_task_verdict()
local token = {
}
local cfg = rule.selector.config
local need_set = false

-- TODO: take metric score into consideration
local k = cfg.keys_map[action]
local k = cfg.keys_map[verdict]

if k then
token[k] = 1.0
@@ -218,10 +217,9 @@ local dkim_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
['reject'] = 's',
['add header'] = 'p',
['rewrite subject'] = 'p',
['no action'] = 'h'
['spam'] = 's',
['junk'] = 'p',
['ham'] = 'h'
},
symbol = 'DKIM_SCORE', -- symbol to be inserted
lower_bound = 10, -- minimum number of messages to be scored
@@ -312,14 +310,14 @@ local function url_reputation_filter(task, rule)
end

local function url_reputation_idempotent(task, rule)
local action = task:get_metric_action()
local verdict = lua_util.get_task_verdict(task)
local token = {
}
local cfg = rule.selector.config
local need_set = false

-- TODO: take metric score into consideration
local k = cfg.keys_map[action]
local k = cfg.keys_map[verdict]

if k then
token[k] = 1.0
@@ -343,10 +341,9 @@ local url_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
['reject'] = 's',
['add header'] = 'p',
['rewrite subject'] = 'p',
['no action'] = 'h'
['spam'] = 's',
['junk'] = 'p',
['ham'] = 'h'
},
symbol = 'URL_SCORE', -- symbol to be inserted
lower_bound = 10, -- minimum number of messages to be scored
@@ -509,13 +506,13 @@ local function ip_reputation_idempotent(task, rule)
end
end

local action = task:get_metric_action()
local verdict = lua_util.get_task_verdict(task)
local token = {
}
local need_set = false

-- TODO: take metric score into consideration
local k = cfg.keys_map[action]
local k = cfg.keys_map[verdict]

if k then
token[k] = 1.0
@@ -545,10 +542,9 @@ local ip_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
['reject'] = 's',
['add header'] = 'p',
['rewrite subject'] = 'p',
['no action'] = 'h'
['spam'] = 's',
['junk'] = 'p',
['ham'] = 'h'
},
scores = { -- how each component is evaluated
['asn'] = 0.4,
@@ -603,7 +599,7 @@ local function spf_reputation_filter(task, rule)
end

local function spf_reputation_idempotent(task, rule)
local action = task:get_metric_action()
local verdict = lua_util.get_task_verdict(task)
local spf_record = task:get_mempool():get_variable('spf_record')
local spf_allow = task:has_symbol('R_SPF_ALLOW')
local token = {
@@ -614,7 +610,7 @@ local function spf_reputation_idempotent(task, rule)
if not spf_record or not spf_allow then return end

-- TODO: take metric score into consideration
local k = cfg.keys_map[action]
local k = cfg.keys_map[verdict]

if k then
token[k] = 1.0
@@ -639,10 +635,9 @@ local spf_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
['reject'] = 's',
['add header'] = 'p',
['rewrite subject'] = 'p',
['no action'] = 'h'
['spam'] = 's',
['junk'] = 'p',
['ham'] = 'h'
},
symbol = 'SPF_SCORE', -- symbol to be inserted
lower_bound = 10, -- minimum number of messages to be scored
@@ -718,7 +713,7 @@ local function generic_reputation_filter(task, rule)
end

local function generic_reputation_idempotent(task, rule)
local action = task:get_metric_action()
local verdict = lua_util.get_task_verdict(task)
local cfg = rule.selector.config
local need_set = false
local token = {}
@@ -726,7 +721,7 @@ local function generic_reputation_idempotent(task, rule)
local selector_res = cfg.selector(task)
if not selector_res then return end

local k = cfg.keys_map[action]
local k = cfg.keys_map[verdict]

if k then
token[k] = 1.0
@@ -767,10 +762,9 @@ local generic_selector = {
-- s is for spam,
-- p is for probable spam
keys_map = {
['reject'] = 's',
['add header'] = 'p',
['rewrite subject'] = 'p',
['no action'] = 'h'
['spam'] = 's',
['junk'] = 'p',
['ham'] = 'h'
},
lower_bound = 10, -- minimum number of messages to be scored
min_score = nil,

Loading…
Cancel
Save