]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add torch conditional to configuration
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 8 Mar 2018 12:34:38 +0000 (12:34 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 8 Mar 2018 12:34:38 +0000 (12:34 +0000)
conf/modules.d/neural.conf
src/libserver/cfg_utils.c

index f12224d48207a009bf72f5215f7aa3367f49664b..296ee2f2a55d786d909fa7c15f64208ec75904a8 100644 (file)
@@ -13,7 +13,7 @@
 #
 # See https://rspamd.com/doc/tutorials/writing_rules.html for details
 
-fann_redis {
+neural {
   #servers = 127.0.0.1:6379; # Redis server to store learning data and ANN
 
   train {
@@ -24,9 +24,15 @@ fann_redis {
   }
 
   timeout = 20; # Increase redis timeout
-  enabled = false; # Explicitly disable module
-  use_settings = false; # If enabled, then settings-id could switch this module to another FANN
+  enabled = ${HAS_TORCH}; # Explicitly disable module when torch is disabled
+  use_settings = false; # If enabled, then settings-id is used to dispatch networks
+
+  # Legacy support
   .include(try=true,priority=5) "${DBDIR}/dynamic/fann_redis.conf"
   .include(try=true,priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/fann_redis.conf"
   .include(try=true,priority=10) "$LOCAL_CONFDIR/override.d/fann_redis.conf"
+
+  .include(try=true,priority=5) "${DBDIR}/dynamic/neural.conf"
+  .include(try=true,priority=1,duplicate=merge) "$LOCAL_CONFDIR/local.d/neural.conf"
+  .include(try=true,priority=10) "$LOCAL_CONFDIR/override.d/neural.conf"
 }
\ No newline at end of file
index 5d0d94096aef06b9abd527b614362e2a1fdb2404..86009712e8ab15ff169a4bde4a0585abf2cd07de 100644 (file)
@@ -1118,6 +1118,14 @@ rspamd_ucl_add_conf_variables (struct ucl_parser *parser, GHashTable *vars)
        ucl_parser_register_variable (parser, RSPAMD_BRANCH_VERSION_MACRO,
                        RSPAMD_VERSION_BRANCH);
 
+#if defined(WITH_TORCH) && defined(WITH_LUAJIT) && defined(__x86_64__)
+       ucl_parser_register_variable (parser, "HAS_TORCH",
+                       "yes");
+#else
+       ucl_parser_register_variable (parser, "HAS_TORCH",
+                       "no");
+#endif
+
        if (vars != NULL) {
                g_hash_table_iter_init (&it, vars);
 
@@ -1619,14 +1627,42 @@ rspamd_config_is_module_enabled (struct rspamd_config *cfg,
        else {
                enabled = ucl_object_lookup (conf, "enabled");
 
-               if (enabled && ucl_object_type (enabled) == UCL_BOOLEAN) {
-                       if (!ucl_object_toboolean (enabled)) {
-                               rspamd_plugins_table_push_elt (L,
-                                               "disabled_explicitly", module_name);
+               if (enabled) {
+                       if (ucl_object_type (enabled) == UCL_BOOLEAN) {
+                               if (!ucl_object_toboolean (enabled)) {
+                                       rspamd_plugins_table_push_elt (L,
+                                                       "disabled_explicitly", module_name);
 
-                               msg_info_config ("%s module %s is disabled in the configuration",
-                                               is_c ? "internal" : "lua", module_name);
-                               return FALSE;
+                                       msg_info_config (
+                                                       "%s module %s is disabled in the configuration",
+                                                       is_c ? "internal" : "lua", module_name);
+                                       return FALSE;
+                               }
+                       }
+                       else if (ucl_object_type (enabled) == UCL_STRING) {
+                               gint ret;
+
+                               ret = rspamd_config_parse_flag (ucl_object_tostring (enabled), 0);
+
+                               if (ret == 0) {
+                                       rspamd_plugins_table_push_elt (L,
+                                                       "disabled_explicitly", module_name);
+
+                                       msg_info_config (
+                                                       "%s module %s is disabled in the configuration",
+                                                       is_c ? "internal" : "lua", module_name);
+                                       return FALSE;
+                               }
+                               else if (ret == -1) {
+                                       rspamd_plugins_table_push_elt (L,
+                                                       "disabled_failed", module_name);
+
+                                       msg_info_config (
+                                                       "%s module %s has wrong enabled flag (%s) in the configuration",
+                                                       is_c ? "internal" : "lua", module_name,
+                                                       ucl_object_tostring (enabled));
+                                       return FALSE;
+                               }
                        }
                }
        }