2021-02-11 09:34:21 +01:00
|
|
|
$(document).ready(function() {
|
|
|
|
// Parse seconds ago to date
|
|
|
|
// Get "now" timestamp
|
|
|
|
var ts_now = Math.round((new Date()).getTime() / 1000);
|
|
|
|
$('.parse_s_ago').each(function(i, parse_s_ago) {
|
|
|
|
var started_s_ago = parseInt($(this).text(), 10);
|
|
|
|
if (typeof started_s_ago != 'NaN') {
|
|
|
|
var started_date = new Date((ts_now - started_s_ago) * 1000);
|
2021-02-12 21:22:05 +01:00
|
|
|
if (started_date instanceof Date && !isNaN(started_date)) {
|
|
|
|
var started_local_date = started_date.toLocaleDateString(undefined, {
|
|
|
|
year: "numeric",
|
|
|
|
month: "2-digit",
|
|
|
|
day: "2-digit",
|
|
|
|
hour: "2-digit",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: "2-digit"
|
|
|
|
});
|
|
|
|
$(this).text(started_local_date);
|
|
|
|
} else {
|
|
|
|
$(this).text('-');
|
|
|
|
}
|
2021-02-11 09:34:21 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Parse general dates
|
|
|
|
$('.parse_date').each(function(i, parse_date) {
|
|
|
|
var started_date = new Date(Date.parse($(this).text()));
|
|
|
|
if (typeof started_date != 'NaN') {
|
|
|
|
var started_local_date = started_date.toLocaleDateString(undefined, {
|
|
|
|
year: "numeric",
|
|
|
|
month: "2-digit",
|
|
|
|
day: "2-digit",
|
|
|
|
hour: "2-digit",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: "2-digit"
|
|
|
|
});
|
|
|
|
$(this).text(started_local_date);
|
|
|
|
}
|
|
|
|
});
|
2022-08-09 20:29:33 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
// set update loop container list
|
|
|
|
containersToUpdate = {}
|
2022-08-09 20:29:33 +02:00
|
|
|
// set default ChartJs Font Color
|
|
|
|
Chart.defaults.color = '#999';
|
2022-08-22 16:08:01 +02:00
|
|
|
// create host cpu and mem charts
|
|
|
|
createHostCpuAndMemChart();
|
2022-08-09 20:29:33 +02:00
|
|
|
// check for new version
|
|
|
|
check_update(mailcow_info.version_tag, mailcow_info.project_url);
|
2022-08-22 16:08:01 +02:00
|
|
|
update_container_stats()
|
2021-02-11 09:34:21 +01:00
|
|
|
});
|
2017-12-09 13:17:15 +01:00
|
|
|
jQuery(function($){
|
2018-07-22 11:03:32 +02:00
|
|
|
if (localStorage.getItem("current_page") === null) {
|
|
|
|
var current_page = {};
|
|
|
|
} else {
|
|
|
|
var current_page = JSON.parse(localStorage.getItem('current_page'));
|
|
|
|
}
|
2017-12-09 13:17:15 +01: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-15 21:24:39 +01: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 11:03:32 +02:00
|
|
|
$(".refresh_table").on('click', function(e) {
|
2017-12-09 13:17:15 +01:00
|
|
|
e.preventDefault();
|
2018-07-22 11:03:32 +02:00
|
|
|
var table_name = $(this).data('table');
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#' + table_name).DataTable().ajax.reload();
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
function draw_autodiscover_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#autodiscover_log') ) {
|
|
|
|
$('#autodiscover_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#autodiscover_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/autodiscover/100",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'autodiscover_log');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'User-Agent',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'ua',
|
|
|
|
defaultContent: ''
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: 'Username',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'user',
|
|
|
|
defaultContent: ''
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: 'IP',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'ip',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Service',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'service',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_postfix_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#postfix_log') ) {
|
|
|
|
$('#postfix_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#postfix_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/postfix",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.priority,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'priority',
|
|
|
|
defaultContent: ''
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.message,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_watchdog_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#watchdog_log') ) {
|
|
|
|
$('#watchdog_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#watchdog_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/watchdog",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'watchdog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Service',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'service',
|
|
|
|
defaultContent: ''
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: 'Trend',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'trend',
|
|
|
|
defaultContent: ''
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.message,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_api_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#api_log') ) {
|
|
|
|
$('#api_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#api_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/api",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'apilog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'URI',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'uri',
|
2022-08-23 12:43:23 +02:00
|
|
|
defaultContent: '',
|
|
|
|
className: 'text-break min-tablet none'
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Method',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'method',
|
|
|
|
defaultContent: ''
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: 'IP',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'remote',
|
|
|
|
defaultContent: ''
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: 'Data',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'data',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
2018-12-15 21:24:39 +01:00
|
|
|
function draw_rl_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#rl_log') ) {
|
|
|
|
$('#rl_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#rl_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/ratelimited",
|
|
|
|
dataSrc: function(data){
|
2018-12-15 21:24:39 +01:00
|
|
|
return process_table_data(data, 'rllog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: ' ',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'indicator',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: lang.rate_name,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'rl_name',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: lang.sender,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'from',
|
|
|
|
defaultContent: ''
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.recipients,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'rcpt',
|
|
|
|
defaultContent: ''
|
2018-12-15 21:24:39 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.authed_user,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'user',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Msg ID',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message_id',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Header From',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'header_from',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Subject',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'header_subject',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Hash',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'rl_hash',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Rspamd QID',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'qid',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'IP',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'ip',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: lang.action,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'action',
|
|
|
|
defaultContent: ''
|
2018-12-15 21:24:39 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2018-12-15 21:24:39 +01:00
|
|
|
});
|
|
|
|
}
|
2018-08-03 20:31:33 +02:00
|
|
|
function draw_ui_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#ui_logs') ) {
|
|
|
|
$('#ui_logs').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#ui_logs').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/ui",
|
|
|
|
dataSrc: function(data){
|
2018-08-03 20:31:33 +02:00
|
|
|
return process_table_data(data, 'mailcow_ui');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Type',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'type',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Task',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'task',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'User',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'user',
|
|
|
|
defaultContent: ''
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: 'Role',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'role',
|
|
|
|
defaultContent: ''
|
2018-08-03 20:31:33 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: 'IP',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'remote',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: lang.message,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'msg',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Call',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'call',
|
2022-08-23 12:43:23 +02:00
|
|
|
defaultContent: '',
|
|
|
|
className: 'none text-break'
|
2018-08-03 20:31:33 +02:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2018-08-03 20:31:33 +02:00
|
|
|
});
|
|
|
|
}
|
2021-06-04 14:29:39 +02:00
|
|
|
function draw_sasl_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#sasl_logs') ) {
|
|
|
|
$('#sasl_logs').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#sasl_logs').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/sasl",
|
|
|
|
dataSrc: function(data){
|
2021-06-04 14:29:39 +02:00
|
|
|
return process_table_data(data, 'sasl_log_table');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.username,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'username',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: lang.service,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'service',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'IP',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'real_rip',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: lang.login_time,
|
|
|
|
data: 'datetime',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data.replace(/-/g, "/"));
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
2021-06-04 14:29:39 +02:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2021-06-04 14:29:39 +02:00
|
|
|
});
|
|
|
|
}
|
2017-12-09 13:17:15 +01:00
|
|
|
function draw_acme_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#acme_log') ) {
|
|
|
|
$('#acme_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#acme_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/acme",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.message,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
2018-02-01 13:28:17 +01:00
|
|
|
function draw_netfilter_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#netfilter_log') ) {
|
|
|
|
$('#netfilter_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#netfilter_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/netfilter",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.priority,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'priority',
|
|
|
|
defaultContent: ''
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.message,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_sogo_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#sogo_log') ) {
|
|
|
|
$('#sogo_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#sogo_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/sogo",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.priority,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'priority',
|
|
|
|
defaultContent: ''
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.message,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_dovecot_logs() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#dovecot_log') ) {
|
|
|
|
$('#dovecot_log').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#dovecot_log').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
2022-06-06 20:38:24 +02:00
|
|
|
order: [[0, 'desc']],
|
2022-05-17 14:08:22 +02:00
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/dovecot",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'general_syslog');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
2019-12-05 15:35:10 +01:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.priority,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'priority',
|
|
|
|
defaultContent: ''
|
2018-07-22 11:03:32 +02:00
|
|
|
},
|
2022-05-17 14:08:22 +02:00
|
|
|
{
|
|
|
|
title: lang.message,
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message',
|
|
|
|
defaultContent: ''
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
2018-07-24 14:03:16 +02:00
|
|
|
function rspamd_pie_graph() {
|
|
|
|
$.ajax({
|
|
|
|
url: '/api/v1/get/rspamd/actions',
|
2020-05-19 20:20:05 +02:00
|
|
|
async: true,
|
2019-11-11 08:14:02 +01:00
|
|
|
success: function(data){
|
2022-06-06 20:38:24 +02:00
|
|
|
console.log(data);
|
2018-07-24 14:03:16 +02:00
|
|
|
|
2019-11-11 08:14:02 +01:00
|
|
|
var total = 0;
|
|
|
|
$(data).map(function(){total += this[1];});
|
|
|
|
var labels = $.makeArray($(data).map(function(){return this[0] + ' ' + Math.round(this[1]/total * 100) + '%';}));
|
|
|
|
var values = $.makeArray($(data).map(function(){return this[1];}));
|
2022-06-06 20:38:24 +02:00
|
|
|
console.log(values);
|
2018-07-24 14:03:16 +02:00
|
|
|
|
2019-11-11 08:14:02 +01:00
|
|
|
var graphdata = {
|
|
|
|
labels: labels,
|
|
|
|
datasets: [{
|
|
|
|
data: values,
|
|
|
|
backgroundColor: ['#DC3023', '#59ABE3', '#FFA400', '#FFA400', '#26A65B']
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
responsive: true,
|
|
|
|
maintainAspectRatio: false,
|
|
|
|
plugins: {
|
|
|
|
datalabels: {
|
|
|
|
color: '#FFF',
|
|
|
|
font: {
|
|
|
|
weight: 'bold'
|
|
|
|
},
|
|
|
|
display: function(context) {
|
|
|
|
return context.dataset.data[context.dataIndex] !== 0;
|
|
|
|
},
|
|
|
|
formatter: function(value, context) {
|
|
|
|
return Math.round(value/total*100) + '%';
|
|
|
|
}
|
2018-07-24 14:03:16 +02:00
|
|
|
}
|
2019-11-11 08:14:02 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var chartcanvas = document.getElementById('rspamd_donut');
|
2022-06-06 20:38:24 +02:00
|
|
|
Chart.register('ChartDataLabels');
|
2020-05-19 20:20:05 +02:00
|
|
|
if(typeof chart == 'undefined') {
|
|
|
|
chart = new Chart(chartcanvas.getContext("2d"), {
|
|
|
|
plugins: [ChartDataLabels],
|
|
|
|
type: 'doughnut',
|
|
|
|
data: graphdata,
|
|
|
|
options: options
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
chart.destroy();
|
|
|
|
chart = new Chart(chartcanvas.getContext("2d"), {
|
|
|
|
plugins: [ChartDataLabels],
|
|
|
|
type: 'doughnut',
|
|
|
|
data: graphdata,
|
|
|
|
options: options
|
|
|
|
});
|
|
|
|
}
|
2018-07-24 14:03:16 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-12-09 13:17:15 +01:00
|
|
|
function draw_rspamd_history() {
|
2022-07-08 11:31:08 +02:00
|
|
|
// just recalc width if instance already exists
|
|
|
|
if ($.fn.DataTable.isDataTable('#rspamd_history') ) {
|
|
|
|
$('#rspamd_history').DataTable().columns.adjust().responsive.recalc();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-17 14:08:22 +02:00
|
|
|
$('#rspamd_history').DataTable({
|
|
|
|
processing: true,
|
|
|
|
serverSide: false,
|
|
|
|
language: lang_datatables,
|
|
|
|
ajax: {
|
|
|
|
type: "GET",
|
|
|
|
url: "/api/v1/get/logs/rspamd-history",
|
|
|
|
dataSrc: function(data){
|
2017-12-09 13:17:15 +01:00
|
|
|
return process_table_data(data, 'rspamd_history');
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
title: lang.time,
|
|
|
|
data: 'time',
|
2022-07-01 16:20:39 +02:00
|
|
|
defaultContent: '',
|
2022-05-17 14:08:22 +02:00
|
|
|
render: function(data, type){
|
|
|
|
var date = new Date(data ? data * 1000 : 0);
|
|
|
|
return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'IP address',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'ip',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'From',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'sender_mime',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'To',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'rcpt',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Subject',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'subject',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Action',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'action',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Score',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'score',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Subject',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'header_subject',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Symbols',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'symbols',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Msg size',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'size',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Scan Time',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'scan_time',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'ID',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'message-id',
|
|
|
|
defaultContent: ''
|
2022-05-17 14:08:22 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Authenticated user',
|
2022-07-01 16:20:39 +02:00
|
|
|
data: 'user',
|
|
|
|
defaultContent: ''
|
2018-06-08 09:13:26 +02:00
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
]
|
2018-05-20 23:30:17 +02:00
|
|
|
});
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
function process_table_data(data, table) {
|
|
|
|
if (table == 'rspamd_history') {
|
|
|
|
$.each(data, function (i, item) {
|
2019-01-29 00:20:39 +01:00
|
|
|
if (item.rcpt_mime != "") {
|
2020-10-18 19:44:56 +02:00
|
|
|
item.rcpt = escapeHtml(item.rcpt_mime.join(", "));
|
2019-01-29 00:20:39 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-10-18 19:44:56 +02:00
|
|
|
item.rcpt = escapeHtml(item.rcpt_smtp.join(", "));
|
2019-01-29 00:20:39 +01:00
|
|
|
}
|
2019-10-12 13:30:29 +02:00
|
|
|
item.symbols = Object.keys(item.symbols).sort(function (a, b) {
|
2019-10-12 13:29:08 +02: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 13:17:15 +01:00
|
|
|
var sym = item.symbols[key];
|
2019-10-12 13:26:40 +02:00
|
|
|
if (sym.score < 0) {
|
2017-12-09 13:17:15 +01:00
|
|
|
sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)'
|
|
|
|
}
|
2019-10-12 13:26:40 +02:00
|
|
|
else if (sym.score === 0) {
|
|
|
|
sym.score_formatted = '(<span><b>' + sym.score + '</b></span>)'
|
|
|
|
}
|
2017-12-09 13:17:15 +01: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) {
|
2020-05-19 20:20:05 +02:00
|
|
|
str += ' [' + escapeHtml(sym.options.join(", ")) + "]";
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2019-10-12 13:30:29 +02:00
|
|
|
return str
|
|
|
|
}).join('<br>\n');
|
2019-08-14 00:22:40 +02:00
|
|
|
item.subject = escapeHtml(item.subject);
|
2019-10-12 23:42:23 +02:00
|
|
|
var scan_time = item.time_real.toFixed(3);
|
|
|
|
if (item.time_virtual) {
|
|
|
|
scan_time += ' / ' + item.time_virtual.toFixed(3);
|
|
|
|
}
|
2017-12-09 13:17:15 +01:00
|
|
|
item.scan_time = {
|
|
|
|
"options": {
|
|
|
|
"sortValue": item.time_real
|
|
|
|
},
|
|
|
|
"value": scan_time
|
|
|
|
};
|
|
|
|
if (item.action === 'clean' || item.action === 'no action') {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.action = "<div class='badge fs-6 bg-success'>" + item.action + "</div>";
|
2017-12-09 13:17:15 +01:00
|
|
|
} else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.action = "<div class='badge fs-6 bg-warning'>" + item.action + "</div>";
|
2017-12-09 13:17:15 +01:00
|
|
|
} else if (item.action === 'spam' || item.action === 'reject') {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.action = "<div class='badge fs-6 bg-danger'>" + item.action + "</div>";
|
2017-12-09 13:17:15 +01:00
|
|
|
} else {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.action = "<div class='badge fs-6 bg-info'>" + item.action + "</div>";
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
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 15:34:57 +02:00
|
|
|
if (item.ua == null) {
|
|
|
|
item.ua = 'unknown';
|
2019-08-14 00:22:40 +02:00
|
|
|
} else {
|
|
|
|
item.ua = escapeHtml(item.ua);
|
2019-05-18 15:34:57 +02:00
|
|
|
}
|
2017-12-09 13:17:15 +01:00
|
|
|
item.ua = '<span style="font-size:small">' + item.ua + '</span>';
|
|
|
|
if (item.service == "activesync") {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.service = '<span class="badge fs-6 bg-info">ActiveSync</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
else if (item.service == "imap") {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.service = '<span class="badge fs-6 bg-success">IMAP, SMTP, Cal-/CardDAV</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
else {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.service = '<span class="badge fs-6 bg-danger">' + escapeHtml(item.service) + '</span>';
|
2017-12-09 13:17:15 +01: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) {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.trend = '<span class="badge fs-6 bg-danger"><i class="bi bi-caret-down-fill"></i> ' + item.hpdiff + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
else if (item.hpdiff == 0) {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.trend = '<span class="badge fs-6 bg-info"><i class="bi bi-caret-right-fill"></i> ' + item.hpdiff + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
else {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.trend = '<span class="badge fs-6 bg-success"><i class="bi bi-caret-up-fill"></i> ' + item.hpdiff + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item.trend = '';
|
|
|
|
item.service = '';
|
|
|
|
}
|
|
|
|
});
|
2018-08-03 20:31:33 +02:00
|
|
|
} else if (table == 'mailcow_ui') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item === null) { return true; }
|
|
|
|
item.user = escapeHtml(item.user);
|
2019-08-14 22:19:50 +02:00
|
|
|
item.call = escapeHtml(item.call);
|
2018-08-13 23:20:40 +02:00
|
|
|
item.task = '<code>' + item.task + '</code>';
|
2022-06-14 15:52:59 +02:00
|
|
|
item.type = '<span class="badge fs-6 bg-' + item.type + '">' + item.type + '</span>';
|
2018-08-03 20:31:33 +02:00
|
|
|
});
|
2021-06-04 14:29:39 +02:00
|
|
|
} else if (table == 'sasl_log_table') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item === null) { return true; }
|
|
|
|
item.username = escapeHtml(item.username);
|
2022-06-14 15:52:59 +02:00
|
|
|
item.service = '<div class="badge fs-6 bg-secondary">' + item.service.toUpperCase() + '</div>';
|
2022-05-17 14:08:22 +02:00
|
|
|
});
|
2017-12-09 13:17:15 +01:00
|
|
|
} else if (table == 'general_syslog') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item === null) { return true; }
|
2018-10-11 11:59:23 +02:00
|
|
|
if (item.message.match("^base64,")) {
|
2021-02-11 09:34:21 +01:00
|
|
|
try {
|
|
|
|
item.message = atob(item.message.slice(7)).replace(/\\n/g, "<br />");
|
|
|
|
} catch(e) {
|
|
|
|
item.message = item.message.slice(7);
|
|
|
|
}
|
2018-10-11 11:59:23 +02:00
|
|
|
} else {
|
|
|
|
item.message = escapeHtml(item.message);
|
|
|
|
}
|
2019-08-13 21:12:24 +02:00
|
|
|
item.call = escapeHtml(item.call);
|
2017-12-09 13:17:15 +01: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) {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.priority = '<span class="badge fs-6 bg-danger">' + item.priority + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
} else if (jQuery.inArray(item.priority, warning_class) !== -1) {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.priority = '<span class="badge fs-6 bg-warning">' + item.priority + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
} else if (jQuery.inArray(item.priority, info_class) !== -1) {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.priority = '<span class="badge fs-6 bg-info">' + item.priority + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (table == 'apilog') {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
if (item === null) { return true; }
|
|
|
|
if (item.method == 'GET') {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.method = '<span class="badge fs-6 bg-success">' + item.method + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
} else if (item.method == 'POST') {
|
2022-06-14 15:52:59 +02:00
|
|
|
item.method = '<span class="badge fs-6 bg-warning">' + item.method + '</span>';
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
2019-08-09 14:14:41 +02:00
|
|
|
item.data = escapeHtml(item.data);
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
2018-12-15 21:24:39 +01: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 11:23:35 +01:00
|
|
|
item.indicator = '<span style="border-right:6px solid #' + intToRGB(hashCode(item.rl_hash)) + ';padding-left:5px;"> </span>';
|
2018-12-15 21:24:39 +01:00
|
|
|
if (item.rl_hash != 'err') {
|
2021-05-26 14:02:27 +02:00
|
|
|
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"><i class="bi bi-trash"></i> ' + lang.reset_limit + '</a>';
|
2018-12-15 21:24:39 +01:00
|
|
|
}
|
|
|
|
});
|
2017-12-09 13:17:15 +01:00
|
|
|
}
|
|
|
|
return data
|
|
|
|
};
|
|
|
|
$('.add_log_lines').on('click', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
var log_table= $(this).data("table")
|
2018-08-03 20:31:33 +02:00
|
|
|
var new_nrows = $(this).data("nrows")
|
2017-12-09 13:17:15 +01: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;
|
|
|
|
}
|
2022-05-17 14:08:22 +02:00
|
|
|
|
|
|
|
// BUG TODO: loading 100 results in loading 10 - loading 1000 results in loading 100
|
|
|
|
if (table = $('#' + log_table).DataTable()) {
|
|
|
|
var heading = $('#' + log_table).closest('.card').find('.card-header');
|
|
|
|
var load_rows = (table.page.len() + 1) + '-' + (table.page.len() + new_nrows)
|
|
|
|
|
2017-12-09 13:17:15 +01: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);
|
2022-05-17 14:08:22 +02:00
|
|
|
var rows_now = (table.page.len() + data.length);
|
2018-07-22 11:03:32 +02:00
|
|
|
$(heading).children('.table-lines').text(rows_now)
|
2017-12-09 13:17:15 +01:00
|
|
|
mailcow_alert_box(data.length + lang.additional_rows, "success");
|
2022-05-17 14:08:22 +02:00
|
|
|
table.rows.add(rows).draw();
|
2017-12-09 13:17:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
2022-05-19 21:29:01 +02:00
|
|
|
|
|
|
|
// detect element visibility changes
|
|
|
|
function onVisible(element, callback) {
|
2022-07-01 16:20:39 +02:00
|
|
|
$(document).ready(function() {
|
|
|
|
element_object = document.querySelector(element);
|
|
|
|
if (element_object === null) return;
|
|
|
|
|
2022-05-19 21:29:01 +02:00
|
|
|
new IntersectionObserver((entries, observer) => {
|
|
|
|
entries.forEach(entry => {
|
|
|
|
if(entry.intersectionRatio > 0) {
|
|
|
|
callback(element_object);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).observe(element_object);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Draw Table if tab is active
|
2022-06-08 11:49:05 +02:00
|
|
|
onVisible("[id^=postfix_log]", () => draw_postfix_logs());
|
|
|
|
onVisible("[id^=dovecot_log]", () => draw_dovecot_logs());
|
|
|
|
onVisible("[id^=sogo_log]", () => draw_sogo_logs());
|
|
|
|
onVisible("[id^=watchdog_log]", () => draw_watchdog_logs());
|
|
|
|
onVisible("[id^=autodiscover_log]", () => draw_autodiscover_logs());
|
|
|
|
onVisible("[id^=acme_log]", () => draw_acme_logs());
|
|
|
|
onVisible("[id^=api_log]", () => draw_api_logs());
|
|
|
|
onVisible("[id^=rl_log]", () => draw_rl_logs());
|
|
|
|
onVisible("[id^=ui_logs]", () => draw_ui_logs());
|
|
|
|
onVisible("[id^=sasl_logs]", () => draw_sasl_logs());
|
|
|
|
onVisible("[id^=netfilter_log]", () => draw_netfilter_logs());
|
|
|
|
onVisible("[id^=rspamd_history]", () => draw_rspamd_history());
|
|
|
|
onVisible("[id^=rspamd_donut]", () => rspamd_pie_graph());
|
2022-08-11 16:11:13 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
// start polling host stats if tab is active
|
2022-08-11 16:11:13 +02:00
|
|
|
onVisible("[id^=tab-containers]", () => update_stats());
|
2022-08-22 16:08:01 +02:00
|
|
|
// start polling container stats if collapse is active
|
|
|
|
var containerElements = document.querySelectorAll(".container-details-collapse");
|
|
|
|
for (let i = 0; i < containerElements.length; i++){
|
|
|
|
new IntersectionObserver((entries, observer) => {
|
|
|
|
entries.forEach(entry => {
|
|
|
|
if(entry.intersectionRatio > 0) {
|
|
|
|
|
|
|
|
if (!containerElements[i].classList.contains("show")){
|
|
|
|
var container = containerElements[i].id.replace("Collapse", "");
|
|
|
|
var container_id = containerElements[i].getAttribute("data-id");
|
|
|
|
|
|
|
|
// check if chart exists or needs to be created
|
|
|
|
if (!Chart.getChart(container + "_DiskIOChart"))
|
|
|
|
createReadWriteChart(container + "_DiskIOChart", "Read", "Write");
|
|
|
|
if (!Chart.getChart(container + "_NetIOChart"))
|
|
|
|
createReadWriteChart(container + "_NetIOChart", "Recv", "Sent");
|
|
|
|
|
|
|
|
// add container to polling list
|
|
|
|
containersToUpdate[container] = {
|
|
|
|
id: container_id,
|
|
|
|
state: "idle"
|
|
|
|
}
|
|
|
|
|
|
|
|
// stop polling if collapse is closed
|
|
|
|
containerElements[i].addEventListener('hidden.bs.collapse', function () {
|
|
|
|
var diskIOCtx = Chart.getChart(container + "_DiskIOChart");
|
|
|
|
var netIOCtx = Chart.getChart(container + "_NetIOChart");
|
|
|
|
|
|
|
|
diskIOCtx.data.datasets[0].data = [];
|
|
|
|
diskIOCtx.data.datasets[1].data = [];
|
|
|
|
diskIOCtx.data.labels = [];
|
|
|
|
netIOCtx.data.datasets[0].data = [];
|
|
|
|
netIOCtx.data.datasets[1].data = [];
|
|
|
|
netIOCtx.data.labels = [];
|
|
|
|
|
|
|
|
diskIOCtx.update();
|
|
|
|
netIOCtx.update();
|
|
|
|
|
|
|
|
delete containersToUpdate[container];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).observe(containerElements[i]);
|
|
|
|
}
|
2018-02-01 13:28:17 +01:00
|
|
|
});
|
2022-08-09 20:29:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
// update system stats - every 5 seconds if system & container tab is active
|
2022-08-22 16:08:01 +02:00
|
|
|
function update_stats(timeout=5){
|
2022-08-09 20:29:33 +02:00
|
|
|
if (!$('#tab-containers').hasClass('active')) {
|
|
|
|
// tab not active - dont fetch stats - run again in n seconds
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.fetch("/api/v1/get/status/host", {method:'GET',cache:'no-cache'}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).then(function(data) {
|
2022-08-22 16:08:01 +02:00
|
|
|
console.log(data);
|
2022-08-09 20:29:33 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
if (data){
|
|
|
|
// display table data
|
|
|
|
$("#host_date").text(data.system_time);
|
|
|
|
$("#host_uptime").text(formatUptime(data.uptime));
|
|
|
|
$("#host_cpu_cores").text(data.cpu.cores);
|
|
|
|
$("#host_cpu_usage").text(parseInt(data.cpu.usage).toString() + "%");
|
|
|
|
$("#host_memory_total").text((data.memory.total / (1024 ** 3)).toFixed(2).toString() + "GB");
|
|
|
|
$("#host_memory_usage").text(parseInt(data.memory.usage).toString() + "%");
|
2022-08-09 20:29:33 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
// update cpu and mem chart
|
|
|
|
var cpu_chart = Chart.getChart("host_cpu_chart");
|
|
|
|
var mem_chart = Chart.getChart("host_mem_chart");
|
2022-08-10 16:16:36 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
cpu_chart.data.labels.push(data.system_time.split(" ")[1]);
|
|
|
|
if (cpu_chart.data.labels.length > 30) cpu_chart.data.labels.shift();
|
|
|
|
mem_chart.data.labels.push(data.system_time.split(" ")[1]);
|
|
|
|
if (mem_chart.data.labels.length > 30) mem_chart.data.labels.shift();
|
2022-08-10 16:16:36 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
cpu_chart.data.datasets[0].data.push(data.cpu.usage);
|
|
|
|
if (cpu_chart.data.datasets[0].data.length > 30) cpu_chart.data.datasets[0].data.shift();
|
|
|
|
mem_chart.data.datasets[0].data.push(data.memory.usage);
|
|
|
|
if (mem_chart.data.datasets[0].data.length > 30) mem_chart.data.datasets[0].data.shift();
|
2022-08-09 20:29:33 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
cpu_chart.update();
|
|
|
|
mem_chart.update();
|
|
|
|
}
|
2022-08-10 16:16:36 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
// run again in n seconds
|
|
|
|
setTimeout(update_stats, timeout * 1000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// update specific container stats - every n (default 5s) seconds
|
|
|
|
function update_container_stats(timeout=5){
|
|
|
|
for (let container in containersToUpdate){
|
|
|
|
container_id = containersToUpdate[container].id;
|
|
|
|
if (containersToUpdate[container].state == "running")
|
|
|
|
continue;
|
|
|
|
containersToUpdate[container].state = "running";
|
2022-08-10 16:16:36 +02:00
|
|
|
|
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
window.fetch("/api/v1/get/status/container/" + container_id, {method:'GET',cache:'no-cache'}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).then(function(data) {
|
|
|
|
var diskIOCtx = Chart.getChart(container + "_DiskIOChart");
|
|
|
|
var netIOCtx = Chart.getChart(container + "_NetIOChart");
|
2022-08-10 16:16:36 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
console.log(container);
|
|
|
|
console.log(data);
|
|
|
|
prev_stats = null;
|
|
|
|
if (data.length >= 2)
|
|
|
|
prev_stats = data[data.length -2]
|
|
|
|
data = data[data.length -1];
|
2022-08-10 16:16:36 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
if (prev_stats != null){
|
|
|
|
// calc time diff
|
|
|
|
var time_diff = (new Date(data.read) - new Date(prev_stats.read)) / 1000;
|
|
|
|
|
|
|
|
// calc disk io b/s
|
|
|
|
var prev_read_bytes = 0;
|
|
|
|
var prev_write_bytes = 0;
|
|
|
|
for (var i = 0; i < prev_stats.blkio_stats.io_service_bytes_recursive.length; i++){
|
|
|
|
if (prev_stats.blkio_stats.io_service_bytes_recursive[i].op == "read")
|
|
|
|
prev_read_bytes = prev_stats.blkio_stats.io_service_bytes_recursive[i].value;
|
|
|
|
else if (prev_stats.blkio_stats.io_service_bytes_recursive[i].op == "write")
|
|
|
|
prev_write_bytes = prev_stats.blkio_stats.io_service_bytes_recursive[i].value;
|
|
|
|
}
|
|
|
|
var read_bytes = 0;
|
|
|
|
var write_bytes = 0;
|
|
|
|
for (var i = 0; i < data.blkio_stats.io_service_bytes_recursive.length; i++){
|
|
|
|
if (data.blkio_stats.io_service_bytes_recursive[i].op == "read")
|
|
|
|
read_bytes = data.blkio_stats.io_service_bytes_recursive[i].value;
|
|
|
|
else if (data.blkio_stats.io_service_bytes_recursive[i].op == "write")
|
|
|
|
write_bytes = data.blkio_stats.io_service_bytes_recursive[i].value;
|
|
|
|
}
|
|
|
|
var diff_bytes_read = (read_bytes - prev_read_bytes) / time_diff;
|
|
|
|
var diff_bytes_write = (write_bytes - prev_write_bytes) / time_diff;
|
|
|
|
|
|
|
|
// calc net io b/s
|
|
|
|
var prev_recv_bytes = 0;
|
|
|
|
var prev_sent_bytes = 0;
|
|
|
|
for (var key in prev_stats.networks){
|
|
|
|
prev_recv_bytes += prev_stats.networks[key].rx_bytes;
|
|
|
|
prev_sent_bytes += prev_stats.networks[key].tx_bytes;
|
|
|
|
}
|
|
|
|
var recv_bytes = 0;
|
|
|
|
var sent_bytes = 0;
|
|
|
|
for (var key in data.networks){
|
|
|
|
recv_bytes += data.networks[key].rx_bytes;
|
|
|
|
sent_bytes += data.networks[key].tx_bytes;
|
|
|
|
}
|
|
|
|
var diff_bytes_recv = (recv_bytes - prev_recv_bytes) / time_diff;
|
|
|
|
var diff_bytes_sent = (sent_bytes - prev_sent_bytes) / time_diff;
|
|
|
|
|
|
|
|
addReadWriteChart(diskIOCtx, diff_bytes_read, diff_bytes_write, "");
|
|
|
|
addReadWriteChart(netIOCtx, diff_bytes_recv, diff_bytes_sent, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
// run again in n seconds
|
|
|
|
containersToUpdate[container].state = "idle";
|
|
|
|
}).catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}
|
2022-08-09 20:29:33 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
// run again in n seconds
|
|
|
|
setTimeout(update_container_stats, timeout * 1000);
|
2022-08-09 20:29:33 +02:00
|
|
|
}
|
|
|
|
// format hosts uptime seconds to readable string
|
|
|
|
function formatUptime(seconds){
|
|
|
|
seconds = Number(seconds);
|
|
|
|
var d = Math.floor(seconds / (3600*24));
|
|
|
|
var h = Math.floor(seconds % (3600*24) / 3600);
|
|
|
|
var m = Math.floor(seconds % 3600 / 60);
|
|
|
|
var s = Math.floor(seconds % 60);
|
|
|
|
|
|
|
|
var dFormat = d > 0 ? d + "D " : "";
|
|
|
|
var hFormat = h > 0 ? h + "H " : "";
|
|
|
|
var mFormat = m > 0 ? m + "M " : "";
|
|
|
|
var sFormat = s > 0 ? s + "S" : "";
|
|
|
|
return dFormat + hFormat + mFormat + sFormat;
|
|
|
|
}
|
2022-08-10 10:56:10 +02:00
|
|
|
// format bytes to readable string
|
|
|
|
function formatBytes(bytes){
|
|
|
|
// b
|
|
|
|
if (bytes < 1000) return bytes.toFixed(2).toString()+' B/s';
|
|
|
|
// b to kb
|
|
|
|
bytes = bytes / 1024;
|
|
|
|
if (bytes < 1000) return bytes.toFixed(2).toString()+' KB/s';
|
|
|
|
// kb to mb
|
|
|
|
bytes = bytes / 1024;
|
|
|
|
if (bytes < 1000) return bytes.toFixed(2).toString()+' MB/s';
|
|
|
|
// final mb to gb
|
|
|
|
return (bytes / 1024).toFixed(2).toString()+' GB/s';
|
|
|
|
}
|
2022-08-22 16:08:01 +02:00
|
|
|
// create read write line chart
|
|
|
|
function createReadWriteChart(chart_id, read_lable, write_lable){
|
|
|
|
var ctx = document.getElementById(chart_id);
|
2022-08-09 20:29:33 +02:00
|
|
|
|
|
|
|
var dataNet = {
|
|
|
|
labels: [],
|
|
|
|
datasets: [{
|
2022-08-22 16:08:01 +02:00
|
|
|
label: read_lable,
|
2022-08-09 20:29:33 +02:00
|
|
|
backgroundColor: "rgba(41, 187, 239, 0.3)",
|
|
|
|
borderColor: "rgba(41, 187, 239, 0.6)",
|
2022-08-10 10:56:10 +02:00
|
|
|
pointRadius: 1,
|
|
|
|
pointHitRadius: 6,
|
2022-08-09 20:29:33 +02:00
|
|
|
borderWidth: 2,
|
|
|
|
fill: true,
|
|
|
|
tension: 0.2,
|
|
|
|
data: []
|
|
|
|
}, {
|
2022-08-22 16:08:01 +02:00
|
|
|
label: write_lable,
|
2022-08-09 20:29:33 +02:00
|
|
|
backgroundColor: "rgba(239, 60, 41, 0.3)",
|
|
|
|
borderColor: "rgba(239, 60, 41, 0.6)",
|
2022-08-10 10:56:10 +02:00
|
|
|
pointRadius: 1,
|
|
|
|
pointHitRadius: 6,
|
2022-08-09 20:29:33 +02:00
|
|
|
borderWidth: 2,
|
|
|
|
fill: true,
|
|
|
|
tension: 0.2,
|
|
|
|
data: []
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
var optionsNet = {
|
2022-08-10 10:56:10 +02:00
|
|
|
interaction: {
|
|
|
|
mode: 'index'
|
|
|
|
},
|
2022-08-09 20:29:33 +02:00
|
|
|
scales: {
|
|
|
|
yAxis: {
|
|
|
|
min: 0,
|
|
|
|
grid: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
callback: function(i, index, ticks) {
|
2022-08-10 10:56:10 +02:00
|
|
|
return formatBytes(i);
|
2022-08-09 20:29:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
grid: {
|
|
|
|
display: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-08-22 16:08:01 +02:00
|
|
|
|
|
|
|
return new Chart(ctx, {
|
|
|
|
type: 'line',
|
|
|
|
data: dataNet,
|
|
|
|
options: optionsNet
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// add to read write line chart
|
|
|
|
function addReadWriteChart(chart_context, read_point, write_point, time, limit = 30){
|
|
|
|
// push time label for x-axis
|
|
|
|
chart_context.data.labels.push(time);
|
|
|
|
if (chart_context.data.labels.length > limit) chart_context.data.labels.shift();
|
2022-08-09 20:29:33 +02:00
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
// push datapoints
|
|
|
|
chart_context.data.datasets[0].data.push(read_point);
|
|
|
|
chart_context.data.datasets[1].data.push(write_point);
|
|
|
|
// shift data if more than 20 entires exists
|
|
|
|
if (chart_context.data.datasets[0].data.length > limit) chart_context.data.datasets[0].data.shift();
|
|
|
|
if (chart_context.data.datasets[1].data.length > limit) chart_context.data.datasets[1].data.shift();
|
|
|
|
|
|
|
|
chart_context.update();
|
|
|
|
}
|
|
|
|
// create host cpu and mem chart
|
|
|
|
function createHostCpuAndMemChart(){
|
|
|
|
var cpu_ctx = document.getElementById("host_cpu_chart");
|
|
|
|
var mem_ctx = document.getElementById("host_mem_chart");
|
|
|
|
|
|
|
|
var dataCpu = {
|
2022-08-09 20:29:33 +02:00
|
|
|
labels: [],
|
|
|
|
datasets: [{
|
2022-08-22 16:08:01 +02:00
|
|
|
label: "CPU %",
|
2022-08-09 20:29:33 +02:00
|
|
|
backgroundColor: "rgba(41, 187, 239, 0.3)",
|
|
|
|
borderColor: "rgba(41, 187, 239, 0.6)",
|
2022-08-10 10:56:10 +02:00
|
|
|
pointRadius: 1,
|
|
|
|
pointHitRadius: 6,
|
2022-08-09 20:29:33 +02:00
|
|
|
borderWidth: 2,
|
|
|
|
fill: true,
|
|
|
|
tension: 0.2,
|
|
|
|
data: []
|
2022-08-22 16:08:01 +02:00
|
|
|
}]
|
|
|
|
};
|
|
|
|
var optionsCpu = {
|
|
|
|
interaction: {
|
|
|
|
mode: 'index'
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxis: {
|
|
|
|
min: 0,
|
|
|
|
grid: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
callback: function(i, index, ticks) {
|
|
|
|
return i.toFixed(0).toString() + "%";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
grid: {
|
|
|
|
display: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var dataMem = {
|
|
|
|
labels: [],
|
|
|
|
datasets: [{
|
|
|
|
label: "MEM %",
|
|
|
|
backgroundColor: "rgba(41, 187, 239, 0.3)",
|
|
|
|
borderColor: "rgba(41, 187, 239, 0.6)",
|
2022-08-10 10:56:10 +02:00
|
|
|
pointRadius: 1,
|
|
|
|
pointHitRadius: 6,
|
2022-08-09 20:29:33 +02:00
|
|
|
borderWidth: 2,
|
|
|
|
fill: true,
|
|
|
|
tension: 0.2,
|
|
|
|
data: []
|
|
|
|
}]
|
|
|
|
};
|
2022-08-22 16:08:01 +02:00
|
|
|
var optionsMem = {
|
2022-08-10 10:56:10 +02:00
|
|
|
interaction: {
|
|
|
|
mode: 'index'
|
|
|
|
},
|
2022-08-09 20:29:33 +02:00
|
|
|
scales: {
|
|
|
|
yAxis: {
|
|
|
|
min: 0,
|
|
|
|
grid: {
|
|
|
|
display: false
|
|
|
|
},
|
|
|
|
ticks: {
|
|
|
|
callback: function(i, index, ticks) {
|
2022-08-22 16:08:01 +02:00
|
|
|
return i.toFixed(0).toString() + "%";
|
2022-08-09 20:29:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
grid: {
|
|
|
|
display: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-08-22 16:08:01 +02:00
|
|
|
var net_io_chart = new Chart(cpu_ctx, {
|
2022-08-09 20:29:33 +02:00
|
|
|
type: 'line',
|
2022-08-22 16:08:01 +02:00
|
|
|
data: dataCpu,
|
|
|
|
options: optionsCpu
|
2022-08-09 20:29:33 +02:00
|
|
|
});
|
2022-08-22 16:08:01 +02:00
|
|
|
var disk_io_chart = new Chart(mem_ctx, {
|
2022-08-09 20:29:33 +02:00
|
|
|
type: 'line',
|
2022-08-22 16:08:01 +02:00
|
|
|
data: dataMem,
|
|
|
|
options: optionsMem
|
2022-08-09 20:29:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// check for mailcow updates
|
|
|
|
function check_update(current_version, github_repo_url){
|
|
|
|
var github_account = github_repo_url.split("/")[3];
|
|
|
|
var github_repo_name = github_repo_url.split("/")[4];
|
|
|
|
|
|
|
|
// get details about latest release
|
|
|
|
window.fetch("https://api.github.com/repos/"+github_account+"/"+github_repo_name+"/releases/latest", {method:'GET',cache:'no-cache'}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).then(function(latest_data) {
|
|
|
|
// get details about current release
|
|
|
|
window.fetch("https://api.github.com/repos/"+github_account+"/"+github_repo_name+"/releases/tags/"+current_version, {method:'GET',cache:'no-cache'}).then(function(response) {
|
|
|
|
return response.json();
|
|
|
|
}).then(function(current_data) {
|
|
|
|
// compare releases
|
|
|
|
var date_current = new Date(current_data.created_at);
|
|
|
|
var date_latest = new Date(latest_data.created_at);
|
|
|
|
if (date_latest.getTime() <= date_current.getTime()){
|
|
|
|
// no update available
|
|
|
|
$("#mailcow_update").removeClass("text-warning text-danger").addClass("text-success");
|
|
|
|
$("#mailcow_update").html("<b>" + lang_debug.no_update_available + "</b>");
|
|
|
|
} else {
|
|
|
|
// update available
|
|
|
|
$("#mailcow_update").removeClass("text-danger text-success").addClass("text-warning");
|
|
|
|
$("#mailcow_update").html(
|
|
|
|
`<b>` + lang_debug.update_available + `
|
|
|
|
<a target="_blank" href="https://github.com/`+github_account+`/`+github_repo_name+`/releases/tag/`+latest_data.tag_name+`">`+latest_data.tag_name+`</a></b>`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
// err
|
|
|
|
console.log(err);
|
|
|
|
$("#mailcow_update").removeClass("text-success text-warning").addClass("text-danger");
|
2022-08-10 10:56:10 +02:00
|
|
|
$("#mailcow_update").html("<b>"+ lang_debug.update_failed +"</b>");
|
2022-08-09 20:29:33 +02:00
|
|
|
});
|
|
|
|
}).catch(err => {
|
|
|
|
// err
|
|
|
|
console.log(err);
|
|
|
|
$("#mailcow_update").removeClass("text-success text-warning").addClass("text-danger");
|
2022-08-10 10:56:10 +02:00
|
|
|
$("#mailcow_update").html("<b>"+ lang_debug.update_failed +"</b>");
|
2022-08-09 20:29:33 +02:00
|
|
|
});
|
|
|
|
}
|