mailbox.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  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. $(".goto_checkbox").click(function( event ) {
  83. $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
  84. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  85. $('#textarea_alias_goto').prop('disabled', true);
  86. }
  87. else {
  88. $("#textarea_alias_goto").removeAttr('disabled');
  89. }
  90. });
  91. $('#addAliasModal').on('show.bs.modal', function(e) {
  92. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  93. $('#textarea_alias_goto').prop('disabled', true);
  94. }
  95. else {
  96. $("#textarea_alias_goto").removeAttr('disabled');
  97. }
  98. });
  99. // Log modal
  100. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  101. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  102. $.ajax({
  103. url: '/inc/ajax/syncjob_logs.php',
  104. data: { id: syncjob_id },
  105. dataType: 'text',
  106. success: function(data){
  107. $(e.currentTarget).find('#logText').text(data);
  108. },
  109. error: function(xhr, status, error) {
  110. $(e.currentTarget).find('#logText').text(xhr.responseText);
  111. }
  112. });
  113. });
  114. // Log modal
  115. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  116. var domain = $(e.relatedTarget).data('domain');
  117. $('.dns-modal-body').html('<div class="spinner-border text-secondary" role="status"><span class="visually-hidden">Loading...</span></div>');
  118. $.ajax({
  119. url: '/inc/ajax/dns_diagnostics.php',
  120. data: { domain: domain },
  121. dataType: 'text',
  122. success: function(data){
  123. $('.dns-modal-body').html(data);
  124. },
  125. error: function(xhr, status, error) {
  126. $('.dns-modal-body').html(xhr.responseText);
  127. }
  128. });
  129. });
  130. // Sieve data modal
  131. $('#sieveDataModal').on('show.bs.modal', function(e) {
  132. var sieveScript = $(e.relatedTarget).data('sieve-script');
  133. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  134. });
  135. // Disable submit button on script change
  136. $('.textarea-code').on('keyup', function() {
  137. // Disable all "save" buttons, could be a "related button only" function, todo
  138. $('.add_sieve_script').attr({"disabled": true});
  139. });
  140. // Validate script data
  141. $(".validate_sieve").click(function( event ) {
  142. event.preventDefault();
  143. var validation_button = $(this);
  144. // Get script_data textarea content from form the button was clicked in
  145. var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
  146. $.ajax({
  147. dataType: 'json',
  148. url: "/inc/ajax/sieve_validation.php",
  149. type: "get",
  150. data: { script: script },
  151. complete: function(data) {
  152. var response = (data.responseText);
  153. response_obj = JSON.parse(response);
  154. if (response_obj.type == "success") {
  155. $(validation_button).next().attr({"disabled": false});
  156. }
  157. mailcow_alert_box(response_obj.msg, response_obj.type);
  158. },
  159. });
  160. });
  161. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  162. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  163. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  164. // });
  165. $('#addResourceModal').on('shown.bs.modal', function() {
  166. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  167. if ($("#multiple_bookings").val() == "custom") {
  168. $("#multiple_bookings_custom_div").show();
  169. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  170. }
  171. })
  172. $("#multiple_bookings_select").change(function() {
  173. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  174. if ($("#multiple_bookings").val() == "custom") {
  175. $("#multiple_bookings_custom_div").show();
  176. }
  177. else {
  178. $("#multiple_bookings_custom_div").hide();
  179. }
  180. });
  181. $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
  182. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  183. });
  184. });
  185. jQuery(function($){
  186. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  187. 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]}
  188. function unix_time_format(i){return""==i?'<i class="bi bi-x"></i>':new Date(i?1e3*i:0).toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}
  189. $(".refresh_table").on('click', function(e) {
  190. e.preventDefault();
  191. var table_name = $(this).data('table');
  192. $('#' + table_name).DataTable().ajax.reload();
  193. });
  194. function draw_domain_table() {
  195. // just recalc width if instance already exists
  196. if ($.fn.DataTable.isDataTable('#domain_table') ) {
  197. $('#domain_table').DataTable().columns.adjust().responsive.recalc();
  198. return;
  199. }
  200. var table = $('#domain_table').DataTable({
  201. processing: true,
  202. serverSide: false,
  203. language: lang_datatables,
  204. ajax: {
  205. type: "GET",
  206. url: "/api/v1/get/domain/all",
  207. dataSrc: function(json){
  208. $.each(json, function(i, item) {
  209. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  210. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  211. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
  212. item.stats = item.msgs_total + "/" + item.bytes_total;
  213. if (!item.rl) item.rl = '∞';
  214. else {
  215. item.rl = $.map(item.rl, function(e){
  216. return e;
  217. }).join('/1');
  218. }
  219. item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
  220. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  221. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  222. item.action = '<div class="btn-group">';
  223. if (role == "admin") {
  224. 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>' +
  225. '<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>' +
  226. '<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>';
  227. }
  228. else {
  229. 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>' +
  230. '<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>';
  231. }
  232. if (Array.isArray(item.tags)){
  233. var tags = '';
  234. for (var i = 0; i < item.tags.length; i++)
  235. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  236. item.tags = tags;
  237. } else {
  238. item.tags = '';
  239. }
  240. if (item.backupmx == 1) {
  241. if (item.relay_unknown_only == 1) {
  242. item.domain_name = '<div class="badge fs-6 bg-info">Relay Non-Local</div> ' + item.domain_name;
  243. } else if (item.relay_all_recipients == 1) {
  244. item.domain_name = '<div class="badge fs-6 bg-info">Relay All</div> ' + item.domain_name;
  245. } else {
  246. item.domain_name = '<div class="badge fs-6 bg-info">Relay</div> ' + item.domain_name;
  247. }
  248. }
  249. });
  250. return json;
  251. }
  252. },
  253. columns: [
  254. {
  255. // placeholder, so checkbox will not block child row toggle
  256. title: '',
  257. data: null,
  258. searchable: false,
  259. orderable: false,
  260. defaultContent: '',
  261. responsivePriority: 1
  262. },
  263. {
  264. title: '',
  265. data: 'chkbox',
  266. searchable: false,
  267. orderable: false,
  268. defaultContent: '',
  269. responsivePriority: 2
  270. },
  271. {
  272. title: lang.domain,
  273. data: 'domain_name',
  274. responsivePriority: 3,
  275. defaultContent: ''
  276. },
  277. {
  278. title: lang.aliases,
  279. data: 'aliases',
  280. defaultContent: ''
  281. },
  282. {
  283. title: lang.mailboxes,
  284. data: 'mailboxes',
  285. responsivePriority: 4,
  286. defaultContent: ''
  287. },
  288. {
  289. title: lang.domain_quota,
  290. data: 'quota',
  291. defaultContent: '',
  292. render: function (data, type) {
  293. data = data.split("/");
  294. return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
  295. }
  296. },
  297. {
  298. title: lang.stats,
  299. data: 'stats',
  300. defaultContent: '',
  301. render: function (data, type) {
  302. data = data.split("/");
  303. return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
  304. }
  305. },
  306. {
  307. title: lang.mailbox_defquota,
  308. data: 'def_quota_for_mbox',
  309. defaultContent: ''
  310. },
  311. {
  312. title: lang.mailbox_quota,
  313. data: 'max_quota_for_mbox',
  314. defaultContent: ''
  315. },
  316. {
  317. title: 'RL',
  318. data: 'rl',
  319. defaultContent: ''
  320. },
  321. {
  322. title: lang.backup_mx,
  323. data: 'backupmx',
  324. defaultContent: '',
  325. redner: function (data, type){
  326. return 1==value ? '<i class="bi bi-check-lg"></i>' : 0==value && '<i class="bi bi-x-lg"></i>';
  327. }
  328. },
  329. {
  330. title: lang.domain_admins,
  331. data: 'domain_admins',
  332. defaultContent: ''
  333. },
  334. {
  335. title: 'Tags',
  336. data: 'tags',
  337. defaultContent: ''
  338. },
  339. {
  340. title: lang.active,
  341. data: 'active',
  342. defaultContent: '',
  343. responsivePriority: 5,
  344. render: function (data, type) {
  345. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  346. }
  347. },
  348. {
  349. title: lang.action,
  350. data: 'action',
  351. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  352. responsivePriority: 5,
  353. defaultContent: ''
  354. },
  355. ]
  356. });
  357. }
  358. function draw_mailbox_table() {
  359. // just recalc width if instance already exists
  360. if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
  361. $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
  362. return;
  363. }
  364. $('#mailbox_table').DataTable({
  365. responsive : true,
  366. processing: true,
  367. serverSide: false,
  368. language: lang_datatables,
  369. ajax: {
  370. type: "GET",
  371. url: "/api/v1/get/mailbox/reduced",
  372. dataSrc: function(json){
  373. $.each(json, function (i, item) {
  374. item.quota = item.quota_used + "/" + item.quota;
  375. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  376. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  377. /*
  378. if (!item.rl) {
  379. item.rl = '∞';
  380. } else {
  381. item.rl = $.map(item.rl, function(e){
  382. return e;
  383. }).join('/1');
  384. if (item.rl_scope === 'domain') {
  385. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  386. }
  387. }
  388. */
  389. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  390. if (item.attributes.passwd_update != '0') {
  391. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  392. 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"});
  393. } else {
  394. item.last_pw_change = '-';
  395. }
  396. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  397. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  398. 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>';
  399. 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>';
  400. 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>';
  401. if (item.attributes.quarantine_notification === 'never') {
  402. item.quarantine_notification = lang.never;
  403. } else if (item.attributes.quarantine_notification === 'hourly') {
  404. item.quarantine_notification = lang.hourly;
  405. } else if (item.attributes.quarantine_notification === 'daily') {
  406. item.quarantine_notification = lang.daily;
  407. } else if (item.attributes.quarantine_notification === 'weekly') {
  408. item.quarantine_notification = lang.weekly;
  409. }
  410. if (item.attributes.quarantine_category === 'reject') {
  411. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  412. } else if (item.attributes.quarantine_category === 'add_header') {
  413. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  414. } else if (item.attributes.quarantine_category === 'all') {
  415. item.quarantine_category = lang.q_all;
  416. }
  417. if (acl_data.login_as === 1) {
  418. var btnSize = 'btn-xs-third';
  419. if (ALLOW_ADMIN_EMAIL_LOGIN) btnSize = 'btn-xs-quart';
  420. item.action = '<div class="btn-group">' +
  421. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-xs ' + btnSize + ' btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  422. '<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>' +
  423. '<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>';
  424. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  425. 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>';
  426. }
  427. item.action += '</div>';
  428. }
  429. else {
  430. item.action = '<div class="btn-group">' +
  431. '<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>' +
  432. '<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>' +
  433. '</div>';
  434. }
  435. item.in_use = '<div class="progress">' +
  436. '<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" ' +
  437. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  438. item.username = escapeHtml(item.username);
  439. if (Array.isArray(item.tags)){
  440. var tags = '';
  441. for (var i = 0; i < item.tags.length; i++)
  442. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  443. item.tags = tags;
  444. } else {
  445. item.tags = '';
  446. }
  447. });
  448. return json;
  449. }
  450. },
  451. columns: [
  452. {
  453. // placeholder, so checkbox will not block child row toggle
  454. title: '',
  455. data: null,
  456. searchable: false,
  457. orderable: false,
  458. defaultContent: '',
  459. responsivePriority: 1
  460. },
  461. {
  462. title: '',
  463. data: 'chkbox',
  464. searchable: false,
  465. orderable: false,
  466. defaultContent: '',
  467. responsivePriority: 2
  468. },
  469. {
  470. title: lang.username,
  471. data: 'username',
  472. responsivePriority: 1,
  473. defaultContent: ''
  474. },
  475. {
  476. title: lang.domain_quota,
  477. data: 'quota',
  478. responsivePriority: 2,
  479. defaultContent: '',
  480. render: function (data, type) {
  481. data = data.split("/");
  482. var of_q = (data[1] == 0 ? "∞" : humanFileSize(data[1]));
  483. return humanFileSize(data[0]) + " / " + of_q;
  484. }
  485. },
  486. {
  487. title: lang.last_mail_login,
  488. data: 'last_mail_login',
  489. defaultContent: '',
  490. responsivePriority: 3,
  491. render: function (data, type) {
  492. res = data.split("/");
  493. return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
  494. '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
  495. '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
  496. }
  497. },
  498. {
  499. title: lang.last_pw_change,
  500. data: 'last_pw_change',
  501. defaultContent: ''
  502. },
  503. {
  504. title: lang.in_use,
  505. data: 'in_use',
  506. defaultContent: '',
  507. responsivePriority: 4
  508. },
  509. {
  510. title: lang.fname,
  511. data: 'name',
  512. defaultContent: ''
  513. },
  514. {
  515. title: lang.domain,
  516. data: 'domain',
  517. defaultContent: ''
  518. },
  519. {
  520. title: lang.tls_enforce_in,
  521. data: 'tls_enforce_in',
  522. defaultContent: ''
  523. },
  524. {
  525. title: lang.tls_enforce_out,
  526. data: 'tls_enforce_out',
  527. defaultContent: ''
  528. },
  529. {
  530. title: 'SMTP',
  531. data: 'smtp_access',
  532. defaultContent: ''
  533. },
  534. {
  535. title: 'IMAP',
  536. data: 'imap_access',
  537. defaultContent: ''
  538. },
  539. {
  540. title: 'POP3',
  541. data: 'pop3_access',
  542. defaultContent: ''
  543. },
  544. {
  545. title: lang.quarantine_notification,
  546. data: 'quarantine_notification',
  547. defaultContent: ''
  548. },
  549. {
  550. title: lang.quarantine_category,
  551. data: 'quarantine_category',
  552. defaultContent: ''
  553. },
  554. {
  555. title: lang.msg_num,
  556. data: 'messages',
  557. defaultContent: '',
  558. responsivePriority: 5
  559. },
  560. {
  561. title: 'Tags',
  562. data: 'tags',
  563. defaultContent: ''
  564. },
  565. {
  566. title: lang.active,
  567. data: 'active',
  568. defaultContent: '',
  569. responsivePriority: 6,
  570. render: function (data, type) {
  571. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  572. }
  573. },
  574. {
  575. title: lang.action,
  576. data: 'action',
  577. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  578. responsivePriority: 5,
  579. defaultContent: ''
  580. },
  581. ]
  582. });
  583. }
  584. function draw_resource_table() {
  585. // just recalc width if instance already exists
  586. if ($.fn.DataTable.isDataTable('#resource_table') ) {
  587. $('#resource_table').DataTable().columns.adjust().responsive.recalc();
  588. return;
  589. }
  590. $('#resource_table').DataTable({
  591. processing: true,
  592. serverSide: false,
  593. language: lang_datatables,
  594. ajax: {
  595. type: "GET",
  596. url: "/api/v1/get/resource/all",
  597. dataSrc: function(json){
  598. $.each(json, function (i, item) {
  599. if (item.multiple_bookings == '0') {
  600. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>';
  601. } else if (item.multiple_bookings == '-1') {
  602. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>';
  603. } else {
  604. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  605. }
  606. item.action = '<div class="btn-group">' +
  607. '<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>' +
  608. '<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>' +
  609. '</div>';
  610. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  611. item.name = escapeHtml(item.name);
  612. item.description = escapeHtml(item.description);
  613. });
  614. return json;
  615. }
  616. },
  617. columns: [
  618. {
  619. // placeholder, so checkbox will not block child row toggle
  620. title: '',
  621. data: null,
  622. searchable: false,
  623. orderable: false,
  624. defaultContent: '',
  625. responsivePriority: 1
  626. },
  627. {
  628. title: '',
  629. data: 'chkbox',
  630. searchable: false,
  631. orderable: false,
  632. defaultContent: '',
  633. responsivePriority: 2
  634. },
  635. {
  636. title: lang.description,
  637. data: 'description',
  638. responsivePriority: 3,
  639. defaultContent: ''
  640. },
  641. {
  642. title: lang.alias,
  643. data: 'name',
  644. defaultContent: ''
  645. },
  646. {
  647. title: lang.kind,
  648. data: 'kind',
  649. defaultContent: ''
  650. },
  651. {
  652. title: lang.domain,
  653. data: 'domain',
  654. responsivePriority: 4,
  655. defaultContent: ''
  656. },
  657. {
  658. title: lang.multiple_bookings,
  659. data: 'multiple_bookings',
  660. defaultContent: ''
  661. },
  662. {
  663. title: lang.active,
  664. data: 'active',
  665. defaultContent: '',
  666. render: function (data, type) {
  667. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  668. }
  669. },
  670. {
  671. title: lang.action,
  672. data: 'action',
  673. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  674. responsivePriority: 5,
  675. defaultContent: ''
  676. },
  677. ]
  678. });
  679. }
  680. function draw_bcc_table() {
  681. $.get("/api/v1/get/bcc-destination-options", function(data){
  682. // Domains
  683. var optgroup = "<optgroup label='" + lang.domains + "'>";
  684. $.each(data.domains, function(index, domain){
  685. optgroup += "<option value='" + domain + "'>" + domain + "</option>"
  686. });
  687. optgroup += "</optgroup>"
  688. $('#bcc-local-dest').append(optgroup);
  689. // Alias domains
  690. var optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
  691. $.each(data.alias_domains, function(index, alias_domain){
  692. optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>"
  693. });
  694. optgroup += "</optgroup>"
  695. $('#bcc-local-dest').append(optgroup);
  696. // Mailboxes and aliases
  697. $.each(data.mailboxes, function(mailbox, aliases){
  698. var optgroup = "<optgroup label='" + mailbox + "'>";
  699. $.each(aliases, function(index, alias){
  700. optgroup += "<option value='" + alias + "'>" + alias + "</option>"
  701. });
  702. optgroup += "</optgroup>"
  703. $('#bcc-local-dest').append(optgroup);
  704. });
  705. // Finish
  706. $('#bcc-local-dest').selectpicker('refresh');
  707. });
  708. // just recalc width if instance already exists
  709. if ($.fn.DataTable.isDataTable('#bcc_table') ) {
  710. $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
  711. return;
  712. }
  713. $('#bcc_table').DataTable({
  714. processing: true,
  715. serverSide: false,
  716. language: lang_datatables,
  717. ajax: {
  718. type: "GET",
  719. url: "/api/v1/get/bcc/all",
  720. dataSrc: function(json){
  721. $.each(json, function (i, item) {
  722. item.action = '<div class="btn-group">' +
  723. '<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>' +
  724. '<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>' +
  725. '</div>';
  726. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  727. item.local_dest = escapeHtml(item.local_dest);
  728. item.bcc_dest = escapeHtml(item.bcc_dest);
  729. if (item.type == 'sender') {
  730. item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>';
  731. } else {
  732. item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>';
  733. }
  734. });
  735. return json;
  736. }
  737. },
  738. columns: [
  739. {
  740. // placeholder, so checkbox will not block child row toggle
  741. title: '',
  742. data: null,
  743. searchable: false,
  744. orderable: false,
  745. defaultContent: '',
  746. responsivePriority: 1
  747. },
  748. {
  749. title: '',
  750. data: 'chkbox',
  751. searchable: false,
  752. orderable: false,
  753. defaultContent: '',
  754. responsivePriority: 2
  755. },
  756. {
  757. title: 'ID',
  758. data: 'id',
  759. responsivePriority: 3,
  760. defaultContent: ''
  761. },
  762. {
  763. title: lang.bcc_type,
  764. data: 'type',
  765. defaultContent: ''
  766. },
  767. {
  768. title: lang.bcc_local_dest,
  769. data: 'local_dest',
  770. defaultContent: ''
  771. },
  772. {
  773. title: lang.bcc_destinations,
  774. data: 'bcc_dest',
  775. defaultContent: ''
  776. },
  777. {
  778. title: lang.domain,
  779. data: 'domain',
  780. responsivePriority: 4,
  781. defaultContent: ''
  782. },
  783. {
  784. title: lang.active,
  785. data: 'active',
  786. defaultContent: '',
  787. render: function (data, type) {
  788. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  789. }
  790. },
  791. {
  792. title: lang.action,
  793. data: 'action',
  794. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  795. responsivePriority: 5,
  796. defaultContent: ''
  797. },
  798. ]
  799. });
  800. }
  801. function draw_recipient_map_table() {
  802. // just recalc width if instance already exists
  803. if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
  804. $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
  805. return;
  806. }
  807. $('#recipient_map_table').DataTable({
  808. processing: true,
  809. serverSide: false,
  810. language: lang_datatables,
  811. ajax: {
  812. type: "GET",
  813. url: "/api/v1/get/recipient_map/all",
  814. dataSrc: function(json){
  815. if (role !== "admin") return null;
  816. $.each(json, function (i, item) {
  817. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  818. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  819. item.action = '<div class="btn-group">' +
  820. '<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>' +
  821. '<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>' +
  822. '</div>';
  823. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  824. });
  825. return json;
  826. }
  827. },
  828. columns: [
  829. {
  830. // placeholder, so checkbox will not block child row toggle
  831. title: '',
  832. data: null,
  833. searchable: false,
  834. orderable: false,
  835. defaultContent: '',
  836. responsivePriority: 1
  837. },
  838. {
  839. title: '',
  840. data: 'chkbox',
  841. searchable: false,
  842. orderable: false,
  843. defaultContent: '',
  844. responsivePriority: 2
  845. },
  846. {
  847. title: 'ID',
  848. data: 'id',
  849. responsivePriority: 3,
  850. defaultContent: ''
  851. },
  852. {
  853. title: lang.recipient_map_old,
  854. data: 'recipient_map_old',
  855. defaultContent: ''
  856. },
  857. {
  858. title: lang.recipient_map_new,
  859. data: 'recipient_map_new',
  860. defaultContent: ''
  861. },
  862. {
  863. title: lang.active,
  864. data: 'active',
  865. defaultContent: '',
  866. render: function (data, type) {
  867. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  868. }
  869. },
  870. {
  871. title: lang.action,
  872. data: 'action',
  873. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  874. responsivePriority: 4,
  875. defaultContent: ''
  876. },
  877. ]
  878. });
  879. }
  880. function draw_tls_policy_table() {
  881. // just recalc width if instance already exists
  882. if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
  883. $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
  884. return;
  885. }
  886. $('#tls_policy_table').DataTable({
  887. processing: true,
  888. serverSide: false,
  889. language: lang_datatables,
  890. ajax: {
  891. type: "GET",
  892. url: "/api/v1/get/tls-policy-map/all",
  893. dataSrc: function(json){
  894. if (role !== "admin") return null;
  895. $.each(json, function (i, item) {
  896. item.dest = escapeHtml(item.dest);
  897. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  898. if (item.parameters == '') {
  899. item.parameters = '<code>-</code>';
  900. } else {
  901. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  902. }
  903. item.action = '<div class="btn-group">' +
  904. '<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>' +
  905. '<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>' +
  906. '</div>';
  907. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  908. });
  909. return json;
  910. }
  911. },
  912. columns: [
  913. {
  914. // placeholder, so checkbox will not block child row toggle
  915. title: '',
  916. data: null,
  917. searchable: false,
  918. orderable: false,
  919. defaultContent: '',
  920. responsivePriority: 1
  921. },
  922. {
  923. title: '',
  924. data: 'chkbox',
  925. searchable: false,
  926. orderable: false,
  927. defaultContent: '',
  928. responsivePriority: 2
  929. },
  930. {
  931. title: 'ID',
  932. data: 'id',
  933. responsivePriority: 3,
  934. defaultContent: ''
  935. },
  936. {
  937. title: lang.tls_map_dest,
  938. data: 'dest',
  939. defaultContent: ''
  940. },
  941. {
  942. title: lang.tls_map_policy,
  943. data: 'policy',
  944. defaultContent: ''
  945. },
  946. {
  947. title: lang.tls_map_parameters,
  948. data: 'parameters',
  949. defaultContent: ''
  950. },
  951. {
  952. title: lang.domain,
  953. data: 'domain',
  954. responsivePriority: 4,
  955. defaultContent: ''
  956. },
  957. {
  958. title: lang.active,
  959. data: 'active',
  960. defaultContent: '',
  961. render: function (data, type) {
  962. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  963. }
  964. },
  965. {
  966. title: lang.action,
  967. data: 'action',
  968. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  969. responsivePriority: 5,
  970. defaultContent: ''
  971. },
  972. ]
  973. });
  974. }
  975. function draw_alias_table() {
  976. // just recalc width if instance already exists
  977. if ($.fn.DataTable.isDataTable('#alias_table') ) {
  978. $('#alias_table').DataTable().columns.adjust().responsive.recalc();
  979. return;
  980. }
  981. $('#alias_table').DataTable({
  982. processing: true,
  983. serverSide: false,
  984. language: lang_datatables,
  985. ajax: {
  986. type: "GET",
  987. url: "/api/v1/get/alias/all",
  988. dataSrc: function(json){
  989. $.each(json, function (i, item) {
  990. item.action = '<div class="btn-group">' +
  991. '<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>' +
  992. '<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>' +
  993. '</div>';
  994. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  995. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  996. if (item.public_comment !== null) {
  997. item.public_comment = escapeHtml(item.public_comment);
  998. }
  999. else {
  1000. item.public_comment = '-';
  1001. }
  1002. if (item.private_comment !== null) {
  1003. item.private_comment = escapeHtml(item.private_comment);
  1004. }
  1005. else {
  1006. item.private_comment = '-';
  1007. }
  1008. if (item.is_catch_all == 1) {
  1009. item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
  1010. }
  1011. else {
  1012. item.address = escapeHtml(item.address);
  1013. }
  1014. if (item.goto == "null@localhost") {
  1015. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  1016. }
  1017. else if (item.goto == "spam@localhost") {
  1018. item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
  1019. }
  1020. else if (item.goto == "ham@localhost") {
  1021. item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
  1022. }
  1023. if (item.in_primary_domain !== "") {
  1024. 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;
  1025. }
  1026. });
  1027. return json;
  1028. }
  1029. },
  1030. columns: [
  1031. {
  1032. // placeholder, so checkbox will not block child row toggle
  1033. title: '',
  1034. data: null,
  1035. searchable: false,
  1036. orderable: false,
  1037. defaultContent: '',
  1038. responsivePriority: 1
  1039. },
  1040. {
  1041. title: '',
  1042. data: 'chkbox',
  1043. searchable: false,
  1044. orderable: false,
  1045. defaultContent: '',
  1046. responsivePriority: 2
  1047. },
  1048. {
  1049. title: 'ID',
  1050. data: 'id',
  1051. responsivePriority: 3,
  1052. defaultContent: ''
  1053. },
  1054. {
  1055. title: lang.alias,
  1056. data: 'address',
  1057. responsivePriority: 4,
  1058. defaultContent: ''
  1059. },
  1060. {
  1061. title: lang.target_address,
  1062. data: 'goto',
  1063. defaultContent: ''
  1064. },
  1065. {
  1066. title: lang.domain,
  1067. data: 'domain',
  1068. defaultContent: '',
  1069. responsivePriority: 5,
  1070. },
  1071. {
  1072. title: lang.bcc_destinations,
  1073. data: 'bcc_dest',
  1074. defaultContent: ''
  1075. },
  1076. {
  1077. title: lang.sogo_visible,
  1078. data: 'sogo_visible',
  1079. defaultContent: '',
  1080. render: function(data, type){
  1081. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1082. }
  1083. },
  1084. {
  1085. title: lang.public_comment,
  1086. data: 'public_comment',
  1087. defaultContent: ''
  1088. },
  1089. {
  1090. title: lang.private_comment,
  1091. data: 'private_comment',
  1092. defaultContent: ''
  1093. },
  1094. {
  1095. title: lang.active,
  1096. data: 'active',
  1097. defaultContent: '',
  1098. responsivePriority: 6,
  1099. render: function (data, type) {
  1100. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1101. }
  1102. },
  1103. {
  1104. title: lang.action,
  1105. data: 'action',
  1106. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  1107. responsivePriority: 5,
  1108. defaultContent: ''
  1109. },
  1110. ]
  1111. });
  1112. }
  1113. function draw_aliasdomain_table() {
  1114. // just recalc width if instance already exists
  1115. if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
  1116. $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
  1117. return;
  1118. }
  1119. $('#aliasdomain_table').DataTable({
  1120. processing: true,
  1121. serverSide: false,
  1122. language: lang_datatables,
  1123. ajax: {
  1124. type: "GET",
  1125. url: "/api/v1/get/alias-domain/all",
  1126. dataSrc: function(json){
  1127. $.each(json, function (i, item) {
  1128. item.action = '<div class="btn-group">' +
  1129. '<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>' +
  1130. '<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>' +
  1131. '<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>' +
  1132. '</div>';
  1133. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  1134. if(item.parent_is_backupmx == '1') {
  1135. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a> <div class="badge fs-6 bg-warning">' + lang.alias_domain_backupmx + '</div></span>';
  1136. } else {
  1137. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  1138. }
  1139. });
  1140. return json;
  1141. }
  1142. },
  1143. columns: [
  1144. {
  1145. // placeholder, so checkbox will not block child row toggle
  1146. title: '',
  1147. data: null,
  1148. searchable: false,
  1149. orderable: false,
  1150. defaultContent: '',
  1151. responsivePriority: 1
  1152. },
  1153. {
  1154. title: '',
  1155. data: 'chkbox',
  1156. searchable: false,
  1157. orderable: false,
  1158. defaultContent: '',
  1159. responsivePriority: 2
  1160. },
  1161. {
  1162. title: lang.alias,
  1163. data: 'alias_domain',
  1164. responsivePriority: 3,
  1165. defaultContent: ''
  1166. },
  1167. {
  1168. title: lang.target_domain,
  1169. data: 'target_domain',
  1170. responsivePriority: 4,
  1171. defaultContent: ''
  1172. },
  1173. {
  1174. title: lang.active,
  1175. data: 'active',
  1176. defaultContent: '',
  1177. render: function (data, type) {
  1178. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1179. }
  1180. },
  1181. {
  1182. title: lang.action,
  1183. data: 'action',
  1184. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  1185. responsivePriority: 5,
  1186. defaultContent: ''
  1187. },
  1188. ]
  1189. });
  1190. }
  1191. function draw_sync_job_table() {
  1192. // just recalc width if instance already exists
  1193. if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
  1194. $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
  1195. return;
  1196. }
  1197. $('#sync_job_table').DataTable({
  1198. processing: true,
  1199. serverSide: false,
  1200. language: lang_datatables,
  1201. ajax: {
  1202. type: "GET",
  1203. url: "/api/v1/get/syncjobs/all/no_log",
  1204. dataSrc: function(json){
  1205. $.each(json, function (i, item) {
  1206. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
  1207. item.user2 = escapeHtml(item.user2);
  1208. if (!item.exclude > 0) {
  1209. item.exclude = '-';
  1210. } else {
  1211. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  1212. }
  1213. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  1214. item.action = '<div class="btn-group">' +
  1215. '<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>' +
  1216. '<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>' +
  1217. '</div>';
  1218. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  1219. if (item.is_running == 1) {
  1220. item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
  1221. } else {
  1222. item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
  1223. }
  1224. if (!item.last_run > 0) {
  1225. item.last_run = lang.waiting;
  1226. }
  1227. if (item.success == null) {
  1228. item.success = '-';
  1229. item.exit_status = '';
  1230. } else {
  1231. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1232. }
  1233. if (lang['syncjob_'+item.exit_status]) {
  1234. item.exit_status = lang['syncjob_'+item.exit_status];
  1235. } else if (item.success != '-') {
  1236. item.exit_status = lang.syncjob_check_log;
  1237. }
  1238. item.exit_status = item.success + ' ' + item.exit_status;
  1239. });
  1240. return json;
  1241. }
  1242. },
  1243. columns: [
  1244. {
  1245. // placeholder, so checkbox will not block child row toggle
  1246. title: '',
  1247. data: null,
  1248. searchable: false,
  1249. orderable: false,
  1250. defaultContent: '',
  1251. responsivePriority: 1
  1252. },
  1253. {
  1254. title: '',
  1255. data: 'chkbox',
  1256. searchable: false,
  1257. orderable: false,
  1258. defaultContent: '',
  1259. responsivePriority: 2
  1260. },
  1261. {
  1262. title: 'ID',
  1263. data: 'id',
  1264. responsivePriority: 3,
  1265. defaultContent: ''
  1266. },
  1267. {
  1268. title: lang.owner,
  1269. data: 'user2',
  1270. responsivePriority: 4,
  1271. defaultContent: ''
  1272. },
  1273. {
  1274. title: 'Server',
  1275. data: 'server_w_port',
  1276. defaultContent: ''
  1277. },
  1278. {
  1279. title: lang.last_run,
  1280. data: 'last_run',
  1281. defaultContent: ''
  1282. },
  1283. {
  1284. title: lang.syncjob_last_run_result,
  1285. data: 'exit_status',
  1286. defaultContent: ''
  1287. },
  1288. {
  1289. title: 'Log',
  1290. data: 'log',
  1291. defaultContent: ''
  1292. },
  1293. {
  1294. title: lang.active,
  1295. data: 'active',
  1296. defaultContent: '',
  1297. render: function (data, type) {
  1298. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1299. }
  1300. },
  1301. {
  1302. title: lang.status,
  1303. data: 'is_running',
  1304. defaultContent: ''
  1305. },
  1306. {
  1307. title: lang.excludes,
  1308. data: 'exclude',
  1309. defaultContent: ''
  1310. },
  1311. {
  1312. title: lang.mins_interval,
  1313. data: 'mins_interval',
  1314. defaultContent: ''
  1315. },
  1316. {
  1317. title: lang.action,
  1318. data: 'action',
  1319. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  1320. responsivePriority: 5,
  1321. defaultContent: ''
  1322. },
  1323. ]
  1324. });
  1325. }
  1326. function draw_filter_table() {
  1327. // just recalc width if instance already exists
  1328. if ($.fn.DataTable.isDataTable('#filter_table') ) {
  1329. $('#filter_table').DataTable().columns.adjust().responsive.recalc();
  1330. return;
  1331. }
  1332. var table = $('#filter_table').DataTable({
  1333. autoWidth: false,
  1334. processing: true,
  1335. serverSide: false,
  1336. language: lang_datatables,
  1337. ajax: {
  1338. type: "GET",
  1339. url: "/api/v1/get/filters/all",
  1340. dataSrc: function(json){
  1341. $.each(json, function (i, item) {
  1342. if (item.active == 1) {
  1343. item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
  1344. } else {
  1345. item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
  1346. }
  1347. item.script_data = '<pre style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1348. item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1349. item.action = '<div class="btn-group">' +
  1350. '<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>' +
  1351. '<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>' +
  1352. '</div>';
  1353. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1354. });
  1355. return json;
  1356. }
  1357. },
  1358. columns: [
  1359. {
  1360. // placeholder, so checkbox will not block child row toggle
  1361. title: '',
  1362. data: null,
  1363. searchable: false,
  1364. orderable: false,
  1365. defaultContent: '',
  1366. responsivePriority: 1
  1367. },
  1368. {
  1369. title: '',
  1370. data: 'chkbox',
  1371. searchable: false,
  1372. orderable: false,
  1373. defaultContent: '',
  1374. responsivePriority: 2
  1375. },
  1376. {
  1377. title: 'ID',
  1378. data: 'id',
  1379. responsivePriority: 2,
  1380. defaultContent: ''
  1381. },
  1382. {
  1383. title: lang.active,
  1384. data: 'active',
  1385. responsivePriority: 3,
  1386. defaultContent: ''
  1387. },
  1388. {
  1389. title: 'Type',
  1390. data: 'filter_type',
  1391. responsivePriority: 4,
  1392. defaultContent: ''
  1393. },
  1394. {
  1395. title: lang.owner,
  1396. data: 'username',
  1397. defaultContent: ''
  1398. },
  1399. {
  1400. title: lang.description,
  1401. data: 'script_desc',
  1402. defaultContent: ''
  1403. },
  1404. {
  1405. title: 'Script',
  1406. data: 'script_data',
  1407. defaultContent: '',
  1408. className: 'none'
  1409. },
  1410. {
  1411. title: lang.action,
  1412. data: 'action',
  1413. className: 'text-md-end dt-sm-head-hidden dt-body-right',
  1414. responsivePriority: 5,
  1415. defaultContent: ''
  1416. },
  1417. ]
  1418. });
  1419. };
  1420. // detect element visibility changes
  1421. function onVisible(element, callback) {
  1422. $(document).ready(function() {
  1423. element_object = document.querySelector(element);
  1424. if (element_object === null) return;
  1425. new IntersectionObserver((entries, observer) => {
  1426. entries.forEach(entry => {
  1427. if(entry.intersectionRatio > 0) {
  1428. callback(element_object);
  1429. }
  1430. });
  1431. }).observe(element_object);
  1432. });
  1433. }
  1434. // Load only if the tab is visible
  1435. onVisible("[id^=domain_table]", () => draw_domain_table());
  1436. onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
  1437. onVisible("[id^=resource_table]", () => draw_resource_table());
  1438. onVisible("[id^=alias_table]", () => draw_alias_table());
  1439. onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
  1440. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  1441. onVisible("[id^=filter_table]", () => draw_filter_table());
  1442. onVisible("[id^=bcc_table]", () => draw_bcc_table());
  1443. onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
  1444. onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
  1445. });