Browse Source

[Minor] Add ip reputation setter logic

tags/1.7.0
Vsevolod Stakhov 6 years ago
parent
commit
1548a8c492
1 changed files with 47 additions and 0 deletions
  1. 47
    0
      src/plugins/lua/reputation.lua

+ 47
- 0
src/plugins/lua/reputation.lua View File

@@ -175,7 +175,54 @@ end

-- Used to set scores
local function ip_reputation_idempotent(task, rule)
if not rule.backend.set_token then return end -- Read only backend
local ip = task:get_from_ip()

if not ip or not ip:is_valid() then return end
if lua_util.is_rspamc_or_controller(task) then return end

local cfg = rule.selector.config

local pool = task:get_mempool()
local asn = pool:get_variable("asn")
local country = pool:get_variable("country")
local ipnet = pool:get_variable("ipnet")

if country and cfg.asn_cc_whitelist then
if cfg.asn_cc_whitelist:get_key(country) then
return
end
if asn and cfg.asn_cc_whitelist:get_key(asn) then
return
end
end

local action = task:get_metric_action()
local token = {
}
local need_set = false

-- TODO: take metric score into consideration
local k = cfg.keys_map[action]

if k then
token[k] = 1.0
need_set = true
end

if need_set then
if asn then
rule.backend.set_token(task, rule, cfg.asn_prefix .. asn, token)
end
if country then
rule.backend.set_token(task, rule, cfg.country_prefix .. country, token)
end
if ipnet then
rule.backend.set_token(task, rule, cfg.ipnet_prefix .. ipnet, token)
end

rule.backend.set_token(task, rule, cfg.ip_prefix .. tostring(ip), token)
end
end

-- Selectors are used to extract reputation tokens

Loading…
Cancel
Save