]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Add concept of experimental modules
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 3 Mar 2018 12:47:33 +0000 (12:47 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 3 Mar 2018 12:47:33 +0000 (12:47 +0000)
lualib/lua_util.lua
lualib/rspamadm/plugins_stats.lua
src/libserver/cfg_file.h
src/libserver/cfg_rcl.c
src/lua/lua_common.c
src/lua/lua_config.c
src/plugins/lua/fann_classifier.lua
src/plugins/lua/url_reputation.lua
src/plugins/lua/url_tags.lua

index a7509665a7986a32f7b1c5165dca01351cf0b540..1f58953cea538663d5c73bb850cc59df30a0c1e8 100644 (file)
@@ -250,7 +250,7 @@ exports.spairs = spairs
 
 --[[[
 -- @function lua_util.disable_module(modname, how)
--- Disables a plugin or disables redis for a plugin.
+-- Disables a plugin or disables a plugin.
 -- @param {string} modname name of plugin to disable
 -- @param {string} how 'redis' to disable redis, 'config' to disable startup
 --]]
@@ -264,6 +264,8 @@ local function disable_module(modname, how)
     rspamd_plugins_state.disabled_redis[modname] = {}
   elseif how == 'config' then
     rspamd_plugins_state.disabled_unconfigured[modname] = {}
+  elseif how == 'experimental' then
+    rspamd_plugins_state.disabled_experimental[modname] = {}
   else
     rspamd_plugins_state.disabled_failed[modname] = {}
   end
@@ -271,6 +273,23 @@ end
 
 exports.disable_module = disable_module
 
+--[[[
+-- @function lua_util.disable_module(modname)
+-- Checks experimental plugins state and disable if needed
+-- @param {string} modname name of plugin to check
+-- @return {boolean} true if plugin should be enabled, false otherwise
+--]]
+local function check_experimental(modname)
+  if rspamd_config:experimental_enabled() then
+    return true
+  else
+    disable_module(modname, 'experimental')
+  end
+
+  return false
+end
+
+exports.check_experimental = check_experimental
 
 --[[[
 -- @function lua_util.parse_time_interval(str)
index de4aec2c8e20845c3c62300ff44016e0072c01c7..5c9797a9ef1a903c181c587ca8e3cc9a0fd07426 100644 (file)
@@ -36,11 +36,13 @@ end
 return function(args, _)
   print_plugins_table(rspamd_plugins_state.enabled, "enabled")
   print_plugins_table(rspamd_plugins_state.disabled_explicitly,
-    "disabled (explicitly)")
+      "disabled (explicitly)")
   print_plugins_table(rspamd_plugins_state.disabled_unconfigured,
-    "disabled (unconfigured)")
+      "disabled (unconfigured)")
   print_plugins_table(rspamd_plugins_state.disabled_redis,
-    "disabled (no Redis)")
+      "disabled (no Redis)")
+  print_plugins_table(rspamd_plugins_state.disabled_experimental,
+      "disabled (experimental)")
   print_plugins_table(rspamd_plugins_state.disabled_failed,
-    "disabled (failed)")
+      "disabled (failed)")
 end
\ No newline at end of file
index fa04564f856452ad9b3858b2bf4c5bcf8784cef8..199c965f4ba860f5ba309c70f0a6307ec296cb7d 100644 (file)
@@ -307,7 +307,8 @@ struct rspamd_config {
        gboolean vectorized_hyperscan;                  /**< use vectorized hyperscan matching                                  */
        gboolean enable_shutdown_workaround;            /**< enable workaround for legacy SA clients (exim)             */
        gboolean ignore_received;                       /**< Ignore data from the first received header                 */
-       gboolean enable_sessions_cache;                 /**< Enable session cache for debug */
+       gboolean enable_sessions_cache;                 /**< Enable session cache for debug                                             */
+       gboolean enable_experimental;                   /**< Enable experimental plugins                                                */
 
        gsize max_diff;                                 /**< maximum diff size for text parts                                   */
        gsize max_cores_size;                           /**< maximum size occupied by rspamd core files                 */
index dbc0fc5a411bc4b8e7cca47bdf511cda28685ee4..fd09302120ee10b37310d98f9982028dd858c2d3 100644 (file)
@@ -2005,6 +2005,12 @@ rspamd_rcl_config_init (struct rspamd_config *cfg)
                        G_STRUCT_OFFSET (struct rspamd_config, check_all_filters),
                        0,
                        "Always check all filters");
+       rspamd_rcl_add_default_handler (sub,
+                       "enable_experimental",
+                       rspamd_rcl_parse_struct_boolean,
+                       G_STRUCT_OFFSET (struct rspamd_config, check_all_filters),
+                       0,
+                       "Enable experimental plugins");
        rspamd_rcl_add_default_handler (sub,
                        "all_filters",
                        rspamd_rcl_parse_struct_boolean,
index 942f5a9b6690ed94f887cb0893a2a5b15f29ba80..f77fe6b6e5163d001ab11902a47d4008e1b52616 100644 (file)
@@ -423,6 +423,7 @@ rspamd_lua_init ()
         *   disabled_redis = {},
         *   disabled_explicitly = {},
         *   disabled_failed = {},
+        *   disabled_experimental = {},
         * }
         */
 #define ADD_TABLE(name) do { \
@@ -436,6 +437,7 @@ rspamd_lua_init ()
        ADD_TABLE (disabled_redis);
        ADD_TABLE (disabled_explicitly);
        ADD_TABLE (disabled_failed);
+       ADD_TABLE (disabled_experimental);
 
 #undef ADD_TABLE
        lua_setglobal (L, rspamd_modules_state_global);
index 935ee78066e3d6510107880069ab062b6a6d7702..5a6bac8bc1daffe343eb8f94a3afddca941f8040 100644 (file)
@@ -667,6 +667,13 @@ LUA_FUNCTION_DEF (config, get_cpu_flags);
  */
 LUA_FUNCTION_DEF (config, has_torch);
 
+/***
+ * @method rspamd_config:experimental_enabled()
+ * Returns true if experimental plugins are enabled
+ * @return {boolean} true if experimental plugins are enabled
+ */
+LUA_FUNCTION_DEF (config, experimental_enabled);
+
 static const struct luaL_reg configlib_m[] = {
        LUA_INTERFACE_DEF (config, get_module_opt),
        LUA_INTERFACE_DEF (config, get_mempool),
@@ -722,6 +729,7 @@ static const struct luaL_reg configlib_m[] = {
        LUA_INTERFACE_DEF (config, set_peak_cb),
        LUA_INTERFACE_DEF (config, get_cpu_flags),
        LUA_INTERFACE_DEF (config, has_torch),
+       LUA_INTERFACE_DEF (config, experimental_enabled),
        {"__tostring", rspamd_lua_class_tostring},
        {"__newindex", lua_config_newindex},
        {NULL, NULL}
@@ -2949,6 +2957,22 @@ lua_config_has_torch (lua_State *L)
        return 1;
 }
 
+static gint
+lua_config_experimental_enabled (lua_State *L)
+{
+       struct rspamd_config *cfg = lua_check_config (L, 1);
+
+       if (cfg != NULL) {
+               lua_pushboolean (L, cfg->enable_experimental);
+       }
+       else {
+               return luaL_error (L, "invalid arguments");
+       }
+
+       return 1;
+}
+
+
 static gint
 lua_monitored_alive (lua_State *L)
 {
index f4133eb9e700981041615cb73ded2a8804710908..f1e93ca2aec6da56978de423172ad830b9dcf835 100644 (file)
@@ -23,7 +23,9 @@ end
 local rspamd_logger = require "rspamd_logger"
 local rspamd_fann = require "rspamd_fann"
 local rspamd_util = require "rspamd_util"
+local lua_util = require "lua_util"
 local fun = require "fun"
+local N = 'fann_classifier'
 
 local redis_params
 local classifier_config = {
@@ -39,6 +41,10 @@ local current_classify_ann = {
   ham_learned = 0
 }
 
+if not lua_util.check_experimental(N) then
+  return
+end
+
 redis_params = rspamd_parse_redis_server('fann_classifier')
 
 local function maybe_load_fann(task, continue_cb, call_if_fail)
index 55f568e56d3ebb7b62e49685d767e71a5cce0187..c3856f3b66125ffb4706ab48fe096daf00e17d7a 100644 (file)
@@ -352,6 +352,10 @@ local function url_reputation_check(task)
   end
 end
 
+if not lua_util.check_experimental(N) then
+  return
+end
+
 local opts = rspamd_config:get_all_opt(N)
 if not opts then return end
 redis_params = rspamd_parse_redis_server(N)
index 1281cc2fc0c3be0d9b2b69c8af6409cffc0af0ac..e64aa926f31db50d3199c3744d5bfdbdbc588e84 100644 (file)
@@ -347,6 +347,10 @@ local function tags_restore(task)
   end
 end
 
+if not lua_util.check_experimental(N) then
+  return
+end
+
 local opts = rspamd_config:get_all_opt(N)
 if not opts then return end
 redis_params = rspamd_parse_redis_server(N)