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