local rspamd_expression = require "rspamd_expression"
local rspamd_ip = require "rspamd_ip"
local lua_util = require "lua_util"
-local rspamd_dns = require "rspamd_dns"
local lua_selectors = require "lua_selectors"
local redis_params
local fun = require "fun"
local ip = task:get_from_ip()
if ip:is_valid() then
local to_resolve = ip_to_rbl(ip, rule['map'])
+ local function dns_cb(_, _, results, err)
+ lua_util.debugm(N, rspamd_config,
+ 'resolve() finished: results=%1, err=%2, to_resolve=%3',
+ results, err, to_resolve)
+
+ if err and
+ (err ~= 'requested record is not found' and
+ err ~= 'no records with this name') then
+ rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, results)
+ elseif results then
+ task:insert_result(rule['symbol'], 1, rule['map'])
+ if pre_filter then
+ task:set_pre_result(rule['action'],
+ 'Matched map: ' .. rule['symbol'], N)
+ end
+ end
+ end
- local is_ok, results = rspamd_dns.request({
- type = "a",
- task = task,
+ task:get_resolver():resolve_a({
+ task= task,
name = to_resolve,
+ callback = dns_cb,
+ forced = true
})
-
- lua_util.debugm(N, rspamd_config,
- 'resolve() finished: results=%1, is_ok=%2, to_resolve=%3',
- results, is_ok, to_resolve)
-
- if not is_ok and
- (results ~= 'requested record is not found' and results ~= 'no records with this name') then
- rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, results)
- elseif is_ok then
- task:insert_result(rule['symbol'], 1, rule['map'])
- if pre_filter then
- task:set_pre_result(rule['action'], 'Matched map: ' .. rule['symbol'], N)
- end
- end
end
end,
header = function()
local rspamd_logger = require "rspamd_logger"
local rspamd_util = require "rspamd_util"
-local rspamd_dns = require "rspamd_dns"
local lua_util = require "lua_util"
local lua_maps = require "lua_maps"
local hash = require 'rspamd_cryptobox_hash'
local key = gen_token_key(token, rule)
local dns_name = key .. '.' .. rule.backend.config.list
- local is_ok, results = rspamd_dns.request({
- type = 'a',
- task = task,
- name = dns_name,
- forced = true,
- })
-
- if not is_ok and (results ~= 'requested record is not found' and results ~= 'no records with this name') then
- rspamd_logger.errx(task, 'error looking up %s: %s', dns_name, results)
- end
+ local function dns_cb(_, _, results, err)
+ if err and (err ~= 'requested record is not found' and
+ err ~= 'no records with this name') then
+ rspamd_logger.errx(task, 'error looking up %s: %s', dns_name, err)
+ end
- lua_util.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 is_ok=%3 list=%4',
- dns_name, results, is_ok, rule.backend.config.list)
+ lua_util.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 err=%3 list=%4',
+ dns_name, results, err, rule.backend.config.list)
- -- Now split tokens to list of values
- if is_ok then
- local values = {}
- -- Format: key1=num1;key2=num2...keyn=numn
- fun.each(function(e)
- local vals = lua_util.rspamd_str_split(e, "=")
- if vals and #vals == 2 then
- local nv = tonumber(vals[2])
- if nv then
- values[vals[1]] = nv
+ -- Now split tokens to list of values
+ if results then
+ local values = {}
+ -- Format: key1=num1;key2=num2...keyn=numn
+ fun.each(function(e)
+ local vals = lua_util.rspamd_str_split(e, "=")
+ if vals and #vals == 2 then
+ local nv = tonumber(vals[2])
+ if nv then
+ values[vals[1]] = nv
+ end
end
- end
- end,
- lua_util.rspamd_str_split(results[1], ";"))
+ end,
+ lua_util.rspamd_str_split(results[1], ";"))
- continuation_cb(nil, dns_name, values)
- else
- continuation_cb(results, dns_name, nil)
+ continuation_cb(nil, dns_name, values)
+ else
+ continuation_cb(results, dns_name, nil)
+ end
end
+
+ task:get_resolver():resolve_a({
+ task = task,
+ name = dns_name,
+ callback = dns_cb,
+ forced = true,
+ })
end
local function reputation_redis_init(rule, cfg, ev_base, worker)