--- /dev/null
+--[[
+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
if (!rspamd_parse_inet_address_ip (addr_str, len, addr->addr)) {
addr = NULL;
- msg_warn ("invalid ip address: %*s, when checking map: %s",
- (gint)len, addr_str, map->map->name);
}
}
else if (lua_type (L, 2) == LUA_TUSERDATA) {
{
LUA_TRACE_POINT;
struct rspamd_lua_map *map = lua_check_map (L, 1);
- const gchar *ret = "undefined";
struct rspamd_map_backend *bk;
- guint i;
+ guint i;
if (map != NULL) {
for (i = 0; i < map->map->backends->len; i ++) {
bk = g_ptr_array_index (map->map->backends, i);
- ret = bk->uri;
- lua_pushstring (L, ret);
+ lua_pushstring (L, bk->uri);
}
}
else {