mailbox.js 51 KB

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