From a1410d8d5e62886dd6a51784bd96c3d844b0d072 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 25 Dec 2019 20:52:14 +0000 Subject: [PATCH] [Minor] Add more redis prefixes --- src/plugins/lua/antivirus.lua | 9 ++++++++- src/plugins/lua/external_services.lua | 9 ++++++++- src/plugins/lua/greylist.lua | 8 ++++++++ src/plugins/lua/maps_stats.lua | 12 +++++++++++- src/plugins/lua/mx_check.lua | 12 ++++++++---- src/plugins/lua/p0f.lua | 5 +++++ src/plugins/lua/url_redirector.lua | 10 ++++++++++ 7 files changed, 58 insertions(+), 7 deletions(-) diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua index 34b0c6947..5d7268b06 100644 --- a/src/plugins/lua/antivirus.lua +++ b/src/plugins/lua/antivirus.lua @@ -16,6 +16,7 @@ limitations under the License. local rspamd_logger = require "rspamd_logger" local lua_util = require "lua_util" +local lua_redis = require "lua_redis" local fun = require "fun" local lua_antivirus = require("lua_scanners").filter('antivirus') local common = require "lua_scanners/common" @@ -119,6 +120,12 @@ local function add_antivirus_rule(sym, opts) rule.patterns = common.create_regex_table(opts.patterns or {}) rule.patterns_fail = common.create_regex_table(opts.patterns_fail or {}) + lua_redis.register_prefix(rule.prefix .. '_*', N, + string.format('Antivirus cache for rule "%s"', + rule.type), { + type = 'string', + }) + if opts.whitelist then rule.whitelist = rspamd_config:add_hash_map(opts.whitelist) end @@ -142,7 +149,7 @@ end -- Registration local opts = rspamd_config:get_all_opt(N) if opts and type(opts) == 'table' then - redis_params = rspamd_parse_redis_server(N) + redis_params = lua_redis.parse_redis_server(N) local has_valid = false for k, m in pairs(opts) do if type(m) == 'table' then diff --git a/src/plugins/lua/external_services.lua b/src/plugins/lua/external_services.lua index 0a9f39ad9..8e29accbe 100644 --- a/src/plugins/lua/external_services.lua +++ b/src/plugins/lua/external_services.lua @@ -17,6 +17,7 @@ limitations under the License. local rspamd_logger = require "rspamd_logger" local lua_util = require "lua_util" +local lua_redis = require "lua_redis" local fun = require "fun" local lua_scanners = require("lua_scanners").filter('scanner') local common = require "lua_scanners/common" @@ -142,6 +143,12 @@ local function add_scanner_rule(sym, opts) rule.redis_params = redis_params + lua_redis.register_prefix(rule.prefix .. '_*', N, + string.format('External services cache for rule "%s"', + rule.type), { + type = 'string', + }) + -- if any mime_part filter defined, do not scan all attachments if opts.mime_parts_filter_regex ~= nil or opts.mime_parts_filter_ext ~= nil then @@ -185,7 +192,7 @@ end -- Registration local opts = rspamd_config:get_all_opt(N) if opts and type(opts) == 'table' then - redis_params = rspamd_parse_redis_server(N) + redis_params = lua_redis.parse_redis_server(N) local has_valid = false for k, m in pairs(opts) do if type(m) == 'table' and m.servers then diff --git a/src/plugins/lua/greylist.lua b/src/plugins/lua/greylist.lua index 3c6335ea1..671b2be69 100644 --- a/src/plugins/lua/greylist.lua +++ b/src/plugins/lua/greylist.lua @@ -464,6 +464,14 @@ if opts then rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module') rspamd_lua_utils.disable_module(N, "redis") else + lua_redis.register_prefix(settings.key_prefix .. 'b[a-z0-9]{20}', N, + 'Greylisting elements (body hashes)"', { + type = 'string', + }) + lua_redis.register_prefix(settings.key_prefix .. 'm[a-z0-9]{20}', N, + 'Greylisting elements (meta hashes)"', { + type = 'string', + }) rspamd_config:register_symbol({ name = 'GREYLIST_SAVE', type = 'postfilter', diff --git a/src/plugins/lua/maps_stats.lua b/src/plugins/lua/maps_stats.lua index 725629a77..46a769f34 100644 --- a/src/plugins/lua/maps_stats.lua +++ b/src/plugins/lua/maps_stats.lua @@ -105,7 +105,17 @@ if opts then end redis_params = lua_redis.parse_redis_server(N, opts) - +-- XXX, this is a poor approach as not all maps are defined here... +local tmaps = rspamd_config:get_maps() +for _,m in ipairs(tmaps) do + if m:get_uri() ~= 'static' then + lua_redis.register_prefix(settings.prefix .. m:get_uri(), N, + 'Maps stats data', { + type = 'zlist', + persistent = true, + }) + end +end if redis_params then rspamd_config:add_on_load(function (_, ev_base, worker) diff --git a/src/plugins/lua/mx_check.lua b/src/plugins/lua/mx_check.lua index 61d1cd1b8..d67524c21 100644 --- a/src/plugins/lua/mx_check.lua +++ b/src/plugins/lua/mx_check.lua @@ -23,6 +23,7 @@ local rspamd_logger = require "rspamd_logger" local rspamd_tcp = require "rspamd_tcp" local rspamd_util = require "rspamd_util" local lua_util = require "lua_util" +local lua_redis = require "lua_redis" local N = "mx_check" local fun = require "fun" @@ -267,15 +268,18 @@ if not (opts and type(opts) == 'table') then return end if opts then - redis_params = rspamd_parse_redis_server('mx_check') + redis_params = lua_redis.parse_redis_server('mx_check') if not redis_params then rspamd_logger.errx(rspamd_config, 'no redis servers are specified, disabling module') lua_util.disable_module(N, "redis") return end - for k,v in pairs(opts) do - settings[k] = v - end + + settings = lua_util.override_defaults(settings, opts) + lua_redis.register_prefix(settings.key_prefix .. '*', N, + 'MX check cache', { + type = 'string', + }) local id = rspamd_config:register_symbol({ name = settings.symbol_bad_mx, diff --git a/src/plugins/lua/p0f.lua b/src/plugins/lua/p0f.lua index f7fed7886..3242e73b0 100644 --- a/src/plugins/lua/p0f.lua +++ b/src/plugins/lua/p0f.lua @@ -78,6 +78,11 @@ rule = p0f.configure(opts) if rule then rule.redis_params = lua_redis.parse_redis_server(N) + lua_redis.register_prefix(rule.prefix .. '*', N, + 'P0f check cache', { + type = 'string', + }) + local id = rspamd_config:register_symbol({ name = 'P0F_CHECK', type = 'prefilter,nostat', diff --git a/src/plugins/lua/url_redirector.lua b/src/plugins/lua/url_redirector.lua index 4952dc25f..ba7d77649 100644 --- a/src/plugins/lua/url_redirector.lua +++ b/src/plugins/lua/url_redirector.lua @@ -343,6 +343,16 @@ if opts then settings.redirector_hosts_map = lua_maps.map_add_from_ucl(settings.redirector_hosts_map, 'set', 'Redirectors definitions') + lua_redis.register_prefix(settings.key_prefix .. '[a-z0-9]{32}', N, + 'URL redirector hashes', { + type = 'string', + }) + if settings.top_urls_key then + lua_redis.register_prefix(settings.top_urls_key, N, + 'URL redirector top urls', { + type = 'zlist', + }) + end local id = rspamd_config:register_symbol{ name = 'URL_REDIRECTOR_CHECK', type = 'callback,prefilter', -- 2.39.5