Ver código fonte

[Project] Dmarc: Use zlists for dmarc reports

tags/3.0
Vsevolod Stakhov 2 anos atrás
pai
commit
50f8ab9d21
1 arquivos alterados com 17 adições e 3 exclusões
  1. 17
    3
      src/plugins/lua/dmarc.lua

+ 17
- 3
src/plugins/lua/dmarc.lua Ver arquivo

reporting = { reporting = {
redis_keys = { redis_keys = {
index_prefix = 'dmarc_idx', index_prefix = 'dmarc_idx',
report_prefix = 'dmarc',
report_prefix = 'dmarc_rpt',
join_char = ';', join_char = ';',
}, },
enabled = false, enabled = false,
max_entries = 1000, max_entries = 1000,
keys_expire = 172800,
only_domains = nil, only_domains = nil,
}, },
actions = {}, actions = {},


local E = {} local E = {}


-- Keys:
-- 1 = index key (string)
-- 2 = report key (string)
-- 3 = max report elements (number)
-- 4 = expiry time for elements (number)
-- Arguments
-- 1 = dmarc domain
-- 2 = dmarc report
local take_report_id local take_report_id
local take_report_script = [[ local take_report_script = [[
local index_key = KEYS[1] local index_key = KEYS[1]
local report_key = KEYS[2] local report_key = KEYS[2]
local max_entries = -(tonumber(KEYS[3]) + 1)
local keys_expiry = tonumber(KEYS[4])
local dmarc_domain = ARGV[1] local dmarc_domain = ARGV[1]
local report = ARGV[2] local report = ARGV[2]
redis.call('SADD', index_key, report_key) redis.call('SADD', index_key, report_key)
redis.call('EXPIRE', index_key, 172800) redis.call('EXPIRE', index_key, 172800)
redis.call('HINCRBY', report_key, report, 1)
redis.call('ZINCRBY', report_key, 1, report)
redis.call('ZREMRANGEBYRANK', report_key, 0, max_entries)
redis.call('EXPIRE', report_key, 172800) redis.call('EXPIRE', report_key, 172800)
]] ]]


rspamd_redis.exec_redis_script(take_report_id, rspamd_redis.exec_redis_script(take_report_id,
{task = task, is_write = true}, {task = task, is_write = true},
dmarc_report_cb, dmarc_report_cb,
{idx_key, dmarc_domain_key},
{idx_key, dmarc_domain_key,
tostring(settings.reporting.max_entries), tostring(settings.reporting.keys_expire)},
{hdrfromdom, report_data}) {hdrfromdom, report_data})
end end
end end
if not redis_params then if not redis_params then
rspamd_logger.errx(rspamd_config, 'cannot parse servers parameter') rspamd_logger.errx(rspamd_config, 'cannot parse servers parameter')
else else
rspamd_logger.infox(rspamd_config, 'dmarc reporting is enabled')
take_report_id = rspamd_redis.add_redis_script(take_report_script, redis_params) take_report_id = rspamd_redis.add_redis_script(take_report_script, redis_params)
end end
end end

Carregando…
Cancelar
Salvar