aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-26 12:19:02 +0200
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-10-26 12:19:22 +0200
commit9d14da102659f864a908d9aabc52d31fe12c8e9d (patch)
tree409de050eb344d78d9782b1d30610096fde4c5cb
parentb2cfa63b1fc61c666ee2539f070ac99c0961fcee (diff)
downloadrspamd-9d14da102659f864a908d9aabc52d31fe12c8e9d.tar.gz
rspamd-9d14da102659f864a908d9aabc52d31fe12c8e9d.zip
[Fix] Fix various errors in lua dynamic conf plugin
-rw-r--r--src/plugins/lua/dynamic_conf.lua35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/plugins/lua/dynamic_conf.lua b/src/plugins/lua/dynamic_conf.lua
index 34bce40df..ab7812c86 100644
--- a/src/plugins/lua/dynamic_conf.lua
+++ b/src/plugins/lua/dynamic_conf.lua
@@ -85,15 +85,15 @@ end
local function apply_dynamic_actions(cfg, acts)
each(function(k, v)
- if type[v] == 'table' then
- v['action'] = k
+ if type(v) == 'table' then
+ v['name'] = k
if not v['priority'] then
v['priority'] = settings.priority
end
rspamd_config:set_metric_action(v)
else
rspamd_config:set_metric_symbol({
- action = k,
+ name = k,
score = v,
priority = settings.priority
})
@@ -110,7 +110,7 @@ end
local function apply_dynamic_scores(cfg, sc)
each(function(k, v)
- if type[v] == 'table' then
+ if type(v) == 'table' then
v['name'] = k
if not v['priority'] then
v['priority'] = settings.priority
@@ -219,13 +219,13 @@ local function check_dynamic_conf(cfg, ev_base)
if err then
rspamd_logger.errx(cfg, "cannot load dynamic conf from redis: %s", err)
else
- apply_dynamic_conf(cfg, res)
- cur_settings.version = rversion
+ local d = parser:get_object()
+ apply_dynamic_conf(cfg, d)
if cur_settings.updates.has_updates then
-- Need to send our updates to Redis
- update_dynamic_conf(cfg, ev_base, res)
+ update_dynamic_conf(cfg, ev_base, d)
else
- cur_settings.data = res
+ cur_settings.data = d
end
end
end
@@ -234,15 +234,19 @@ local function check_dynamic_conf(cfg, ev_base)
if not err and type(data) == 'string' then
local rver = tonumber(data)
- if rver and rver > cur_settings.version then
+ if not cur_settings.version or (rver and rver > cur_settings.version) then
rspamd_logger.infox(cfg, "need to load fresh dynamic settings with version %s, local version is %s",
rver, cur_settings.version)
+ cur_settings.version = rver
redis_make_request(ev_base, cfg, settings.redis_key, false,
redis_load_cb, 'HGET', {settings.redis_key, 'd'})
elseif cur_settings.updates.has_updates then
-- Need to send our updates to Redis
update_dynamic_conf(cfg, ev_base)
end
+ elseif cur_settings.updates.has_updates then
+ -- Need to send our updates to Redis
+ update_dynamic_conf(cfg, ev_base)
end
end
@@ -305,10 +309,11 @@ end
local function add_dynamic_action(cfg, act, score)
local add = false
if not cur_settings.data then
- rspamd_logger.errx(cfg, 'cannot add action as no dynamic conf is loaded')
+ cur_settings.data = {}
+ cur_settings.version = 0
end
- if not cur_settings.data.scores then
+ if not cur_settings.data.actions then
cur_settings.data.actions = {}
cur_settings.data.actions[act] = score
add = true
@@ -334,11 +339,7 @@ end
if redis_params then
rspamd_plugins["dynamic_conf"] = {
- add_symbol = function(cfg, sym, score)
- return add_dynamic_symbol(cfg, sym, score)
- end,
- add_action = function(cfg, act, score)
- return add_dynamic_action(cfg, act, score)
- end,
+ add_symbol = add_dynamic_symbol,
+ add_action = add_dynamic_action,
}
end