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