diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-07-01 11:53:29 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2020-07-01 11:53:29 +0100 |
commit | f860d55ac4b9b678b0a1419e88bf014d9bca72f5 (patch) | |
tree | a2b09051ab7f15835a632be08eb953d8a07c791c /rules/controller | |
parent | 80d82fd1bde27d3db317dcdd6d1dc8a25968e24e (diff) | |
download | rspamd-f860d55ac4b9b678b0a1419e88bf014d9bca72f5.tar.gz rspamd-f860d55ac4b9b678b0a1419e88bf014d9bca72f5.zip |
[Feature] Preliminary maps addon for controller
Diffstat (limited to 'rules/controller')
-rw-r--r-- | rules/controller/init.lua | 3 | ||||
-rw-r--r-- | rules/controller/maps.lua | 72 |
2 files changed, 74 insertions, 1 deletions
diff --git a/rules/controller/init.lua b/rules/controller/init.lua index 5057c08f5..e5204da63 100644 --- a/rules/controller/init.lua +++ b/rules/controller/init.lua @@ -25,7 +25,8 @@ local rspamd_logger = require "rspamd_logger" -- Define default controller paths, could be overridden in local.d/controller.lua local controller_plugin_paths = { - selectors = dofile(local_rules .. "/controller/selectors.lua") + selectors = dofile(local_rules .. "/controller/selectors.lua"), + maps = dofile(local_rules .. "/controller/maps.lua") } if rspamd_util.file_exists(local_conf .. '/controller.lua') then diff --git a/rules/controller/maps.lua b/rules/controller/maps.lua new file mode 100644 index 000000000..42d761172 --- /dev/null +++ b/rules/controller/maps.lua @@ -0,0 +1,72 @@ +--[[ +Copyright (c) 2020, Vsevolod Stakhov <vsevolod@highsecure.ru> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +]]-- + +-- Controller maps plugin +local maps_cache +local maps_aliases +local lua_util = require "lua_util" + +local function maybe_fill_maps_cache() + if not maps_cache then + maps_cache = {} + maps_aliases = {} + local maps = rspamd_config:get_maps() + for _,m in ipairs(maps) do + -- We get the first url here and that's it + local url = m:get_uri() + if url ~= 'static' then + if not maps_cache[url] then + local alias = url:match('/([^/]+)$') + maps_cache[url] = m + if not maps_aliases[alias] then + maps_aliases[alias] = url + end + else + -- Do not override, as we don't care about duplicate maps that come from different + -- sources. + -- In theory, that should be cached but there are some exceptions even so far... + end + end + end + end +end + +local function handle_query_map(_, conn, req_params) + maybe_fill_maps_cache() + if req_params.value and req_params.value ~= '' then + + conn:send_ucl({success = false and true}) + else + conn:send_error(404, 'missing value') + end +end + +local function handle_list_maps(_, conn, _) + maybe_fill_maps_cache() + conn:send_ucl({maps = lua_util.keys(maps_cache), + aliases = maps_aliases}) +end + +return { + query = { + handler = handle_query_map, + enable = false, + }, + list = { + handler = handle_list_maps, + enable = false, + }, +}
\ No newline at end of file |