Browse Source

[Minor] Reputation: Support compatible whitelist definition

Issue: #3545
tags/2.7
Vsevolod Stakhov 3 years ago
parent
commit
d75fdb486e
1 changed files with 34 additions and 6 deletions
  1. 34
    6
      src/plugins/lua/reputation.lua

+ 34
- 6
src/plugins/lua/reputation.lua View File

dependencies = {"DKIM_TRACE"}, dependencies = {"DKIM_TRACE"},
filter = dkim_reputation_filter, -- used to get scores filter = dkim_reputation_filter, -- used to get scores
postfilter = dkim_reputation_postfilter, -- used to adjust DKIM scores postfilter = dkim_reputation_postfilter, -- used to adjust DKIM scores
idempotent = dkim_reputation_idempotent -- used to set scores
idempotent = dkim_reputation_idempotent, -- used to set scores
} }


-- URL Selector functions -- URL Selector functions
--dependencies = {"ASN"}, -- ASN is a prefilter now... --dependencies = {"ASN"}, -- ASN is a prefilter now...
init = ip_reputation_init, init = ip_reputation_init,
filter = ip_reputation_filter, -- used to get scores filter = ip_reputation_filter, -- used to get scores
idempotent = ip_reputation_idempotent -- used to set scores
idempotent = ip_reputation_idempotent, -- used to set scores
} }


-- SPF Selector functions -- SPF Selector functions
}, },
dependencies = {"R_SPF_ALLOW"}, dependencies = {"R_SPF_ALLOW"},
filter = spf_reputation_filter, -- used to get scores filter = spf_reputation_filter, -- used to get scores
idempotent = spf_reputation_idempotent -- used to set scores
idempotent = spf_reputation_idempotent, -- used to set scores
} }


-- Generic selector based on lua_selectors framework -- Generic selector based on lua_selectors framework
inbound = ts.boolean, inbound = ts.boolean,
selector = ts.string, selector = ts.string,
delimiter = ts.string, delimiter = ts.string,
whitelist = ts.string:is_optional(),
whitelist = ts.one_of(lua_maps.map_schema, lua_maps_exprs.schema):is_optional(),
}, },
config = { config = {
lower_bound = 10, -- minimum number of messages to be scored lower_bound = 10, -- minimum number of messages to be scored
rule.config = lua_util.override_defaults(rule.config, tbl) rule.config = lua_util.override_defaults(rule.config, tbl)


if rule.config.whitelist then if rule.config.whitelist then
rule.config.whitelist_map = lua_maps_exprs.create(rspamd_config,
rule.config.whitelist, N)
if lua_maps_exprs.schema(rule.config.whitelist) then
rule.config.whitelist_map = lua_maps_exprs.create(rspamd_config,
rule.config.whitelist, N)
elseif lua_maps.map_schema(rule.config.whitelist) then
local map = lua_maps.map_add_from_ucl(rule.config.whitelist,
'radix',
sel_type .. ' reputation whitelist')

if not map then
rspamd_logger.errx(rspamd_config, "cannot parse whitelist map config for %s: (%s)",
sel_type,
rule.config.whitelist)
return
end

rule.config.whitelist_map = {
process = function(_, task)
-- Hack: we assume that it is an ip whitelist :(
local ip = task:get_from_ip()

if ip and map:get_key(ip) then return true end
return false
end
}
else
rspamd_logger.errx(rspamd_config, "cannot parse whitelist map config for %s: (%s)",
sel_type,
rule.config.whitelist)
return
end
end end


local symbol = rule.selector.config.symbol or name local symbol = rule.selector.config.symbol or name

Loading…
Cancel
Save