]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix resetting symbols to their default values in WebUI
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Mar 2016 10:54:51 +0000 (10:54 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 18 Mar 2016 10:54:51 +0000 (10:54 +0000)
src/controller.c
src/libserver/dynamic_cfg.c
src/libserver/dynamic_cfg.h

index 1c26a802a5cc907d9bfb80429470a85ef6f74964..f5a624b7c889a5b887a6979f61bd8cd8a85ceb67 100644 (file)
@@ -1612,6 +1612,11 @@ rspamd_controller_handle_saveactions (
                        add_dynamic_action (ctx->cfg, DEFAULT_METRIC, act, score);
                        added ++;
                }
+               else {
+                       if (remove_dynamic_action (ctx->cfg, DEFAULT_METRIC, act)) {
+                               added ++;
+                       }
+               }
        }
 
        if (dump_dynamic_config (ctx->cfg)) {
@@ -1729,6 +1734,12 @@ rspamd_controller_handle_savesymbols (
                        }
                        added ++;
                }
+               else if (sym) {
+                       if (remove_dynamic_symbol (ctx->cfg, DEFAULT_METRIC,
+                                       ucl_object_tostring (jname))) {
+                               added ++;
+                       }
+               }
        }
 
        if (added > 0) {
index 48ce0725af68578a125cceeaa923a948c527cea8..8845032f539765dfdc77ac23172b8dfbc3252676 100644 (file)
@@ -439,6 +439,47 @@ add_dynamic_symbol (struct rspamd_config *cfg,
        return TRUE;
 }
 
+gboolean
+remove_dynamic_symbol (struct rspamd_config *cfg,
+       const gchar *metric_name,
+       const gchar *symbol)
+{
+       ucl_object_t *metric, *syms;
+       gboolean ret = FALSE;
+
+       if (cfg->dynamic_conf == NULL) {
+               msg_info ("dynamic conf is disabled");
+               return FALSE;
+       }
+
+       metric = dynamic_metric_find_metric (cfg->current_dynamic_conf,
+                       metric_name);
+       if (metric == NULL) {
+               return FALSE;
+       }
+
+       syms = (ucl_object_t *)ucl_object_lookup (metric, "symbols");
+       if (syms != NULL) {
+               ucl_object_t *sym;
+
+               sym = dynamic_metric_find_elt (syms, symbol);
+
+               if (sym) {
+                       ret = ucl_array_delete ((ucl_object_t *)syms, sym) != NULL;
+
+                       if (ret) {
+                               ucl_object_unref (sym);
+                       }
+               }
+       }
+
+       if (ret) {
+               apply_dynamic_conf (cfg->current_dynamic_conf, cfg);
+       }
+
+       return TRUE;
+}
+
 
 /**
  * Add action for specified metric
@@ -485,3 +526,45 @@ add_dynamic_action (struct rspamd_config *cfg,
 
        return TRUE;
 }
+
+gboolean
+remove_dynamic_action (struct rspamd_config *cfg,
+       const gchar *metric_name,
+       guint action)
+{
+       ucl_object_t *metric, *acts;
+       const gchar *action_name = rspamd_action_to_str (action);
+       gboolean ret = FALSE;
+
+       if (cfg->dynamic_conf == NULL) {
+               msg_info ("dynamic conf is disabled");
+               return FALSE;
+       }
+
+       metric = dynamic_metric_find_metric (cfg->current_dynamic_conf,
+                       metric_name);
+       if (metric == NULL) {
+               return FALSE;
+       }
+
+       acts = (ucl_object_t *)ucl_object_lookup (metric, "actions");
+
+       if (acts != NULL) {
+               ucl_object_t *act;
+
+               act = dynamic_metric_find_elt (acts, action_name);
+
+               if (act) {
+                       ret = ucl_array_delete (acts, act) != NULL;
+               }
+               if (ret) {
+                       ucl_object_unref (act);
+               }
+       }
+
+       if (ret) {
+               apply_dynamic_conf (cfg->current_dynamic_conf, cfg);
+       }
+
+       return ret;
+}
index f3c6068519830d2bf374c0dea2953205f409aa2c..ebbc8b650f660191051440a746e6b7b98d303ca7 100644 (file)
@@ -45,6 +45,9 @@ gboolean add_dynamic_symbol (struct rspamd_config *cfg,
        const gchar *symbol,
        gdouble value);
 
+gboolean remove_dynamic_symbol (struct rspamd_config *cfg,
+       const gchar *metric,
+       const gchar *symbol);
 
 /**
  * Add action for specified metric
@@ -59,5 +62,11 @@ gboolean add_dynamic_action (struct rspamd_config *cfg,
        guint action,
        gdouble value);
 
+/**
+ * Removes dynamic action
+ */
+gboolean remove_dynamic_action (struct rspamd_config *cfg,
+               const gchar *metric,
+               guint action);
 
 #endif /* DYNAMIC_CFG_H_ */