From af3f7ea81f0146898f37c4372aed38e85efd903e Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Wed, 31 Aug 2016 10:37:50 +0200 Subject: [PATCH] [Feature] Support excluding selected users from ratelimits --- src/plugins/lua/ratelimit.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua index 1b0ec4f7a..9ca645506 100644 --- a/src/plugins/lua/ratelimit.lua +++ b/src/plugins/lua/ratelimit.lua @@ -38,6 +38,7 @@ local bounce_senders = {'postmaster', 'mailer-daemon', '', 'null', 'fetchmail-da -- Do not check ratelimits for these senders local whitelisted_rcpts = {'postmaster', 'mailer-daemon'} local whitelisted_ip +local whitelisted_user local max_rcpt = 5 local redis_params local ratelimit_symbol @@ -289,7 +290,15 @@ local function rate_test_set(task, func) -- Get user (authuser) local auser = task:get_user() if auser and settings['user'][1] > 0 then - table.insert(args, {settings['user'], make_rate_key (auser, '', nil)}) + if whitelisted_user and whitelisted_user:get_key(auser) then + rspamd_logger.infox(task, 'skip ratelimit for whitelisted user') + else + table.insert(args, {settings['user'], make_rate_key ('user', {['user'] = auser}) }) + end + end + local asn + if settings['asn'][1] > 0 then + asn = task:get_mempool():get_variable('asn') end local is_bounce = check_bounce(from_user) @@ -399,6 +408,10 @@ if opts then whitelisted_ip = rspamd_config:add_radix_map(opts['whitelisted_ip'], 'Ratelimit whitelist ip map') end + if opts['whitelisted_user'] then + whitelisted_user = rspamd_config:add_kv_map(opts['whitelisted_user'], 'Ratelimit whitelist user map') + end + if opts['symbol'] then -- We want symbol instead of pre-result ratelimit_symbol = opts['symbol'] -- 2.39.5