// Base64 functions var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(r){var t,e,o,a,h,n,c,d="",C=0;for(r=Base64._utf8_encode(r);C>2,h=(3&t)<<4|(e=r.charCodeAt(C++))>>4,n=(15&e)<<2|(o=r.charCodeAt(C++))>>6,c=63&o,isNaN(e)?n=c=64:isNaN(o)&&(c=64),d=d+this._keyStr.charAt(a)+this._keyStr.charAt(h)+this._keyStr.charAt(n)+this._keyStr.charAt(c);return d},decode:function(r){var t,e,o,a,h,n,c="",d=0;for(r=r.replace(/[^A-Za-z0-9\+\/\=]/g,"");d>4,e=(15&a)<<4|(h=this._keyStr.indexOf(r.charAt(d++)))>>2,o=(3&h)<<6|(n=this._keyStr.indexOf(r.charAt(d++))),c+=String.fromCharCode(t),64!=h&&(c+=String.fromCharCode(e)),64!=n&&(c+=String.fromCharCode(o));return c=Base64._utf8_decode(c)},_utf8_encode:function(r){r=r.replace(/\r\n/g,"\n");for(var t="",e=0;e127&&o<2048?(t+=String.fromCharCode(o>>6|192),t+=String.fromCharCode(63&o|128)):(t+=String.fromCharCode(o>>12|224),t+=String.fromCharCode(o>>6&63|128),t+=String.fromCharCode(63&o|128))}return t},_utf8_decode:function(r){for(var t="",e=0,o=c1=c2=0;e191&&o<224?(c2=r.charCodeAt(e+1),t+=String.fromCharCode((31&o)<<6|63&c2),e+=2):(c2=r.charCodeAt(e+1),c3=r.charCodeAt(e+2),t+=String.fromCharCode((15&o)<<12|(63&c2)<<6|63&c3),e+=3);return t}}; 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)' } 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 == 'relayhoststable') { $.each(data, function (i, item) { item.action = ''; item.chkbox = ''; }); } else if (table == 'forwardinghoststable') { $.each(data, function (i, item) { item.action = ''; if (item.keep_spam == "yes") { item.keep_spam = lang.no; } else { item.keep_spam = lang.yes; } item.chkbox = ''; }); } else if (table == 'domainadminstable') { $.each(data, function (i, item) { item.chkbox = ''; item.action = ''; }); } 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 == 'general_syslog') { $.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 + ''; } }); } return data }; // Initial table drawings draw_postfix_logs(); draw_autodiscover_logs(); draw_dovecot_logs(); draw_sogo_logs(); draw_fail2ban_logs(); draw_domain_admins(); draw_fwd_hosts(); draw_relayhosts(); draw_rspamd_history(); // Relayhost $('#testRelayhostModal').on('show.bs.modal', function (e) { $('#test_relayhost_result').text("-"); button = $(e.relatedTarget) if (button != null) { $('#relayhost_id').val(button.data('relayhost-id')); } }) $('#test_relayhost').on('click', function (e) { e.preventDefault(); prev = $('#test_relayhost').text(); $(this).prop("disabled",true); $(this).html(' '); $.ajax({ type: 'GET', url: 'inc/ajax/relay_check.php', dataType: 'text', data: $('#test_relayhost_form').serialize(), complete: function (data) { $('#test_relayhost_result').html(data.responseText); $('#test_relayhost').prop("disabled",false); $('#test_relayhost').text(prev); } }); }) // DKIM private key modal $('#showDKIMprivKey').on('show.bs.modal', function (e) { $('#priv_key_pre').text("-"); p_related = $(e.relatedTarget) if (p_related != null) { var decoded_key = Base64.decode((p_related.data('priv-key'))); $('#priv_key_pre').text(decoded_key); } }) $('.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); }); } }) // App links function add_table_row(table_id) { var row = $(''); cols = ''; cols += ''; cols += 'Remove row'; row.append(cols); table_id.append(row); } $('#app_link_table').on('click', 'tr a', function (e) { e.preventDefault(); $(this).parents('tr').remove(); }); $('#add_app_link_row').click(function() { add_table_row($('#app_link_table')); }); }); $(window).load(function(){ initial_width = $("#sidebar-admin").width(); $("#scrollbox").css("width", initial_width); $(window).bind('scroll', function() { if ($(window).scrollTop() > 70) { $('#scrollbox').addClass('scrollboxFixed'); } else { $('#scrollbox').removeClass('scrollboxFixed'); } }); }); function resizeScrollbox() { on_resize_width = $("#sidebar-admin").width(); $("#scrollbox").removeAttr("style"); $("#scrollbox").css("width", on_resize_width); } $(window).on('resize', resizeScrollbox); $('a[data-toggle="tab"]').on('shown.bs.tab', resizeScrollbox);