blob: 36bcfa63e86dabc7401cec30ac14a43bd793ba15 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001// Base64 functions
2var 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}};
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01003$(document).ready(function() {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02004 // 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
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010033 $('#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); });
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020049
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010050});
51jQuery(function($){
52 // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
53 var entityMap = {
54 '&': '&amp;',
55 '<': '&lt;',
56 '>': '&gt;',
57 '"': '&quot;',
58 "'": '&#39;',
59 '/': '&#x2F;',
60 '`': '&#x60;',
61 '=': '&#x3D;'
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);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020078
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
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010082 function last_logins(action, days = 7) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020083 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"});
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100104 var service = '<div class="badge fs-6 bg-secondary">' + item.service.toUpperCase() + '</div>';
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100105 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;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200109 $(".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 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100129
130 function draw_tla_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100131 // just recalc width if instance already exists
132 if ($.fn.DataTable.isDataTable('#tla_table') ) {
133 $('#tla_table').DataTable().columns.adjust().responsive.recalc();
134 return;
135 }
136
137 $('#tla_table').DataTable({
138 processing: true,
139 serverSide: false,
140 language: lang_datatables,
141 ajax: {
142 type: "GET",
143 url: "/api/v1/get/time_limited_aliases",
144 dataSrc: function(data){
145 console.log(data);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100146 $.each(data, function (i, item) {
147 if (acl_data.spam_alias === 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100148 item.action = '<div class="btn-group">' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200149 '<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>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100150 '</div>';
151 item.chkbox = '<input type="checkbox" data-id="tla" name="multi_select" value="' + encodeURIComponent(item.address) + '" />';
152 item.address = escapeHtml(item.address);
153 }
154 else {
155 item.chkbox = '<input type="checkbox" disabled />';
156 item.action = '<span>-</span>';
157 }
158 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100159
160 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100161 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100162 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100163 columns: [
164 {
165 // placeholder, so checkbox will not block child row toggle
166 title: '',
167 data: null,
168 searchable: false,
169 orderable: false,
170 defaultContent: ''
171 },
172 {
173 title: '',
174 data: 'chkbox',
175 searchable: false,
176 orderable: false,
177 defaultContent: ''
178 },
179 {
180 title: lang.alias,
181 data: 'address',
182 defaultContent: ''
183 },
184 {
185 title: lang.alias_valid_until,
186 data: 'validity',
187 defaultContent: '',
188 render: function (data, type) {
189 var date = new Date(data ? data * 1000 : 0);
190 return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
191 }
192 },
193 {
194 title: lang.created_on,
195 data: 'created',
196 defaultContent: '',
197 render: function (data, type) {
198 var date = new Date(data.replace(/-/g, "/"));
199 return date.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
200 }
201 },
202 {
203 title: lang.action,
204 data: 'action',
205 className: 'text-md-end dt-sm-head-hidden dt-body-right',
206 defaultContent: ''
207 }
208 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100209 });
210 }
211 function draw_sync_job_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100212 // just recalc width if instance already exists
213 if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
214 $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
215 return;
216 }
217
218 $('#sync_job_table').DataTable({
219 processing: true,
220 serverSide: false,
221 language: lang_datatables,
222 ajax: {
223 type: "GET",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100224 url: '/api/v1/get/syncjobs/' + encodeURIComponent(mailcow_cc_username) + '/no_log',
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100225 dataSrc: function(data){
226 console.log(data);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100227 $.each(data, function (i, item) {
228 item.user1 = escapeHtml(item.user1);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100229 item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + item.id + '">' + lang.open_logs + '</a>'
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100230 if (!item.exclude > 0) {
231 item.exclude = '-';
232 } else {
233 item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
234 }
235 item.server_w_port = escapeHtml(item.user1 + '@' + item.host1 + ':' + item.port1);
236 if (acl_data.syncjobs === 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100237 item.action = '<div class="btn-group">' +
238 '<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>' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200239 '<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>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100240 '</div>';
241 item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
242 }
243 else {
244 item.action = '<span>-</span>';
245 item.chkbox = '<input type="checkbox" disabled />';
246 }
247 if (item.is_running == 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100248 item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100249 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100250 item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100251 }
252 if (!item.last_run > 0) {
253 item.last_run = lang.waiting;
254 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100255 if (item.success == null) {
256 item.success = '-';
257 item.exit_status = '';
258 } else {
259 item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
260 }
261 if (lang['syncjob_'+item.exit_status]) {
262 item.exit_status = lang['syncjob_'+item.exit_status];
263 } else if (item.success != '-') {
264 item.exit_status = lang.syncjob_check_log;
265 }
266 item.exit_status = item.success + ' ' + item.exit_status;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100267 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100268
269 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100270 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100271 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100272 columns: [
273 {
274 // placeholder, so checkbox will not block child row toggle
275 title: '',
276 data: null,
277 searchable: false,
278 orderable: false,
279 defaultContent: '',
280 responsivePriority: 1
281 },
282 {
283 title: '',
284 data: 'chkbox',
285 searchable: false,
286 orderable: false,
287 defaultContent: '',
288 responsivePriority: 2
289 },
290 {
291 title: 'ID',
292 data: 'id',
293 defaultContent: '',
294 responsivePriority: 3
295 },
296 {
297 title: 'Server',
298 data: 'server_w_port',
299 defaultContent: ''
300 },
301 {
302 title: lang.username,
303 data: 'user1',
304 defaultContent: '',
305 responsivePriority: 3
306 },
307 {
308 title: lang.last_run,
309 data: 'last_run',
310 defaultContent: ''
311 },
312 {
313 title: lang.syncjob_last_run_result,
314 data: 'exit_status',
315 defaultContent: ''
316 },
317 {
318 title: 'Log',
319 data: 'log',
320 defaultContent: ''
321 },
322 {
323 title: lang.active,
324 data: 'active',
325 defaultContent: '',
326 render: function (data, type) {
327 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>'
328 }
329 },
330 {
331 title: lang.status,
332 data: 'is_running',
333 defaultContent: '',
334 responsivePriority: 5
335 },
336 {
337 title: lang.encryption,
338 data: 'enc1',
339 defaultContent: ''
340 },
341 {
342 title: lang.excludes,
343 data: 'exclude',
344 defaultContent: ''
345 },
346 {
347 title: lang.interval + " (min)",
348 data: 'mins_interval',
349 defaultContent: ''
350 },
351 {
352 title: lang.action,
353 data: 'action',
354 className: 'text-md-end dt-sm-head-hidden dt-body-right',
355 defaultContent: '',
356 responsivePriority: 5
357 }
358 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100359 });
360 }
361 function draw_app_passwd_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100362 // just recalc width if instance already exists
363 if ($.fn.DataTable.isDataTable('#app_passwd_table') ) {
364 $('#app_passwd_table').DataTable().columns.adjust().responsive.recalc();
365 return;
366 }
367
368 $('#app_passwd_table').DataTable({
369 processing: true,
370 serverSide: false,
371 language: lang_datatables,
372 ajax: {
373 type: "GET",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100374 url: '/api/v1/get/app-passwd/all',
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100375 dataSrc: function(data){
376 console.log(data);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100377 $.each(data, function (i, item) {
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100378 item.name = escapeHtml(item.name)
379 item.protocols = []
380 if (item.imap_access == 1) { item.protocols.push("<code>IMAP</code>"); }
381 if (item.smtp_access == 1) { item.protocols.push("<code>SMTP</code>"); }
382 if (item.eas_access == 1) { item.protocols.push("<code>EAS/ActiveSync</code>"); }
383 if (item.dav_access == 1) { item.protocols.push("<code>DAV</code>"); }
384 if (item.pop3_access == 1) { item.protocols.push("<code>POP3</code>"); }
385 if (item.sieve_access == 1) { item.protocols.push("<code>Sieve</code>"); }
386 item.protocols = item.protocols.join(" ")
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100387 if (acl_data.app_passwds === 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100388 item.action = '<div class="btn-group">' +
389 '<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>' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200390 '<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>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100391 '</div>';
392 item.chkbox = '<input type="checkbox" data-id="apppasswd" name="multi_select" value="' + item.id + '" />';
393 }
394 else {
395 item.action = '<span>-</span>';
396 item.chkbox = '<input type="checkbox" disabled />';
397 }
398 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100399
400 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100401 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100402 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100403 columns: [
404 {
405 // placeholder, so checkbox will not block child row toggle
406 title: '',
407 data: null,
408 searchable: false,
409 orderable: false,
410 defaultContent: ''
411 },
412 {
413 title: '',
414 data: 'chkbox',
415 searchable: false,
416 orderable: false,
417 defaultContent: ''
418 },
419 {
420 title: 'ID',
421 data: 'id',
422 defaultContent: ''
423 },
424 {
425 title: lang.app_name,
426 data: 'name',
427 defaultContent: ''
428 },
429 {
430 title: lang.allowed_protocols,
431 data: 'protocols',
432 defaultContent: ''
433 },
434 {
435 title: lang.active,
436 data: 'active',
437 defaultContent: '',
438 render: function (data, type) {
439 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>'
440 }
441 },
442 {
443 title: lang.action,
444 data: 'action',
445 className: 'text-md-end dt-sm-head-hidden dt-body-right',
446 defaultContent: ''
447 }
448 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100449 });
450 }
451 function draw_wl_policy_mailbox_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100452 // just recalc width if instance already exists
453 if ($.fn.DataTable.isDataTable('#wl_policy_mailbox_table') ) {
454 $('#wl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc();
455 return;
456 }
457
458 $('#wl_policy_mailbox_table').DataTable({
459 processing: true,
460 serverSide: false,
461 language: lang_datatables,
462 ajax: {
463 type: "GET",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100464 url: '/api/v1/get/policy_wl_mailbox',
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100465 dataSrc: function(data){
466 console.log(data);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100467 $.each(data, function (i, item) {
468 if (validateEmail(item.object)) {
469 item.chkbox = '<input type="checkbox" data-id="policy_wl_mailbox" name="multi_select" value="' + item.prefid + '" />';
470 }
471 else {
472 item.chkbox = '<input type="checkbox" disabled title="' + lang.spamfilter_table_domain_policy + '" />';
473 }
474 if (acl_data.spam_policy === 0) {
475 item.chkbox = '<input type="checkbox" disabled />';
476 }
477 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100478
479 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100480 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100481 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100482 columns: [
483 {
484 // placeholder, so checkbox will not block child row toggle
485 title: '',
486 data: null,
487 searchable: false,
488 orderable: false,
489 defaultContent: ''
490 },
491 {
492 title: '',
493 data: 'chkbox',
494 searchable: false,
495 orderable: false,
496 defaultContent: ''
497 },
498 {
499 title: 'ID',
500 data: 'prefid',
501 defaultContent: ''
502 },
503 {
504 title: lang.spamfilter_table_rule,
505 data: 'value',
506 defaultContent: ''
507 },
508 {
509 title:'Scope',
510 data: 'object',
511 defaultContent: ''
512 }
513 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100514 });
515 }
516 function draw_bl_policy_mailbox_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100517 // just recalc width if instance already exists
518 if ($.fn.DataTable.isDataTable('#bl_policy_mailbox_table') ) {
519 $('#bl_policy_mailbox_table').DataTable().columns.adjust().responsive.recalc();
520 return;
521 }
522
523 $('#bl_policy_mailbox_table').DataTable({
524 processing: true,
525 serverSide: false,
526 language: lang_datatables,
527 ajax: {
528 type: "GET",
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100529 url: '/api/v1/get/policy_bl_mailbox',
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100530 dataSrc: function(data){
531 console.log(data);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100532 $.each(data, function (i, item) {
533 if (validateEmail(item.object)) {
534 item.chkbox = '<input type="checkbox" data-id="policy_bl_mailbox" name="multi_select" value="' + item.prefid + '" />';
535 }
536 else {
537 item.chkbox = '<input type="checkbox" disabled tooltip="' + lang.spamfilter_table_domain_policy + '" />';
538 }
539 if (acl_data.spam_policy === 0) {
540 item.chkbox = '<input type="checkbox" disabled />';
541 }
542 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100543
544 return data;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100545 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100546 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100547 columns: [
548 {
549 // placeholder, so checkbox will not block child row toggle
550 title: '',
551 data: null,
552 searchable: false,
553 orderable: false,
554 defaultContent: ''
555 },
556 {
557 title: '',
558 data: 'chkbox',
559 searchable: false,
560 orderable: false,
561 defaultContent: ''
562 },
563 {
564 title: 'ID',
565 data: 'prefid',
566 defaultContent: ''
567 },
568 {
569 title: lang.spamfilter_table_rule,
570 data: 'value',
571 defaultContent: ''
572 },
573 {
574 title:'Scope',
575 data: 'object',
576 defaultContent: ''
577 }
578 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100579 });
580 }
581
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100582 // FIDO2 friendly name modal
583 $('#fido2ChangeFn').on('show.bs.modal', function (e) {
584 rename_link = $(e.relatedTarget)
585 if (rename_link != null) {
586 $('#fido2_cid').val(rename_link.data('cid'));
587 $('#fido2_subject_desc').text(Base64.decode(rename_link.data('subject')));
588 }
589 })
590
591 // Sieve data modal
592 $('#userFilterModal').on('show.bs.modal', function(e) {
593 $('#user_sieve_filter').text(lang.loading);
594 $.ajax({
595 dataType: 'json',
596 url: '/api/v1/get/active-user-sieve/' + encodeURIComponent(mailcow_cc_username),
597 jsonp: false,
598 error: function () {
599 console.log('Cannot get active sieve script');
600 },
601 complete: function (data) {
602 if (data.responseText == '{}') {
603 $('#user_sieve_filter').text(lang.no_active_filter);
604 } else {
605 $('#user_sieve_filter').text(JSON.parse(data.responseText));
606 }
607 }
608 })
609 });
610 $('#userFilterModal').on('hidden.bs.modal', function () {
611 $('#user_sieve_filter').text(lang.loading);
612 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100613
614 // detect element visibility changes
615 function onVisible(element, callback) {
616 $(document).ready(function() {
617 element_object = document.querySelector(element);
618 if (element_object === null) return;
619
620 new IntersectionObserver((entries, observer) => {
621 entries.forEach(entry => {
622 if(entry.intersectionRatio > 0) {
623 callback(element_object);
624 }
625 });
626 }).observe(element_object);
627 });
628 }
629
630 // Load only if the tab is visible
631 onVisible("[id^=tla_table]", () => draw_tla_table());
632 onVisible("[id^=bl_policy_mailbox_table]", () => draw_bl_policy_mailbox_table());
633 onVisible("[id^=wl_policy_mailbox_table]", () => draw_wl_policy_mailbox_table());
634 onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
635 onVisible("[id^=app_passwd_table]", () => draw_app_passwd_table());
636 last_logins('get');
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200637});