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)' } else { sym.score_formatted = '(' + sym.score + ')' } var str = '' + key + ' ' + 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("
\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 = "
" + 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'; } 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 + ''; } }); } 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.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,")) { item.message = atob(item.message.slice(7)).replace(/\\n/g, "
"); } else { 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 + ''; } }); } 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('.tab-pane').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(); $(window).resize(function () { var timer; clearTimeout(timer); timer = setTimeout(function () { rspamd_pie_graph(); }, 500); }); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var target = $(e.target).attr("href"); if ((target == '#tab-rspamd-history')) { rspamd_pie_graph(); } }); });