mailbox.js 47 KB

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