Browse Source

[Minor] Fix various issues in reputation module, allow per rule redis settings

tags/1.7.9
Vsevolod Stakhov 6 years ago
parent
commit
56e9209f9c
1 changed files with 30 additions and 7 deletions
  1. 30
    7
      src/plugins/lua/reputation.lua

+ 30
- 7
src/plugins/lua/reputation.lua View File

'map', 'map',
'IP score whitelisted ASNs/countries') 'IP score whitelisted ASNs/countries')
end end

return true
end end


local function ip_reputation_filter(task, rule) local function ip_reputation_filter(task, rule)
end end


local function reputation_redis_init(rule, cfg, ev_base, worker) local function reputation_redis_init(rule, cfg, ev_base, worker)
if not redis_params then
local our_redis_params = {}

if not lua_redis.try_load_redis_servers(rule.backend.config,
rspamd_config, our_redis_params) then
our_redis_params = redis_params
end
if not our_redis_params then
rspamd_logger.errx(rspamd_config, 'cannot init redis for reputation rule: %s',
rule)
return false return false
end end
-- Init scripts for buckets -- Init scripts for buckets
return result return result
]]) ]])
rule.backend.script_get = lua_redis.add_redis_script(table.concat(redis_script_tbl, '\n'), rule.backend.script_get = lua_redis.add_redis_script(table.concat(redis_script_tbl, '\n'),
redis_params)
our_redis_params)


redis_script_tbl = {} redis_script_tbl = {}
local redis_set_script_tpl = [[ local redis_set_script_tpl = [[
end end


rule.backend.script_set = lua_redis.add_redis_script(table.concat(redis_script_tbl, '\n'), rule.backend.script_set = lua_redis.add_redis_script(table.concat(redis_script_tbl, '\n'),
redis_params)
our_redis_params)


return true return true
end end
values[data[i]] = ndata values[data[i]] = ndata
end end
end end
rspamd_logger.debugm(N, task, 'got values for key %s -> %s',
key, values)
continuation_cb(nil, key, values) continuation_cb(nil, key, values)
else else
rspamd_logger.errx(task, 'invalid type while getting reputation keys %s: %s', rspamd_logger.errx(task, 'invalid type while getting reputation keys %s: %s',
key, err) key, err)
continuation_cb(err, key, nil) continuation_cb(err, key, nil)
else else
rspamd_logger.errx(task, 'got error while getting reputation keys %s: %s',
key, "unknown error")
continuation_cb("unknown error", key, nil) continuation_cb("unknown error", key, nil)
end end
end end
table.insert(args, k) table.insert(args, k)
table.insert(args, v) table.insert(args, v)
end end
rspamd_logger.debugm(N, task, 'set values for key %s -> %s',
key, values)
local ret = lua_redis.exec_redis_script(rule.backend.script_set, local ret = lua_redis.exec_redis_script(rule.backend.script_set,
{task = task, is_write = true}, {task = task, is_write = true},
redis_set_cb, redis_set_cb,
if rule.config.whitelisted_ip then if rule.config.whitelisted_ip then
rule.config.whitelisted_ip_map = lua_maps.rspamd_map_add_from_ucl(rule.whitelisted_ip, rule.config.whitelisted_ip_map = lua_maps.rspamd_map_add_from_ucl(rule.whitelisted_ip,
'radix', 'radix',
'Reputation whiteliist for ' .. name)
'Reputation whitelist for ' .. name)
end end


local symbol = name local symbol = name
if rule.selector.init then if rule.selector.init then
if not rule.selector.init(rule, cfg, ev_base, worker) then if not rule.selector.init(rule, cfg, ev_base, worker) then
rule.enabled = false rule.enabled = false
rspamd_logger.errx(rspamd_config, 'Cannot init selector %s (backend %s) for symbol %s',
sel_type, bk_type, rule.symbol)
else else
rule.enabled = true rule.enabled = true
end end
if rule.backend.init then if rule.backend.init then
if not rule.backend.init(rule, cfg, ev_base, worker) then if not rule.backend.init(rule, cfg, ev_base, worker) then
rule.enabled = false rule.enabled = false
rspamd_logger.errx(rspamd_config, 'Cannot init backend (%s) for rule %s for symbol %s',
bk_type, sel_type, rule.symbol)
else else
rule.enabled = true rule.enabled = true
end end
end end

if rule.enabled then
rspamd_logger.infox(rspamd_config, 'Enable %s (%s backend) rule for symbol %s',
sel_type, bk_type, rule.symbol)
end
end) end)


-- We now generate symbol for checking -- We now generate symbol for checking
} }
end end


rspamd_logger.infox('Enable %s(%s backend) rule for symbol %s',
sel_type, bk_type, rule.symbol)
end end


redis_params = rspamd_parse_redis_server('reputation')
redis_params = lua_redis.parse_redis_server('reputation')
local opts = rspamd_config:get_all_opt("reputation") local opts = rspamd_config:get_all_opt("reputation")


-- Initialization part -- Initialization part

Loading…
Cancel
Save