blob: 5ad5cceabeb4650ef2665d682bb8597d6d371344 [file] [log] [blame]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001$(document).ready(function() {
2 acl_data = JSON.parse(acl);
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01003 // Set paging
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01004 // Clone mailbox mass actions
5 $("div").find("[data-actions-header='true'").each(function() {
6 $(this).html($(this).nextAll('.mass-actions-mailbox:first').html());
7 });
8 // Auto-fill domain quota when adding new domain
9 auto_fill_quota = function(domain) {
10 $.get("/api/v1/get/domain/" + domain, function(data){
11 var result = $.parseJSON(JSON.stringify(data));
12 def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576);
13 max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
14 if (max_new_mailbox_quota != '0') {
15 $('.addInputQuotaExhausted').hide();
16 $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
17 $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
18 $('#addInputQuota').val(def_new_mailbox_quota);
19 }
20 else {
21 $('.addInputQuotaExhausted').show();
22 $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
23 $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
24 $('#addInputQuota').val(max_new_mailbox_quota);
25 }
26 });
27 }
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +020028 $('#addSelectDomain').on('change', function() {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010029 auto_fill_quota($('#addSelectDomain').val());
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +020030 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010031 auto_fill_quota($('#addSelectDomain').val());
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +010032
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010033 $(".goto_checkbox").click(function( event ) {
34 $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
35 if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
36 $('#textarea_alias_goto').prop('disabled', true);
37 }
38 else {
39 $("#textarea_alias_goto").removeAttr('disabled');
40 }
41 });
42 $('#addAliasModal').on('show.bs.modal', function(e) {
43 if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
44 $('#textarea_alias_goto').prop('disabled', true);
45 }
46 else {
47 $("#textarea_alias_goto").removeAttr('disabled');
48 }
49 });
50 // Log modal
51 $('#syncjobLogModal').on('show.bs.modal', function(e) {
52 var syncjob_id = $(e.relatedTarget).data('syncjob-id');
53 $.ajax({
54 url: '/inc/ajax/syncjob_logs.php',
55 data: { id: syncjob_id },
56 dataType: 'text',
57 success: function(data){
58 $(e.currentTarget).find('#logText').text(data);
59 },
60 error: function(xhr, status, error) {
61 $(e.currentTarget).find('#logText').text(xhr.responseText);
62 }
63 });
64 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010065 // Log modal
66 $('#dnsInfoModal').on('show.bs.modal', function(e) {
67 var domain = $(e.relatedTarget).data('domain');
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010068 $('.dns-modal-body').html('<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div>');
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010069 $.ajax({
70 url: '/inc/ajax/dns_diagnostics.php',
71 data: { domain: domain },
72 dataType: 'text',
73 success: function(data){
74 $('.dns-modal-body').html(data);
75 },
76 error: function(xhr, status, error) {
77 $('.dns-modal-body').html(xhr.responseText);
78 }
79 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010080 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010081 // @Open Domain add modal
82 $('#addDomainModal').on('show.bs.modal', function(e) {
83 $.ajax({
84 url: '/api/v1/get/domain/template/all',
85 data: {},
86 dataType: 'json',
87 success: async function(data){
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010088 $('#domain_templates').find('option').remove();
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010089 $('#domain_templates').selectpicker('destroy');
90 $('#domain_templates').selectpicker();
91 for (var i = 0; i < data.length; i++){
92 if (data[i].template === "Default"){
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +010093 $('#domain_templates').prepend($('<option>', {
94 'value': data[i].id,
95 'text': data[i].template,
96 'data-attributes': JSON.stringify(data[i].attributes),
97 'selected': true
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +010098 }));
99 setDomainTemplateData(data[i].attributes);
100 } else {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100101 $('#domain_templates').append($('<option>', {
102 'value': data[i].id,
103 'text': data[i].template,
104 'data-attributes': JSON.stringify(data[i].attributes),
105 'selected': false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100106 }));
107 }
108 };
109 $('#domain_templates').selectpicker("refresh");
110
111 // @selecting template
112 $('#domain_templates').on('change', function(){
113 var selected = $('#domain_templates option:selected');
114 var attr = selected.data('attributes');
115 setDomainTemplateData(attr);
116 });
117 },
118 error: function(xhr, status, error) {
119 console.log(error);
120 }
121 });
122 });
123 // @Open Mailbox add modal
124 $('#addMailboxModal').on('show.bs.modal', function(e) {
125 $.ajax({
126 url: '/api/v1/get/mailbox/template/all',
127 data: {},
128 dataType: 'json',
129 success: async function(data){
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100130 $('#mailbox_templates').find('option').remove();
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100131 $('#mailbox_templates').selectpicker('destroy');
132 $('#mailbox_templates').selectpicker();
133 for (var i = 0; i < data.length; i++){
134 if (data[i].template === "Default"){
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100135 $('#mailbox_templates').prepend($('<option>', {
136 'value': data[i].id,
137 'text': data[i].template,
138 'data-attributes': JSON.stringify(data[i].attributes),
139 'selected': true
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100140 }));
141 setMailboxTemplateData(data[i].attributes);
142 } else {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100143 $('#mailbox_templates').append($('<option>', {
144 value: data[i].id,
145 text : data[i].template,
146 'data-attributes': JSON.stringify(data[i].attributes),
147 'selected': false
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100148 }));
149 }
150 };
151 $('#mailbox_templates').selectpicker("refresh");
152
153 // @selecting template
154 $('#mailbox_templates').on('change', function(){
155 var selected = $('#mailbox_templates option:selected');
156 var attr = selected.data('attributes');
157 setMailboxTemplateData(attr);
158 });
159 },
160 error: function(xhr, status, error) {
161 console.log(error);
162 }
163 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100164 });
165 // Sieve data modal
166 $('#sieveDataModal').on('show.bs.modal', function(e) {
167 var sieveScript = $(e.relatedTarget).data('sieve-script');
168 $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
169 });
170 // Disable submit button on script change
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200171 $('.textarea-code').on('keyup', function() {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100172 // Disable all "save" buttons, could be a "related button only" function, todo
173 $('.add_sieve_script').attr({"disabled": true});
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200174 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100175 // Validate script data
176 $(".validate_sieve").click(function( event ) {
177 event.preventDefault();
178 var validation_button = $(this);
179 // Get script_data textarea content from form the button was clicked in
180 var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
181 $.ajax({
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100182 url: "/inc/ajax/sieve_validation.php",
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200183 type: "post",
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100184 data: { script: script },
185 complete: function(data) {
186 var response = (data.responseText);
187 response_obj = JSON.parse(response);
188 if (response_obj.type == "success") {
189 $(validation_button).next().attr({"disabled": false});
190 }
191 mailcow_alert_box(response_obj.msg, response_obj.type);
192 },
193 });
194 });
195 // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
196 // $("#active-script").closest('td').css('background-color','#b0f0a0');
197 // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
198 // });
199 $('#addResourceModal').on('shown.bs.modal', function() {
200 $("#multiple_bookings").val($("#multiple_bookings_select").val());
201 if ($("#multiple_bookings").val() == "custom") {
202 $("#multiple_bookings_custom_div").show();
203 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
204 }
205 })
206 $("#multiple_bookings_select").change(function() {
207 $("#multiple_bookings").val($("#multiple_bookings_select").val());
208 if ($("#multiple_bookings").val() == "custom") {
209 $("#multiple_bookings_custom_div").show();
210 }
211 else {
212 $("#multiple_bookings_custom_div").hide();
213 }
214 });
215 $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
216 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
217 });
218
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100219 function setDomainTemplateData(template){
220 $("#addDomain_max_aliases").val(template.max_num_aliases_for_domain);
221 $("#addDomain_max_mailboxes").val(template.max_num_mboxes_for_domain);
222 $("#addDomain_mailbox_quota_def").val(template.def_quota_for_mbox / 1048576);
223 $("#addDomain_mailbox_quota_m").val(template.max_quota_for_mbox / 1048576);
224 $("#addDomain_domain_quota_m").val(template.max_quota_for_domain / 1048576);
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100225
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100226 if (template.gal == 1){
227 $('#addDomain_gal').prop('checked', true);
228 } else {
229 $('#addDomain_gal').prop('checked', false);
230 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100231
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100232 if (template.active == 1){
233 $('#addDomain_active').prop('checked', true);
234 } else {
235 $('#addDomain_active').prop('checked', false);
236 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100237
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100238 $("#addDomain_rl_value").val(template.rl_value);
239 $('#addDomain_rl_frame').selectpicker('val', template.rl_frame);
240 $("#dkim_selector").val(template.dkim_selector);
241 if (!template.key_size)
242 template.key_size = 2048;
243 $('#key_size').selectpicker('val', template.key_size.toString());
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100244
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100245 if (template.backupmx == 1){
246 $('#addDomain_relay_domain').prop('checked', true);
247 } else {
248 $('#addDomain_relay_domain').prop('checked', false);
249 }
250 if (template.relay_all_recipients == 1){
251 $('#addDomain_relay_all').prop('checked', true);
252 } else {
253 $('#addDomain_relay_all').prop('checked', false);
254 }
255 if (template.relay_unknown_only == 1){
256 $('#addDomain_relay_unknown_only').prop('checked', true);
257 } else {
258 $('#addDomain_relay_unknown_only').prop('checked', false);
259 }
260
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100261
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100262 // load tags
263 $('#addDomain_tags').val("");
264 $($('#addDomain_tags').parent().find(".tag-values")[0]).val("");
265 $('#addDomain_tags').parent().find(".tag-badge").remove();
266 for (var i = 0; i < template.tags.length; i++)
267 addTag($('#addDomain_tags'), template.tags[i]);
268 }
269 function setMailboxTemplateData(template){
270 $("#addInputQuota").val(template.quota / 1048576);
271
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200272 if (template.tagged_mail_handler === "subfolder"){
273 $('#tagged_mail_handler_subfolder').prop('checked', true);
274 $('#tagged_mail_handler_subject').prop('checked', false);
275 $('#tagged_mail_handler_none').prop('checked', false);
276 } else if(template.tagged_mail_handler === "subject"){
277 $('#tagged_mail_handler_subfolder').prop('checked', false);
278 $('#tagged_mail_handler_subject').prop('checked', true);
279 $('#tagged_mail_handler_none').prop('checked', false);
280 } else if(template.tagged_mail_handler === "none"){
281 $('#tagged_mail_handler_subfolder').prop('checked', false);
282 $('#tagged_mail_handler_subject').prop('checked', false);
283 $('#tagged_mail_handler_none').prop('checked', true);
284 } else {
285 $('#tagged_mail_handler_subfolder').prop('checked', false);
286 $('#tagged_mail_handler_subject').prop('checked', false);
287 $('#tagged_mail_handler_none').prop('checked', true);
288 }
289
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100290 if (template.quarantine_notification === "never"){
291 $('#quarantine_notification_never').prop('checked', true);
292 $('#quarantine_notification_hourly').prop('checked', false);
293 $('#quarantine_notification_daily').prop('checked', false);
294 $('#quarantine_notification_weekly').prop('checked', false);
295 } else if(template.quarantine_notification === "hourly"){
296 $('#quarantine_notification_never').prop('checked', false);
297 $('#quarantine_notification_hourly').prop('checked', true);
298 $('#quarantine_notification_daily').prop('checked', false);
299 $('#quarantine_notification_weekly').prop('checked', false);
300 } else if(template.quarantine_notification === "daily"){
301 $('#quarantine_notification_never').prop('checked', false);
302 $('#quarantine_notification_hourly').prop('checked', false);
303 $('#quarantine_notification_daily').prop('checked', true);
304 $('#quarantine_notification_weekly').prop('checked', false);
305 } else if(template.quarantine_notification === "weekly"){
306 $('#quarantine_notification_never').prop('checked', false);
307 $('#quarantine_notification_hourly').prop('checked', false);
308 $('#quarantine_notification_daily').prop('checked', false);
309 $('#quarantine_notification_weekly').prop('checked', true);
310 } else {
311 $('#quarantine_notification_never').prop('checked', false);
312 $('#quarantine_notification_hourly').prop('checked', false);
313 $('#quarantine_notification_daily').prop('checked', false);
314 $('#quarantine_notification_weekly').prop('checked', false);
315 }
316
317 if (template.quarantine_category === "reject"){
318 $('#quarantine_category_reject').prop('checked', true);
319 $('#quarantine_category_add_header').prop('checked', false);
320 $('#quarantine_category_all').prop('checked', false);
321 } else if(template.quarantine_category === "add_header"){
322 $('#quarantine_category_reject').prop('checked', false);
323 $('#quarantine_category_add_header').prop('checked', true);
324 $('#quarantine_category_all').prop('checked', false);
325 } else if(template.quarantine_category === "all"){
326 $('#quarantine_category_reject').prop('checked', false);
327 $('#quarantine_category_add_header').prop('checked', false);
328 $('#quarantine_category_all').prop('checked', true);
329 }
330
331 if (template.tls_enforce_in == 1){
332 $('#tls_enforce_in').prop('checked', true);
333 } else {
334 $('#tls_enforce_in').prop('checked', false);
335 }
336 if (template.tls_enforce_out == 1){
337 $('#tls_enforce_out').prop('checked', true);
338 } else {
339 $('#tls_enforce_out').prop('checked', false);
340 }
341
342 var protocol_access = [];
343 if (template.imap_access == 1){
344 protocol_access.push("imap");
345 }
346 if (template.pop3_access == 1){
347 protocol_access.push("pop3");
348 }
349 if (template.smtp_access == 1){
350 protocol_access.push("smtp");
351 }
352 if (template.sieve_access == 1){
353 protocol_access.push("sieve");
354 }
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200355 if (template.eas_access == 1){
356 protocol_access.push("eas");
357 }
358 if (template.dav_access == 1){
359 protocol_access.push("dav");
360 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100361 $('#protocol_access').selectpicker('val', protocol_access);
362
363 var acl = [];
364 if (template.acl_spam_alias == 1){
365 acl.push("spam_alias");
366 }
367 if (template.acl_tls_policy == 1){
368 acl.push("tls_policy");
369 }
370 if (template.acl_spam_score == 1){
371 acl.push("spam_score");
372 }
373 if (template.acl_spam_policy == 1){
374 acl.push("spam_policy");
375 }
376 if (template.acl_delimiter_action == 1){
377 acl.push("delimiter_action");
378 }
379 if (template.acl_syncjobs == 1){
380 acl.push("syncjobs");
381 }
382 if (template.acl_eas_reset == 1){
383 acl.push("eas_reset");
384 }
385 if (template.acl_sogo_profile_reset == 1){
386 acl.push("sogo_profile_reset");
387 }
388 if (template.acl_pushover == 1){
389 acl.push("pushover");
390 }
391 if (template.acl_quarantine == 1){
392 acl.push("quarantine");
393 }
394 if (template.acl_quarantine_attachments == 1){
395 acl.push("quarantine_attachments");
396 }
397 if (template.acl_quarantine_notification == 1){
398 acl.push("quarantine_notification");
399 }
400 if (template.acl_quarantine_category == 1){
401 acl.push("quarantine_category");
402 }
403 if (template.acl_app_passwds == 1){
404 acl.push("app_passwds");
405 }
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200406 if (template.acl_pw_reset == 1){
407 acl.push("pw_reset");
408 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100409 $('#user_acl').selectpicker('val', acl);
410
411 $('#rl_value').val(template.rl_value);
412 if (template.rl_frame){
413 $('#rl_frame').selectpicker('val', template.rl_frame);
414 }
415
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100416 if (template.active){
417 $('#mbox_active').selectpicker('val', template.active.toString());
418 } else {
419 $('#mbox_active').selectpicker('val', '');
420 }
421
422 if (template.force_pw_update == 1){
423 $('#force_pw_update').prop('checked', true);
424 } else {
425 $('#force_pw_update').prop('checked', false);
426 }
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200427 if (template.force_tfa == 1){
428 $('#force_tfa').prop('checked', true);
429 } else {
430 $('#force_tfa').prop('checked', false);
431 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100432 if (template.sogo_access == 1){
433 $('#sogo_access').prop('checked', true);
434 } else {
435 $('#sogo_access').prop('checked', false);
436 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100437
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100438 // load tags
439 $('#addMailbox_tags').val("");
440 $($('#addMailbox_tags').parent().find(".tag-values")[0]).val("");
441 $('#addMailbox_tags').parent().find(".tag-badge").remove();
442 for (var i = 0; i < template.tags.length; i++)
443 addTag($('#addMailbox_tags'), template.tags[i]);
444 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100445});
446jQuery(function($){
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100447 // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
448 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<B.length-1);return i.toFixed(1)+" "+B[e]}
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100449 function unix_time_format(i){return""==i?'<i class="bi bi-x"></i>':new Date(i?1e3*i:0).toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100450
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100451 $(".refresh_table").on('click', function(e) {
452 e.preventDefault();
453 var table_name = $(this).data('table');
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100454
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100455 if ($.fn.DataTable.isDataTable('#' + table_name))
456 $('#' + table_name).DataTable().ajax.reload();
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100457 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100458 function draw_domain_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100459 // just recalc width if instance already exists
460 if ($.fn.DataTable.isDataTable('#domain_table') ) {
461 $('#domain_table').DataTable().columns.adjust().responsive.recalc();
462 return;
463 }
464
465 var table = $('#domain_table').DataTable({
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100466 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100467 processing: true,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100468 serverSide: true,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100469 stateSave: true,
470 pageLength: pagination_size,
471 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
472 "tr" +
473 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100474 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100475 initComplete: function(){
476 hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
477 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100478 ajax: {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200479 type: "POST",
480 url: "/api/v1/search/domain",
481 contentType: "application/json",
482 processData: false,
483 data: function(d) {
484 return JSON.stringify(d);
485 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100486 dataSrc: function(json){
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100487 $.each(json.data, function(i, item) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100488 item.domain_name = escapeHtml(item.domain_name);
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100489 item.domain_h_name = escapeHtml(item.domain_h_name);
490 if (item.domain_name != item.domain_h_name){
491 item.domain_h_name = item.domain_h_name + '<small class="d-block">' + item.domain_name + '</small>';
492 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100493
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100494 item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
495 item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
496 item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
497 item.stats = item.msgs_total + "/" + item.bytes_total;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100498
499 if (!item.rl) item.rl = '∞';
500 else {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100501 item.rl = $.map(item.rl, function(e){
502 return e;
503 }).join('/1');
504 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100505
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100506 item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
507 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100508 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100509 item.action = '<div class="btn-group">';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100510 if (role == "admin") {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100511 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
512 '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
513 '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100514 }
515 else {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100516 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
517 '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-half btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100518 }
519
520 if (Array.isArray(item.tags)){
521 var tags = '';
522 for (var i = 0; i < item.tags.length; i++)
523 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
524 item.tags = tags;
525 } else {
526 item.tags = '';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100527 }
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200528
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100529 if (item.backupmx == 1) {
530 if (item.relay_unknown_only == 1) {
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100531 item.domain_h_name = '<div class="badge fs-7 bg-info">Relay Non-Local</div> ' + item.domain_h_name;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100532 } else if (item.relay_all_recipients == 1) {
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100533 item.domain_h_name = '<div class="badge fs-7 bg-info">Relay All</div> ' + item.domain_h_name;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100534 } else {
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100535 item.domain_h_name = '<div class="badge fs-7 bg-info">Relay</div> ' + item.domain_h_name;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100536 }
537 }
538 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100539
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100540 return json.data;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100541 }
542 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100543 columns: [
544 {
545 // placeholder, so checkbox will not block child row toggle
546 title: '',
547 data: null,
548 searchable: false,
549 orderable: false,
550 defaultContent: '',
551 responsivePriority: 1
552 },
553 {
554 title: '',
555 data: 'chkbox',
556 searchable: false,
557 orderable: false,
558 defaultContent: '',
559 responsivePriority: 2
560 },
561 {
562 title: lang.domain,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100563 data: 'domain_h_name',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100564 responsivePriority: 3,
565 defaultContent: ''
566 },
567 {
568 title: lang.aliases,
569 data: 'aliases',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100570 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100571 defaultContent: ''
572 },
573 {
574 title: lang.mailboxes,
575 data: 'mailboxes',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100576 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100577 responsivePriority: 4,
578 defaultContent: ''
579 },
580 {
581 title: lang.domain_quota,
582 data: 'quota',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100583 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100584 defaultContent: '',
585 render: function (data, type) {
586 data = data.split("/");
587 return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
588 }
589 },
590 {
591 title: lang.stats,
592 data: 'stats',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100593 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100594 defaultContent: '',
595 render: function (data, type) {
596 data = data.split("/");
597 return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
598 }
599 },
600 {
601 title: lang.mailbox_defquota,
602 data: 'def_quota_for_mbox',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100603 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100604 defaultContent: ''
605 },
606 {
607 title: lang.mailbox_quota,
608 data: 'max_quota_for_mbox',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100609 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100610 defaultContent: ''
611 },
612 {
613 title: 'RL',
614 data: 'rl',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100615 searchable: false,
616 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100617 defaultContent: ''
618 },
619 {
620 title: lang.backup_mx,
621 data: 'backupmx',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100622 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100623 defaultContent: '',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100624 render: function (data, type){
625 return 1==data ? '<i class="bi bi-check-lg"></i>' : 0==data && '<i class="bi bi-x-lg"></i>';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100626 }
627 },
628 {
629 title: lang.domain_admins,
630 data: 'domain_admins',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100631 searchable: false,
632 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100633 defaultContent: '',
634 className: 'none'
635 },
636 {
637 title: lang.created_on,
638 data: 'created',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100639 searchable: false,
640 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100641 defaultContent: '',
642 className: 'none'
643 },
644 {
645 title: lang.last_modified,
646 data: 'modified',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100647 searchable: false,
648 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100649 defaultContent: '',
650 className: 'none'
651 },
652 {
653 title: 'Tags',
654 data: 'tags',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100655 searchable: true,
656 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100657 defaultContent: '',
658 className: 'none'
659 },
660 {
661 title: lang.active,
662 data: 'active',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100663 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100664 defaultContent: '',
665 responsivePriority: 6,
666 render: function (data, type) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100667 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100668 }
669 },
670 {
671 title: lang.action,
672 data: 'action',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100673 searchable: false,
674 orderable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100675 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100676 responsivePriority: 5,
677 defaultContent: ''
678 },
679 ]
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100680 });
681
682 table.on('responsive-resize', function (e, datatable, columns){
683 hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
684 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100685 }
686 function draw_templates_domain_table() {
687 // just recalc width if instance already exists
688 if ($.fn.DataTable.isDataTable('#templates_domain_table') ) {
689 $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc();
690 return;
691 }
692
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100693 var table = $('#templates_domain_table').DataTable({
694 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100695 processing: true,
696 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100697 stateSave: true,
698 pageLength: pagination_size,
699 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
700 "tr" +
701 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100702 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100703 order: [[2, 'desc']],
704 initComplete: function(){
705 hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
706 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100707 ajax: {
708 type: "GET",
709 url: "/api/v1/get/domain/template/all",
710 dataSrc: function(json){
711 $.each(json, function (i, item) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100712 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100713
714 item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox);
715 item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox);
716 item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain);
717
718 item.template = escapeHtml(item.template);
719 if (item.attributes.rl_frame === "s"){
720 item.attributes.rl_frame = lang_rl.second;
721 } else if (item.attributes.rl_frame === "m"){
722 item.attributes.rl_frame = lang_rl.minute;
723 } else if (item.attributes.rl_frame === "h"){
724 item.attributes.rl_frame = lang_rl.hour;
725 } else if (item.attributes.rl_frame === "d"){
726 item.attributes.rl_frame = lang_rl.day;
727 }
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200728 item.attributes.rl_value = (!item.attributes.rl_value) ? "∞" : escapeHtml(item.attributes.rl_value);
729 item.attributes.ratelimit = item.attributes.rl_value + " " + item.attributes.rl_frame;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100730
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100731 if (item.template.toLowerCase() == "default"){
732 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100733 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100734 '</div>';
735 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100736 else {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100737 item.action = '<div class="btn-group">' +
738 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
739 '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/domain/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100740 '</div>';
741 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100742
743 if (Array.isArray(item.attributes.tags)){
744 var tags = '';
745 for (var i = 0; i < item.attributes.tags.length; i++)
746 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
747 item.attributes.tags = tags;
748 } else {
749 item.attributes.tags = '';
750 }
751 });
752
753 return json;
754 }
755 },
756 columns: [
757 {
758 // placeholder, so checkbox will not block child row toggle
759 title: '',
760 data: null,
761 searchable: false,
762 orderable: false,
763 defaultContent: '',
764 responsivePriority: 1
765 },
766 {
767 title: '',
768 data: 'chkbox',
769 searchable: false,
770 orderable: false,
771 defaultContent: '',
772 responsivePriority: 1
773 },
774 {
775 title: "ID",
776 data: 'id',
777 responsivePriority: 2,
778 defaultContent: ''
779 },
780 {
781 title: lang.template,
782 data: 'template',
783 responsivePriority: 3,
784 defaultContent: ''
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100785 },
786 {
787 title: lang.max_aliases,
788 data: 'attributes.max_num_aliases_for_domain',
789 defaultContent: '',
790 },
791 {
792 title: lang.max_mailboxes,
793 data: 'attributes.max_num_mboxes_for_domain',
794 defaultContent: '',
795 },
796 {
797 title: lang.mailbox_defquota,
798 data: 'attributes.def_quota_for_mbox',
799 defaultContent: '',
800 },
801 {
802 title: lang.max_quota,
803 data: 'attributes.max_quota_for_mbox',
804 defaultContent: '',
805 },
806 {
807 title: lang.domain_quota_total,
808 data: 'attributes.max_quota_for_domain',
809 defaultContent: '',
810 },
811 {
812 title: lang.gal,
813 data: 'attributes.gal',
814 defaultContent: '',
815 render: function (data, type) {
816 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
817 }
818 },
819 {
820 title: lang.backup_mx,
821 data: 'attributes.backupmx',
822 defaultContent: '',
823 render: function (data, type) {
824 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
825 }
826 },
827 {
828 title: lang.relay_all,
829 data: 'attributes.relay_all_recipients',
830 defaultContent: '',
831 render: function (data, type) {
832 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
833 }
834 },
835 {
836 title: lang.relay_unknown,
837 data: 'attributes.relay_unknown_only',
838 defaultContent: '',
839 render: function (data, type) {
840 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
841 }
842 },
843 {
844 title: lang.active,
845 data: 'attributes.active',
846 defaultContent: '',
847 responsivePriority: 4,
848 render: function (data, type) {
849 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
850 }
851 },
852 {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200853 title: lang_edit.ratelimit,
854 data: 'attributes.ratelimit',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100855 defaultContent: '',
856 class: 'none',
857 },
858 {
859 title: lang.dkim_domains_selector,
860 data: 'attributes.dkim_selector',
861 defaultContent: '',
862 class: 'none',
863 },
864 {
865 title: lang.dkim_key_length,
866 data: 'attributes.key_size',
867 defaultContent: '',
868 class: 'none',
869 },
870 {
871 title: 'Tags',
872 data: 'attributes.tags',
873 defaultContent: '',
874 className: 'none'
875 },
876 {
877 title: lang.action,
878 data: 'action',
879 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
880 responsivePriority: 6,
881 defaultContent: ''
882 },
883 ]
884 });
885
886 table.on('responsive-resize', function (e, datatable, columns){
887 hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
888 });
889 }
890 function draw_mailbox_table() {
891 // just recalc width if instance already exists
892 if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
893 $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
894 return;
895 }
896
897 var table = $('#mailbox_table').DataTable({
898 responsive: true,
899 processing: true,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100900 serverSide: true,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100901 stateSave: true,
902 pageLength: pagination_size,
903 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
904 "tr" +
905 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
906 language: lang_datatables,
907 initComplete: function(settings, json){
908 hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100909 },
910 ajax: {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200911 type: "POST",
912 url: "/api/v1/search/mailbox",
913 contentType: "application/json",
914 processData: false,
915 data: function(d) {
916 return JSON.stringify(d);
917 },
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100918 dataSrc: function(json){
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100919 $.each(json.data, function (i, item) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100920 item.quota = {
921 sortBy: item.quota_used,
922 value: item.quota
923 }
924 item.quota.value = (item.quota.value == 0 ? "∞" : humanFileSize(item.quota.value));
925 item.quota.value = humanFileSize(item.quota_used) + "/" + item.quota.value;
926
927 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200928 item.last_mail_login = (item.attributes.imap_access == 1 ? '<div class="text-start badge bg-info mb-2" style="min-width: 70px;">IMAP @ ' + unix_time_format(Number(item.last_imap_login)) + '</div><br>' : '') +
929 (item.attributes.pop3_access == 1 ? '<div class="text-start badge bg-info mb-2" style="min-width: 70px;">POP3 @ ' + unix_time_format(Number(item.last_pop3_login)) + '</div><br>' : '') +
930 (item.attributes.smtp_access == 1 ? '<div class="text-start badge bg-info mb-2" style="min-width: 70px;">SMTP @ ' + unix_time_format(Number(item.last_smtp_login)) + '</div><br>' : '') +
931 '<div class="text-start badge bg-info" style="min-width: 70px;">SSO @ ' + unix_time_format(Number(item.last_sso_login)) + '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100932 /*
933 if (!item.rl) {
934 item.rl = '∞';
935 } else {
936 item.rl = $.map(item.rl, function(e){
937 return e;
938 }).join('/1');
939 if (item.rl_scope === 'domain') {
940 item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
941 }
942 }
943 */
944 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
945 if (item.attributes.passwd_update != '0') {
946 var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
947 item.last_pw_change = last_pw_change.toLocaleDateString(undefined, {year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit"});
948 } else {
949 item.last_pw_change = '-';
950 }
951 item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
952 item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
953 item.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
954 item.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
955 item.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
956 item.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200957 item.eas_access = '<i class="text-' + (item.attributes.eas_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.eas_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
958 item.dav_access = '<i class="text-' + (item.attributes.dav_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.dav_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100959 if (item.attributes.quarantine_notification === 'never') {
960 item.quarantine_notification = lang.never;
961 } else if (item.attributes.quarantine_notification === 'hourly') {
962 item.quarantine_notification = lang.hourly;
963 } else if (item.attributes.quarantine_notification === 'daily') {
964 item.quarantine_notification = lang.daily;
965 } else if (item.attributes.quarantine_notification === 'weekly') {
966 item.quarantine_notification = lang.weekly;
967 }
968 if (item.attributes.quarantine_category === 'reject') {
969 item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
970 } else if (item.attributes.quarantine_category === 'add_header') {
971 item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
972 } else if (item.attributes.quarantine_category === 'all') {
973 item.quarantine_category = lang.q_all;
974 }
975 if (acl_data.login_as === 1) {
976
977 item.action = '<div class="btn-group">' +
978 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
979 '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
980 '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-success"><i class="bi bi-person-fill"></i> Login</a>';
981 if (ALLOW_ADMIN_EMAIL_LOGIN) {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200982 item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-primary"><i class="bi bi-envelope-fill"></i> SOGo</a>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100983 }
984 item.action += '</div>';
985 }
986 else {
987 item.action = '<div class="btn-group">' +
988 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
989 '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
990 '</div>';
991 }
992 item.in_use = {
993 sortBy: item.percent_in_use,
994 value: '<div class="progress">' +
995 '<div class="progress-bar-mailbox progress-bar progress-bar-' + item.percent_class + '" role="progressbar" aria-valuenow="' + item.percent_in_use + '" aria-valuemin="0" aria-valuemax="100" ' +
996 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>'
997 };
998 item.username = escapeHtml(item.username);
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +0200999 item.name = escapeHtml(item.name);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001000
1001 if (Array.isArray(item.tags)){
1002 var tags = '';
1003 for (var i = 0; i < item.tags.length; i++)
1004 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
1005 item.tags = tags;
1006 } else {
1007 item.tags = '';
1008 }
1009 });
1010
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001011 return json.data;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001012 }
1013 },
1014 columns: [
1015 {
1016 // placeholder, so checkbox will not block child row toggle
1017 title: '',
1018 data: null,
1019 searchable: false,
1020 orderable: false,
1021 defaultContent: '',
1022 responsivePriority: 1
1023 },
1024 {
1025 title: '',
1026 data: 'chkbox',
1027 searchable: false,
1028 orderable: false,
1029 defaultContent: '',
1030 responsivePriority: 2
1031 },
1032 {
1033 title: lang.username,
1034 data: 'username',
1035 responsivePriority: 3,
1036 defaultContent: ''
1037 },
1038 {
1039 title: lang.domain_quota,
1040 data: 'quota.value',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001041 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001042 responsivePriority: 8,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001043 defaultContent: ''
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001044 },
1045 {
1046 title: lang.last_mail_login,
1047 data: 'last_mail_login',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001048 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001049 defaultContent: '',
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001050 responsivePriority: 7
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001051 },
1052 {
1053 title: lang.last_pw_change,
1054 data: 'last_pw_change',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001055 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001056 defaultContent: ''
1057 },
1058 {
1059 title: lang.in_use,
1060 data: 'in_use.value',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001061 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001062 defaultContent: '',
1063 responsivePriority: 9,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001064 className: 'dt-data-w100'
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001065 },
1066 {
1067 title: lang.fname,
1068 data: 'name',
1069 defaultContent: '',
1070 className: 'none'
1071 },
1072 {
1073 title: lang.domain,
1074 data: 'domain',
1075 defaultContent: '',
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001076 className: 'none',
1077 },
1078 {
1079 title: lang.iam,
1080 data: 'authsource',
1081 defaultContent: '',
1082 className: 'none',
1083 render: function (data, type) {
1084 return '<span class="badge bg-primary">' + data + '<i class="ms-2 bi bi-person-circle"></i></i></span>';
1085 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001086 },
1087 {
1088 title: lang.tls_enforce_in,
1089 data: 'tls_enforce_in',
1090 defaultContent: '',
1091 className: 'none'
1092 },
1093 {
1094 title: lang.tls_enforce_out,
1095 data: 'tls_enforce_out',
1096 defaultContent: '',
1097 className: 'none'
1098 },
1099 {
1100 title: 'SMTP',
1101 data: 'smtp_access',
1102 defaultContent: '',
1103 className: 'none'
1104 },
1105 {
1106 title: 'IMAP',
1107 data: 'imap_access',
1108 defaultContent: '',
1109 className: 'none'
1110 },
1111 {
1112 title: 'POP3',
1113 data: 'pop3_access',
1114 defaultContent: '',
1115 className: 'none'
1116 },
1117 {
1118 title: 'SIEVE',
1119 data: 'sieve_access',
1120 defaultContent: '',
1121 className: 'none'
1122 },
1123 {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001124 title: 'EAS',
1125 data: 'eas_access',
1126 defaultContent: '',
1127 className: 'none'
1128 },
1129 {
1130 title: 'DAV',
1131 data: 'dav_access',
1132 defaultContent: '',
1133 className: 'none'
1134 },
1135 {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001136 title: lang.quarantine_notification,
1137 data: 'quarantine_notification',
1138 defaultContent: '',
1139 className: 'none'
1140 },
1141 {
1142 title: lang.quarantine_category,
1143 data: 'quarantine_category',
1144 defaultContent: '',
1145 className: 'none'
1146 },
1147 {
1148 title: lang.msg_num,
1149 data: 'messages',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001150 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001151 defaultContent: '',
1152 responsivePriority: 5
1153 },
1154 {
1155 title: lang.created_on,
1156 data: 'created',
1157 defaultContent: '',
1158 className: 'none'
1159 },
1160 {
1161 title: lang.last_modified,
1162 data: 'modified',
1163 defaultContent: '',
1164 className: 'none'
1165 },
1166 {
1167 title: 'Tags',
1168 data: 'tags',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001169 searchable: true,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001170 defaultContent: '',
1171 className: 'none'
1172 },
1173 {
1174 title: lang.active,
1175 data: 'active',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001176 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001177 defaultContent: '',
1178 responsivePriority: 4,
1179 render: function (data, type) {
1180 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
1181 }
1182 },
1183 {
1184 title: lang.action,
1185 data: 'action',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001186 searchable: false,
1187 orderable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001188 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1189 responsivePriority: 6,
1190 defaultContent: ''
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001191 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001192 ]
1193 });
1194
1195 table.on('responsive-resize', function (e, datatable, columns){
1196 hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
1197 });
1198 }
1199 function draw_templates_mbox_table() {
1200 // just recalc width if instance already exists
1201 if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) {
1202 $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc();
1203 return;
1204 }
1205
1206 var table = $('#templates_mbox_table').DataTable({
1207 responsive: true,
1208 processing: true,
1209 serverSide: false,
1210 stateSave: true,
1211 pageLength: pagination_size,
1212 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1213 "tr" +
1214 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
1215 language: lang_datatables,
1216 order: [[2, 'desc']],
1217 initComplete: function(){
1218 hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
1219 },
1220 ajax: {
1221 type: "GET",
1222 url: "/api/v1/get/mailbox/template/all",
1223 dataSrc: function(json){
1224 $.each(json, function (i, item) {
1225 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
1226
1227 item.template = escapeHtml(item.template);
1228 if (item.attributes.rl_frame === "s"){
1229 item.attributes.rl_frame = lang_rl.second;
1230 } else if (item.attributes.rl_frame === "m"){
1231 item.attributes.rl_frame = lang_rl.minute;
1232 } else if (item.attributes.rl_frame === "h"){
1233 item.attributes.rl_frame = lang_rl.hour;
1234 } else if (item.attributes.rl_frame === "d"){
1235 item.attributes.rl_frame = lang_rl.day;
1236 }
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001237 item.attributes.rl_value = (!item.attributes.rl_value) ? "∞" : escapeHtml(item.attributes.rl_value);
1238 item.attributes.ratelimit = item.attributes.rl_value + " " + item.attributes.rl_frame;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001239
1240 item.attributes.quota = humanFileSize(item.attributes.quota);
1241
1242 item.attributes.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_in == 1 ? '1' : '0') + '</span></i>';
1243 item.attributes.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_out == 1 ? '1' : '0') + '</span></i>';
1244 item.attributes.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.pop3_access == 1 ? '1' : '0') + '</span></i>';
1245 item.attributes.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.imap_access == 1 ? '1' : '0') + '</span></i>';
1246 item.attributes.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.smtp_access == 1 ? '1' : '0') + '</span></i>';
1247 item.attributes.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.sieve_access == 1 ? '1' : '0') + '</span></i>';
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001248 item.attributes.eas_access = '<i class="text-' + (item.attributes.eas_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.eas_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.eas_access == 1 ? '1' : '0') + '</span></i>';
1249 item.attributes.dav_access = '<i class="text-' + (item.attributes.dav_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.dav_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.dav_access == 1 ? '1' : '0') + '</span></i>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001250 item.attributes.sogo_access = '<i class="text-' + (item.attributes.sogo_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sogo_access == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.sogo_access == 1 ? '1' : '0') + '</span></i>';
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001251 item.attributes.force_tfa = '<i class="text-' + (item.attributes.force_tfa == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.force_tfa == 1 ? 'check-lg' : 'x-lg') + '"><span class="sorting-value">' + (item.attributes.force_tfa == 1 ? '1' : '0') + '</span></i>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001252 if (item.attributes.quarantine_notification === 'never') {
1253 item.attributes.quarantine_notification = lang.never;
1254 } else if (item.attributes.quarantine_notification === 'hourly') {
1255 item.attributes.quarantine_notification = lang.hourly;
1256 } else if (item.attributes.quarantine_notification === 'daily') {
1257 item.attributes.quarantine_notification = lang.daily;
1258 } else if (item.attributes.quarantine_notification === 'weekly') {
1259 item.attributes.quarantine_notification = lang.weekly;
1260 }
1261 if (item.attributes.quarantine_category === 'reject') {
1262 item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
1263 } else if (item.attributes.quarantine_category === 'add_header') {
1264 item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
1265 } else if (item.attributes.quarantine_category === 'all') {
1266 item.attributes.quarantine_category = lang.q_all;
1267 }
1268
1269 if (item.template.toLowerCase() == "default"){
1270 item.action = '<div class="btn-group">' +
1271 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1272 '</div>';
1273 }
1274 else {
1275 item.action = '<div class="btn-group">' +
1276 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1277 '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/mailbox/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
1278 '</div>';
1279 }
1280
1281 if (Array.isArray(item.attributes.tags)){
1282 var tags = '';
1283 for (var i = 0; i < item.attributes.tags.length; i++)
1284 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
1285 item.attributes.tags = tags;
1286 } else {
1287 item.attributes.tags = '';
1288 }
1289 });
1290
1291 return json;
1292 }
1293 },
1294 columns: [
1295 {
1296 // placeholder, so checkbox will not block child row toggle
1297 title: '',
1298 data: null,
1299 searchable: false,
1300 orderable: false,
1301 defaultContent: '',
1302 responsivePriority: 1
1303 },
1304 {
1305 title: '',
1306 data: 'chkbox',
1307 searchable: false,
1308 orderable: false,
1309 defaultContent: '',
1310 responsivePriority: 1
1311 },
1312 {
1313 title: "ID",
1314 data: 'id',
1315 responsivePriority: 2,
1316 defaultContent: ''
1317 },
1318 {
1319 title: lang.template,
1320 data: 'template',
1321 responsivePriority: 3,
1322 defaultContent: ''
1323 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001324 {
1325 title: lang.domain_quota,
1326 data: 'attributes.quota',
1327 defaultContent: '',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001328 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001329 {
1330 title: lang.tls_enforce_in,
1331 data: 'attributes.tls_enforce_in',
1332 defaultContent: ''
1333 },
1334 {
1335 title: lang.tls_enforce_out,
1336 data: 'attributes.tls_enforce_out',
1337 defaultContent: ''
1338 },
1339 {
1340 title: 'SMTP',
1341 data: 'attributes.smtp_access',
1342 defaultContent: '',
1343 },
1344 {
1345 title: 'IMAP',
1346 data: 'attributes.imap_access',
1347 defaultContent: '',
1348 },
1349 {
1350 title: 'POP3',
1351 data: 'attributes.pop3_access',
1352 defaultContent: '',
1353 },
1354 {
1355 title: 'SIEVE',
1356 data: 'attributes.sieve_access',
1357 defaultContent: '',
1358 },
1359 {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001360 title: 'EAS',
1361 data: 'attributes.eas_access',
1362 defaultContent: '',
1363 },
1364 {
1365 title: 'DAV',
1366 data: 'attributes.dav_access',
1367 defaultContent: '',
1368 },
1369 {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001370 title: 'SOGO',
1371 data: 'attributes.sogo_access',
1372 defaultContent: '',
1373 },
1374 {
1375 title: lang.quarantine_notification,
1376 data: 'attributes.quarantine_notification',
1377 defaultContent: '',
1378 className: 'none'
1379 },
1380 {
1381 title: lang.quarantine_category,
1382 data: 'attributes.quarantine_category',
1383 defaultContent: '',
1384 className: 'none'
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001385 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001386 {
1387 title: lang.force_pw_update,
1388 data: 'attributes.force_pw_update',
1389 defaultContent: '',
1390 class: 'none',
1391 render: function (data, type) {
1392 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
1393 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001394 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001395 {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001396 title: lang.force_tfa,
1397 data: 'attributes.force_tfa',
1398 defaultContent: ''
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001399 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001400 {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02001401 title: lang_edit.ratelimit,
1402 data: 'attributes.ratelimit',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001403 defaultContent: '',
1404 class: 'none',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001405 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001406 {
1407 title: 'Tags',
1408 data: 'attributes.tags',
1409 defaultContent: '',
1410 className: 'none'
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001411 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001412 {
1413 title: lang.active,
1414 data: 'attributes.active',
1415 defaultContent: '',
1416 responsivePriority: 4,
1417 render: function (data, type) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001418 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001419 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001420 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001421 {
1422 title: lang.action,
1423 data: 'action',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001424 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001425 responsivePriority: 6,
1426 defaultContent: ''
1427 },
1428 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001429 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001430
1431 table.on('responsive-resize', function (e, datatable, columns){
1432 hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
1433 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001434 }
1435 function draw_resource_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001436 // just recalc width if instance already exists
1437 if ($.fn.DataTable.isDataTable('#resource_table') ) {
1438 $('#resource_table').DataTable().columns.adjust().responsive.recalc();
1439 return;
1440 }
1441
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001442 var table = $('#resource_table').DataTable({
1443 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001444 processing: true,
1445 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001446 stateSave: true,
1447 pageLength: pagination_size,
1448 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1449 "tr" +
1450 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001451 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001452 initComplete: function(settings, json){
1453 hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
1454 filterByDomain(json, 5, table);
1455 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001456 ajax: {
1457 type: "GET",
1458 url: "/api/v1/get/resource/all",
1459 dataSrc: function(json){
1460 $.each(json, function (i, item) {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001461 if (item.multiple_bookings == '0') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001462 item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001463 } else if (item.multiple_bookings == '-1') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001464 item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001465 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001466 item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001467 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001468 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001469 '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1470 '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001471 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001472 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001473 item.name = escapeHtml(item.name);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001474 item.description = escapeHtml(item.description);
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001475 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001476
1477 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001478 }
1479 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001480 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001481 {
1482 // placeholder, so checkbox will not block child row toggle
1483 title: '',
1484 data: null,
1485 searchable: false,
1486 orderable: false,
1487 defaultContent: '',
1488 responsivePriority: 1
1489 },
1490 {
1491 title: '',
1492 data: 'chkbox',
1493 searchable: false,
1494 orderable: false,
1495 defaultContent: '',
1496 responsivePriority: 2
1497 },
1498 {
1499 title: lang.description,
1500 data: 'description',
1501 responsivePriority: 3,
1502 defaultContent: ''
1503 },
1504 {
1505 title: lang.alias,
1506 data: 'name',
1507 defaultContent: ''
1508 },
1509 {
1510 title: lang.kind,
1511 data: 'kind',
1512 defaultContent: ''
1513 },
1514 {
1515 title: lang.domain,
1516 data: 'domain',
1517 responsivePriority: 4,
1518 defaultContent: ''
1519 },
1520 {
1521 title: lang.multiple_bookings,
1522 data: 'multiple_bookings',
1523 defaultContent: ''
1524 },
1525 {
1526 title: lang.active,
1527 data: 'active',
1528 defaultContent: '',
1529 render: function (data, type) {
1530 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
1531 }
1532 },
1533 {
1534 title: lang.action,
1535 data: 'action',
1536 responsivePriority: 5,
1537 defaultContent: '',
1538 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right'
1539 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001540 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001541 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001542
1543 table.on('responsive-resize', function (e, datatable, columns){
1544 hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
1545 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001546 }
1547 function draw_bcc_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001548 $.get("/api/v1/get/bcc-destination-options", function(data){
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001549 var optgroup = "";
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001550 // Domains
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001551 if (data.domains && data.domains.length > 0) {
1552 optgroup = "<optgroup label='" + lang.domains + "'>";
1553 $.each(data.domains, function(index, domain){
1554 optgroup += "<option value='" + domain + "'>" + domain + "</option>";
1555 });
1556 optgroup += "</optgroup>";
1557 $('#bcc-local-dest').append(optgroup);
1558 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001559 // Alias domains
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001560 if (data.alias_domains && data.alias_domains.length > 0) {
1561 optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
1562 $.each(data.alias_domains, function(index, alias_domain){
1563 optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>";
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001564 });
1565 optgroup += "</optgroup>"
1566 $('#bcc-local-dest').append(optgroup);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001567 }
1568 // Mailboxes and aliases
1569 if (data.mailboxes && Object.keys(data.mailboxes).length > 0) {
1570 $.each(data.mailboxes, function(mailbox, aliases){
1571 optgroup = "<optgroup label='" + mailbox + "'>";
1572 $.each(aliases, function(index, alias){
1573 optgroup += "<option value='" + alias + "'>" + alias + "</option>";
1574 });
1575 optgroup += "</optgroup>";
1576 $('#bcc-local-dest').append(optgroup);
1577 });
1578 }
1579 // Recreate picker
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001580 $('#bcc-local-dest').selectpicker('refresh');
1581 });
1582
1583 // just recalc width if instance already exists
1584 if ($.fn.DataTable.isDataTable('#bcc_table') ) {
1585 $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
1586 return;
1587 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001588
1589 var table = $('#bcc_table').DataTable({
1590 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001591 processing: true,
1592 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001593 stateSave: true,
1594 pageLength: pagination_size,
1595 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1596 "tr" +
1597 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001598 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001599 order: [[2, 'desc']],
1600 initComplete: function(settings, json){
1601 hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
1602 filterByDomain(json, 6, table);
1603 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001604 ajax: {
1605 type: "GET",
1606 url: "/api/v1/get/bcc/all",
1607 dataSrc: function(json){
1608 $.each(json, function (i, item) {
1609 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001610 '<a href="/edit/bcc/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1611 '<a href="#" data-action="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001612 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001613 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="bcc" name="multi_select" value="' + item.id + '" />';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001614 item.local_dest = escapeHtml(item.local_dest);
1615 item.bcc_dest = escapeHtml(item.bcc_dest);
1616 if (item.type == 'sender') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001617 item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001618 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001619 item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001620 }
1621 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001622
1623 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001624 }
1625 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001626 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001627 {
1628 // placeholder, so checkbox will not block child row toggle
1629 title: '',
1630 data: null,
1631 searchable: false,
1632 orderable: false,
1633 defaultContent: '',
1634 responsivePriority: 1
1635 },
1636 {
1637 title: '',
1638 data: 'chkbox',
1639 searchable: false,
1640 orderable: false,
1641 defaultContent: '',
1642 responsivePriority: 2
1643 },
1644 {
1645 title: 'ID',
1646 data: 'id',
1647 responsivePriority: 3,
1648 defaultContent: ''
1649 },
1650 {
1651 title: lang.bcc_type,
1652 data: 'type',
1653 defaultContent: ''
1654 },
1655 {
1656 title: lang.bcc_local_dest,
1657 data: 'local_dest',
1658 defaultContent: ''
1659 },
1660 {
1661 title: lang.bcc_destinations,
1662 data: 'bcc_dest',
1663 defaultContent: ''
1664 },
1665 {
1666 title: lang.domain,
1667 data: 'domain',
1668 responsivePriority: 4,
1669 defaultContent: ''
1670 },
1671 {
1672 title: lang.active,
1673 data: 'active',
1674 defaultContent: '',
1675 render: function (data, type) {
1676 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
1677 }
1678 },
1679 {
1680 title: lang.action,
1681 data: 'action',
1682 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1683 responsivePriority: 5,
1684 defaultContent: ''
1685 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001686 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001687 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001688
1689 table.on('responsive-resize', function (e, datatable, columns){
1690 hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
1691 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001692 }
1693 function draw_recipient_map_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001694 // just recalc width if instance already exists
1695 if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
1696 $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
1697 return;
1698 }
1699
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001700 var table = $('#recipient_map_table').DataTable({
1701 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001702 processing: true,
1703 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001704 stateSave: true,
1705 pageLength: pagination_size,
1706 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1707 "tr" +
1708 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001709 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001710 order: [[2, 'desc']],
1711 initComplete: function(){
1712 hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
1713 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001714 ajax: {
1715 type: "GET",
1716 url: "/api/v1/get/recipient_map/all",
1717 dataSrc: function(json){
1718 if (role !== "admin") return null;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001719
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001720 $.each(json, function (i, item) {
1721 item.recipient_map_old = escapeHtml(item.recipient_map_old);
1722 item.recipient_map_new = escapeHtml(item.recipient_map_new);
1723 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001724 '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1725 '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001726 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001727 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001728 });
1729
1730 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001731 }
1732 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001733 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001734 {
1735 // placeholder, so checkbox will not block child row toggle
1736 title: '',
1737 data: null,
1738 searchable: false,
1739 orderable: false,
1740 defaultContent: '',
1741 responsivePriority: 1
1742 },
1743 {
1744 title: '',
1745 data: 'chkbox',
1746 searchable: false,
1747 orderable: false,
1748 defaultContent: '',
1749 responsivePriority: 2
1750 },
1751 {
1752 title: 'ID',
1753 data: 'id',
1754 responsivePriority: 3,
1755 defaultContent: ''
1756 },
1757 {
1758 title: lang.recipient_map_old,
1759 data: 'recipient_map_old',
1760 defaultContent: ''
1761 },
1762 {
1763 title: lang.recipient_map_new,
1764 data: 'recipient_map_new',
1765 defaultContent: '',
1766 responsivePriority: 4
1767 },
1768 {
1769 title: lang.active,
1770 data: 'active',
1771 defaultContent: '',
1772 render: function (data, type) {
1773 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
1774 }
1775 },
1776 {
1777 title: lang.action,
1778 data: 'action',
1779 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1780 responsivePriority: 5,
1781 defaultContent: ''
1782 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001783 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001784 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001785
1786 table.on('responsive-resize', function (e, datatable, columns){
1787 hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
1788 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001789 }
1790 function draw_tls_policy_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001791 // just recalc width if instance already exists
1792 if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
1793 $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
1794 return;
1795 }
1796
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001797 var table = $('#tls_policy_table').DataTable({
1798 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001799 processing: true,
1800 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001801 stateSave: true,
1802 pageLength: pagination_size,
1803 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1804 "tr" +
1805 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001806 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001807 order: [[2, 'desc']],
1808 initComplete: function(){
1809 hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
1810 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001811 ajax: {
1812 type: "GET",
1813 url: "/api/v1/get/tls-policy-map/all",
1814 dataSrc: function(json){
1815 if (role !== "admin") return null;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001816
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001817 $.each(json, function (i, item) {
1818 item.dest = escapeHtml(item.dest);
1819 item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
1820 if (item.parameters == '') {
1821 item.parameters = '<code>-</code>';
1822 } else {
1823 item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
1824 }
1825 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001826 '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1827 '<a href="#" data-action="delete_selected" data-id="single-tls-policy-map" data-api-url="delete/tls-policy-map" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001828 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001829 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001830 });
1831
1832 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001833 }
1834 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001835 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001836 {
1837 // placeholder, so checkbox will not block child row toggle
1838 title: '',
1839 data: null,
1840 searchable: false,
1841 orderable: false,
1842 defaultContent: '',
1843 responsivePriority: 1
1844 },
1845 {
1846 title: '',
1847 data: 'chkbox',
1848 searchable: false,
1849 orderable: false,
1850 defaultContent: '',
1851 responsivePriority: 2
1852 },
1853 {
1854 title: 'ID',
1855 data: 'id',
1856 responsivePriority: 3,
1857 defaultContent: ''
1858 },
1859 {
1860 title: lang.tls_map_dest,
1861 data: 'dest',
1862 defaultContent: '',
1863 responsivePriority: 4
1864 },
1865 {
1866 title: lang.tls_map_policy,
1867 data: 'policy',
1868 defaultContent: ''
1869 },
1870 {
1871 title: lang.tls_map_parameters,
1872 data: 'parameters',
1873 defaultContent: ''
1874 },
1875 {
1876 title: lang.active,
1877 data: 'active',
1878 defaultContent: '',
1879 render: function (data, type) {
1880 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
1881 }
1882 },
1883 {
1884 title: lang.action,
1885 data: 'action',
1886 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1887 responsivePriority: 5,
1888 defaultContent: ''
1889 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001890 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001891 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001892
1893 table.on('responsive-resize', function (e, datatable, columns){
1894 hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
1895 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001896 }
1897 function draw_alias_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001898 // just recalc width if instance already exists
1899 if ($.fn.DataTable.isDataTable('#alias_table') ) {
1900 $('#alias_table').DataTable().columns.adjust().responsive.recalc();
1901 return;
1902 }
1903
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001904 var table = $('#alias_table').DataTable({
1905 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001906 processing: true,
1907 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001908 stateSave: true,
1909 pageLength: pagination_size,
1910 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1911 "tr" +
1912 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001913 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001914 order: [[2, 'desc']],
1915 initComplete: function(settings, json){
1916 hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
1917 filterByDomain(json, 5, table);
1918 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001919 ajax: {
1920 type: "GET",
1921 url: "/api/v1/get/alias/all",
1922 dataSrc: function(json){
1923 $.each(json, function (i, item) {
1924 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001925 '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1926 '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001927 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001928 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001929 item.goto = escapeHtml(item.goto.replace(/,/g, " "));
1930 if (item.public_comment !== null) {
1931 item.public_comment = escapeHtml(item.public_comment);
1932 }
1933 else {
1934 item.public_comment = '-';
1935 }
1936 if (item.private_comment !== null) {
1937 item.private_comment = escapeHtml(item.private_comment);
1938 }
1939 else {
1940 item.private_comment = '-';
1941 }
1942 if (item.is_catch_all == 1) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001943 item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001944 }
1945 else {
1946 item.address = escapeHtml(item.address);
1947 }
1948 if (item.goto == "null@localhost") {
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +02001949 item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001950 }
1951 else if (item.goto == "spam@localhost") {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001952 item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001953 }
1954 else if (item.goto == "ham@localhost") {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001955 item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001956 }
1957 if (item.in_primary_domain !== "") {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001958 item.domain = '<i data-domainname="' + item.domain + '" class="bi bi-info-circle-fill alias-domain-info text-info" data-bs-toggle="tooltip" title="' + lang.target_domain + ': ' + item.in_primary_domain + '"></i> ' + item.domain;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001959 }
1960 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001961
1962 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001963 }
1964 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001965 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001966 {
1967 // placeholder, so checkbox will not block child row toggle
1968 title: '',
1969 data: null,
1970 searchable: false,
1971 orderable: false,
1972 defaultContent: '',
1973 responsivePriority: 1
1974 },
1975 {
1976 title: '',
1977 data: 'chkbox',
1978 searchable: false,
1979 orderable: false,
1980 defaultContent: '',
1981 responsivePriority: 2
1982 },
1983 {
1984 title: 'ID',
1985 data: 'id',
1986 responsivePriority: 3,
1987 defaultContent: ''
1988 },
1989 {
1990 title: lang.alias,
1991 data: 'address',
1992 responsivePriority: 4,
1993 defaultContent: ''
1994 },
1995 {
1996 title: lang.target_address,
1997 data: 'goto',
1998 defaultContent: ''
1999 },
2000 {
2001 title: lang.domain,
2002 data: 'domain',
2003 defaultContent: '',
2004 responsivePriority: 5,
2005 },
2006 {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002007 title: lang.sogo_visible,
2008 data: 'sogo_visible',
2009 defaultContent: '',
2010 render: function(data, type){
2011 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
2012 }
2013 },
2014 {
2015 title: lang.public_comment,
2016 data: 'public_comment',
2017 defaultContent: ''
2018 },
2019 {
2020 title: lang.private_comment,
2021 data: 'private_comment',
2022 defaultContent: ''
2023 },
2024 {
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02002025 title: lang.internal,
2026 data: 'internal',
2027 defaultContent: '',
2028 responsivePriority: 6,
2029 render: function (data, type) {
2030 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
2031 }
2032 },
2033 {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002034 title: lang.active,
2035 data: 'active',
2036 defaultContent: '',
2037 responsivePriority: 6,
2038 render: function (data, type) {
2039 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
2040 }
2041 },
2042 {
2043 title: lang.action,
2044 data: 'action',
2045 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
2046 responsivePriority: 5,
2047 defaultContent: ''
2048 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002049 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002050 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002051
2052 table.on('responsive-resize', function (e, datatable, columns){
2053 hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
2054 });
2055
2056 table.on( 'draw', function (){
2057 $('#alias_table [data-bs-toggle="tooltip"]').tooltip();
2058 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002059 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002060 function draw_aliasdomain_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002061 // just recalc width if instance already exists
2062 if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
2063 $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
2064 return;
2065 }
2066
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002067 var table = $('#aliasdomain_table').DataTable({
2068 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002069 processing: true,
2070 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002071 stateSave: true,
2072 pageLength: pagination_size,
2073 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
2074 "tr" +
2075 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002076 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002077 initComplete: function(){
2078 hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
2079 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002080 ajax: {
2081 type: "GET",
2082 url: "/api/v1/get/alias-domain/all",
2083 dataSrc: function(json){
2084 $.each(json, function (i, item) {
2085 item.alias_domain = escapeHtml(item.alias_domain);
2086
2087 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002088 '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-lg btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
2089 '<a href="#" data-action="delete_selected" data-id="single-alias-domain" data-api-url="delete/alias-domain" data-item="' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-lg btn-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
2090 '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-third btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><i class="bi bi-globe2"></i> DNS</a></div>' +
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002091 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002092 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002093 if(item.parent_is_backupmx == '1') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002094 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="badge fs-6 bg-warning">' + lang.alias_domain_backupmx + '</div></span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002095 } else {
2096 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
2097 }
2098 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002099
2100 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002101 }
2102 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002103 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002104 {
2105 // placeholder, so checkbox will not block child row toggle
2106 title: '',
2107 data: null,
2108 searchable: false,
2109 orderable: false,
2110 defaultContent: '',
2111 responsivePriority: 1
2112 },
2113 {
2114 title: '',
2115 data: 'chkbox',
2116 searchable: false,
2117 orderable: false,
2118 defaultContent: '',
2119 responsivePriority: 2
2120 },
2121 {
2122 title: lang.alias,
2123 data: 'alias_domain',
2124 responsivePriority: 3,
2125 defaultContent: ''
2126 },
2127 {
2128 title: lang.target_domain,
2129 data: 'target_domain',
2130 responsivePriority: 4,
2131 defaultContent: ''
2132 },
2133 {
2134 title: lang.active,
2135 data: 'active',
2136 defaultContent: '',
2137 render: function (data, type) {
2138 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
2139 }
2140 },
2141 {
2142 title: lang.action,
2143 data: 'action',
2144 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
2145 responsivePriority: 5,
2146 defaultContent: ''
2147 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002148 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002149 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002150
2151 table.on('responsive-resize', function (e, datatable, columns){
2152 hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
2153 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002154 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002155 function draw_sync_job_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002156 // just recalc width if instance already exists
2157 if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
2158 $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
2159 return;
2160 }
2161
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002162 var table = $('#sync_job_table').DataTable({
2163 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002164 processing: true,
2165 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002166 stateSave: true,
2167 pageLength: pagination_size,
2168 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
2169 "tr" +
2170 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002171 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002172 order: [[2, 'desc']],
2173 initComplete: function(){
2174 hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
2175 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002176 ajax: {
2177 type: "GET",
2178 url: "/api/v1/get/syncjobs/all/no_log",
2179 dataSrc: function(json){
2180 $.each(json, function (i, item) {
2181 item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002182 item.user2 = escapeHtml(item.user2);
2183 if (!item.exclude > 0) {
2184 item.exclude = '-';
2185 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002186 item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002187 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002188 item.server_w_port = escapeHtml(item.user1) + '@' + escapeHtml(item.host1) + ':' + escapeHtml(item.port1);
2189 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002190 '<a href="/edit/syncjob/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
2191 '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002192 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002193 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002194 if (item.is_running == 1) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002195 item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002196 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002197 item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002198 }
2199 if (!item.last_run > 0) {
2200 item.last_run = lang.waiting;
2201 }
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01002202 if (item.success == null) {
2203 item.success = '-';
2204 item.exit_status = '';
2205 } else {
2206 item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
2207 }
2208 if (lang['syncjob_'+item.exit_status]) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002209 item.exit_status = lang['syncjob_'+item.exit_status];
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01002210 } else if (item.success != '-') {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002211 item.exit_status = lang.syncjob_check_log;
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01002212 }
2213 item.exit_status = item.success + ' ' + item.exit_status;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002214 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002215
2216 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002217 }
2218 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002219 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002220 {
2221 // placeholder, so checkbox will not block child row toggle
2222 title: '',
2223 data: null,
2224 searchable: false,
2225 orderable: false,
2226 defaultContent: '',
2227 responsivePriority: 1
2228 },
2229 {
2230 title: '',
2231 data: 'chkbox',
2232 searchable: false,
2233 orderable: false,
2234 defaultContent: '',
2235 responsivePriority: 2
2236 },
2237 {
2238 title: 'ID',
2239 data: 'id',
2240 responsivePriority: 3,
2241 defaultContent: ''
2242 },
2243 {
2244 title: lang.owner,
2245 data: 'user2',
2246 responsivePriority: 4,
2247 defaultContent: ''
2248 },
2249 {
2250 title: 'Server',
2251 data: 'server_w_port',
2252 defaultContent: ''
2253 },
2254 {
2255 title: lang.last_run,
2256 data: 'last_run',
2257 defaultContent: ''
2258 },
2259 {
2260 title: lang.syncjob_last_run_result,
2261 data: 'exit_status',
2262 defaultContent: ''
2263 },
2264 {
2265 title: 'Log',
2266 data: 'log',
2267 defaultContent: ''
2268 },
2269 {
2270 title: lang.active,
2271 data: 'active',
2272 defaultContent: '',
2273 render: function (data, type) {
2274 return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
2275 }
2276 },
2277 {
2278 title: lang.status,
2279 data: 'is_running',
2280 defaultContent: ''
2281 },
2282 {
2283 title: lang.excludes,
2284 data: 'exclude',
2285 defaultContent: '',
2286 className: 'none'
2287 },
2288 {
2289 title: lang.mins_interval,
2290 data: 'mins_interval',
2291 defaultContent: '',
2292 className: 'none'
2293 },
2294 {
2295 title: lang.action,
2296 data: 'action',
2297 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
2298 responsivePriority: 5,
2299 defaultContent: ''
2300 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002301 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002302 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002303
2304 table.on('responsive-resize', function (e, datatable, columns){
2305 hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
2306 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002307 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002308 function draw_filter_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002309 // just recalc width if instance already exists
2310 if ($.fn.DataTable.isDataTable('#filter_table') ) {
2311 $('#filter_table').DataTable().columns.adjust().responsive.recalc();
2312 return;
2313 }
2314
2315 var table = $('#filter_table').DataTable({
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002316 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002317 autoWidth: false,
2318 processing: true,
2319 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002320 stateSave: true,
2321 pageLength: pagination_size,
2322 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
2323 "tr" +
2324 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002325 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002326 order: [[2, 'desc']],
2327 initComplete: function(){
2328 hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
2329 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002330 ajax: {
2331 type: "GET",
2332 url: "/api/v1/get/filters/all",
2333 dataSrc: function(json){
2334 $.each(json, function (i, item) {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002335 if (item.active == 1) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002336 item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002337 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002338 item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002339 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002340 item.script_desc = escapeHtml(item.script_desc);
2341 item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
2342 item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
2343 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002344 '<a href="/edit/filter/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
2345 '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002346 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002347 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002348 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002349
2350 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002351 }
2352 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002353 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002354 {
2355 // placeholder, so checkbox will not block child row toggle
2356 title: '',
2357 data: null,
2358 searchable: false,
2359 orderable: false,
2360 defaultContent: '',
2361 responsivePriority: 1
2362 },
2363 {
2364 title: '',
2365 data: 'chkbox',
2366 searchable: false,
2367 orderable: false,
2368 defaultContent: '',
2369 responsivePriority: 2
2370 },
2371 {
2372 title: 'ID',
2373 data: 'id',
2374 responsivePriority: 2,
2375 defaultContent: ''
2376 },
2377 {
2378 title: lang.active,
2379 data: 'active',
2380 responsivePriority: 3,
2381 defaultContent: ''
2382 },
2383 {
2384 title: 'Type',
2385 data: 'filter_type',
2386 responsivePriority: 4,
2387 defaultContent: ''
2388 },
2389 {
2390 title: lang.owner,
2391 data: 'username',
2392 defaultContent: ''
2393 },
2394 {
2395 title: lang.description,
2396 data: 'script_desc',
2397 defaultContent: ''
2398 },
2399 {
2400 title: 'Script',
2401 data: 'script_data',
2402 defaultContent: '',
2403 className: 'none'
2404 },
2405 {
2406 title: lang.action,
2407 data: 'action',
2408 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
2409 responsivePriority: 5,
2410 defaultContent: ''
2411 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002412 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002413 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002414
2415 table.on('responsive-resize', function (e, datatable, columns){
2416 hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
2417 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002418 };
2419
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002420 function hideTableExpandCollapseBtn(tab, table){
2421 if ($(table).hasClass('collapsed'))
2422 $(tab).find(".table_collapse_option").show();
2423 else
2424 $(tab).find(".table_collapse_option").hide();
2425 }
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02002426
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002427 function filterByDomain(json, column, table){
2428 var tableId = $(table.table().container()).attr('id');
2429 // Create the `select` element
2430 var select = $('<select class="btn btn-sm btn-xs-lg btn-light text-start mx-2"><option value="">'+lang.all_domains+'</option></select>')
2431 .insertBefore(
2432 $('#'+tableId+' .dataTables_filter > label > input')
2433 )
2434 .on( 'change', function(){
2435 table.column(column)
2436 .search($(this).val())
2437 .draw();
2438 });
2439
2440 // get all domains
2441 var domains = [];
2442 json.forEach(obj => {
2443 Object.entries(obj).forEach(([key, value]) => {
2444 if(key === 'domain') {
2445 domains.push(value)
2446 }
2447 });
2448 });
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02002449
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002450 // get unique domain list
2451 domains = domains.filter(function(value, index, array) {
2452 return array.indexOf(value) === index;
2453 });
Matthias Andreas Benkard97f12022026-10-23 08:46:40 +02002454
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002455 // add domains to select
2456 domains.forEach(function(domain) {
2457 select.append($('<option>' + domain + '</option>'));
2458 });
2459 }
2460
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002461 // detect element visibility changes
2462 function onVisible(element, callback) {
2463 $(document).ready(function() {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002464 let element_object = document.querySelector(element);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002465 if (element_object === null) return;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002466
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002467 let observer = new IntersectionObserver((entries, observer) => {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002468 entries.forEach(entry => {
2469 if(entry.intersectionRatio > 0) {
2470 callback(element_object);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002471 observer.unobserve(element_object);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002472 }
2473 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002474 })
2475
2476 observer.observe(element_object);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002477 });
2478 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002479
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002480 // Load only if the tab is visible
2481 onVisible("[id^=domain_table]", () => draw_domain_table());
2482 onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table());
2483 onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
2484 onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table());
2485 onVisible("[id^=resource_table]", () => draw_resource_table());
2486 onVisible("[id^=alias_table]", () => draw_alias_table());
2487 onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
2488 onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
2489 onVisible("[id^=filter_table]", () => draw_filter_table());
2490 onVisible("[id^=bcc_table]", () => draw_bcc_table());
2491 onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
2492 onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002493});