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
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
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')
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);
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;
}
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;
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);
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",
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",
}
}
+ rspamd_plugins_table_push_elt (L, "enabled", module_name);
+
return TRUE;
}
{NULL, NULL}
};
+static const char rspamd_modules_state_global[] = "rspamd_plugins_state";
+
static GQuark
lua_error_quark (void)
{
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 */
}
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;
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;
#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
* @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
*/