Browse Source

[WebUI] Move history tab

tags/1.5.0
Vsevolod Stakhov 7 years ago
parent
commit
712d1dc173
2 changed files with 201 additions and 236 deletions
  1. 195
    0
      interface/js/app/history.js
  2. 6
    236
      interface/js/app/rspamd.js

+ 195
- 0
interface/js/app/history.js View File

@@ -0,0 +1,195 @@
/*
The MIT License (MIT)

Copyright (C) 2017 Vsevolod Stakhov <vsevolod@highsecure.ru>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

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

interface.getHistory = function (rspamd, tables) {
if (tables.history !== undefined) {
var history_length = document.getElementsByName('historyLog_length')[0];
if (history_length !== undefined) {
history_length = parseInt(history_length.value);
} else {
history_length = 10;
}
tables.history.destroy();
tables.history = undefined;
$('#historyLog').children('tbody').remove();
}

var items = [];
$.ajax({
dataType: 'json',
url: 'history',
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
},
error: function () {
rspamd.alertMessage('alert-error', 'Cannot receive history');
},
success: function (data) {
$.each(data, function (i, item) {
var action;

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

var score;
if (item.score < item.required_score) {
score = 'label-success';
} else {
score = 'label-danger';
}

items.push(
'<tr><td data-order="' + item.unix_time + '">' + item.time + '</td>' +
'<td data-order="' + item.id + '"><div class="cell-overflow" tabindex="1" title="' + item.id + '">' + item.id + '</div></td>' +
'<td data-order="' + item.ip + '"><div class="cell-overflow" tabindex="1" title="' + item.ip + '">' + item.ip + '</div></td>' +
'<td data-order="' + item.action + '"><span class="label ' + action + '">' + item.action + '</span></td>' +
'<td data-order="' + item.score + '"><span class="label ' + score + '">' + item.score.toFixed(2) + ' / ' + item.required_score.toFixed(2) + '</span></td>' +
'<td data-order="' + item.symbols + '"><div class="cell-overflow" tabindex="1" title="' + item.symbols + '">' + item.symbols + '</div></td>' +
'<td data-order="' + item.size + '">' + item.size + '</td>' +
'<td data-order="' + item.scan_time + '">' + item.scan_time.toFixed(3) + '</td>' +
'<td data-order="' + item.user + '"><div class="cell-overflow" tabindex="1" "title="' + item.user + '">' + item.user + '</div></td></tr>');
});
$('<tbody/>', {
html: items.join('')
}).insertAfter('#historyLog thead');
tables.history = $('#historyLog').DataTable({
"aLengthMenu": [
[100, 200, -1],
[100, 200, "All"]
],
"bStateSave": true,
"order": [
[0, "desc"]
],
"pageLength": history_length
});
}
});
};

interface.getErrors = function(rspamd, tables) {
if (rspamd.read_only) return;

if (tables.errors) {
tables.errors.destroy();
$('#errorsLog').children('tbody').remove();
tables.errors = undefined;
}

var items = [];
$.ajax({
dataType: 'json',
url: 'errors',
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
},
error: function () {
rspamd.alertMessage('alert-error', 'Cannot receive errors');
},
success: function (data) {
$.each(data, function (i, item) {

items.push(
'<tr><td data-order="' + item.ts + '">' + new Date(item.ts * 1000) + '</td>' +
'<td data-order="' + item.type + '">' + item.type + '</td>' +
'<td data-order="' + item.pid + '">' + item.pid + '</td>' +
'<td data-order="' + item.module + '">' + item.module + '</td>' +
'<td data-order="' + item.id + '">' + item.id + '</td>' +
'<td data-order="' + item.message + '"><div class="cell-overflow" tabindex="1" title="' + item.message + '">' + item.message + '</div></td></tr>'
);
});
$('<tbody/>', {
html: items.join('')
}).insertAfter('#errorsLog thead');
tables.errors = $('#errorsLog').DataTable({
"paging": true,
"orderMulti": false,
"order": [
[0, "desc"],
],
"info": false,
"columns": [
{"width": "15%", "searchable": true, "orderable": true, "type": "num"},
{"width": "5%", "searchable": true, "orderable": true},
{"width": "5%", "searchable": true, "orderable": true},
{"width": "3%", "searchable": true, "orderable": true},
{"width": "3%", "searchable": true, "orderable": true},
{"width": "65%", "searchable": true, "orderable": true},
],
});
tables.errors.columns.adjust().draw();
}
});
};

interface.setup = function(rspamd, tables) {
$('#updateHistory').on('click', function () {
interface.getHistory(rspamd, tables);
});
$('#updateErrors').on('click', function () {
interface.getErrors(rspamd, tables);
});
// @reset history log
$('#resetHistory').on('click', function () {
if (!confirm("Are you sure you want to reset history log?")) {
return;
}
if (tables.history) {
tables.history.destroy();
tables.history = undefined;
$('#historyLog').children('tbody').remove();
}
$.ajax({
dataType: 'json',
type: 'GET',
jsonp: false,
url: 'historyreset',
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', rspamd.getPassword());
},
success: function () {
interface.getHistory(rspamd, tables);
interface.getErrors(rspamd, tables);
},
error: function (data) {
rspamd.alertMessage('alert-modal alert-error', data.statusText);
}
});
});
};
return interface;
});

+ 6
- 236
interface/js/app/rspamd.js View File

@@ -23,8 +23,9 @@
THE SOFTWARE.
*/
define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
'app/symbols'],
function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, tab_symbols) {
'app/symbols', 'app/history'],
function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
tab_symbols, tab_history) {
// begin
var graphs = {};
var tables = {};
@@ -110,8 +111,8 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
tab_symbols.getSymbols(interface, tables, checked_server);
break;
case "#history_nav":
getHistory();
getErrors();
tab_history.getHistory(interface, tables, checked_server);
tab_history.getErrors(interface, tables, checked_server);
break;
case "#disconnect":
disconnect();
@@ -198,6 +199,7 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
});
tab_config.setup(interface);
tab_symbols.setup(interface, tables);
tab_history.setup(interface, tables);
};

interface.alertMessage = function (alertState, alertText) {
@@ -474,194 +476,6 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',

return interface;

// @alert popover

// @opem modal with target form enabled



// @get history log
// function getChart() {
// //console.log(data)
// $.ajax({
// dataType: 'json',
// url: './pie',
// beforeSend: function(xhr) {
// xhr.setRequestHeader('Password', getPassword())
// },
// error: function() {
// alertMessage('alert-error', 'Cannot receive history');
// },
// success: function(data) {
// console.log(data);
// }
// });
// }
// @get history log
function getHistory() {

if (history) {
var history_length = document.getElementsByName('historyLog_length')[0];
if (history_length !== undefined) {
history_length = parseInt(history_length.value);
} else {
history_length = 10;
}
history.destroy();
$('#historyLog').children('tbody').remove();
}

var items = [];
$.ajax({
dataType: 'json',
url: 'history',
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', getPassword());
},
error: function () {
alertMessage('alert-error', 'Cannot receive history');
},
success: function (data) {
$.each(data, function (i, item) {
var action;

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

var score;
if (item.score < item.required_score) {
score = 'label-success';
} else {
score = 'label-danger';
}

items.push(
'<tr><td data-order="' + item.unix_time + '">' + item.time + '</td>' +
'<td data-order="' + item.id + '"><div class="cell-overflow" tabindex="1" title="' + item.id + '">' + item.id + '</div></td>' +
'<td data-order="' + item.ip + '"><div class="cell-overflow" tabindex="1" title="' + item.ip + '">' + item.ip + '</div></td>' +
'<td data-order="' + item.action + '"><span class="label ' + action + '">' + item.action + '</span></td>' +
'<td data-order="' + item.score + '"><span class="label ' + score + '">' + item.score.toFixed(2) + ' / ' + item.required_score.toFixed(2) + '</span></td>' +
'<td data-order="' + item.symbols + '"><div class="cell-overflow" tabindex="1" title="' + item.symbols + '">' + item.symbols + '</div></td>' +
'<td data-order="' + item.size + '">' + item.size + '</td>' +
'<td data-order="' + item.scan_time + '">' + item.scan_time.toFixed(3) + '</td>' +
'<td data-order="' + item.user + '"><div class="cell-overflow" tabindex="1" "title="' + item.user + '">' + item.user + '</div></td></tr>');
});
$('<tbody/>', {
html: items.join('')
}).insertAfter('#historyLog thead');
history = $('#historyLog').DataTable({
"aLengthMenu": [
[100, 200, -1],
[100, 200, "All"]
],
"bStateSave": true,
"order": [
[0, "desc"]
],
"pageLength": history_length
});
}
});
}

function getErrors() {
if (interface.read_only) return;

if (errors) {
errors.destroy();
$('#errorsLog').children('tbody').remove();
}

var items = [];
$.ajax({
dataType: 'json',
url: 'errors',
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', getPassword());
},
error: function () {
alertMessage('alert-error', 'Cannot receive errors');
},
success: function (data) {
$.each(data, function (i, item) {

items.push(
'<tr><td data-order="' + item.ts + '">' + new Date(item.ts * 1000) + '</td>' +
'<td data-order="' + item.type + '">' + item.type + '</td>' +
'<td data-order="' + item.pid + '">' + item.pid + '</td>' +
'<td data-order="' + item.module + '">' + item.module + '</td>' +
'<td data-order="' + item.id + '">' + item.id + '</td>' +
'<td data-order="' + item.message + '"><div class="cell-overflow" tabindex="1" title="' + item.message + '">' + item.message + '</div></td></tr>'
);
});
$('<tbody/>', {
html: items.join('')
}).insertAfter('#errorsLog thead');
errors = $('#errorsLog').DataTable({
"paging": true,
"orderMulti": false,
"order": [
[0, "desc"],
],
"info": false,
"columns": [
{"width": "15%", "searchable": true, "orderable": true, "type": "num"},
{"width": "5%", "searchable": true, "orderable": true},
{"width": "5%", "searchable": true, "orderable": true},
{"width": "3%", "searchable": true, "orderable": true},
{"width": "3%", "searchable": true, "orderable": true},
{"width": "65%", "searchable": true, "orderable": true},
],
});
errors.columns.adjust().draw();
}
});
}

// @reset history log
$('#resetHistory').on('click', function () {
if (!confirm("Are you sure you want to reset history log?")) {
return;
}
if (history) {
history.destroy();
$('#historyLog').children('tbody').remove();
}
$.ajax({
dataType: 'json',
type: 'GET',
jsonp: false,
url: 'historyreset',
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', getPassword());
},
success: function () {
getHistory();
getErrors();
},
error: function (data) {
alertMessage('alert-modal alert-error', data.statusText);
}
});
});

// @update history log
$('#updateHistory').on('click', function () {
getHistory();
});
$('#updateErrors').on('click', function () {
getErrors();
});


// @upload text
function uploadText(data, source, headers) {
@@ -845,48 +659,4 @@ define(['jquery', 'd3pie', 'visibility', 'app/stats', 'app/graph', 'app/config',
$(this).closest('form').find('button').attr('disabled').addClass('disabled');
}
});

// @upload symbols from modal
function saveSymbols(action, id, is_cluster) {
var inputs = $('#' + id + ' :input[data-role="numerictextbox"]');
var url = action;
var values = [];
$(inputs).each(function () {
values.push({
name: $(this).attr('id').substring(5),
value: parseFloat($(this).val())
});
});
if (is_cluster) {
interface.queryNeighbours(url, function () {
alertMessage('alert-modal alert-success', 'Symbols successfully saved');
}, function (serv, qXHR, textStatus, errorThrown) {
alertMessage('alert-modal alert-error',
'Save symbols error on ' +
serv.name + ': ' + errorThrown);
}, "POST", {}, {
data: JSON.stringify(values),
dataType: "json",
});
}
else {
$.ajax({
data: JSON.stringify(values),
dataType: 'json',
type: 'POST',
url: url,
jsonp: false,
beforeSend: function (xhr) {
xhr.setRequestHeader('Password', getPassword());
},
success: function () {
alertMessage('alert-modal alert-success', 'Symbols successfully saved');
},
error: function (data) {
alertMessage('alert-modal alert-error', data.statusText);
}
});
}
}
// @connect to server
});

Loading…
Cancel
Save