diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-03-19 19:48:04 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-03-19 19:48:04 +0300 |
commit | 0c78ea6747f9edaca63d0e122dca1e3b53587ec6 (patch) | |
tree | 2c6f1d0c224da08655965b0590a8e27180f0f6ec | |
parent | bef67cce03e24465a7f7ea1ed2689727fd83a859 (diff) | |
download | rspamd-0c78ea6747f9edaca63d0e122dca1e3b53587ec6.tar.gz rspamd-0c78ea6747f9edaca63d0e122dca1e3b53587ec6.zip |
[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
-rw-r--r-- | interface/js/app/config.js | 53 | ||||
-rw-r--r-- | 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 4346dee45..894f080fd 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($) { '</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); diff --git a/src/controller.c b/src/controller.c index 09b446e8c..1685f7eb0 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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); |