2017-03-02 11:23:23 +01:00
|
|
|
$(document).ready(function() {
|
2017-05-11 23:10:32 +02:00
|
|
|
// Collect values of input fields with name multi_select with same data-id to js array multi_data[data-id]
|
2017-05-09 13:43:54 +02:00
|
|
|
var multi_data = [];
|
|
|
|
$(document).on('change', 'input[name=multi_select]:checkbox', function() {
|
2017-05-11 23:10:32 +02:00
|
|
|
if ($(this).is(':checked') && $(this).data('id')) {
|
|
|
|
var id = $(this).data('id');
|
2017-05-09 13:43:54 +02:00
|
|
|
if (typeof multi_data[id] == "undefined") {
|
|
|
|
multi_data[id] = [];
|
|
|
|
}
|
|
|
|
multi_data[id].push($(this).val());
|
|
|
|
}
|
|
|
|
else {
|
2017-05-11 23:10:32 +02:00
|
|
|
var id = $(this).data('id');
|
2017-05-09 13:43:54 +02:00
|
|
|
multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1);
|
|
|
|
}
|
|
|
|
});
|
2017-05-09 21:30:08 +02:00
|
|
|
// Select checkbox by click on parent tr
|
2017-05-11 23:18:57 +02:00
|
|
|
$(document).on('click', 'tbody>tr', function(e) {
|
2017-05-09 13:43:54 +02:00
|
|
|
if (e.target.type == "checkbox") {
|
|
|
|
e.stopPropagation();
|
|
|
|
} else {
|
|
|
|
var checkbox = $(this).find(':checkbox');
|
|
|
|
checkbox.trigger('click');
|
|
|
|
}
|
|
|
|
});
|
2017-05-11 23:10:32 +02:00
|
|
|
// Select or deselect all checkboxes with same data-id
|
2017-05-09 13:43:54 +02:00
|
|
|
$(document).on('click', '#toggle_multi_select_all', function(e) {
|
|
|
|
e.preventDefault();
|
2017-05-11 23:10:32 +02:00
|
|
|
id = $(this).data("id");
|
|
|
|
multi_data[id] = [];
|
|
|
|
var all_checkboxes = $("input[data-id=" + id + "]:enabled");
|
2017-05-09 23:25:23 +02:00
|
|
|
all_checkboxes.prop("checked", !all_checkboxes.prop("checked")).change();
|
2017-05-09 13:43:54 +02:00
|
|
|
});
|
2017-05-11 23:10:32 +02:00
|
|
|
// General API edit function
|
|
|
|
$(document).on('click', '#delete_selected', function(e) {
|
2017-05-09 13:43:54 +02:00
|
|
|
e.preventDefault();
|
2017-05-11 23:10:32 +02:00
|
|
|
var id = $(this).data('id');
|
|
|
|
if (typeof multi_data[id] == "undefined" || multi_data[id] == "") return;
|
2017-05-09 13:43:54 +02:00
|
|
|
data_array = multi_data[id];
|
2017-05-11 23:10:32 +02:00
|
|
|
api_url = $(this).data('api-url');
|
2017-05-09 13:43:54 +02:00
|
|
|
$(document).on('show.bs.modal','#ConfirmDeleteModal', function () {
|
|
|
|
$("#ItemsToDelete").empty();
|
|
|
|
for (var i in data_array) {
|
|
|
|
$("#ItemsToDelete").append("<li>" + data_array[i] + "</li>");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
$('#ConfirmDeleteModal').modal({
|
|
|
|
backdrop: 'static',
|
|
|
|
keyboard: false
|
|
|
|
})
|
|
|
|
.one('click', '#IsConfirmed', function(e) {
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
dataType: "json",
|
2017-05-11 23:10:32 +02:00
|
|
|
data: { "items": JSON.stringify(data_array) },
|
|
|
|
url: '/api/v1/' + api_url,
|
2017-05-09 13:43:54 +02:00
|
|
|
jsonp: false,
|
|
|
|
complete: function (data) {
|
2017-05-11 23:10:32 +02:00
|
|
|
location.assign(window.location);
|
2017-05-09 13:43:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.one('click', '#isCanceled', function(e) {
|
|
|
|
$('#ConfirmDeleteModal').modal('hide');
|
|
|
|
});;
|
|
|
|
});
|
|
|
|
|
2017-05-11 23:10:32 +02:00
|
|
|
});
|
|
|
|
jQuery(function($){
|
|
|
|
function unix_time_format(tm) {
|
|
|
|
var date = new Date(tm ? tm * 1000 : 0);
|
|
|
|
return date.toLocaleString();
|
|
|
|
}
|
|
|
|
$("#refresh_postfix_log").on('click', function(e) {
|
2017-05-09 21:30:08 +02:00
|
|
|
e.preventDefault();
|
2017-05-11 23:10:32 +02:00
|
|
|
draw_postfix_logs();
|
2017-05-09 21:30:08 +02:00
|
|
|
});
|
2017-05-08 00:27:35 +02:00
|
|
|
$("#refresh_dovecot_log").on('click', function(e) {
|
2017-05-11 23:10:32 +02:00
|
|
|
e.preventDefault();
|
|
|
|
draw_dovecot_logs();
|
|
|
|
});
|
|
|
|
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({
|
2017-05-08 00:27:35 +02:00
|
|
|
dataType: 'json',
|
2017-05-11 23:10:32 +02:00
|
|
|
url: '/api/v1/get/logs/postfix/1000',
|
2017-05-08 00:27:35 +02:00
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
2017-05-11 23:10:32 +02:00
|
|
|
console.log('Cannot draw postfix log table');
|
2017-05-06 23:52:40 +02:00
|
|
|
},
|
2017-05-08 00:27:35 +02:00
|
|
|
success: function (data) {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
var danger_class = ["emerg", "alert", "crit"];
|
|
|
|
var warning_class = ["warning"];
|
|
|
|
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>';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-05-11 23:10:32 +02:00
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {
|
|
|
|
"enabled": true,
|
|
|
|
"limit": 5,
|
|
|
|
"size": pagination_size
|
|
|
|
},
|
|
|
|
"filtering": {
|
|
|
|
"enabled": true,
|
|
|
|
"position": "left",
|
|
|
|
"placeholder": lang.filter_table
|
|
|
|
},
|
|
|
|
"sorting": {
|
|
|
|
"enabled": true
|
2017-05-08 00:27:35 +02:00
|
|
|
}
|
2017-05-11 23:10:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_dovecot_logs() {
|
|
|
|
ft_postfix_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({
|
2017-05-08 00:27:35 +02:00
|
|
|
dataType: 'json',
|
2017-05-11 23:10:32 +02:00
|
|
|
url: '/api/v1/get/logs/dovecot/1000',
|
2017-05-08 00:27:35 +02:00
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
2017-05-11 23:10:32 +02:00
|
|
|
console.log('Cannot draw dovecot log table');
|
2017-05-06 23:52:40 +02:00
|
|
|
},
|
2017-05-08 00:27:35 +02:00
|
|
|
success: function (data) {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
var danger_class = ["emerg", "alert", "crit"];
|
|
|
|
var warning_class = ["warning"];
|
|
|
|
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>';
|
|
|
|
}
|
|
|
|
});
|
2017-05-11 23:10:32 +02:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {
|
|
|
|
"enabled": true,
|
|
|
|
"limit": 5,
|
|
|
|
"size": pagination_size
|
|
|
|
},
|
|
|
|
"filtering": {
|
|
|
|
"enabled": true,
|
|
|
|
"position": "left",
|
|
|
|
"placeholder": lang.filter_table
|
|
|
|
},
|
|
|
|
"sorting": {
|
|
|
|
"enabled": true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function draw_domain_admins() {
|
|
|
|
ft_domainadmins = FooTable.init('#domainadminstable', {
|
|
|
|
"columns": [
|
|
|
|
{"sorted": true,"name":"username","title":lang.username,"style":{"width":"250px"}},
|
|
|
|
{"name":"selected_domains","title":lang.admin_domains,"breakpoints":"xs sm"},
|
|
|
|
{"name":"tfa_active","title":"TFA", "filterable": false,"style":{"maxWidth":"80px","width":"80px"}},
|
|
|
|
{"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"}
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/domain-admin/all',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw domain admin table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
item.action = '<div class="btn-group">' +
|
|
|
|
'<a href="/edit.php?domainadmin=' + encodeURI(item.username) + '" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span> ' + lang.edit + '</a>' +
|
|
|
|
'<a href="/delete.php?domainadmin=' + encodeURI(item.username) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
|
|
|
|
'</div>';
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {
|
|
|
|
"enabled": true,
|
|
|
|
"limit": 5,
|
|
|
|
"size": pagination_size
|
|
|
|
},
|
|
|
|
"filtering": {
|
|
|
|
"enabled": true,
|
|
|
|
"position": "left",
|
|
|
|
"placeholder": lang.filter_table
|
|
|
|
},
|
|
|
|
"sorting": {
|
|
|
|
"enabled": true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function draw_fwd_hosts() {
|
|
|
|
ft_domainadmins = FooTable.init('#forwardinghoststable', {
|
|
|
|
"columns": [
|
|
|
|
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
|
|
|
|
{"name":"host","type":"text","title":lang.host,"style":{"width":"250px"}},
|
|
|
|
{"name":"source","title":lang.source,"breakpoints":"xs sm"},
|
|
|
|
{"name":"keep_spam","title":lang.spamfilter, "type": "text","style":{"maxWidth":"80px","width":"80px"}},
|
|
|
|
{"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
|
|
|
|
],
|
|
|
|
"rows": $.ajax({
|
|
|
|
dataType: 'json',
|
|
|
|
url: '/api/v1/get/fwdhost/all',
|
|
|
|
jsonp: false,
|
|
|
|
error: function () {
|
|
|
|
console.log('Cannot draw forwarding hosts table');
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
$.each(data, function (i, item) {
|
|
|
|
item.action = '<div class="btn-group">' +
|
|
|
|
'<a href="/delete.php?forwardinghost=' + encodeURI(item.host) + '" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-trash"></span> ' + lang.remove + '</a>' +
|
|
|
|
'</div>';
|
|
|
|
if (item.keep_spam == "yes") {
|
|
|
|
item.keep_spam = lang.no;
|
2017-05-08 00:27:35 +02:00
|
|
|
}
|
2017-05-11 23:10:32 +02:00
|
|
|
else {
|
|
|
|
item.keep_spam = lang.yes;
|
|
|
|
}
|
|
|
|
item.chkbox = '<input type="checkbox" data-id="fwdhosts" name="multi_select" value="' + item.host + '" />';
|
2017-05-08 00:27:35 +02:00
|
|
|
});
|
2017-05-06 23:52:40 +02:00
|
|
|
}
|
2017-05-11 23:10:32 +02:00
|
|
|
}),
|
|
|
|
"empty": lang.empty,
|
|
|
|
"paging": {
|
|
|
|
"enabled": true,
|
|
|
|
"limit": 5,
|
|
|
|
"size": pagination_size
|
|
|
|
},
|
|
|
|
"sorting": {
|
|
|
|
"enabled": true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
draw_postfix_logs();
|
|
|
|
draw_dovecot_logs();
|
|
|
|
draw_domain_admins();
|
|
|
|
draw_fwd_hosts();
|
2017-03-02 11:23:23 +01:00
|
|
|
});
|