$(document).ready(function() { $('#syncjobLogModal').on('show.bs.modal', function(e) { var syncjob_id = $(e.relatedTarget).data('syncjob-id'); $.ajax({ url: '/inc/ajax/syncjob_logs.php', data: { id: syncjob_id }, dataType: 'text', success: function(data){ $(e.currentTarget).find('#logText').text(data); }, error: function(xhr, status, error) { $(e.currentTarget).find('#logText').text(xhr.responseText); } }); }); $(".arrow-toggle").on('click', function(e) { e.preventDefault(); $(this).find('.arrow').toggleClass("animation"); }); $("#pushover_delete").click(function() { return confirm(lang.delete_ays); }); }); 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]; }); } // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript function validateEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); } function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"}); } acl_data = JSON.parse(acl); var last_login = $('.last_login_date').data('time'); $('.last_login_date').text(unix_time_format(last_login)); function draw_tla_table() { ft_tla_table = FooTable.init('#tla_table', { "columns": [ {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"}, {"sorted": true,"name":"address","title":lang.alias}, {"name":"validity","formatter":function unix_time_format(tm) { var date = new Date(tm ? tm * 1000 : 0); return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});},"title":lang.alias_valid_until,"style":{"width":"170px"}}, {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"} ], "empty": lang.empty, "rows": $.ajax({ dataType: 'json', url: '/api/v1/get/time_limited_aliases', jsonp: false, error: function () { console.log('Cannot draw tla table'); }, success: function (data) { $.each(data, function (i, item) { if (acl_data.spam_alias === 1) { item.action = '
' + ' ' + lang.remove + '' + '
'; item.chkbox = ''; item.address = escapeHtml(item.address); } else { item.chkbox = ''; item.action = '-'; } }); } }), "paging": { "enabled": true, "limit": 5, "size": pagination_size }, "state": {"enabled": true}, "sorting": { "enabled": true }, "toggleSelector": "table tbody span.footable-toggle" }); } function draw_sync_job_table() { ft_syncjob_table = FooTable.init('#sync_job_table', { "columns": [ {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"}, {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}}, {"name":"server_w_port","title":"Server"}, {"name":"enc1","title":lang.encryption,"breakpoints":"xs sm"}, {"name":"user1","title":lang.username}, {"name":"exclude","title":lang.excludes,"breakpoints":"all"}, {"name":"mins_interval","title":lang.interval + " (min)","breakpoints":"all"}, {"name":"last_run","title":lang.last_run,"breakpoints":"all"}, {"name":"log","title":"Log"}, {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'✓':0==value&&'✕';}}, {"name":"is_running","filterable": false,"style":{"maxWidth":"120px","width":"100px"},"title":lang.status}, {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"} ], "empty": lang.empty, "rows": $.ajax({ dataType: 'json', url: '/api/v1/get/syncjobs/' + encodeURIComponent(mailcow_cc_username) + '/no_log', jsonp: false, error: function () { console.log('Cannot draw sync job table'); }, success: function (data) { $.each(data, function (i, item) { item.user1 = escapeHtml(item.user1); item.log = 'Open logs' if (!item.exclude > 0) { item.exclude = '-'; } else { item.exclude = '' + escapeHtml(item.exclude) + ''; } item.server_w_port = escapeHtml(item.user1 + '@' + item.host1 + ':' + item.port1); if (acl_data.syncjobs === 1) { item.action = '
' + ' ' + lang.edit + '' + ' ' + lang.remove + '' + '
'; item.chkbox = ''; } else { item.action = '-'; item.chkbox = ''; } if (item.is_running == 1) { item.is_running = '' + lang.running + ''; } else { item.is_running = '' + lang.waiting + ''; } if (!item.last_run > 0) { item.last_run = lang.waiting; } }); } }), "paging": { "enabled": true, "limit": 5, "size": pagination_size }, "state": {"enabled": true}, "sorting": { "enabled": true }, "toggleSelector": "table tbody span.footable-toggle" }); } function draw_app_passwd_table() { ft_apppasswd_table = FooTable.init('#app_passwd_table', { "columns": [ {"name":"chkbox","title":"","style":{"maxWidth":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"}, {"sorted": true,"name":"id","title":"ID","style":{"maxWidth":"60px","width":"60px","text-align":"center"}}, {"name":"name","title":lang.app_name}, {"name":"active","filterable": false,"style":{"maxWidth":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'✓':0==value&&'✕';}}, {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"} ], "empty": lang.empty, "rows": $.ajax({ dataType: 'json', url: '/api/v1/get/app-passwd/all', jsonp: false, error: function () { console.log('Cannot draw app passwd table'); }, success: function (data) { $.each(data, function (i, item) { if (acl_data.app_passwds === 1) { item.action = '
' + ' ' + lang.edit + '' + ' ' + lang.remove + '' + '
'; item.chkbox = ''; } else { item.action = '-'; item.chkbox = ''; } }); } }), "paging": { "enabled": true, "limit": 5, "size": pagination_size }, "state": {"enabled": true}, "sorting": { "enabled": true }, "toggleSelector": "table tbody span.footable-toggle" }); } function draw_wl_policy_mailbox_table() { ft_wl_policy_mailbox_table = FooTable.init('#wl_policy_mailbox_table', { "columns": [ {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"}, {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false}, {"sorted": true,"name":"value","title":lang.spamfilter_table_rule}, {"name":"object","title":"Scope"} ], "empty": lang.empty, "rows": $.ajax({ dataType: 'json', url: '/api/v1/get/policy_wl_mailbox', jsonp: false, error: function () { console.log('Cannot draw mailbox policy wl table'); }, success: function (data) { $.each(data, function (i, item) { if (validateEmail(item.object)) { item.chkbox = ''; } else { item.chkbox = ''; } if (acl_data.spam_policy === 0) { item.chkbox = ''; } }); } }), "state": {"enabled": true}, "paging": { "enabled": true, "limit": 5, "size": pagination_size }, "sorting": { "enabled": true } }); } function draw_bl_policy_mailbox_table() { ft_bl_policy_mailbox_table = FooTable.init('#bl_policy_mailbox_table', { "columns": [ {"name":"chkbox","title":"","style":{"maxWidth":"40px","width":"40px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"}, {"name":"prefid","style":{"maxWidth":"40px","width":"40px"},"title":"ID","filterable": false,"sortable": false}, {"sorted": true,"name":"value","title":lang.spamfilter_table_rule}, {"name":"object","title":"Scope"} ], "empty": lang.empty, "rows": $.ajax({ dataType: 'json', url: '/api/v1/get/policy_bl_mailbox', jsonp: false, error: function () { console.log('Cannot draw mailbox policy bl table'); }, success: function (data) { $.each(data, function (i, item) { if (validateEmail(item.object)) { item.chkbox = ''; } else { item.chkbox = ''; } if (acl_data.spam_policy === 0) { item.chkbox = ''; } }); } }), "paging": { "enabled": true, "limit": 5, "size": pagination_size }, "state": {"enabled": true}, "sorting": { "enabled": true } }); } $('body').on('click', 'span.footable-toggle', function () { event.stopPropagation(); }) draw_sync_job_table(); draw_app_passwd_table(); draw_tla_table(); draw_wl_policy_mailbox_table(); draw_bl_policy_mailbox_table(); // Sieve data modal $('#userFilterModal').on('show.bs.modal', function(e) { $('#user_sieve_filter').text(lang.loading); $.ajax({ dataType: 'json', url: '/api/v1/get/active-user-sieve/' + encodeURIComponent(mailcow_cc_username), jsonp: false, error: function () { console.log('Cannot get active sieve script'); }, complete: function (data) { if (data.responseText == '{}') { $('#user_sieve_filter').text(lang.no_active_filter); } else { $('#user_sieve_filter').text(JSON.parse(data.responseText)); } } }) }); $('#userFilterModal').on('hidden.bs.modal', function () { $('#user_sieve_filter').text(lang.loading); }); });