2017-12-09 20:17:15 +08:00
|
|
|
jQuery(function($){
|
2018-07-22 17:03:32 +08:00
|
|
|
if (localStorage.getItem("current_page") === null) {
|
|
|
|
var current_page = {};
|
|
|
|
} else {
|
|
|
|
var current_page = JSON.parse(localStorage.getItem('current_page'));
|
|
|
|
}
|
2017-12-09 20:17:15 +08:00
|
|
|
// http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
|
|
|
|
var entityMap={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};
|
|
|
|
function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
|
|
|
|
function humanFileSize(i){if(Math.abs(i)<1024)return i+" B";var B=["KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],e=-1;do{i/=1024,++e}while(Math.abs(i)>=1024&&e<B.length-1);return i.toFixed(1)+" "+B[e]}
|
2018-12-16 04:24:39 +08:00
|
|
|
function hashCode(t){for(var n=0,r=0;r<t.length;r++)n=t.charCodeAt(r)+((n<<5)-n);return n}
|
|
|
|
function intToRGB(t){var n=(16777215&t).toString(16).toUpperCase();return"00000".substring(0,6-n.length)+n}
|
2018-07-22 17:03:32 +08:00
|
|
|
$(".refresh_table").on('click', function(e) {
|
2017-12-09 20:17:15 +08:00
|
|
|
e.preventDefault();
|
2018-07-22 17:03:32 +08:00
|
|
|
var table_name = $(this).data('table');
|
|
|
|
$('#' + table_name).find("tr.footable-empty").remove();
|
|
|
|
draw_table = $(this).data('draw');
|
|
|
|
eval(draw_table + '()');
|
2017-12-09 20:17:15 +08:00
|
|
|
});
|
2018-07-22 17:03:32 +08:00
|
|
|
function table_log_ready(ft, name) {
|
2019-10-11 14:51:40 +08:00
|
|
|
heading = ft.$el.parents('.panel').find('.panel-heading')
|
2018-07-22 17:03:32 +08:00
|
|
|
var ft_paging = ft.use(FooTable.Paging)
|
|
|
|
$(heading).children('.table-lines').text(function(){
|
|
|
|
return ft_paging.totalRows;
|
|
|
|
})
|
|
|
|
if (current_page[name]) {
|
|
|
|
ft_paging.goto(parseInt(current_page[name]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function table_log_paging(ft, name) {
|
|
|
|
var ft_paging = ft.use(FooTable.Paging)
|
|
|
|
current_page[name] = ft_paging.current;
|
|
|
|
localStorage.setItem('current_page', JSON.stringify(current_page));
|
|
|
|
}
|
2017-12-09 20:17:15 +08:00
|
|
|
function draw_autodiscover_logs() {
|
|
|
|
ft_autodiscover_logs = FooTable.init('#autodiscover_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"ua","title":"User-Agent","style":{"min-width":"200px"}},
|
|
|
|
{"name":"user","title":"Username","style":{"min-width":"200px"}},
|
|
|
|
{"name":"service","title":"Service"},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/autodiscover/100',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw autodiscover log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'autodiscover_log');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
2018-07-22 17:03:32 +08:00
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
|
|
|
table_log_ready(ft, 'autodiscover_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'autodiscover_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_postfix_logs() {
|
|
|
|
ft_postfix_logs = FooTable.init('#postfix_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"priority","title":lang.priority,"style":{"width":"80px"}},
|
|
|
|
{"name":"message","title":lang.message},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/postfix',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw postfix log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'postfix_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'postfix_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_watchdog_logs() {
|
|
|
|
ft_watchdog_logs = FooTable.init('#watchdog_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"service","title":"Service"},
|
|
|
|
{"name":"trend","title":"Trend"},
|
|
|
|
{"name":"message","title":lang.message},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/watchdog',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw watchdog log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'watchdog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'postfix_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'postfix_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_api_logs() {
|
|
|
|
ft_api_logs = FooTable.init('#api_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"uri","title":"URI","style":{"width":"310px"}},
|
|
|
|
{"name":"method","title":"Method","style":{"width":"80px"}},
|
|
|
|
{"name":"remote","title":"IP","style":{"width":"80px"}},
|
2018-08-04 02:31:33 +08:00
|
|
|
{"name":"data","title":"Data","breakpoints": "all","style":{"word-break":"break-all"}},
|
2017-12-09 20:17:15 +08:00
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/api',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw api log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'apilog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'api_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'api_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-12-16 04:24:39 +08:00
|
|
|
function draw_rl_logs() {
|
|
|
|
ft_rl_logs = FooTable.init('#rl_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"indicator","title":" ","style":{"width":"50px"}},
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.last_applied,"style":{"width":"170px"}},
|
|
|
|
{"name":"rl_name","title":lang.rate_name},
|
|
|
|
{"name":"from","title":lang.sender},
|
|
|
|
{"name":"rcpt","title":lang.recipients},
|
|
|
|
{"name":"user","title":lang.authed_user},
|
|
|
|
{"name":"message_id","title":"Msg ID","breakpoints": "all","style":{"word-break":"break-all"}},
|
|
|
|
{"name":"header_from","title":"Header From","breakpoints": "all","style":{"word-break":"break-all"}},
|
|
|
|
{"name":"header_subject","title":"Subject","breakpoints": "all","style":{"word-break":"break-all"}},
|
|
|
|
{"name":"rl_hash","title":"Hash","breakpoints": "all","style":{"word-break":"break-all"}},
|
|
|
|
{"name":"qid","title":"Rspamd QID","breakpoints": "all","style":{"word-break":"break-all"}},
|
|
|
|
{"name":"ip","title":"IP","breakpoints": "all","style":{"word-break":"break-all"}},
|
|
|
|
{"name":"action","title":lang.action,"breakpoints": "all","style":{"word-break":"break-all"}},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/ratelimited',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw rl log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'rllog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2018-12-16 04:24:39 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
|
|
|
table_log_ready(ft, 'rl_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'rl_logs');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-08-04 02:31:33 +08:00
|
|
|
function draw_ui_logs() {
|
|
|
|
ft_api_logs = FooTable.init('#ui_logs', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"type","title":"Type"},
|
2018-08-14 05:20:40 +08:00
|
|
|
{"name":"task","title":"Task"},
|
2018-08-04 02:31:33 +08:00
|
|
|
{"name":"user","title":"User"},
|
|
|
|
{"name":"role","title":"Role"},
|
|
|
|
{"name":"remote","title":"IP"},
|
2018-08-21 23:41:04 +08:00
|
|
|
{"name":"msg","title":lang.message,"style":{"word-break":"break-all"}},
|
2018-08-04 02:31:33 +08:00
|
|
|
{"name":"call","title":"Call","breakpoints": "all"},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/ui',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw ui log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'mailcow_ui');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2018-08-04 02:31:33 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
|
|
|
table_log_ready(ft, 'ui_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'ui_logs');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-09 20:17:15 +08:00
|
|
|
function draw_acme_logs() {
|
|
|
|
ft_acme_logs = FooTable.init('#acme_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
2019-02-05 07:07:34 +08:00
|
|
|
{"name":"message","title":lang.message,"style":{"word-break":"break-all"}},
|
2017-12-09 20:17:15 +08:00
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/acme',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw acme log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'acme_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'acme_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-02-01 20:28:17 +08:00
|
|
|
function draw_netfilter_logs() {
|
|
|
|
ft_netfilter_logs = FooTable.init('#netfilter_log', {
|
2017-12-09 20:17:15 +08:00
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"priority","title":lang.priority,"style":{"width":"80px"}},
|
|
|
|
{"name":"message","title":lang.message},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
2018-02-01 20:28:17 +08:00
|
|
|
url: '/api/v1/get/logs/netfilter',
|
2017-12-09 20:17:15 +08:00
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
2018-02-01 20:28:17 +08:00
|
|
|
console.log('Cannot draw netfilter log table');
|
2017-12-09 20:17:15 +08:00
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'netfilter_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'netfilter_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_sogo_logs() {
|
|
|
|
ft_sogo_logs = FooTable.init('#sogo_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"priority","title":lang.priority,"style":{"width":"80px"}},
|
|
|
|
{"name":"message","title":lang.message},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/sogo',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw sogo log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'sogo_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'sogo_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_dovecot_logs() {
|
|
|
|
ft_dovecot_logs = FooTable.init('#dovecot_log', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name":"priority","title":lang.priority,"style":{"width":"80px"}},
|
|
|
|
{"name":"message","title":lang.message},
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/dovecot',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw dovecot log table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'dovecot_logs');
|
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'dovecot_logs');
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-07-24 20:03:16 +08:00
|
|
|
function rspamd_pie_graph() {
|
|
|
|
$.ajax({
|
|
|
|
url: '/api/v1/get/rspamd/actions',
|
|
|
|
success: function(graphdata){
|
|
|
|
graphdata.unshift(['Type', 'Count']);
|
|
|
|
google.charts.load('current', {'packages':['corechart']});
|
|
|
|
google.charts.setOnLoadCallback(drawChart);
|
|
|
|
|
|
|
|
function drawChart() {
|
|
|
|
|
|
|
|
var data = google.visualization.arrayToDataTable(graphdata);
|
2019-01-29 07:20:39 +08:00
|
|
|
var body_font_color = $('body').css("color");
|
2018-07-24 20:03:16 +08:00
|
|
|
var options = {
|
|
|
|
is3D: true,
|
2018-07-25 07:09:19 +08:00
|
|
|
sliceVisibilityThreshold: 0,
|
2018-07-24 20:03:16 +08:00
|
|
|
pieSliceText: 'percentage',
|
2019-01-29 07:20:39 +08:00
|
|
|
backgroundColor: { fill:'transparent' },
|
|
|
|
legend: {textStyle: {color: body_font_color}},
|
2018-07-24 20:03:16 +08:00
|
|
|
chartArea: {
|
|
|
|
left: 0,
|
|
|
|
right: 0,
|
|
|
|
top: 20,
|
|
|
|
width: '100%',
|
|
|
|
height: '100%'
|
|
|
|
},
|
2018-07-25 07:09:19 +08:00
|
|
|
|
2018-07-24 20:03:16 +08:00
|
|
|
slices: {
|
|
|
|
0: { color: '#DC3023' },
|
|
|
|
1: { color: '#59ABE3' },
|
|
|
|
2: { color: '#FFA400' },
|
|
|
|
3: { color: '#FFA400' },
|
|
|
|
4: { color: '#26A65B' }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var chart = new google.visualization.PieChart(document.getElementById('rspamd_donut'));
|
|
|
|
|
|
|
|
chart.draw(data, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-09 20:17:15 +08:00
|
|
|
function draw_rspamd_history() {
|
|
|
|
ft_rspamd_history = FooTable.init('#rspamd_history', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"unix_time","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.time,"style":{"width":"170px"}},
|
|
|
|
{"name": "ip","title": "IP address","breakpoints": "all","style": {"minWidth": 88}},
|
|
|
|
{"name": "sender_mime","title": "From","breakpoints": "xs sm md","style": {"minWidth": 100}},
|
2019-01-29 07:20:39 +08:00
|
|
|
{"name": "rcpt","title": "To","breakpoints": "xs sm md","style": {"minWidth": 100}},
|
2017-12-09 20:17:15 +08:00
|
|
|
{"name": "subject","title": "Subject","breakpoints": "all","style": {"word-break": "break-all","minWidth": 150}},
|
|
|
|
{"name": "action","title": "Action","style": {"minwidth": 82}},
|
|
|
|
{"name": "score","title": "Score","style": {"maxWidth": 110},},
|
|
|
|
{"name": "symbols","title": "Symbols","breakpoints": "all",},
|
|
|
|
{"name": "size","title": "Msg size","breakpoints": "all","style": {"minwidth": 50},"formatter": function(value){return humanFileSize(value);}},
|
|
|
|
{"name": "scan_time","title": "Scan time","breakpoints": "all","style": {"maxWidth": 72},},
|
|
|
|
{"name": "message-id","title": "ID","breakpoints": "all","style": {"minWidth": 130,"overflow": "hidden","textOverflow": "ellipsis","wordBreak": "break-all","whiteSpace": "normal"}},
|
|
|
|
{"name": "user","title": "Authenticated user","breakpoints": "xs sm md","style": {"minWidth": 100}}
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/logs/rspamd-history',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw rspamd history table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
return process_table_data(data, 'rspamd_history');
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
2019-09-22 21:10:56 +08:00
|
|
|
"filtering": {"enabled": true,"delay": 1200,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
2017-12-09 20:17:15 +08:00
|
|
|
"sorting": {"enabled": true},
|
|
|
|
"on": {
|
|
|
|
"ready.ft.table": function(e, ft){
|
2018-07-22 17:03:32 +08:00
|
|
|
table_log_ready(ft, 'rspamd_history');
|
2019-10-11 14:51:40 +08:00
|
|
|
heading = ft.$el.parents('.panel').find('.panel-heading')
|
2018-07-22 17:03:32 +08:00
|
|
|
$(heading).children('.table-lines').text(function(){
|
2017-12-09 20:17:15 +08:00
|
|
|
var ft_paging = ft.use(FooTable.Paging)
|
|
|
|
return ft_paging.totalRows;
|
|
|
|
})
|
2018-07-24 20:03:16 +08:00
|
|
|
rspamd_pie_graph();
|
2018-07-22 17:03:32 +08:00
|
|
|
},
|
|
|
|
"after.ft.paging": function(e, ft){
|
|
|
|
table_log_paging(ft, 'rspamd_history');
|
2018-06-08 15:13:26 +08:00
|
|
|
}
|
2018-05-21 05:30:17 +08:00
|
|
|
}
|
|
|
|
});
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
function process_table_data(data, table) {
|
|
|
|
if (table == 'rspamd_history') {
|
|
|
|
$.each(data, function (i, item) {
|
2019-01-29 07:20:39 +08:00
|
|
|
if (item.rcpt_mime != "") {
|
|
|
|
item.rcpt = item.rcpt_mime.join(", ");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.rcpt = item.rcpt_smtp.join(", ");
|
|
|
|
}
|
2019-10-12 19:30:29 +08:00
|
|
|
item.symbols = Object.keys(item.symbols).sort(function (a, b) {
|
2019-10-12 19:29:08 +08:00
|
|
|
if (item.symbols[a].score === 0) return 1
|
|
|
|
if (item.symbols[b].score === 0) return -1
|
|
|
|
if (item.symbols[b].score < 0 && item.symbols[a].score < 0) {
|
|
|
|
return item.symbols[a].score - item.symbols[b].score
|
|
|
|
}
|
|
|
|
if (item.symbols[b].score > 0 && item.symbols[a].score > 0) {
|
|
|
|
return item.symbols[b].score - item.symbols[a].score
|
|
|
|
}
|
|
|
|
return item.symbols[b].score - item.symbols[a].score
|
|
|
|
}).map(function(key) {
|
2017-12-09 20:17:15 +08:00
|
|
|
var sym = item.symbols[key];
|
2019-10-12 19:26:40 +08:00
|
|
|
if (sym.score < 0) {
|
2017-12-09 20:17:15 +08:00
|
|
|
sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)'
|
|
|
|
}
|
2019-10-12 19:26:40 +08:00
|
|
|
else if (sym.score === 0) {
|
|
|
|
sym.score_formatted = '(<span><b>' + sym.score + '</b></span>)'
|
|
|
|
}
|
2017-12-09 20:17:15 +08:00
|
|
|
else {
|
|
|
|
sym.score_formatted = '(<span class="text-danger"><b>' + sym.score + '</b></span>)'
|
|
|
|
}
|
|
|
|
var str = '<strong>' + key + '</strong> ' + sym.score_formatted;
|
|
|
|
if (sym.options) {
|
2019-10-12 19:27:21 +08:00
|
|
|
str += ' [' + sym.options.join(", ") + "]";
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
2019-10-12 19:30:29 +08:00
|
|
|
return str
|
|
|
|
}).join('<br>\n');
|
2019-08-14 06:22:40 +08:00
|
|
|
item.subject = escapeHtml(item.subject);
|
2019-10-13 05:42:23 +08:00
|
|
|
var scan_time = item.time_real.toFixed(3);
|
|
|
|
if (item.time_virtual) {
|
|
|
|
scan_time += ' / ' + item.time_virtual.toFixed(3);
|
|
|
|
}
|
2017-12-09 20:17:15 +08:00
|
|
|
item.scan_time = {
|
|
|
|
"options": {
|
|
|
|
"sortValue": item.time_real
|
|
|
|
},
|
|
|
|
"value": scan_time
|
|
|
|
};
|
|
|
|
if (item.action === 'clean' || item.action === 'no action') {
|
|
|
|
item.action = "<div class='label label-success'>" + item.action + "</div>";
|
|
|
|
} else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') {
|
|
|
|
item.action = "<div class='label label-warning'>" + item.action + "</div>";
|
|
|
|
} else if (item.action === 'spam' || item.action === 'reject') {
|
|
|
|
item.action = "<div class='label label-danger'>" + item.action + "</div>";
|
|
|
|
} else {
|
|
|
|
item.action = "<div class='label label-info'>" + item.action + "</div>";
|
|
|
|
}
|
|
|
|
var score_content;
|
|
|
|
if (item.score < item.required_score) {
|
|
|
|
score_content = "[ <span class='text-success'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
|
|
|
|
} else {
|
|
|
|
score_content = "[ <span class='text-danger'>" + item.score.toFixed(2) + " / " + item.required_score + "</span> ]";
|
|
|
|
}
|
|
|
|
item.score = {
|
|
|
|
"options": {
|
|
|
|
"sortValue": item.score
|
|
|
|
},
|
|
|
|
"value": score_content
|
|
|
|
};
|
|
|
|
if (item.user == null) {
|
|
|
|
item.user = "none";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (table == 'autodiscover_log') {
|
|
|
|
$.each(data, function (i, item) {
|
2019-05-18 21:34:57 +08:00
|
|
|
if (item.ua == null) {
|
|
|
|
item.ua = 'unknown';
|
2019-08-14 06:22:40 +08:00
|
|
|
} else {
|
|
|
|
item.ua = escapeHtml(item.ua);
|
2019-05-18 21:34:57 +08:00
|
|
|
}
|
2017-12-09 20:17:15 +08:00
|
|
|
item.ua = '<span style="font-size:small">' + item.ua + '</span>';
|
|
|
|
if (item.service == "activesync") {
|
|
|
|
item.service = '<span class="label label-info">ActiveSync</span>';
|
|
|
|
}
|
|
|
|
else if (item.service == "imap") {
|
|
|
|
item.service = '<span class="label label-success">IMAP, SMTP, Cal-/CardDAV</span>';
|
|
|
|
}
|
|
|
|
else {
|
2019-08-14 06:22:40 +08:00
|
|
|
item.service = '<span class="label label-danger">' + escapeHtml(item.service) + '</span>';
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (table == 'watchdog') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item.message == null) {
|
|
|
|
item.message = 'Health level: ' + item.lvl + '% (' + item.hpnow + '/' + item.hptotal + ')';
|
|
|
|
if (item.hpdiff < 0) {
|
|
|
|
item.trend = '<span class="label label-danger"><span class="glyphicon glyphicon-arrow-down"></span> ' + item.hpdiff + '</span>';
|
|
|
|
}
|
|
|
|
else if (item.hpdiff == 0) {
|
|
|
|
item.trend = '<span class="label label-info"><span class="glyphicon glyphicon-arrow-right"></span> ' + item.hpdiff + '</span>';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.trend = '<span class="label label-success"><span class="glyphicon glyphicon-arrow-up"></span> ' + item.hpdiff + '</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.trend = '';
|
|
|
|
item.service = '';
|
|
|
|
}
|
|
|
|
});
|
2018-08-04 02:31:33 +08:00
|
|
|
} else if (table == 'mailcow_ui') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item === null) { return true; }
|
|
|
|
item.user = escapeHtml(item.user);
|
2019-08-15 04:19:50 +08:00
|
|
|
item.call = escapeHtml(item.call);
|
2018-08-14 05:20:40 +08:00
|
|
|
item.task = '<code>' + item.task + '</code>';
|
2018-08-04 02:31:33 +08:00
|
|
|
item.type = '<span class="label label-' + item.type + '">' + item.type + '</span>';
|
|
|
|
});
|
2017-12-09 20:17:15 +08:00
|
|
|
} else if (table == 'general_syslog') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item === null) { return true; }
|
2018-10-11 17:59:23 +08:00
|
|
|
if (item.message.match("^base64,")) {
|
2019-02-05 07:07:34 +08:00
|
|
|
item.message = atob(item.message.slice(7)).replace(/\\n/g, "<br />");
|
2018-10-11 17:59:23 +08:00
|
|
|
} else {
|
|
|
|
item.message = escapeHtml(item.message);
|
|
|
|
}
|
2019-08-14 03:12:24 +08:00
|
|
|
item.call = escapeHtml(item.call);
|
2017-12-09 20:17:15 +08:00
|
|
|
var danger_class = ["emerg", "alert", "crit", "err"];
|
|
|
|
var warning_class = ["warning", "warn"];
|
|
|
|
var info_class = ["notice", "info", "debug"];
|
|
|
|
if (jQuery.inArray(item.priority, danger_class) !== -1) {
|
|
|
|
item.priority = '<span class="label label-danger">' + item.priority + '</span>';
|
|
|
|
} else if (jQuery.inArray(item.priority, warning_class) !== -1) {
|
|
|
|
item.priority = '<span class="label label-warning">' + item.priority + '</span>';
|
|
|
|
} else if (jQuery.inArray(item.priority, info_class) !== -1) {
|
|
|
|
item.priority = '<span class="label label-info">' + item.priority + '</span>';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (table == 'apilog') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item === null) { return true; }
|
|
|
|
if (item.method == 'GET') {
|
|
|
|
item.method = '<span class="label label-success">' + item.method + '</span>';
|
|
|
|
} else if (item.method == 'POST') {
|
|
|
|
item.method = '<span class="label label-warning">' + item.method + '</span>';
|
|
|
|
}
|
2019-08-09 20:14:41 +08:00
|
|
|
item.data = escapeHtml(item.data);
|
2017-12-09 20:17:15 +08:00
|
|
|
});
|
2018-12-16 04:24:39 +08:00
|
|
|
} else if (table == 'rllog') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item.user == null) {
|
|
|
|
item.user = "none";
|
|
|
|
}
|
|
|
|
if (item.rl_hash == null) {
|
|
|
|
item.rl_hash = "err";
|
|
|
|
}
|
2018-12-20 18:23:35 +08:00
|
|
|
item.indicator = '<span style="border-right:6px solid #' + intToRGB(hashCode(item.rl_hash)) + ';padding-left:5px;"> </span>';
|
2018-12-16 04:24:39 +08:00
|
|
|
if (item.rl_hash != 'err') {
|
|
|
|
item.action = '<a href="#" data-action="delete_selected" data-id="single-hash" data-api-url="delete/rlhash" data-item="' + encodeURI(item.rl_hash) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.reset_limit + '</a>';
|
|
|
|
}
|
|
|
|
});
|
2017-12-09 20:17:15 +08:00
|
|
|
}
|
|
|
|
return data
|
|
|
|
};
|
|
|
|
$('.add_log_lines').on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var log_table= $(this).data("table")
|
2018-08-04 02:31:33 +08:00
|
|
|
var new_nrows = $(this).data("nrows")
|
2017-12-09 20:17:15 +08:00
|
|
|
var post_process = $(this).data("post-process")
|
|
|
|
var log_url = $(this).data("log-url")
|
|
|
|
if (log_table === undefined || new_nrows === undefined || post_process === undefined || log_url === undefined) {
|
|
|
|
console.log("no data-table or data-nrows or log_url or data-post-process attr found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ft = FooTable.get($('#' + log_table))) {
|
2019-10-11 14:51:40 +08:00
|
|
|
var heading = ft.$el.parents('.panel').find('.panel-heading')
|
2017-12-09 20:17:15 +08:00
|
|
|
var ft_paging = ft.use(FooTable.Paging)
|
2018-08-04 02:31:33 +08:00
|
|
|
var load_rows = (ft_paging.totalRows + 1) + '-' + (ft_paging.totalRows + new_nrows)
|
2017-12-09 20:17:15 +08:00
|
|
|
$.get('/api/v1/get/logs/' + log_url + '/' + load_rows).then(function(data){
|
|
|
|
if (data.length === undefined) { mailcow_alert_box(lang.no_new_rows, "info"); return; }
|
|
|
|
var rows = process_table_data(data, post_process);
|
|
|
|
var rows_now = (ft_paging.totalRows + data.length);
|
2018-07-22 17:03:32 +08:00
|
|
|
$(heading).children('.table-lines').text(rows_now)
|
2017-12-09 20:17:15 +08:00
|
|
|
mailcow_alert_box(data.length + lang.additional_rows, "success");
|
|
|
|
ft.rows.load(rows, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// Initial table drawings
|
|
|
|
draw_postfix_logs();
|
|
|
|
draw_autodiscover_logs();
|
|
|
|
draw_dovecot_logs();
|
|
|
|
draw_sogo_logs();
|
|
|
|
draw_watchdog_logs();
|
|
|
|
draw_acme_logs();
|
|
|
|
draw_api_logs();
|
2018-12-16 04:24:39 +08:00
|
|
|
draw_rl_logs();
|
2018-08-04 02:31:33 +08:00
|
|
|
draw_ui_logs();
|
2018-02-01 20:28:17 +08:00
|
|
|
draw_netfilter_logs();
|
2017-12-09 20:17:15 +08:00
|
|
|
draw_rspamd_history();
|
2018-05-21 05:30:17 +08:00
|
|
|
$(window).resize(function () {
|
|
|
|
var timer;
|
|
|
|
clearTimeout(timer);
|
|
|
|
timer = setTimeout(function () {
|
2018-07-24 20:03:16 +08:00
|
|
|
rspamd_pie_graph();
|
2018-05-21 05:30:17 +08:00
|
|
|
}, 500);
|
|
|
|
});
|
2018-05-31 23:58:51 +08:00
|
|
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
|
|
|
var target = $(e.target).attr("href");
|
|
|
|
if ((target == '#tab-rspamd-history')) {
|
2018-07-24 20:03:16 +08:00
|
|
|
rspamd_pie_graph();
|
2018-05-31 23:58:51 +08:00
|
|
|
}
|
|
|
|
});
|
2018-02-01 20:28:17 +08:00
|
|
|
});
|