mailbox.js 48 KB

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