Matthias Andreas Benkard | d1f5b68 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 1 | // Base64 functions |
| 2 | 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<r.length;)a=(t=r.charCodeAt(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<r.length;)t=this._keyStr.indexOf(r.charAt(d++))<<2|(a=this._keyStr.indexOf(r.charAt(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;e<r.length;e++){var o=r.charCodeAt(e);o<128?t+=String.fromCharCode(o):o>127&&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;e<r.length;)(o=r.charCodeAt(e))<128?(t+=String.fromCharCode(o),e++):o>191&&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}}; |
| 3 | $(document).ready(function() { |
| 4 | // Spam score slider |
| 5 | var spam_slider = $('#spam_score')[0]; |
| 6 | if (typeof spam_slider !== 'undefined') { |
| 7 | noUiSlider.create(spam_slider, { |
| 8 | start: user_spam_score, |
| 9 | connect: [true, true, true], |
| 10 | range: { |
| 11 | 'min': [0], //stepsize is 50.000 |
| 12 | '50%': [10], |
| 13 | '70%': [20, 5], |
| 14 | '80%': [50, 10], |
| 15 | '90%': [100, 100], |
| 16 | '95%': [1000, 1000], |
| 17 | 'max': [5000] |
| 18 | }, |
| 19 | }); |
| 20 | var connect = spam_slider.querySelectorAll('.noUi-connect'); |
| 21 | var classes = ['c-1-color', 'c-2-color', 'c-3-color']; |
| 22 | for (var i = 0; i < connect.length; i++) { |
| 23 | connect[i].classList.add(classes[i]); |
| 24 | } |
| 25 | spam_slider.noUiSlider.on('update', function (values, handle) { |
| 26 | $('.spam-ham-score').text('< ' + Math.round(values[0] * 10) / 10); |
| 27 | $('.spam-spam-score').text(Math.round(values[0] * 10) / 10 + ' - ' + Math.round(values[1] * 10) / 10); |
| 28 | $('.spam-reject-score').text('> ' + Math.round(values[1] * 10) / 10); |
| 29 | $('#spam_score_value').val((Math.round(values[0] * 10) / 10) + ',' + (Math.round(values[1] * 10) / 10)); |
| 30 | }); |
| 31 | } |
| 32 | // syncjobLogModal |
| 33 | $('#syncjobLogModal').on('show.bs.modal', function(e) { |
| 34 | var syncjob_id = $(e.relatedTarget).data('syncjob-id'); |
| 35 | $.ajax({ |
| 36 | url: '/inc/ajax/syncjob_logs.php', |
| 37 | data: { id: syncjob_id }, |
| 38 | dataType: 'text', |
| 39 | success: function(data){ |
| 40 | $(e.currentTarget).find('#logText').text(data); |
| 41 | }, |
| 42 | error: function(xhr, status, error) { |
| 43 | $(e.currentTarget).find('#logText').text(xhr.responseText); |
| 44 | } |
| 45 | }); |
| 46 | }); |
| 47 | $(".arrow-toggle").on('click', function(e) { e.preventDefault(); $(this).find('.arrow').toggleClass("animation"); }); |
| 48 | $("#pushover_delete").click(function() { return confirm(lang.delete_ays); }); |
| 49 | |
| 50 | }); |
| 51 | jQuery(function($){ |
| 52 | // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery |
| 53 | var entityMap = { |
| 54 | '&': '&', |
| 55 | '<': '<', |
| 56 | '>': '>', |
| 57 | '"': '"', |
| 58 | "'": ''', |
| 59 | '/': '/', |
| 60 | '`': '`', |
| 61 | '=': '=' |
| 62 | }; |
| 63 | function escapeHtml(string) { |
| 64 | return String(string).replace(/[&<>"'`=\/]/g, function (s) { |
| 65 | return entityMap[s]; |
| 66 | }); |
| 67 | } |
| 68 | // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript |
| 69 | function validateEmail(email) { |
| 70 | 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,}))$/; |
| 71 | return re.test(email); |
| 72 | } |
| 73 | function unix_time_format(tm) { |
| 74 | var date = new Date(tm ? tm * 1000 : 0); |
| 75 | return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"}); |
| 76 | } |
| 77 | acl_data = JSON.parse(acl); |
| 78 | |
| 79 | $('.clear-last-logins').on('click', function () {if (confirm(lang.delete_ays)) {last_logins('reset');}}) |
| 80 | $(".login-history").on('click', function(e) {e.preventDefault(); last_logins('get', $(this).data('days'));$(this).addClass('active').siblings().removeClass('active');}); |
| 81 | |
| 82 | function last_logins(action, days = 7) { |
| 83 | if (action == 'get') { |
| 84 | $('.last-login').html('<i class="bi bi-hourglass"></i>' + lang.waiting); |
| 85 | $.ajax({ |
| 86 | dataType: 'json', |
| 87 | url: '/api/v1/get/last-login/' + encodeURIComponent(mailcow_cc_username) + '/' + days, |
| 88 | jsonp: false, |
| 89 | error: function () { |
| 90 | console.log('error reading last logins'); |
| 91 | }, |
| 92 | success: function (data) { |
| 93 | $('.last-login').html(); |
| 94 | if (data.ui.time) { |
| 95 | $('.last-login').html('<i class="bi bi-person-fill"></i> ' + lang.last_ui_login + ': ' + unix_time_format(data.ui.time)); |
| 96 | } else { |
| 97 | $('.last-login').text(lang.no_last_login); |
| 98 | } |
| 99 | if (data.sasl) { |
| 100 | $('.last-login').append('<ul class="list-group">'); |
| 101 | $.each(data.sasl, function (i, item) { |
| 102 | var datetime = new Date(item.datetime.replace(/-/g, "/")); |
| 103 | var local_datetime = datetime.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"}); |
| 104 | var service = '<div class="badge fs-6 bg-secondary">' + item.service.toUpperCase() + '</div>'; |
| 105 | var app_password = item.app_password ? ' <a href="/edit/app-passwd/' + item.app_password + '"><i class="bi bi-app-indicator"></i> ' + escapeHtml(item.app_password_name || "App") + '</a>' : ''; |
| 106 | var real_rip = item.real_rip.startsWith("Web") ? item.real_rip : '<a href="https://bgp.he.net/ip/' + item.real_rip + '" target="_blank">' + item.real_rip + "</a>"; |
| 107 | var ip_location = item.location ? ' <span class="flag-icon flag-icon-' + item.location.toLowerCase() + '"></span>' : ''; |
| 108 | var ip_data = real_rip + ip_location + app_password; |
| 109 | $(".last-login").append('<li class="list-group-item">' + local_datetime + " " + service + " " + lang.from + " " + ip_data + "</li>"); |
| 110 | }) |
| 111 | $('.last-login').append('</ul>'); |
| 112 | } |
| 113 | } |
| 114 | }) |
| 115 | } else if (action == 'reset') { |
| 116 | $.ajax({ |
| 117 | dataType: 'json', |
| 118 | url: '/api/v1/get/reset-last-login/' + encodeURIComponent(mailcow_cc_username), |
| 119 | jsonp: false, |
| 120 | error: function () { |
| 121 | console.log('cannot reset last logins'); |
| 122 | }, |
| 123 | success: function (data) { |
| 124 | last_logins('get'); |
| 125 | } |
| 126 | }) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | |
| 131 | function createSortableDate(td, cellData, date_string = false) { |
| 132 | if (date_string) |
| 133 | var date = new Date(cellData); |
| 134 | else |
| 135 | var date = new Date(cellData ? cellData * 1000 : 0); |
| 136 | |
| 137 | var timestamp = date.getTime(); |
| 138 | $(td).attr({ |
| 139 | "data-order": timestamp, |
| 140 | "data-sort": timestamp |
| 141 | }); |
| 142 | $(td).html(date.toLocaleDateString(LOCALE, DATETIME_FORMAT)); |
| 143 | } |
| 144 | function draw_tla_table() { |
| 145 | // just recalc width if instance already exists |
| 146 | if ($.fn.DataTable.isDataTable('#tla_table') ) { |
| 147 | $('#tla_table').DataTable().columns.adjust().responsive.recalc(); |
| 148 | return; |
| 149 | } |
| 150 | |
| 151 | $('#tla_table').DataTable({ |
| 152 | responsive: true, |
| 153 | processing: true, |
| 154 | serverSide: false, |
| 155 | stateSave: true, |
| 156 | pageLength: pagination_size, |
| 157 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 158 | "tr" + |
| 159 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
| 160 | language: lang_datatables, |
| 161 | order: [[4, 'desc']], |
| 162 | ajax: { |
| 163 | type: "GET", |
| 164 | url: "/api/v1/get/time_limited_aliases", |
| 165 | dataSrc: function(data){ |
| 166 | console.log(data); |
| 167 | $.each(data, function (i, item) { |
| 168 | if (acl_data.spam_alias === 1) { |
| 169 | item.action = '<div class="btn-group">' + |
| 170 | '<a href="#" data-action="delete_selected" data-id="single-tla" data-api-url="delete/time_limited_alias" data-item="' + encodeURIComponent(item.address) + '" class="btn btn-xs btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 171 | '</div>'; |
| 172 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="tla" name="multi_select" value="' + encodeURIComponent(item.address) + '" />'; |
| 173 | item.address = escapeHtml(item.address); |
| 174 | } |
| 175 | else { |
| 176 | item.chkbox = '<input type="checkbox" class="form-check-input" disabled />'; |
| 177 | item.action = '<span>-</span>'; |
| 178 | } |
| 179 | }); |
| 180 | |
| 181 | return data; |
| 182 | } |
| 183 | }, |
| 184 | columns: [ |
| 185 | { |
| 186 | // placeholder, so checkbox will not block child row toggle |
| 187 | title: '', |
| 188 | data: null, |
| 189 | searchable: false, |
| 190 | orderable: false, |
| 191 | defaultContent: '' |
| 192 | }, |
| 193 | { |
| 194 | title: '', |
| 195 | data: 'chkbox', |
| 196 | searchable: false, |
| 197 | orderable: false, |
| 198 | defaultContent: '' |
| 199 | }, |
| 200 | { |
| 201 | title: lang.alias, |
| 202 | data: 'address', |
| 203 | defaultContent: '' |
| 204 | }, |
| 205 | { |
| 206 | title: lang.alias_valid_until, |
| 207 | data: 'validity', |
| 208 | defaultContent: '', |
| 209 | createdCell: function(td, cellData) { |
| 210 | createSortableDate(td, cellData) |
| 211 | } |
| 212 | }, |
| 213 | { |
| 214 | title: lang.created_on, |
| 215 | data: 'created', |
| 216 | defaultContent: '', |
| 217 | createdCell: function(td, cellData) { |
| 218 | createSortableDate(td, cellData, true) |
| 219 | } |
| 220 | }, |
| 221 | { |
| 222 | title: lang.action, |
| 223 | data: 'action', |
| 224 | className: 'dt-sm-head-hidden dt-text-right', |
| 225 | defaultContent: '' |
| 226 | } |
| 227 | ] |
| 228 | }); |
| 229 | } |
| 230 | function draw_sync_job_table() { |
| 231 | // just recalc width if instance already exists |
| 232 | if ($.fn.DataTable.isDataTable('#sync_job_table') ) { |
| 233 | $('#sync_job_table').DataTable().columns.adjust().responsive.recalc(); |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | $('#sync_job_table').DataTable({ |
| 238 | responsive: true, |
| 239 | processing: true, |
| 240 | serverSide: false, |
| 241 | stateSave: true, |
| 242 | pageLength: pagination_size, |
| 243 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 244 | "tr" + |
| 245 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
| 246 | language: lang_datatables, |
| 247 | ajax: { |
| 248 | type: "GET", |
| 249 | url: '/api/v1/get/syncjobs/' + encodeURIComponent(mailcow_cc_username) + '/no_log', |
| 250 | dataSrc: function(data){ |
| 251 | console.log(data); |
| 252 | $.each(data, function (i, item) { |
| 253 | item.user1 = escapeHtml(item.user1); |
| 254 | item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + item.id + '">' + lang.open_logs + '</a>' |
| 255 | if (!item.exclude > 0) { |
| 256 | item.exclude = '-'; |
| 257 | } else { |
| 258 | item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>'; |
| 259 | } |
| 260 | item.server_w_port = escapeHtml(item.user1 + '@' + item.host1 + ':' + item.port1); |
| 261 | if (acl_data.syncjobs === 1) { |
| 262 | item.action = '<div class="btn-group">' + |
| 263 | '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 264 | '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 265 | '</div>'; |
| 266 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="syncjob" name="multi_select" value="' + item.id + '" />'; |
| 267 | } |
| 268 | else { |
| 269 | item.action = '<span>-</span>'; |
| 270 | item.chkbox = '<input type="checkbox" class="form-check-input" disabled />'; |
| 271 | } |
| 272 | if (item.is_running == 1) { |
| 273 | item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>'; |
| 274 | } else { |
| 275 | item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>'; |
| 276 | } |
| 277 | if (!item.last_run > 0) { |
| 278 | item.last_run = lang.waiting; |
| 279 | } |
| 280 | if (item.success == null) { |
| 281 | item.success = '-'; |
| 282 | item.exit_status = ''; |
| 283 | } else { |
| 284 | item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>'; |
| 285 | } |
| 286 | if (lang['syncjob_'+item.exit_status]) { |
| 287 | item.exit_status = lang['syncjob_'+item.exit_status]; |
| 288 | } else if (item.success != '-') { |
| 289 | item.exit_status = lang.syncjob_check_log; |
| 290 | } |
| 291 | item.exit_status = item.success + ' ' + item.exit_status; |
| 292 | }); |
| 293 | |
| 294 | return data; |
| 295 | } |
| 296 | }, |
| 297 | columns: [ |
| 298 | { |
| 299 | // placeholder, so checkbox will not block child row toggle |
| 300 | title: '', |
| 301 | data: null, |
| 302 | searchable: false, |
| 303 | orderable: false, |
| 304 | defaultContent: '', |
| 305 | responsivePriority: 1 |
| 306 | }, |
| 307 | { |
| 308 | title: '', |
| 309 | data: 'chkbox', |
| 310 | searchable: false, |
| 311 | orderable: false, |
| 312 | defaultContent: '', |
| 313 | responsivePriority: 2 |
| 314 | }, |
| 315 | { |
| 316 | title: 'ID', |
| 317 | data: 'id', |
| 318 | defaultContent: '', |
| 319 | responsivePriority: 3 |
| 320 | }, |
| 321 | { |
| 322 | title: 'Server', |
| 323 | data: 'server_w_port', |
| 324 | defaultContent: '' |
| 325 | }, |
| 326 | { |
| 327 | title: lang.username, |
| 328 | data: 'user1', |
| 329 | defaultContent: '', |
| 330 | responsivePriority: 3 |
| 331 | }, |
| 332 | { |
| 333 | title: lang.last_run, |
| 334 | data: 'last_run', |
| 335 | defaultContent: '' |
| 336 | }, |
| 337 | { |
| 338 | title: lang.syncjob_last_run_result, |
| 339 | data: 'exit_status', |
| 340 | defaultContent: '' |
| 341 | }, |
| 342 | { |
| 343 | title: 'Log', |
| 344 | data: 'log', |
| 345 | defaultContent: '' |
| 346 | }, |
| 347 | { |
| 348 | title: lang.active, |
| 349 | data: 'active', |
| 350 | defaultContent: '', |
| 351 | render: function (data, type) { |
| 352 | return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>' |
| 353 | } |
| 354 | }, |
| 355 | { |
| 356 | title: lang.status, |
| 357 | data: 'is_running', |
| 358 | defaultContent: '', |
| 359 | responsivePriority: 5 |
| 360 | }, |
| 361 | { |
| 362 | title: lang.encryption, |
| 363 | data: 'enc1', |
| 364 | defaultContent: '' |
| 365 | }, |
| 366 | { |
| 367 | title: lang.excludes, |
| 368 | data: 'exclude', |
| 369 | defaultContent: '' |
| 370 | }, |
| 371 | { |
| 372 | title: lang.interval + " (min)", |
| 373 | data: 'mins_interval', |
| 374 | defaultContent: '' |
| 375 | }, |
| 376 | { |
| 377 | title: lang.action, |
| 378 | data: 'action', |
| 379 | className: 'dt-sm-head-hidden dt-text-right', |
| 380 | defaultContent: '', |
| 381 | responsivePriority: 5 |
| 382 | } |
| 383 | ] |
| 384 | }); |
| 385 | } |
| 386 | function draw_app_passwd_table() { |
| 387 | // just recalc width if instance already exists |
| 388 | if ($.fn.DataTable.isDataTable('#app_passwd_table') ) { |
| 389 | $('#app_passwd_table').DataTable().columns.adjust().responsive.recalc(); |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | $('#app_passwd_table').DataTable({ |
| 394 | responsive: true, |
| 395 | processing: true, |
| 396 | serverSide: false, |
| 397 | stateSave: true, |
| 398 | pageLength: pagination_size, |
| 399 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 400 | "tr" + |
| 401 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
| 402 | language: lang_datatables, |
| 403 | ajax: { |
| 404 | type: "GET", |
| 405 | url: '/api/v1/get/app-passwd/all', |
| 406 | dataSrc: function(data){ |
| 407 | console.log(data); |
| 408 | $.each(data, function (i, item) { |
| 409 | item.name = escapeHtml(item.name) |
| 410 | item.protocols = [] |
| 411 | if (item.imap_access == 1) { item.protocols.push("<code>IMAP</code>"); } |
| 412 | if (item.smtp_access == 1) { item.protocols.push("<code>SMTP</code>"); } |
| 413 | if (item.eas_access == 1) { item.protocols.push("<code>EAS/ActiveSync</code>"); } |
| 414 | if (item.dav_access == 1) { item.protocols.push("<code>DAV</code>"); } |
| 415 | if (item.pop3_access == 1) { item.protocols.push("<code>POP3</code>"); } |
| 416 | if (item.sieve_access == 1) { item.protocols.push("<code>Sieve</code>"); } |
| 417 | item.protocols = item.protocols.join(" ") |
| 418 | if (acl_data.app_passwds === 1) { |
| 419 | item.action = '<div class="btn-group">' + |
| 420 | '<a href="/edit/app-passwd/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' + |
| 421 | '<a href="#" data-action="delete_selected" data-id="single-apppasswd" data-api-url="delete/app-passwd" data-item="' + item.id + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' + |
| 422 | '</div>'; |
| 423 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="apppasswd" name="multi_select" value="' + item.id + '" />'; |
| 424 | } |
| 425 | else { |
| 426 | item.action = '<span>-</span>'; |
| 427 | item.chkbox = '<input type="checkbox" class="form-check-input" disabled />'; |
| 428 | } |
| 429 | }); |
| 430 | |
| 431 | return data; |
| 432 | } |
| 433 | }, |
| 434 | columns: [ |
| 435 | { |
| 436 | // placeholder, so checkbox will not block child row toggle |
| 437 | title: '', |
| 438 | data: null, |
| 439 | searchable: false, |
| 440 | orderable: false, |
| 441 | defaultContent: '' |
| 442 | }, |
| 443 | { |
| 444 | title: '', |
| 445 | data: 'chkbox', |
| 446 | searchable: false, |
| 447 | orderable: false, |
| 448 | defaultContent: '' |
| 449 | }, |
| 450 | { |
| 451 | title: 'ID', |
| 452 | data: 'id', |
| 453 | defaultContent: '' |
| 454 | }, |
| 455 | { |
| 456 | title: lang.app_name, |
| 457 | data: 'name', |
| 458 | defaultContent: '' |
| 459 | }, |
| 460 | { |
| 461 | title: lang.allowed_protocols, |
| 462 | data: 'protocols', |
| 463 | defaultContent: '' |
| 464 | }, |
| 465 | { |
| 466 | title: lang.active, |
| 467 | data: 'active', |
| 468 | defaultContent: '', |
| 469 | render: function (data, type) { |
| 470 | return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>' |
| 471 | } |
| 472 | }, |
| 473 | { |
| 474 | title: lang.action, |
| 475 | data: 'action', |
| 476 | className: 'dt-sm-head-hidden dt-text-right', |
| 477 | defaultContent: '' |
| 478 | } |
| 479 | ] |
| 480 | }); |
| 481 | } |
| 482 | function draw_wl_policy_mailbox_table() { |
| 483 | // just recalc width if instance already exists |
| 484 | if ($.fn.DataTable.isDataTable('#wl_policy_mailbox_table') ) { |
| 485 | $('#wl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc(); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | $('#wl_policy_mailbox_table').DataTable({ |
| 490 | responsive: true, |
| 491 | processing: true, |
| 492 | serverSide: false, |
| 493 | stateSave: true, |
| 494 | pageLength: pagination_size, |
| 495 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 496 | "tr" + |
| 497 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
| 498 | language: lang_datatables, |
| 499 | ajax: { |
| 500 | type: "GET", |
| 501 | url: '/api/v1/get/policy_wl_mailbox', |
| 502 | dataSrc: function(data){ |
| 503 | console.log(data); |
| 504 | $.each(data, function (i, item) { |
| 505 | if (validateEmail(item.object)) { |
| 506 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />'; |
| 507 | } |
| 508 | else { |
| 509 | item.chkbox = '<input type="checkbox" class="form-check-input" disabled title="' + lang.spamfilter_table_domain_policy + '" />'; |
| 510 | } |
| 511 | if (acl_data.spam_policy === 0) { |
| 512 | item.chkbox = '<input type="checkbox" class="form-check-input" disabled />'; |
| 513 | } |
| 514 | }); |
| 515 | |
| 516 | return data; |
| 517 | } |
| 518 | }, |
| 519 | columns: [ |
| 520 | { |
| 521 | // placeholder, so checkbox will not block child row toggle |
| 522 | title: '', |
| 523 | data: null, |
| 524 | searchable: false, |
| 525 | orderable: false, |
| 526 | defaultContent: '' |
| 527 | }, |
| 528 | { |
| 529 | title: '', |
| 530 | data: 'chkbox', |
| 531 | searchable: false, |
| 532 | orderable: false, |
| 533 | defaultContent: '' |
| 534 | }, |
| 535 | { |
| 536 | title: 'ID', |
| 537 | data: 'prefid', |
| 538 | defaultContent: '' |
| 539 | }, |
| 540 | { |
| 541 | title: lang.spamfilter_table_rule, |
| 542 | data: 'value', |
| 543 | defaultContent: '' |
| 544 | }, |
| 545 | { |
| 546 | title:'Scope', |
| 547 | data: 'object', |
| 548 | defaultContent: '' |
| 549 | } |
| 550 | ] |
| 551 | }); |
| 552 | } |
| 553 | function draw_bl_policy_mailbox_table() { |
| 554 | // just recalc width if instance already exists |
| 555 | if ($.fn.DataTable.isDataTable('#bl_policy_mailbox_table') ) { |
| 556 | $('#bl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc(); |
| 557 | return; |
| 558 | } |
| 559 | |
| 560 | $('#bl_policy_mailbox_table').DataTable({ |
| 561 | responsive: true, |
| 562 | processing: true, |
| 563 | serverSide: false, |
| 564 | stateSave: true, |
| 565 | pageLength: pagination_size, |
| 566 | dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" + |
| 567 | "tr" + |
| 568 | "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>", |
| 569 | language: lang_datatables, |
| 570 | ajax: { |
| 571 | type: "GET", |
| 572 | url: '/api/v1/get/policy_bl_mailbox', |
| 573 | dataSrc: function(data){ |
| 574 | console.log(data); |
| 575 | $.each(data, function (i, item) { |
| 576 | if (validateEmail(item.object)) { |
| 577 | item.chkbox = '<input type="checkbox" class="form-check-input" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />'; |
| 578 | } |
| 579 | else { |
| 580 | item.chkbox = '<input type="checkbox" class="form-check-input" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />'; |
| 581 | } |
| 582 | if (acl_data.spam_policy === 0) { |
| 583 | item.chkbox = '<input type="checkbox" class="form-check-input" disabled />'; |
| 584 | } |
| 585 | }); |
| 586 | |
| 587 | return data; |
| 588 | } |
| 589 | }, |
| 590 | columns: [ |
| 591 | { |
| 592 | // placeholder, so checkbox will not block child row toggle |
| 593 | title: '', |
| 594 | data: null, |
| 595 | searchable: false, |
| 596 | orderable: false, |
| 597 | defaultContent: '' |
| 598 | }, |
| 599 | { |
| 600 | title: '', |
| 601 | data: 'chkbox', |
| 602 | searchable: false, |
| 603 | orderable: false, |
| 604 | defaultContent: '' |
| 605 | }, |
| 606 | { |
| 607 | title: 'ID', |
| 608 | data: 'prefid', |
| 609 | defaultContent: '' |
| 610 | }, |
| 611 | { |
| 612 | title: lang.spamfilter_table_rule, |
| 613 | data: 'value', |
| 614 | defaultContent: '' |
| 615 | }, |
| 616 | { |
| 617 | title:'Scope', |
| 618 | data: 'object', |
| 619 | defaultContent: '' |
| 620 | } |
| 621 | ] |
| 622 | }); |
| 623 | } |
| 624 | |
| 625 | // FIDO2 friendly name modal |
| 626 | $('#fido2ChangeFn').on('show.bs.modal', function (e) { |
| 627 | rename_link = $(e.relatedTarget) |
| 628 | if (rename_link != null) { |
| 629 | $('#fido2_cid').val(rename_link.data('cid')); |
| 630 | $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject'))); |
| 631 | } |
| 632 | }) |
| 633 | |
| 634 | // Sieve data modal |
| 635 | $('#userFilterModal').on('show.bs.modal', function(e) { |
| 636 | $('#user_sieve_filter').text(lang.loading); |
| 637 | $.ajax({ |
| 638 | dataType: 'json', |
| 639 | url: '/api/v1/get/active-user-sieve/' + encodeURIComponent(mailcow_cc_username), |
| 640 | jsonp: false, |
| 641 | error: function () { |
| 642 | console.log('Cannot get active sieve script'); |
| 643 | }, |
| 644 | complete: function (data) { |
| 645 | if (data.responseText == '{}') { |
| 646 | $('#user_sieve_filter').text(lang.no_active_filter); |
| 647 | } else { |
| 648 | $('#user_sieve_filter').text(JSON.parse(data.responseText)); |
| 649 | } |
| 650 | } |
| 651 | }) |
| 652 | }); |
| 653 | $('#userFilterModal').on('hidden.bs.modal', function () { |
| 654 | $('#user_sieve_filter').text(lang.loading); |
| 655 | }); |
| 656 | |
| 657 | // detect element visibility changes |
| 658 | function onVisible(element, callback) { |
| 659 | $(document).ready(function() { |
| 660 | element_object = document.querySelector(element); |
| 661 | if (element_object === null) return; |
| 662 | |
| 663 | new IntersectionObserver((entries, observer) => { |
| 664 | entries.forEach(entry => { |
| 665 | if(entry.intersectionRatio > 0) { |
| 666 | callback(element_object); |
| 667 | } |
| 668 | }); |
| 669 | }).observe(element_object); |
| 670 | }); |
| 671 | } |
| 672 | |
| 673 | // Load only if the tab is visible |
| 674 | onVisible("[id^=tla_table]", () => draw_tla_table()); |
| 675 | onVisible("[id^=bl_policy_mailbox_table]", () => draw_bl_policy_mailbox_table()); |
| 676 | onVisible("[id^=wl_policy_mailbox_table]", () => draw_wl_policy_mailbox_table()); |
| 677 | onVisible("[id^=sync_job_table]", () => draw_sync_job_table()); |
| 678 | onVisible("[id^=app_passwd_table]", () => draw_app_passwd_table()); |
| 679 | last_logins('get'); |
| 680 | }); |