mailbox.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  1. $(document).ready(function() {
  2. acl_data = JSON.parse(acl);
  3. // FooTable.domainFilter = FooTable.Filtering.extend({
  4. // construct: function(instance){
  5. // this._super(instance);
  6. // this.def = lang.all_domains;
  7. // this.$domain = null;
  8. // },
  9. // $create: function(){
  10. // this._super();
  11. // var self = this;
  12. // var domains = [];
  13. // $.each(self.ft.rows.all, function(i, row){
  14. // if((row.val().domain != null) && ($.inArray(row.val().domain, domains) === -1)) domains.push(row.val().domain);
  15. // });
  16. // $form_grp = $('<div/>', {'class': 'form-group'})
  17. // .append($('<label/>', {'class': 'sr-only', text: 'Domain'}))
  18. // .prependTo(self.$form);
  19. // self.$domain = $('<select/>', { 'class': 'aform-control' })
  20. // .on('change', {self: self}, self._onDomainDropdownChanged)
  21. // .append($('<option/>', {text: self.def}))
  22. // .appendTo($form_grp);
  23. // $.each(domains, function(i, domain){
  24. // domainname = $($.parseHTML(domain)).data('domainname')
  25. // if (domainname !== undefined) {
  26. // self.$domain.append($('<option/>').text(domainname));
  27. // } else {
  28. // self.$domain.append($('<option/>').text(domain));
  29. // }
  30. // });
  31. // },
  32. // _onDomainDropdownChanged: function(e){
  33. // var self = e.data.self,
  34. // selected = $(this).val();
  35. // if (selected !== self.def){
  36. // self.addFilter('domain', selected, ['domain']);
  37. // } else {
  38. // self.removeFilter('domain');
  39. // }
  40. // self.filter();
  41. // },
  42. // draw: function(){
  43. // this._super();
  44. // var domain = this.find('domain');
  45. // if (domain instanceof FooTable.Filter){
  46. // this.$domain.val(domain.query.val());
  47. // } else {
  48. // this.$domain.val(this.def);
  49. // }
  50. // $(this.$domain).closest("select").selectpicker();
  51. // }
  52. // });
  53. // Set paging
  54. // Clone mailbox mass actions
  55. $("div").find("[data-actions-header='true'").each(function() {
  56. $(this).html($(this).nextAll('.mass-actions-mailbox:first').html());
  57. });
  58. // Auto-fill domain quota when adding new domain
  59. auto_fill_quota = function(domain) {
  60. $.get("/api/v1/get/domain/" + domain, function(data){
  61. var result = $.parseJSON(JSON.stringify(data));
  62. def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576);
  63. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  64. if (max_new_mailbox_quota != '0') {
  65. $('.addInputQuotaExhausted').hide();
  66. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  67. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  68. $('#addInputQuota').val(def_new_mailbox_quota);
  69. }
  70. else {
  71. $('.addInputQuotaExhausted').show();
  72. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  73. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  74. $('#addInputQuota').val(max_new_mailbox_quota);
  75. }
  76. });
  77. }
  78. $('#addSelectDomain').on('change', function() {
  79. auto_fill_quota($('#addSelectDomain').val());
  80. });
  81. auto_fill_quota($('#addSelectDomain').val());
  82. // Read bcc local dests
  83. // Using ajax to not be a blocking moo
  84. $.get("/api/v1/get/bcc-destination-options", function(data){
  85. // Domains
  86. var optgroup = "<optgroup label='" + lang.domains + "'>";
  87. $.each(data.domains, function(index, domain){
  88. optgroup += "<option value='" + domain + "'>" + domain + "</option>"
  89. });
  90. optgroup += "</optgroup>"
  91. $('#bcc-local-dest').append(optgroup);
  92. // Alias domains
  93. var optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
  94. $.each(data.alias_domains, function(index, alias_domain){
  95. optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>"
  96. });
  97. optgroup += "</optgroup>"
  98. $('#bcc-local-dest').append(optgroup);
  99. // Mailboxes and aliases
  100. $.each(data.mailboxes, function(mailbox, aliases){
  101. var optgroup = "<optgroup label='" + mailbox + "'>";
  102. $.each(aliases, function(index, alias){
  103. optgroup += "<option value='" + alias + "'>" + alias + "</option>"
  104. });
  105. optgroup += "</optgroup>"
  106. $('#bcc-local-dest').append(optgroup);
  107. });
  108. // Finish
  109. $('#bcc-local-dest').find('option:selected').remove();
  110. $('#bcc-local-dest').selectpicker('refresh');
  111. });
  112. $(".goto_checkbox").click(function( event ) {
  113. $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
  114. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  115. $('#textarea_alias_goto').prop('disabled', true);
  116. }
  117. else {
  118. $("#textarea_alias_goto").removeAttr('disabled');
  119. }
  120. });
  121. $('#addAliasModal').on('show.bs.modal', function(e) {
  122. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  123. $('#textarea_alias_goto').prop('disabled', true);
  124. }
  125. else {
  126. $("#textarea_alias_goto").removeAttr('disabled');
  127. }
  128. });
  129. // Log modal
  130. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  131. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  132. $.ajax({
  133. url: '/inc/ajax/syncjob_logs.php',
  134. data: { id: syncjob_id },
  135. dataType: 'text',
  136. success: function(data){
  137. $(e.currentTarget).find('#logText').text(data);
  138. },
  139. error: function(xhr, status, error) {
  140. $(e.currentTarget).find('#logText').text(xhr.responseText);
  141. }
  142. });
  143. });
  144. // Log modal
  145. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  146. var domain = $(e.relatedTarget).data('domain');
  147. $('.dns-modal-body').html('<div class="spinner-border text-secondary" role="status"><span class="visually-hidden">Loading...</span></div>');
  148. $.ajax({
  149. url: '/inc/ajax/dns_diagnostics.php',
  150. data: { domain: domain },
  151. dataType: 'text',
  152. success: function(data){
  153. $('.dns-modal-body').html(data);
  154. },
  155. error: function(xhr, status, error) {
  156. $('.dns-modal-body').html(xhr.responseText);
  157. }
  158. });
  159. });
  160. // Sieve data modal
  161. $('#sieveDataModal').on('show.bs.modal', function(e) {
  162. var sieveScript = $(e.relatedTarget).data('sieve-script');
  163. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  164. });
  165. // Disable submit button on script change
  166. $('.textarea-code').on('keyup', function() {
  167. // Disable all "save" buttons, could be a "related button only" function, todo
  168. $('.add_sieve_script').attr({"disabled": true});
  169. });
  170. // Validate script data
  171. $(".validate_sieve").click(function( event ) {
  172. event.preventDefault();
  173. var validation_button = $(this);
  174. // Get script_data textarea content from form the button was clicked in
  175. var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
  176. $.ajax({
  177. dataType: 'json',
  178. url: "/inc/ajax/sieve_validation.php",
  179. type: "get",
  180. data: { script: script },
  181. complete: function(data) {
  182. var response = (data.responseText);
  183. response_obj = JSON.parse(response);
  184. if (response_obj.type == "success") {
  185. $(validation_button).next().attr({"disabled": false});
  186. }
  187. mailcow_alert_box(response_obj.msg, response_obj.type);
  188. },
  189. });
  190. });
  191. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  192. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  193. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  194. // });
  195. $('#addResourceModal').on('shown.bs.modal', function() {
  196. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  197. if ($("#multiple_bookings").val() == "custom") {
  198. $("#multiple_bookings_custom_div").show();
  199. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  200. }
  201. })
  202. $("#multiple_bookings_select").change(function() {
  203. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  204. if ($("#multiple_bookings").val() == "custom") {
  205. $("#multiple_bookings_custom_div").show();
  206. }
  207. else {
  208. $("#multiple_bookings_custom_div").hide();
  209. }
  210. });
  211. $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
  212. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  213. });
  214. });
  215. jQuery(function($){
  216. // http://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery
  217. var entityMap={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"};
  218. function escapeHtml(n){return String(n).replace(/[&<>"'`=\/]/g,function(n){return entityMap[n]})}
  219. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  220. 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]}
  221. 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"})}
  222. $(".refresh_table").on('click', function(e) {
  223. e.preventDefault();
  224. var table_name = $(this).data('table');
  225. $('#' + table_name).DataTable().ajax.reload();
  226. });
  227. function draw_domain_table() {
  228. $('#domain_table').DataTable({
  229. processing: true,
  230. serverSide: false,
  231. language: lang_datatables,
  232. ajax: {
  233. type: "GET",
  234. url: "/api/v1/get/domain/all",
  235. dataSrc: function(json){
  236. $.each(json, function(i, item) {
  237. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  238. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  239. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
  240. item.stats = item.msgs_total + "/" + item.bytes_total;
  241. if (!item.rl) item.rl = '∞';
  242. else {
  243. item.rl = $.map(item.rl, function(e){
  244. return e;
  245. }).join('/1');
  246. }
  247. item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
  248. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  249. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  250. item.action = '<div class="btn-group footable-actions">';
  251. if (role == "admin") {
  252. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-xs btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  253. '<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>' +
  254. '<a href="#dnsInfoModal" class="btn btn-xs btn-xs-third btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
  255. }
  256. else {
  257. 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>' +
  258. '<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>';
  259. }
  260. if (item.backupmx == 1) {
  261. if (item.relay_unknown_only == 1) {
  262. item.domain_name = '<div class="badge fs-5 bg-info">Relay Non-Local</div> ' + item.domain_name;
  263. } else if (item.relay_all_recipients == 1) {
  264. item.domain_name = '<div class="badge fs-5 bg-info">Relay All</div> ' + item.domain_name;
  265. } else {
  266. item.domain_name = '<div class="badge fs-5 bg-info">Relay</div> ' + item.domain_name;
  267. }
  268. }
  269. });
  270. return json;
  271. }
  272. },
  273. columns: [
  274. {
  275. // placeholder, so checkbox will not block child row toggle
  276. title: '',
  277. data: null,
  278. searchable: false,
  279. orderable: false,
  280. defaultContent: ''
  281. },
  282. {
  283. title: '',
  284. data: 'chkbox',
  285. searchable: false,
  286. orderable: false,
  287. defaultContent: ''
  288. },
  289. {
  290. title: lang.domain,
  291. data: 'domain_name'
  292. },
  293. {
  294. title: lang.aliases,
  295. data: 'aliases_in_domain'
  296. },
  297. {
  298. title: lang.mailboxes,
  299. data: 'mboxes_in_domain'
  300. },
  301. {
  302. title: lang.domain_quota,
  303. data: 'quota',
  304. render: function (data, type) {
  305. data = data.split("/");
  306. return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
  307. }
  308. },
  309. {
  310. title: lang.stats,
  311. data: 'stats',
  312. render: function (data, type) {
  313. data = data.split("/");
  314. return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
  315. }
  316. },
  317. {
  318. title: lang.mailbox_defquota,
  319. data: 'def_quota_for_mbox'
  320. },
  321. {
  322. title: lang.mailbox_quota,
  323. data: 'max_quota_for_mbox'
  324. },
  325. {
  326. title: 'RL',
  327. data: 'rl'
  328. },
  329. {
  330. title: lang.backup_mx,
  331. data: 'backupmx',
  332. redner: function (data, type){
  333. return 1==value ? '<i class="bi bi-check-lg"></i>' : 0==value && '<i class="bi bi-x-lg"></i>';
  334. }
  335. },
  336. {
  337. title: lang.domain_admins,
  338. data: 'domain_admins'
  339. },
  340. {
  341. title: lang.action,
  342. data: 'action'
  343. },
  344. ]
  345. });
  346. }
  347. function draw_mailbox_table() {
  348. $('#mailbox_table').DataTable({
  349. responsive : true,
  350. processing: true,
  351. serverSide: false,
  352. language: lang_datatables,
  353. ajax: {
  354. type: "GET",
  355. url: "/api/v1/get/mailbox/reduced",
  356. dataSrc: function(json){
  357. $.each(json, function (i, item) {
  358. item.quota = item.quota_used + "/" + item.quota;
  359. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  360. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  361. /*
  362. if (!item.rl) {
  363. item.rl = '∞';
  364. } else {
  365. item.rl = $.map(item.rl, function(e){
  366. return e;
  367. }).join('/1');
  368. if (item.rl_scope === 'domain') {
  369. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  370. }
  371. }
  372. */
  373. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  374. if (item.attributes.passwd_update != '0') {
  375. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  376. 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"});
  377. } else {
  378. item.last_pw_change = '-';
  379. }
  380. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  381. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  382. 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>';
  383. 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>';
  384. 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>';
  385. if (item.attributes.quarantine_notification === 'never') {
  386. item.quarantine_notification = lang.never;
  387. } else if (item.attributes.quarantine_notification === 'hourly') {
  388. item.quarantine_notification = lang.hourly;
  389. } else if (item.attributes.quarantine_notification === 'daily') {
  390. item.quarantine_notification = lang.daily;
  391. } else if (item.attributes.quarantine_notification === 'weekly') {
  392. item.quarantine_notification = lang.weekly;
  393. }
  394. if (item.attributes.quarantine_category === 'reject') {
  395. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  396. } else if (item.attributes.quarantine_category === 'add_header') {
  397. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  398. } else if (item.attributes.quarantine_category === 'all') {
  399. item.quarantine_category = lang.q_all;
  400. }
  401. if (acl_data.login_as === 1) {
  402. var btnSize = 'btn-xs-third';
  403. if (ALLOW_ADMIN_EMAIL_LOGIN) btnSize = 'btn-xs-quart';
  404. item.action = '<div class="btn-group footable-actions">' +
  405. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs ' + btnSize + ' btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  406. '<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>' +
  407. '<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>';
  408. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  409. 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>';
  410. }
  411. item.action += '</div>';
  412. }
  413. else {
  414. item.action = '<div class="btn-group">' +
  415. '<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>' +
  416. '<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>' +
  417. '</div>';
  418. }
  419. item.in_use = '<div class="progress">' +
  420. '<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" ' +
  421. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  422. item.username = escapeHtml(item.username);
  423. });
  424. return json;
  425. }
  426. },
  427. columns: [
  428. {
  429. // placeholder, so checkbox will not block child row toggle
  430. title: '',
  431. data: null,
  432. searchable: false,
  433. orderable: false,
  434. defaultContent: ''
  435. },
  436. {
  437. title: '',
  438. data: 'chkbox',
  439. searchable: false,
  440. orderable: false,
  441. defaultContent: ''
  442. },
  443. {
  444. title: lang.username,
  445. data: 'username'
  446. },
  447. {
  448. title: lang.fname,
  449. data: 'name'
  450. },
  451. {
  452. title: lang.domain,
  453. data: 'domain'
  454. },
  455. {
  456. title: lang.domain_quota,
  457. data: 'quota',
  458. render: function (data, type) {
  459. data = data.split("/");
  460. var of_q = (data[1] == 0 ? "∞" : humanFileSize(data[1]));
  461. return humanFileSize(data[0]) + " / " + of_q;
  462. }
  463. },
  464. {
  465. title: lang.tls_enforce_in,
  466. data: 'tls_enforce_in'
  467. },
  468. {
  469. title: lang.tls_enforce_out,
  470. data: 'tls_enforce_out'
  471. },
  472. {
  473. title: 'SMTP',
  474. data: 'smtp_access'
  475. },
  476. {
  477. title: 'IMAP',
  478. data: 'imap_access'
  479. },
  480. {
  481. title: 'POP3',
  482. data: 'pop3_access'
  483. },
  484. {
  485. title: lang.last_mail_login,
  486. data: 'last_mail_login'
  487. },
  488. {
  489. title: lang.last_pw_change,
  490. data: 'last_pw_change'
  491. },
  492. {
  493. title: lang.quarantine_notification,
  494. data: 'quarantine_notification'
  495. },
  496. {
  497. title: lang.quarantine_category,
  498. data: 'quarantine_category'
  499. },
  500. {
  501. title: lang.in_use,
  502. data: 'in_use'
  503. },
  504. {
  505. title: lang.msg_num,
  506. data: 'messages'
  507. },
  508. {
  509. title: lang.active,
  510. data: 'active',
  511. render: function (data, type) {
  512. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  513. }
  514. },
  515. {
  516. title: lang.action,
  517. data: 'action'
  518. },
  519. ]
  520. });
  521. }
  522. function draw_resource_table() {
  523. $('#resource_table').DataTable({
  524. processing: true,
  525. serverSide: false,
  526. language: lang_datatables,
  527. ajax: {
  528. type: "GET",
  529. url: "/api/v1/get/resource/all",
  530. dataSrc: function(json){
  531. $.each(json, function (i, item) {
  532. if (item.multiple_bookings == '0') {
  533. item.multiple_bookings = '<span id="active-script" class="badge fs-5 bg-success">' + lang.booking_0_short + '</span>';
  534. } else if (item.multiple_bookings == '-1') {
  535. item.multiple_bookings = '<span id="active-script" class="badge fs-5 bg-warning">' + lang.booking_lt0_short + '</span>';
  536. } else {
  537. item.multiple_bookings = '<span id="active-script" class="badge fs-5 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  538. }
  539. item.action = '<div class="btn-group footable-actions">' +
  540. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  541. '<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>' +
  542. '</div>';
  543. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  544. item.name = escapeHtml(item.name);
  545. });
  546. return json;
  547. }
  548. },
  549. columns: [
  550. {
  551. // placeholder, so checkbox will not block child row toggle
  552. title: '',
  553. data: null,
  554. searchable: false,
  555. orderable: false,
  556. defaultContent: ''
  557. },
  558. {
  559. title: '',
  560. data: 'chkbox',
  561. searchable: false,
  562. orderable: false,
  563. defaultContent: ''
  564. },
  565. {
  566. title: lang.description,
  567. data: 'description'
  568. },
  569. {
  570. title: lang.alias,
  571. data: 'name'
  572. },
  573. {
  574. title: lang.kind,
  575. data: 'kind'
  576. },
  577. {
  578. title: lang.domain,
  579. data: 'domain'
  580. },
  581. {
  582. title: lang.multiple_bookings,
  583. data: 'multiple_bookings'
  584. },
  585. {
  586. title: lang.active,
  587. data: 'active',
  588. render: function (data, type) {
  589. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  590. }
  591. },
  592. {
  593. title: lang.action,
  594. data: 'action'
  595. },
  596. ]
  597. });
  598. }
  599. function draw_bcc_table() {
  600. $('#bcc_table').DataTable({
  601. processing: true,
  602. serverSide: false,
  603. language: lang_datatables,
  604. ajax: {
  605. type: "GET",
  606. url: "/api/v1/get/bcc/all",
  607. dataSrc: function(json){
  608. $.each(json, function (i, item) {
  609. item.action = '<div class="btn-group footable-actions">' +
  610. '<a href="/edit/bcc/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  611. '<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>' +
  612. '</div>';
  613. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  614. item.local_dest = escapeHtml(item.local_dest);
  615. item.bcc_dest = escapeHtml(item.bcc_dest);
  616. if (item.type == 'sender') {
  617. item.type = '<span id="active-script" class="badge fs-5 bg-success">' + lang.bcc_sender_map + '</span>';
  618. } else {
  619. item.type = '<span id="inactive-script" class="badge fs-5 bg-warning">' + lang.bcc_rcpt_map + '</span>';
  620. }
  621. });
  622. return json;
  623. }
  624. },
  625. columns: [
  626. {
  627. // placeholder, so checkbox will not block child row toggle
  628. title: '',
  629. data: null,
  630. searchable: false,
  631. orderable: false,
  632. defaultContent: ''
  633. },
  634. {
  635. title: '',
  636. data: 'chkbox',
  637. searchable: false,
  638. orderable: false,
  639. defaultContent: ''
  640. },
  641. {
  642. title: 'ID',
  643. data: 'id'
  644. },
  645. {
  646. title: lang.bcc_type,
  647. data: 'type'
  648. },
  649. {
  650. title: lang.bcc_local_dest,
  651. data: 'local_dest'
  652. },
  653. {
  654. title: lang.bcc_destinations,
  655. data: 'bcc_dest'
  656. },
  657. {
  658. title: lang.domain,
  659. data: 'domain'
  660. },
  661. {
  662. title: lang.active,
  663. data: 'active',
  664. render: function (data, type) {
  665. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  666. }
  667. },
  668. {
  669. title: lang.action,
  670. data: 'action'
  671. },
  672. ]
  673. });
  674. }
  675. function draw_recipient_map_table() {
  676. $('#recipient_map_table').DataTable({
  677. processing: true,
  678. serverSide: false,
  679. language: lang_datatables,
  680. ajax: {
  681. type: "GET",
  682. url: "/api/v1/get/recipient_map/all",
  683. dataSrc: function(json){
  684. if (role !== "admin") return null;
  685. $.each(json, function (i, item) {
  686. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  687. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  688. item.action = '<div class="btn-group footable-actions">' +
  689. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  690. '<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>' +
  691. '</div>';
  692. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  693. });
  694. return json;
  695. }
  696. },
  697. columns: [
  698. {
  699. // placeholder, so checkbox will not block child row toggle
  700. title: '',
  701. data: null,
  702. searchable: false,
  703. orderable: false,
  704. defaultContent: ''
  705. },
  706. {
  707. title: '',
  708. data: 'chkbox',
  709. searchable: false,
  710. orderable: false,
  711. defaultContent: ''
  712. },
  713. {
  714. title: 'ID',
  715. data: 'id'
  716. },
  717. {
  718. title: lang.recipient_map_old,
  719. data: 'recipient_map_old'
  720. },
  721. {
  722. title: lang.recipient_map_new,
  723. data: 'recipient_map_new'
  724. },
  725. {
  726. title: lang.active,
  727. data: 'active',
  728. render: function (data, type) {
  729. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  730. }
  731. },
  732. {
  733. title: lang.action,
  734. data: 'action'
  735. },
  736. ]
  737. });
  738. }
  739. function draw_tls_policy_table() {
  740. $('#tls_policy_table').DataTable({
  741. processing: true,
  742. serverSide: false,
  743. language: lang_datatables,
  744. ajax: {
  745. type: "GET",
  746. url: "/api/v1/get/tls-policy-map/all",
  747. dataSrc: function(json){
  748. if (role !== "admin") return null;
  749. $.each(json, function (i, item) {
  750. item.dest = escapeHtml(item.dest);
  751. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  752. if (item.parameters == '') {
  753. item.parameters = '<code>-</code>';
  754. } else {
  755. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  756. }
  757. item.action = '<div class="btn-group footable-actions">' +
  758. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  759. '<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>' +
  760. '</div>';
  761. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  762. });
  763. return json;
  764. }
  765. },
  766. columns: [
  767. {
  768. // placeholder, so checkbox will not block child row toggle
  769. title: '',
  770. data: null,
  771. searchable: false,
  772. orderable: false,
  773. defaultContent: ''
  774. },
  775. {
  776. title: '',
  777. data: 'chkbox',
  778. searchable: false,
  779. orderable: false,
  780. defaultContent: ''
  781. },
  782. {
  783. title: 'ID',
  784. data: 'id'
  785. },
  786. {
  787. title: lang.tls_map_dest,
  788. data: 'dest'
  789. },
  790. {
  791. title: lang.tls_map_policy,
  792. data: 'policy'
  793. },
  794. {
  795. title: lang.tls_map_parameters,
  796. data: 'parameters'
  797. },
  798. {
  799. title: lang.domain,
  800. data: 'domain'
  801. },
  802. {
  803. title: lang.active,
  804. data: 'active',
  805. render: function (data, type) {
  806. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  807. }
  808. },
  809. {
  810. title: lang.action,
  811. data: 'action'
  812. },
  813. ]
  814. });
  815. }
  816. function draw_alias_table() {
  817. $('#alias_table').DataTable({
  818. processing: true,
  819. serverSide: false,
  820. language: lang_datatables,
  821. ajax: {
  822. type: "GET",
  823. url: "/api/v1/get/alias/all",
  824. dataSrc: function(json){
  825. $.each(json, function (i, item) {
  826. item.action = '<div class="btn-group footable-actions">' +
  827. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  828. '<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>' +
  829. '</div>';
  830. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  831. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  832. if (item.public_comment !== null) {
  833. item.public_comment = escapeHtml(item.public_comment);
  834. }
  835. else {
  836. item.public_comment = '-';
  837. }
  838. if (item.private_comment !== null) {
  839. item.private_comment = escapeHtml(item.private_comment);
  840. }
  841. else {
  842. item.private_comment = '-';
  843. }
  844. if (item.is_catch_all == 1) {
  845. item.address = '<div class="badge fs-5 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
  846. }
  847. else {
  848. item.address = escapeHtml(item.address);
  849. }
  850. if (item.goto == "null@localhost") {
  851. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  852. }
  853. else if (item.goto == "spam@localhost") {
  854. item.goto = '<span class="badge fs-5 bg-danger">' + lang.goto_spam + '</span>';
  855. }
  856. else if (item.goto == "ham@localhost") {
  857. item.goto = '<span class="badge fs-5 bg-success">' + lang.goto_ham + '</span>';
  858. }
  859. if (item.in_primary_domain !== "") {
  860. 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;
  861. }
  862. });
  863. return json;
  864. }
  865. },
  866. columns: [
  867. {
  868. // placeholder, so checkbox will not block child row toggle
  869. title: '',
  870. data: null,
  871. searchable: false,
  872. orderable: false,
  873. defaultContent: ''
  874. },
  875. {
  876. title: '',
  877. data: 'chkbox',
  878. searchable: false,
  879. orderable: false,
  880. defaultContent: ''
  881. },
  882. {
  883. title: 'ID',
  884. data: 'id'
  885. },
  886. {
  887. title: lang.alias,
  888. data: 'address'
  889. },
  890. {
  891. title: lang.target_address,
  892. data: 'goto'
  893. },
  894. {
  895. title: lang.bcc_destinations,
  896. data: 'bcc_dest'
  897. },
  898. {
  899. title: lang.domain,
  900. data: 'domain'
  901. },
  902. {
  903. title: lang.public_comment,
  904. data: 'public_comment'
  905. },
  906. {
  907. title: lang.private_comment,
  908. data: 'private_comment'
  909. },
  910. {
  911. title: lang.sogo_visible,
  912. data: 'sogo_visible'
  913. },
  914. {
  915. title: lang.active,
  916. data: 'active',
  917. render: function (data, type) {
  918. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  919. }
  920. },
  921. {
  922. title: lang.action,
  923. data: 'action'
  924. },
  925. ]
  926. });
  927. }
  928. function draw_aliasdomain_table() {
  929. $('#aliasdomain_table').DataTable({
  930. processing: true,
  931. serverSide: false,
  932. language: lang_datatables,
  933. ajax: {
  934. type: "GET",
  935. url: "/api/v1/get/alias-domain/all",
  936. dataSrc: function(json){
  937. $.each(json, function (i, item) {
  938. item.action = '<div class="btn-group footable-actions">' +
  939. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-xs btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  940. '<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>' +
  941. '<a href="#dnsInfoModal" class="btn btn-xs btn-xs-third btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><i class="bi bi-globe2"></i> DNS</a></div>' +
  942. '</div>';
  943. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  944. if(item.parent_is_backupmx == '1') {
  945. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="badge fs-5 bg-warning">' + lang.alias_domain_backupmx + '</div></span>';
  946. } else {
  947. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  948. }
  949. });
  950. return json;
  951. }
  952. },
  953. columns: [
  954. {
  955. // placeholder, so checkbox will not block child row toggle
  956. title: '',
  957. data: null,
  958. searchable: false,
  959. orderable: false,
  960. defaultContent: ''
  961. },
  962. {
  963. title: '',
  964. data: 'chkbox',
  965. searchable: false,
  966. orderable: false,
  967. defaultContent: ''
  968. },
  969. {
  970. title: lang.alias,
  971. data: 'alias_domain'
  972. },
  973. {
  974. title: lang.target_domain,
  975. data: 'target_domain'
  976. },
  977. {
  978. title: lang.bcc_local_dest,
  979. data: 'local_dest'
  980. },
  981. {
  982. title: lang.bcc_destinations,
  983. data: 'bcc_dest'
  984. },
  985. {
  986. title: lang.domain,
  987. data: 'domain'
  988. },
  989. {
  990. title: lang.active,
  991. data: 'active',
  992. render: function (data, type) {
  993. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  994. }
  995. },
  996. {
  997. title: lang.action,
  998. data: 'action'
  999. },
  1000. ]
  1001. });
  1002. }
  1003. function draw_sync_job_table() {
  1004. $('#sync_job_table').DataTable({
  1005. processing: true,
  1006. serverSide: false,
  1007. language: lang_datatables,
  1008. ajax: {
  1009. type: "GET",
  1010. url: "/api/v1/get/syncjobs/all/no_log",
  1011. dataSrc: function(json){
  1012. $.each(json, function (i, item) {
  1013. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
  1014. item.user2 = escapeHtml(item.user2);
  1015. if (!item.exclude > 0) {
  1016. item.exclude = '-';
  1017. } else {
  1018. item.exclude = '<code>' + item.exclude + '</code>';
  1019. }
  1020. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  1021. item.action = '<div class="btn-group footable-actions">' +
  1022. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1023. '<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>' +
  1024. '</div>';
  1025. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  1026. if (item.is_running == 1) {
  1027. item.is_running = '<span id="active-script" class="badge fs-5 bg-success">' + lang.running + '</span>';
  1028. } else {
  1029. item.is_running = '<span id="inactive-script" class="badge fs-5 bg-warning">' + lang.waiting + '</span>';
  1030. }
  1031. if (!item.last_run > 0) {
  1032. item.last_run = lang.waiting;
  1033. }
  1034. if (item.success == null) {
  1035. item.success = '-';
  1036. item.exit_status = '';
  1037. } else {
  1038. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1039. }
  1040. if (lang['syncjob_'+item.exit_status]) {
  1041. item.exit_status = lang['syncjob_'+item.exit_status];
  1042. } else if (item.success != '-') {
  1043. item.exit_status = lang.syncjob_check_log;
  1044. }
  1045. item.exit_status = item.success + ' ' + item.exit_status;
  1046. });
  1047. return json;
  1048. }
  1049. },
  1050. columns: [
  1051. {
  1052. // placeholder, so checkbox will not block child row toggle
  1053. title: '',
  1054. data: null,
  1055. searchable: false,
  1056. orderable: false,
  1057. defaultContent: ''
  1058. },
  1059. {
  1060. title: '',
  1061. data: 'chkbox',
  1062. searchable: false,
  1063. orderable: false,
  1064. defaultContent: ''
  1065. },
  1066. {
  1067. title: 'ID',
  1068. data: 'id'
  1069. },
  1070. {
  1071. title: lang.owner,
  1072. data: 'user2'
  1073. },
  1074. {
  1075. title: 'Server',
  1076. data: 'server_w_port'
  1077. },
  1078. {
  1079. title: lang.excludes,
  1080. data: 'exclude'
  1081. },
  1082. {
  1083. title: lang.mins_interval,
  1084. data: 'mins_interval'
  1085. },
  1086. {
  1087. title: lang.last_run,
  1088. data: 'last_run'
  1089. },
  1090. {
  1091. title: lang.syncjob_last_run_result,
  1092. data: 'exit_status'
  1093. },
  1094. {
  1095. title: lang.status,
  1096. data: 'is_running'
  1097. },
  1098. {
  1099. title: lang.active,
  1100. data: 'active',
  1101. render: function (data, type) {
  1102. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1103. }
  1104. },
  1105. {
  1106. title: 'Log',
  1107. data: 'log'
  1108. },
  1109. {
  1110. title: lang.action,
  1111. data: 'action'
  1112. },
  1113. ]
  1114. });
  1115. }
  1116. function draw_filter_table() {
  1117. $('#filter_table').DataTable({
  1118. processing: true,
  1119. serverSide: false,
  1120. language: lang_datatables,
  1121. ajax: {
  1122. type: "GET",
  1123. url: "/api/v1/get/filters/all",
  1124. dataSrc: function(json){
  1125. $.each(json, function (i, item) {
  1126. if (item.active == 1) {
  1127. item.active = '<span id="active-script" class="badge fs-5 bg-success">' + lang.active + '</span>';
  1128. } else {
  1129. item.active = '<span id="inactive-script" class="badge fs-5 bg-warning">' + lang.inactive + '</span>';
  1130. }
  1131. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1132. item.filter_type = '<div class="badge fs-5 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1133. item.action = '<div class="btn-group footable-actions">' +
  1134. '<a href="/edit/filter/' + 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-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>' +
  1136. '</div>';
  1137. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1138. });
  1139. return json;
  1140. }
  1141. },
  1142. columns: [
  1143. {
  1144. // placeholder, so checkbox will not block child row toggle
  1145. title: '',
  1146. data: null,
  1147. searchable: false,
  1148. orderable: false,
  1149. defaultContent: ''
  1150. },
  1151. {
  1152. title: '',
  1153. data: 'chkbox',
  1154. searchable: false,
  1155. orderable: false,
  1156. defaultContent: ''
  1157. },
  1158. {
  1159. title: 'ID',
  1160. data: 'id'
  1161. },
  1162. {
  1163. title: lang.active,
  1164. data: 'active'
  1165. },
  1166. {
  1167. title: lang.filter_type,
  1168. data: 'Type'
  1169. },
  1170. {
  1171. title: lang.owner,
  1172. data: 'username'
  1173. },
  1174. {
  1175. title: lang.description,
  1176. data: 'script_desc'
  1177. },
  1178. {
  1179. title: 'Script',
  1180. data: 'script_data'
  1181. },
  1182. {
  1183. title: lang.action,
  1184. data: 'action'
  1185. },
  1186. ]
  1187. });
  1188. };
  1189. // detect element visibility changes
  1190. function onVisible(element, callback) {
  1191. $(element).ready(function() {
  1192. element_object = document.querySelector(element)
  1193. new IntersectionObserver((entries, observer) => {
  1194. entries.forEach(entry => {
  1195. if(entry.intersectionRatio > 0) {
  1196. callback(element_object);
  1197. observer.disconnect();
  1198. }
  1199. });
  1200. }).observe(element_object);
  1201. });
  1202. }
  1203. // Load only if the tab is visible
  1204. onVisible("[id^=domain_table]", () => draw_domain_table());
  1205. onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
  1206. onVisible("[id^=resource_table]", () => draw_resource_table());
  1207. onVisible("[id^=alias_table]", () => draw_alias_table());
  1208. onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
  1209. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  1210. onVisible("[id^=filter_table]", () => draw_filter_table());
  1211. onVisible("[id^=bcc_table]", () => draw_bcc_table());
  1212. onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
  1213. onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
  1214. });