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);
}
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;
'</div>'
});
}
- if (item.value > max) {
- max = item.value * 2;
- }
- if (item.value < min) {
- min = item.value;
- }
});
items.sort(function (a, b) {
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);
/* 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);
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;
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;
}
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);