From 0c78ea6747f9edaca63d0e122dca1e3b53587ec6 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Mon, 19 Mar 2018 19:48:04 +0300 Subject: [PATCH] [Fix] Never hide actions from WebUI `configuration` tab - Never hide actions (fixes #1910) - Allow to disable actions from WebUI - Add `rewrite subject` action to `configuration` tab --- interface/js/app/config.js | 53 +++++++++++++++++--------------------- src/controller.c | 32 +++++++++++------------ 2 files changed, 39 insertions(+), 46 deletions(-) diff --git a/interface/js/app/config.js b/interface/js/app/config.js index 4346dee45a..894f080fd9 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -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($) { '' }); } - 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]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); -- 2.47.3