blob: e2016e3edaad9186ce117c4e2e183ccef651d4cd [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({
182 dataType: 'json',
183 url: "/inc/ajax/sieve_validation.php",
184 type: "get",
185 data: { script: script },
186 complete: function(data) {
187 var response = (data.responseText);
188 response_obj = JSON.parse(response);
189 if (response_obj.type == "success") {
190 $(validation_button).next().attr({"disabled": false});
191 }
192 mailcow_alert_box(response_obj.msg, response_obj.type);
193 },
194 });
195 });
196 // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
197 // $("#active-script").closest('td').css('background-color','#b0f0a0');
198 // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
199 // });
200 $('#addResourceModal').on('shown.bs.modal', function() {
201 $("#multiple_bookings").val($("#multiple_bookings_select").val());
202 if ($("#multiple_bookings").val() == "custom") {
203 $("#multiple_bookings_custom_div").show();
204 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
205 }
206 })
207 $("#multiple_bookings_select").change(function() {
208 $("#multiple_bookings").val($("#multiple_bookings_select").val());
209 if ($("#multiple_bookings").val() == "custom") {
210 $("#multiple_bookings_custom_div").show();
211 }
212 else {
213 $("#multiple_bookings_custom_div").hide();
214 }
215 });
216 $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
217 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
218 });
219
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100220 function setDomainTemplateData(template){
221 $("#addDomain_max_aliases").val(template.max_num_aliases_for_domain);
222 $("#addDomain_max_mailboxes").val(template.max_num_mboxes_for_domain);
223 $("#addDomain_mailbox_quota_def").val(template.def_quota_for_mbox / 1048576);
224 $("#addDomain_mailbox_quota_m").val(template.max_quota_for_mbox / 1048576);
225 $("#addDomain_domain_quota_m").val(template.max_quota_for_domain / 1048576);
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100226
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100227 if (template.gal == 1){
228 $('#addDomain_gal').prop('checked', true);
229 } else {
230 $('#addDomain_gal').prop('checked', false);
231 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100232
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100233 if (template.active == 1){
234 $('#addDomain_active').prop('checked', true);
235 } else {
236 $('#addDomain_active').prop('checked', false);
237 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100238
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100239 $("#addDomain_rl_value").val(template.rl_value);
240 $('#addDomain_rl_frame').selectpicker('val', template.rl_frame);
241 $("#dkim_selector").val(template.dkim_selector);
242 if (!template.key_size)
243 template.key_size = 2048;
244 $('#key_size').selectpicker('val', template.key_size.toString());
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100245
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100246 if (template.backupmx == 1){
247 $('#addDomain_relay_domain').prop('checked', true);
248 } else {
249 $('#addDomain_relay_domain').prop('checked', false);
250 }
251 if (template.relay_all_recipients == 1){
252 $('#addDomain_relay_all').prop('checked', true);
253 } else {
254 $('#addDomain_relay_all').prop('checked', false);
255 }
256 if (template.relay_unknown_only == 1){
257 $('#addDomain_relay_unknown_only').prop('checked', true);
258 } else {
259 $('#addDomain_relay_unknown_only').prop('checked', false);
260 }
261
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100262
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100263 // load tags
264 $('#addDomain_tags').val("");
265 $($('#addDomain_tags').parent().find(".tag-values")[0]).val("");
266 $('#addDomain_tags').parent().find(".tag-badge").remove();
267 for (var i = 0; i < template.tags.length; i++)
268 addTag($('#addDomain_tags'), template.tags[i]);
269 }
270 function setMailboxTemplateData(template){
271 $("#addInputQuota").val(template.quota / 1048576);
272
273 if (template.quarantine_notification === "never"){
274 $('#quarantine_notification_never').prop('checked', true);
275 $('#quarantine_notification_hourly').prop('checked', false);
276 $('#quarantine_notification_daily').prop('checked', false);
277 $('#quarantine_notification_weekly').prop('checked', false);
278 } else if(template.quarantine_notification === "hourly"){
279 $('#quarantine_notification_never').prop('checked', false);
280 $('#quarantine_notification_hourly').prop('checked', true);
281 $('#quarantine_notification_daily').prop('checked', false);
282 $('#quarantine_notification_weekly').prop('checked', false);
283 } else if(template.quarantine_notification === "daily"){
284 $('#quarantine_notification_never').prop('checked', false);
285 $('#quarantine_notification_hourly').prop('checked', false);
286 $('#quarantine_notification_daily').prop('checked', true);
287 $('#quarantine_notification_weekly').prop('checked', false);
288 } else if(template.quarantine_notification === "weekly"){
289 $('#quarantine_notification_never').prop('checked', false);
290 $('#quarantine_notification_hourly').prop('checked', false);
291 $('#quarantine_notification_daily').prop('checked', false);
292 $('#quarantine_notification_weekly').prop('checked', true);
293 } else {
294 $('#quarantine_notification_never').prop('checked', false);
295 $('#quarantine_notification_hourly').prop('checked', false);
296 $('#quarantine_notification_daily').prop('checked', false);
297 $('#quarantine_notification_weekly').prop('checked', false);
298 }
299
300 if (template.quarantine_category === "reject"){
301 $('#quarantine_category_reject').prop('checked', true);
302 $('#quarantine_category_add_header').prop('checked', false);
303 $('#quarantine_category_all').prop('checked', false);
304 } else if(template.quarantine_category === "add_header"){
305 $('#quarantine_category_reject').prop('checked', false);
306 $('#quarantine_category_add_header').prop('checked', true);
307 $('#quarantine_category_all').prop('checked', false);
308 } else if(template.quarantine_category === "all"){
309 $('#quarantine_category_reject').prop('checked', false);
310 $('#quarantine_category_add_header').prop('checked', false);
311 $('#quarantine_category_all').prop('checked', true);
312 }
313
314 if (template.tls_enforce_in == 1){
315 $('#tls_enforce_in').prop('checked', true);
316 } else {
317 $('#tls_enforce_in').prop('checked', false);
318 }
319 if (template.tls_enforce_out == 1){
320 $('#tls_enforce_out').prop('checked', true);
321 } else {
322 $('#tls_enforce_out').prop('checked', false);
323 }
324
325 var protocol_access = [];
326 if (template.imap_access == 1){
327 protocol_access.push("imap");
328 }
329 if (template.pop3_access == 1){
330 protocol_access.push("pop3");
331 }
332 if (template.smtp_access == 1){
333 protocol_access.push("smtp");
334 }
335 if (template.sieve_access == 1){
336 protocol_access.push("sieve");
337 }
338 $('#protocol_access').selectpicker('val', protocol_access);
339
340 var acl = [];
341 if (template.acl_spam_alias == 1){
342 acl.push("spam_alias");
343 }
344 if (template.acl_tls_policy == 1){
345 acl.push("tls_policy");
346 }
347 if (template.acl_spam_score == 1){
348 acl.push("spam_score");
349 }
350 if (template.acl_spam_policy == 1){
351 acl.push("spam_policy");
352 }
353 if (template.acl_delimiter_action == 1){
354 acl.push("delimiter_action");
355 }
356 if (template.acl_syncjobs == 1){
357 acl.push("syncjobs");
358 }
359 if (template.acl_eas_reset == 1){
360 acl.push("eas_reset");
361 }
362 if (template.acl_sogo_profile_reset == 1){
363 acl.push("sogo_profile_reset");
364 }
365 if (template.acl_pushover == 1){
366 acl.push("pushover");
367 }
368 if (template.acl_quarantine == 1){
369 acl.push("quarantine");
370 }
371 if (template.acl_quarantine_attachments == 1){
372 acl.push("quarantine_attachments");
373 }
374 if (template.acl_quarantine_notification == 1){
375 acl.push("quarantine_notification");
376 }
377 if (template.acl_quarantine_category == 1){
378 acl.push("quarantine_category");
379 }
380 if (template.acl_app_passwds == 1){
381 acl.push("app_passwds");
382 }
383 $('#user_acl').selectpicker('val', acl);
384
385 $('#rl_value').val(template.rl_value);
386 if (template.rl_frame){
387 $('#rl_frame').selectpicker('val', template.rl_frame);
388 }
389
390 console.log(template.active)
391 if (template.active){
392 $('#mbox_active').selectpicker('val', template.active.toString());
393 } else {
394 $('#mbox_active').selectpicker('val', '');
395 }
396
397 if (template.force_pw_update == 1){
398 $('#force_pw_update').prop('checked', true);
399 } else {
400 $('#force_pw_update').prop('checked', false);
401 }
402 if (template.sogo_access == 1){
403 $('#sogo_access').prop('checked', true);
404 } else {
405 $('#sogo_access').prop('checked', false);
406 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100407
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100408 // load tags
409 $('#addMailbox_tags').val("");
410 $($('#addMailbox_tags').parent().find(".tag-values")[0]).val("");
411 $('#addMailbox_tags').parent().find(".tag-badge").remove();
412 for (var i = 0; i < template.tags.length; i++)
413 addTag($('#addMailbox_tags'), template.tags[i]);
414 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100415});
416jQuery(function($){
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100417 // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
418 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 +0100419 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 +0100420
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100421 $(".refresh_table").on('click', function(e) {
422 e.preventDefault();
423 var table_name = $(this).data('table');
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100424
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100425 if ($.fn.DataTable.isDataTable('#' + table_name))
426 $('#' + table_name).DataTable().ajax.reload();
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100427 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100428 function draw_domain_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100429 // just recalc width if instance already exists
430 if ($.fn.DataTable.isDataTable('#domain_table') ) {
431 $('#domain_table').DataTable().columns.adjust().responsive.recalc();
432 return;
433 }
434
435 var table = $('#domain_table').DataTable({
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100436 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100437 processing: true,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100438 serverSide: true,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100439 stateSave: true,
440 pageLength: pagination_size,
441 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
442 "tr" +
443 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100444 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100445 initComplete: function(){
446 hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
447 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100448 ajax: {
449 type: "GET",
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100450 url: "/api/v1/get/domain/datatables",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100451 dataSrc: function(json){
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100452 $.each(json.data, function(i, item) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100453 item.domain_name = escapeHtml(item.domain_name);
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100454 item.domain_h_name = escapeHtml(item.domain_h_name);
455 if (item.domain_name != item.domain_h_name){
456 item.domain_h_name = item.domain_h_name + '<small class="d-block">' + item.domain_name + '</small>';
457 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100458
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100459 item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
460 item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
461 item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
462 item.stats = item.msgs_total + "/" + item.bytes_total;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100463
464 if (!item.rl) item.rl = '∞';
465 else {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100466 item.rl = $.map(item.rl, function(e){
467 return e;
468 }).join('/1');
469 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100470
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100471 item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
472 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100473 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 +0100474 item.action = '<div class="btn-group">';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100475 if (role == "admin") {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100476 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>' +
477 '<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>' +
478 '<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 +0100479 }
480 else {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100481 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>' +
482 '<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 +0100483 }
484
485 if (Array.isArray(item.tags)){
486 var tags = '';
487 for (var i = 0; i < item.tags.length; i++)
488 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
489 item.tags = tags;
490 } else {
491 item.tags = '';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100492 }
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200493
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100494 if (item.backupmx == 1) {
495 if (item.relay_unknown_only == 1) {
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100496 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 +0100497 } else if (item.relay_all_recipients == 1) {
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100498 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 +0100499 } else {
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100500 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 +0100501 }
502 }
503 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100504
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100505 return json.data;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100506 }
507 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100508 columns: [
509 {
510 // placeholder, so checkbox will not block child row toggle
511 title: '',
512 data: null,
513 searchable: false,
514 orderable: false,
515 defaultContent: '',
516 responsivePriority: 1
517 },
518 {
519 title: '',
520 data: 'chkbox',
521 searchable: false,
522 orderable: false,
523 defaultContent: '',
524 responsivePriority: 2
525 },
526 {
527 title: lang.domain,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100528 data: 'domain_h_name',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100529 responsivePriority: 3,
530 defaultContent: ''
531 },
532 {
533 title: lang.aliases,
534 data: 'aliases',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100535 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100536 defaultContent: ''
537 },
538 {
539 title: lang.mailboxes,
540 data: 'mailboxes',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100541 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100542 responsivePriority: 4,
543 defaultContent: ''
544 },
545 {
546 title: lang.domain_quota,
547 data: 'quota',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100548 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100549 defaultContent: '',
550 render: function (data, type) {
551 data = data.split("/");
552 return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
553 }
554 },
555 {
556 title: lang.stats,
557 data: 'stats',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100558 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100559 defaultContent: '',
560 render: function (data, type) {
561 data = data.split("/");
562 return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
563 }
564 },
565 {
566 title: lang.mailbox_defquota,
567 data: 'def_quota_for_mbox',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100568 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100569 defaultContent: ''
570 },
571 {
572 title: lang.mailbox_quota,
573 data: 'max_quota_for_mbox',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100574 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100575 defaultContent: ''
576 },
577 {
578 title: 'RL',
579 data: 'rl',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100580 searchable: false,
581 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100582 defaultContent: ''
583 },
584 {
585 title: lang.backup_mx,
586 data: 'backupmx',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100587 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100588 defaultContent: '',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100589 render: function (data, type){
590 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 +0100591 }
592 },
593 {
594 title: lang.domain_admins,
595 data: 'domain_admins',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100596 searchable: false,
597 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100598 defaultContent: '',
599 className: 'none'
600 },
601 {
602 title: lang.created_on,
603 data: 'created',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100604 searchable: false,
605 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100606 defaultContent: '',
607 className: 'none'
608 },
609 {
610 title: lang.last_modified,
611 data: 'modified',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100612 searchable: false,
613 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100614 defaultContent: '',
615 className: 'none'
616 },
617 {
618 title: 'Tags',
619 data: 'tags',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100620 searchable: true,
621 orderable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100622 defaultContent: '',
623 className: 'none'
624 },
625 {
626 title: lang.active,
627 data: 'active',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100628 searchable: false,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100629 defaultContent: '',
630 responsivePriority: 6,
631 render: function (data, type) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100632 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 +0100633 }
634 },
635 {
636 title: lang.action,
637 data: 'action',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100638 searchable: false,
639 orderable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100640 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100641 responsivePriority: 5,
642 defaultContent: ''
643 },
644 ]
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100645 });
646
647 table.on('responsive-resize', function (e, datatable, columns){
648 hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
649 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100650 }
651 function draw_templates_domain_table() {
652 // just recalc width if instance already exists
653 if ($.fn.DataTable.isDataTable('#templates_domain_table') ) {
654 $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc();
655 return;
656 }
657
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100658 var table = $('#templates_domain_table').DataTable({
659 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100660 processing: true,
661 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100662 stateSave: true,
663 pageLength: pagination_size,
664 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
665 "tr" +
666 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100667 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100668 order: [[2, 'desc']],
669 initComplete: function(){
670 hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
671 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100672 ajax: {
673 type: "GET",
674 url: "/api/v1/get/domain/template/all",
675 dataSrc: function(json){
676 $.each(json, function (i, item) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100677 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 +0100678
679 item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox);
680 item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox);
681 item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain);
682
683 item.template = escapeHtml(item.template);
684 if (item.attributes.rl_frame === "s"){
685 item.attributes.rl_frame = lang_rl.second;
686 } else if (item.attributes.rl_frame === "m"){
687 item.attributes.rl_frame = lang_rl.minute;
688 } else if (item.attributes.rl_frame === "h"){
689 item.attributes.rl_frame = lang_rl.hour;
690 } else if (item.attributes.rl_frame === "d"){
691 item.attributes.rl_frame = lang_rl.day;
692 }
693 item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
694
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100695
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100696 if (item.template.toLowerCase() == "default"){
697 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100698 '<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 +0100699 '</div>';
700 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100701 else {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100702 item.action = '<div class="btn-group">' +
703 '<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>' +
704 '<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 +0100705 '</div>';
706 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100707
708 if (Array.isArray(item.attributes.tags)){
709 var tags = '';
710 for (var i = 0; i < item.attributes.tags.length; i++)
711 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
712 item.attributes.tags = tags;
713 } else {
714 item.attributes.tags = '';
715 }
716 });
717
718 return json;
719 }
720 },
721 columns: [
722 {
723 // placeholder, so checkbox will not block child row toggle
724 title: '',
725 data: null,
726 searchable: false,
727 orderable: false,
728 defaultContent: '',
729 responsivePriority: 1
730 },
731 {
732 title: '',
733 data: 'chkbox',
734 searchable: false,
735 orderable: false,
736 defaultContent: '',
737 responsivePriority: 1
738 },
739 {
740 title: "ID",
741 data: 'id',
742 responsivePriority: 2,
743 defaultContent: ''
744 },
745 {
746 title: lang.template,
747 data: 'template',
748 responsivePriority: 3,
749 defaultContent: ''
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100750 },
751 {
752 title: lang.max_aliases,
753 data: 'attributes.max_num_aliases_for_domain',
754 defaultContent: '',
755 },
756 {
757 title: lang.max_mailboxes,
758 data: 'attributes.max_num_mboxes_for_domain',
759 defaultContent: '',
760 },
761 {
762 title: lang.mailbox_defquota,
763 data: 'attributes.def_quota_for_mbox',
764 defaultContent: '',
765 },
766 {
767 title: lang.max_quota,
768 data: 'attributes.max_quota_for_mbox',
769 defaultContent: '',
770 },
771 {
772 title: lang.domain_quota_total,
773 data: 'attributes.max_quota_for_domain',
774 defaultContent: '',
775 },
776 {
777 title: lang.gal,
778 data: 'attributes.gal',
779 defaultContent: '',
780 render: function (data, type) {
781 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>';
782 }
783 },
784 {
785 title: lang.backup_mx,
786 data: 'attributes.backupmx',
787 defaultContent: '',
788 render: function (data, type) {
789 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>';
790 }
791 },
792 {
793 title: lang.relay_all,
794 data: 'attributes.relay_all_recipients',
795 defaultContent: '',
796 render: function (data, type) {
797 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>';
798 }
799 },
800 {
801 title: lang.relay_unknown,
802 data: 'attributes.relay_unknown_only',
803 defaultContent: '',
804 render: function (data, type) {
805 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>';
806 }
807 },
808 {
809 title: lang.active,
810 data: 'attributes.active',
811 defaultContent: '',
812 responsivePriority: 4,
813 render: function (data, type) {
814 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>';
815 }
816 },
817 {
818 title: 'rl_frame',
819 data: 'attributes.rl_frame',
820 defaultContent: '',
821 class: 'none',
822 },
823 {
824 title: 'rl_value',
825 data: 'attributes.rl_value',
826 defaultContent: '',
827 class: 'none',
828 },
829 {
830 title: lang.dkim_domains_selector,
831 data: 'attributes.dkim_selector',
832 defaultContent: '',
833 class: 'none',
834 },
835 {
836 title: lang.dkim_key_length,
837 data: 'attributes.key_size',
838 defaultContent: '',
839 class: 'none',
840 },
841 {
842 title: 'Tags',
843 data: 'attributes.tags',
844 defaultContent: '',
845 className: 'none'
846 },
847 {
848 title: lang.action,
849 data: 'action',
850 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
851 responsivePriority: 6,
852 defaultContent: ''
853 },
854 ]
855 });
856
857 table.on('responsive-resize', function (e, datatable, columns){
858 hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
859 });
860 }
861 function draw_mailbox_table() {
862 // just recalc width if instance already exists
863 if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
864 $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
865 return;
866 }
867
868 var table = $('#mailbox_table').DataTable({
869 responsive: true,
870 processing: true,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100871 serverSide: true,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100872 stateSave: true,
873 pageLength: pagination_size,
874 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
875 "tr" +
876 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
877 language: lang_datatables,
878 initComplete: function(settings, json){
879 hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100880 },
881 ajax: {
882 type: "GET",
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100883 url: "/api/v1/get/mailbox/datatables",
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100884 dataSrc: function(json){
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100885 $.each(json.data, function (i, item) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100886 item.quota = {
887 sortBy: item.quota_used,
888 value: item.quota
889 }
890 item.quota.value = (item.quota.value == 0 ? "∞" : humanFileSize(item.quota.value));
891 item.quota.value = humanFileSize(item.quota_used) + "/" + item.quota.value;
892
893 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
894 item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
895 /*
896 if (!item.rl) {
897 item.rl = '∞';
898 } else {
899 item.rl = $.map(item.rl, function(e){
900 return e;
901 }).join('/1');
902 if (item.rl_scope === 'domain') {
903 item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
904 }
905 }
906 */
907 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
908 if (item.attributes.passwd_update != '0') {
909 var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
910 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"});
911 } else {
912 item.last_pw_change = '-';
913 }
914 item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
915 item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
916 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>';
917 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>';
918 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>';
919 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>';
920 if (item.attributes.quarantine_notification === 'never') {
921 item.quarantine_notification = lang.never;
922 } else if (item.attributes.quarantine_notification === 'hourly') {
923 item.quarantine_notification = lang.hourly;
924 } else if (item.attributes.quarantine_notification === 'daily') {
925 item.quarantine_notification = lang.daily;
926 } else if (item.attributes.quarantine_notification === 'weekly') {
927 item.quarantine_notification = lang.weekly;
928 }
929 if (item.attributes.quarantine_category === 'reject') {
930 item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
931 } else if (item.attributes.quarantine_category === 'add_header') {
932 item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
933 } else if (item.attributes.quarantine_category === 'all') {
934 item.quarantine_category = lang.q_all;
935 }
936 if (acl_data.login_as === 1) {
937
938 item.action = '<div class="btn-group">' +
939 '<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>' +
940 '<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>' +
941 '<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>';
942 if (ALLOW_ADMIN_EMAIL_LOGIN) {
943 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" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>';
944 }
945 item.action += '</div>';
946 }
947 else {
948 item.action = '<div class="btn-group">' +
949 '<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>' +
950 '<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>' +
951 '</div>';
952 }
953 item.in_use = {
954 sortBy: item.percent_in_use,
955 value: '<div class="progress">' +
956 '<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" ' +
957 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>'
958 };
959 item.username = escapeHtml(item.username);
960
961 if (Array.isArray(item.tags)){
962 var tags = '';
963 for (var i = 0; i < item.tags.length; i++)
964 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
965 item.tags = tags;
966 } else {
967 item.tags = '';
968 }
969 });
970
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100971 return json.data;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100972 }
973 },
974 columns: [
975 {
976 // placeholder, so checkbox will not block child row toggle
977 title: '',
978 data: null,
979 searchable: false,
980 orderable: false,
981 defaultContent: '',
982 responsivePriority: 1
983 },
984 {
985 title: '',
986 data: 'chkbox',
987 searchable: false,
988 orderable: false,
989 defaultContent: '',
990 responsivePriority: 2
991 },
992 {
993 title: lang.username,
994 data: 'username',
995 responsivePriority: 3,
996 defaultContent: ''
997 },
998 {
999 title: lang.domain_quota,
1000 data: 'quota.value',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001001 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001002 responsivePriority: 8,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001003 defaultContent: ''
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001004 },
1005 {
1006 title: lang.last_mail_login,
1007 data: 'last_mail_login',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001008 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001009 defaultContent: '',
1010 responsivePriority: 7,
1011 render: function (data, type) {
1012 res = data.split("/");
1013 return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
1014 '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
1015 '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
1016 }
1017 },
1018 {
1019 title: lang.last_pw_change,
1020 data: 'last_pw_change',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001021 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001022 defaultContent: ''
1023 },
1024 {
1025 title: lang.in_use,
1026 data: 'in_use.value',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001027 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001028 defaultContent: '',
1029 responsivePriority: 9,
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001030 className: 'dt-data-w100'
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001031 },
1032 {
1033 title: lang.fname,
1034 data: 'name',
1035 defaultContent: '',
1036 className: 'none'
1037 },
1038 {
1039 title: lang.domain,
1040 data: 'domain',
1041 defaultContent: '',
1042 className: 'none'
1043 },
1044 {
1045 title: lang.tls_enforce_in,
1046 data: 'tls_enforce_in',
1047 defaultContent: '',
1048 className: 'none'
1049 },
1050 {
1051 title: lang.tls_enforce_out,
1052 data: 'tls_enforce_out',
1053 defaultContent: '',
1054 className: 'none'
1055 },
1056 {
1057 title: 'SMTP',
1058 data: 'smtp_access',
1059 defaultContent: '',
1060 className: 'none'
1061 },
1062 {
1063 title: 'IMAP',
1064 data: 'imap_access',
1065 defaultContent: '',
1066 className: 'none'
1067 },
1068 {
1069 title: 'POP3',
1070 data: 'pop3_access',
1071 defaultContent: '',
1072 className: 'none'
1073 },
1074 {
1075 title: 'SIEVE',
1076 data: 'sieve_access',
1077 defaultContent: '',
1078 className: 'none'
1079 },
1080 {
1081 title: lang.quarantine_notification,
1082 data: 'quarantine_notification',
1083 defaultContent: '',
1084 className: 'none'
1085 },
1086 {
1087 title: lang.quarantine_category,
1088 data: 'quarantine_category',
1089 defaultContent: '',
1090 className: 'none'
1091 },
1092 {
1093 title: lang.msg_num,
1094 data: 'messages',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001095 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001096 defaultContent: '',
1097 responsivePriority: 5
1098 },
1099 {
1100 title: lang.created_on,
1101 data: 'created',
1102 defaultContent: '',
1103 className: 'none'
1104 },
1105 {
1106 title: lang.last_modified,
1107 data: 'modified',
1108 defaultContent: '',
1109 className: 'none'
1110 },
1111 {
1112 title: 'Tags',
1113 data: 'tags',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001114 searchable: true,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001115 defaultContent: '',
1116 className: 'none'
1117 },
1118 {
1119 title: lang.active,
1120 data: 'active',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001121 searchable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001122 defaultContent: '',
1123 responsivePriority: 4,
1124 render: function (data, type) {
1125 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;');
1126 }
1127 },
1128 {
1129 title: lang.action,
1130 data: 'action',
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001131 searchable: false,
1132 orderable: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001133 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1134 responsivePriority: 6,
1135 defaultContent: ''
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +01001136 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001137 ]
1138 });
1139
1140 table.on('responsive-resize', function (e, datatable, columns){
1141 hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
1142 });
1143 }
1144 function draw_templates_mbox_table() {
1145 // just recalc width if instance already exists
1146 if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) {
1147 $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc();
1148 return;
1149 }
1150
1151 var table = $('#templates_mbox_table').DataTable({
1152 responsive: true,
1153 processing: true,
1154 serverSide: false,
1155 stateSave: true,
1156 pageLength: pagination_size,
1157 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1158 "tr" +
1159 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
1160 language: lang_datatables,
1161 order: [[2, 'desc']],
1162 initComplete: function(){
1163 hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
1164 },
1165 ajax: {
1166 type: "GET",
1167 url: "/api/v1/get/mailbox/template/all",
1168 dataSrc: function(json){
1169 $.each(json, function (i, item) {
1170 item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
1171
1172 item.template = escapeHtml(item.template);
1173 if (item.attributes.rl_frame === "s"){
1174 item.attributes.rl_frame = lang_rl.second;
1175 } else if (item.attributes.rl_frame === "m"){
1176 item.attributes.rl_frame = lang_rl.minute;
1177 } else if (item.attributes.rl_frame === "h"){
1178 item.attributes.rl_frame = lang_rl.hour;
1179 } else if (item.attributes.rl_frame === "d"){
1180 item.attributes.rl_frame = lang_rl.day;
1181 }
1182 item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
1183
1184 item.attributes.quota = humanFileSize(item.attributes.quota);
1185
1186 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>';
1187 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>';
1188 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>';
1189 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>';
1190 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>';
1191 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>';
1192 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>';
1193 if (item.attributes.quarantine_notification === 'never') {
1194 item.attributes.quarantine_notification = lang.never;
1195 } else if (item.attributes.quarantine_notification === 'hourly') {
1196 item.attributes.quarantine_notification = lang.hourly;
1197 } else if (item.attributes.quarantine_notification === 'daily') {
1198 item.attributes.quarantine_notification = lang.daily;
1199 } else if (item.attributes.quarantine_notification === 'weekly') {
1200 item.attributes.quarantine_notification = lang.weekly;
1201 }
1202 if (item.attributes.quarantine_category === 'reject') {
1203 item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
1204 } else if (item.attributes.quarantine_category === 'add_header') {
1205 item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
1206 } else if (item.attributes.quarantine_category === 'all') {
1207 item.attributes.quarantine_category = lang.q_all;
1208 }
1209
1210 if (item.template.toLowerCase() == "default"){
1211 item.action = '<div class="btn-group">' +
1212 '<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>' +
1213 '</div>';
1214 }
1215 else {
1216 item.action = '<div class="btn-group">' +
1217 '<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>' +
1218 '<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>' +
1219 '</div>';
1220 }
1221
1222 if (Array.isArray(item.attributes.tags)){
1223 var tags = '';
1224 for (var i = 0; i < item.attributes.tags.length; i++)
1225 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
1226 item.attributes.tags = tags;
1227 } else {
1228 item.attributes.tags = '';
1229 }
1230 });
1231
1232 return json;
1233 }
1234 },
1235 columns: [
1236 {
1237 // placeholder, so checkbox will not block child row toggle
1238 title: '',
1239 data: null,
1240 searchable: false,
1241 orderable: false,
1242 defaultContent: '',
1243 responsivePriority: 1
1244 },
1245 {
1246 title: '',
1247 data: 'chkbox',
1248 searchable: false,
1249 orderable: false,
1250 defaultContent: '',
1251 responsivePriority: 1
1252 },
1253 {
1254 title: "ID",
1255 data: 'id',
1256 responsivePriority: 2,
1257 defaultContent: ''
1258 },
1259 {
1260 title: lang.template,
1261 data: 'template',
1262 responsivePriority: 3,
1263 defaultContent: ''
1264 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001265 {
1266 title: lang.domain_quota,
1267 data: 'attributes.quota',
1268 defaultContent: '',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001269 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001270 {
1271 title: lang.tls_enforce_in,
1272 data: 'attributes.tls_enforce_in',
1273 defaultContent: ''
1274 },
1275 {
1276 title: lang.tls_enforce_out,
1277 data: 'attributes.tls_enforce_out',
1278 defaultContent: ''
1279 },
1280 {
1281 title: 'SMTP',
1282 data: 'attributes.smtp_access',
1283 defaultContent: '',
1284 },
1285 {
1286 title: 'IMAP',
1287 data: 'attributes.imap_access',
1288 defaultContent: '',
1289 },
1290 {
1291 title: 'POP3',
1292 data: 'attributes.pop3_access',
1293 defaultContent: '',
1294 },
1295 {
1296 title: 'SIEVE',
1297 data: 'attributes.sieve_access',
1298 defaultContent: '',
1299 },
1300 {
1301 title: 'SOGO',
1302 data: 'attributes.sogo_access',
1303 defaultContent: '',
1304 },
1305 {
1306 title: lang.quarantine_notification,
1307 data: 'attributes.quarantine_notification',
1308 defaultContent: '',
1309 className: 'none'
1310 },
1311 {
1312 title: lang.quarantine_category,
1313 data: 'attributes.quarantine_category',
1314 defaultContent: '',
1315 className: 'none'
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001316 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001317 {
1318 title: lang.force_pw_update,
1319 data: 'attributes.force_pw_update',
1320 defaultContent: '',
1321 class: 'none',
1322 render: function (data, type) {
1323 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
1324 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001325 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001326 {
1327 title: "rl_frame",
1328 data: 'attributes.rl_frame',
1329 defaultContent: '',
1330 class: 'none',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001331 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001332 {
1333 title: 'rl_value',
1334 data: 'attributes.rl_value',
1335 defaultContent: '',
1336 class: 'none',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001337 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001338 {
1339 title: 'Tags',
1340 data: 'attributes.tags',
1341 defaultContent: '',
1342 className: 'none'
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001343 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001344 {
1345 title: lang.active,
1346 data: 'attributes.active',
1347 defaultContent: '',
1348 responsivePriority: 4,
1349 render: function (data, type) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001350 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 +01001351 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001352 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001353 {
1354 title: lang.action,
1355 data: 'action',
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001356 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001357 responsivePriority: 6,
1358 defaultContent: ''
1359 },
1360 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001361 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001362
1363 table.on('responsive-resize', function (e, datatable, columns){
1364 hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
1365 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001366 }
1367 function draw_resource_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001368 // just recalc width if instance already exists
1369 if ($.fn.DataTable.isDataTable('#resource_table') ) {
1370 $('#resource_table').DataTable().columns.adjust().responsive.recalc();
1371 return;
1372 }
1373
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001374 var table = $('#resource_table').DataTable({
1375 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001376 processing: true,
1377 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001378 stateSave: true,
1379 pageLength: pagination_size,
1380 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1381 "tr" +
1382 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001383 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001384 initComplete: function(settings, json){
1385 hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
1386 filterByDomain(json, 5, table);
1387 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001388 ajax: {
1389 type: "GET",
1390 url: "/api/v1/get/resource/all",
1391 dataSrc: function(json){
1392 $.each(json, function (i, item) {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001393 if (item.multiple_bookings == '0') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001394 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 +01001395 } else if (item.multiple_bookings == '-1') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001396 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 +01001397 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001398 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 +01001399 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001400 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001401 '<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>' +
1402 '<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 +01001403 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001404 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 +01001405 item.name = escapeHtml(item.name);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001406 item.description = escapeHtml(item.description);
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001407 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001408
1409 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001410 }
1411 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001412 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001413 {
1414 // placeholder, so checkbox will not block child row toggle
1415 title: '',
1416 data: null,
1417 searchable: false,
1418 orderable: false,
1419 defaultContent: '',
1420 responsivePriority: 1
1421 },
1422 {
1423 title: '',
1424 data: 'chkbox',
1425 searchable: false,
1426 orderable: false,
1427 defaultContent: '',
1428 responsivePriority: 2
1429 },
1430 {
1431 title: lang.description,
1432 data: 'description',
1433 responsivePriority: 3,
1434 defaultContent: ''
1435 },
1436 {
1437 title: lang.alias,
1438 data: 'name',
1439 defaultContent: ''
1440 },
1441 {
1442 title: lang.kind,
1443 data: 'kind',
1444 defaultContent: ''
1445 },
1446 {
1447 title: lang.domain,
1448 data: 'domain',
1449 responsivePriority: 4,
1450 defaultContent: ''
1451 },
1452 {
1453 title: lang.multiple_bookings,
1454 data: 'multiple_bookings',
1455 defaultContent: ''
1456 },
1457 {
1458 title: lang.active,
1459 data: 'active',
1460 defaultContent: '',
1461 render: function (data, type) {
1462 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;');
1463 }
1464 },
1465 {
1466 title: lang.action,
1467 data: 'action',
1468 responsivePriority: 5,
1469 defaultContent: '',
1470 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right'
1471 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001472 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001473 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001474
1475 table.on('responsive-resize', function (e, datatable, columns){
1476 hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
1477 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001478 }
1479 function draw_bcc_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001480 $.get("/api/v1/get/bcc-destination-options", function(data){
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001481 var optgroup = "";
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001482 // Domains
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001483 if (data.domains && data.domains.length > 0) {
1484 optgroup = "<optgroup label='" + lang.domains + "'>";
1485 $.each(data.domains, function(index, domain){
1486 optgroup += "<option value='" + domain + "'>" + domain + "</option>";
1487 });
1488 optgroup += "</optgroup>";
1489 $('#bcc-local-dest').append(optgroup);
1490 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001491 // Alias domains
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001492 if (data.alias_domains && data.alias_domains.length > 0) {
1493 optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
1494 $.each(data.alias_domains, function(index, alias_domain){
1495 optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>";
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001496 });
1497 optgroup += "</optgroup>"
1498 $('#bcc-local-dest').append(optgroup);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001499 }
1500 // Mailboxes and aliases
1501 if (data.mailboxes && Object.keys(data.mailboxes).length > 0) {
1502 $.each(data.mailboxes, function(mailbox, aliases){
1503 optgroup = "<optgroup label='" + mailbox + "'>";
1504 $.each(aliases, function(index, alias){
1505 optgroup += "<option value='" + alias + "'>" + alias + "</option>";
1506 });
1507 optgroup += "</optgroup>";
1508 $('#bcc-local-dest').append(optgroup);
1509 });
1510 }
1511 // Recreate picker
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001512 $('#bcc-local-dest').selectpicker('refresh');
1513 });
1514
1515 // just recalc width if instance already exists
1516 if ($.fn.DataTable.isDataTable('#bcc_table') ) {
1517 $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
1518 return;
1519 }
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001520
1521 var table = $('#bcc_table').DataTable({
1522 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001523 processing: true,
1524 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001525 stateSave: true,
1526 pageLength: pagination_size,
1527 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1528 "tr" +
1529 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001530 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001531 order: [[2, 'desc']],
1532 initComplete: function(settings, json){
1533 hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
1534 filterByDomain(json, 6, table);
1535 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001536 ajax: {
1537 type: "GET",
1538 url: "/api/v1/get/bcc/all",
1539 dataSrc: function(json){
1540 $.each(json, function (i, item) {
1541 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001542 '<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>' +
1543 '<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 +01001544 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001545 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 +01001546 item.local_dest = escapeHtml(item.local_dest);
1547 item.bcc_dest = escapeHtml(item.bcc_dest);
1548 if (item.type == 'sender') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001549 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 +01001550 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001551 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 +01001552 }
1553 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001554
1555 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001556 }
1557 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001558 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001559 {
1560 // placeholder, so checkbox will not block child row toggle
1561 title: '',
1562 data: null,
1563 searchable: false,
1564 orderable: false,
1565 defaultContent: '',
1566 responsivePriority: 1
1567 },
1568 {
1569 title: '',
1570 data: 'chkbox',
1571 searchable: false,
1572 orderable: false,
1573 defaultContent: '',
1574 responsivePriority: 2
1575 },
1576 {
1577 title: 'ID',
1578 data: 'id',
1579 responsivePriority: 3,
1580 defaultContent: ''
1581 },
1582 {
1583 title: lang.bcc_type,
1584 data: 'type',
1585 defaultContent: ''
1586 },
1587 {
1588 title: lang.bcc_local_dest,
1589 data: 'local_dest',
1590 defaultContent: ''
1591 },
1592 {
1593 title: lang.bcc_destinations,
1594 data: 'bcc_dest',
1595 defaultContent: ''
1596 },
1597 {
1598 title: lang.domain,
1599 data: 'domain',
1600 responsivePriority: 4,
1601 defaultContent: ''
1602 },
1603 {
1604 title: lang.active,
1605 data: 'active',
1606 defaultContent: '',
1607 render: function (data, type) {
1608 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;');
1609 }
1610 },
1611 {
1612 title: lang.action,
1613 data: 'action',
1614 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1615 responsivePriority: 5,
1616 defaultContent: ''
1617 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001618 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001619 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001620
1621 table.on('responsive-resize', function (e, datatable, columns){
1622 hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
1623 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001624 }
1625 function draw_recipient_map_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001626 // just recalc width if instance already exists
1627 if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
1628 $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
1629 return;
1630 }
1631
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001632 var table = $('#recipient_map_table').DataTable({
1633 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001634 processing: true,
1635 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001636 stateSave: true,
1637 pageLength: pagination_size,
1638 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1639 "tr" +
1640 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001641 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001642 order: [[2, 'desc']],
1643 initComplete: function(){
1644 hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
1645 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001646 ajax: {
1647 type: "GET",
1648 url: "/api/v1/get/recipient_map/all",
1649 dataSrc: function(json){
1650 if (role !== "admin") return null;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001651
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001652 $.each(json, function (i, item) {
1653 item.recipient_map_old = escapeHtml(item.recipient_map_old);
1654 item.recipient_map_new = escapeHtml(item.recipient_map_new);
1655 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001656 '<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>' +
1657 '<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 +01001658 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001659 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 +01001660 });
1661
1662 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001663 }
1664 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001665 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001666 {
1667 // placeholder, so checkbox will not block child row toggle
1668 title: '',
1669 data: null,
1670 searchable: false,
1671 orderable: false,
1672 defaultContent: '',
1673 responsivePriority: 1
1674 },
1675 {
1676 title: '',
1677 data: 'chkbox',
1678 searchable: false,
1679 orderable: false,
1680 defaultContent: '',
1681 responsivePriority: 2
1682 },
1683 {
1684 title: 'ID',
1685 data: 'id',
1686 responsivePriority: 3,
1687 defaultContent: ''
1688 },
1689 {
1690 title: lang.recipient_map_old,
1691 data: 'recipient_map_old',
1692 defaultContent: ''
1693 },
1694 {
1695 title: lang.recipient_map_new,
1696 data: 'recipient_map_new',
1697 defaultContent: '',
1698 responsivePriority: 4
1699 },
1700 {
1701 title: lang.active,
1702 data: 'active',
1703 defaultContent: '',
1704 render: function (data, type) {
1705 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>';
1706 }
1707 },
1708 {
1709 title: lang.action,
1710 data: 'action',
1711 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1712 responsivePriority: 5,
1713 defaultContent: ''
1714 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001715 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001716 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001717
1718 table.on('responsive-resize', function (e, datatable, columns){
1719 hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
1720 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001721 }
1722 function draw_tls_policy_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001723 // just recalc width if instance already exists
1724 if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
1725 $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
1726 return;
1727 }
1728
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001729 var table = $('#tls_policy_table').DataTable({
1730 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001731 processing: true,
1732 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001733 stateSave: true,
1734 pageLength: pagination_size,
1735 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1736 "tr" +
1737 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001738 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001739 order: [[2, 'desc']],
1740 initComplete: function(){
1741 hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
1742 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001743 ajax: {
1744 type: "GET",
1745 url: "/api/v1/get/tls-policy-map/all",
1746 dataSrc: function(json){
1747 if (role !== "admin") return null;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001748
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001749 $.each(json, function (i, item) {
1750 item.dest = escapeHtml(item.dest);
1751 item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
1752 if (item.parameters == '') {
1753 item.parameters = '<code>-</code>';
1754 } else {
1755 item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
1756 }
1757 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001758 '<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>' +
1759 '<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 +01001760 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001761 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 +01001762 });
1763
1764 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001765 }
1766 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001767 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001768 {
1769 // placeholder, so checkbox will not block child row toggle
1770 title: '',
1771 data: null,
1772 searchable: false,
1773 orderable: false,
1774 defaultContent: '',
1775 responsivePriority: 1
1776 },
1777 {
1778 title: '',
1779 data: 'chkbox',
1780 searchable: false,
1781 orderable: false,
1782 defaultContent: '',
1783 responsivePriority: 2
1784 },
1785 {
1786 title: 'ID',
1787 data: 'id',
1788 responsivePriority: 3,
1789 defaultContent: ''
1790 },
1791 {
1792 title: lang.tls_map_dest,
1793 data: 'dest',
1794 defaultContent: '',
1795 responsivePriority: 4
1796 },
1797 {
1798 title: lang.tls_map_policy,
1799 data: 'policy',
1800 defaultContent: ''
1801 },
1802 {
1803 title: lang.tls_map_parameters,
1804 data: 'parameters',
1805 defaultContent: ''
1806 },
1807 {
1808 title: lang.active,
1809 data: 'active',
1810 defaultContent: '',
1811 render: function (data, type) {
1812 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>';
1813 }
1814 },
1815 {
1816 title: lang.action,
1817 data: 'action',
1818 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1819 responsivePriority: 5,
1820 defaultContent: ''
1821 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001822 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001823 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001824
1825 table.on('responsive-resize', function (e, datatable, columns){
1826 hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
1827 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001828 }
1829 function draw_alias_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001830 // just recalc width if instance already exists
1831 if ($.fn.DataTable.isDataTable('#alias_table') ) {
1832 $('#alias_table').DataTable().columns.adjust().responsive.recalc();
1833 return;
1834 }
1835
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001836 var table = $('#alias_table').DataTable({
1837 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001838 processing: true,
1839 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001840 stateSave: true,
1841 pageLength: pagination_size,
1842 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
1843 "tr" +
1844 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001845 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001846 order: [[2, 'desc']],
1847 initComplete: function(settings, json){
1848 hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
1849 filterByDomain(json, 5, table);
1850 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001851 ajax: {
1852 type: "GET",
1853 url: "/api/v1/get/alias/all",
1854 dataSrc: function(json){
1855 $.each(json, function (i, item) {
1856 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001857 '<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>' +
1858 '<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 +01001859 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001860 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 +01001861 item.goto = escapeHtml(item.goto.replace(/,/g, " "));
1862 if (item.public_comment !== null) {
1863 item.public_comment = escapeHtml(item.public_comment);
1864 }
1865 else {
1866 item.public_comment = '-';
1867 }
1868 if (item.private_comment !== null) {
1869 item.private_comment = escapeHtml(item.private_comment);
1870 }
1871 else {
1872 item.private_comment = '-';
1873 }
1874 if (item.is_catch_all == 1) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001875 item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001876 }
1877 else {
1878 item.address = escapeHtml(item.address);
1879 }
1880 if (item.goto == "null@localhost") {
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +02001881 item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001882 }
1883 else if (item.goto == "spam@localhost") {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001884 item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001885 }
1886 else if (item.goto == "ham@localhost") {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001887 item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001888 }
1889 if (item.in_primary_domain !== "") {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001890 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 +01001891 }
1892 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001893
1894 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001895 }
1896 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001897 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001898 {
1899 // placeholder, so checkbox will not block child row toggle
1900 title: '',
1901 data: null,
1902 searchable: false,
1903 orderable: false,
1904 defaultContent: '',
1905 responsivePriority: 1
1906 },
1907 {
1908 title: '',
1909 data: 'chkbox',
1910 searchable: false,
1911 orderable: false,
1912 defaultContent: '',
1913 responsivePriority: 2
1914 },
1915 {
1916 title: 'ID',
1917 data: 'id',
1918 responsivePriority: 3,
1919 defaultContent: ''
1920 },
1921 {
1922 title: lang.alias,
1923 data: 'address',
1924 responsivePriority: 4,
1925 defaultContent: ''
1926 },
1927 {
1928 title: lang.target_address,
1929 data: 'goto',
1930 defaultContent: ''
1931 },
1932 {
1933 title: lang.domain,
1934 data: 'domain',
1935 defaultContent: '',
1936 responsivePriority: 5,
1937 },
1938 {
1939 title: lang.bcc_destinations,
1940 data: 'bcc_dest',
1941 defaultContent: ''
1942 },
1943 {
1944 title: lang.sogo_visible,
1945 data: 'sogo_visible',
1946 defaultContent: '',
1947 render: function(data, type){
1948 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>';
1949 }
1950 },
1951 {
1952 title: lang.public_comment,
1953 data: 'public_comment',
1954 defaultContent: ''
1955 },
1956 {
1957 title: lang.private_comment,
1958 data: 'private_comment',
1959 defaultContent: ''
1960 },
1961 {
1962 title: lang.active,
1963 data: 'active',
1964 defaultContent: '',
1965 responsivePriority: 6,
1966 render: function (data, type) {
1967 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>';
1968 }
1969 },
1970 {
1971 title: lang.action,
1972 data: 'action',
1973 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
1974 responsivePriority: 5,
1975 defaultContent: ''
1976 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001977 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001978 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001979
1980 table.on('responsive-resize', function (e, datatable, columns){
1981 hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
1982 });
1983
1984 table.on( 'draw', function (){
1985 $('#alias_table [data-bs-toggle="tooltip"]').tooltip();
1986 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001987 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001988 function draw_aliasdomain_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001989 // just recalc width if instance already exists
1990 if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
1991 $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
1992 return;
1993 }
1994
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001995 var table = $('#aliasdomain_table').DataTable({
1996 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001997 processing: true,
1998 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01001999 stateSave: true,
2000 pageLength: pagination_size,
2001 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
2002 "tr" +
2003 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002004 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002005 initComplete: function(){
2006 hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
2007 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002008 ajax: {
2009 type: "GET",
2010 url: "/api/v1/get/alias-domain/all",
2011 dataSrc: function(json){
2012 $.each(json, function (i, item) {
2013 item.alias_domain = escapeHtml(item.alias_domain);
2014
2015 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002016 '<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>' +
2017 '<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>' +
2018 '<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 +01002019 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002020 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 +01002021 if(item.parent_is_backupmx == '1') {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002022 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 +01002023 } else {
2024 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
2025 }
2026 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002027
2028 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002029 }
2030 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002031 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002032 {
2033 // placeholder, so checkbox will not block child row toggle
2034 title: '',
2035 data: null,
2036 searchable: false,
2037 orderable: false,
2038 defaultContent: '',
2039 responsivePriority: 1
2040 },
2041 {
2042 title: '',
2043 data: 'chkbox',
2044 searchable: false,
2045 orderable: false,
2046 defaultContent: '',
2047 responsivePriority: 2
2048 },
2049 {
2050 title: lang.alias,
2051 data: 'alias_domain',
2052 responsivePriority: 3,
2053 defaultContent: ''
2054 },
2055 {
2056 title: lang.target_domain,
2057 data: 'target_domain',
2058 responsivePriority: 4,
2059 defaultContent: ''
2060 },
2061 {
2062 title: lang.active,
2063 data: 'active',
2064 defaultContent: '',
2065 render: function (data, type) {
2066 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>';
2067 }
2068 },
2069 {
2070 title: lang.action,
2071 data: 'action',
2072 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
2073 responsivePriority: 5,
2074 defaultContent: ''
2075 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002076 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002077 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002078
2079 table.on('responsive-resize', function (e, datatable, columns){
2080 hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
2081 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002082 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002083 function draw_sync_job_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002084 // just recalc width if instance already exists
2085 if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
2086 $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
2087 return;
2088 }
2089
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002090 var table = $('#sync_job_table').DataTable({
2091 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002092 processing: true,
2093 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002094 stateSave: true,
2095 pageLength: pagination_size,
2096 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
2097 "tr" +
2098 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002099 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002100 order: [[2, 'desc']],
2101 initComplete: function(){
2102 hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
2103 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002104 ajax: {
2105 type: "GET",
2106 url: "/api/v1/get/syncjobs/all/no_log",
2107 dataSrc: function(json){
2108 $.each(json, function (i, item) {
2109 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 +01002110 item.user2 = escapeHtml(item.user2);
2111 if (!item.exclude > 0) {
2112 item.exclude = '-';
2113 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002114 item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002115 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002116 item.server_w_port = escapeHtml(item.user1) + '@' + escapeHtml(item.host1) + ':' + escapeHtml(item.port1);
2117 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002118 '<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>' +
2119 '<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 +01002120 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002121 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 +01002122 if (item.is_running == 1) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002123 item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002124 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002125 item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002126 }
2127 if (!item.last_run > 0) {
2128 item.last_run = lang.waiting;
2129 }
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01002130 if (item.success == null) {
2131 item.success = '-';
2132 item.exit_status = '';
2133 } else {
2134 item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
2135 }
2136 if (lang['syncjob_'+item.exit_status]) {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002137 item.exit_status = lang['syncjob_'+item.exit_status];
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01002138 } else if (item.success != '-') {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002139 item.exit_status = lang.syncjob_check_log;
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +01002140 }
2141 item.exit_status = item.success + ' ' + item.exit_status;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002142 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002143
2144 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002145 }
2146 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002147 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002148 {
2149 // placeholder, so checkbox will not block child row toggle
2150 title: '',
2151 data: null,
2152 searchable: false,
2153 orderable: false,
2154 defaultContent: '',
2155 responsivePriority: 1
2156 },
2157 {
2158 title: '',
2159 data: 'chkbox',
2160 searchable: false,
2161 orderable: false,
2162 defaultContent: '',
2163 responsivePriority: 2
2164 },
2165 {
2166 title: 'ID',
2167 data: 'id',
2168 responsivePriority: 3,
2169 defaultContent: ''
2170 },
2171 {
2172 title: lang.owner,
2173 data: 'user2',
2174 responsivePriority: 4,
2175 defaultContent: ''
2176 },
2177 {
2178 title: 'Server',
2179 data: 'server_w_port',
2180 defaultContent: ''
2181 },
2182 {
2183 title: lang.last_run,
2184 data: 'last_run',
2185 defaultContent: ''
2186 },
2187 {
2188 title: lang.syncjob_last_run_result,
2189 data: 'exit_status',
2190 defaultContent: ''
2191 },
2192 {
2193 title: 'Log',
2194 data: 'log',
2195 defaultContent: ''
2196 },
2197 {
2198 title: lang.active,
2199 data: 'active',
2200 defaultContent: '',
2201 render: function (data, type) {
2202 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>';
2203 }
2204 },
2205 {
2206 title: lang.status,
2207 data: 'is_running',
2208 defaultContent: ''
2209 },
2210 {
2211 title: lang.excludes,
2212 data: 'exclude',
2213 defaultContent: '',
2214 className: 'none'
2215 },
2216 {
2217 title: lang.mins_interval,
2218 data: 'mins_interval',
2219 defaultContent: '',
2220 className: 'none'
2221 },
2222 {
2223 title: lang.action,
2224 data: 'action',
2225 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
2226 responsivePriority: 5,
2227 defaultContent: ''
2228 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002229 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002230 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002231
2232 table.on('responsive-resize', function (e, datatable, columns){
2233 hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
2234 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002235 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002236 function draw_filter_table() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002237 // just recalc width if instance already exists
2238 if ($.fn.DataTable.isDataTable('#filter_table') ) {
2239 $('#filter_table').DataTable().columns.adjust().responsive.recalc();
2240 return;
2241 }
2242
2243 var table = $('#filter_table').DataTable({
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002244 responsive: true,
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002245 autoWidth: false,
2246 processing: true,
2247 serverSide: false,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002248 stateSave: true,
2249 pageLength: pagination_size,
2250 dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
2251 "tr" +
2252 "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002253 language: lang_datatables,
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002254 order: [[2, 'desc']],
2255 initComplete: function(){
2256 hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
2257 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002258 ajax: {
2259 type: "GET",
2260 url: "/api/v1/get/filters/all",
2261 dataSrc: function(json){
2262 $.each(json, function (i, item) {
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002263 if (item.active == 1) {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002264 item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002265 } else {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002266 item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002267 }
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002268 item.script_desc = escapeHtml(item.script_desc);
2269 item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
2270 item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
2271 item.action = '<div class="btn-group">' +
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002272 '<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>' +
2273 '<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 +01002274 '</div>';
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002275 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 +01002276 });
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002277
2278 return json;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002279 }
2280 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002281 columns: [
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002282 {
2283 // placeholder, so checkbox will not block child row toggle
2284 title: '',
2285 data: null,
2286 searchable: false,
2287 orderable: false,
2288 defaultContent: '',
2289 responsivePriority: 1
2290 },
2291 {
2292 title: '',
2293 data: 'chkbox',
2294 searchable: false,
2295 orderable: false,
2296 defaultContent: '',
2297 responsivePriority: 2
2298 },
2299 {
2300 title: 'ID',
2301 data: 'id',
2302 responsivePriority: 2,
2303 defaultContent: ''
2304 },
2305 {
2306 title: lang.active,
2307 data: 'active',
2308 responsivePriority: 3,
2309 defaultContent: ''
2310 },
2311 {
2312 title: 'Type',
2313 data: 'filter_type',
2314 responsivePriority: 4,
2315 defaultContent: ''
2316 },
2317 {
2318 title: lang.owner,
2319 data: 'username',
2320 defaultContent: ''
2321 },
2322 {
2323 title: lang.description,
2324 data: 'script_desc',
2325 defaultContent: ''
2326 },
2327 {
2328 title: 'Script',
2329 data: 'script_data',
2330 defaultContent: '',
2331 className: 'none'
2332 },
2333 {
2334 title: lang.action,
2335 data: 'action',
2336 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
2337 responsivePriority: 5,
2338 defaultContent: ''
2339 },
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002340 ]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002341 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002342
2343 table.on('responsive-resize', function (e, datatable, columns){
2344 hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
2345 });
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002346 };
2347
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002348 function hideTableExpandCollapseBtn(tab, table){
2349 if ($(table).hasClass('collapsed'))
2350 $(tab).find(".table_collapse_option").show();
2351 else
2352 $(tab).find(".table_collapse_option").hide();
2353 }
2354
2355 function filterByDomain(json, column, table){
2356 var tableId = $(table.table().container()).attr('id');
2357 // Create the `select` element
2358 var select = $('<select class="btn btn-sm btn-xs-lg btn-light text-start mx-2"><option value="">'+lang.all_domains+'</option></select>')
2359 .insertBefore(
2360 $('#'+tableId+' .dataTables_filter > label > input')
2361 )
2362 .on( 'change', function(){
2363 table.column(column)
2364 .search($(this).val())
2365 .draw();
2366 });
2367
2368 // get all domains
2369 var domains = [];
2370 json.forEach(obj => {
2371 Object.entries(obj).forEach(([key, value]) => {
2372 if(key === 'domain') {
2373 domains.push(value)
2374 }
2375 });
2376 });
2377
2378 // get unique domain list
2379 domains = domains.filter(function(value, index, array) {
2380 return array.indexOf(value) === index;
2381 });
2382
2383 // add domains to select
2384 domains.forEach(function(domain) {
2385 select.append($('<option>' + domain + '</option>'));
2386 });
2387 }
2388
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002389 // detect element visibility changes
2390 function onVisible(element, callback) {
2391 $(document).ready(function() {
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002392 let element_object = document.querySelector(element);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002393 if (element_object === null) return;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002394
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002395 let observer = new IntersectionObserver((entries, observer) => {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002396 entries.forEach(entry => {
2397 if(entry.intersectionRatio > 0) {
2398 callback(element_object);
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002399 observer.unobserve(element_object);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002400 }
2401 });
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +01002402 })
2403
2404 observer.observe(element_object);
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002405 });
2406 }
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002407
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01002408 // Load only if the tab is visible
2409 onVisible("[id^=domain_table]", () => draw_domain_table());
2410 onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table());
2411 onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
2412 onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table());
2413 onVisible("[id^=resource_table]", () => draw_resource_table());
2414 onVisible("[id^=alias_table]", () => draw_alias_table());
2415 onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
2416 onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
2417 onVisible("[id^=filter_table]", () => draw_filter_table());
2418 onVisible("[id^=bcc_table]", () => draw_bcc_table());
2419 onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
2420 onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01002421});