]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support excluding selected users from ratelimits 917/head
authorAndrew Lewis <nerf@judo.za.org>
Wed, 31 Aug 2016 08:37:50 +0000 (10:37 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 31 Aug 2016 08:37:50 +0000 (10:37 +0200)
src/plugins/lua/ratelimit.lua

index e261a927562e9bac52cf32f7be7337aab4c76ad9..b80a122f174cb5e1a71602ae9ffa8aa63a7d3a28 100644 (file)
@@ -42,6 +42,7 @@ local bounce_senders = {'postmaster', 'mailer-daemon', '', 'null', 'fetchmail-da
 -- Do not check ratelimits for these recipients
 local whitelisted_rcpts = {'postmaster', 'mailer-daemon'}
 local whitelisted_ip
+local whitelisted_user
 local max_rcpt = 5
 local redis_params
 local ratelimit_symbol
@@ -346,7 +347,11 @@ 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 ('user', {['user'] = auser}) })
+    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
@@ -470,6 +475,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']