Browse Source

[Minor] JS: Use double quotes wherever possible

tags/1.7.8
Alexander Moisseev 5 years ago
parent
commit
ba2a5ba57c

+ 92
- 92
interface/js/app/config.js View File

@@ -22,34 +22,34 @@
THE SOFTWARE.
*/

define(['jquery'],
define(["jquery"],
function($) {
var interface = {}

function save_map_success(rspamd) {
rspamd.alertMessage('alert-modal alert-success', 'Map data successfully saved');
$('#modalDialog').modal('hide');
rspamd.alertMessage("alert-modal alert-success", "Map data successfully saved");
$("#modalDialog").modal("hide");
}
function save_map_error(rspamd, serv, jqXHR, textStatus, errorThrown) {
rspamd.alertMessage('alert-modal alert-error', 'Save map error on ' +
serv.name + ': ' + errorThrown);
rspamd.alertMessage("alert-modal alert-error", "Save map error on " +
serv.name + ": " + errorThrown);
}
// @upload map from modal
function saveMap(rspamd, action, id) {
var data = $('#' + id).find('textarea').val();
var data = $("#" + id).find("textarea").val();
$.ajax({
data: data,
dataType: 'text',
type: 'POST',
dataType: "text",
type: "POST",
jsonp: false,
url: action,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader('Map', id);
xhr.setRequestHeader('Debug', true);
xhr.setRequestHeader("Password", rspamd.getPassword());
xhr.setRequestHeader("Map", id);
xhr.setRequestHeader("Debug", true);
},
error: function (data) {
save_map_error(rspamd, 'local', null, null, data.statusText);
save_map_error(rspamd, "local", null, null, data.statusText);
},
success: function() {save_map_success(rspamd)},
});
@@ -58,73 +58,73 @@ function($) {
// @get maps id
function getMaps(rspamd) {
var items = [];
var $listmaps = $('#listMaps')
$listmaps.closest('.widget-box').hide();
var $listmaps = $("#listMaps")
$listmaps.closest(".widget-box").hide();
$.ajax({
dataType: 'json',
url: 'maps',
dataType: "json",
url: "maps",
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
error: function (data) {
rspamd.alertMessage('alert-modal alert-error', data.statusText);
rspamd.alertMessage("alert-modal alert-error", data.statusText);
},
success: function (data) {
$listmaps.empty();
$('#modalBody').empty();
$tbody = $('<tbody>');
$("#modalBody").empty();
$tbody = $("<tbody>");

$.each(data, function (i, item) {
if ((item.editable === false || rspamd.read_only)) {
var label = '<span class="label label-default">Read</span>';
var label = "<span class=\"label label-default\">Read</span>";
} else {
var label = '<span class="label label-default">Read</span>&nbsp;<span class="label label-success">Write</span>';
var label = "<span class=\"label label-default\">Read</span>&nbsp;<span class=\"label label-success\">Write</span>";
}
var $tr = $("<tr>");
$('<td class="col-md-2 maps-cell">' + label + '</td>').appendTo($tr);
$span = $('<span class="map-link" data-toggle="modal" data-target="#modalDialog">' + item.uri + '</span>').data("item",item);
$("<td class=\"col-md-2 maps-cell\">" + label + "</td>").appendTo($tr);
$span = $("<span class=\"map-link\" data-toggle=\"modal\" data-target=\"#modalDialog\">" + item.uri + "</span>").data("item",item);
$span.wrap("<td>").parent().appendTo($tr);
$('<td>' + item.description + '</td>').appendTo($tr);
$("<td>" + item.description + "</td>").appendTo($tr);
$tr.appendTo($tbody);
});
$tbody.appendTo($listmaps);
$listmaps.closest('.widget-box').show();
$listmaps.closest(".widget-box").show();
}
});
}
// @get map by id
function getMapById(rspamd, item) {
return $.ajax({
dataType: 'text',
url: 'getmap',
dataType: "text",
url: "getmap",
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader('Map', item.map);
xhr.setRequestHeader("Password", rspamd.getPassword());
xhr.setRequestHeader("Map", item.map);
},
error: function () {
rspamd.alertMessage('alert-error', 'Cannot receive maps data');
rspamd.alertMessage("alert-error", "Cannot receive maps data");
},
success: function (text) {
var disabled = '';
var disabled = "";
if ((item.editable === false || rspamd.read_only)) {
disabled = 'disabled="disabled"';
disabled = "disabled=\"disabled\"";
}
$("#"+item.map).remove();
$('<form class="form-horizontal form-map" method="post" action="savemap" data-type="map" id="' +
item.map + '" style="display:none">' +
'<textarea class="list-textarea"' + disabled + '>' + text +
'</textarea>' +
'</form').appendTo('#modalBody');
$("<form class=\"form-horizontal form-map\" method=\"post\" action=\"savemap\" data-type=\"map\" id=\"" +
item.map + "\" style=\"display:none\">" +
"<textarea class=\"list-textarea\"" + disabled + ">" + text +
"</textarea>" +
"</form").appendTo("#modalBody");
}
});
}

function loadActionsFromForm() {
var values = [];
var inputs = $('#actionsForm :input[data-id="action"]');
var 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);
@@ -136,43 +136,43 @@ function($) {

function getActions(rspamd) {
$.ajax({
dataType: 'json',
type: 'GET',
url: 'actions',
dataType: "json",
type: "GET",
url: "actions",
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function (data) {
// Order of sliders greylist -> probable spam -> rewrite subject -> spam
$('#actionsBody').empty();
$('#actionsForm').empty();
$("#actionsBody").empty();
$("#actionsForm").empty();
var items = [];
$.each(data, function (i, item) {
var idx = -1;
var label;
if (item.action === 'add header') {
label = 'Probably Spam';
if (item.action === "add header") {
label = "Probably Spam";
idx = 1;
} else if (item.action === 'greylist') {
label = 'Greylist';
} else if (item.action === "greylist") {
label = "Greylist";
idx = 0;
} else if (item.action === 'rewrite subject') {
label = 'Rewrite subject';
} else if (item.action === "rewrite subject") {
label = "Rewrite subject";
idx = 2;
} else if (item.action === 'reject') {
label = 'Spam';
} else if (item.action === "reject") {
label = "Spam";
idx = 3;
}
if (idx >= 0) {
items.push({
idx: idx,
html: '<div class="form-group">' +
'<label class="control-label col-sm-2">' + label + '</label>' +
'<div class="controls slider-controls col-sm-10">' +
'<input class="action-scores form-control" data-id="action" type="number" value="' + item.value + '">' +
'</div>' +
'</div>'
html: "<div class=\"form-group\">" +
"<label class=\"control-label col-sm-2\">" + label + "</label>" +
"<div class=\"controls slider-controls col-sm-10\">" +
"<input class=\"action-scores form-control\" data-id=\"action\" type=\"number\" value=\"" + item.value + "\">" +
"</div>" +
"</div>"
});
}
});
@@ -181,19 +181,19 @@ function($) {
return a.idx - b.idx;
});

$('#actionsBody').html('<form id="actionsForm"><fieldset id="actionsFormField">' +
$("#actionsBody").html("<form id=\"actionsForm\"><fieldset id=\"actionsFormField\">" +
items.map(function (e) {
return e.html;
}).join('') +
'<br><div class="form-group">' +
'<div class="btn-group">' +
'<button class="btn btn-primary" type="button" id="saveActionsBtn">Save actions</button>' +
'<button class="btn btn-primary" type="button" id="saveActionsClusterBtn">Save cluster</button>' +
'</div></div></fieldset></form>');
}).join("") +
"<br><div class=\"form-group\">" +
"<div class=\"btn-group\">" +
"<button class=\"btn btn-primary\" type=\"button\" id=\"saveActionsBtn\">Save actions</button>" +
"<button class=\"btn btn-primary\" type=\"button\" id=\"saveActionsClusterBtn\">Save cluster</button>" +
"</div></div></fieldset></form>");
if (rspamd.read_only) {
$('#saveActionsClusterBtn').attr('disabled', true);
$('#saveActionsBtn').attr('disabled', true);
$('#actionsFormField').attr('disabled', true);
$("#saveActionsClusterBtn").attr("disabled", true);
$("#saveActionsBtn").attr("disabled", true);
$("#actionsFormField").attr("disabled", true);
}

function saveActions(callback) {
@@ -222,10 +222,10 @@ function($) {
}
}

$('#saveActionsBtn').on('click', function() {
$("#saveActionsBtn").on("click", function() {
saveActions(rspamd.queryLocal);
});
$('#saveActionsClusterBtn').on('click', function() {
$("#saveActionsClusterBtn").on("click", function() {
saveActions(rspamd.queryNeighbours);
});
},
@@ -235,39 +235,39 @@ function($) {
// @upload edited actions
interface.setup = function(rspamd) {
// Modal form for maps
$(document).on('click', '[data-toggle="modal"]', function () {
var item = $(this).data('item');
$(document).on("click", "[data-toggle=\"modal\"]", function () {
var item = $(this).data("item");
getMapById(rspamd, item).done(function() {
$('#modalTitle').html(item.uri);
$('#' + item.map).first().show();
$('#modalDialog .progress').hide();
$('#modalDialog').modal(show = true, backdrop = true, keyboard = show);
$("#modalTitle").html(item.uri);
$("#" + item.map).first().show();
$("#modalDialog .progress").hide();
$("#modalDialog").modal(show = true, backdrop = true, keyboard = show);
if (item.editable === false) {
$('#modalSave').hide();
$('#modalSaveAll').hide();
$("#modalSave").hide();
$("#modalSaveAll").hide();
} else {
$('#modalSave').show();
$('#modalSaveAll').show();
$("#modalSave").show();
$("#modalSaveAll").show();
}
});
return false;
});
// close modal without saving
$('[data-dismiss="modal"]').on('click', function () {
$('#modalBody form').hide();
$("[data-dismiss=\"modal\"]").on("click", function () {
$("#modalBody form").hide();
});
// @save forms from modal
$('#modalSave').on('click', function () {
var form = $('#modalBody').children().filter(':visible');
var action = $(form).attr('action');
var id = $(form).attr('id');
$("#modalSave").on("click", function () {
var form = $("#modalBody").children().filter(":visible");
var action = $(form).attr("action");
var id = $(form).attr("id");
saveMap(rspamd, action, id);
});
$('#modalSaveAll').on('click', function () {
var form = $('#modalBody').children().filter(':visible');
var action = $(form).attr('action');
var id = $(form).attr('id');
var data = $('#' + id).find('textarea').val();
$("#modalSaveAll").on("click", function () {
var form = $("#modalBody").children().filter(":visible");
var action = $(form).attr("action");
var id = $(form).attr("id");
var data = $("#" + id).find("textarea").val();
rspamd.queryNeighbours(action, save_map_success, save_map_error, "POST", {
"Map": id,
}, {

+ 14
- 14
interface/js/app/graph.js View File

@@ -23,7 +23,7 @@
THE SOFTWARE.
*/

define(['jquery', 'd3evolution', 'footable'],
define(["jquery", "d3evolution", "footable"],
function($, D3Evolution, unused) {
var rrd_pie_config = {
header: {},
@@ -148,9 +148,9 @@ function($, D3Evolution, unused) {
};
}, []);

document.getElementById('rrd-total-value').innerHTML = total_messages;
document.getElementById("rrd-total-value").innerHTML = total_messages;

$('#rrd-table').footable({
$("#rrd-table").footable({
sorting: {
enabled: true
},
@@ -219,8 +219,8 @@ function($, D3Evolution, unused) {
neighbours_data.reduce(function (res, curr) {
if ((curr[0][0].x !== res[0][0].x) ||
(curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) {
rspamd.alertMessage('alert-error',
'Neighbours time extents do not match. Check if time is synchronized on all servers.');
rspamd.alertMessage("alert-error",
"Neighbours time extents do not match. Check if time is synchronized on all servers.");
updateWidgets();
return;
}
@@ -244,12 +244,12 @@ function($, D3Evolution, unused) {
}
},
function (serv, jqXHR, textStatus, errorThrown) {
var alert_status = serv.name + '_alerted';
var alert_status = serv.name + "_alerted";

if (!(alert_status in sessionStorage)) {
sessionStorage.setItem(alert_status, true);
rspamd.alertMessage('alert-error', 'Cannot receive RRD data from: ' +
serv.name + ', error: ' + errorThrown);
rspamd.alertMessage("alert-error", "Cannot receive RRD data from: " +
serv.name + ", error: " + errorThrown);
}
}, "GET", {}, {}, {
type: type
@@ -258,22 +258,22 @@ function($, D3Evolution, unused) {
}

$.ajax({
dataType: 'json',
type: 'GET',
url: neighbours[checked_server].url + 'graph',
dataType: "json",
type: "GET",
url: neighbours[checked_server].url + "graph",
jsonp: false,
data: {
"type": type
},
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function (data) {
updateWidgets(data);
},
error: function (jqXHR, textStatus, errorThrown) {
rspamd.alertMessage('alert-error', 'Cannot receive throughput data: ' +
textStatus + ' ' + jqXHR.status + ' ' + errorThrown);
rspamd.alertMessage("alert-error", "Cannot receive throughput data: " +
textStatus + " " + jqXHR.status + " " + errorThrown);
}
});
};

+ 59
- 59
interface/js/app/history.js View File

@@ -22,25 +22,25 @@
THE SOFTWARE.
*/

define(['jquery', 'footable', 'humanize'],
define(["jquery", "footable", "humanize"],
function($, _, Humanize) {
var interface = {};
var ft = {};
var htmlEscapes = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
'/': '&#x2F;',
'`': '&#x60;',
'=': '&#x3D;'
"&": "&amp;",
"<": "&lt;",
">": "&gt;",
"\"": "&quot;",
"'": "&#39;",
"/": "&#x2F;",
"`": "&#x60;",
"=": "&#x3D;"
};
var htmlEscaper = /[&<>"'\/`=]/g;
var symbolDescriptions = {};

EscapeHTML = function(string) {
return ('' + string).replace(htmlEscaper, function(match) {
return ("" + string).replace(htmlEscaper, function(match) {
return htmlEscapes[match];
});
};
@@ -84,11 +84,11 @@ function($, _, Humanize) {
}
}

if (item.action === 'clean' || item.action === 'no action') {
if (item.action === "clean" || item.action === "no action") {
item.action = "<div style='font-size:11px' class='label label-success'>" + item.action + "</div>";
} else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') {
} else if (item.action === "rewrite subject" || item.action === "add header" || item.action === "probable spam") {
item.action = "<div style='font-size:11px' class='label label-warning'>" + item.action + "</div>";
} else if (item.action === 'spam' || item.action === 'reject') {
} else if (item.action === "spam" || item.action === "reject") {
item.action = "<div style='font-size:11px' class='label label-danger'>" + item.action + "</div>";
} else {
item.action = "<div style='font-size:11px' class='label label-info'>" + item.action + "</div>";
@@ -158,16 +158,16 @@ function($, _, Humanize) {
var sym = item.symbols[key];

if (sym.description) {
var str = '<strong><abbr data-sym-key="' + key + '">' + sym.name + '</abbr></strong>' + "(" + sym.score + ")";
var str = "<strong><abbr data-sym-key=\"" + key + "\">" + sym.name + "</abbr></strong>" + "(" + sym.score + ")";

// Store description for tooltip
symbolDescriptions[key] = sym.description;
} else {
var str = '<strong>' + sym.name + '</strong>' + "(" + sym.score + ")";
var str = "<strong>" + sym.name + "</strong>" + "(" + sym.score + ")";
}

if (sym.options) {
str += '[' + sym.options.join(",") + "]";
str += "[" + sym.options.join(",") + "]";
}
item.symbols[key].str = str;
});
@@ -184,7 +184,7 @@ function($, _, Humanize) {
"sortValue": item.unix_time
}
};
var scan_time = item.time_real.toFixed(3) + ' / ' +
var scan_time = item.time_real.toFixed(3) + " / " +
item.time_virtual.toFixed(3);
item.scan_time = {
"options": {
@@ -192,7 +192,7 @@ function($, _, Humanize) {
},
"value": scan_time
};
item.id = item['message-id'];
item.id = item["message-id"];

var rcpt = {};
if (!item.rcpt_mime.length) {
@@ -487,52 +487,52 @@ function($, _, Humanize) {
FooTable.actionFilter = FooTable.Filtering.extend({
construct : function(instance) {
this._super(instance);
this.actions = [ 'reject', 'add header', 'greylist',
'no action', 'soft reject', 'rewrite subject' ];
this.def = 'Any action';
this.actions = [ "reject", "add header", "greylist",
"no action", "soft reject", "rewrite subject" ];
this.def = "Any action";
this.$action = null;
},
$create : function() {
this._super();
var self = this, $form_grp = $('<div/>', {
'class' : 'form-group'
}).append($('<label/>', {
'class' : 'sr-only',
text : 'Action'
var self = this, $form_grp = $("<div/>", {
"class" : "form-group"
}).append($("<label/>", {
"class" : "sr-only",
text : "Action"
})).prependTo(self.$form);

self.$action = $('<select/>', {
'class' : 'form-control'
}).on('change', {
self.$action = $("<select/>", {
"class" : "form-control"
}).on("change", {
self : self
}, self._onStatusDropdownChanged).append(
$('<option/>', {
$("<option/>", {
text : self.def
})).appendTo($form_grp);

$.each(self.actions, function(i, action) {
self.$action.append($('<option/>').text(action));
self.$action.append($("<option/>").text(action));
});
},
_onStatusDropdownChanged : function(e) {
var self = e.data.self, selected = $(this).val();
if (selected !== self.def) {
if(selected === "reject"){
self.addFilter('action', 'reject -soft', [ 'action' ]);
self.addFilter("action", "reject -soft", [ "action" ]);
} else {
self.addFilter('action', selected, [ 'action' ]);
self.addFilter("action", selected, [ "action" ]);
}
} else {
self.removeFilter('action');
self.removeFilter("action");
}
self.filter();
},
draw : function() {
this._super();
var action = this.find('action');
var action = this.find("action");
if (action instanceof FooTable.Filter) {
if(action.query.val() === 'reject -soft'){
this.$action.val('reject');
if(action.query.val() === "reject -soft"){
this.$action.val("reject");
} else {
this.$action.val(action.query.val());
}
@@ -545,7 +545,7 @@ function($, _, Humanize) {
var drawTooltips = function() {
// Update symbol description tooltips
$.each(symbolDescriptions, function (key, description) {
$('abbr[data-sym-key=' + key + ']').tooltip({
$("abbr[data-sym-key=" + key + "]").tooltip({
"placement": "bottom",
"html": true,
"title": description
@@ -560,8 +560,8 @@ function($, _, Humanize) {
return e.version !== neighbours_data[0].version;
});
if (dv) {
rspamd.alertMessage('alert-error',
'Neighbours history backend versions do not match. Cannot display history.');
rspamd.alertMessage("alert-error",
"Neighbours history backend versions do not match. Cannot display history.");
return true;
}
}
@@ -620,14 +620,14 @@ function($, _, Humanize) {
}
else {
$.ajax({
dataType: 'json',
url: neighbours[checked_server].url + 'history',
dataType: "json",
url: neighbours[checked_server].url + "history",
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
error: function () {
rspamd.alertMessage('alert-error', 'Cannot receive history');
rspamd.alertMessage("alert-error", "Cannot receive history");
},
success: function (data) {
var items = process_history_data(data);
@@ -660,8 +660,8 @@ function($, _, Humanize) {
}
});
}
$('#updateHistory').off('click');
$('#updateHistory').on('click', function (e) {
$("#updateHistory").off("click");
$("#updateHistory").on("click", function (e) {
e.preventDefault();
interface.getHistory(rspamd, tables, neighbours, checked_server);
});
@@ -670,8 +670,8 @@ function($, _, Humanize) {
});

// @reset history log
$('#resetHistory').off('click');
$('#resetHistory').on('click', function (e) {
$("#resetHistory").off("click");
$("#resetHistory").on("click", function (e) {
e.preventDefault();
if (!confirm("Are you sure you want to reset history log?")) {
return;
@@ -692,19 +692,19 @@ function($, _, Humanize) {
}
else {
$.ajax({
dataType: 'json',
type: 'GET',
dataType: "json",
type: "GET",
jsonp: false,
url: neighbours[checked_server].url + 'historyreset',
url: neighbours[checked_server].url + "historyreset",
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function () {
interface.getHistory(rspamd, tables, neighbours, checked_server);
interface.getErrors(rspamd, tables, neighbours, checked_server);
},
error: function (data) {
rspamd.alertMessage('alert-modal alert-error', data.statusText);
rspamd.alertMessage("alert-modal alert-error", data.statusText);
}
});
}
@@ -749,14 +749,14 @@ function($, _, Humanize) {

if (checked_server !== "All SERVERS") {
$.ajax({
dataType: 'json',
url: neighbours[checked_server].url + 'errors',
dataType: "json",
url: neighbours[checked_server].url + "errors",
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
error: function () {
rspamd.alertMessage('alert-error', 'Cannot receive errors');
rspamd.alertMessage("alert-error", "Cannot receive errors");
},
success: function (data) {
drawErrorsTable(data);
@@ -774,8 +774,8 @@ function($, _, Humanize) {
drawErrorsTable([].concat.apply([], neighbours_data));
});
}
$('#updateErrors').off('click');
$('#updateErrors').on('click', function (e) {
$("#updateErrors").off("click");
$("#updateErrors").on("click", function (e) {
e.preventDefault();
interface.getErrors(rspamd, tables, neighbours, checked_server);
});

+ 74
- 74
interface/js/app/rspamd.js View File

@@ -22,8 +22,8 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
'app/symbols', 'app/history', 'app/upload'],
define(["jquery", "d3pie", "visibility", "app/stats", "app/graph", "app/config",
"app/symbols", "app/history", "app/upload"],
function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
tab_symbols, tab_history, tab_upload) {
// begin
@@ -76,13 +76,13 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
}

function tabClick(tab_id) {
if ($(tab_id).attr('disabled')) return;
$(tab_id).attr('disabled', true);
if ($(tab_id).attr("disabled")) return;
$(tab_id).attr("disabled", true);

stopTimers();

if (tab_id === "#refresh") {
tab_id = "#" + $('.navbar-nav .active > a' ).attr('id');
tab_id = "#" + $(".navbar-nav .active > a" ).attr("id");
}

switch (tab_id) {
@@ -120,35 +120,35 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
}

setTimeout(function () {
$(tab_id).removeAttr('disabled');
$('#refresh').removeAttr('disabled');
$(tab_id).removeAttr("disabled");
$("#refresh").removeAttr("disabled");
}, 1000);
}

// @return password
function getPassword() {
return sessionStorage.getItem('Password');
return sessionStorage.getItem("Password");
}

// @save credentials
function saveCredentials(password) {
sessionStorage.setItem('Password', password);
sessionStorage.setItem("Password", password);
}

// @clean credentials
function cleanCredentials() {
sessionStorage.clear();
$('#statWidgets').empty();
$('#listMaps').empty();
$('#modalBody').empty();
$('#historyLog tbody').remove();
$('#errorsLog tbody').remove();
$('#symbolsTable tbody').remove();
password = '';
$("#statWidgets").empty();
$("#listMaps").empty();
$("#modalBody").empty();
$("#historyLog tbody").remove();
$("#errorsLog tbody").remove();
$("#symbolsTable tbody").remove();
password = "";
}

function isLogged() {
if (sessionStorage.getItem('Credentials') !== null) {
if (sessionStorage.getItem("Credentials") !== null) {
return true;
}
return false;
@@ -156,23 +156,23 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',

function displayUI() {
// @toggle auth and main
var disconnect = $('#navBar .pull-right');
$('#mainUI').show();
$('#progress').show();
var disconnect = $("#navBar .pull-right");
$("#mainUI").show();
$("#progress").show();
$(disconnect).show();
tabClick("#refresh");
$('#progress').hide();
$("#progress").hide();
}

function alertMessage(alertClass, alertText) {
var a = $('<div class="alert ' + alertClass + ' alert-dismissible fade in show">' +
'<button type="button" class="close" data-dismiss="alert" title="Dismiss">&times;</button>' +
'<strong>' + alertText + '</strong>');
$('.notification-area').append(a);
var a = $("<div class=\"alert " + alertClass + " alert-dismissible fade in show\">" +
"<button type=\"button\" class=\"close\" data-dismiss=\"alert\" title=\"Dismiss\">&times;</button>" +
"<strong>" + alertText + "</strong>");
$(".notification-area").append(a);

setTimeout(function () {
$(a).fadeTo(500, 0).slideUp(500, function () {
$(this).alert('close');
$(this).alert("close");
});
}, 5000);
}
@@ -190,40 +190,40 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
});

$(document).ajaxStart(function () {
$('#navBar').addClass('loading');
$("#navBar").addClass("loading");
});
$(document).ajaxComplete(function () {
setTimeout(function () {
$('#navBar').removeClass('loading');
$("#navBar").removeClass("loading");
}, 1000);
});

$.ajax({
type: 'GET',
url: 'stat',
type: "GET",
url: "stat",
success: function () {
saveCredentials({}, 'nopassword');
var dialog = $('#connectDialog');
var backdrop = $('#backDrop');
saveCredentials({}, "nopassword");
var dialog = $("#connectDialog");
var backdrop = $("#backDrop");
$(dialog).hide();
$(backdrop).hide();
displayUI();
},
});

$('a[data-toggle="tab"]').on('click', function (e) {
$("a[data-toggle=\"tab\"]").on("click", function (e) {
var tab_id = "#" + $(e.target).attr("id");
tabClick(tab_id);
});

$("#selSrv").change(function () {
checked_server = this.value;
$('#selSrv [value="' + checked_server + '"]').prop("checked", true);
$("#selSrv [value=\"" + checked_server + "\"]").prop("checked", true);
tabClick("#" + $("#navBar ul li.active > a").attr("id"));
});

// Radio buttons
$(document).on('click', 'input:radio[name="clusterName"]', function () {
$(document).on("click", "input:radio[name=\"clusterName\"]", function () {
if (!this.disabled) {
checked_server = this.value;
tabClick("#status_nav");
@@ -238,65 +238,65 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',

interface.connect = function() {
if (isLogged()) {
var data = JSON.parse(sessionStorage.getItem('Credentials'));
var data = JSON.parse(sessionStorage.getItem("Credentials"));

if (data && data[checked_server].read_only) {
interface.read_only = true;
$('#learning_nav').hide();
$('#resetHistory').attr('disabled', true);
$('#errors-history').hide();
$("#learning_nav").hide();
$("#resetHistory").attr("disabled", true);
$("#errors-history").hide();
}
else {
interface.read_only = false;
$('#learning_nav').show();
$('#resetHistory').removeAttr('disabled', true);
$("#learning_nav").show();
$("#resetHistory").removeAttr("disabled", true);
}
displayUI();
return;
}

var ui = $('#mainUI');
var dialog = $('#connectDialog');
var backdrop = $('#backDrop');
var ui = $("#mainUI");
var dialog = $("#connectDialog");
var backdrop = $("#backDrop");
$(ui).hide();
$(dialog).show();
$(backdrop).show();
$('#connectPassword').focus();
$('#connectForm').off('submit');
$("#connectPassword").focus();
$("#connectForm").off("submit");

$('#connectForm').on('submit', function (e) {
$("#connectForm").on("submit", function (e) {
e.preventDefault();
var password = $('#connectPassword').val();
var password = $("#connectPassword").val();
if (!/^[\u0000-\u007f]*$/.test(password)) {
alertMessage('alert-modal alert-error', 'Invalid characters in the password');
$('#connectPassword').focus();
alertMessage("alert-modal alert-error", "Invalid characters in the password");
$("#connectPassword").focus();
return;
}

$.ajax({
global: false,
jsonp: false,
dataType: 'json',
type: 'GET',
url: 'auth',
dataType: "json",
type: "GET",
url: "auth",
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', password);
xhr.setRequestHeader("Password", password);
},
success: function (data) {
$('#connectPassword').val('');
if (data.auth === 'failed') {
$("#connectPassword").val("");
if (data.auth === "failed") {
// Is actually never returned by Rspamd
} else {
if (data.read_only) {
interface.read_only = true;
$('#learning_nav').hide();
$('#resetHistory').attr('disabled', true);
$('#errors-history').hide();
$("#learning_nav").hide();
$("#resetHistory").attr("disabled", true);
$("#errors-history").hide();
}
else {
interface.read_only = false;
$('#learning_nav').show();
$('#resetHistory').removeAttr('disabled', true);
$("#learning_nav").show();
$("#resetHistory").removeAttr("disabled", true);
}

saveCredentials(password);
@@ -306,9 +306,9 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
}
},
error: function (data) {
interface.alertMessage('alert-modal alert-error', data.statusText);
$('#connectPassword').val('');
$('#connectPassword').focus();
interface.alertMessage("alert-modal alert-error", data.statusText);
$("#connectPassword").val("");
$("#connectPassword").focus();
}
});
});
@@ -333,15 +333,15 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
on_success(data);
}
else {
alertMessage('alert-success', 'Data saved');
alertMessage("alert-success", "Data saved");
}
},
error: function(jqXHR, textStatus, errorThrown) {
if (on_error) {
on_error('local', jqXHR, textStatus, errorThrown);
on_error("local", jqXHR, textStatus, errorThrown);
}
else {
alertMessage('alert-error', 'Cannot receive data: ' + errorThrown);
alertMessage("alert-error", "Cannot receive data: " + errorThrown);
}
}
};
@@ -386,7 +386,7 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
});
$.each(neighbours_status, function (ind) {
"use strict";
method = typeof method !== 'undefined' ? method : "GET";
method = typeof method !== "undefined" ? method : "GET";
var req_params = {
type: method,
jsonp: false,
@@ -415,7 +415,7 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
on_success(neighbours_status);
}
else {
alertMessage('alert-success', 'Request completed');
alertMessage("alert-success", "Request completed");
}
}
},
@@ -427,8 +427,8 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
jqXHR, textStatus, errorThrown);
}
else {
alertMessage('alert-error', 'Cannot receive data from ' +
neighbours_status[ind].host + ': ' + errorThrown);
alertMessage("alert-error", "Cannot receive data from " +
neighbours_status[ind].host + ": " + errorThrown);
}
if (neighbours_status.every(
function (elt) {return elt.checked;})) {
@@ -436,7 +436,7 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
on_success(neighbours_status);
}
else {
alertMessage('alert-success', 'Request completed');
alertMessage("alert-success", "Request completed");
}
}
}
@@ -451,7 +451,7 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
});
},
error: function () {
interface.alertMessage('alert-error', 'Cannot receive neighbours data');
interface.alertMessage("alert-error", "Cannot receive neighbours data");
},
});
};

+ 46
- 46
interface/js/app/stats.js View File

@@ -22,7 +22,7 @@
THE SOFTWARE.
*/

define(['jquery', 'd3pie', 'humanize'],
define(["jquery", "d3pie", "humanize"],
function($, d3pie, Humanize) {
// @ ms to date
function msToTime(seconds) {
@@ -33,27 +33,27 @@ function($, d3pie, Humanize) {
minutes = seconds % 31536000 % 2628000 % 86400 % 3600 / 60 >> 0;
if (years > 0) {
if (months > 0) {
out = years + 'yr ' + months + 'mth';
out = years + "yr " + months + "mth";
} else {
out = years + 'yr ' + days + 'd';
out = years + "yr " + days + "d";
}
} else if (months > 0) {
out = months + 'mth ' + days + 'd';
out = months + "mth " + days + "d";
} else if (days > 0) {
out = days + 'd ' + hours + 'hr';
out = days + "d " + hours + "hr";
} else if (hours > 0) {
out = hours + 'hr ' + minutes + 'min';
out = hours + "hr " + minutes + "min";
} else {
out = minutes + 'min';
out = minutes + "min";
}
return out;
}

function displayStatWidgets(checked_server) {
var widgets = $('#statWidgets');
var widgets = $("#statWidgets");
$(widgets).empty().hide();

var servers = JSON.parse(sessionStorage.getItem('Credentials'));
var servers = JSON.parse(sessionStorage.getItem("Credentials"));
var data = {};

if (servers && servers[checked_server]) {
@@ -62,32 +62,32 @@ function($, d3pie, Humanize) {
var stat_w = [];

$.each(data, function (i, item) {
var widget = '';
if (i == 'auth') {}
else if (i == 'error') {}
else if (i == 'version') {
widget = '<div class="left"><strong>' + item + '</strong>' +
i + '</div>';
var widget = "";
if (i == "auth") {}
else if (i == "error") {}
else if (i == "version") {
widget = "<div class=\"left\"><strong>" + item + "</strong>" +
i + "</div>";
$(widget).appendTo(widgets);
} else if (i == 'uptime') {
widget = '<div class="right"><strong>' + msToTime(item) +
'</strong>' + i + '</div>';
} else if (i == "uptime") {
widget = "<div class=\"right\"><strong>" + msToTime(item) +
"</strong>" + i + "</div>";
$(widget).appendTo(widgets);
} else {
var titleAtt = Humanize.intComma(item) + ' ' + i;
widget = '<li class="stat-box"><div class="widget" title="' + titleAtt + '"><strong>' +
Humanize.compactInteger(item) + '</strong>' + i + '</div></li>';
if (i == 'scanned') {
var titleAtt = Humanize.intComma(item) + " " + i;
widget = "<li class=\"stat-box\"><div class=\"widget\" title=\"" + titleAtt + "\"><strong>" +
Humanize.compactInteger(item) + "</strong>" + i + "</div></li>";
if (i == "scanned") {
stat_w[0] = widget;
} else if (i == 'clean') {
} else if (i == "clean") {
stat_w[1] = widget;
} else if (i == 'greylist') {
} else if (i == "greylist") {
stat_w[2] = widget;
} else if (i == 'probable') {
} else if (i == "probable") {
stat_w[3] = widget;
} else if (i == 'reject') {
} else if (i == "reject") {
stat_w[4] = widget;
} else if (i == 'learned') {
} else if (i == "learned") {
stat_w[5] = widget;
}
}
@@ -95,15 +95,15 @@ function($, d3pie, Humanize) {
$.each(stat_w, function (i, item) {
$(item).appendTo(widgets);
});
$('#statWidgets .left,#statWidgets .right').wrapAll('<li class="stat-box pull-right"><div class="widget"></div></li>');
$('#statWidgets').find('li.pull-right').appendTo('#statWidgets');
$("#statWidgets .left,#statWidgets .right").wrapAll("<li class=\"stat-box pull-right\"><div class=\"widget\"></div></li>");
$("#statWidgets").find("li.pull-right").appendTo("#statWidgets");

$("#clusterTable tbody").empty();
$("#selSrv").empty();
$.each(servers, function (key, val) {
var glyph_status;
var short_id;
if (!('config_id' in val.data)) {
if (!("config_id" in val.data)) {
val.data.config_id = "";
}
if (val.status) {
@@ -115,29 +115,29 @@ function($, d3pie, Humanize) {
short_id = "???";
}

$('#clusterTable tbody').append('<tr>' +
'<td class="col1" title="Radio"><input type="radio" class="form-control radio" name="clusterName" value="' + key + '"></td>' +
'<td class="col2" title="SNAme">' + key + '</td>' +
'<td class="col3" title="SHost">' + val.host + '</td>' +
'<td class="col4" title="SStatus"><span class="icon"><i class="' + glyph_status + '"></i></span></td>' +
'<td class="col5" title="short_id">' + short_id + '</td></tr>');
$("#clusterTable tbody").append("<tr>" +
"<td class=\"col1\" title=\"Radio\"><input type=\"radio\" class=\"form-control radio\" name=\"clusterName\" value=\"" + key + "\"></td>" +
"<td class=\"col2\" title=\"SNAme\">" + key + "</td>" +
"<td class=\"col3\" title=\"SHost\">" + val.host + "</td>" +
"<td class=\"col4\" title=\"SStatus\"><span class=\"icon\"><i class=\"" + glyph_status + "\"></i></span></td>" +
"<td class=\"col5\" title=\"short_id\">" + short_id + "</td></tr>");

$("#selSrv").append( $('<option value="' + key + '">' + key + '</option>'));
$("#selSrv").append( $("<option value=\"" + key + "\">" + key + "</option>"));

if (checked_server == key) {
$('#clusterTable tbody [value="' + key + '"]').prop("checked", true);
$('#selSrv [value="' + key + '"]').prop("selected", true);
$("#clusterTable tbody [value=\"" + key + "\"]").prop("checked", true);
$("#selSrv [value=\"" + key + "\"]").prop("selected", true);
}
else if (!val.status) {
$('#clusterTable tbody [value="' + key + '"]').prop("disabled", true);
$('#selSrv [value="' + key + '"]').prop("disabled", true);
$("#clusterTable tbody [value=\"" + key + "\"]").prop("disabled", true);
$("#selSrv [value=\"" + key + "\"]").prop("disabled", true);
}
});
$(widgets).show();
}

function getChart(rspamd, pie, checked_server) {
var creds = JSON.parse(sessionStorage.getItem('Credentials'));
var creds = JSON.parse(sessionStorage.getItem("Credentials"));
if (creds && creds[checked_server]) {
var data = creds[checked_server].data;
var new_data = [ {
@@ -192,7 +192,7 @@ function($, d3pie, Humanize) {
for(var e in neighbours_status) {
if(neighbours_status[e].status === true) {
// Remove alert status
localStorage.removeItem(e + '_alerted');
localStorage.removeItem(e + "_alerted");
neighbours_sum.clean += neighbours_status[e].data.clean;
neighbours_sum.probable += neighbours_status[e].data.probable;
neighbours_sum.greylist += neighbours_status[e].data.greylist;
@@ -221,12 +221,12 @@ function($, d3pie, Humanize) {
graphs.chart = getChart(rspamd, graphs.chart, checked_server);
},
function (serv, jqXHR, textStatus, errorThrown) {
var alert_status = serv.name + '_alerted';
var alert_status = serv.name + "_alerted";

if (!(alert_status in sessionStorage)) {
sessionStorage.setItem(alert_status, true);
rspamd.alertMessage('alert-error', 'Cannot receive stats data from: ' +
serv.name + ', error: ' + errorThrown);
rspamd.alertMessage("alert-error", "Cannot receive stats data from: " +
serv.name + ", error: " + errorThrown);
}
});
},

+ 54
- 54
interface/js/app/symbols.js View File

@@ -22,29 +22,29 @@
THE SOFTWARE.
*/

define(['jquery', 'footable'],
define(["jquery", "footable"],
function($) {
var interface = {}
var ft = {}

function saveSymbols(rspamd, action, id, is_cluster) {
var inputs = $('#' + id + ' :input[data-role="numerictextbox"]');
var inputs = $("#" + id + " :input[data-role=\"numerictextbox\"]");
var url = action;
var values = [];
$(inputs).each(function () {
values.push({
name: $(this).attr('id').substring(5),
name: $(this).attr("id").substring(5),
value: parseFloat($(this).val())
});
});

if (is_cluster) {
rspamd.queryNeighbours(url, function () {
rspamd.alertMessage('alert-modal alert-success', 'Symbols successfully saved');
rspamd.alertMessage("alert-modal alert-success", "Symbols successfully saved");
}, function (serv, qXHR, textStatus, errorThrown) {
rspamd.alertMessage('alert-modal alert-error',
'Save symbols error on ' +
serv.name + ': ' + errorThrown);
rspamd.alertMessage("alert-modal alert-error",
"Save symbols error on " +
serv.name + ": " + errorThrown);
}, "POST", {}, {
data: JSON.stringify(values),
dataType: "json",
@@ -53,24 +53,24 @@ function($) {
else {
$.ajax({
data: JSON.stringify(values),
dataType: 'json',
type: 'POST',
dataType: "json",
type: "POST",
url: url,
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function () {
rspamd.alertMessage('alert-modal alert-success', 'Symbols successfully saved');
rspamd.alertMessage("alert-modal alert-success", "Symbols successfully saved");
},
error: function (data) {
rspamd.alertMessage('alert-modal alert-error', data.statusText);
rspamd.alertMessage("alert-modal alert-error", data.statusText);
}
});
}
}
function decimalStep(number) {
var digits = ((+number).toFixed(20)).replace(/^-?\d*\.?|0+$/g, '').length;
var digits = ((+number).toFixed(20)).replace(/^-?\d*\.?|0+$/g, "").length;
if (digits === 0 || digits > 4) {
return 0.1;
} else {
@@ -94,22 +94,22 @@ function($) {
if (item.weight < min) {
min = item.weight * 2;
}
var label_class = '';
var label_class = "";
if (item.weight < 0) {
label_class = 'scorebar-ham';
label_class = "scorebar-ham";
} else if (item.weight > 0) {
label_class = 'scorebar-spam';
label_class = "scorebar-spam";
}
item.weight = '<input class="form-control input-sm mb-disabled ' + label_class +
'" data-role="numerictextbox" autocomplete="off" "type="number" class="input" min="' +
min + '" max="' +
max + '" step="' + decimalStep(item.weight) +
'" tabindex="1" value="' + Number(item.weight).toFixed(3) +
'" id="_sym_' + item.symbol + '"></input>'
item.weight = "<input class=\"form-control input-sm mb-disabled " + label_class +
"\" data-role=\"numerictextbox\" autocomplete=\"off\" \"type=\"number\" class=\"input\" min=\"" +
min + "\" max=\"" +
max + "\" step=\"" + decimalStep(item.weight) +
"\" tabindex=\"1\" value=\"" + Number(item.weight).toFixed(3) +
"\" id=\"_sym_" + item.symbol + "\"></input>"
if (!item.time) {
item.time = 0;
}
item.time = Number(item.time).toFixed(2) + 's'
item.time = Number(item.time).toFixed(2) + "s"
if (!item.frequency) {
item.frequency = 0;
}
@@ -119,8 +119,8 @@ function($) {
lookup[item.group] = 1;
distinct_groups.push(item.group);
}
item.save = '<button type="button" data-save="local" class="btn btn-primary btn-sm mb-disabled">Save</button>' +
'&nbsp;<button data-save="cluster" type="button" class="btn btn-primary btn-sm mb-disabled">Save in cluster</button>';
item.save = "<button type=\"button\" data-save=\"local\" class=\"btn btn-primary btn-sm mb-disabled\">Save</button>" +
"&nbsp;<button data-save=\"cluster\" type=\"button\" class=\"btn btn-primary btn-sm mb-disabled\">Save in cluster</button>";
items.push(item)
});
});
@@ -144,7 +144,7 @@ function($) {
item.frequency = Number(item.frequency) * mult;

if (exp > 0) {
item.frequency = item.frequency.toFixed(2) + 'e-' + exp;
item.frequency = item.frequency.toFixed(2) + "e-" + exp;
}
else {
item.frequency = item.frequency.toFixed(2);
@@ -156,12 +156,12 @@ function($) {
interface.getSymbols = function(rspamd, tables, checked_server) {

$.ajax({
dataType: 'json',
type: 'GET',
url: 'symbols',
dataType: "json",
type: "GET",
url: "symbols",
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function (data) {
var items = process_symbols_data(data);
@@ -169,43 +169,43 @@ function($) {
construct : function(instance) {
this._super(instance);
this.groups = items[1];
this.def = 'Any group';
this.def = "Any group";
this.$group = null;
},
$create : function() {
this._super();
var self = this, $form_grp = $('<div/>', {
'class' : 'form-group'
}).append($('<label/>', {
'class' : 'sr-only',
text : 'Group'
var self = this, $form_grp = $("<div/>", {
"class" : "form-group"
}).append($("<label/>", {
"class" : "sr-only",
text : "Group"
})).prependTo(self.$form);

self.$group = $('<select/>', {
'class' : 'form-control'
}).on('change', {
self.$group = $("<select/>", {
"class" : "form-control"
}).on("change", {
self : self
}, self._onStatusDropdownChanged).append(
$('<option/>', {
$("<option/>", {
text : self.def
})).appendTo($form_grp);

$.each(self.groups, function(i, group) {
self.$group.append($('<option/>').text(group));
self.$group.append($("<option/>").text(group));
});
},
_onStatusDropdownChanged : function(e) {
var self = e.data.self, selected = $(this).val();
if (selected !== self.def) {
self.addFilter('group', selected, [ 'group' ]);
self.addFilter("group", selected, [ "group" ]);
} else {
self.removeFilter('group');
self.removeFilter("group");
}
self.filter();
},
draw : function() {
this._super();
var group = this.find('group');
var group = this.find("group");
if (group instanceof FooTable.Filter) {
this.$group.val(group.query.val());
} else {
@@ -243,40 +243,40 @@ function($) {
"on": {
"ready.ft.table": function () {
if (rspamd.read_only) {
$(".mb-disabled").attr('disabled', true);
$(".mb-disabled").attr("disabled", true);
}
}
}
});
},
error: function (data) {
rspamd.alertMessage('alert-modal alert-error', data.statusText);
rspamd.alertMessage("alert-modal alert-error", data.statusText);
}
});
$(document).on("click", "#symbolsTable :button", function(event){
var value = $(this).data('save');
var value = $(this).data("save");
if (!value) return
saveSymbols(rspamd, "./savesymbols", "symbolsTable", value == 'cluster');
saveSymbols(rspamd, "./savesymbols", "symbolsTable", value == "cluster");
});
};

interface.setup = function(rspamd, tables) {
$('#updateSymbols').on('click', function (e) {
$("#updateSymbols").on("click", function (e) {
e.preventDefault();
$.ajax({
dataType: 'json',
type: 'GET',
dataType: "json",
type: "GET",
jsonp: false,
url: 'symbols',
url: "symbols",
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function (data) {
var items = process_symbols_data(data)[0];
ft.symbols.rows.load(items);
},
error: function (data) {
rspamd.alertMessage('alert-modal alert-error', data.statusText);
rspamd.alertMessage("alert-modal alert-error", data.statusText);
}
});
});

+ 72
- 72
interface/js/app/upload.js View File

@@ -22,35 +22,35 @@
THE SOFTWARE.
*/

define(['jquery'],
define(["jquery"],
function($) {
var interface = {}

function cleanTextUpload(source) {
$('#' + source + 'TextSource').val('');
$("#" + source + "TextSource").val("");
}

// @upload text
function uploadText(rspamd, data, source, headers) {
var url;
if (source === 'spam') {
url = 'learnspam';
} else if (source === 'ham') {
url = 'learnham';
} else if (source == 'fuzzy') {
url = 'fuzzyadd';
} else if (source === 'scan') {
url = 'scan';
if (source === "spam") {
url = "learnspam";
} else if (source === "ham") {
url = "learnham";
} else if (source == "fuzzy") {
url = "fuzzyadd";
} else if (source === "scan") {
url = "scan";
}
$.ajax({
data: data,
dataType: 'json',
type: 'POST',
dataType: "json",
type: "POST",
url: url,
processData: false,
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
$.each(headers, function (name, value) {
xhr.setRequestHeader(name, value);
});
@@ -58,7 +58,7 @@ function($) {
success: function (data) {
cleanTextUpload(source);
if (data.success) {
rspamd.alertMessage('alert-success', 'Data successfully uploaded');
rspamd.alertMessage("alert-success", "Data successfully uploaded");
}
},
error: function (xhr, textStatus, errorThrown) {
@@ -66,140 +66,140 @@ function($) {

try {
var json = $.parseJSON(xhr.responseText);
errorMsg = $('<a>').text(json.error).html();
errorMsg = $("<a>").text(json.error).html();
} catch (err) {
errorMsg = $('<a>').text("Error: [" + textStatus + "] " + errorThrown).html();
errorMsg = $("<a>").text("Error: [" + textStatus + "] " + errorThrown).html();
}
rspamd.alertMessage('alert-error', errorMsg);
rspamd.alertMessage("alert-error", errorMsg);
}
});
}
// @upload text
function scanText(rspamd, data) {
var url = 'scan';
var url = "scan";
var items = [];
$.ajax({
data: data,
dataType: 'json',
type: 'POST',
dataType: "json",
type: "POST",
url: url,
processData: false,
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
xhr.setRequestHeader("Password", rspamd.getPassword());
},
success: function (input) {
var data = input;
if (data.action) {
rspamd.alertMessage('alert-success', 'Data successfully scanned');
var action = '';
rspamd.alertMessage("alert-success", "Data successfully scanned");
var action = "";

if (data.action === 'clean' || 'no action') {
action = 'label-success';
if (data.action === "clean" || "no action") {
action = "label-success";
}
else if (data.action === 'rewrite subject' || 'add header' || 'probable spam') {
action = 'label-warning';
else if (data.action === "rewrite subject" || "add header" || "probable spam") {
action = "label-warning";
}
else if (data.action === 'spam') {
action = 'label-danger';
else if (data.action === "spam") {
action = "label-danger";
}

var score = '';
var score = "";
if (data.score <= data.required_score) {
score = 'label-success';
score = "label-success";
}
else if (data.score >= data.required_score) {
score = 'label-danger';
score = "label-danger";
}
$('<tbody id="tmpBody"><tr>' +
'<td><span class="label ' + action + '">' + data.action + '</span></td>' +
'<td><span class="label ' + score + '">' + data.score.toFixed(2) + '/' + data.required_score.toFixed(2) + '</span></td>' +
'</tr></tbody>')
.insertAfter('#scanOutput thead');
$("<tbody id=\"tmpBody\"><tr>" +
"<td><span class=\"label " + action + "\">" + data.action + "</span></td>" +
"<td><span class=\"label " + score + "\">" + data.score.toFixed(2) + "/" + data.required_score.toFixed(2) + "</span></td>" +
"</tr></tbody>")
.insertAfter("#scanOutput thead");
var sym_desc = {};
var nsym = 0;

$.each(data.symbols, function (i, item) {
if (typeof item == 'object') {
if (typeof item == "object") {
var sym_id = "sym_" + nsym;
if (item.description) {
sym_desc[sym_id] = item.description;
}
items.push('<div class="cell-overflow" tabindex="1"><abbr id="' + sym_id +
'">' + item.name + '</abbr>: ' + item.score.toFixed(2) + '</div>');
items.push("<div class=\"cell-overflow\" tabindex=\"1\"><abbr id=\"" + sym_id +
"\">" + item.name + "</abbr>: " + item.score.toFixed(2) + "</div>");
nsym++;
}
});
$('<td/>', {
id: 'tmpSymbols',
html: items.join('')
}).appendTo('#scanResult');
$('#tmpSymbols').insertAfter('#tmpBody td:last').removeAttr('id');
$('#tmpBody').removeAttr('id');
$('#scanResult').show();
$("<td/>", {
id: "tmpSymbols",
html: items.join("")
}).appendTo("#scanResult");
$("#tmpSymbols").insertAfter("#tmpBody td:last").removeAttr("id");
$("#tmpBody").removeAttr("id");
$("#scanResult").show();
// Show tooltips
$.each(sym_desc, function (k, v) {
$('#' + k).tooltip({
$("#" + k).tooltip({
"placement": "bottom",
"title": v
});
});
$('html, body').animate({
scrollTop: $('#scanResult').offset().top
$("html, body").animate({
scrollTop: $("#scanResult").offset().top
}, 1000);
} else {
rspamd.alertMessage('alert-error', 'Cannot scan data');
rspamd.alertMessage("alert-error", "Cannot scan data");
}
},
error: function (jqXHR, textStatus, errorThrown) {
rspamd.alertMessage('alert-error', 'Cannot upload data: ' +
rspamd.alertMessage("alert-error", "Cannot upload data: " +
textStatus + ", " + errorThrown);
},
statusCode: {
404: function () {
rspamd.alertMessage('alert-error', 'Cannot upload data, no server found');
rspamd.alertMessage("alert-error", "Cannot upload data, no server found");
},
500: function () {
rspamd.alertMessage('alert-error', 'Cannot tokenize message: no text data');
rspamd.alertMessage("alert-error", "Cannot tokenize message: no text data");
},
503: function () {
rspamd.alertMessage('alert-error', 'Cannot tokenize message: no text data');
rspamd.alertMessage("alert-error", "Cannot tokenize message: no text data");
}
}
});
}

interface.setup = function(rspamd) {
$('textarea').change(function () {
if ($(this).val().length !== '') {
$(this).closest('form').find('button').removeAttr('disabled').removeClass('disabled');
$("textarea").change(function () {
if ($(this).val().length !== "") {
$(this).closest("form").find("button").removeAttr("disabled").removeClass("disabled");
} else {
$(this).closest('form').find('button').attr('disabled').addClass('disabled');
$(this).closest("form").find("button").attr("disabled").addClass("disabled");
}
});

$('#scanClean').on('click', function () {
$('#scanTextSource').val("");
$('#scanResult').hide();
$('#scanOutput tbody').remove();
$('html, body').animate({scrollTop: 0}, 1000);
$("#scanClean").on("click", function () {
$("#scanTextSource").val("");
$("#scanResult").hide();
$("#scanOutput tbody").remove();
$("html, body").animate({scrollTop: 0}, 1000);
return false;
});
// @init upload
$('[data-upload]').on('click', function () {
var source = $(this).data('upload');
$("[data-upload]").on("click", function () {
var source = $(this).data("upload");
var data;
var headers = {};
data = $('#' + source + 'TextSource').val();
if (source == 'fuzzy') {
data = $("#" + source + "TextSource").val();
if (source == "fuzzy") {
//To access the proper
headers.flag = $('#fuzzyFlagText').val();
headers.weight = $('#fuzzyWeightText').val();
headers.flag = $("#fuzzyFlagText").val();
headers.weight = $("#fuzzyWeightText").val();
} else {
data = $('#' + source + 'TextSource').val();
data = $("#" + source + "TextSource").val();
}
if (data.length > 0) {
if (source == 'scan') {
if (source == "scan") {
scanText(rspamd, data);
} else {
uploadText(rspamd, data, source, headers);

+ 18
- 18
interface/js/main.js View File

@@ -1,23 +1,23 @@
requirejs.config({
baseUrl: 'js/lib',
baseUrl: "js/lib",
paths: {
app: '../app',
jquery: 'jquery-3.3.1.min',
visibility: 'visibility.min',
humanize: 'humanize.min',
bootstrap: 'bootstrap.min',
d3: 'd3.min',
d3evolution: 'd3evolution.min',
d3pie: 'd3pie.min',
footable: 'footable.min',
bootstrap: 'bootstrap.min',
app: "../app",
jquery: "jquery-3.3.1.min",
visibility: "visibility.min",
humanize: "humanize.min",
bootstrap: "bootstrap.min",
d3: "d3.min",
d3evolution: "d3evolution.min",
d3pie: "d3pie.min",
footable: "footable.min",
bootstrap: "bootstrap.min",
},
shim: {
d3: {exports: 'd3'},
bootstrap: {exports: 'bootstrap', deps: ['jquery']},
d3pie: {exports: 'd3pie', deps: ['d3.global', 'jquery']},
d3evolution: {exports: 'D3Evolution', deps: ['d3', 'd3pie', 'jquery']},
footable: {deps: ['bootstrap', 'jquery']}
d3: {exports: "d3"},
bootstrap: {exports: "bootstrap", deps: ["jquery"]},
d3pie: {exports: "d3pie", deps: ["d3.global", "jquery"]},
d3evolution: {exports: "D3Evolution", deps: ["d3", "d3pie", "jquery"]},
footable: {deps: ["bootstrap", "jquery"]}
}
});

@@ -31,10 +31,10 @@ define("d3.global", ["d3"], function(_) {
});

// Load main UI
require(['domReady'],
require(["domReady"],
function(domReady) {
domReady(function () {
require(['jquery', 'd3', 'app/rspamd'],
require(["jquery", "d3", "app/rspamd"],
function ($, d3, rspamd) {
rspamd.setup();
rspamd.connect();

Loading…
Cancel
Save