mailbox.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  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">';
  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. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  344. },
  345. ]
  346. });
  347. }
  348. function draw_mailbox_table() {
  349. $('#mailbox_table').DataTable({
  350. responsive : true,
  351. processing: true,
  352. serverSide: false,
  353. language: lang_datatables,
  354. ajax: {
  355. type: "GET",
  356. url: "/api/v1/get/mailbox/reduced",
  357. dataSrc: function(json){
  358. $.each(json, function (i, item) {
  359. item.quota = item.quota_used + "/" + item.quota;
  360. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  361. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  362. /*
  363. if (!item.rl) {
  364. item.rl = '∞';
  365. } else {
  366. item.rl = $.map(item.rl, function(e){
  367. return e;
  368. }).join('/1');
  369. if (item.rl_scope === 'domain') {
  370. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  371. }
  372. }
  373. */
  374. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  375. if (item.attributes.passwd_update != '0') {
  376. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  377. 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"});
  378. } else {
  379. item.last_pw_change = '-';
  380. }
  381. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  382. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  383. 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>';
  384. 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>';
  385. 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>';
  386. if (item.attributes.quarantine_notification === 'never') {
  387. item.quarantine_notification = lang.never;
  388. } else if (item.attributes.quarantine_notification === 'hourly') {
  389. item.quarantine_notification = lang.hourly;
  390. } else if (item.attributes.quarantine_notification === 'daily') {
  391. item.quarantine_notification = lang.daily;
  392. } else if (item.attributes.quarantine_notification === 'weekly') {
  393. item.quarantine_notification = lang.weekly;
  394. }
  395. if (item.attributes.quarantine_category === 'reject') {
  396. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  397. } else if (item.attributes.quarantine_category === 'add_header') {
  398. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  399. } else if (item.attributes.quarantine_category === 'all') {
  400. item.quarantine_category = lang.q_all;
  401. }
  402. if (acl_data.login_as === 1) {
  403. var btnSize = 'btn-xs-third';
  404. if (ALLOW_ADMIN_EMAIL_LOGIN) btnSize = 'btn-xs-quart';
  405. item.action = '<div class="btn-group">' +
  406. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs ' + btnSize + ' btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  407. '<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>' +
  408. '<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>';
  409. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  410. 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>';
  411. }
  412. item.action += '</div>';
  413. }
  414. else {
  415. item.action = '<div class="btn-group">' +
  416. '<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>' +
  417. '<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>' +
  418. '</div>';
  419. }
  420. item.in_use = '<div class="progress">' +
  421. '<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" ' +
  422. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  423. item.username = escapeHtml(item.username);
  424. });
  425. return json;
  426. }
  427. },
  428. columns: [
  429. {
  430. // placeholder, so checkbox will not block child row toggle
  431. title: '',
  432. data: null,
  433. searchable: false,
  434. orderable: false,
  435. defaultContent: ''
  436. },
  437. {
  438. title: '',
  439. data: 'chkbox',
  440. searchable: false,
  441. orderable: false,
  442. defaultContent: ''
  443. },
  444. {
  445. title: lang.username,
  446. data: 'username'
  447. },
  448. {
  449. title: lang.fname,
  450. data: 'name'
  451. },
  452. {
  453. title: lang.domain,
  454. data: 'domain'
  455. },
  456. {
  457. title: lang.domain_quota,
  458. data: 'quota',
  459. render: function (data, type) {
  460. data = data.split("/");
  461. var of_q = (data[1] == 0 ? "∞" : humanFileSize(data[1]));
  462. return humanFileSize(data[0]) + " / " + of_q;
  463. }
  464. },
  465. {
  466. title: lang.tls_enforce_in,
  467. data: 'tls_enforce_in'
  468. },
  469. {
  470. title: lang.tls_enforce_out,
  471. data: 'tls_enforce_out'
  472. },
  473. {
  474. title: 'SMTP',
  475. data: 'smtp_access'
  476. },
  477. {
  478. title: 'IMAP',
  479. data: 'imap_access'
  480. },
  481. {
  482. title: 'POP3',
  483. data: 'pop3_access'
  484. },
  485. {
  486. title: lang.last_mail_login,
  487. data: 'last_mail_login'
  488. },
  489. {
  490. title: lang.last_pw_change,
  491. data: 'last_pw_change'
  492. },
  493. {
  494. title: lang.quarantine_notification,
  495. data: 'quarantine_notification'
  496. },
  497. {
  498. title: lang.quarantine_category,
  499. data: 'quarantine_category'
  500. },
  501. {
  502. title: lang.in_use,
  503. data: 'in_use'
  504. },
  505. {
  506. title: lang.msg_num,
  507. data: 'messages'
  508. },
  509. {
  510. title: lang.active,
  511. data: 'active',
  512. render: function (data, type) {
  513. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  514. }
  515. },
  516. {
  517. title: lang.action,
  518. data: 'action',
  519. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  520. },
  521. ]
  522. });
  523. }
  524. function draw_resource_table() {
  525. $('#resource_table').DataTable({
  526. processing: true,
  527. serverSide: false,
  528. language: lang_datatables,
  529. ajax: {
  530. type: "GET",
  531. url: "/api/v1/get/resource/all",
  532. dataSrc: function(json){
  533. $.each(json, function (i, item) {
  534. if (item.multiple_bookings == '0') {
  535. item.multiple_bookings = '<span id="active-script" class="badge fs-5 bg-success">' + lang.booking_0_short + '</span>';
  536. } else if (item.multiple_bookings == '-1') {
  537. item.multiple_bookings = '<span id="active-script" class="badge fs-5 bg-warning">' + lang.booking_lt0_short + '</span>';
  538. } else {
  539. item.multiple_bookings = '<span id="active-script" class="badge fs-5 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  540. }
  541. item.action = '<div class="btn-group">' +
  542. '<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>' +
  543. '<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>' +
  544. '</div>';
  545. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  546. item.name = escapeHtml(item.name);
  547. });
  548. return json;
  549. }
  550. },
  551. columns: [
  552. {
  553. // placeholder, so checkbox will not block child row toggle
  554. title: '',
  555. data: null,
  556. searchable: false,
  557. orderable: false,
  558. defaultContent: ''
  559. },
  560. {
  561. title: '',
  562. data: 'chkbox',
  563. searchable: false,
  564. orderable: false,
  565. defaultContent: ''
  566. },
  567. {
  568. title: lang.description,
  569. data: 'description'
  570. },
  571. {
  572. title: lang.alias,
  573. data: 'name'
  574. },
  575. {
  576. title: lang.kind,
  577. data: 'kind'
  578. },
  579. {
  580. title: lang.domain,
  581. data: 'domain'
  582. },
  583. {
  584. title: lang.multiple_bookings,
  585. data: 'multiple_bookings'
  586. },
  587. {
  588. title: lang.active,
  589. data: 'active',
  590. render: function (data, type) {
  591. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  592. }
  593. },
  594. {
  595. title: lang.action,
  596. data: 'action',
  597. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  598. },
  599. ]
  600. });
  601. }
  602. function draw_bcc_table() {
  603. $('#bcc_table').DataTable({
  604. processing: true,
  605. serverSide: false,
  606. language: lang_datatables,
  607. ajax: {
  608. type: "GET",
  609. url: "/api/v1/get/bcc/all",
  610. dataSrc: function(json){
  611. $.each(json, function (i, item) {
  612. item.action = '<div class="btn-group">' +
  613. '<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>' +
  614. '<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>' +
  615. '</div>';
  616. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  617. item.local_dest = escapeHtml(item.local_dest);
  618. item.bcc_dest = escapeHtml(item.bcc_dest);
  619. if (item.type == 'sender') {
  620. item.type = '<span id="active-script" class="badge fs-5 bg-success">' + lang.bcc_sender_map + '</span>';
  621. } else {
  622. item.type = '<span id="inactive-script" class="badge fs-5 bg-warning">' + lang.bcc_rcpt_map + '</span>';
  623. }
  624. });
  625. return json;
  626. }
  627. },
  628. columns: [
  629. {
  630. // placeholder, so checkbox will not block child row toggle
  631. title: '',
  632. data: null,
  633. searchable: false,
  634. orderable: false,
  635. defaultContent: ''
  636. },
  637. {
  638. title: '',
  639. data: 'chkbox',
  640. searchable: false,
  641. orderable: false,
  642. defaultContent: ''
  643. },
  644. {
  645. title: 'ID',
  646. data: 'id'
  647. },
  648. {
  649. title: lang.bcc_type,
  650. data: 'type'
  651. },
  652. {
  653. title: lang.bcc_local_dest,
  654. data: 'local_dest'
  655. },
  656. {
  657. title: lang.bcc_destinations,
  658. data: 'bcc_dest'
  659. },
  660. {
  661. title: lang.domain,
  662. data: 'domain'
  663. },
  664. {
  665. title: lang.active,
  666. data: 'active',
  667. render: function (data, type) {
  668. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  669. }
  670. },
  671. {
  672. title: lang.action,
  673. data: 'action',
  674. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  675. },
  676. ]
  677. });
  678. }
  679. function draw_recipient_map_table() {
  680. $('#recipient_map_table').DataTable({
  681. processing: true,
  682. serverSide: false,
  683. language: lang_datatables,
  684. ajax: {
  685. type: "GET",
  686. url: "/api/v1/get/recipient_map/all",
  687. dataSrc: function(json){
  688. if (role !== "admin") return null;
  689. $.each(json, function (i, item) {
  690. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  691. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  692. item.action = '<div class="btn-group">' +
  693. '<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>' +
  694. '<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>' +
  695. '</div>';
  696. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  697. });
  698. return json;
  699. }
  700. },
  701. columns: [
  702. {
  703. // placeholder, so checkbox will not block child row toggle
  704. title: '',
  705. data: null,
  706. searchable: false,
  707. orderable: false,
  708. defaultContent: ''
  709. },
  710. {
  711. title: '',
  712. data: 'chkbox',
  713. searchable: false,
  714. orderable: false,
  715. defaultContent: ''
  716. },
  717. {
  718. title: 'ID',
  719. data: 'id'
  720. },
  721. {
  722. title: lang.recipient_map_old,
  723. data: 'recipient_map_old'
  724. },
  725. {
  726. title: lang.recipient_map_new,
  727. data: 'recipient_map_new'
  728. },
  729. {
  730. title: lang.active,
  731. data: 'active',
  732. render: function (data, type) {
  733. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  734. }
  735. },
  736. {
  737. title: lang.action,
  738. data: 'action',
  739. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  740. },
  741. ]
  742. });
  743. }
  744. function draw_tls_policy_table() {
  745. $('#tls_policy_table').DataTable({
  746. processing: true,
  747. serverSide: false,
  748. language: lang_datatables,
  749. ajax: {
  750. type: "GET",
  751. url: "/api/v1/get/tls-policy-map/all",
  752. dataSrc: function(json){
  753. if (role !== "admin") return null;
  754. $.each(json, function (i, item) {
  755. item.dest = escapeHtml(item.dest);
  756. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  757. if (item.parameters == '') {
  758. item.parameters = '<code>-</code>';
  759. } else {
  760. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  761. }
  762. item.action = '<div class="btn-group">' +
  763. '<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>' +
  764. '<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>' +
  765. '</div>';
  766. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  767. });
  768. return json;
  769. }
  770. },
  771. columns: [
  772. {
  773. // placeholder, so checkbox will not block child row toggle
  774. title: '',
  775. data: null,
  776. searchable: false,
  777. orderable: false,
  778. defaultContent: ''
  779. },
  780. {
  781. title: '',
  782. data: 'chkbox',
  783. searchable: false,
  784. orderable: false,
  785. defaultContent: ''
  786. },
  787. {
  788. title: 'ID',
  789. data: 'id'
  790. },
  791. {
  792. title: lang.tls_map_dest,
  793. data: 'dest'
  794. },
  795. {
  796. title: lang.tls_map_policy,
  797. data: 'policy'
  798. },
  799. {
  800. title: lang.tls_map_parameters,
  801. data: 'parameters'
  802. },
  803. {
  804. title: lang.domain,
  805. data: 'domain'
  806. },
  807. {
  808. title: lang.active,
  809. data: 'active',
  810. render: function (data, type) {
  811. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  812. }
  813. },
  814. {
  815. title: lang.action,
  816. data: 'action',
  817. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  818. },
  819. ]
  820. });
  821. }
  822. function draw_alias_table() {
  823. $('#alias_table').DataTable({
  824. processing: true,
  825. serverSide: false,
  826. language: lang_datatables,
  827. ajax: {
  828. type: "GET",
  829. url: "/api/v1/get/alias/all",
  830. dataSrc: function(json){
  831. $.each(json, function (i, item) {
  832. item.action = '<div class="btn-group">' +
  833. '<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>' +
  834. '<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>' +
  835. '</div>';
  836. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  837. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  838. if (item.public_comment !== null) {
  839. item.public_comment = escapeHtml(item.public_comment);
  840. }
  841. else {
  842. item.public_comment = '-';
  843. }
  844. if (item.private_comment !== null) {
  845. item.private_comment = escapeHtml(item.private_comment);
  846. }
  847. else {
  848. item.private_comment = '-';
  849. }
  850. if (item.is_catch_all == 1) {
  851. item.address = '<div class="badge fs-5 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
  852. }
  853. else {
  854. item.address = escapeHtml(item.address);
  855. }
  856. if (item.goto == "null@localhost") {
  857. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  858. }
  859. else if (item.goto == "spam@localhost") {
  860. item.goto = '<span class="badge fs-5 bg-danger">' + lang.goto_spam + '</span>';
  861. }
  862. else if (item.goto == "ham@localhost") {
  863. item.goto = '<span class="badge fs-5 bg-success">' + lang.goto_ham + '</span>';
  864. }
  865. if (item.in_primary_domain !== "") {
  866. 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;
  867. }
  868. });
  869. return json;
  870. }
  871. },
  872. columns: [
  873. {
  874. // placeholder, so checkbox will not block child row toggle
  875. title: '',
  876. data: null,
  877. searchable: false,
  878. orderable: false,
  879. defaultContent: ''
  880. },
  881. {
  882. title: '',
  883. data: 'chkbox',
  884. searchable: false,
  885. orderable: false,
  886. defaultContent: ''
  887. },
  888. {
  889. title: 'ID',
  890. data: 'id'
  891. },
  892. {
  893. title: lang.alias,
  894. data: 'address'
  895. },
  896. {
  897. title: lang.target_address,
  898. data: 'goto'
  899. },
  900. {
  901. title: lang.bcc_destinations,
  902. data: 'bcc_dest'
  903. },
  904. {
  905. title: lang.domain,
  906. data: 'domain'
  907. },
  908. {
  909. title: lang.public_comment,
  910. data: 'public_comment'
  911. },
  912. {
  913. title: lang.private_comment,
  914. data: 'private_comment'
  915. },
  916. {
  917. title: lang.sogo_visible,
  918. data: 'sogo_visible'
  919. },
  920. {
  921. title: lang.active,
  922. data: 'active',
  923. render: function (data, type) {
  924. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  925. }
  926. },
  927. {
  928. title: lang.action,
  929. data: 'action',
  930. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  931. },
  932. ]
  933. });
  934. }
  935. function draw_aliasdomain_table() {
  936. $('#aliasdomain_table').DataTable({
  937. processing: true,
  938. serverSide: false,
  939. language: lang_datatables,
  940. ajax: {
  941. type: "GET",
  942. url: "/api/v1/get/alias-domain/all",
  943. dataSrc: function(json){
  944. $.each(json, function (i, item) {
  945. item.action = '<div class="btn-group">' +
  946. '<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>' +
  947. '<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>' +
  948. '<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>' +
  949. '</div>';
  950. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  951. if(item.parent_is_backupmx == '1') {
  952. 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>';
  953. } else {
  954. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  955. }
  956. });
  957. return json;
  958. }
  959. },
  960. columns: [
  961. {
  962. // placeholder, so checkbox will not block child row toggle
  963. title: '',
  964. data: null,
  965. searchable: false,
  966. orderable: false,
  967. defaultContent: ''
  968. },
  969. {
  970. title: '',
  971. data: 'chkbox',
  972. searchable: false,
  973. orderable: false,
  974. defaultContent: ''
  975. },
  976. {
  977. title: lang.alias,
  978. data: 'alias_domain'
  979. },
  980. {
  981. title: lang.target_domain,
  982. data: 'target_domain'
  983. },
  984. {
  985. title: lang.bcc_local_dest,
  986. data: 'local_dest'
  987. },
  988. {
  989. title: lang.bcc_destinations,
  990. data: 'bcc_dest'
  991. },
  992. {
  993. title: lang.domain,
  994. data: 'domain'
  995. },
  996. {
  997. title: lang.active,
  998. data: 'active',
  999. render: function (data, type) {
  1000. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1001. }
  1002. },
  1003. {
  1004. title: lang.action,
  1005. data: 'action',
  1006. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  1007. },
  1008. ]
  1009. });
  1010. }
  1011. function draw_sync_job_table() {
  1012. $('#sync_job_table').DataTable({
  1013. processing: true,
  1014. serverSide: false,
  1015. language: lang_datatables,
  1016. ajax: {
  1017. type: "GET",
  1018. url: "/api/v1/get/syncjobs/all/no_log",
  1019. dataSrc: function(json){
  1020. $.each(json, function (i, item) {
  1021. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
  1022. item.user2 = escapeHtml(item.user2);
  1023. if (!item.exclude > 0) {
  1024. item.exclude = '-';
  1025. } else {
  1026. item.exclude = '<code>' + item.exclude + '</code>';
  1027. }
  1028. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  1029. item.action = '<div class="btn-group">' +
  1030. '<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>' +
  1031. '<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>' +
  1032. '</div>';
  1033. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  1034. if (item.is_running == 1) {
  1035. item.is_running = '<span id="active-script" class="badge fs-5 bg-success">' + lang.running + '</span>';
  1036. } else {
  1037. item.is_running = '<span id="inactive-script" class="badge fs-5 bg-warning">' + lang.waiting + '</span>';
  1038. }
  1039. if (!item.last_run > 0) {
  1040. item.last_run = lang.waiting;
  1041. }
  1042. if (item.success == null) {
  1043. item.success = '-';
  1044. item.exit_status = '';
  1045. } else {
  1046. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1047. }
  1048. if (lang['syncjob_'+item.exit_status]) {
  1049. item.exit_status = lang['syncjob_'+item.exit_status];
  1050. } else if (item.success != '-') {
  1051. item.exit_status = lang.syncjob_check_log;
  1052. }
  1053. item.exit_status = item.success + ' ' + item.exit_status;
  1054. });
  1055. return json;
  1056. }
  1057. },
  1058. columns: [
  1059. {
  1060. // placeholder, so checkbox will not block child row toggle
  1061. title: '',
  1062. data: null,
  1063. searchable: false,
  1064. orderable: false,
  1065. defaultContent: ''
  1066. },
  1067. {
  1068. title: '',
  1069. data: 'chkbox',
  1070. searchable: false,
  1071. orderable: false,
  1072. defaultContent: ''
  1073. },
  1074. {
  1075. title: 'ID',
  1076. data: 'id'
  1077. },
  1078. {
  1079. title: lang.owner,
  1080. data: 'user2'
  1081. },
  1082. {
  1083. title: 'Server',
  1084. data: 'server_w_port'
  1085. },
  1086. {
  1087. title: lang.excludes,
  1088. data: 'exclude'
  1089. },
  1090. {
  1091. title: lang.mins_interval,
  1092. data: 'mins_interval'
  1093. },
  1094. {
  1095. title: lang.last_run,
  1096. data: 'last_run'
  1097. },
  1098. {
  1099. title: lang.syncjob_last_run_result,
  1100. data: 'exit_status'
  1101. },
  1102. {
  1103. title: lang.status,
  1104. data: 'is_running'
  1105. },
  1106. {
  1107. title: lang.active,
  1108. data: 'active',
  1109. render: function (data, type) {
  1110. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1111. }
  1112. },
  1113. {
  1114. title: 'Log',
  1115. data: 'log'
  1116. },
  1117. {
  1118. title: lang.action,
  1119. data: 'action',
  1120. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  1121. },
  1122. ]
  1123. });
  1124. }
  1125. function draw_filter_table() {
  1126. $('#filter_table').DataTable({
  1127. processing: true,
  1128. serverSide: false,
  1129. language: lang_datatables,
  1130. ajax: {
  1131. type: "GET",
  1132. url: "/api/v1/get/filters/all",
  1133. dataSrc: function(json){
  1134. $.each(json, function (i, item) {
  1135. if (item.active == 1) {
  1136. item.active = '<span id="active-script" class="badge fs-5 bg-success">' + lang.active + '</span>';
  1137. } else {
  1138. item.active = '<span id="inactive-script" class="badge fs-5 bg-warning">' + lang.inactive + '</span>';
  1139. }
  1140. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1141. item.filter_type = '<div class="badge fs-5 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1142. item.action = '<div class="btn-group">' +
  1143. '<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>' +
  1144. '<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>' +
  1145. '</div>';
  1146. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1147. });
  1148. return json;
  1149. }
  1150. },
  1151. columns: [
  1152. {
  1153. // placeholder, so checkbox will not block child row toggle
  1154. title: '',
  1155. data: null,
  1156. searchable: false,
  1157. orderable: false,
  1158. defaultContent: ''
  1159. },
  1160. {
  1161. title: '',
  1162. data: 'chkbox',
  1163. searchable: false,
  1164. orderable: false,
  1165. defaultContent: ''
  1166. },
  1167. {
  1168. title: 'ID',
  1169. data: 'id'
  1170. },
  1171. {
  1172. title: lang.active,
  1173. data: 'active'
  1174. },
  1175. {
  1176. title: lang.filter_type,
  1177. data: 'Type'
  1178. },
  1179. {
  1180. title: lang.owner,
  1181. data: 'username'
  1182. },
  1183. {
  1184. title: lang.description,
  1185. data: 'script_desc'
  1186. },
  1187. {
  1188. title: 'Script',
  1189. data: 'script_data'
  1190. },
  1191. {
  1192. title: lang.action,
  1193. data: 'action',
  1194. className: 'text-md-end d-md-block dt-sm-head-hidden dt-body-right'
  1195. },
  1196. ]
  1197. });
  1198. };
  1199. // detect element visibility changes
  1200. function onVisible(element, callback) {
  1201. $(element).ready(function() {
  1202. element_object = document.querySelector(element)
  1203. new IntersectionObserver((entries, observer) => {
  1204. entries.forEach(entry => {
  1205. if(entry.intersectionRatio > 0) {
  1206. callback(element_object);
  1207. observer.disconnect();
  1208. }
  1209. });
  1210. }).observe(element_object);
  1211. });
  1212. }
  1213. // Load only if the tab is visible
  1214. onVisible("[id^=domain_table]", () => draw_domain_table());
  1215. onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
  1216. onVisible("[id^=resource_table]", () => draw_resource_table());
  1217. onVisible("[id^=alias_table]", () => draw_alias_table());
  1218. onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
  1219. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  1220. onVisible("[id^=filter_table]", () => draw_filter_table());
  1221. onVisible("[id^=bcc_table]", () => draw_bcc_table());
  1222. onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
  1223. onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
  1224. });