]> source.dussan.org Git - rspamd.git/commitdiff
Allow to override settings from the query.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 25 Aug 2015 16:12:59 +0000 (17:12 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 25 Aug 2015 16:12:59 +0000 (17:12 +0100)
src/plugins/lua/settings.lua

index bd2f2ce29a418547c5dab8f0cabe62c50792c900..ca98a3d70dd6857199e7793e81e3a6141c3f4325 100644 (file)
@@ -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