diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-25 17:12:59 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-08-25 17:12:59 +0100 |
commit | 089619e2abce44867df8059f3a90b6b58400d77f (patch) | |
tree | e1aa9f48f0028aee6b9032fb4a5d074f2d552649 | |
parent | 6f3d45840be0c65cb451ba4f163c5f22697c7c63 (diff) | |
download | rspamd-089619e2abce44867df8059f3a90b6b58400d77f.tar.gz rspamd-089619e2abce44867df8059f3a90b6b58400d77f.zip |
Allow to override settings from the query.
-rw-r--r-- | src/plugins/lua/settings.lua | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index bd2f2ce29..ca98a3d70 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -40,8 +40,53 @@ local max_pri = 0 local rspamd_logger = require "rspamd_logger" local rspamd_ip = require "rspamd_ip" local rspamd_regexp = require "rspamd_regexp" +local ucl = require "ucl" require "fun" () +-- Checks for overrided settings within query params and returns 'true' if +-- settings are overrided +local function check_query_settings(task) + -- Try 'settings' attribute + local query_set = task:get_request_header('settings') + if query_set then + local parser = ucl.parser() + local res,err = parser:parse_string(tostring(query_set)) + if res then + task:set_settings(parser:get_object()) + + return true + end + end + + local query_maxscore = task:get_request_header('maxscore') + if query_maxscore then + -- We have score limits redefined by request + local ms = tonumber(tostring(query_maxscore)) + + if ms then + local nset = { + default = { + actions { + reject = ms + } + } + } + + local query_softscore = task:get_request_header('softscore') + if query_softscore then + local ss = tonumber(tostring(query_softscore)) + nset['default']['actions']['add_header'] = ss + end + + task:set_settings(nset) + + return true + end + end + + return false +end + -- Check limit for a task local function check_settings(task) local function check_addr_setting(rule, addr) @@ -164,7 +209,12 @@ local function check_settings(task) return nil end - + + -- Check if we have override as query argument + if check_query_settings(task) then + return + end + -- Do not waste resources if not settings_initialized then return |