diff options
author | Andrew Lewis <nerf@judo.za.org> | 2016-08-19 11:37:46 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2016-08-19 11:37:46 +0200 |
commit | 9263847299a41761dc098bafa7e116af113a8902 (patch) | |
tree | 76d7e9279c13a987eaa889bbc945779cfccadb51 /src/plugins/lua/ip_score.lua | |
parent | 8d34d56b6e6ef7b884d8dd5799853aac03b17abe (diff) | |
download | rspamd-9263847299a41761dc098bafa7e116af113a8902.tar.gz rspamd-9263847299a41761dc098bafa7e116af113a8902.zip |
[Feature] Allow for more fine-grained scoring for ip_score
- Also simplify some funny math
Diffstat (limited to 'src/plugins/lua/ip_score.lua')
-rw-r--r-- | src/plugins/lua/ip_score.lua | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua index db53b6cf2..677ed12a5 100644 --- a/src/plugins/lua/ip_score.lua +++ b/src/plugins/lua/ip_score.lua @@ -49,7 +49,8 @@ local options = { lower_bound = 10, -- minimum number of messages to be scored metric = 'default', min_score = nil, - max_score = nil + max_score = nil, + score_divisor = nil } local asn_re = rspamd_regexp.create_cached("[\\|\\s]") @@ -87,7 +88,7 @@ local function normalize_score(sc, total, mult) if total < options['lower_bound'] then return 0 end - return mult * rspamd_util.tanh(2.718 * sc / total) + return mult * rspamd_util.tanh(2.718281 * sc / total) end -- Set score based on metric's action @@ -137,7 +138,11 @@ local ip_score_set = function(task) score_mult = 0 end - score = score_mult * rspamd_util.tanh (2.718 * score) + if options['score_divisor'] then + score = score_mult * rspamd_util.tanh (2.718281 * (score/options['score_divisor'])) + else + score = score_mult * rspamd_util.tanh (2.718281 * score) + end local hkey = ip_score_hash_key(asn, country, ipnet, ip) local upstream,ret @@ -174,19 +179,19 @@ local ip_score_set = function(task) if ip_score ~= 0 then total_score = total_score + ip_score - table.insert(description_t, 'ip: ' .. '(' .. math.floor(ip_score * 1000) / 100 .. ')') + table.insert(description_t, 'ip: ' .. '(' .. math.floor(ip_score * 10) .. ')') end if ipnet_score ~= 0 then total_score = total_score + ipnet_score - table.insert(description_t, 'ipnet: ' .. ipnet .. '(' .. math.floor(ipnet_score * 1000) / 100 .. ')') + table.insert(description_t, 'ipnet: ' .. ipnet .. '(' .. math.floor(ipnet_score * 10) .. ')') end if asn_score ~= 0 then total_score = total_score + asn_score - table.insert(description_t, 'asn: ' .. asn .. '(' .. math.floor(asn_score * 1000) / 100 .. ')') + table.insert(description_t, 'asn: ' .. asn .. '(' .. math.floor(asn_score * 10) .. ')') end if country_score ~= 0 then total_score = total_score + country_score - table.insert(description_t, 'country: ' .. country .. '(' .. math.floor(country_score * 1000) / 100 .. ')') + table.insert(description_t, 'country: ' .. country .. '(' .. math.floor(country_score * 10) .. ')') end if options['max_score'] and (total_score*10) > options['max_score'] then |