Various...
This commit is contained in:
@@ -5,199 +5,10 @@ jQuery(function($){
|
||||
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]}
|
||||
$("#refresh_postfix_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_postfix_logs();
|
||||
});
|
||||
$("#refresh_autodiscover_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_autodiscover_logs();
|
||||
});
|
||||
$("#refresh_dovecot_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_dovecot_logs();
|
||||
});
|
||||
$("#refresh_sogo_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_sogo_logs();
|
||||
});
|
||||
$("#refresh_fail2ban_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_fail2ban_logs();
|
||||
});
|
||||
$("#refresh_rspamd_history").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_rspamd_history();
|
||||
});
|
||||
$("#import_dkim_legend").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
$('#import_dkim_arrow').toggleClass("animation");
|
||||
});
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function draw_fail2ban_logs() {
|
||||
ft_fail2ban_logs = FooTable.init('#fail2ban_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/fail2ban',
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw fail2ban log table');
|
||||
},
|
||||
success: function (data) {
|
||||
return process_table_data(data, 'general_syslog');
|
||||
}
|
||||
}),
|
||||
"empty": lang.empty,
|
||||
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function draw_domain_admins() {
|
||||
ft_domainadmins = FooTable.init('#domainadminstable', {
|
||||
"columns": [
|
||||
@@ -278,108 +89,9 @@ jQuery(function($){
|
||||
"sorting": {"enabled": true}
|
||||
});
|
||||
}
|
||||
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}},
|
||||
{"name": "rcpt_mime","title": "To","breakpoints": "xs sm md","style": {"minWidth": 100}},
|
||||
{"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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function process_table_data(data, table) {
|
||||
if (table == 'rspamd_history') {
|
||||
$.each(data, function (i, item) {
|
||||
item.rcpt_mime = item.rcpt_mime.join(",​");
|
||||
Object.keys(item.symbols).map(function(key) {
|
||||
var sym = item.symbols[key];
|
||||
if (sym.score <= 0) {
|
||||
sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)'
|
||||
}
|
||||
else {
|
||||
sym.score_formatted = '(<span class="text-danger"><b>' + sym.score + '</b></span>)'
|
||||
}
|
||||
var str = '<strong>' + key + '</strong> ' + sym.score_formatted;
|
||||
if (sym.options) {
|
||||
str += ' [' + sym.options.join(",") + "]";
|
||||
}
|
||||
item.symbols[key].str = str;
|
||||
});
|
||||
item.symbols = Object.keys(item.symbols).
|
||||
map(function(key) {
|
||||
return item.symbols[key];
|
||||
}).sort(function(e1, e2) {
|
||||
return Math.abs(e1.score) < Math.abs(e2.score);
|
||||
}).map(function(e) {
|
||||
return e.str;
|
||||
}).join("<br>\n");
|
||||
var scan_time = item.time_real.toFixed(3) + ' / ' + item.time_virtual.toFixed(3);
|
||||
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 == 'relayhoststable') {
|
||||
if (table == 'relayhoststable') {
|
||||
$.each(data, function (i, item) {
|
||||
item.action = '<div class="btn-group">' +
|
||||
'<a href="#" data-toggle="modal" id="miau" data-target="#testRelayhostModal" data-relayhost-id="' + encodeURI(item.id) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-stats"></span> Test</a>' +
|
||||
@@ -409,48 +121,13 @@ jQuery(function($){
|
||||
'<a href="#" id="delete_selected" data-id="single-domain-admin" data-api-url="delete/domain-admin" data-item="' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
|
||||
'</div>';
|
||||
});
|
||||
} else if (table == 'autodiscover_log') {
|
||||
$.each(data, function (i, item) {
|
||||
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 {
|
||||
item.service = '<span class="label label-danger">' + item.service + '</span>';
|
||||
}
|
||||
});
|
||||
} else if (table == 'general_syslog') {
|
||||
$.each(data, function (i, item) {
|
||||
item.message = escapeHtml(item.message);
|
||||
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>';
|
||||
}
|
||||
});
|
||||
}
|
||||
return data
|
||||
};
|
||||
// Initial table drawings
|
||||
draw_postfix_logs();
|
||||
draw_autodiscover_logs();
|
||||
draw_dovecot_logs();
|
||||
draw_sogo_logs();
|
||||
draw_fail2ban_logs();
|
||||
draw_domain_admins();
|
||||
draw_fwd_hosts();
|
||||
draw_relayhosts();
|
||||
draw_rspamd_history();
|
||||
// Relayhost
|
||||
$('#testRelayhostModal').on('show.bs.modal', function (e) {
|
||||
$('#test_relayhost_result').text("-");
|
||||
@@ -485,31 +162,6 @@ jQuery(function($){
|
||||
$('#priv_key_pre').text(decoded_key);
|
||||
}
|
||||
})
|
||||
|
||||
$('.add_log_lines').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var log_table= $(this).data("table")
|
||||
var new_nrows = ($(this).data("nrows") - 1)
|
||||
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))) {
|
||||
var heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
var load_rows = ft_paging.totalRows + '-' + (ft_paging.totalRows + new_nrows)
|
||||
$.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);
|
||||
$(heading).children('.log-lines').text(rows_now)
|
||||
mailcow_alert_box(data.length + lang.additional_rows, "success");
|
||||
ft.rows.load(rows, true);
|
||||
});
|
||||
}
|
||||
})
|
||||
// App links
|
||||
function add_table_row(table_id) {
|
||||
var row = $('<tr />');
|
||||
|
@@ -102,6 +102,7 @@ $(document).ready(function() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// alert(JSON.stringify(api_attr));
|
||||
// If clicked element #edit_selected has data-item attribute, it is added to "items"
|
||||
if (typeof $(this).data('item') !== 'undefined') {
|
||||
var id = $(this).data('id');
|
||||
@@ -126,7 +127,9 @@ $(document).ready(function() {
|
||||
jsonp: false,
|
||||
complete: function(data) {
|
||||
var response = (data.responseText);
|
||||
response_obj = JSON.parse(response);
|
||||
if (typeof response !== 'undefined' && response.length !== 0) {
|
||||
response_obj = JSON.parse(response);
|
||||
}
|
||||
if (api_reload_window === true) {
|
||||
window.location = window.location.href.split("#")[0];
|
||||
}
|
||||
@@ -141,6 +144,11 @@ $(document).ready(function() {
|
||||
var id = $(this).data('id');
|
||||
var api_url = $(this).data('api-url');
|
||||
var api_attr = $(this).data('api-attr');
|
||||
if (typeof $(this).data('api-reload-window') !== 'undefined') {
|
||||
api_reload_window = $(this).data('api-reload-window');
|
||||
} else {
|
||||
api_reload_window = true;
|
||||
}
|
||||
// If clicked button is in a form with the same data-id as the button,
|
||||
// we merge all input fields by {"name":"value"} into api-attr
|
||||
if ($(this).closest("form").data('id') == id) {
|
||||
@@ -188,10 +196,20 @@ $(document).ready(function() {
|
||||
url: '/api/v1/' + api_url,
|
||||
jsonp: false,
|
||||
complete: function(data) {
|
||||
// var reponse = (JSON.parse(data.responseText));
|
||||
// console.log(reponse.type);
|
||||
// console.log(reponse.msg);
|
||||
window.location = window.location.href.split("#")[0];
|
||||
var response = (data.responseText);
|
||||
if (typeof response !== 'undefined' && response.length !== 0) {
|
||||
response_obj = JSON.parse(response);
|
||||
if (response_obj.type == 'success') {
|
||||
$('form').formcache('clear');
|
||||
}
|
||||
else {
|
||||
var add_modal = $('.modal.in').attr('id');
|
||||
localStorage.setItem("add_modal", add_modal);
|
||||
}
|
||||
}
|
||||
if (api_reload_window === true) {
|
||||
window.location = window.location.href.split("#")[0];
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
503
data/web/js/debug.js
Normal file
503
data/web/js/debug.js
Normal file
@@ -0,0 +1,503 @@
|
||||
jQuery(function($){
|
||||
// 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]}
|
||||
$("#refresh_postfix_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_postfix_logs();
|
||||
});
|
||||
$("#refresh_autodiscover_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_autodiscover_logs();
|
||||
});
|
||||
$("#refresh_dovecot_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_dovecot_logs();
|
||||
});
|
||||
$("#refresh_sogo_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_sogo_logs();
|
||||
});
|
||||
$("#refresh_watchdog_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_watchdog_logs();
|
||||
});
|
||||
$("#refresh_api_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_api_logs();
|
||||
});
|
||||
$("#refresh_acme_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_acme_logs();
|
||||
});
|
||||
$("#refresh_fail2ban_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_fail2ban_logs();
|
||||
});
|
||||
$("#refresh_rspamd_history").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_rspamd_history();
|
||||
});
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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"}},
|
||||
{"name":"data","title":"Data","style":{"word-break":"break-all"}},
|
||||
],
|
||||
"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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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"}},
|
||||
{"name":"message","title":lang.message},
|
||||
],
|
||||
"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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function draw_fail2ban_logs() {
|
||||
ft_fail2ban_logs = FooTable.init('#fail2ban_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/fail2ban',
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw fail2ban log table');
|
||||
},
|
||||
success: function (data) {
|
||||
return process_table_data(data, 'general_syslog');
|
||||
}
|
||||
}),
|
||||
"empty": lang.empty,
|
||||
"paging": {"enabled": true,"limit": 5,"size": log_pagination_size},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
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}},
|
||||
{"name": "rcpt_mime","title": "To","breakpoints": "xs sm md","style": {"minWidth": 100}},
|
||||
{"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},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(e, ft){
|
||||
heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
$(heading).children('.log-lines').text(function(){
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
return ft_paging.totalRows;
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function process_table_data(data, table) {
|
||||
if (table == 'rspamd_history') {
|
||||
$.each(data, function (i, item) {
|
||||
item.rcpt_mime = item.rcpt_mime.join(",​");
|
||||
Object.keys(item.symbols).map(function(key) {
|
||||
var sym = item.symbols[key];
|
||||
if (sym.score <= 0) {
|
||||
sym.score_formatted = '(<span class="text-success"><b>' + sym.score + '</b></span>)'
|
||||
}
|
||||
else {
|
||||
sym.score_formatted = '(<span class="text-danger"><b>' + sym.score + '</b></span>)'
|
||||
}
|
||||
var str = '<strong>' + key + '</strong> ' + sym.score_formatted;
|
||||
if (sym.options) {
|
||||
str += ' [' + sym.options.join(",") + "]";
|
||||
}
|
||||
item.symbols[key].str = str;
|
||||
});
|
||||
item.symbols = Object.keys(item.symbols).
|
||||
map(function(key) {
|
||||
return item.symbols[key];
|
||||
}).sort(function(e1, e2) {
|
||||
return Math.abs(e1.score) < Math.abs(e2.score);
|
||||
}).map(function(e) {
|
||||
return e.str;
|
||||
}).join("<br>\n");
|
||||
var scan_time = item.time_real.toFixed(3) + ' / ' + item.time_virtual.toFixed(3);
|
||||
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) {
|
||||
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 {
|
||||
item.service = '<span class="label label-danger">' + item.service + '</span>';
|
||||
}
|
||||
});
|
||||
} 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 = '';
|
||||
}
|
||||
});
|
||||
} else if (table == 'general_syslog') {
|
||||
$.each(data, function (i, item) {
|
||||
if (item === null) { return true; }
|
||||
item.message = escapeHtml(item.message);
|
||||
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>';
|
||||
}
|
||||
});
|
||||
}
|
||||
return data
|
||||
};
|
||||
$('.add_log_lines').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var log_table= $(this).data("table")
|
||||
var new_nrows = ($(this).data("nrows") - 1)
|
||||
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))) {
|
||||
var heading = ft.$el.parents('.tab-pane').find('.panel-heading')
|
||||
var ft_paging = ft.use(FooTable.Paging)
|
||||
var load_rows = ft_paging.totalRows + '-' + (ft_paging.totalRows + new_nrows)
|
||||
$.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);
|
||||
$(heading).children('.log-lines').text(rows_now)
|
||||
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();
|
||||
draw_fail2ban_logs();
|
||||
draw_rspamd_history();
|
||||
|
||||
});
|
10
data/web/js/formcache.min.js
vendored
Normal file
10
data/web/js/formcache.min.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*!
|
||||
* Form Cache v@VERSION
|
||||
* https://github.com/fengyuanchen/formcache
|
||||
*
|
||||
* Copyright 2014 Fengyuan Chen
|
||||
* Released under the MIT license
|
||||
*
|
||||
* Date: @DATE
|
||||
*/
|
||||
!function(t){"function"==typeof define&&define.amd?define("formcache",["jquery"],t):t(jQuery)}(function(t){"use strict";var e=t(window),i=window.sessionStorage,s=window.localStorage,n="undefined",o=".formcache",a=/[\.\*\+\^\$\:\!\[\]#>~]+/g,c="change"+o,h="beforeunload"+o,r=function(t){return"checkbox"===t.type||"radio"===t.type},f=function(t){return parseInt(t,10)},u=function(e,i){this.form=e,this.$form=t(e),this.defaults=t.extend({},u.DEFAULTS,t.isPlainObject(i)?i:{}),this.init()};u.prototype={constructor:u,init:function(){var e=this.defaults;e.maxAge=Math.abs(e.maxAge||e.maxage),e.autoStore=Boolean(e.autoStore||e.autostore),this.initKey(),this.initStorage(),this.caches=this.storage.caches,this.index=0,this.activeIndex=0,this.storing=null,t.isArray(e.controls)||(e.controls=[]),this.$controls=this.$form.find(e.controls.join()).not(":file"),this.addListeners(),this.outputCache()},initKey:function(){var e=this.$form,i=this.defaults.key||e.data("key");i||(t("form").each(function(e){t(this).data("key",e)}),i=e.data("key")),this.key=location.pathname+"#formcache-"+i},initStorage:function(){var e,n=this.defaults,o=this.key,a=new Date,c={date:a,maxAge:n.maxAge,caches:[]};i&&(e=i.getItem(o)),!e&&s&&(e=s.getItem(o)),e="string"==typeof e?JSON.parse(e):null,t.isPlainObject(e)?"number"==typeof e.maxAge&&(a-new Date(e.date))/1e3>e.maxAge&&(e=c):e=c,this.storage=e},addListeners:function(){this.defaults.autoStore&&(this.$controls.on(c,t.proxy(this.change,this)),e.on(h,t.proxy(this.beforeunload,this)))},removeListeners:function(){this.defaults.autoStore&&(this.$controls.off(c,this.change),e.off(h,this.beforeunload))},change:function(e){var i,s,n=e.target,o=t(n),c=o.attr("name"),h=[];c&&(i=c.replace(a,""),this.$controls.filter('[name*="'+i+'"]').each(function(){r(n)?h.push(this.checked):(s=t(this).val(),s&&h.push(s))}),h.length&&(this.update(c,h),clearTimeout(this.storing),this.storing=setTimeout(t.proxy(this.store,this),1e3)))},beforeunload:function(){this.update(),this.store()},update:function(t,e){var i=this.activeIndex||this.index,s=this.getCache(i);"string"==typeof t?s[t]=e:s=this.serialize(),this.setCache(i,s)},serialize:function(){var e={};return this.$controls.each(function(){var i,s,n=t(this),o=n.attr("name");o&&(i=e[o],i=t.isArray(i)?i:[],r(this)?i.push(this.checked):(s=n.val(),s&&i.push(s)),i.length&&(e[o]=i))}),e},getCache:function(t){return this.caches[f(t)||this.index]||{}},getCaches:function(){return this.caches},setCache:function(e,i){typeof i===n&&(i=e,e=NaN),t.isPlainObject(i)&&(e=f(e)||this.index,this.caches[e]=i,this.store())},setCaches:function(e){t.isArray(e)&&(this.caches=e,this.store())},removeCache:function(t){this.caches.splice(f(t)||this.index,1),this.store()},removeCaches:function(){this.caches=[],this.store()},outputCache:function(e){var i=this.getCache(e);t.isPlainObject(i)&&(this.activeIndex=f(e)||this.index,i=t.extend(!0,{},i),this.$controls.each(function(){var e,s,n=t(this),o=n.attr("name");o&&(e=i[o],t.isArray(e)&&e.length&&(s=e.shift(),r(this)?this.checked=s:n.val(s)))}))},store:function(){var t=this.storage,e=this.key,n=this.defaults;t.date=new Date,t.maxAge=n.maxAge,t=JSON.stringify(t),n.session&&i&&i.setItem(e,t),n.local&&s&&s.setItem(e,t)},clear:function(){var t=this.key,e=this.defaults;e.session&&i&&i.removeItem(t),e.local&&s&&s.removeItem(t)},destroy:function(){this.removeListeners(),this.$form.removeData("formcache")}},u.DEFAULTS={key:"",local:!0,session:0,autoStore:!0,maxAge:void 0,controls:["select","textarea","input"]},u.setDefaults=function(e){t.extend(u.DEFAULTS,e)},u.other=t.fn.formcache,t.fn.formcache=function(e){var i,s=[].slice.call(arguments,1);return this.each(function(){var n,o=t(this),a=o.data("formcache");a||o.data("formcache",a=new u(this,e)),"string"==typeof e&&t.isFunction(n=a[e])&&(i=n.apply(a,s))}),typeof i!==n?i:this},t.fn.formcache.Constructor=u,t.fn.formcache.setDefaults=u.setDefaults,t.fn.formcache.noConflict=function(){return t.fn.formcache=u.other,this},t(function(){t('form[data-toggle="formcache"]').formcache()})});
|
@@ -319,9 +319,9 @@ jQuery(function($){
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}},
|
||||
{"name":"type","title":"Type"},
|
||||
{"name":"local_dest","title":"Local destination"},
|
||||
{"name":"bcc_dest","title":"BCC destination/s"},
|
||||
{"name":"type","title":lang.bcc_type},
|
||||
{"name":"local_dest","title":lang.bcc_local_dest},
|
||||
{"name":"bcc_dest","title":lang.bcc_destinations},
|
||||
{"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
|
||||
{"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active},
|
||||
{"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
|
||||
|
82
data/web/js/quarantaine.js
Normal file
82
data/web/js/quarantaine.js
Normal file
@@ -0,0 +1,82 @@
|
||||
// Base64 functions
|
||||
var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(r){var t,e,o,a,h,n,c,d="",C=0;for(r=Base64._utf8_encode(r);C<r.length;)a=(t=r.charCodeAt(C++))>>2,h=(3&t)<<4|(e=r.charCodeAt(C++))>>4,n=(15&e)<<2|(o=r.charCodeAt(C++))>>6,c=63&o,isNaN(e)?n=c=64:isNaN(o)&&(c=64),d=d+this._keyStr.charAt(a)+this._keyStr.charAt(h)+this._keyStr.charAt(n)+this._keyStr.charAt(c);return d},decode:function(r){var t,e,o,a,h,n,c="",d=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<r.length;)t=this._keyStr.indexOf(r.charAt(d++))<<2|(a=this._keyStr.indexOf(r.charAt(d++)))>>4,e=(15&a)<<4|(h=this._keyStr.indexOf(r.charAt(d++)))>>2,o=(3&h)<<6|(n=this._keyStr.indexOf(r.charAt(d++))),c+=String.fromCharCode(t),64!=h&&(c+=String.fromCharCode(e)),64!=n&&(c+=String.fromCharCode(o));return c=Base64._utf8_decode(c)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var t="",e=0;e<r.length;e++){var o=r.charCodeAt(e);o<128?t+=String.fromCharCode(o):o>127&&o<2048?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t},_utf8_decode:function(r){for(var t="",e=0,o=c1=c2=0;e<r.length;)(o=r.charCodeAt(e))<128?(t+=String.fromCharCode(o),e++):o>191&&o<224?(c2=r.charCodeAt(e+1),t+=String.fromCharCode((31&o)<<6|63&c2),e+=2):(c2=r.charCodeAt(e+1),c3=r.charCodeAt(e+2),t+=String.fromCharCode((15&o)<<12|(63&c2)<<6|63&c3),e+=3);return t}};
|
||||
jQuery(function($){
|
||||
// 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]}
|
||||
|
||||
function draw_quarantaine_table() {
|
||||
ft_quarantainetable = FooTable.init('#quarantainetable', {
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"name":"id","type":"ID","filterable": false,"sorted": true,"direction":"DESC","title":"ID","style":{"width":"50px"}},
|
||||
{"name":"qid","type":"text","title":lang.qid,"style":{"width":"125px"}},
|
||||
{"name":"sender","title":lang.sender,"breakpoints":"xs sm"},
|
||||
{"name":"rcpt","title":lang.rcpt, "type": "text"},
|
||||
{"name":"created","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.received,"style":{"width":"170px"}},
|
||||
{"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right"},"style":{"width":"205px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
|
||||
],
|
||||
"rows": $.ajax({
|
||||
dataType: 'json',
|
||||
url: '/api/v1/get/quarantaine/all',
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw quarantaine table');
|
||||
},
|
||||
success: function (data) {
|
||||
$.each(data, function (i, item) {
|
||||
item.action = '<div class="btn-group">' +
|
||||
'<a href="#" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-info show_qid_info"><span class="glyphicon glyphicon-modal-window"></span> ' + lang.show_item + '</a>' +
|
||||
'<a href="#" id="delete_selected" data-id="del-single-qitem" data-api-url="delete/qitem" data-item="' + encodeURI(item.id) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
|
||||
'</div>';
|
||||
item.chkbox = '<input type="checkbox" data-id="qitems" name="multi_select" value="' + item.id + '" />';
|
||||
});
|
||||
}
|
||||
}),
|
||||
"empty": lang.empty,
|
||||
"paging": {"enabled": true,"limit": 5,"size": pagination_size},
|
||||
"sorting": {"enabled": true},
|
||||
"on": {
|
||||
"ready.ft.table": function(ev, ft){
|
||||
$('.show_qid_info').on('click', function (e) {
|
||||
e.preventDefault();
|
||||
var qitem = $(this).data('item');
|
||||
$('#qidDetailModal').modal('show');
|
||||
$( "#qid_error" ).hide();
|
||||
$.ajax({
|
||||
url: '/inc/ajax/qitem_details.php',
|
||||
data: { id: qitem },
|
||||
dataType: 'json',
|
||||
success: function(data){
|
||||
if (typeof data.error !== 'undefined') {
|
||||
$( "#qid_error" ).text(data.error);
|
||||
$( "#qid_error" ).show();
|
||||
}
|
||||
$('#qid_detail_subj').text(escapeHtml(data.subject));
|
||||
$('#qid_detail_text').text(escapeHtml(data.text_plain));
|
||||
if (typeof data.attachments !== 'undefined') {
|
||||
$( "#qid_detail_atts" ).text('');
|
||||
$.each(data.attachments, function( index, value ) {
|
||||
$( "#qid_detail_atts" ).append(
|
||||
'<p><a href="/inc/ajax/qitem_details.php?id=' + qitem + '&att=' + index + '" target="_blank">' + value[0] + '</a> (' + value[1] + ')' +
|
||||
' - <small><a href="' + value[3] + '" target="_blank">' + lang.check_hash + '</a></small></p>'
|
||||
);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$( "#qid_detail_atts" ).text('-');
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
},
|
||||
"filtering": {"enabled": true,"position": "left","connectors": false,"placeholder": lang.filter_table},
|
||||
});
|
||||
}
|
||||
|
||||
// Initial table drawings
|
||||
draw_quarantaine_table();
|
||||
|
||||
});
|
Reference in New Issue
Block a user