blob: 745c4f2184843bda38669f96807ff441e0163216 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001$(document).ready(function() {
2 acl_data = JSON.parse(acl);
3 FooTable.domainFilter = FooTable.Filtering.extend({
4 construct: function(instance){
5 this._super(instance);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02006 this.def = lang.all_domains;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01007 this.$domain = null;
8 },
9 $create: function(){
10 this._super();
11 var self = this;
12 var domains = [];
13
14 $.each(self.ft.rows.all, function(i, row){
15 if((row.val().domain != null) && ($.inArray(row.val().domain, domains) === -1)) domains.push(row.val().domain);
16 });
17
18 $form_grp = $('<div/>', {'class': 'form-group'})
19 .append($('<label/>', {'class': 'sr-only', text: 'Domain'}))
20 .prependTo(self.$form);
21 self.$domain = $('<select/>', { 'class': 'aform-control' })
22 .on('change', {self: self}, self._onDomainDropdownChanged)
23 .append($('<option/>', {text: self.def}))
24 .appendTo($form_grp);
25
26 $.each(domains, function(i, domain){
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020027 domainname = $($.parseHTML(domain)).data('domainname')
28 if (domainname !== undefined) {
29 self.$domain.append($('<option/>').text(domainname));
30 } else {
31 self.$domain.append($('<option/>').text(domain));
32 }
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010033 });
34 },
35 _onDomainDropdownChanged: function(e){
36 var self = e.data.self,
37 selected = $(this).val();
38 if (selected !== self.def){
39 self.addFilter('domain', selected, ['domain']);
40 } else {
41 self.removeFilter('domain');
42 }
43 self.filter();
44 },
45 draw: function(){
46 this._super();
47 var domain = this.find('domain');
48 if (domain instanceof FooTable.Filter){
49 this.$domain.val(domain.query.val());
50 } else {
51 this.$domain.val(this.def);
52 }
53 $(this.$domain).closest("select").selectpicker();
54 }
55 });
56 // Set paging
57 $('[data-page-size]').on('click', function(e){
58 e.preventDefault();
59 var new_size = $(this).data('page-size');
60 var parent_ul = $(this).closest('ul');
61 var table_id = $(parent_ul).data('table-id');
62 FooTable.get('#' + table_id).pageSize(new_size);
63 //$(this).parent().addClass('active').siblings().removeClass('active')
64 heading = $(this).parents('.panel').find('.panel-heading')
65 var n_results = $(heading).children('.table-lines').text().split(' / ')[1];
66 $(heading).children('.table-lines').text(function(){
67 if (new_size > n_results) {
68 new_size = n_results;
69 }
70 return new_size + ' / ' + n_results;
71 })
72 });
73 // Clone mailbox mass actions
74 $("div").find("[data-actions-header='true'").each(function() {
75 $(this).html($(this).nextAll('.mass-actions-mailbox:first').html());
76 });
77 // Auto-fill domain quota when adding new domain
78 auto_fill_quota = function(domain) {
79 $.get("/api/v1/get/domain/" + domain, function(data){
80 var result = $.parseJSON(JSON.stringify(data));
81 def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576);
82 max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
83 if (max_new_mailbox_quota != '0') {
84 $('.addInputQuotaExhausted').hide();
85 $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
86 $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
87 $('#addInputQuota').val(def_new_mailbox_quota);
88 }
89 else {
90 $('.addInputQuotaExhausted').show();
91 $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
92 $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
93 $('#addInputQuota').val(max_new_mailbox_quota);
94 }
95 });
96 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020097 $('#addSelectDomain').on('change', function() {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010098 auto_fill_quota($('#addSelectDomain').val());
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020099 });
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100100 auto_fill_quota($('#addSelectDomain').val());
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100101
102 // Read bcc local dests
103 // Using ajax to not be a blocking moo
104 $.get("/api/v1/get/bcc-destination-options", function(data){
105 // Domains
106 var optgroup = "<optgroup label='" + lang.domains + "'>";
107 $.each(data.domains, function(index, domain){
108 optgroup += "<option value='" + domain + "'>" + domain + "</option>"
109 });
110 optgroup += "</optgroup>"
111 $('#bcc-local-dest').append(optgroup);
112 // Alias domains
113 var optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
114 $.each(data.alias_domains, function(index, alias_domain){
115 optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>"
116 });
117 optgroup += "</optgroup>"
118 $('#bcc-local-dest').append(optgroup);
119 // Mailboxes and aliases
120 $.each(data.mailboxes, function(mailbox, aliases){
121 var optgroup = "<optgroup label='" + mailbox + "'>";
122 $.each(aliases, function(index, alias){
123 optgroup += "<option value='" + alias + "'>" + alias + "</option>"
124 });
125 optgroup += "</optgroup>"
126 $('#bcc-local-dest').append(optgroup);
127 });
128 // Finish
129 $('#bcc-local-dest').find('option:selected').remove();
130 $('#bcc-local-dest').selectpicker('refresh');
131 });
132
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100133 $(".goto_checkbox").click(function( event ) {
134 $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
135 if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
136 $('#textarea_alias_goto').prop('disabled', true);
137 }
138 else {
139 $("#textarea_alias_goto").removeAttr('disabled');
140 }
141 });
142 $('#addAliasModal').on('show.bs.modal', function(e) {
143 if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
144 $('#textarea_alias_goto').prop('disabled', true);
145 }
146 else {
147 $("#textarea_alias_goto").removeAttr('disabled');
148 }
149 });
150 // Log modal
151 $('#syncjobLogModal').on('show.bs.modal', function(e) {
152 var syncjob_id = $(e.relatedTarget).data('syncjob-id');
153 $.ajax({
154 url: '/inc/ajax/syncjob_logs.php',
155 data: { id: syncjob_id },
156 dataType: 'text',
157 success: function(data){
158 $(e.currentTarget).find('#logText').text(data);
159 },
160 error: function(xhr, status, error) {
161 $(e.currentTarget).find('#logText').text(xhr.responseText);
162 }
163 });
164 });
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100165 // Log modal
166 $('#dnsInfoModal').on('show.bs.modal', function(e) {
167 var domain = $(e.relatedTarget).data('domain');
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200168 $('.dns-modal-body').html('<center><i class="bi bi-arrow-repeat icon-spin"></i></center>');
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100169 $.ajax({
170 url: '/inc/ajax/dns_diagnostics.php',
171 data: { domain: domain },
172 dataType: 'text',
173 success: function(data){
174 $('.dns-modal-body').html(data);
175 },
176 error: function(xhr, status, error) {
177 $('.dns-modal-body').html(xhr.responseText);
178 }
179 });
180 });
181 // Sieve data modal
182 $('#sieveDataModal').on('show.bs.modal', function(e) {
183 var sieveScript = $(e.relatedTarget).data('sieve-script');
184 $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
185 });
186 // Disable submit button on script change
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200187 $('.textarea-code').on('keyup', function() {
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100188 // Disable all "save" buttons, could be a "related button only" function, todo
189 $('.add_sieve_script').attr({"disabled": true});
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200190 });
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100191 // Validate script data
192 $(".validate_sieve").click(function( event ) {
193 event.preventDefault();
194 var validation_button = $(this);
195 // Get script_data textarea content from form the button was clicked in
196 var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
197 $.ajax({
198 dataType: 'json',
199 url: "/inc/ajax/sieve_validation.php",
200 type: "get",
201 data: { script: script },
202 complete: function(data) {
203 var response = (data.responseText);
204 response_obj = JSON.parse(response);
205 if (response_obj.type == "success") {
206 $(validation_button).next().attr({"disabled": false});
207 }
208 mailcow_alert_box(response_obj.msg, response_obj.type);
209 },
210 });
211 });
212 // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
213 // $("#active-script").closest('td').css('background-color','#b0f0a0');
214 // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
215 // });
216 $('#addResourceModal').on('shown.bs.modal', function() {
217 $("#multiple_bookings").val($("#multiple_bookings_select").val());
218 if ($("#multiple_bookings").val() == "custom") {
219 $("#multiple_bookings_custom_div").show();
220 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
221 }
222 })
223 $("#multiple_bookings_select").change(function() {
224 $("#multiple_bookings").val($("#multiple_bookings_select").val());
225 if ($("#multiple_bookings").val() == "custom") {
226 $("#multiple_bookings_custom_div").show();
227 }
228 else {
229 $("#multiple_bookings_custom_div").hide();
230 }
231 });
232 $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
233 $("#multiple_bookings").val($("#multiple_bookings_custom").val());
234 });
235
236
237});
238jQuery(function($){
239 // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
240 var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
241 function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
242 // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
243 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 Benkard7b2a3a12021-08-16 10:57:25 +0200244 function unix_time_format(i){return""==i?'<i class="bi bi-x-lg"></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 Benkardb382b102021-01-02 15:32:21 +0100245 $(".refresh_table").on('click', function(e) {
246 e.preventDefault();
247 var table_name = $(this).data('table');
248 $('#' + table_name).find("tr.footable-empty").remove();
249 draw_table = $(this).data('draw');
250 eval(draw_table + '()');
251 });
252 function table_mailbox_ready(ft, name) {
253 if(is_dual) {
254 $('.login_as').data("toggle", "tooltip")
255 .attr("disabled", true)
256 .removeAttr("href")
257 .attr("title", "Dual login cannot be used twice")
258 .tooltip();
259 }
260 $('.refresh_table').prop("disabled", false);
261 heading = ft.$el.parents('.panel').find('.panel-heading')
262 var ft_paging = ft.use(FooTable.Paging)
263 $(heading).children('.table-lines').text(function(){
264 var total_rows = ft_paging.totalRows;
265 var size = ft_paging.size;
266 if (size > total_rows) {
267 size = total_rows;
268 }
269 return size + ' / ' + total_rows;
270 })
271 }
272 function draw_domain_table() {
273 ft_domain_table = FooTable.init('#domain_table', {
274 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200275 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100276 {"sorted": true,"name":"domain_name","title":lang.domain,"style":{"width":"250px"}},
277 {"name":"aliases","title":lang.aliases,"breakpoints":"xs sm"},
278 {"name":"mailboxes","title":lang.mailboxes},
279 {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
280 res = value.split("/");
281 return humanFileSize(res[0]) + " / " + humanFileSize(res[1]);
282 },
283 "sortValue": function(value){
284 res = value.split("/");
285 return Number(res[0]);
286 }},
287 {"name":"stats","sortable": false,"style":{"whiteSpace":"nowrap"},"title":lang.stats,"formatter": function(value){
288 res = value.split("/");
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200289 return '<i class="bi bi-files"></i> ' + res[0] + ' / ' + humanFileSize(res[1]);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100290 }},
291 {"name":"def_quota_for_mbox","title":lang.mailbox_defquota,"breakpoints":"xs sm md","style":{"width":"125px"}},
292 {"name":"max_quota_for_mbox","title":lang.mailbox_quota,"breakpoints":"xs sm","style":{"width":"125px"}},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200293 {"name":"rl","title":"RL","breakpoints":"xs sm md lg","style":{"min-width":"100px","width":"100px"}},
294 {"name":"backupmx","filterable": false,"style":{"min-width":"120px","width":"120px"},"title":lang.backup_mx,"breakpoints":"xs sm md lg","formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100295 {"name":"domain_admins","title":lang.domain_admins,"style":{"word-break":"break-all","min-width":"200px"},"breakpoints":"xs sm md lg","filterable":(role == "admin"),"visible":(role == "admin")},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200296 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
297 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"240px","width":"240px"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100298 ],
299 "rows": $.ajax({
300 dataType: 'json',
301 url: '/api/v1/get/domain/all',
302 jsonp: false,
303 error: function (data) {
304 console.log('Cannot draw domain table');
305 },
306 success: function (data) {
307 $.each(data, function (i, item) {
308 item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
309 item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
310 item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
311 item.stats = item.msgs_total + "/" + item.bytes_total;
312 if (!item.rl) {
313 item.rl = '∞';
314 } else {
315 item.rl = $.map(item.rl, function(e){
316 return e;
317 }).join('/1');
318 }
319 item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
320 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
321 item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200322 item.action = '<div class="btn-group footable-actions">';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100323 if (role == "admin") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200324 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-xs-third btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
325 '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
326 '<a href="#dnsInfoModal" class="btn btn-xs btn-xs-third btn-info" data-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 +0100327 }
328 else {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200329 item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
330 '<a href="#dnsInfoModal" class="btn btn-xs btn-xs-half btn-info" data-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 +0100331 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200332
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100333 if (item.backupmx == 1) {
334 if (item.relay_unknown_only == 1) {
335 item.domain_name = '<div class="label label-info">Relay Non-Local</div> ' + item.domain_name;
336 } else if (item.relay_all_recipients == 1) {
337 item.domain_name = '<div class="label label-info">Relay All</div> ' + item.domain_name;
338 } else {
339 item.domain_name = '<div class="label label-info">Relay</div> ' + item.domain_name;
340 }
341 }
342 });
343 }
344 }),
345 "empty": lang.empty,
346 "paging": {
347 "enabled": true,
348 "limit": 5,
349 "size": pagination_size
350 },
351 "state": {
352 "enabled": true
353 },
354 "filtering": {
355 "enabled": true,
356 "delay": 1200,
357 "position": "left",
358 "connectors": false,
359 "placeholder": lang.filter_table
360 },
361 "sorting": {
362 "enabled": true
363 },
364 "on": {
365 "destroy.ft.table": function(e, ft){
366 $('.refresh_table').attr('disabled', 'true');
367 },
368 "ready.ft.table": function(e, ft){
369 table_mailbox_ready(ft, 'domain_table');
370 },
371 "after.ft.filtering": function(e, ft){
372 table_mailbox_ready(ft, 'domain_table');
373 }
374 },
375 "toggleSelector": "table tbody span.footable-toggle"
376 });
377 }
378 function draw_mailbox_table() {
379 ft_mailbox_table = FooTable.init('#mailbox_table', {
380 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200381 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100382 {"sorted": true,"name":"username","style":{"word-break":"break-all","min-width":"120px"},"title":lang.username},
383 {"name":"name","title":lang.fname,"style":{"word-break":"break-all","min-width":"120px"},"breakpoints":"xs sm md lg"},
384 {"name":"domain","title":lang.domain,"breakpoints":"xs sm md lg"},
385 {"name":"quota","style":{"whiteSpace":"nowrap"},"title":lang.domain_quota,"formatter": function(value){
386 res = value.split("/");
387 var of_q = (res[1] == 0 ? "∞" : humanFileSize(res[1]));
388 return humanFileSize(res[0]) + " / " + of_q;
389 },
390 "sortValue": function(value){
391 res = value.split("/");
392 return Number(res[0]);
393 },
394 },
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200395 /* {"name":"spam_aliases","filterable": false,"title":lang.spam_aliases,"breakpoints":"all"}, */
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100396 {"name":"tls_enforce_in","filterable": false,"title":lang.tls_enforce_in,"breakpoints":"all"},
397 {"name":"tls_enforce_out","filterable": false,"title":lang.tls_enforce_out,"breakpoints":"all"},
398 {"name":"smtp_access","filterable": false,"title":"SMTP","breakpoints":"all"},
399 {"name":"imap_access","filterable": false,"title":"IMAP","breakpoints":"all"},
400 {"name":"pop3_access","filterable": false,"title":"POP3","breakpoints":"all"},
401 {"name":"last_mail_login","breakpoints":"xs sm","title":lang.last_mail_login,"style":{"width":"170px"},
402 "sortValue": function(value){
403 res = value.split("/");
404 return Math.max(res[0], res[1]);
405 },
406 "formatter": function(value){
407 res = value.split("/");
408 return '<div class="label label-last-login">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200409 '<div class="label label-last-login">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100410 '<div class="label label-last-login">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
411 }},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200412 {"name":"last_pw_change","filterable": false,"title":lang.last_pw_change,"breakpoints":"all"},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100413 {"name":"quarantine_notification","filterable": false,"title":lang.quarantine_notification,"breakpoints":"all"},
414 {"name":"quarantine_category","filterable": false,"title":lang.quarantine_category,"breakpoints":"all"},
415 {"name":"in_use","filterable": false,"type":"html","title":lang.in_use,"sortValue": function(value){
416 return Number($(value).find(".progress-bar-mailbox").attr('aria-valuenow'));
417 },
418 },
419 {"name":"messages","filterable": false,"title":lang.msg_num,"breakpoints":"xs sm md"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200420 /* {"name":"rl","title":"RL","breakpoints":"all","style":{"width":"125px"}}, */
421 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':(0==value?'<i class="bi bi-x-lg"></i>':2==value&&'&#8212;');}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100422 {"name":"action","filterable": false,"sortable": false,"style":{"min-width":"290px","text-align":"right"},"type":"html","title":lang.action,"breakpoints":"xs sm md"}
423 ],
424 "empty": lang.empty,
425 "rows": $.ajax({
426 dataType: 'json',
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200427 url: '/api/v1/get/mailbox/reduced',
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100428 jsonp: false,
429 error: function () {
430 console.log('Cannot draw mailbox table');
431 },
432 success: function (data) {
433 $.each(data, function (i, item) {
434 item.quota = item.quota_used + "/" + item.quota;
435 item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
436 item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200437 /*
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100438 if (!item.rl) {
439 item.rl = '∞';
440 } else {
441 item.rl = $.map(item.rl, function(e){
442 return e;
443 }).join('/1');
444 if (item.rl_scope === 'domain') {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200445 item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100446 }
447 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200448 */
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100449 item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200450 if (item.attributes.passwd_update != '0') {
451 var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
452 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"});
453 } else {
454 item.last_pw_change = '-';
455 }
456 item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
457 item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
458 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>';
459 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>';
460 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 Benkardb382b102021-01-02 15:32:21 +0100461 if (item.attributes.quarantine_notification === 'never') {
462 item.quarantine_notification = lang.never;
463 } else if (item.attributes.quarantine_notification === 'hourly') {
464 item.quarantine_notification = lang.hourly;
465 } else if (item.attributes.quarantine_notification === 'daily') {
466 item.quarantine_notification = lang.daily;
467 } else if (item.attributes.quarantine_notification === 'weekly') {
468 item.quarantine_notification = lang.weekly;
469 }
470 if (item.attributes.quarantine_category === 'reject') {
471 item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
472 } else if (item.attributes.quarantine_category === 'add_header') {
473 item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
474 } else if (item.attributes.quarantine_category === 'all') {
475 item.quarantine_category = lang.q_all;
476 }
477 if (acl_data.login_as === 1) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200478 var btnSize = 'btn-xs-third';
479 if (ALLOW_ADMIN_EMAIL_LOGIN) btnSize = 'btn-xs-quart';
480
481 item.action = '<div class="btn-group footable-actions">' +
482 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs ' + btnSize + ' btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
483 '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-xs ' + btnSize + ' btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
484 '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs ' + btnSize + ' btn-success"><i class="bi bi-person-fill"></i> Login</a>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100485 if (ALLOW_ADMIN_EMAIL_LOGIN) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200486 item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-xs ' + btnSize + ' btn-primary" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100487 }
488 item.action += '</div>';
489 }
490 else {
491 item.action = '<div class="btn-group">' +
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200492 '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
493 '<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 +0100494 '</div>';
495 }
496 item.in_use = '<div class="progress">' +
497 '<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" ' +
498 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
499 item.username = escapeHtml(item.username);
500 });
501 }
502 }),
503 "paging": {
504 "enabled": true,
505 "limit": 5,
506 "size": pagination_size
507 },
508 "state": {
509 "enabled": true
510 },
511 "filtering": {
512 "enabled": true,
513 "delay": 1200,
514 "position": "left",
515 "connectors": false,
516 //"container": "#tab-mailboxes.panel",
517 "placeholder": lang.filter_table
518 },
519 "components": {
520 "filtering": FooTable.domainFilter
521 },
522 "sorting": {
523 "enabled": true
524 },
525 "on": {
526 "destroy.ft.table": function(e, ft){
527 $('.refresh_table').attr('disabled', 'true');
528 },
529 "ready.ft.table": function(e, ft){
530 table_mailbox_ready(ft, 'mailbox_table');
531 },
532 "after.ft.filtering": function(e, ft){
533 table_mailbox_ready(ft, 'mailbox_table');
534 }
535 },
536 "toggleSelector": "table tbody span.footable-toggle"
537 });
538 }
539 function draw_resource_table() {
540 ft_resource_table = FooTable.init('#resource_table', {
541 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200542 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100543 {"sorted": true,"name":"description","title":lang.description,"style":{"width":"250px"}},
544 {"name":"name","title":lang.alias},
545 {"name":"kind","title":lang.kind},
546 {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200547 {"name":"multiple_bookings","filterable": false,"style":{"min-width":"150px","width":"140px"},"title":lang.multiple_bookings,"breakpoints":"xs sm"},
548 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
549 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100550 ],
551 "empty": lang.empty,
552 "rows": $.ajax({
553 dataType: 'json',
554 url: '/api/v1/get/resource/all',
555 jsonp: false,
556 error: function () {
557 console.log('Cannot draw resource table');
558 },
559 success: function (data) {
560 $.each(data, function (i, item) {
561 if (item.multiple_bookings == '0') {
562 item.multiple_bookings = '<span id="active-script" class="label label-success">' + lang.booking_0_short + '</span>';
563 } else if (item.multiple_bookings == '-1') {
564 item.multiple_bookings = '<span id="active-script" class="label label-warning">' + lang.booking_lt0_short + '</span>';
565 } else {
566 item.multiple_bookings = '<span id="active-script" class="label label-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
567 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200568 item.action = '<div class="btn-group footable-actions">' +
569 '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
570 '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" 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 +0100571 '</div>';
572 item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
573 item.name = escapeHtml(item.name);
574 });
575 }
576 }),
577 "paging": {
578 "enabled": true,
579 "limit": 5,
580 "size": pagination_size
581 },
582 "state": {
583 "enabled": true
584 },
585 "filtering": {
586 "enabled": true,
587 "delay": 1200,
588 "position": "left",
589 "connectors": false,
590 "placeholder": lang.filter_table
591 },
592 "components": {
593 "filtering": FooTable.domainFilter
594 },
595 "sorting": {
596 "enabled": true
597 },
598 "on": {
599 "destroy.ft.table": function(e, ft){
600 $('.refresh_table').attr('disabled', 'true');
601 },
602 "ready.ft.table": function(e, ft){
603 table_mailbox_ready(ft, 'resource_table');
604 },
605 "after.ft.filtering": function(e, ft){
606 table_mailbox_ready(ft, 'resource_table');
607 }
608 },
609 "toggleSelector": "table tbody span.footable-toggle"
610 });
611 }
612 function draw_bcc_table() {
613 ft_bcc_table = FooTable.init('#bcc_table', {
614 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200615 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
616 {"sorted": true,"name":"id","title":"ID","style":{"min-width":"60px","width":"60px","text-align":"center"}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100617 {"name":"type","title":lang.bcc_type},
618 {"name":"local_dest","title":lang.bcc_local_dest},
619 {"name":"bcc_dest","title":lang.bcc_destinations},
620 {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200621 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
622 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100623 ],
624 "empty": lang.empty,
625 "rows": $.ajax({
626 dataType: 'json',
627 url: '/api/v1/get/bcc/all',
628 jsonp: false,
629 error: function () {
630 console.log('Cannot draw bcc table');
631 },
632 success: function (data) {
633 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200634 item.action = '<div class="btn-group footable-actions">' +
635 '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
636 '<a href="#" data-action="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100637 '</div>';
638 item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
639 item.local_dest = escapeHtml(item.local_dest);
640 item.bcc_dest = escapeHtml(item.bcc_dest);
641 if (item.type == 'sender') {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200642 item.type = '<span id="active-script" class="label label-success">' + lang.bcc_sender_map + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100643 } else {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200644 item.type = '<span id="inactive-script" class="label label-warning">' + lang.bcc_rcpt_map + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100645 }
646 });
647 }
648 }),
649 "paging": {
650 "enabled": true,
651 "limit": 5,
652 "size": pagination_size
653 },
654 "state": {
655 "enabled": true
656 },
657 "filtering": {
658 "enabled": true,
659 "delay": 1200,
660 "position": "left",
661 "connectors": false,
662 "placeholder": lang.filter_table
663 },
664 "sorting": {
665 "enabled": true
666 },
667 "on": {
668 "destroy.ft.table": function(e, ft){
669 $('.refresh_table').attr('disabled', 'true');
670 },
671 "ready.ft.table": function(e, ft){
672 table_mailbox_ready(ft, 'bcc_table');
673 },
674 "after.ft.filtering": function(e, ft){
675 table_mailbox_ready(ft, 'bcc_table');
676 }
677 },
678 "toggleSelector": "table tbody span.footable-toggle"
679 });
680 }
681 function draw_recipient_map_table() {
682 ft_recipient_map_table = FooTable.init('#recipient_map_table', {
683 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200684 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
685 {"sorted": true,"name":"id","title":"ID","style":{"min-width":"60px","width":"60px","text-align":"center"}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100686 {"name":"recipient_map_old","title":lang.recipient_map_old},
687 {"name":"recipient_map_new","title":lang.recipient_map_new},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200688 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
689 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100690 ],
691 "empty": lang.empty,
692 "rows": $.ajax({
693 dataType: 'json',
694 url: '/api/v1/get/recipient_map/all',
695 jsonp: false,
696 error: function () {
697 console.log('Cannot draw recipient map table');
698 },
699 success: function (data) {
700 if (role == "admin") {
701 $.each(data, function (i, item) {
702 item.recipient_map_old = escapeHtml(item.recipient_map_old);
703 item.recipient_map_new = escapeHtml(item.recipient_map_new);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200704 item.action = '<div class="btn-group footable-actions">' +
705 '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
706 '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100707 '</div>';
708 item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
709 });
710 }
711 }
712 }),
713 "paging": {
714 "enabled": true,
715 "limit": 5,
716 "size": pagination_size
717 },
718 "state": {
719 "enabled": true
720 },
721 "filtering": {
722 "enabled": true,
723 "delay": 1200,
724 "position": "left",
725 "connectors": false,
726 "placeholder": lang.filter_table
727 },
728 "sorting": {
729 "enabled": true
730 },
731 "on": {
732 "destroy.ft.table": function(e, ft){
733 $('.refresh_table').attr('disabled', 'true');
734 },
735 "ready.ft.table": function(e, ft){
736 table_mailbox_ready(ft, 'recipient_map_table');
737 },
738 "after.ft.filtering": function(e, ft){
739 table_mailbox_ready(ft, 'recipient_map_table');
740 }
741 },
742 "toggleSelector": "table tbody span.footable-toggle"
743 });
744 }
745 function draw_tls_policy_table() {
746 ft_tls_policy_table = FooTable.init('#tls_policy_table', {
747 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200748 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
749 {"sorted": true,"name":"id","title":"ID","style":{"min-width":"60px","width":"60px","text-align":"center"}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100750 {"name":"dest","title":lang.tls_map_dest},
751 {"name":"policy","title":lang.tls_map_policy},
752 {"name":"parameters","title":lang.tls_map_parameters},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200753 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
754 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":(role == "admin" ? lang.action : ""),"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100755 ],
756 "empty": lang.empty,
757 "rows": $.ajax({
758 dataType: 'json',
759 url: '/api/v1/get/tls-policy-map/all',
760 jsonp: false,
761 error: function () {
762 console.log('Cannot draw tls policy map table');
763 },
764 success: function (data) {
765 if (role == "admin") {
766 $.each(data, function (i, item) {
767 item.dest = escapeHtml(item.dest);
768 item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
769 if (item.parameters == '') {
770 item.parameters = '<code>-</code>';
771 } else {
772 item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
773 }
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200774 item.action = '<div class="btn-group footable-actions">' +
775 '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
776 '<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-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100777 '</div>';
778 item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
779 });
780 }
781 }
782 }),
783 "paging": {
784 "enabled": true,
785 "limit": 5,
786 "size": pagination_size
787 },
788 "state": {
789 "enabled": true
790 },
791 "filtering": {
792 "enabled": true,
793 "delay": 1200,
794 "position": "left",
795 "connectors": false,
796 "placeholder": lang.filter_table
797 },
798 "sorting": {
799 "enabled": true
800 },
801 "on": {
802 "destroy.ft.table": function(e, ft){
803 $('.refresh_table').attr('disabled', 'true');
804 },
805 "ready.ft.table": function(e, ft){
806 table_mailbox_ready(ft, 'tls_policy_table');
807 },
808 "after.ft.filtering": function(e, ft){
809 table_mailbox_ready(ft, 'tls_policy_table');
810 }
811 },
812 "toggleSelector": "table tbody span.footable-toggle"
813 });
814 }
815 function draw_alias_table() {
816 ft_alias_table = FooTable.init('#alias_table', {
817 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200818 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
819 {"name":"id","title":"ID","style":{"min-width":"60px","width":"60px","text-align":"center"}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100820 {"sorted": true,"name":"address","title":lang.alias,"style":{"width":"250px"}},
821 {"name":"goto","title":lang.target_address},
822 {"name":"domain","title":lang.domain,"breakpoints":"xs sm"},
823 {"name":"public_comment","title":lang.public_comment,"breakpoints":"all"},
824 {"name":"private_comment","title":lang.private_comment,"breakpoints":"all"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200825 {"name":"sogo_visible","title":lang.sogo_visible,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';},"breakpoints":"all"},
826 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
827 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100828 ],
829 "empty": lang.empty,
830 "rows": $.ajax({
831 dataType: 'json',
832 url: '/api/v1/get/alias/all',
833 jsonp: false,
834 error: function () {
835 console.log('Cannot draw alias table');
836 },
837 success: function (data) {
838 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200839 item.action = '<div class="btn-group footable-actions">' +
840 '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
841 '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100842 '</div>';
843 item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
844 item.goto = escapeHtml(item.goto.replace(/,/g, " "));
845 if (item.public_comment !== null) {
846 item.public_comment = escapeHtml(item.public_comment);
847 }
848 else {
849 item.public_comment = '-';
850 }
851 if (item.private_comment !== null) {
852 item.private_comment = escapeHtml(item.private_comment);
853 }
854 else {
855 item.private_comment = '-';
856 }
857 if (item.is_catch_all == 1) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200858 item.address = '<div class="label label-default">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100859 }
860 else {
861 item.address = escapeHtml(item.address);
862 }
863 if (item.goto == "null@localhost") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200864 item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100865 }
866 else if (item.goto == "spam@localhost") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200867 item.goto = '<span class="label label-danger">' + lang.goto_spam + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100868 }
869 else if (item.goto == "ham@localhost") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200870 item.goto = '<span class="label label-success">' + lang.goto_ham + '</span>';
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100871 }
872 if (item.in_primary_domain !== "") {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200873 item.domain = '<i data-domainname="' + item.domain + '" class="bi bi-info-circle-fill alias-domain-info text-info" data-toggle="tooltip" title="' + lang.target_domain + ': ' + item.in_primary_domain + '"></i> ' + item.domain;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100874 }
875 });
876 }
877 }),
878 "paging": {
879 "enabled": true,
880 "limit": 5,
881 "size": pagination_size
882 },
883 "state": {
884 "enabled": true
885 },
886 "filtering": {
887 "enabled": true,
888 "delay": 1200,
889 "position": "left",
890 "connectors": false,
891 "placeholder": lang.filter_table
892 },
893 "components": {
894 "filtering": FooTable.domainFilter
895 },
896 "sorting": {
897 "enabled": true
898 },
899 "on": {
900 "destroy.ft.table": function(e, ft){
901 $('.refresh_table').attr('disabled', 'true');
902 },
903 "ready.ft.table": function(e, ft){
904 table_mailbox_ready(ft, 'alias_table');
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200905 $('.alias-domain-info').tooltip();
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100906 },
907 "after.ft.filtering": function(e, ft){
908 table_mailbox_ready(ft, 'alias_table');
909 }
910 },
911 "toggleSelector": "table tbody span.footable-toggle"
912 });
913 }
914
915 function draw_aliasdomain_table() {
916 ft_aliasdomain_table = FooTable.init('#aliasdomain_table', {
917 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200918 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px"},"filterable": false,"sortable": false,"type":"html"},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100919 {"sorted": true,"name":"alias_domain","title":lang.alias,"style":{"width":"250px"}},
920 {"name":"target_domain","title":lang.target_domain,"type":"html"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200921 {"name":"active","filterable": false,"style":{"min-width":"80px","width":"80px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
922 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"250px","width":"250px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100923 ],
924 "empty": lang.empty,
925 "rows": $.ajax({
926 dataType: 'json',
927 url: '/api/v1/get/alias-domain/all',
928 jsonp: false,
929 error: function () {
930 console.log('Cannot draw alias domain table');
931 },
932 success: function (data) {
933 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200934 item.action = '<div class="btn-group footable-actions">' +
935 '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-xs-third btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
936 '<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-xs btn-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
937 '<a href="#dnsInfoModal" class="btn btn-xs btn-xs-third btn-info" data-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 +0100938 '</div>';
939 item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
940 if(item.parent_is_backupmx == '1') {
941 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="label label-warning">' + lang.alias_domain_backupmx + '</div></span>';
942 } else {
943 item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
944 }
945 });
946 }
947 }),
948 "paging": {
949 "enabled": true,
950 "limit": 5,
951 "size": pagination_size
952 },
953 "state": {
954 "enabled": true
955 },
956 "filtering": {
957 "enabled": true,
958 "delay": 1200,
959 "position": "left",
960 "connectors": false,
961 "placeholder": lang.filter_table
962 },
963 "sorting": {
964 "enabled": true
965 },
966 "on": {
967 "destroy.ft.table": function(e, ft){
968 $('.refresh_table').attr('disabled', 'true');
969 },
970 "ready.ft.table": function(e, ft){
971 table_mailbox_ready(ft, 'aliasdomain_table');
972 },
973 "after.ft.filtering": function(e, ft){
974 table_mailbox_ready(ft, 'aliasdomain_table');
975 }
976 },
977 "toggleSelector": "table tbody span.footable-toggle"
978 });
979 }
980
981 function draw_sync_job_table() {
982 ft_syncjob_table = FooTable.init('#sync_job_table', {
983 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200984 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
985 {"sorted": true,"name":"id","title":"ID","style":{"min-width":"60px","width":"60px","text-align":"center"}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100986 {"name":"user2","title":lang.owner},
987 {"name":"server_w_port","title":"Server","breakpoints":"xs sm md","style":{"word-break":"break-all"}},
988 {"name":"exclude","title":lang.excludes,"breakpoints":"all"},
989 {"name":"mins_interval","title":lang.mins_interval,"breakpoints":"all"},
990 {"name":"last_run","title":lang.last_run,"breakpoints":"xs sm md"},
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100991 {"name":"exit_status","filterable": false,"title":lang.syncjob_last_run_result},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100992 {"name":"log","title":"Log"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200993 {"name":"active","filterable": false,"style":{"min-width":"70px","width":"70px"},"title":lang.active,"formatter": function(value){return 1==value?'<i class="bi bi-check-lg"></i>':0==value&&'<i class="bi bi-x-lg"></i>';}},
994 {"name":"is_running","filterable": false,"style":{"min-width":"120px","width":"100px"},"title":lang.status},
995 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100996 ],
997 "empty": lang.empty,
998 "rows": $.ajax({
999 dataType: 'json',
1000 url: '/api/v1/get/syncjobs/all/no_log',
1001 jsonp: false,
1002 error: function () {
1003 console.log('Cannot draw sync job table');
1004 },
1005 success: function (data) {
1006 $.each(data, function (i, item) {
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001007 item.log = '<a href="#syncjobLogModal" data-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001008 item.user2 = escapeHtml(item.user2);
1009 if (!item.exclude > 0) {
1010 item.exclude = '-';
1011 } else {
1012 item.exclude = '<code>' + item.exclude + '</code>';
1013 }
1014 item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001015 item.action = '<div class="btn-group footable-actions">' +
1016 '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1017 '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001018 '</div>';
1019 item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
1020 if (item.is_running == 1) {
1021 item.is_running = '<span id="active-script" class="label label-success">' + lang.running + '</span>';
1022 } else {
1023 item.is_running = '<span id="inactive-script" class="label label-warning">' + lang.waiting + '</span>';
1024 }
1025 if (!item.last_run > 0) {
1026 item.last_run = lang.waiting;
1027 }
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +01001028 if (item.success == null) {
1029 item.success = '-';
1030 item.exit_status = '';
1031 } else {
1032 item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
1033 }
1034 if (lang['syncjob_'+item.exit_status]) {
1035 item.exit_status = lang['syncjob_'+item.exit_status];
1036 } else if (item.success != '-') {
1037 item.exit_status = lang.syncjob_check_log;
1038 }
1039 item.exit_status = item.success + ' ' + item.exit_status;
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001040 });
1041 }
1042 }),
1043 "paging": {
1044 "enabled": true,
1045 "limit": 5,
1046 "size": pagination_size
1047 },
1048 "state": {
1049 "enabled": true
1050 },
1051 "filtering": {
1052 "enabled": true,
1053 "delay": 1200,
1054 "position": "left",
1055 "connectors": false,
1056 "placeholder": lang.filter_table
1057 },
1058 "sorting": {
1059 "enabled": true
1060 },
1061 "on": {
1062 "destroy.ft.table": function(e, ft){
1063 $('.refresh_table').attr('disabled', 'true');
1064 },
1065 "ready.ft.table": function(e, ft){
1066 table_mailbox_ready(ft, 'sync_job_table');
1067 },
1068 "after.ft.filtering": function(e, ft){
1069 table_mailbox_ready(ft, 'sync_job_table');
1070 }
1071 },
1072 "toggleSelector": "table tbody span.footable-toggle"
1073 });
1074 }
1075
1076 function draw_filter_table() {
1077 ft_filter_table = FooTable.init('#filter_table', {
1078 "columns": [
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001079 {"name":"chkbox","title":"","style":{"min-width":"60px","width":"60px","text-align":"center"},"filterable": false,"sortable": false,"type":"html"},
1080 {"name":"id","title":"ID","style":{"min-width":"60px","width":"60px","text-align":"center"}},
1081 {"name":"active","style":{"min-width":"80px","width":"80px"},"title":lang.active},
1082 {"name":"filter_type","style":{"min-width":"80px","width":"80px"},"title":"Type"},
1083 {"sorted": true,"name":"username","title":lang.owner,"style":{"min-width":"550px","width":"350px"}},
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001084 {"name":"script_desc","title":lang.description,"breakpoints":"xs"},
1085 {"name":"script_data","title":"Script","breakpoints":"all"},
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001086 {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","min-width":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"}
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001087 ],
1088 "empty": lang.empty,
1089 "rows": $.ajax({
1090 dataType: 'json',
1091 url: '/api/v1/get/filters/all',
1092 jsonp: false,
1093 error: function () {
1094 console.log('Cannot draw filter table');
1095 },
1096 success: function (data) {
1097 $.each(data, function (i, item) {
1098 if (item.active == 1) {
1099 item.active = '<span id="active-script" class="label label-success">' + lang.active + '</span>';
1100 } else {
1101 item.active = '<span id="inactive-script" class="label label-warning">' + lang.inactive + '</span>';
1102 }
1103 item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
1104 item.filter_type = '<div class="label label-default">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001105 item.action = '<div class="btn-group footable-actions">' +
1106 '<a href="/edit/filter/' + item.id + '" class="btn btn-xs btn-xs-half btn-default"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
1107 '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001108 '</div>';
1109 item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
1110 });
1111 }
1112 }),
1113 "paging": {
1114 "enabled": true,
1115 "limit": 5,
1116 "size": pagination_size
1117 },
1118 "state": {
1119 "enabled": true
1120 },
1121 "filtering": {
1122 "enabled": true,
1123 "delay": 1200,
1124 "position": "left",
1125 "connectors": false,
1126 "placeholder": lang.filter_table
1127 },
1128 "sorting": {
1129 "enabled": true
1130 },
1131 "on": {
1132 "destroy.ft.table": function(e, ft){
1133 $('.refresh_table').attr('disabled', 'true');
1134 },
1135 "ready.ft.table": function(e, ft){
1136 table_mailbox_ready(ft, 'filter_table');
1137 },
1138 "after.ft.filtering": function(e, ft){
1139 table_mailbox_ready(ft, 'filter_table');
1140 }
1141 },
1142 "toggleSelector": "table tbody span.footable-toggle"
1143 });
1144 };
1145
1146 $('body').on('click', 'span.footable-toggle', function () {
1147 event.stopPropagation();
1148 })
1149
1150 draw_domain_table();
1151 draw_mailbox_table();
1152 draw_resource_table();
1153 draw_alias_table();
1154 draw_aliasdomain_table();
1155 draw_sync_job_table();
1156 draw_filter_table();
1157 draw_bcc_table();
1158 draw_recipient_map_table();
1159 draw_tls_policy_table();
1160
1161});