aboutsummaryrefslogtreecommitdiffstats
path: root/interface/js
diff options
context:
space:
mode:
authormoisseev <moiseev@mezonplus.ru>2023-11-17 13:02:41 +0300
committermoisseev <moiseev@mezonplus.ru>2023-11-17 13:02:41 +0300
commit2bed972703dfe52206eb06e8583eb39b38596cc4 (patch)
tree78ac0be55f2f4fc9dfa59ced581d77d725e308b7 /interface/js
parent66620b534846573efd0222e3d6980b54b5259c20 (diff)
downloadrspamd-2bed972703dfe52206eb06e8583eb39b38596cc4.tar.gz
rspamd-2bed972703dfe52206eb06e8583eb39b38596cc4.zip
[Minor] Get rid of 'var' declarations
Diffstat (limited to 'interface/js')
-rw-r--r--interface/js/app/config.js42
-rw-r--r--interface/js/app/graph.js38
-rw-r--r--interface/js/app/history.js36
-rw-r--r--interface/js/app/rspamd.js110
-rw-r--r--interface/js/app/selectors.js20
-rw-r--r--interface/js/app/stats.js66
-rw-r--r--interface/js/app/symbols.js48
-rw-r--r--interface/js/app/upload.js24
8 files changed, 192 insertions, 192 deletions
diff --git a/interface/js/app/config.js b/interface/js/app/config.js
index dd47578ae..d62298693 100644
--- a/interface/js/app/config.js
+++ b/interface/js/app/config.js
@@ -27,16 +27,16 @@
define(["jquery", "app/rspamd"],
function ($, rspamd) {
"use strict";
- var ui = {};
+ const ui = {};
ui.getActions = function getActions(checked_server) {
rspamd.query("actions", {
success: function (data) {
$("#actionsFormField").empty();
- var items = [];
+ const items = [];
$.each(data[0].data, function (i, item) {
- var actionsOrder = ["greylist", "add header", "rewrite subject", "reject"];
- var idx = actionsOrder.indexOf(item.action);
+ const actionsOrder = ["greylist", "add header", "rewrite subject", "reject"];
+ const idx = actionsOrder.indexOf(item.action);
if (idx >= 0) {
items.push({
idx: idx,
@@ -67,11 +67,11 @@ define(["jquery", "app/rspamd"],
ui.saveActions = function (server) {
function descending(arr) {
- var desc = true;
- var filtered = arr.filter(function (el) {
+ let desc = true;
+ const filtered = arr.filter(function (el) {
return el !== null;
});
- for (var i = 0; i < filtered.length - 1; i++) {
+ for (let i = 0; i < filtered.length - 1; i++) {
if (filtered[i + 1] >= filtered[i]) {
desc = false;
break;
@@ -80,9 +80,9 @@ define(["jquery", "app/rspamd"],
return desc;
}
- var elts = (function () {
- var values = [];
- var inputs = $("#actionsForm :input[data-id=\"action\"]");
+ const elts = (function () {
+ const values = [];
+ const inputs = $("#actionsForm :input[data-id=\"action\"]");
// Rspamd order: [spam, rewrite_subject, probable_spam, greylist]
values[0] = parseFloat(inputs[3].value);
values[1] = parseFloat(inputs[2].value);
@@ -92,7 +92,7 @@ define(["jquery", "app/rspamd"],
return JSON.stringify(values);
}());
// String to array for comparison
- var eltsArray = JSON.parse(elts);
+ const eltsArray = JSON.parse(elts);
if (eltsArray[0] < 0) {
rspamd.alertMessage("alert-modal alert-error", "Spam can not be negative");
} else if (eltsArray[1] < 0) {
@@ -116,23 +116,23 @@ define(["jquery", "app/rspamd"],
};
ui.getMaps = function (checked_server) {
- var $listmaps = $("#listMaps");
+ const $listmaps = $("#listMaps");
$listmaps.closest(".card").hide();
rspamd.query("maps", {
success: function (json) {
- var data = json[0].data;
+ const data = json[0].data;
$listmaps.empty();
$("#modalBody").empty();
- var $tbody = $("<tbody>");
+ const $tbody = $("<tbody>");
$.each(data, function (i, item) {
- var $td = '<td><span class="badge text-bg-secondary">Read</span></td>';
+ let $td = '<td><span class="badge text-bg-secondary">Read</span></td>';
if (!(item.editable === false || rspamd.read_only)) {
$td = $($td).append('&nbsp;<span class="badge text-bg-success">Write</span>');
}
- var $tr = $("<tr>").append($td);
+ const $tr = $("<tr>").append($td);
- var $span = $('<span class="map-link" data-bs-toggle="modal" data-bs-target="#modalDialog">' + item.uri + "</span>").data("item", item);
+ const $span = $('<span class="map-link" data-bs-toggle="modal" data-bs-target="#modalDialog">' + item.uri + "</span>").data("item", item);
$span.wrap("<td>").parent().appendTo($tr);
$("<td>" + item.description + "</td>").appendTo($tr);
$tr.appendTo($tbody);
@@ -145,7 +145,7 @@ define(["jquery", "app/rspamd"],
};
- var jar = {};
+ let jar = {};
const editor = {
advanced: {
codejar: true,
@@ -163,8 +163,8 @@ define(["jquery", "app/rspamd"],
// Modal form for maps
$(document).on("click", "[data-bs-toggle=\"modal\"]", function () {
- var checked_server = rspamd.getSelector("selSrv");
- var item = $(this).data("item");
+ const checked_server = rspamd.getSelector("selSrv");
+ const item = $(this).data("item");
rspamd.query("getmap", {
headers: {
Map: item.map
@@ -188,7 +188,7 @@ define(["jquery", "app/rspamd"],
document.querySelector("#editor").innerHTML = rspamd.escapeHTML(data[0].data);
}
- var icon = "fa-edit";
+ let icon = "fa-edit";
if (item.editable === false || rspamd.read_only) {
$("#editor").attr(editor[mode].readonly_attr);
icon = "fa-eye";
diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js
index 3dca7da9c..b7276f1c1 100644
--- a/interface/js/app/graph.js
+++ b/interface/js/app/graph.js
@@ -29,7 +29,7 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
function ($, rspamd, D3Evolution, D3Pie, d3) {
"use strict";
- var rrd_pie_config = {
+ const rrd_pie_config = {
cornerRadius: 2,
size: {
canvasWidth: 400,
@@ -56,11 +56,11 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
},
};
- var ui = {};
- var prevUnit = "msg/s";
+ const ui = {};
+ let prevUnit = "msg/s";
ui.draw = function (graphs, neighbours, checked_server, type) {
- var graph_options = {
+ const graph_options = {
title: "Rspamd throughput",
width: 1060,
height: 370,
@@ -73,7 +73,7 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
};
function initGraph() {
- var graph = new D3Evolution("graph", $.extend({}, graph_options, {
+ const graph = new D3Evolution("graph", $.extend({}, graph_options, {
yScale: rspamd.getSelector("selYScale"),
type: rspamd.getSelector("selType"),
interpolate: rspamd.getSelector("selInterpolate"),
@@ -96,16 +96,16 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
}
function getRrdSummary(json, scaleFactor) {
- var xExtents = d3.extent(d3.merge(json), function (d) { return d.x; });
- var timeInterval = xExtents[1] - xExtents[0];
+ const xExtents = d3.extent(d3.merge(json), function (d) { return d.x; });
+ const timeInterval = xExtents[1] - xExtents[0];
- var total = 0;
- var rows = json.map(function (curr, i) {
+ let total = 0;
+ const rows = json.map(function (curr, i) {
// Time intervals that don't have data are excluded from average calculation as d3.mean()ignores nulls
- var avg = d3.mean(curr, function (d) { return d.y; });
+ const avg = d3.mean(curr, function (d) { return d.y; });
// To find an integral on the whole time interval we need to convert nulls to zeroes
- var value = d3.mean(curr, function (d) { return Number(d.y); }) * timeInterval / scaleFactor ^ 0; // eslint-disable-line no-bitwise
- var yExtents = d3.extent(curr, function (d) { return d.y; });
+ const value = d3.mean(curr, function (d) { return Number(d.y); }) * timeInterval / scaleFactor ^ 0; // eslint-disable-line no-bitwise
+ const yExtents = d3.extent(curr, function (d) { return d.y; });
total += value;
return {
@@ -162,13 +162,13 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
}
function updateWidgets(data) {
- var rrd_summary = {rows:[]};
- var unit = "msg/s";
+ let rrd_summary = {rows:[]};
+ let unit = "msg/s";
if (data) {
// Autoranging
- var scaleFactor = 1;
- var yMax = d3.max(d3.merge(data), function (d) { return d.y; });
+ let scaleFactor = 1;
+ const yMax = d3.max(d3.merge(data), function (d) { return d.y; });
if (yMax < 1) {
scaleFactor = 60;
unit = "msg/min";
@@ -202,15 +202,15 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"],
rspamd.query("graph", {
success: function (req_data) {
- var data = null;
- var neighbours_data = req_data
+ let data = null;
+ const neighbours_data = req_data
.filter(function (d) { return d.status; }) // filter out unavailable neighbours
.map(function (d) { return d.data; });
if (neighbours_data.length === 1) {
data = neighbours_data[0];
} else {
- var time_match = true;
+ let time_match = true;
neighbours_data.reduce(function (res, curr, _, arr) {
if ((curr[0][0].x !== res[0][0].x) ||
(curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
diff --git a/interface/js/app/history.js b/interface/js/app/history.js
index 4118bc61d..30fa06700 100644
--- a/interface/js/app/history.js
+++ b/interface/js/app/history.js
@@ -27,13 +27,13 @@
define(["jquery", "app/rspamd", "d3", "footable"],
function ($, rspamd, d3) {
"use strict";
- var ui = {};
- var prevVersion = null;
+ const ui = {};
+ let prevVersion = null;
function process_history_legacy(data) {
- var items = [];
+ const items = [];
- var compare = function (e1, e2) {
+ const compare = function (e1, e2) {
return e1.name.localeCompare(e2.name);
};
@@ -287,20 +287,20 @@ define(["jquery", "app/rspamd", "d3", "footable"],
}];
}
- var columns = {
+ const columns = {
2: columns_v2,
legacy: columns_legacy
};
function process_history_data(data) {
- var process_functions = {
+ const process_functions = {
2: rspamd.process_history_v2,
legacy: process_history_legacy
};
- var pf = process_functions.legacy;
+ let pf = process_functions.legacy;
if (data.version) {
- var strkey = data.version.toString();
+ const strkey = data.version.toString();
if (process_functions[strkey]) {
pf = process_functions[strkey];
}
@@ -310,10 +310,10 @@ define(["jquery", "app/rspamd", "d3", "footable"],
}
function get_history_columns(data) {
- var func = columns.legacy;
+ let func = columns.legacy;
if (data.version) {
- var strkey = data.version.toString();
+ const strkey = data.version.toString();
if (columns[strkey]) {
func = columns[strkey];
}
@@ -326,7 +326,7 @@ define(["jquery", "app/rspamd", "d3", "footable"],
rspamd.query("history", {
success: function (req_data) {
function differentVersions(neighbours_data) {
- var dv = neighbours_data.some(function (e) {
+ const dv = neighbours_data.some(function (e) {
return e.version !== neighbours_data[0].version;
});
if (dv) {
@@ -337,12 +337,12 @@ define(["jquery", "app/rspamd", "d3", "footable"],
return false;
}
- var neighbours_data = req_data
+ const neighbours_data = req_data
.filter(function (d) { return d.status; }) // filter out unavailable neighbours
.map(function (d) { return d.data; });
if (neighbours_data.length && !differentVersions(neighbours_data)) {
- var data = {};
- var version = neighbours_data[0].version;
+ let data = {};
+ const version = neighbours_data[0].version;
if (version) {
data.rows = [].concat.apply([], neighbours_data
.map(function (e) {
@@ -355,8 +355,8 @@ define(["jquery", "app/rspamd", "d3", "footable"],
data = [].concat.apply([], neighbours_data);
$("#legacy-history-badge").show();
}
- var o = process_history_data(data);
- var items = o.items;
+ const o = process_history_data(data);
+ const items = o.items;
rspamd.symbols.history = o.symbols;
if (Object.prototype.hasOwnProperty.call(rspamd.tables, "history") &&
@@ -418,14 +418,14 @@ define(["jquery", "app/rspamd", "d3", "footable"],
rspamd.query("errors", {
success: function (data) {
- var neighbours_data = data
+ const neighbours_data = data
.filter(function (d) {
return d.status;
}) // filter out unavailable neighbours
.map(function (d) {
return d.data;
});
- var rows = [].concat.apply([], neighbours_data);
+ const rows = [].concat.apply([], neighbours_data);
$.each(rows, function (i, item) {
item.ts = {
value: rspamd.unix_time_format(item.ts),
diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js
index faec47f7f..4ad806d76 100644
--- a/interface/js/app/rspamd.js
+++ b/interface/js/app/rspamd.js
@@ -29,7 +29,7 @@ define(["jquery", "nprogress", "stickytabs", "visibility",
"bootstrap", "fontawesome"],
function ($, NProgress) {
"use strict";
- var ui = {
+ const ui = {
chartLegend: [
{label: "reject", color: "#FF0000"},
{label: "soft reject", color: "#BF8040"},
@@ -52,14 +52,14 @@ function ($, NProgress) {
const defaultAjaxTimeout = 20000;
const ajaxTimeoutBox = ".popover #settings-popover #ajax-timeout";
- var graphs = {};
- var tables = {};
- var neighbours = []; // list of clusters
- var checked_server = "All SERVERS";
- var timer_id = [];
+ const graphs = {};
+ const tables = {};
+ let neighbours = []; // list of clusters
+ let checked_server = "All SERVERS";
+ const timer_id = [];
let pageSizeTimerId = null;
let pageSizeInvocationCounter = 0;
- var locale = (localStorage.getItem("selected_locale") === "custom") ? localStorage.getItem("custom_locale") : null;
+ let locale = (localStorage.getItem("selected_locale") === "custom") ? localStorage.getItem("custom_locale") : null;
NProgress.configure({
minimum: 0.01,
@@ -85,7 +85,7 @@ function ($, NProgress) {
}
function stopTimers() {
- for (var key in timer_id) {
+ for (const key in timer_id) {
if (!{}.hasOwnProperty.call(timer_id, key)) continue;
Visibility.stop(timer_id[key]);
}
@@ -110,14 +110,14 @@ function ($, NProgress) {
// Get selectors' current state
function getSelector(id) {
- var e = document.getElementById(id);
+ const e = document.getElementById(id);
return e.options[e.selectedIndex].value;
}
function tabClick(id) {
- var tab_id = id;
+ let tab_id = id;
if ($(id).attr("disabled")) return;
- var navBarControls = $("#selSrv, #navBar li, #navBar a, #navBar button");
+ let navBarControls = $("#selSrv, #navBar li, #navBar a, #navBar button");
if (id !== "#autoRefresh") navBarControls.attr("disabled", true).addClass("disabled", true);
stopTimers();
@@ -137,7 +137,7 @@ function ($, NProgress) {
return;
}
- var timeLeft = interval;
+ let timeLeft = interval;
$("#countdown").text("00:00");
timer_id.countdown = Visibility.every(1000, 1000, function () {
timeLeft -= 1000;
@@ -168,7 +168,7 @@ function ($, NProgress) {
switch (tab_id) {
case "#status_nav":
require(["app/stats"], (module) => {
- var refreshInterval = $(".dropdown-menu a.active.preset").data("value");
+ const refreshInterval = $(".dropdown-menu a.active.preset").data("value");
setAutoRefresh(refreshInterval, "status",
function () { return module.statWidgets(graphs, checked_server); });
if (id !== "#autoRefresh") module.statWidgets(graphs, checked_server);
@@ -181,11 +181,11 @@ function ($, NProgress) {
case "#throughput_nav":
require(["app/graph"], (module) => {
const selData = getSelector("selData"); // Graph's dataset selector state
- var step = {
+ const step = {
day: 60000,
week: 300000
};
- var refreshInterval = step[selData] || 3600000;
+ let refreshInterval = step[selData] || 3600000;
$("#dynamic-item").text((refreshInterval / 60000) + " min");
if (!$(".dropdown-menu a.active.dynamic").data("value")) {
@@ -221,7 +221,7 @@ function ($, NProgress) {
module.getHistory();
module.getErrors();
}
- var refreshInterval = $(".dropdown-menu a.active.history").data("value");
+ const refreshInterval = $(".dropdown-menu a.active.history").data("value");
setAutoRefresh(refreshInterval, "history",
function () { return getHistoryAndErrors(); });
if (id !== "#autoRefresh") getHistoryAndErrors();
@@ -250,7 +250,7 @@ function ($, NProgress) {
}
function get_compare_function(table) {
- var compare_functions = {
+ const compare_functions = {
magnitude: function (e1, e2) {
return Math.abs(e2.score) - Math.abs(e1.score);
},
@@ -270,7 +270,7 @@ function ($, NProgress) {
}
function set_page_size(table, page_size, changeTablePageSize) {
- var n = parseInt(page_size, 10); // HTML Input elements return string representing a number
+ const n = parseInt(page_size, 10); // HTML Input elements return string representing a number
if (n > 0) {
ui.page_size[table] = n;
@@ -302,7 +302,7 @@ function ($, NProgress) {
}
function unix_time_format(tm) {
- var date = new Date(tm ? tm * 1000 : 0);
+ const date = new Date(tm ? tm * 1000 : 0);
return (locale)
? date.toLocaleString(locale)
: date.toLocaleString();
@@ -347,7 +347,7 @@ function ($, NProgress) {
}
function alertMessage(alertClass, alertText) {
- var a = $("<div class=\"alert " + alertClass + " alert-dismissible fade in show\">" +
+ const a = $("<div class=\"alert " + alertClass + " alert-dismissible fade in show\">" +
"<button type=\"button\" class=\"btn-close\" data-bs-dismiss=\"alert\" title=\"Dismiss\"></button>" +
"<strong>" + alertText + "</strong>");
$(".notification-area").append(a);
@@ -363,19 +363,19 @@ function ($, NProgress) {
neighbours_status[ind].checked = false;
neighbours_status[ind].data = {};
neighbours_status[ind].status = false;
- var req_params = {
+ const req_params = {
jsonp: false,
data: o.data,
headers: $.extend({Password:getPassword()}, o.headers),
url: neighbours_status[ind].url + req_url,
xhr: function () {
- var xhr = $.ajaxSettings.xhr();
+ const xhr = $.ajaxSettings.xhr();
// Download progress
if (req_url !== "neighbours") {
xhr.addEventListener("progress", function (e) {
if (e.lengthComputable) {
neighbours_status[ind].percentComplete = e.loaded / e.total;
- var percentComplete = neighbours_status.reduce(function (prev, curr) {
+ const percentComplete = neighbours_status.reduce(function (prev, curr) {
return curr.percentComplete ? curr.percentComplete + prev : prev;
}, 0);
NProgress.set(percentComplete / neighbours_status.length);
@@ -400,7 +400,7 @@ function ($, NProgress) {
o.error(neighbours_status[ind],
jqXHR, textStatus, errorThrown);
} else if (o.errorOnceId) {
- var alert_status = o.errorOnceId + neighbours_status[ind].name;
+ const alert_status = o.errorOnceId + neighbours_status[ind].name;
if (!(alert_status in sessionStorage)) {
sessionStorage.setItem(alert_status, true);
errorMessage();
@@ -473,7 +473,7 @@ function ($, NProgress) {
$("#connectForm").off("submit").on("submit", function (e) {
e.preventDefault();
- var password = $("#connectPassword").val();
+ const password = $("#connectPassword").val();
function invalidFeedback(tooltip) {
$("#connectPassword")
@@ -493,7 +493,7 @@ function ($, NProgress) {
Password: password
},
success: function (json) {
- var data = json[0].data;
+ const data = json[0].data;
$("#connectPassword").val("");
if (data.auth === "ok") {
sessionStorage.setItem("read_only", data.read_only);
@@ -546,7 +546,7 @@ function ($, NProgress) {
*/
ui.query = function (url, options) {
// Force options to be an object
- var o = options || {};
+ const o = options || {};
Object.keys(o).forEach(function (option) {
if (["complete", "data", "error", "errorMessage", "errorOnceId", "headers", "method", "params", "server", "statusCode",
"success"]
@@ -555,7 +555,7 @@ function ($, NProgress) {
}
});
- var neighbours_status = [{
+ let neighbours_status = [{
name: "local",
host: "local",
url: "",
@@ -564,7 +564,7 @@ function ($, NProgress) {
if (o.server === "All SERVERS") {
queryServer(neighbours_status, 0, "neighbours", {
success: function (json) {
- var data = json[0].data;
+ const data = json[0].data;
if (jQuery.isEmptyObject(data)) {
neighbours = {
local: {
@@ -610,20 +610,20 @@ function ($, NProgress) {
ui.bindHistoryTableEventHandlers = function (table, symbolsCol) {
function change_symbols_order(order) {
$(".btn-sym-" + table + "-" + order).addClass("active").siblings().removeClass("active");
- var compare_function = get_compare_function(table);
+ const compare_function = get_compare_function(table);
$.each(tables[table].rows.all, function (i, row) {
- var cell_val = sort_symbols(ui.symbols[table][i], compare_function);
+ const cell_val = sort_symbols(ui.symbols[table][i], compare_function);
row.cells[symbolsCol].val(cell_val, false, true);
});
}
$("#selSymOrder_" + table).unbind().change(function () {
- var order = this.value;
+ const order = this.value;
change_symbols_order(order);
});
$("#" + table + "_page_size").change((e) => set_page_size(table, e.target.value, true));
$(document).on("click", ".btn-sym-order-" + table + " input", function () {
- var order = this.value;
+ const order = this.value;
$("#selSymOrder_" + table).val(order);
change_symbols_order(order);
});
@@ -739,8 +739,8 @@ function ($, NProgress) {
on: {
"expand.ft.row": function (e, ft, row) {
setTimeout(function () {
- var detail_row = row.$el.next();
- var order = getSelector("selSymOrder_" + table);
+ const detail_row = row.$el.next();
+ const order = getSelector("selSymOrder_" + table);
detail_row.find(".btn-sym-" + table + "-" + order)
.addClass("active").siblings().removeClass("active");
}, 5);
@@ -750,8 +750,8 @@ function ($, NProgress) {
};
ui.escapeHTML = function (string) {
- var htmlEscaper = /[&<>"'/`=]/g;
- var htmlEscapes = {
+ const htmlEscaper = /[&<>"'/`=]/g;
+ const htmlEscapes = {
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
@@ -771,7 +771,7 @@ function ($, NProgress) {
arr.forEach(function (d, i) { arr[i] = ui.escapeHTML(d); });
}
- for (var prop in item) {
+ for (const prop in item) {
if (!{}.hasOwnProperty.call(item, prop)) continue;
switch (prop) {
case "rcpt_mime":
@@ -780,7 +780,7 @@ function ($, NProgress) {
break;
case "symbols":
Object.keys(item.symbols).forEach(function (key) {
- var sym = item.symbols[key];
+ const sym = item.symbols[key];
if (!sym.name) {
sym.name = key;
}
@@ -811,7 +811,7 @@ function ($, NProgress) {
item.action = "<div style='font-size:11px' class='badge text-bg-info'>" + item.action + "</div>";
}
- var score_content = (item.score < item.required_score)
+ const score_content = (item.score < item.required_score)
? "<span class='text-success'>" + item.score.toFixed(2) + " / " + item.required_score + "</span>"
: "<span class='text-danger'>" + item.score.toFixed(2) + " / " + item.required_score + "</span>";
@@ -825,22 +825,22 @@ function ($, NProgress) {
ui.process_history_v2 = function (data, table) {
// Display no more than rcpt_lim recipients
- var rcpt_lim = 3;
- var items = [];
- var unsorted_symbols = [];
- var compare_function = get_compare_function(table);
+ const rcpt_lim = 3;
+ const items = [];
+ const unsorted_symbols = [];
+ const compare_function = get_compare_function(table);
$("#selSymOrder_" + table + ", label[for='selSymOrder_" + table + "']").show();
$.each(data.rows,
function (i, item) {
function more(p) {
- var l = item[p].length;
+ const l = item[p].length;
return (l > rcpt_lim) ? " … (" + l + ")" : "";
}
function format_rcpt(smtp, mime) {
- var full = "";
- var shrt = "";
+ let full = "";
+ let shrt = "";
if (smtp) {
full = "[" + item.rcpt_smtp.join(", ") + "] ";
shrt = "[" + item.rcpt_smtp.slice(0, rcpt_lim).join(",&#8203;") + more("rcpt_smtp") + "]";
@@ -899,7 +899,7 @@ function ($, NProgress) {
item.id = item["message-id"];
if (table === "history") {
- var rcpt = {};
+ let rcpt = {};
if (!item.rcpt_mime.length) {
rcpt = format_rcpt(true, false);
} else if ($(item.rcpt_mime).not(item.rcpt_smtp).length !== 0 || $(item.rcpt_smtp).not(item.rcpt_mime).length !== 0) {
@@ -921,8 +921,8 @@ function ($, NProgress) {
};
ui.waitForRowsDisplayed = function (table, rows_total, callback, iteration) {
- var i = (typeof iteration === "undefined") ? 10 : iteration;
- var num_rows = $("#historyTable_" + table + " > tbody > tr:not(.footable-detail-row)").length;
+ let i = (typeof iteration === "undefined") ? 10 : iteration;
+ const num_rows = $("#historyTable_" + table + " > tbody > tr:not(.footable-detail-row)").length;
if (num_rows === ui.page_size[table] ||
num_rows === rows_total) {
return callback();
@@ -936,8 +936,8 @@ function ($, NProgress) {
(function initSettings() {
- var selected_locale = null;
- var custom_locale = null;
+ let selected_locale = null;
+ let custom_locale = null;
const localeTextbox = ".popover #settings-popover #locale";
function validateLocale(saveToLocalStorage) {
@@ -945,7 +945,7 @@ function ($, NProgress) {
$(localeTextbox).removeClass("is-" + remove).addClass("is-" + add);
}
- var now = new Date();
+ const now = new Date();
if (custom_locale.length) {
try {
@@ -1050,8 +1050,8 @@ function ($, NProgress) {
});
$(".dropdown-menu a").click(function (e) {
e.preventDefault();
- var classList = $(this).attr("class");
- var menuClass = (/\b(?:dynamic|history|preset)\b/).exec(classList)[0];
+ const classList = $(this).attr("class");
+ const menuClass = (/\b(?:dynamic|history|preset)\b/).exec(classList)[0];
$(".dropdown-menu a.active." + menuClass).removeClass("active");
$(this).addClass("active");
tabClick("#autoRefresh");
diff --git a/interface/js/app/selectors.js b/interface/js/app/selectors.js
index 8e9da052b..759e3ea16 100644
--- a/interface/js/app/selectors.js
+++ b/interface/js/app/selectors.js
@@ -1,7 +1,7 @@
define(["jquery", "app/rspamd"],
function ($, rspamd) {
"use strict";
- var ui = {};
+ const ui = {};
function enable_disable_check_btn() {
$("#selectorsChkMsgBtn").prop("disabled", (
@@ -11,17 +11,17 @@ define(["jquery", "app/rspamd"],
}
function get_server() {
- var checked_server = rspamd.getSelector("selSrv");
+ const checked_server = rspamd.getSelector("selSrv");
return (checked_server === "All SERVERS") ? "local" : checked_server;
}
function checkMsg(data) {
- var selector = $("#selectorsSelArea").val();
+ const selector = $("#selectorsSelArea").val();
rspamd.query("plugins/selectors/check_message?selector=" + encodeURIComponent(selector), {
data: data,
method: "POST",
success: function (neighbours_status) {
- var json = neighbours_status[0].data;
+ const json = neighbours_status[0].data;
if (json.success) {
rspamd.alertMessage("alert-success", "Message successfully processed");
$("#selectorsResArea")
@@ -39,7 +39,7 @@ define(["jquery", "app/rspamd"],
$("#selectorsSelArea").removeClass("is-" + remove).addClass("is-" + add);
enable_disable_check_btn();
}
- var selector = $("#selectorsSelArea").val();
+ const selector = $("#selectorsSelArea").val();
if (selector.length && !rspamd.read_only ) {
rspamd.query("plugins/selectors/check_selector?selector=" + encodeURIComponent(selector), {
method: "GET",
@@ -61,8 +61,8 @@ define(["jquery", "app/rspamd"],
function buildLists() {
function build_table_from_json(json, table_id) {
Object.keys(json).forEach(function (key) {
- var td = $("<td/>");
- var tr = $("<tr/>")
+ const td = $("<td/>");
+ const tr = $("<tr/>")
.append(td.clone().html("<code>" + key + "</code>"))
.append(td.clone().html(json[key].description));
$(table_id + " tbody").append(tr);
@@ -73,7 +73,7 @@ define(["jquery", "app/rspamd"],
rspamd.query("plugins/selectors/list_" + list, {
method: "GET",
success: function (neighbours_status) {
- var json = neighbours_status[0].data;
+ const json = neighbours_status[0].data;
build_table_from_json(json, "#selectorsTable-" + list);
},
server: get_server()
@@ -94,8 +94,8 @@ define(["jquery", "app/rspamd"],
function toggleSidebar(side) {
$("#sidebar-" + side).toggleClass("collapsed");
- var contentClass = "col-lg-6";
- var openSidebarsCount = $("#sidebar-left").hasClass("collapsed") +
+ let contentClass = "col-lg-6";
+ const openSidebarsCount = $("#sidebar-left").hasClass("collapsed") +
$("#sidebar-right").hasClass("collapsed");
switch (openSidebarsCount) {
case 1:
diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js
index f2460c816..86386fe56 100644
--- a/interface/js/app/stats.js
+++ b/interface/js/app/stats.js
@@ -29,13 +29,13 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
function msToTime(seconds) {
if (!Number.isFinite(seconds)) return "???";
/* eslint-disable no-bitwise */
- var years = seconds / 31536000 >> 0; // 3600*24*365
- var months = seconds % 31536000 / 2628000 >> 0; // 3600*24*365/12
- var days = seconds % 31536000 % 2628000 / 86400 >> 0; // 24*3600
- var hours = seconds % 31536000 % 2628000 % 86400 / 3600 >> 0;
- var minutes = seconds % 31536000 % 2628000 % 86400 % 3600 / 60 >> 0;
+ const years = seconds / 31536000 >> 0; // 3600*24*365
+ const months = seconds % 31536000 / 2628000 >> 0; // 3600*24*365/12
+ const days = seconds % 31536000 % 2628000 / 86400 >> 0; // 24*3600
+ const hours = seconds % 31536000 % 2628000 % 86400 / 3600 >> 0;
+ const minutes = seconds % 31536000 % 2628000 % 86400 % 3600 / 60 >> 0;
/* eslint-enable no-bitwise */
- var out = null;
+ let out = null;
if (years > 0) {
if (months > 0) {
out = years + "yr " + months + "mth";
@@ -55,20 +55,20 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
}
function displayStatWidgets(checked_server) {
- var servers = JSON.parse(sessionStorage.getItem("Credentials"));
- var data = {};
+ const servers = JSON.parse(sessionStorage.getItem("Credentials"));
+ let data = {};
if (servers && servers[checked_server]) {
data = servers[checked_server].data;
}
- var stat_w = [];
+ const stat_w = [];
$("#statWidgets").empty().hide();
$.each(data, function (i, item) {
- var widgetsOrder = ["scanned", "no action", "greylist", "add header", "rewrite subject", "reject", "learned"];
+ const widgetsOrder = ["scanned", "no action", "greylist", "add header", "rewrite subject", "reject", "learned"];
function widget(k, v, cls) {
- var c = (typeof cls === "undefined") ? "" : cls;
- var titleAtt = d3.format(",")(v) + " " + k;
+ const c = (typeof cls === "undefined") ? "" : cls;
+ const titleAtt = d3.format(",")(v) + " " + k;
return '<div class="card stat-box d-inline-block text-center shadow-sm me-3 px-3">' +
'<div class="widget overflow-hidden p-2' + c + '" title="' + titleAtt +
'"><strong class="d-block mt-2 mb-1 fw-bold">' +
@@ -77,8 +77,8 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
if (i === "auth" || i === "error") return; // Skip to the next iteration
if (i === "uptime" || i === "version") {
- var cls = "border-end ";
- var val = item;
+ let cls = "border-end ";
+ let val = item;
if (i === "uptime") {
cls = "";
val = msToTime(item);
@@ -106,11 +106,11 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
$("#clusterTable tbody").empty();
$("#selSrv").empty();
$.each(servers, function (key, val) {
- var row_class = "danger";
- var glyph_status = "fas fa-times";
- var version = "???";
- var uptime = "???";
- var short_id = "???";
+ let row_class = "danger";
+ let glyph_status = "fas fa-times";
+ let version = "???";
+ let uptime = "???";
+ let short_id = "???";
let scan_times = {
data: "???",
title: ""
@@ -176,7 +176,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
function addStatfiles(server, statfiles) {
$.each(statfiles, function (i, statfile) {
- var cls = "";
+ let cls = "";
switch (statfile.symbol) {
case "BAYES_SPAM":
cls = "symbol-positive";
@@ -196,7 +196,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
}
function addFuzzyStorage(server, storages) {
- var i = 0;
+ let i = 0;
$.each(storages, function (storage, hashes) {
$("#fuzzyTable tbody").append("<tr>" +
(i === 0 ? '<td rowspan="' + Object.keys(storages).length + '">' + server + "</td>" : "") +
@@ -242,11 +242,11 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
});
}
- var data = [];
- var creds = JSON.parse(sessionStorage.getItem("Credentials"));
+ const data = [];
+ const creds = JSON.parse(sessionStorage.getItem("Credentials"));
// Controller doesn't return the 'actions' object until at least one message is scanned
if (creds && creds[checked_server] && creds[checked_server].data.scanned) {
- var actions = creds[checked_server].data.actions;
+ const actions = creds[checked_server].data.actions;
["no action", "soft reject", "add header", "rewrite subject", "greylist", "reject"]
.forEach(function (action) {
@@ -261,11 +261,11 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
}
// Public API
- var ui = {
+ const ui = {
statWidgets: function (graphs, checked_server) {
rspamd.query("stat", {
success: function (neighbours_status) {
- var neighbours_sum = {
+ const neighbours_sum = {
version: neighbours_status[0].data.version,
uptime: 0,
scanned: 0,
@@ -279,9 +279,9 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
"soft reject": 0,
}
};
- var status_count = 0;
- var promises = [];
- var to_Credentials = {
+ let status_count = 0;
+ const promises = [];
+ const to_Credentials = {
"All SERVERS": {
name: "All SERVERS",
url: "",
@@ -292,10 +292,10 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
};
function process_node_stat(e) {
- var data = neighbours_status[e].data;
+ const data = neighbours_status[e].data;
// Controller doesn't return the 'actions' object until at least one message is scanned
if (data.scanned) {
- for (var action in neighbours_sum.actions) {
+ for (const action in neighbours_sum.actions) {
if ({}.hasOwnProperty.call(neighbours_sum.actions, action)) {
neighbours_sum.actions[action] += data.actions[action];
}
@@ -309,7 +309,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
// Get config_id, version and uptime using /auth query for Rspamd 2.5 and earlier
function get_legacy_stat(e) {
- var alerted = "alerted_stats_legacy_" + neighbours_status[e].name;
+ const alerted = "alerted_stats_legacy_" + neighbours_status[e].name;
promises.push($.ajax({
url: neighbours_status[e].url + "auth",
headers: {Password:rspamd.getPassword()},
@@ -331,7 +331,7 @@ define(["jquery", "app/rspamd", "d3pie", "d3"],
}));
}
- for (var e in neighbours_status) {
+ for (const e in neighbours_status) {
if ({}.hasOwnProperty.call(neighbours_status, e)) {
to_Credentials[neighbours_status[e].name] = neighbours_status[e];
if (neighbours_status[e].status === true) {
diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js
index 8718599d7..7df5a8dfb 100644
--- a/interface/js/app/symbols.js
+++ b/interface/js/app/symbols.js
@@ -27,12 +27,12 @@
define(["jquery", "app/rspamd", "footable"],
function ($, rspamd) {
"use strict";
- var ui = {};
+ const ui = {};
function saveSymbols(action, id, server) {
- var inputs = $("#" + id + " :input[data-role=\"numerictextbox\"]");
- var url = action;
- var values = [];
+ const inputs = $("#" + id + " :input[data-role=\"numerictextbox\"]");
+ const url = action;
+ const values = [];
$(inputs).each(function () {
values.push({
name: $(this).attr("id").substring(5),
@@ -54,20 +54,20 @@ define(["jquery", "app/rspamd", "footable"],
});
}
function decimalStep(number) {
- var digits = Number(number).toFixed(20).replace(/^-?\d*\.?|0+$/g, "").length;
+ const digits = Number(number).toFixed(20).replace(/^-?\d*\.?|0+$/g, "").length;
return (digits === 0 || digits > 4) ? 0.1 : 1.0 / Math.pow(10, digits);
}
function process_symbols_data(data) {
- var items = [];
- var lookup = {};
- var freqs = [];
- var distinct_groups = [];
- var selected_server = rspamd.getSelector("selSrv");
+ const items = [];
+ const lookup = {};
+ const freqs = [];
+ const distinct_groups = [];
+ const selected_server = rspamd.getSelector("selSrv");
data.forEach(function (group) {
group.rules.forEach(function (item) {
- var max = 20;
- var min = -20;
+ let max = 20;
+ let min = -20;
if (item.weight > max) {
max = item.weight * 2;
}
@@ -75,7 +75,7 @@ define(["jquery", "app/rspamd", "footable"],
if (item.weight < min) {
min = item.weight * 2;
}
- var label_class = "";
+ let label_class = "";
if (item.weight < 0) {
label_class = "scorebar-ham";
} else if (item.weight > 0) {
@@ -112,13 +112,13 @@ define(["jquery", "app/rspamd", "footable"],
});
// For better mean calculations
- var avg_freq = freqs.sort(function (a, b) {
+ const avg_freq = freqs.sort(function (a, b) {
return Number(a) < Number(b);
}).reduce(function (f1, acc) {
return f1 + acc;
}) / (freqs.length !== 0 ? freqs.length : 1.0);
- var mult = 1.0;
- var exp = 0.0;
+ let mult = 1.0;
+ let exp = 0.0;
if (avg_freq > 0.0) {
while (mult * avg_freq < 1.0) {
@@ -141,8 +141,8 @@ define(["jquery", "app/rspamd", "footable"],
ui.getSymbols = function (checked_server) {
rspamd.query("symbols", {
success: function (json) {
- var data = json[0].data;
- var items = process_symbols_data(data);
+ const data = json[0].data;
+ const items = process_symbols_data(data);
/* eslint-disable consistent-this, no-underscore-dangle, one-var-declaration-per-line */
FooTable.groupFilter = FooTable.Filtering.extend({
@@ -154,7 +154,7 @@ define(["jquery", "app/rspamd", "footable"],
},
$create: function () {
this._super();
- var self = this, $form_grp = $("<div/>", {
+ const self = this, $form_grp = $("<div/>", {
class: "form-group"
}).append($("<label/>", {
class: "sr-only",
@@ -175,7 +175,7 @@ define(["jquery", "app/rspamd", "footable"],
});
},
_onStatusDropdownChanged: function (e) {
- var self = e.data.self, selected = $(this).val();
+ const self = e.data.self, selected = $(this).val();
if (selected !== self.def) {
self.addFilter("group", selected, ["group"]);
} else {
@@ -185,7 +185,7 @@ define(["jquery", "app/rspamd", "footable"],
},
draw: function () {
this._super();
- var group = this.find("group");
+ const group = this.find("group");
if (group instanceof FooTable.Filter) {
this.$group.val(group.query.val());
} else {
@@ -236,7 +236,7 @@ define(["jquery", "app/rspamd", "footable"],
$("#symbolsTable")
.off("click", ":button")
.on("click", ":button", function () {
- var value = $(this).data("save");
+ const value = $(this).data("save");
if (!value) return;
saveSymbols("./savesymbols", "symbolsTable", value);
});
@@ -245,10 +245,10 @@ define(["jquery", "app/rspamd", "footable"],
$("#updateSymbols").on("click", function (e) {
e.preventDefault();
- var checked_server = rspamd.getSelector("selSrv");
+ const checked_server = rspamd.getSelector("selSrv");
rspamd.query("symbols", {
success: function (data) {
- var items = process_symbols_data(data[0].data)[0];
+ const items = process_symbols_data(data[0].data)[0];
rspamd.tables.symbols.rows.load(items);
},
server: (checked_server === "All SERVERS") ? "local" : checked_server
diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js
index 269d32460..26bb82e8d 100644
--- a/interface/js/app/upload.js
+++ b/interface/js/app/upload.js
@@ -27,7 +27,7 @@
define(["jquery", "app/rspamd"],
function ($, rspamd) {
"use strict";
- var ui = {};
+ const ui = {};
function cleanTextUpload(source) {
$("#" + source + "TextSource").val("");
@@ -35,7 +35,7 @@ define(["jquery", "app/rspamd"],
// @upload text
function uploadText(data, source, headers) {
- var url = null;
+ let url = null;
if (source === "spam") {
url = "learnspam";
} else if (source === "ham") {
@@ -142,7 +142,7 @@ define(["jquery", "app/rspamd"],
}
function get_server() {
- var checked_server = rspamd.getSelector("selSrv");
+ const checked_server = rspamd.getSelector("selSrv");
return (checked_server === "All SERVERS") ? "local" : checked_server;
}
@@ -166,13 +166,13 @@ define(["jquery", "app/rspamd"],
});
}
- var json = neighbours_status[0].data;
+ const json = neighbours_status[0].data;
if (json.action) {
rspamd.alertMessage("alert-success", "Data successfully scanned");
- var rows_total = $("#historyTable_scan > tbody > tr:not(.footable-detail-row)").length + 1;
- var o = rspamd.process_history_v2({rows:[json]}, "scan");
- var items = o.items;
+ const rows_total = $("#historyTable_scan > tbody > tr:not(.footable-detail-row)").length + 1;
+ const o = rspamd.process_history_v2({rows:[json]}, "scan");
+ const items = o.items;
rspamd.symbols.scan.push(o.symbols[0]);
if (Object.prototype.hasOwnProperty.call(rspamd.tables, "scan")) {
@@ -228,7 +228,7 @@ define(["jquery", "app/rspamd"],
},
method: "POST",
success: function (neighbours_status) {
- var json = neighbours_status[0].data;
+ const json = neighbours_status[0].data;
if (json.success) {
rspamd.alertMessage("alert-success", "Message successfully processed");
fillHashTable(json.hashes);
@@ -277,13 +277,13 @@ define(["jquery", "app/rspamd"],
});
$("[data-upload]").on("click", function () {
- var source = $(this).data("upload");
- var data = $("#scanMsgSource").val();
- var headers = {};
+ const source = $(this).data("upload");
+ const data = $("#scanMsgSource").val();
+ let headers = {};
if ($.trim(data).length > 0) {
if (source === "scan") {
headers = ["IP", "User", "From", "Rcpt", "Helo", "Hostname"].reduce(function (o, header) {
- var value = $("#scan-opt-" + header.toLowerCase()).val();
+ const value = $("#scan-opt-" + header.toLowerCase()).val();
if (value !== "") o[header] = value;
return o;
}, {});