@@ -200,19 +200,16 @@ end | |||
exports.spairs = spairs | |||
local function disable_module(modname, how) | |||
for i,mn in ipairs(rspamd_plugins_state.enabled) do | |||
if modname == mn then | |||
table.remove(rspamd_plugins_state.enabled, i) | |||
break | |||
end | |||
if rspamd_plugins_state.enabled[modname] then | |||
rspamd_plugins_state.enabled[modname] = nil | |||
end | |||
if how == 'redis' then | |||
table.insert(rspamd_plugins_state.disabled_redis, modname) | |||
rspamd_plugins_state.disabled_redis[modname] = {} | |||
elseif how == 'config' then | |||
table.insert(rspamd_plugins_state.disabled_unconfigured, modname) | |||
rspamd_plugins_state.disabled_unconfigured[modname] = {} | |||
else | |||
table.insert(rspamd_plugins_state.disabled_failed, modname) | |||
rspamd_plugins_state.disabled_failed[modname] = {} | |||
end | |||
end | |||
@@ -20,6 +20,8 @@ local rspamd_util = require "rspamd_util" | |||
local rspamd_logger = require "rspamd_logger" | |||
local lua_util = require "lua_util" | |||
local plugins_stat = require "rspamadm/plugins_stats" | |||
local function printf(fmt, ...) | |||
print(string.format(fmt, ...)) | |||
end | |||
@@ -196,6 +198,7 @@ return function(args, cfg) | |||
printf("Welcome to %s configuration tool", highlight("Rspamd")) | |||
printf("We use %s configuration file, writing results to %s", | |||
highlight(cfg.config_path), highlight(local_conf)) | |||
plugins_stat(nil, nil) | |||
if ask_yes_no("Do you wish to continue?", true) then | |||
local controller = find_worker(cfg, 'controller') |
@@ -1383,12 +1383,11 @@ rspamd_init_filters (struct rspamd_config *cfg, bool reconfig) | |||
while (cur) { | |||
/* Perform modules configuring */ | |||
mod_ctx = NULL; | |||
mod_ctx = g_hash_table_lookup (cfg->c_modules, cur->data); | |||
if (mod_ctx) { | |||
mod = mod_ctx->mod; | |||
mod_ctx->enabled = TRUE; | |||
mod_ctx->enabled = rspamd_config_is_module_enabled (cfg, mod->name); | |||
if (reconfig) { | |||
(void)mod->module_reconfig_func (cfg); | |||
@@ -1530,9 +1529,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, | |||
if (g_hash_table_lookup (cfg->explicit_modules, module_name) != NULL) { | |||
/* Always load module */ | |||
rspamd_table_push_global_elt (L, | |||
rspamd_modules_state_global, | |||
"enabled", module_name); | |||
rspamd_plugins_table_push_elt (L, "enabled", module_name); | |||
return TRUE; | |||
} | |||
@@ -1554,8 +1551,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, | |||
if (!found) { | |||
msg_info_config ("internal module %s is disable in `filters` line", | |||
module_name); | |||
rspamd_table_push_global_elt (L, | |||
rspamd_modules_state_global, | |||
rspamd_plugins_table_push_elt (L, | |||
"disabled_explicitly", module_name); | |||
return FALSE; | |||
@@ -1565,9 +1561,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, | |||
conf = ucl_object_lookup (cfg->rcl_obj, module_name); | |||
if (conf == NULL) { | |||
rspamd_table_push_global_elt (L, | |||
rspamd_modules_state_global, | |||
"disabled_unconfigured", module_name); | |||
rspamd_plugins_table_push_elt (L, "disabled_unconfigured", module_name); | |||
msg_info_config ("%s module %s is enabled but has not been configured", | |||
is_c ? "internal" : "lua", module_name); | |||
@@ -1582,8 +1576,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, | |||
if (enabled && ucl_object_type (enabled) == UCL_BOOLEAN) { | |||
if (!ucl_object_toboolean (enabled)) { | |||
rspamd_table_push_global_elt (L, | |||
rspamd_modules_state_global, | |||
rspamd_plugins_table_push_elt (L, | |||
"disabled_explicitly", module_name); | |||
msg_info_config ("%s module %s is disabled in the configuration", | |||
@@ -1598,8 +1591,7 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, | |||
if (gr) { | |||
if (gr->disabled) { | |||
rspamd_table_push_global_elt (L, | |||
rspamd_modules_state_global, | |||
rspamd_plugins_table_push_elt (L, | |||
"disabled_explicitly", module_name); | |||
msg_info_config ("%s module %s is disabled in the configuration as " | |||
"its group has been disabled", | |||
@@ -1609,6 +1601,8 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg, | |||
} | |||
} | |||
rspamd_plugins_table_push_elt (L, "enabled", module_name); | |||
return TRUE; | |||
} | |||
@@ -49,6 +49,8 @@ const luaL_reg worker_reg[] = { | |||
{NULL, NULL} | |||
}; | |||
static const char rspamd_modules_state_global[] = "rspamd_plugins_state"; | |||
static GQuark | |||
lua_error_quark (void) | |||
{ | |||
@@ -467,18 +469,17 @@ rspamd_free_lua_locked (struct lua_locked_state *st) | |||
g_free (st); | |||
} | |||
void | |||
rspamd_table_push_global_elt (lua_State *L, const gchar *global_name, | |||
const gchar *field_name, const gchar *new_elt) | |||
rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name, | |||
const gchar *new_elt) | |||
{ | |||
gsize last; | |||
lua_getglobal (L, global_name); | |||
lua_getglobal (L, rspamd_modules_state_global); | |||
lua_pushstring (L, field_name); | |||
lua_gettable (L, -2); | |||
last = lua_rawlen (L, -1); | |||
lua_pushstring (L, new_elt); | |||
lua_rawseti (L, -2, last + 1); | |||
lua_newtable (L); | |||
lua_settable (L, -3); | |||
lua_pop (L, 2); /* Global + element */ | |||
} | |||
@@ -513,8 +514,8 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) | |||
lua_tostring (L, -1)); | |||
lua_pop (L, 1); /* Error function */ | |||
rspamd_table_push_global_elt (L, rspamd_modules_state_global, | |||
"disabled_failed", module->name); | |||
rspamd_plugins_table_push_elt (L, "disabled_failed", | |||
module->name); | |||
cur = g_list_next (cur); | |||
continue; | |||
@@ -535,8 +536,8 @@ rspamd_init_lua_filters (struct rspamd_config *cfg, gboolean force_load) | |||
g_string_free (tb, TRUE); | |||
lua_pop (L, 2); /* Result and error function */ | |||
rspamd_table_push_global_elt (L, rspamd_modules_state_global, | |||
"disabled_failed", module->name); | |||
rspamd_plugins_table_push_elt (L, "disabled_failed", | |||
module->name); | |||
cur = g_list_next (cur); | |||
continue; |
@@ -48,7 +48,6 @@ luaL_register (lua_State *L, const gchar *name, const struct luaL_reg *methods) | |||
#define LUA_INTERFACE_DEF(class, name) { # name, lua_ ## class ## _ ## name } | |||
extern const luaL_reg null_reg[]; | |||
static const char rspamd_modules_state_global[] = "rspamd_plugins_state"; | |||
#define RSPAMD_LUA_API_VERSION 12 | |||
@@ -169,8 +168,8 @@ lua_State *rspamd_lua_init (void); | |||
* @param new_elt | |||
*/ | |||
void | |||
rspamd_table_push_global_elt (lua_State *L, const gchar *global_name, | |||
const gchar *field_name, const gchar *new_elt); | |||
rspamd_plugins_table_push_elt (lua_State *L, const gchar *field_name, | |||
const gchar *new_elt); | |||
/** | |||
* Load and initialize lua plugins | |||
*/ |