Browse Source

[Feature] Allow custom functions for ratelimits

tags/1.4.0
Vsevolod Stakhov 7 years ago
parent
commit
99488d5a2a
2 changed files with 15 additions and 2 deletions
  1. 6
    1
      src/plugins/lua/greylist.lua
  2. 9
    1
      src/plugins/lua/ratelimit.lua

+ 6
- 1
src/plugins/lua/greylist.lua View 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'],

+ 9
- 1
src/plugins/lua/ratelimit.lua View 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')

Loading…
Cancel
Save