瀏覽代碼

[Minor] Update some Lua using new API

tags/1.8.0
Mikhail Galanin 5 年之前
父節點
當前提交
5a3f2d9a98
共有 2 個文件被更改,包括 44 次插入49 次删除
  1. 14
    14
      src/plugins/lua/multimap.lua
  2. 30
    35
      src/plugins/lua/reputation.lua

+ 14
- 14
src/plugins/lua/multimap.lua 查看文件

@@ -701,24 +701,24 @@ local function multimap_callback(task, rule)
if rt == 'ip' then
match_rule(rule, ip)
else
local cb = function (_, to_resolve, results, err)
task:inc_dns_req()
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, err)
end
if results then
task:insert_result(rule['symbol'], 1, rule['map'])
local to_resolve = ip_to_rbl(ip, rule['map'])

local is_ok, results = task:get_resolver():resolve_a({
task = task,
name = to_resolve,
})

if pre_filter then
task:set_pre_result(rule['action'], 'Matched map: ' .. rule['symbol'])
end
lua_util.debugm(N, rspamd_config, 'resolve_a() 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'])
end
end

task:get_resolver():resolve_a({task = task,
name = ip_to_rbl(ip, rule['map']),
callback = cb,
})
end
end
end,

+ 30
- 35
src/plugins/lua/reputation.lua 查看文件

@@ -720,45 +720,40 @@ local function reputation_dns_get_token(task, rule, token, continuation_cb)
local key = gen_token_key(token, rule)
local dns_name = key .. '.' .. rule.backend.config.list

local function dns_callback(_, to_resolve, 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', to_resolve, err)
end
if not results then
lua_util.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 error=%3 list=%4',
to_resolve, false, err, rule.backend.config.list)
else
lua_util.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 error=%3 list=%4',
to_resolve, true, err, rule.backend.config.list)
end

-- Now split tokens to list of values
if not err and 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,
lua_util.rspamd_str_split(results[1], ";"))
continuation_cb(nil, to_resolve, values)
else
continuation_cb(err, to_resolve, nil)
end

task:inc_dns_req()
end
r:resolve_a({
local is_ok, results = r:resolve_a({
task = task,
name = dns_name,
callback = dns_callback,
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

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)

-- 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
end
end
end,
lua_util.rspamd_str_split(results[1], ";"))

continuation_cb(nil, dns_name, values)
else
continuation_cb(results, dns_name, nil)
end

task:inc_dns_req()
end

local function reputation_redis_init(rule, cfg, ev_base, worker)

Loading…
取消
儲存