blob: 12c4bb4d720641e65499f0966b2907b0f7d2f393 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001$(document).ready(function() {
2 acl_data = JSON.parse(acl);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01003 // Set paging
Matthias Andreas Benkardb382b102021-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 Benkard7b2a3a12021-08-16 10:57:25 +020028 $('#addSelectDomain').on('change', function() {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010029 auto_fill_quota($('#addSelectDomain').val());
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020030 });
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010031 auto_fill_quota($('#addSelectDomain').val());
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010032
Matthias Andreas Benkardb382b102021-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 Benkardb382b102021-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 Benkard1ba53812022-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 Benkardb382b102021-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 Benkard1ba53812022-12-27 17:32:58 +010080 });
81 // @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){
88 $('#domain_templates').find('option').remove();
89 $('#domain_templates').selectpicker('destroy');
90 $('#domain_templates').selectpicker();
91 for (var i = 0; i < data.length; i++){
92 if (data[i].template === "Default"){
93 $('#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
98 }));
99 setDomainTemplateData(data[i].attributes);
100 } else {
101 $('#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
106 }));
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){
130 $('#mailbox_templates').find('option').remove();
131 $('#mailbox_templates').selectpicker('destroy');
132 $('#mailbox_templates').selectpicker();
133 for (var i = 0; i < data.length; i++){
134 if (data[i].template === "Default"){
135 $('#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
140 }));
141 setMailboxTemplateData(data[i].attributes);
142 } else {
143 $('#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
148 }));
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 Benkardb382b102021-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 Benkard7b2a3a12021-08-16 10:57:25 +0200171 $('.textarea-code').on('keyup', function() {
Matthias Andreas Benkardb382b102021-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 Benkard7b2a3a12021-08-16 10:57:25 +0200174 });
Matthias Andreas Benkardb382b102021-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 Benkard1ba53812022-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 Benkardb382b102021-01-02 15:32:21 +0100226
Matthias Andreas Benkard1ba53812022-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 }
232
233 if (template.active == 1){
234 $('#addDomain_active').prop('checked', true);
235 } else {
236 $('#addDomain_active').prop('checked', false);
237 }
238
239 $("#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());
245
246 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
262
263 // 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 }
407
408 // 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 Benkardb382b102021-01-02 15:32:21 +0100415});
416jQuery(function($){
Matthias Andreas Benkardb382b102021-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 Benkard1ba53812022-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"})}
420
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100421 $(".refresh_table").on('click', function(e) {
422 e.preventDefault();
423 var table_name = $(this).data('table');
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100424
425 if ($.fn.DataTable.isDataTable('#' + table_name))
426 $('#' + table_name).DataTable().ajax.reload();
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100427 });
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100428 function draw_domain_table() {
Matthias Andreas Benkard1ba53812022-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({
436 processing: true,
437 serverSide: false,
438 language: lang_datatables,
439 ajax: {
440 type: "GET",
441 url: "/api/v1/get/domain/all",
442 dataSrc: function(json){
443 $.each(json, function(i, item) {
444 item.domain_name = escapeHtml(item.domain_name);
445
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100446 item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
447 item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
448 item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
449 item.stats = item.msgs_total + "/" + item.bytes_total;
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100450
451 if (!item.rl) item.rl = '∞';
452 else {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100453 item.rl = $.map(item.rl, function(e){
454 return e;
455 }).join('/1');
456 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100457
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100458 item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
459 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
460 item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100461 item.action = '<div class="btn-group">';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100462 if (role == "admin") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100463 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
464 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
465 '<a href="#dnsInfoModal" class="btn btn-sm btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100466 }
467 else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100468 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
469 '<a href="#dnsInfoModal" class="btn btn-xs btn-xs-half btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
470 }
471
472 if (Array.isArray(item.tags)){
473 var tags = '';
474 for (var i = 0; i < item.tags.length; i++)
475 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
476 item.tags = tags;
477 } else {
478 item.tags = '';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100479 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200480
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100481 if (item.backupmx == 1) {
482 if (item.relay_unknown_only == 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100483 item.domain_name = '<div class="badge fs-6 bg-info">Relay Non-Local</div> ' + item.domain_name;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100484 } else if (item.relay_all_recipients == 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100485 item.domain_name = '<div class="badge fs-6 bg-info">Relay All</div> ' + item.domain_name;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100486 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100487 item.domain_name = '<div class="badge fs-6 bg-info">Relay</div> ' + item.domain_name;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100488 }
489 }
490 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100491
492 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100493 }
494 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100495 columns: [
496 {
497 // placeholder, so checkbox will not block child row toggle
498 title: '',
499 data: null,
500 searchable: false,
501 orderable: false,
502 defaultContent: '',
503 responsivePriority: 1
504 },
505 {
506 title: '',
507 data: 'chkbox',
508 searchable: false,
509 orderable: false,
510 defaultContent: '',
511 responsivePriority: 2
512 },
513 {
514 title: lang.domain,
515 data: 'domain_name',
516 responsivePriority: 3,
517 defaultContent: ''
518 },
519 {
520 title: lang.aliases,
521 data: 'aliases',
522 defaultContent: ''
523 },
524 {
525 title: lang.mailboxes,
526 data: 'mailboxes',
527 responsivePriority: 4,
528 defaultContent: ''
529 },
530 {
531 title: lang.domain_quota,
532 data: 'quota',
533 defaultContent: '',
534 render: function (data, type) {
535 data = data.split("/");
536 return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
537 }
538 },
539 {
540 title: lang.stats,
541 data: 'stats',
542 defaultContent: '',
543 render: function (data, type) {
544 data = data.split("/");
545 return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
546 }
547 },
548 {
549 title: lang.mailbox_defquota,
550 data: 'def_quota_for_mbox',
551 defaultContent: ''
552 },
553 {
554 title: lang.mailbox_quota,
555 data: 'max_quota_for_mbox',
556 defaultContent: ''
557 },
558 {
559 title: 'RL',
560 data: 'rl',
561 defaultContent: ''
562 },
563 {
564 title: lang.backup_mx,
565 data: 'backupmx',
566 defaultContent: '',
567 redner: function (data, type){
568 return 1==value ? '<i class="bi bi-check-lg"></i>' : 0==value && '<i class="bi bi-x-lg"></i>';
569 }
570 },
571 {
572 title: lang.domain_admins,
573 data: 'domain_admins',
574 defaultContent: '',
575 className: 'none'
576 },
577 {
578 title: lang.created_on,
579 data: 'created',
580 defaultContent: '',
581 className: 'none'
582 },
583 {
584 title: lang.last_modified,
585 data: 'modified',
586 defaultContent: '',
587 className: 'none'
588 },
589 {
590 title: 'Tags',
591 data: 'tags',
592 defaultContent: '',
593 className: 'none'
594 },
595 {
596 title: lang.active,
597 data: 'active',
598 defaultContent: '',
599 responsivePriority: 6,
600 render: function (data, type) {
601 return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
602 }
603 },
604 {
605 title: lang.action,
606 data: 'action',
607 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
608 responsivePriority: 5,
609 defaultContent: ''
610 },
611 ]
612 });
613 }
614 function draw_templates_domain_table() {
615 // just recalc width if instance already exists
616 if ($.fn.DataTable.isDataTable('#templates_domain_table') ) {
617 $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc();
618 return;
619 }
620
621 $('#templates_domain_table').DataTable({
622 responsive : true,
623 processing: true,
624 serverSide: false,
625 language: lang_datatables,
626 ajax: {
627 type: "GET",
628 url: "/api/v1/get/domain/template/all",
629 dataSrc: function(json){
630 $.each(json, function (i, item) {
631 item.chkbox = '<input type="checkbox" data-id="domain_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
632
633 item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox);
634 item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox);
635 item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain);
636
637 item.template = escapeHtml(item.template);
638 if (item.attributes.rl_frame === "s"){
639 item.attributes.rl_frame = lang_rl.second;
640 } else if (item.attributes.rl_frame === "m"){
641 item.attributes.rl_frame = lang_rl.minute;
642 } else if (item.attributes.rl_frame === "h"){
643 item.attributes.rl_frame = lang_rl.hour;
644 } else if (item.attributes.rl_frame === "d"){
645 item.attributes.rl_frame = lang_rl.day;
646 }
647 item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
648
649
650 if (item.template.toLowerCase() == "default"){
651 item.action = '<div class="btn-group">' +
652 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
653 '</div>';
654 }
655 else{
656 item.action = '<div class="btn-group">' +
657 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
658 '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/domain/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
659 '</div>';
660 }
661
662 if (Array.isArray(item.attributes.tags)){
663 var tags = '';
664 for (var i = 0; i < item.attributes.tags.length; i++)
665 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
666 item.attributes.tags = tags;
667 } else {
668 item.attributes.tags = '';
669 }
670 });
671
672 return json;
673 }
674 },
675 columns: [
676 {
677 // placeholder, so checkbox will not block child row toggle
678 title: '',
679 data: null,
680 searchable: false,
681 orderable: false,
682 defaultContent: '',
683 responsivePriority: 1
684 },
685 {
686 title: '',
687 data: 'chkbox',
688 searchable: false,
689 orderable: false,
690 defaultContent: '',
691 responsivePriority: 1
692 },
693 {
694 title: "ID",
695 data: 'id',
696 responsivePriority: 2,
697 defaultContent: ''
698 },
699 {
700 title: lang.template,
701 data: 'template',
702 responsivePriority: 3,
703 defaultContent: ''
704 },
705 {
706 title: lang.max_aliases,
707 data: 'attributes.max_num_aliases_for_domain',
708 defaultContent: '',
709 },
710 {
711 title: lang.max_mailboxes,
712 data: 'attributes.max_num_mboxes_for_domain',
713 defaultContent: '',
714 },
715 {
716 title: lang.mailbox_defquota,
717 data: 'attributes.def_quota_for_mbox',
718 defaultContent: '',
719 },
720 {
721 title: lang.max_quota,
722 data: 'attributes.max_quota_for_mbox',
723 defaultContent: '',
724 },
725 {
726 title: lang.domain_quota_total,
727 data: 'attributes.max_quota_for_domain',
728 defaultContent: '',
729 },
730 {
731 title: lang.gal,
732 data: 'attributes.gal',
733 defaultContent: '',
734 render: function (data, type) {
735 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
736 }
737 },
738 {
739 title: lang.backup_mx,
740 data: 'attributes.backupmx',
741 defaultContent: '',
742 render: function (data, type) {
743 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
744 }
745 },
746 {
747 title: lang.relay_all,
748 data: 'attributes.relay_all_recipients',
749 defaultContent: '',
750 render: function (data, type) {
751 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
752 }
753 },
754 {
755 title: lang.relay_unknown,
756 data: 'attributes.relay_unknown_only',
757 defaultContent: '',
758 render: function (data, type) {
759 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
760 }
761 },
762 {
763 title: lang.active,
764 data: 'attributes.active',
765 defaultContent: '',
766 responsivePriority: 4,
767 render: function (data, type) {
768 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
769 }
770 },
771 {
772 title: 'rl_frame',
773 data: 'attributes.rl_frame',
774 defaultContent: '',
775 class: 'none',
776 },
777 {
778 title: 'rl_value',
779 data: 'attributes.rl_value',
780 defaultContent: '',
781 class: 'none',
782 },
783 {
784 title: lang.dkim_domains_selector,
785 data: 'attributes.dkim_selector',
786 defaultContent: '',
787 class: 'none',
788 },
789 {
790 title: lang.dkim_key_length,
791 data: 'attributes.key_size',
792 defaultContent: '',
793 class: 'none',
794 },
795 {
796 title: 'Tags',
797 data: 'attributes.tags',
798 defaultContent: '',
799 className: 'none'
800 },
801 {
802 title: lang.action,
803 data: 'action',
804 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
805 responsivePriority: 6,
806 defaultContent: ''
807 },
808 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100809 });
810 }
811 function draw_mailbox_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100812 // just recalc width if instance already exists
813 if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
814 $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
815 return;
816 }
817
818 $('#mailbox_table').DataTable({
819 responsive : true,
820 processing: true,
821 serverSide: false,
822 language: lang_datatables,
823 ajax: {
824 type: "GET",
825 url: "/api/v1/get/mailbox/reduced",
826 dataSrc: function(json){
827 $.each(json, function (i, item) {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100828 item.quota = item.quota_used + "/" + item.quota;
829 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
830 item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200831 /*
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100832 if (!item.rl) {
833 item.rl = '∞';
834 } else {
835 item.rl = $.map(item.rl, function(e){
836 return e;
837 }).join('/1');
838 if (item.rl_scope === 'domain') {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200839 item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100840 }
841 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200842 */
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100843 item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200844 if (item.attributes.passwd_update != '0') {
845 var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
846 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"});
847 } else {
848 item.last_pw_change = '-';
849 }
850 item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
851 item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
852 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>';
853 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>';
854 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>';
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100855 item.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100856 if (item.attributes.quarantine_notification === 'never') {
857 item.quarantine_notification = lang.never;
858 } else if (item.attributes.quarantine_notification === 'hourly') {
859 item.quarantine_notification = lang.hourly;
860 } else if (item.attributes.quarantine_notification === 'daily') {
861 item.quarantine_notification = lang.daily;
862 } else if (item.attributes.quarantine_notification === 'weekly') {
863 item.quarantine_notification = lang.weekly;
864 }
865 if (item.attributes.quarantine_category === 'reject') {
866 item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
867 } else if (item.attributes.quarantine_category === 'add_header') {
868 item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
869 } else if (item.attributes.quarantine_category === 'all') {
870 item.quarantine_category = lang.q_all;
871 }
872 if (acl_data.login_as === 1) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200873
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100874 item.action = '<div class="btn-group">' +
875 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
876 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
877 '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-half btn-success"><i class="bi bi-person-fill"></i> Login</a>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100878 if (ALLOW_ADMIN_EMAIL_LOGIN) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100879 item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-half btn-primary" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100880 }
881 item.action += '</div>';
882 }
883 else {
884 item.action = '<div class="btn-group">' +
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100885 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200886 '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100887 '</div>';
888 }
889 item.in_use = '<div class="progress">' +
890 '<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" ' +
891 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
892 item.username = escapeHtml(item.username);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100893
894 if (Array.isArray(item.tags)){
895 var tags = '';
896 for (var i = 0; i < item.tags.length; i++)
897 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
898 item.tags = tags;
899 } else {
900 item.tags = '';
901 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100902 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100903
904 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100905 }
906 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +0100907 columns: [
908 {
909 // placeholder, so checkbox will not block child row toggle
910 title: '',
911 data: null,
912 searchable: false,
913 orderable: false,
914 defaultContent: '',
915 responsivePriority: 1
916 },
917 {
918 title: '',
919 data: 'chkbox',
920 searchable: false,
921 orderable: false,
922 defaultContent: '',
923 responsivePriority: 2
924 },
925 {
926 title: lang.username,
927 data: 'username',
928 responsivePriority: 3,
929 defaultContent: ''
930 },
931 {
932 title: lang.domain_quota,
933 data: 'quota',
934 responsivePriority: 8,
935 defaultContent: '',
936 render: function (data, type) {
937 data = data.split("/");
938 var of_q = (data[1] == 0 ? "∞" : humanFileSize(data[1]));
939 return humanFileSize(data[0]) + " / " + of_q;
940 }
941 },
942 {
943 title: lang.last_mail_login,
944 data: 'last_mail_login',
945 defaultContent: '',
946 responsivePriority: 7,
947 render: function (data, type) {
948 res = data.split("/");
949 return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
950 '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
951 '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
952 }
953 },
954 {
955 title: lang.last_pw_change,
956 data: 'last_pw_change',
957 defaultContent: ''
958 },
959 {
960 title: lang.in_use,
961 data: 'in_use',
962 defaultContent: '',
963 responsivePriority: 9,
964 className: 'dt-data-w100'
965 },
966 {
967 title: lang.fname,
968 data: 'name',
969 defaultContent: '',
970 className: 'none'
971 },
972 {
973 title: lang.domain,
974 data: 'domain',
975 defaultContent: '',
976 className: 'none'
977 },
978 {
979 title: lang.tls_enforce_in,
980 data: 'tls_enforce_in',
981 defaultContent: '',
982 className: 'none'
983 },
984 {
985 title: lang.tls_enforce_out,
986 data: 'tls_enforce_out',
987 defaultContent: '',
988 className: 'none'
989 },
990 {
991 title: 'SMTP',
992 data: 'smtp_access',
993 defaultContent: '',
994 className: 'none'
995 },
996 {
997 title: 'IMAP',
998 data: 'imap_access',
999 defaultContent: '',
1000 className: 'none'
1001 },
1002 {
1003 title: 'POP3',
1004 data: 'pop3_access',
1005 defaultContent: '',
1006 className: 'none'
1007 },
1008 {
1009 title: 'SIEVE',
1010 data: 'sieve_access',
1011 defaultContent: '',
1012 className: 'none'
1013 },
1014 {
1015 title: lang.quarantine_notification,
1016 data: 'quarantine_notification',
1017 defaultContent: '',
1018 className: 'none'
1019 },
1020 {
1021 title: lang.quarantine_category,
1022 data: 'quarantine_category',
1023 defaultContent: '',
1024 className: 'none'
1025 },
1026 {
1027 title: lang.msg_num,
1028 data: 'messages',
1029 defaultContent: '',
1030 responsivePriority: 5
1031 },
1032 {
1033 title: lang.created_on,
1034 data: 'created',
1035 defaultContent: '',
1036 className: 'none'
1037 },
1038 {
1039 title: lang.last_modified,
1040 data: 'modified',
1041 defaultContent: '',
1042 className: 'none'
1043 },
1044 {
1045 title: 'Tags',
1046 data: 'tags',
1047 defaultContent: '',
1048 className: 'none'
1049 },
1050 {
1051 title: lang.active,
1052 data: 'active',
1053 defaultContent: '',
1054 responsivePriority: 4,
1055 render: function (data, type) {
1056 return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
1057 }
1058 },
1059 {
1060 title: lang.action,
1061 data: 'action',
1062 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
1063 responsivePriority: 6,
1064 defaultContent: ''
1065 },
1066 ]
1067 });
1068 }
1069 function draw_templates_mbox_table() {
1070 // just recalc width if instance already exists
1071 if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) {
1072 $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc();
1073 return;
1074 }
1075
1076 $('#templates_mbox_table').DataTable({
1077 responsive : true,
1078 processing: true,
1079 serverSide: false,
1080 language: lang_datatables,
1081 ajax: {
1082 type: "GET",
1083 url: "/api/v1/get/mailbox/template/all",
1084 dataSrc: function(json){
1085 $.each(json, function (i, item) {
1086 item.chkbox = '<input type="checkbox" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
1087
1088 item.template = escapeHtml(item.template);
1089 if (item.attributes.rl_frame === "s"){
1090 item.attributes.rl_frame = lang_rl.second;
1091 } else if (item.attributes.rl_frame === "m"){
1092 item.attributes.rl_frame = lang_rl.minute;
1093 } else if (item.attributes.rl_frame === "h"){
1094 item.attributes.rl_frame = lang_rl.hour;
1095 } else if (item.attributes.rl_frame === "d"){
1096 item.attributes.rl_frame = lang_rl.day;
1097 }
1098 item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
1099
1100 item.attributes.quota = humanFileSize(item.attributes.quota);
1101
1102 item.attributes.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
1103 item.attributes.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
1104 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') + '"></i>';
1105 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') + '"></i>';
1106 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') + '"></i>';
1107 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') + '"></i>';
1108 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') + '"></i>';
1109 if (item.attributes.quarantine_notification === 'never') {
1110 item.attributes.quarantine_notification = lang.never;
1111 } else if (item.attributes.quarantine_notification === 'hourly') {
1112 item.attributes.quarantine_notification = lang.hourly;
1113 } else if (item.attributes.quarantine_notification === 'daily') {
1114 item.attributes.quarantine_notification = lang.daily;
1115 } else if (item.attributes.quarantine_notification === 'weekly') {
1116 item.attributes.quarantine_notification = lang.weekly;
1117 }
1118 if (item.attributes.quarantine_category === 'reject') {
1119 item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
1120 } else if (item.attributes.quarantine_category === 'add_header') {
1121 item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
1122 } else if (item.attributes.quarantine_category === 'all') {
1123 item.attributes.quarantine_category = lang.q_all;
1124 }
1125
1126
1127 if (item.template.toLowerCase() == "default"){
1128 item.action = '<div class="btn-group">' +
1129 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1130 '</div>';
1131 }
1132 else {
1133 item.action = '<div class="btn-group">' +
1134 '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1135 '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/mailbox/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
1136 '</div>';
1137 }
1138
1139 if (Array.isArray(item.attributes.tags)){
1140 var tags = '';
1141 for (var i = 0; i < item.attributes.tags.length; i++)
1142 tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
1143 item.attributes.tags = tags;
1144 } else {
1145 item.attributes.tags = '';
1146 }
1147 });
1148
1149 return json;
1150 }
1151 },
1152 columns: [
1153 {
1154 // placeholder, so checkbox will not block child row toggle
1155 title: '',
1156 data: null,
1157 searchable: false,
1158 orderable: false,
1159 defaultContent: '',
1160 responsivePriority: 1
1161 },
1162 {
1163 title: '',
1164 data: 'chkbox',
1165 searchable: false,
1166 orderable: false,
1167 defaultContent: '',
1168 responsivePriority: 1
1169 },
1170 {
1171 title: "ID",
1172 data: 'id',
1173 responsivePriority: 2,
1174 defaultContent: ''
1175 },
1176 {
1177 title: lang.template,
1178 data: 'template',
1179 responsivePriority: 3,
1180 defaultContent: ''
1181 },
1182 {
1183 title: lang.domain_quota,
1184 data: 'attributes.quota',
1185 defaultContent: '',
1186 },
1187 {
1188 title: lang.tls_enforce_in,
1189 data: 'attributes.tls_enforce_in',
1190 defaultContent: ''
1191 },
1192 {
1193 title: lang.tls_enforce_out,
1194 data: 'attributes.tls_enforce_out',
1195 defaultContent: ''
1196 },
1197 {
1198 title: 'SMTP',
1199 data: 'attributes.smtp_access',
1200 defaultContent: '',
1201 },
1202 {
1203 title: 'IMAP',
1204 data: 'attributes.imap_access',
1205 defaultContent: '',
1206 },
1207 {
1208 title: 'POP3',
1209 data: 'attributes.pop3_access',
1210 defaultContent: '',
1211 },
1212 {
1213 title: 'SIEVE',
1214 data: 'attributes.sieve_access',
1215 defaultContent: '',
1216 },
1217 {
1218 title: 'SOGO',
1219 data: 'attributes.sogo_access',
1220 defaultContent: '',
1221 },
1222 {
1223 title: lang.quarantine_notification,
1224 data: 'attributes.quarantine_notification',
1225 defaultContent: '',
1226 className: 'none'
1227 },
1228 {
1229 title: lang.quarantine_category,
1230 data: 'attributes.quarantine_category',
1231 defaultContent: '',
1232 className: 'none'
1233 },
1234 {
1235 title: lang.force_pw_update,
1236 data: 'attributes.force_pw_update',
1237 defaultContent: '',
1238 class: 'none',
1239 render: function (data, type) {
1240 return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
1241 }
1242 },
1243 {
1244 title: "rl_frame",
1245 data: 'attributes.rl_frame',
1246 defaultContent: '',
1247 class: 'none',
1248 },
1249 {
1250 title: 'rl_value',
1251 data: 'attributes.rl_value',
1252 defaultContent: '',
1253 class: 'none',
1254 },
1255 {
1256 title: 'Tags',
1257 data: 'attributes.tags',
1258 defaultContent: '',
1259 className: 'none'
1260 },
1261 {
1262 title: lang.active,
1263 data: 'attributes.active',
1264 defaultContent: '',
1265 responsivePriority: 4,
1266 render: function (data, type) {
1267 return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
1268 }
1269 },
1270 {
1271 title: lang.action,
1272 data: 'action',
1273 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
1274 responsivePriority: 6,
1275 defaultContent: ''
1276 },
1277 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001278 });
1279 }
1280 function draw_resource_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001281 // just recalc width if instance already exists
1282 if ($.fn.DataTable.isDataTable('#resource_table') ) {
1283 $('#resource_table').DataTable().columns.adjust().responsive.recalc();
1284 return;
1285 }
1286
1287 $('#resource_table').DataTable({
1288 processing: true,
1289 serverSide: false,
1290 language: lang_datatables,
1291 ajax: {
1292 type: "GET",
1293 url: "/api/v1/get/resource/all",
1294 dataSrc: function(json){
1295 $.each(json, function (i, item) {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001296 if (item.multiple_bookings == '0') {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001297 item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001298 } else if (item.multiple_bookings == '-1') {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001299 item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001300 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001301 item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001302 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001303 item.action = '<div class="btn-group">' +
1304 '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1305 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001306 '</div>';
1307 item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
1308 item.name = escapeHtml(item.name);
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001309 item.description = escapeHtml(item.description);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001310 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001311
1312 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001313 }
1314 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001315 columns: [
1316 {
1317 // placeholder, so checkbox will not block child row toggle
1318 title: '',
1319 data: null,
1320 searchable: false,
1321 orderable: false,
1322 defaultContent: '',
1323 responsivePriority: 1
1324 },
1325 {
1326 title: '',
1327 data: 'chkbox',
1328 searchable: false,
1329 orderable: false,
1330 defaultContent: '',
1331 responsivePriority: 2
1332 },
1333 {
1334 title: lang.description,
1335 data: 'description',
1336 responsivePriority: 3,
1337 defaultContent: ''
1338 },
1339 {
1340 title: lang.alias,
1341 data: 'name',
1342 defaultContent: ''
1343 },
1344 {
1345 title: lang.kind,
1346 data: 'kind',
1347 defaultContent: ''
1348 },
1349 {
1350 title: lang.domain,
1351 data: 'domain',
1352 responsivePriority: 4,
1353 defaultContent: ''
1354 },
1355 {
1356 title: lang.multiple_bookings,
1357 data: 'multiple_bookings',
1358 defaultContent: ''
1359 },
1360 {
1361 title: lang.active,
1362 data: 'active',
1363 defaultContent: '',
1364 render: function (data, type) {
1365 return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
1366 }
1367 },
1368 {
1369 title: lang.action,
1370 data: 'action',
1371 responsivePriority: 5,
1372 defaultContent: '',
1373 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right'
1374 },
1375 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001376 });
1377 }
1378 function draw_bcc_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001379 $.get("/api/v1/get/bcc-destination-options", function(data){
1380 // Domains
1381 var optgroup = "<optgroup label='" + lang.domains + "'>";
1382 $.each(data.domains, function(index, domain){
1383 optgroup += "<option value='" + domain + "'>" + domain + "</option>"
1384 });
1385 optgroup += "</optgroup>"
1386 $('#bcc-local-dest').append(optgroup);
1387 // Alias domains
1388 var optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
1389 $.each(data.alias_domains, function(index, alias_domain){
1390 optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>"
1391 });
1392 optgroup += "</optgroup>"
1393 $('#bcc-local-dest').append(optgroup);
1394 // Mailboxes and aliases
1395 $.each(data.mailboxes, function(mailbox, aliases){
1396 var optgroup = "<optgroup label='" + mailbox + "'>";
1397 $.each(aliases, function(index, alias){
1398 optgroup += "<option value='" + alias + "'>" + alias + "</option>"
1399 });
1400 optgroup += "</optgroup>"
1401 $('#bcc-local-dest').append(optgroup);
1402 });
1403 // Finish
1404 $('#bcc-local-dest').selectpicker('refresh');
1405 });
1406
1407 // just recalc width if instance already exists
1408 if ($.fn.DataTable.isDataTable('#bcc_table') ) {
1409 $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
1410 return;
1411 }
1412
1413 $('#bcc_table').DataTable({
1414 processing: true,
1415 serverSide: false,
1416 language: lang_datatables,
1417 ajax: {
1418 type: "GET",
1419 url: "/api/v1/get/bcc/all",
1420 dataSrc: function(json){
1421 $.each(json, function (i, item) {
1422 item.action = '<div class="btn-group">' +
1423 '<a href="/edit/bcc/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1424 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001425 '</div>';
1426 item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
1427 item.local_dest = escapeHtml(item.local_dest);
1428 item.bcc_dest = escapeHtml(item.bcc_dest);
1429 if (item.type == 'sender') {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001430 item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001431 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001432 item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001433 }
1434 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001435
1436 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001437 }
1438 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001439 columns: [
1440 {
1441 // placeholder, so checkbox will not block child row toggle
1442 title: '',
1443 data: null,
1444 searchable: false,
1445 orderable: false,
1446 defaultContent: '',
1447 responsivePriority: 1
1448 },
1449 {
1450 title: '',
1451 data: 'chkbox',
1452 searchable: false,
1453 orderable: false,
1454 defaultContent: '',
1455 responsivePriority: 2
1456 },
1457 {
1458 title: 'ID',
1459 data: 'id',
1460 responsivePriority: 3,
1461 defaultContent: ''
1462 },
1463 {
1464 title: lang.bcc_type,
1465 data: 'type',
1466 defaultContent: ''
1467 },
1468 {
1469 title: lang.bcc_local_dest,
1470 data: 'local_dest',
1471 defaultContent: ''
1472 },
1473 {
1474 title: lang.bcc_destinations,
1475 data: 'bcc_dest',
1476 defaultContent: ''
1477 },
1478 {
1479 title: lang.domain,
1480 data: 'domain',
1481 responsivePriority: 4,
1482 defaultContent: ''
1483 },
1484 {
1485 title: lang.active,
1486 data: 'active',
1487 defaultContent: '',
1488 render: function (data, type) {
1489 return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
1490 }
1491 },
1492 {
1493 title: lang.action,
1494 data: 'action',
1495 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
1496 responsivePriority: 5,
1497 defaultContent: ''
1498 },
1499 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001500 });
1501 }
1502 function draw_recipient_map_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001503 // just recalc width if instance already exists
1504 if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
1505 $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
1506 return;
1507 }
1508
1509 $('#recipient_map_table').DataTable({
1510 processing: true,
1511 serverSide: false,
1512 language: lang_datatables,
1513 ajax: {
1514 type: "GET",
1515 url: "/api/v1/get/recipient_map/all",
1516 dataSrc: function(json){
1517 if (role !== "admin") return null;
1518
1519 $.each(json, function (i, item) {
1520 item.recipient_map_old = escapeHtml(item.recipient_map_old);
1521 item.recipient_map_new = escapeHtml(item.recipient_map_new);
1522 item.action = '<div class="btn-group">' +
1523 '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1524 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
1525 '</div>';
1526 item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
1527 });
1528
1529 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001530 }
1531 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001532 columns: [
1533 {
1534 // placeholder, so checkbox will not block child row toggle
1535 title: '',
1536 data: null,
1537 searchable: false,
1538 orderable: false,
1539 defaultContent: '',
1540 responsivePriority: 1
1541 },
1542 {
1543 title: '',
1544 data: 'chkbox',
1545 searchable: false,
1546 orderable: false,
1547 defaultContent: '',
1548 responsivePriority: 2
1549 },
1550 {
1551 title: 'ID',
1552 data: 'id',
1553 responsivePriority: 3,
1554 defaultContent: ''
1555 },
1556 {
1557 title: lang.recipient_map_old,
1558 data: 'recipient_map_old',
1559 defaultContent: ''
1560 },
1561 {
1562 title: lang.recipient_map_new,
1563 data: 'recipient_map_new',
1564 defaultContent: '',
1565 responsivePriority: 4
1566 },
1567 {
1568 title: lang.active,
1569 data: 'active',
1570 defaultContent: '',
1571 render: function (data, type) {
1572 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
1573 }
1574 },
1575 {
1576 title: lang.action,
1577 data: 'action',
1578 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
1579 responsivePriority: 5,
1580 defaultContent: ''
1581 },
1582 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001583 });
1584 }
1585 function draw_tls_policy_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001586 // just recalc width if instance already exists
1587 if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
1588 $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
1589 return;
1590 }
1591
1592 $('#tls_policy_table').DataTable({
1593 processing: true,
1594 serverSide: false,
1595 language: lang_datatables,
1596 ajax: {
1597 type: "GET",
1598 url: "/api/v1/get/tls-policy-map/all",
1599 dataSrc: function(json){
1600 if (role !== "admin") return null;
1601
1602 $.each(json, function (i, item) {
1603 item.dest = escapeHtml(item.dest);
1604 item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
1605 if (item.parameters == '') {
1606 item.parameters = '<code>-</code>';
1607 } else {
1608 item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
1609 }
1610 item.action = '<div class="btn-group">' +
1611 '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1612 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
1613 '</div>';
1614 item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
1615 });
1616
1617 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001618 }
1619 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001620 columns: [
1621 {
1622 // placeholder, so checkbox will not block child row toggle
1623 title: '',
1624 data: null,
1625 searchable: false,
1626 orderable: false,
1627 defaultContent: '',
1628 responsivePriority: 1
1629 },
1630 {
1631 title: '',
1632 data: 'chkbox',
1633 searchable: false,
1634 orderable: false,
1635 defaultContent: '',
1636 responsivePriority: 2
1637 },
1638 {
1639 title: 'ID',
1640 data: 'id',
1641 responsivePriority: 3,
1642 defaultContent: ''
1643 },
1644 {
1645 title: lang.tls_map_dest,
1646 data: 'dest',
1647 defaultContent: '',
1648 responsivePriority: 4
1649 },
1650 {
1651 title: lang.tls_map_policy,
1652 data: 'policy',
1653 defaultContent: ''
1654 },
1655 {
1656 title: lang.tls_map_parameters,
1657 data: 'parameters',
1658 defaultContent: ''
1659 },
1660 {
1661 title: lang.active,
1662 data: 'active',
1663 defaultContent: '',
1664 render: function (data, type) {
1665 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
1666 }
1667 },
1668 {
1669 title: lang.action,
1670 data: 'action',
1671 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
1672 responsivePriority: 5,
1673 defaultContent: ''
1674 },
1675 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001676 });
1677 }
1678 function draw_alias_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001679 // just recalc width if instance already exists
1680 if ($.fn.DataTable.isDataTable('#alias_table') ) {
1681 $('#alias_table').DataTable().columns.adjust().responsive.recalc();
1682 return;
1683 }
1684
1685 $('#alias_table').DataTable({
1686 processing: true,
1687 serverSide: false,
1688 language: lang_datatables,
1689 ajax: {
1690 type: "GET",
1691 url: "/api/v1/get/alias/all",
1692 dataSrc: function(json){
1693 $.each(json, function (i, item) {
1694 item.action = '<div class="btn-group">' +
1695 '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1696 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001697 '</div>';
1698 item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
1699 item.goto = escapeHtml(item.goto.replace(/,/g, " "));
1700 if (item.public_comment !== null) {
1701 item.public_comment = escapeHtml(item.public_comment);
1702 }
1703 else {
1704 item.public_comment = '-';
1705 }
1706 if (item.private_comment !== null) {
1707 item.private_comment = escapeHtml(item.private_comment);
1708 }
1709 else {
1710 item.private_comment = '-';
1711 }
1712 if (item.is_catch_all == 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001713 item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001714 }
1715 else {
1716 item.address = escapeHtml(item.address);
1717 }
1718 if (item.goto == "null@localhost") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001719 item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001720 }
1721 else if (item.goto == "spam@localhost") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001722 item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001723 }
1724 else if (item.goto == "ham@localhost") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001725 item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001726 }
1727 if (item.in_primary_domain !== "") {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001728 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 Benkardb382b102021-01-02 15:32:21 +01001729 }
1730 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001731
1732 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001733 }
1734 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001735 columns: [
1736 {
1737 // placeholder, so checkbox will not block child row toggle
1738 title: '',
1739 data: null,
1740 searchable: false,
1741 orderable: false,
1742 defaultContent: '',
1743 responsivePriority: 1
1744 },
1745 {
1746 title: '',
1747 data: 'chkbox',
1748 searchable: false,
1749 orderable: false,
1750 defaultContent: '',
1751 responsivePriority: 2
1752 },
1753 {
1754 title: 'ID',
1755 data: 'id',
1756 responsivePriority: 3,
1757 defaultContent: ''
1758 },
1759 {
1760 title: lang.alias,
1761 data: 'address',
1762 responsivePriority: 4,
1763 defaultContent: ''
1764 },
1765 {
1766 title: lang.target_address,
1767 data: 'goto',
1768 defaultContent: ''
1769 },
1770 {
1771 title: lang.domain,
1772 data: 'domain',
1773 defaultContent: '',
1774 responsivePriority: 5,
1775 },
1776 {
1777 title: lang.bcc_destinations,
1778 data: 'bcc_dest',
1779 defaultContent: ''
1780 },
1781 {
1782 title: lang.sogo_visible,
1783 data: 'sogo_visible',
1784 defaultContent: '',
1785 render: function(data, type){
1786 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
1787 }
1788 },
1789 {
1790 title: lang.public_comment,
1791 data: 'public_comment',
1792 defaultContent: ''
1793 },
1794 {
1795 title: lang.private_comment,
1796 data: 'private_comment',
1797 defaultContent: ''
1798 },
1799 {
1800 title: lang.active,
1801 data: 'active',
1802 defaultContent: '',
1803 responsivePriority: 6,
1804 render: function (data, type) {
1805 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
1806 }
1807 },
1808 {
1809 title: lang.action,
1810 data: 'action',
1811 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
1812 responsivePriority: 5,
1813 defaultContent: ''
1814 },
1815 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001816 });
1817 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001818 function draw_aliasdomain_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001819 // just recalc width if instance already exists
1820 if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
1821 $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
1822 return;
1823 }
1824
1825 $('#aliasdomain_table').DataTable({
1826 processing: true,
1827 serverSide: false,
1828 language: lang_datatables,
1829 ajax: {
1830 type: "GET",
1831 url: "/api/v1/get/alias-domain/all",
1832 dataSrc: function(json){
1833 $.each(json, function (i, item) {
1834 item.alias_domain = escapeHtml(item.alias_domain);
1835
1836 item.action = '<div class="btn-group">' +
1837 '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1838 '<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-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
1839 '<a href="#dnsInfoModal" class="btn btn-sm 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 Benkardb382b102021-01-02 15:32:21 +01001840 '</div>';
1841 item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
1842 if(item.parent_is_backupmx == '1') {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001843 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 Benkardb382b102021-01-02 15:32:21 +01001844 } else {
1845 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
1846 }
1847 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001848
1849 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001850 }
1851 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001852 columns: [
1853 {
1854 // placeholder, so checkbox will not block child row toggle
1855 title: '',
1856 data: null,
1857 searchable: false,
1858 orderable: false,
1859 defaultContent: '',
1860 responsivePriority: 1
1861 },
1862 {
1863 title: '',
1864 data: 'chkbox',
1865 searchable: false,
1866 orderable: false,
1867 defaultContent: '',
1868 responsivePriority: 2
1869 },
1870 {
1871 title: lang.alias,
1872 data: 'alias_domain',
1873 responsivePriority: 3,
1874 defaultContent: ''
1875 },
1876 {
1877 title: lang.target_domain,
1878 data: 'target_domain',
1879 responsivePriority: 4,
1880 defaultContent: ''
1881 },
1882 {
1883 title: lang.active,
1884 data: 'active',
1885 defaultContent: '',
1886 render: function (data, type) {
1887 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
1888 }
1889 },
1890 {
1891 title: lang.action,
1892 data: 'action',
1893 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
1894 responsivePriority: 5,
1895 defaultContent: ''
1896 },
1897 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001898 });
1899 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001900 function draw_sync_job_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001901 // just recalc width if instance already exists
1902 if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
1903 $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
1904 return;
1905 }
1906
1907 $('#sync_job_table').DataTable({
1908 processing: true,
1909 serverSide: false,
1910 language: lang_datatables,
1911 ajax: {
1912 type: "GET",
1913 url: "/api/v1/get/syncjobs/all/no_log",
1914 dataSrc: function(json){
1915 $.each(json, function (i, item) {
1916 item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001917 item.user2 = escapeHtml(item.user2);
1918 if (!item.exclude > 0) {
1919 item.exclude = '-';
1920 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001921 item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001922 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001923 item.server_w_port = escapeHtml(item.user1) + '@' + escapeHtml(item.host1) + ':' + escapeHtml(item.port1);
1924 item.action = '<div class="btn-group">' +
1925 '<a href="/edit/syncjob/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1926 '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001927 '</div>';
1928 item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
1929 if (item.is_running == 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001930 item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001931 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001932 item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001933 }
1934 if (!item.last_run > 0) {
1935 item.last_run = lang.waiting;
1936 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001937 if (item.success == null) {
1938 item.success = '-';
1939 item.exit_status = '';
1940 } else {
1941 item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
1942 }
1943 if (lang['syncjob_'+item.exit_status]) {
1944 item.exit_status = lang['syncjob_'+item.exit_status];
1945 } else if (item.success != '-') {
1946 item.exit_status = lang.syncjob_check_log;
1947 }
1948 item.exit_status = item.success + ' ' + item.exit_status;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001949 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001950
1951 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001952 }
1953 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001954 columns: [
1955 {
1956 // placeholder, so checkbox will not block child row toggle
1957 title: '',
1958 data: null,
1959 searchable: false,
1960 orderable: false,
1961 defaultContent: '',
1962 responsivePriority: 1
1963 },
1964 {
1965 title: '',
1966 data: 'chkbox',
1967 searchable: false,
1968 orderable: false,
1969 defaultContent: '',
1970 responsivePriority: 2
1971 },
1972 {
1973 title: 'ID',
1974 data: 'id',
1975 responsivePriority: 3,
1976 defaultContent: ''
1977 },
1978 {
1979 title: lang.owner,
1980 data: 'user2',
1981 responsivePriority: 4,
1982 defaultContent: ''
1983 },
1984 {
1985 title: 'Server',
1986 data: 'server_w_port',
1987 defaultContent: ''
1988 },
1989 {
1990 title: lang.last_run,
1991 data: 'last_run',
1992 defaultContent: ''
1993 },
1994 {
1995 title: lang.syncjob_last_run_result,
1996 data: 'exit_status',
1997 defaultContent: ''
1998 },
1999 {
2000 title: 'Log',
2001 data: 'log',
2002 defaultContent: ''
2003 },
2004 {
2005 title: lang.active,
2006 data: 'active',
2007 defaultContent: '',
2008 render: function (data, type) {
2009 return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
2010 }
2011 },
2012 {
2013 title: lang.status,
2014 data: 'is_running',
2015 defaultContent: ''
2016 },
2017 {
2018 title: lang.excludes,
2019 data: 'exclude',
2020 defaultContent: '',
2021 className: 'none'
2022 },
2023 {
2024 title: lang.mins_interval,
2025 data: 'mins_interval',
2026 defaultContent: '',
2027 className: 'none'
2028 },
2029 {
2030 title: lang.action,
2031 data: 'action',
2032 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
2033 responsivePriority: 5,
2034 defaultContent: ''
2035 },
2036 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002037 });
2038 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002039 function draw_filter_table() {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002040 // just recalc width if instance already exists
2041 if ($.fn.DataTable.isDataTable('#filter_table') ) {
2042 $('#filter_table').DataTable().columns.adjust().responsive.recalc();
2043 return;
2044 }
2045
2046 var table = $('#filter_table').DataTable({
2047 autoWidth: false,
2048 processing: true,
2049 serverSide: false,
2050 language: lang_datatables,
2051 ajax: {
2052 type: "GET",
2053 url: "/api/v1/get/filters/all",
2054 dataSrc: function(json){
2055 $.each(json, function (i, item) {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002056 if (item.active == 1) {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002057 item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002058 } else {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002059 item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002060 }
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002061 item.script_desc = escapeHtml(item.script_desc);
2062 item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
2063 item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
2064 item.action = '<div class="btn-group">' +
2065 '<a href="/edit/filter/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
2066 '<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-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002067 '</div>';
2068 item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
2069 });
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002070
2071 return json;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002072 }
2073 },
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002074 columns: [
2075 {
2076 // placeholder, so checkbox will not block child row toggle
2077 title: '',
2078 data: null,
2079 searchable: false,
2080 orderable: false,
2081 defaultContent: '',
2082 responsivePriority: 1
2083 },
2084 {
2085 title: '',
2086 data: 'chkbox',
2087 searchable: false,
2088 orderable: false,
2089 defaultContent: '',
2090 responsivePriority: 2
2091 },
2092 {
2093 title: 'ID',
2094 data: 'id',
2095 responsivePriority: 2,
2096 defaultContent: ''
2097 },
2098 {
2099 title: lang.active,
2100 data: 'active',
2101 responsivePriority: 3,
2102 defaultContent: ''
2103 },
2104 {
2105 title: 'Type',
2106 data: 'filter_type',
2107 responsivePriority: 4,
2108 defaultContent: ''
2109 },
2110 {
2111 title: lang.owner,
2112 data: 'username',
2113 defaultContent: ''
2114 },
2115 {
2116 title: lang.description,
2117 data: 'script_desc',
2118 defaultContent: ''
2119 },
2120 {
2121 title: 'Script',
2122 data: 'script_data',
2123 defaultContent: '',
2124 className: 'none'
2125 },
2126 {
2127 title: lang.action,
2128 data: 'action',
2129 className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
2130 responsivePriority: 5,
2131 defaultContent: ''
2132 },
2133 ]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002134 });
2135 };
2136
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002137 // detect element visibility changes
2138 function onVisible(element, callback) {
2139 $(document).ready(function() {
2140 element_object = document.querySelector(element);
2141 if (element_object === null) return;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002142
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002143 new IntersectionObserver((entries, observer) => {
2144 entries.forEach(entry => {
2145 if(entry.intersectionRatio > 0) {
2146 callback(element_object);
2147 }
2148 });
2149 }).observe(element_object);
2150 });
2151 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002152
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01002153 // Load only if the tab is visible
2154 onVisible("[id^=domain_table]", () => draw_domain_table());
2155 onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table());
2156 onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
2157 onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table());
2158 onVisible("[id^=resource_table]", () => draw_resource_table());
2159 onVisible("[id^=alias_table]", () => draw_alias_table());
2160 onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
2161 onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
2162 onVisible("[id^=filter_table]", () => draw_filter_table());
2163 onVisible("[id^=bcc_table]", () => draw_bcc_table());
2164 onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
2165 onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01002166});