From 1424d904c9c5cb1593b369949354d376af56f111 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 29 Mar 2016 15:29:51 +0100 Subject: [PATCH] [Feature] Allow to select settings by id in HTTP query --- src/plugins/lua/settings.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/plugins/lua/settings.lua b/src/plugins/lua/settings.lua index 621e33a2b..5b27d4b66 100644 --- a/src/plugins/lua/settings.lua +++ b/src/plugins/lua/settings.lua @@ -25,6 +25,7 @@ local settings = { [2] = {}, [3] = {} } +local settings_ids = {} local settings_initialized = false local max_pri = 0 local rspamd_logger = require "rspamd_logger" @@ -73,6 +74,16 @@ local function check_query_settings(task) end end + local settings_id = task:get_request_header('settings-id') + if settings_id and settings_initialized then + local elt = settings_ids[settings_id] + if elt and elt['apply'] then + task:set_settings(elt['apply']) + + return true + end + end + return false end @@ -398,6 +409,11 @@ local function process_settings_table(tbl) -- Now we must process actions if elt['symbols'] then out['symbols'] = elt['symbols'] end + if elt['id'] then + out['id'] = elt['id'] + settings[elt['id']] = out + end + if elt['apply'] then -- Just insert all metric results to the action key out['apply'] = elt['apply'] @@ -424,6 +440,7 @@ local function process_settings_table(tbl) -- clear all settings max_pri = 0 local nrules = 0 + settings_ids = {} for k,v in pairs(settings) do settings[k]={} end -- fill new settings by priority for_each(function(k, v) -- 2.39.5