jQuery(function($){ // 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" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%";})); rspamd_donut_plot = $.jqplot('rspamd_donut', [data], { seriesDefaults: { renderer: jQuery.jqplot.DonutRenderer, rendererOptions: { showDataLabels: true, dataLabels: rspamd_labels, dataLabelThreshold: 1, sliceMargin: 5, totalLabel: true }, shadow: false, seriesColors: ['#FF4136', '#75CAEB', '#FF851B', '#FF851B', '#28B62C'] }, legend: { show:false, }, grid: { drawGridLines: true, gridLineColor: '#efefef', background: '#ffffff', borderWidth: 0, shadow: false, } } ); } }); } } }); } function process_table_data(data, table) { if (table == 'rspamd_history') { $.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 = '(' + sym.score + ')' } 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) { 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 == 'general_syslog') { $.each(data, function (i, item) { if (item === null) { return true; } 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 + ''; } }); } return data }; $('.add_log_lines').on('click', function (e) { e.preventDefault(); var log_table= $(this).data("table") var new_nrows = ($(this).data("nrows") - 1) 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 + '-' + (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('.log-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_netfilter_logs(); draw_rspamd_history(); $(window).resize(function () { var timer; clearTimeout(timer); timer = setTimeout(function () { if (typeof rspamd_donut_plot !== 'undefined') { rspamd_donut_plot.replot({}); } }, 500); }); $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var target = $(e.target).attr("href"); if ((target == '#tab-rspamd-history')) { rspamd_donut_plot.replot({}); } }); });