local E = {}
-local take_report_sha
+local take_report_id
local take_report_script = [[
local index_key = KEYS[1]
local report_key = KEYS[2]
local tz_offset = get_timezone_offset(os.time())
-local function load_scripts(cfg, ev_base)
- local function redis_report_script_cb(err, data)
- if err then
- rspamd_logger.errx(cfg, 'DMARC report script loading failed: ' .. err)
- else
- take_report_sha = tostring(data)
- rspamd_logger.infox(cfg, 'Loaded DMARC report script with SHA %s', take_report_sha)
- end
- end
- local ret = rspamd_redis.redis_make_request_taskless(ev_base,
- rspamd_config,
- redis_params,
- nil,
- true, -- is write
- redis_report_script_cb, --callback
- 'SCRIPT', -- command
- {'LOAD', take_report_script}
- )
- if not ret then
- rspamd_logger.errx(cfg, 'Unable to load DMARC report script')
- end
-end
-
local function gen_dmarc_grammar()
local lpeg = require "lpeg"
lpeg.locale(lpeg)
rspamd_logger.infox(task, '<%1> dmarc report saved for %2',
task:get_message_id(), hfromdom)
else
- if string.match(err, 'NOSCRIPT') then
- load_scripts(rspamd_config, task:get_ev_base())
- end
rspamd_logger.errx(task, '<%1> dmarc report is not saved for %2: %3',
task:get_message_id(), hfromdom, err)
end
local idx_key = table.concat({redis_keys.index_prefix, period}, redis_keys.join_char)
if report_data then
- local ret = rspamd_redis.redis_make_request(task,
- redis_params, -- connect params
- hfromdom, -- hash key
- true, -- is write
- dmarc_report_cb, --callback
- 'EVALSHA', -- command
- {take_report_sha, 2, idx_key, dmarc_domain_key, hfromdom, report_data} -- arguments
- )
- if not ret then
- rspamd_logger.errx(task, 'Unable to schedule redis request')
- end
+ rspamd_redis.exec_redis_script(take_report_id, {task = task, is_write = true}, dmarc_report_cb,
+ {2, idx_key, dmarc_domain_key, hfromdom, report_data})
end
end
rspamd_logger.errx(rspamd_config, 'cannot parse servers parameter')
elseif not opts['send_reports'] then
dmarc_reporting = true
- rspamd_config:add_on_load(function(cfg, ev_base, worker)
- load_scripts(cfg, ev_base)
- end)
+ take_report_id = rspamd_redis.add_redis_script(take_report_script, redis_params)
else
dmarc_reporting = true
if type(opts['report_settings']) == 'table' then
return
end
end
+ take_report_id = rspamd_redis.add_redis_script(take_report_script, redis_params)
rspamd_config:add_on_load(function(cfg, ev_base, worker)
- load_scripts(cfg, ev_base)
if not worker:is_primary_controller() then return end
local rresolver = rspamd_resolver.init(ev_base, rspamd_config)
rspamd_config:register_finish_script(function ()