aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-28 13:33:24 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-05-28 13:33:24 +0100
commitcaa85eb1ec3cae941795dea727e794625b9c8bf3 (patch)
tree66407baf24e1c773d4787dc2d2ec69e5fc5a60bb
parentf7d54ff789833242766d565c79ea2e0d174dde45 (diff)
downloadrspamd-caa85eb1ec3cae941795dea727e794625b9c8bf3.tar.gz
rspamd-caa85eb1ec3cae941795dea727e794625b9c8bf3.zip
[Feature] Use universal redis definitions in rspamd plugins
-rw-r--r--src/lua/global_functions.lua1
-rw-r--r--src/plugins/lua/dmarc.lua11
-rw-r--r--src/plugins/lua/greylist.lua15
-rw-r--r--src/plugins/lua/ip_score.lua21
-rw-r--r--src/plugins/lua/ratelimit.lua28
-rw-r--r--src/plugins/lua/replies.lua7
6 files changed, 30 insertions, 53 deletions
diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua
index 833832188..d2c742a9c 100644
--- a/src/lua/global_functions.lua
+++ b/src/lua/global_functions.lua
@@ -6,6 +6,7 @@ function rspamd_parse_redis_server(module_name)
local default_port = 6379
local logger = require "rspamd_logger"
+ local upstream_list = require "rspamd_upstream_list"
local function try_load_redis_servers(options)
local key = options['servers']
diff --git a/src/plugins/lua/dmarc.lua b/src/plugins/lua/dmarc.lua
index 924b02017..063142f24 100644
--- a/src/plugins/lua/dmarc.lua
+++ b/src/plugins/lua/dmarc.lua
@@ -35,7 +35,6 @@ local symbols = {
dkim_deny_symbol = 'R_DKIM_REJECT',
}
-- Default port for redis upstreams
-local default_port = 6379
local upstreams = nil
local dmarc_redis_key_prefix = "dmarc_"
local dmarc_domain = nil
@@ -272,13 +271,9 @@ if not opts or type(opts) ~= 'table' then
return
end
-if not opts['servers'] then
- rspamd_logger.infox(rspamd_config, 'no servers are specified for dmarc stats')
-else
- upstreams = upstream_list.create(rspamd_config, opts['servers'], default_port)
- if not upstreams then
- rspamd_logger.errx(rspamd_config, 'cannot parse servers parameter')
- end
+upstreams = rspamd_parse_redis_server('dmarc')
+if not upstreams then
+ rspamd_logger.errx(rspamd_config, 'cannot parse servers parameter')
end
if opts['key_prefix'] then
diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua
index 81d4604a0..ebb9a4586 100644
--- a/src/plugins/lua/greylist.lua
+++ b/src/plugins/lua/greylist.lua
@@ -16,8 +16,6 @@ limitations under the License.
-- A plugin that implements greylisting using redis
--- Default port for redis upstreams
-local default_port = 6379
local upstreams
local whitelisted_ip
local settings = {
@@ -295,16 +293,13 @@ if opts then
whitelisted_ip = rspamd_config:add_radix_map(opts['whitelisted_ip'],
'Greylist whitelist ip map')
end
- if not opts['servers'] then
+
+ upstreams = rspamd_parse_redis_server('greylist')
+ if not upstreams then
rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
else
- upstreams = upstream_list.create(rspamd_config, opts['servers'], default_port)
- if not upstreams then
- rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
- else
- rspamd_config:register_pre_filter(greylist_check)
- rspamd_config:register_post_filter(greylist_set, 10)
- end
+ rspamd_config:register_pre_filter(greylist_check)
+ rspamd_config:register_post_filter(greylist_set, 10)
end
for k,v in pairs(opts) do
diff --git a/src/plugins/lua/ip_score.lua b/src/plugins/lua/ip_score.lua
index 7d12f1a5e..bb34003cb 100644
--- a/src/plugins/lua/ip_score.lua
+++ b/src/plugins/lua/ip_score.lua
@@ -23,7 +23,6 @@ local rspamd_util = require "rspamd_util"
local _ = require "fun"
-- Default settings
-local default_port = 6379
local upstreams = nil
local whitelist = nil
local asn_cc_whitelist = nil
@@ -333,19 +332,17 @@ local configure_ip_score_module = function()
for k,v in pairs(opts) do
options[k] = v
end
- if options['servers'] and options['servers'] ~= '' then
- upstreams = upstream_list.create(rspamd_config, options['servers'], default_port)
- if not upstreams then
- rspamd_logger.infox(rspamd_config, 'no servers are specified')
- end
- end
- if options['whitelist'] then
- whitelist = rspamd_config:add_radix_map(opts['whitelist'])
- end
- if options['asn_cc_whitelist'] then
- asn_cc_whitelist = rspamd_config:add_hash_map(opts['asn_cc_whitelist'])
+ upstreams = rspamd_parse_redis_server('ip_score')
+ if not upstreams then
+ rspamd_logger.infox(rspamd_config, 'no servers are specified')
end
end
+ if options['whitelist'] then
+ whitelist = rspamd_config:add_radix_map(opts['whitelist'])
+ end
+ if options['asn_cc_whitelist'] then
+ asn_cc_whitelist = rspamd_config:add_hash_map(opts['asn_cc_whitelist'])
+ end
end
diff --git a/src/plugins/lua/ratelimit.lua b/src/plugins/lua/ratelimit.lua
index d8bbf0dfa..42ae569c6 100644
--- a/src/plugins/lua/ratelimit.lua
+++ b/src/plugins/lua/ratelimit.lua
@@ -16,8 +16,6 @@ limitations under the License.
-- A plugin that implements ratelimits using redis or kvstorage server
--- Default port for redis upstreams
-local default_port = 6379
-- Default settings for limits, 1-st member is burst, second is rate and the third is numeric type
local settings = {
-- Limit for all mail per recipient (burst 100, rate 2 per minute)
@@ -420,25 +418,21 @@ if opts then
max_rcpt = tonumber(opts['max_delay'])
end
- if not opts['servers'] then
+ upstreams = rspamd_parse_redis_server('ratelimit')
+ if not upstreams then
rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
else
- upstreams = upstream_list.create(rspamd_config, opts['servers'], default_port)
- if not upstreams then
- rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
+ if not ratelimit_symbol then
+ rspamd_config:register_pre_filter(rate_test)
else
- if not ratelimit_symbol then
- rspamd_config:register_pre_filter(rate_test)
- else
- rspamd_config:register_symbol({
- name = ratelimit_symbol,
- callback = rate_test,
- flags = 'empty'
- })
- end
-
- rspamd_config:register_post_filter(rate_set)
+ rspamd_config:register_symbol({
+ name = ratelimit_symbol,
+ callback = rate_test,
+ flags = 'empty'
+ })
end
+
+ rspamd_config:register_post_filter(rate_set)
end
end
diff --git a/src/plugins/lua/replies.lua b/src/plugins/lua/replies.lua
index 70228f0dc..98a48bb1f 100644
--- a/src/plugins/lua/replies.lua
+++ b/src/plugins/lua/replies.lua
@@ -18,7 +18,6 @@ limitations under the License.
-- A plugin that implements replies check using redis
-- Default port for redis upstreams
-local default_port = 6379
local upstreams
local whitelisted_ip
local settings = {
@@ -102,17 +101,13 @@ end
local opts = rspamd_config:get_all_opt('replies')
if opts then
- if not opts['servers'] then
- rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
- else
- upstreams = upstream_list.create(rspamd_config, opts['servers'], default_port)
+ upstreams = rspamd_parse_redis_server('replies')
if not upstreams then
rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
else
rspamd_config:register_pre_filter(replies_check)
rspamd_config:register_post_filter(replies_set, 10)
end
- end
for k,v in pairs(opts) do
settings[k] = v