]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Never hide actions from WebUI `configuration` tab 2092/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Mon, 19 Mar 2018 16:48:04 +0000 (19:48 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Mon, 19 Mar 2018 16:48:04 +0000 (19:48 +0300)
- Never hide actions (fixes #1910)
- Allow to disable actions from WebUI
- Add `rewrite subject` action to `configuration` tab

interface/js/app/config.js
src/controller.c

index 4346dee45a4eb6a49a903a9605789b95e3bb9161..894f080fd96915056b262726a37c17fd13203063 100644 (file)
@@ -137,10 +137,11 @@ function($) {
     function loadActionsFromForm() {
         var values = [];
         var inputs = $('#actionsForm :input[data-id="action"]');
-        // Rspamd order: [spam,probable_spam,greylist]
-        values[0] = parseFloat(inputs[2].value);
-        values[1] = parseFloat(inputs[1].value);
-        values[2] = parseFloat(inputs[0].value);
+        // Rspamd order: [spam, rewrite_subject, probable_spam, greylist]
+        values[0] = parseFloat(inputs[3].value);
+        values[1] = parseFloat(inputs[2].value);
+        values[2] = parseFloat(inputs[1].value);
+        values[3] = parseFloat(inputs[0].value);
 
         return JSON.stringify(values);
     }
@@ -155,12 +156,10 @@ function($) {
                 xhr.setRequestHeader('Password', rspamd.getPassword());
             },
             success: function (data) {
-                // Order of sliders greylist -> probable spam -> spam
+                // Order of sliders greylist -> probable spam -> rewrite subject -> spam
                 $('#actionsBody').empty();
                 $('#actionsForm').empty();
                 var items = [];
-                var min = 0;
-                var max = Number.MIN_VALUE;
                 $.each(data, function (i, item) {
                     var idx = -1;
                     var label;
@@ -188,12 +187,6 @@ function($) {
                                 '</div>'
                         });
                     }
-                    if (item.value > max) {
-                        max = item.value * 2;
-                    }
-                    if (item.value < min) {
-                        min = item.value;
-                    }
                 });
 
                 items.sort(function (a, b) {
@@ -219,25 +212,27 @@ function($) {
                     var elts = loadActionsFromForm();
                     // String to array for comparison
                     var eltsArray = JSON.parse(loadActionsFromForm());
-                    if(eltsArray[0]<0){
-                        rspamd.alertMessage('alert-modal alert-error', 'Spam can not be negative');
-                    }
-                    else if(eltsArray[1]<0){
-                        rspamd.alertMessage('alert-modal alert-error', 'Probable spam can not be negative');
-                    }
-                    else if(eltsArray[2]<0){
-                        rspamd.alertMessage('alert-modal alert-error', 'Greylist can not be negative');
-                    }
-                    else if(eltsArray[2]<eltsArray[1] && eltsArray[1]<eltsArray[0]){
-                        callback('saveactions', null, null, "POST", {}, {
+                    if (eltsArray[0] < 0) {
+                        rspamd.alertMessage("alert-modal alert-error", "Spam can not be negative");
+                    } else if (eltsArray[1] < 0) {
+                        rspamd.alertMessage("alert-modal alert-error", "Rewrite subject can not be negative");
+                    } else if (eltsArray[2] < 0) {
+                        rspamd.alertMessage("alert-modal alert-error", "Probable spam can not be negative");
+                    } else if (eltsArray[3] < 0) {
+                        rspamd.alertMessage("alert-modal alert-error", "Greylist can not be negative");
+                    } else if (
+                        (eltsArray[2] === null || eltsArray[3] < eltsArray[2]) &&
+                        (eltsArray[1] === null || eltsArray[2] < eltsArray[1]) &&
+                        (eltsArray[0] === null || eltsArray[1] < eltsArray[0])
+                    ) {
+                        callback("saveactions", null, null, "POST", {}, {
                             data: elts,
-                            dataType: "json",
+                            dataType: "json"
                         });
+                    } else {
+                        rspamd.alertMessage("alert-modal alert-error", "Incorrect order of metric actions threshold");
                     }
-                    else {
-                        rspamd.alertMessage('alert-modal alert-error', 'Incorrect order of metric actions threshold');
-                    }
-                };
+                }
 
                 $('#saveActionsBtn').on('click', function() {
                     saveActions(rspamd.queryLocal);
index 09b446e8cb87b48f35a076b43580f4a5820b9ea9..1685f7eb021f05d63b0eca2b1597d6cf87dbef8f 100644 (file)
@@ -868,15 +868,13 @@ rspamd_controller_handle_actions (struct rspamd_http_connection_entry *conn_ent,
        /* Get actions for default metric */
        for (i = METRIC_ACTION_REJECT; i < METRIC_ACTION_MAX; i++) {
                act = &session->cfg->actions[i];
-               if (act->score >= 0) {
-                       obj = ucl_object_typed_new (UCL_OBJECT);
-                       ucl_object_insert_key (obj,
-                                       ucl_object_fromstring (rspamd_action_to_str (
-                                                       act->action)), "action", 0, false);
-                       ucl_object_insert_key (obj, ucl_object_fromdouble (
-                                       act->score), "value", 0, false);
-                       ucl_array_append (top, obj);
-               }
+               obj = ucl_object_typed_new (UCL_OBJECT);
+               ucl_object_insert_key (obj,
+                               ucl_object_fromstring (rspamd_action_to_str (
+                                               act->action)), "action", 0, false);
+               ucl_object_insert_key (obj, ucl_object_fromdouble (
+                               act->score), "value", 0, false);
+               ucl_array_append (top, obj);
        }
 
        rspamd_controller_send_ucl (conn_ent, top);
@@ -2159,8 +2157,8 @@ rspamd_controller_handle_saveactions (
        obj = ucl_parser_get_object (parser);
        ucl_parser_free (parser);
 
-       if (obj->type != UCL_ARRAY || obj->len != 3) {
-               msg_err_session ("input is not an array of 3 elements");
+       if (obj->type != UCL_ARRAY || obj->len != 4) {
+               msg_err_session ("input is not an array of 4 elements");
                rspamd_controller_send_error (conn_ent, 400, "Cannot parse input");
                ucl_object_unref (obj);
                return 0;
@@ -2168,19 +2166,20 @@ rspamd_controller_handle_saveactions (
 
        it = ucl_object_iterate_new (obj);
 
-       for (i = 0; i < 3; i++) {
+       for (i = 0; i < 4; i++) {
                cur = ucl_object_iterate_safe (it, TRUE);
-               if (cur == NULL) {
-                       break;
-               }
+
                switch (i) {
                case 0:
                        act = METRIC_ACTION_REJECT;
                        break;
                case 1:
-                       act = METRIC_ACTION_ADD_HEADER;
+                       act = METRIC_ACTION_REWRITE_SUBJECT;
                        break;
                case 2:
+                       act = METRIC_ACTION_ADD_HEADER;
+                       break;
+               case 3:
                        act = METRIC_ACTION_GREYLIST;
                        break;
                }
@@ -2193,7 +2192,6 @@ rspamd_controller_handle_saveactions (
                        score = ucl_object_todouble (cur);
                }
 
-
                if ((isnan (session->cfg->actions[act].score) != isnan (score)) ||
                                (session->cfg->actions[act].score != score)) {
                        add_dynamic_action (ctx->cfg, DEFAULT_METRIC, act, score);