var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function(e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function(e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function(e) { e = e.replace(/\r\n/g, "\n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function(e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } } jQuery(function($){ // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery var entityMap = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', '/': '/', '`': '`', '=': '=' }; function escapeHtml(string) { return String(string).replace(/[&<>"'`=\/]/g, function (s) { return entityMap[s]; }); } 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(); }); $("#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_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/1000', jsonp: false, error: function () { console.log('Cannot draw postfix log table'); }, success: function (data) { $.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 = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, warning_class) !== -1) { item.priority = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, info_class) !== -1) { item.priority = '' + item.priority + ''; } }); } }), "empty": lang.empty, "paging": { "enabled": true, "limit": 5, "size": log_pagination_size }, "filtering": { "enabled": true, "position": "left", "placeholder": lang.filter_table }, "sorting": { "enabled": true } }); } 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) { $.each(data, function (i, item) { item.ua = '' + item.ua + ''; if (item.service == "activesync") { item.service = 'ActiveSync'; } else if (item.service == "imap") { item.service = 'IMAP, SMTP, Cal-/CardDAV'; } else { item.service = '' + item.service + ''; } }); } }), "empty": lang.empty, "paging": { "enabled": true, "limit": 5, "size": log_pagination_size }, "filtering": { "enabled": true, "position": "left", "placeholder": lang.filter_table }, "sorting": { "enabled": true } }); } 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/1000', jsonp: false, error: function () { console.log('Cannot draw fail2ban log table'); }, success: function (data) { $.each(data, function (i, item) { var danger_class = ["emerg", "alert", "crit", "err"]; var warning_class = ["warning", "warn"]; var info_class = ["notice", "info", "debug"]; item.message = escapeHtml(item.message); if (jQuery.inArray(item.priority, danger_class) !== -1) { item.priority = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, warning_class) !== -1) { item.priority = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, info_class) !== -1) { item.priority = '' + item.priority + ''; } }); } }), "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 } }); } 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/1000', jsonp: false, error: function () { console.log('Cannot draw sogo log table'); }, success: function (data) { $.each(data, function (i, item) { var danger_class = ["emerg", "alert", "crit", "err"]; var warning_class = ["warning", "warn"]; var info_class = ["notice", "info", "debug"]; item.message = escapeHtml(item.message); if (jQuery.inArray(item.priority, danger_class) !== -1) { item.priority = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, warning_class) !== -1) { item.priority = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, info_class) !== -1) { item.priority = '' + item.priority + ''; } }); } }), "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 } }); } 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({ dataType: 'json', url: '/api/v1/get/logs/dovecot/1000', jsonp: false, error: function () { console.log('Cannot draw dovecot log table'); }, success: function (data) { $.each(data, function (i, item) { var danger_class = ["emerg", "alert", "crit", "err"]; var warning_class = ["warning", "warn"]; var info_class = ["notice", "info", "debug"]; item.message = escapeHtml(item.message); if (jQuery.inArray(item.priority, danger_class) !== -1) { item.priority = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, warning_class) !== -1) { item.priority = '' + item.priority + ''; } else if (jQuery.inArray(item.priority, info_class) !== -1) { item.priority = '' + item.priority + ''; } }); } }), "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 } }); } function draw_domain_admins() { ft_domainadmins = FooTable.init('#domainadminstable', { "columns": [ {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px"},"filterable": false,"sortable": false,"type":"html"}, {"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.chkbox = ''; item.action = '