]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Allow custom functions for ratelimits
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 2 Nov 2016 13:15:05 +0000 (13:15 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 2 Nov 2016 13:15:05 +0000 (13:15 +0000)
src/plugins/lua/greylist.lua
src/plugins/lua/ratelimit.lua

index 249d52b5371e5b846e09c8dceb73e52bc728fa86..68af9b933031d9058e3a7e633d66eaf4a691727c 100644 (file)
@@ -379,8 +379,13 @@ end
 
 local opts =  rspamd_config:get_all_opt('greylist')
 if opts then
+  if opts['message_func'] then
+    settings.message_func = assert(loadstring(opts['message_func']))()
+  end
   for k,v in pairs(opts) do
-    settings[k] = v
+    if k ~= 'message_func' then
+      settings[k] = v
+    end
   end
   if settings['whitelisted_ip'] then
     whitelisted_ip = rspamd_config:add_radix_map(settings['whitelisted_ip'],
index 7d6086c3b88fe401175724d6122f9c89e0ab3f02..571cfda97f4544f45146c7c598cbc4a8505bfae4 100644 (file)
@@ -36,6 +36,10 @@ local ip_score_lower_bound = 10
 local ip_score_ham_multiplier = 1.1
 local ip_score_spam_divisor = 1.1
 
+local message_func = function(task, limit_type, bucket, threshold)
+  return string.format('Ratelimit "%s" exceeded', limit_type)
+end
+
 local rspamd_logger = require "rspamd_logger"
 local rspamd_redis = require "rspamd_redis"
 local upstream_list = require "rspamd_upstream_list"
@@ -285,7 +289,7 @@ local function check_limits(task, args)
                 'ratelimit "%s" exceeded: %s elements with %s limit',
                 rtype, bucket, threshold)
               task:set_pre_result('soft reject',
-                string.format('Ratelimit "%s" exceeded', rtype))
+                message_func(task, rtype, bucket, threshold))
             end
           end
         end
@@ -566,6 +570,10 @@ if opts then
     user_keywords = opts['user_keywords']
   end
 
+  if opts['message_func'] then
+    message_func = assert(loadstring(opts['message_func']))()
+  end
+
   redis_params = rspamd_parse_redis_server('ratelimit')
   if not redis_params then
     rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')