$(document).ready(function() { // Parse seconds ago to date // Get "now" timestamp var ts_now = Math.round((new Date()).getTime() / 1000); $('.parse_s_ago').each(function(i, parse_s_ago) { var started_s_ago = parseInt($(this).text(), 10); if (typeof started_s_ago != 'NaN') { var started_date = new Date((ts_now - started_s_ago) * 1000); var started_local_date = started_date.toLocaleDateString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" }); $(this).text(started_local_date); } }); // Parse general dates $('.parse_date').each(function(i, parse_date) { var started_date = new Date(Date.parse($(this).text())); if (typeof started_date != 'NaN') { var started_local_date = started_date.toLocaleDateString(undefined, { year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit" }); $(this).text(started_local_date); } }); }); jQuery(function($){ if (localStorage.getItem("current_page") === null) { var current_page = {}; } else { var current_page = JSON.parse(localStorage.getItem('current_page')); } // 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 0 && item.symbols[a].score > 0) { return item.symbols[b].score - item.symbols[a].score } return item.symbols[b].score - item.symbols[a].score }).map(function(key) { var sym = item.symbols[key]; if (sym.score < 0) { sym.score_formatted = '(' + sym.score + ')' } else if (sym.score === 0) { sym.score_formatted = '(' + sym.score + ')' } else { sym.score_formatted = '(' + sym.score + ')' } var str = '' + key + ' ' + sym.score_formatted; if (sym.options) { str += ' [' + escapeHtml(sym.options.join(", ")) + "]"; } return str }).join('
\n'); item.subject = escapeHtml(item.subject); var scan_time = item.time_real.toFixed(3); if (item.time_virtual) { scan_time += ' / ' + 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 = "
" + item.action + "
"; } else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') { item.action = "
" + item.action + "
"; } else if (item.action === 'spam' || item.action === 'reject') { item.action = "
" + item.action + "
"; } else { item.action = "
" + item.action + "
"; } var score_content; if (item.score < item.required_score) { score_content = "[ " + item.score.toFixed(2) + " / " + item.required_score + " ]"; } else { score_content = "[ " + item.score.toFixed(2) + " / " + item.required_score + " ]"; } 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) { if (item.ua == null) { item.ua = 'unknown'; } else { item.ua = escapeHtml(item.ua); } 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 = '' + escapeHtml(item.service) + ''; } }); } 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 = ' ' + item.hpdiff + ''; } else if (item.hpdiff == 0) { item.trend = ' ' + item.hpdiff + ''; } else { item.trend = ' ' + item.hpdiff + ''; } } else { item.trend = ''; item.service = ''; } }); } else if (table == 'mailcow_ui') { $.each(data, function (i, item) { if (item === null) { return true; } item.user = escapeHtml(item.user); item.call = escapeHtml(item.call); item.task = '' + item.task + ''; item.type = '' + item.type + ''; }); } else if (table == 'general_syslog') { $.each(data, function (i, item) { if (item === null) { return true; } if (item.message.match("^base64,")) { try { item.message = atob(item.message.slice(7)).replace(/\\n/g, "
"); } catch(e) { item.message = item.message.slice(7); } } else { item.message = escapeHtml(item.message); } item.call = escapeHtml(item.call); 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 + ''; } }); } else if (table == 'apilog') { $.each(data, function (i, item) { if (item === null) { return true; } if (item.method == 'GET') { item.method = '' + item.method + ''; } else if (item.method == 'POST') { item.method = '' + item.method + ''; } item.data = escapeHtml(item.data); }); } else if (table == 'rllog') { $.each(data, function (i, item) { if (item.user == null) { item.user = "none"; } if (item.rl_hash == null) { item.rl_hash = "err"; } item.indicator = ' '; if (item.rl_hash != 'err') { item.action = ' ' + lang.reset_limit + ''; } }); } return data }; $('.add_log_lines').on('click', function (e) { e.preventDefault(); var log_table= $(this).data("table") var new_nrows = $(this).data("nrows") 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('.panel').find('.panel-heading') var ft_paging = ft.use(FooTable.Paging) var load_rows = (ft_paging.totalRows + 1) + '-' + (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('.table-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_rl_logs(); draw_ui_logs(); draw_netfilter_logs(); draw_rspamd_history(); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var target = $(e.target).attr("href"); if (target == '#tab-rspamd-history') { rspamd_pie_graph(); } }); });