More structural changes
This commit is contained in:
@@ -1,76 +1,20 @@
|
||||
$(document).ready(function() {
|
||||
// Collect values of input fields with name multi_select with same data-id to js array multi_data[data-id]
|
||||
var multi_data = [];
|
||||
$(document).on('change', 'input[name=multi_select]:checkbox', function() {
|
||||
if ($(this).is(':checked') && $(this).data('id')) {
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined") {
|
||||
multi_data[id] = [];
|
||||
}
|
||||
multi_data[id].push($(this).val());
|
||||
}
|
||||
else {
|
||||
var id = $(this).data('id');
|
||||
multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1);
|
||||
}
|
||||
});
|
||||
// Select checkbox by click on parent tr
|
||||
$(document).on('click', 'tbody>tr', function(e) {
|
||||
if (e.target.type == "checkbox") {
|
||||
e.stopPropagation();
|
||||
} else {
|
||||
var checkbox = $(this).find(':checkbox');
|
||||
checkbox.trigger('click');
|
||||
}
|
||||
});
|
||||
// Select or deselect all checkboxes with same data-id
|
||||
$(document).on('click', '#toggle_multi_select_all', function(e) {
|
||||
e.preventDefault();
|
||||
id = $(this).data("id");
|
||||
multi_data[id] = [];
|
||||
var all_checkboxes = $("input[data-id=" + id + "]:enabled");
|
||||
all_checkboxes.prop("checked", !all_checkboxes.prop("checked")).change();
|
||||
});
|
||||
// General API edit function
|
||||
$(document).on('click', '#delete_selected', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined" || multi_data[id] == "") return;
|
||||
data_array = multi_data[id];
|
||||
api_url = $(this).data('api-url');
|
||||
$(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",
|
||||
data: { "items": JSON.stringify(data_array), "csrf_token": csrf_token },
|
||||
url: '/api/v1/' + api_url,
|
||||
jsonp: false,
|
||||
complete: function (data) {
|
||||
location.reload(true);
|
||||
}
|
||||
});
|
||||
})
|
||||
.one('click', '#isCanceled', function(e) {
|
||||
$('#ConfirmDeleteModal').modal('hide');
|
||||
});;
|
||||
});
|
||||
|
||||
});
|
||||
jQuery(function($){
|
||||
function unix_time_format(tm) {
|
||||
var date = new Date(tm ? tm * 1000 : 0);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
function humanFileSize(bytes) {
|
||||
if(Math.abs(bytes) < 1024) {
|
||||
return bytes + ' B';
|
||||
}
|
||||
var units = ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
|
||||
var u = -1;
|
||||
do {
|
||||
bytes /= 1024;
|
||||
++u;
|
||||
} while(Math.abs(bytes) >= 1024 && u < units.length - 1);
|
||||
return bytes.toFixed(1)+' '+units[u];
|
||||
}
|
||||
$("#refresh_postfix_log").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_postfix_logs();
|
||||
@@ -83,6 +27,10 @@ jQuery(function($){
|
||||
e.preventDefault();
|
||||
draw_sogo_logs();
|
||||
});
|
||||
$("#refresh_rspamd_history").on('click', function(e) {
|
||||
e.preventDefault();
|
||||
draw_rspamd_history();
|
||||
});
|
||||
function draw_postfix_logs() {
|
||||
ft_postfix_logs = FooTable.init('#postfix_log', {
|
||||
"columns": [
|
||||
@@ -307,10 +255,185 @@ jQuery(function($){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function draw_rspamd_history() {
|
||||
ft_postfix_logs = FooTable.init('#rspamd_history', {
|
||||
"columns": [{
|
||||
"name": "message-id",
|
||||
"title": "ID",
|
||||
"breakpoints": "all",
|
||||
"style": {
|
||||
"minWidth": 130,
|
||||
"overflow": "hidden",
|
||||
"textOverflow": "ellipsis",
|
||||
"wordBreak": "break-all",
|
||||
"whiteSpace": "normal"
|
||||
}
|
||||
}, {
|
||||
"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
|
||||
},
|
||||
}, {
|
||||
"sorted": true,
|
||||
"breakpoints": "all",
|
||||
"direction": "DESC",
|
||||
"name": "time",
|
||||
"title": "Time",
|
||||
}, {
|
||||
"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) {
|
||||
$.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");
|
||||
item.time = {
|
||||
"value": unix_time_format(item.unix_time),
|
||||
"options": {
|
||||
"sortValue": item.unix_time
|
||||
}
|
||||
};
|
||||
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";
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
"empty": lang.empty,
|
||||
"paging": {
|
||||
"enabled": true,
|
||||
"limit": 5,
|
||||
"size": pagination_size
|
||||
},
|
||||
"filtering": {
|
||||
"enabled": true,
|
||||
"position": "left",
|
||||
"placeholder": lang.filter_table
|
||||
},
|
||||
"sorting": {
|
||||
"enabled": true
|
||||
}
|
||||
});
|
||||
}
|
||||
draw_postfix_logs();
|
||||
draw_dovecot_logs();
|
||||
draw_sogo_logs();
|
||||
draw_domain_admins();
|
||||
draw_fwd_hosts();
|
||||
draw_rspamd_history();
|
||||
});
|
154
data/web/js/api.js
Normal file
154
data/web/js/api.js
Normal file
@@ -0,0 +1,154 @@
|
||||
$(document).ready(function() {
|
||||
// Collect values of input fields with name "multi_select" an same data-id to js array multi_data[data-id]
|
||||
var multi_data = [];
|
||||
$(document).on('change', 'input[name=multi_select]:checkbox', function() {
|
||||
if ($(this).is(':checked') && $(this).data('id')) {
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined") {
|
||||
multi_data[id] = [];
|
||||
}
|
||||
multi_data[id].push($(this).val());
|
||||
}
|
||||
else {
|
||||
var id = $(this).data('id');
|
||||
multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1);
|
||||
}
|
||||
});
|
||||
|
||||
// Select checkbox by click on parent tr
|
||||
$(document).on('click', 'tbody>tr', function(e) {
|
||||
if (e.target.type == "checkbox") {
|
||||
e.stopPropagation();
|
||||
} else {
|
||||
var checkbox = $(this).find(':checkbox');
|
||||
checkbox.trigger('click');
|
||||
}
|
||||
});
|
||||
|
||||
// Select or deselect all checkboxes with same data-id
|
||||
$(document).on('click', '#toggle_multi_select_all', function(e) {
|
||||
e.preventDefault();
|
||||
id = $(this).data("id");
|
||||
multi_data[id] = [];
|
||||
var all_checkboxes = $("input[data-id=" + id + "]:enabled");
|
||||
all_checkboxes.prop("checked", !all_checkboxes.prop("checked")).change();
|
||||
});
|
||||
|
||||
// General API edit actions
|
||||
$(document).on('click', '#edit_selected', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
var api_url = $(this).data('api-url');
|
||||
var api_attr = $(this).data('api-attr');
|
||||
// If clicked element #edit_selected 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) {
|
||||
var attr_to_merge = {};
|
||||
$.each($(this).closest("form").serializeArray(), function(i, field) {
|
||||
attr_to_merge[field.name] = field.value;
|
||||
});
|
||||
var api_attr = $.extend(api_attr, attr_to_merge)
|
||||
}
|
||||
// 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');
|
||||
if (typeof multi_data[id] == "undefined") {
|
||||
multi_data[id] = [];
|
||||
}
|
||||
multi_data[id].push($(this).data('item'));
|
||||
}
|
||||
if (typeof multi_data[id] == "undefined") return;
|
||||
api_items = multi_data[id];
|
||||
if (Object.keys(api_items).length !== 0) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { "items": JSON.stringify(api_items), "attr": JSON.stringify(api_attr), "csrf_token": csrf_token },
|
||||
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];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// General API add actions
|
||||
$(document).on('click', '#add_item', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
var api_url = $(this).data('api-url');
|
||||
var api_attr = $(this).data('api-attr');
|
||||
// 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) {
|
||||
var attr_to_merge = {};
|
||||
$.each($(this).closest("form").serializeArray(), function(i, field) {
|
||||
attr_to_merge[field.name] = field.value;
|
||||
});
|
||||
var api_attr = $.extend(api_attr, attr_to_merge)
|
||||
}
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { "attr": JSON.stringify(api_attr), "csrf_token": csrf_token },
|
||||
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];
|
||||
}
|
||||
});
|
||||
});
|
||||
// General API delete actions
|
||||
$(document).on('click', '#delete_selected', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
// If clicked element #delete_selected has data-item attribute, it is added to "items"
|
||||
if (typeof $(this).data('item') !== 'undefined') {
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined") {
|
||||
multi_data[id] = [];
|
||||
}
|
||||
multi_data[id].splice($.inArray($(this).data('item'), multi_data[id]),1);
|
||||
multi_data[id].push($(this).data('item'));
|
||||
}
|
||||
if (typeof $(this).data('text') !== 'undefined') {
|
||||
$("#DeleteText").empty();
|
||||
$("#DeleteText").text($(this).data('text'));
|
||||
}
|
||||
if (typeof multi_data[id] == "undefined" || multi_data[id] == "") return;
|
||||
data_array = multi_data[id];
|
||||
api_url = $(this).data('api-url');
|
||||
$(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",
|
||||
data: { "items": JSON.stringify(data_array), "csrf_token": csrf_token },
|
||||
url: '/api/v1/' + api_url,
|
||||
jsonp: false,
|
||||
complete: function (data) {
|
||||
window.location = window.location.href.split("#")[0];
|
||||
}
|
||||
});
|
||||
})
|
||||
.one('click', '#isCanceled', function(e) {
|
||||
$('#ConfirmDeleteModal').modal('hide');
|
||||
});;
|
||||
});
|
||||
});
|
83
data/web/js/edit.js
Normal file
83
data/web/js/edit.js
Normal file
@@ -0,0 +1,83 @@
|
||||
jQuery(function($){
|
||||
// http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
|
||||
function validateEmail(email) {
|
||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test(email);
|
||||
}
|
||||
function draw_wl_policy_domain_table() {
|
||||
ft_wl_policy_mailbox_table = FooTable.init('#wl_policy_domain_table', {
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
|
||||
{"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
|
||||
{"name":"object","title":"Scope"}
|
||||
],
|
||||
"empty": lang.empty,
|
||||
"rows": $.ajax({
|
||||
dataType: 'json',
|
||||
url: '/api/v1/get/policy_wl_domain/' + table_for_domain,
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw mailbox policy wl table');
|
||||
},
|
||||
success: function (data) {
|
||||
$.each(data, function (i, item) {
|
||||
if (!validateEmail(item.object)) {
|
||||
item.chkbox = '<input type="checkbox" data-id="policy_wl_domain" name="multi_select" value="' + item.prefid + '" />';
|
||||
}
|
||||
else {
|
||||
item.chkbox = '<input type="checkbox" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
"paging": {
|
||||
"enabled": true,
|
||||
"limit": 5,
|
||||
"size": pagination_size
|
||||
},
|
||||
"sorting": {
|
||||
"enabled": true
|
||||
}
|
||||
});
|
||||
}
|
||||
function draw_bl_policy_domain_table() {
|
||||
ft_bl_policy_mailbox_table = FooTable.init('#bl_policy_domain_table', {
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
|
||||
{"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
|
||||
{"name":"object","title":"Scope"}
|
||||
],
|
||||
"empty": lang.empty,
|
||||
"rows": $.ajax({
|
||||
dataType: 'json',
|
||||
url: '/api/v1/get/policy_bl_domain/' + table_for_domain,
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw mailbox policy bl table');
|
||||
},
|
||||
success: function (data) {
|
||||
$.each(data, function (i, item) {
|
||||
if (!validateEmail(item.object)) {
|
||||
item.chkbox = '<input type="checkbox" data-id="policy_bl_domain" name="multi_select" value="' + item.prefid + '" />';
|
||||
}
|
||||
else {
|
||||
item.chkbox = '<input type="checkbox" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
"paging": {
|
||||
"enabled": true,
|
||||
"limit": 5,
|
||||
"size": pagination_size
|
||||
},
|
||||
"sorting": {
|
||||
"enabled": true
|
||||
}
|
||||
});
|
||||
}
|
||||
draw_wl_policy_domain_table();
|
||||
draw_bl_policy_domain_table();
|
||||
});
|
@@ -1,95 +1,3 @@
|
||||
$(document).ready(function() {
|
||||
// Collect values of input fields with name multi_select with same data-id to js array multi_data[data-id]
|
||||
var multi_data = [];
|
||||
$(document).on('change', 'input[name=multi_select]:checkbox', function() {
|
||||
if ($(this).is(':checked') && $(this).data('id')) {
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined") {
|
||||
multi_data[id] = [];
|
||||
}
|
||||
multi_data[id].push($(this).val());
|
||||
}
|
||||
else {
|
||||
var id = $(this).data('id');
|
||||
multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1);
|
||||
}
|
||||
});
|
||||
// Select checkbox by click on parent tr
|
||||
$(document).on('click', 'tbody>tr', function(e) {
|
||||
if (e.target.type == "checkbox") {
|
||||
e.stopPropagation();
|
||||
} else {
|
||||
var checkbox = $(this).find(':checkbox');
|
||||
checkbox.trigger('click');
|
||||
}
|
||||
});
|
||||
// Select or deselect all checkboxes with same data-id
|
||||
$(document).on('click', '#toggle_multi_select_all', function(e) {
|
||||
e.preventDefault();
|
||||
id = $(this).data("id");
|
||||
multi_data[id] = [];
|
||||
var all_checkboxes = $("input[data-id=" + id + "]:enabled");
|
||||
all_checkboxes.prop("checked", !all_checkboxes.prop("checked")).change();
|
||||
});
|
||||
// General API edit actions
|
||||
$(document).on('click', '#edit_selected', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined") return;
|
||||
data_array = multi_data[id];
|
||||
api_url = $(this).data('api-url');
|
||||
api_attr = $(this).data('api-attr');
|
||||
if (Object.keys(data_array).length !== 0) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { "items": JSON.stringify(data_array), "attr": JSON.stringify(api_attr), "csrf_token": csrf_token },
|
||||
url: '/api/v1/' + api_url,
|
||||
jsonp: false,
|
||||
complete: function (data) {
|
||||
// var reponse = (JSON.parse(data.responseText));
|
||||
// console.log(reponse.type);
|
||||
// console.log(reponse.msg);
|
||||
location.assign(window.location);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// General API delete actions
|
||||
$(document).on('click', '#delete_selected', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined" || multi_data[id] == "") return;
|
||||
data_array = multi_data[id];
|
||||
api_url = $(this).data('api-url');
|
||||
$(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",
|
||||
data: { "items": JSON.stringify(data_array), "csrf_token": csrf_token },
|
||||
url: '/api/v1/' + api_url,
|
||||
jsonp: false,
|
||||
complete: function (data) {
|
||||
location.assign(window.location);
|
||||
}
|
||||
});
|
||||
})
|
||||
.one('click', '#isCanceled', function(e) {
|
||||
$('#ConfirmDeleteModal').modal('hide');
|
||||
});;
|
||||
});
|
||||
});
|
||||
|
||||
jQuery(function($){
|
||||
// Calculation human readable file sizes
|
||||
function humanFileSize(bytes) {
|
||||
|
@@ -1,29 +1,4 @@
|
||||
$(document).ready(function() {
|
||||
// Show and activate password fields after box was checked
|
||||
// Hidden by default
|
||||
if ( !$("#togglePwNew").is(':checked') ) {
|
||||
$(".passFields").hide();
|
||||
}
|
||||
$('#togglePwNew').click(function() {
|
||||
$("#user_new_pass").attr("disabled", !this.checked);
|
||||
$("#user_new_pass2").attr("disabled", !this.checked);
|
||||
var $this = $(this);
|
||||
if ($this.is(':checked')) {
|
||||
$(".passFields").slideDown();
|
||||
} else {
|
||||
$(".passFields").slideUp();
|
||||
}
|
||||
});
|
||||
// Show generate button after time selection
|
||||
$('#generate_tla').hide();
|
||||
$('#validity').change(function(){
|
||||
$('#generate_tla').show();
|
||||
});
|
||||
|
||||
// Init Bootstrap Switch
|
||||
$.fn.bootstrapSwitch.defaults.onColor = 'success';
|
||||
$("#tls_out").bootstrapSwitch();
|
||||
$("#tls_in").bootstrapSwitch();
|
||||
|
||||
// Log modal
|
||||
$('#logModal').on('show.bs.modal', function(e) {
|
||||
@@ -31,96 +6,8 @@ $(document).ready(function() {
|
||||
$(e.currentTarget).find('#logText').html('<pre style="background:none;font-size:11px;line-height:1.1;border:0px">' + logText + '</pre>');
|
||||
});
|
||||
|
||||
// Collect values of input fields with name multi_select with same data-id to js array multi_data[data-id]
|
||||
var multi_data = [];
|
||||
$(document).on('change', 'input[name=multi_select]:checkbox', function() {
|
||||
if ($(this).is(':checked') && $(this).data('id')) {
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined") {
|
||||
multi_data[id] = [];
|
||||
}
|
||||
multi_data[id].push($(this).val());
|
||||
}
|
||||
else {
|
||||
var id = $(this).data('id');
|
||||
multi_data[id].splice($.inArray($(this).val(), multi_data[id]),1);
|
||||
}
|
||||
});
|
||||
// Select checkbox by click on parent tr
|
||||
$(document).on('click', 'tbody>tr', function(e) {
|
||||
if (e.target.type == "checkbox") {
|
||||
e.stopPropagation();
|
||||
} else {
|
||||
var checkbox = $(this).find(':checkbox');
|
||||
checkbox.trigger('click');
|
||||
}
|
||||
});
|
||||
// Select or deselect all checkboxes with same data-id
|
||||
$(document).on('click', '#toggle_multi_select_all', function(e) {
|
||||
e.preventDefault();
|
||||
id = $(this).data("id");
|
||||
multi_data[id] = [];
|
||||
var all_checkboxes = $("input[data-id=" + id + "]:enabled");
|
||||
all_checkboxes.prop("checked", !all_checkboxes.prop("checked")).change();
|
||||
});
|
||||
// General API edit actions
|
||||
$(document).on('click', '#edit_selected', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined") return;
|
||||
data_array = multi_data[id];
|
||||
api_url = $(this).data('api-url');
|
||||
api_attr = $(this).data('api-attr');
|
||||
if (Object.keys(data_array).length !== 0) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
data: { "items": JSON.stringify(data_array), "attr": JSON.stringify(api_attr), "csrf_token": csrf_token },
|
||||
url: '/api/v1/' + api_url,
|
||||
jsonp: false,
|
||||
complete: function (data) {
|
||||
// var reponse = (JSON.parse(data.responseText));
|
||||
// console.log(reponse.type);
|
||||
// console.log(reponse.msg);
|
||||
location.assign(window.location);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// General API delete actions
|
||||
$(document).on('click', '#delete_selected', function(e) {
|
||||
e.preventDefault();
|
||||
var id = $(this).data('id');
|
||||
if (typeof multi_data[id] == "undefined" || multi_data[id] == "") return;
|
||||
data_array = multi_data[id];
|
||||
api_url = $(this).data('api-url');
|
||||
$(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",
|
||||
data: { "items": JSON.stringify(data_array), "csrf_token": csrf_token },
|
||||
url: '/api/v1/' + api_url,
|
||||
jsonp: false,
|
||||
complete: function (data) {
|
||||
location.reload(true);
|
||||
}
|
||||
});
|
||||
})
|
||||
.one('click', '#isCanceled', function(e) {
|
||||
$('#ConfirmDeleteModal').modal('hide');
|
||||
});;
|
||||
});
|
||||
});
|
||||
|
||||
jQuery(function($){
|
||||
// http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
|
||||
var entityMap = {
|
||||
@@ -138,11 +25,52 @@ jQuery(function($){
|
||||
return entityMap[s];
|
||||
});
|
||||
}
|
||||
function draw_sync_job_table() {
|
||||
ft_aliasdomain_table = FooTable.init('#sync_job_table', {
|
||||
// http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
|
||||
function validateEmail(email) {
|
||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
return re.test(email);
|
||||
}
|
||||
function unix_time_format(tm) {
|
||||
var date = new Date(tm ? tm * 1000 : 0);
|
||||
return date.toLocaleString();
|
||||
}
|
||||
function draw_tla_table() {
|
||||
ft_tla_table = FooTable.init('#tla_table', {
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"sorted": true,"name":"server_w_port","title":"Server"},
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"sorted": true,"name":"address","title":lang.alias},
|
||||
{"name":"validity","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleString();},"title":lang.alias_valid_until,"style":{"width":"170px"}},
|
||||
],
|
||||
"empty": lang.empty,
|
||||
"rows": $.ajax({
|
||||
dataType: 'json',
|
||||
url: '/api/v1/get/time_limited_aliases',
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw tla table');
|
||||
},
|
||||
success: function (data) {
|
||||
$.each(data, function (i, item) {
|
||||
item.chkbox = '<input type="checkbox" data-id="tla" name="multi_select" value="' + item.address + '" />';
|
||||
});
|
||||
}
|
||||
}),
|
||||
"paging": {
|
||||
"enabled": true,
|
||||
"limit": 5,
|
||||
"size": pagination_size
|
||||
},
|
||||
"sorting": {
|
||||
"enabled": true
|
||||
}
|
||||
});
|
||||
}
|
||||
function draw_sync_job_table() {
|
||||
ft_syncjob_table = FooTable.init('#sync_job_table', {
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"sorted": true,"name":"id","title":"ID"},
|
||||
{"name":"server_w_port","title":"Server"},
|
||||
{"name":"enc1","title":lang.encryption},
|
||||
{"name":"user1","title":lang.username},
|
||||
{"name":"exclude","title":lang.excludes},
|
||||
@@ -155,7 +83,7 @@ jQuery(function($){
|
||||
"empty": lang.empty,
|
||||
"rows": $.ajax({
|
||||
dataType: 'json',
|
||||
url: '/api/v1/get/syncjob',
|
||||
url: '/api/v1/get/syncjobs',
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw sync job table');
|
||||
@@ -182,5 +110,82 @@ jQuery(function($){
|
||||
}
|
||||
});
|
||||
}
|
||||
function draw_wl_policy_mailbox_table() {
|
||||
ft_wl_policy_mailbox_table = FooTable.init('#wl_policy_mailbox_table', {
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
|
||||
{"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
|
||||
{"name":"object","title":"Scope"}
|
||||
],
|
||||
"empty": lang.empty,
|
||||
"rows": $.ajax({
|
||||
dataType: 'json',
|
||||
url: '/api/v1/get/policy_wl_mailbox',
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw mailbox policy wl table');
|
||||
},
|
||||
success: function (data) {
|
||||
$.each(data, function (i, item) {
|
||||
if (validateEmail(item.object)) {
|
||||
item.chkbox = '<input type="checkbox" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />';
|
||||
}
|
||||
else {
|
||||
item.chkbox = '<input type="checkbox" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
"paging": {
|
||||
"enabled": true,
|
||||
"limit": 5,
|
||||
"size": pagination_size
|
||||
},
|
||||
"sorting": {
|
||||
"enabled": true
|
||||
}
|
||||
});
|
||||
}
|
||||
function draw_bl_policy_mailbox_table() {
|
||||
ft_bl_policy_mailbox_table = FooTable.init('#bl_policy_mailbox_table', {
|
||||
"columns": [
|
||||
{"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
|
||||
{"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false},
|
||||
{"sorted": true,"name":"value","title":lang.spamfilter_table_rule},
|
||||
{"name":"object","title":"Scope"}
|
||||
],
|
||||
"empty": lang.empty,
|
||||
"rows": $.ajax({
|
||||
dataType: 'json',
|
||||
url: '/api/v1/get/policy_bl_mailbox',
|
||||
jsonp: false,
|
||||
error: function () {
|
||||
console.log('Cannot draw mailbox policy bl table');
|
||||
},
|
||||
success: function (data) {
|
||||
$.each(data, function (i, item) {
|
||||
if (validateEmail(item.object)) {
|
||||
item.chkbox = '<input type="checkbox" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />';
|
||||
}
|
||||
else {
|
||||
item.chkbox = '<input type="checkbox" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
|
||||
}
|
||||
});
|
||||
}
|
||||
}),
|
||||
"paging": {
|
||||
"enabled": true,
|
||||
"limit": 5,
|
||||
"size": pagination_size
|
||||
},
|
||||
"sorting": {
|
||||
"enabled": true
|
||||
}
|
||||
});
|
||||
}
|
||||
draw_sync_job_table();
|
||||
draw_tla_table();
|
||||
draw_wl_policy_mailbox_table();
|
||||
draw_bl_policy_mailbox_table();
|
||||
});
|
Reference in New Issue
Block a user