mailbox.js 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125
  1. $(document).ready(function() {
  2. acl_data = JSON.parse(acl);
  3. // Set paging
  4. // Clone mailbox mass actions
  5. $("div").find("[data-actions-header='true'").each(function() {
  6. $(this).html($(this).nextAll('.mass-actions-mailbox:first').html());
  7. });
  8. // Auto-fill domain quota when adding new domain
  9. auto_fill_quota = function(domain) {
  10. $.get("/api/v1/get/domain/" + domain, function(data){
  11. var result = $.parseJSON(JSON.stringify(data));
  12. def_new_mailbox_quota = ( result.def_new_mailbox_quota / 1048576);
  13. max_new_mailbox_quota = ( result.max_new_mailbox_quota / 1048576);
  14. if (max_new_mailbox_quota != '0') {
  15. $('.addInputQuotaExhausted').hide();
  16. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  17. $('#addInputQuota').attr({"disabled": false, "value": "", "type": "number", "max": max_new_mailbox_quota});
  18. $('#addInputQuota').val(def_new_mailbox_quota);
  19. }
  20. else {
  21. $('.addInputQuotaExhausted').show();
  22. $("#quotaBadge").html('max. ' + max_new_mailbox_quota + ' MiB');
  23. $('#addInputQuota').attr({"disabled": true, "value": "", "type": "text", "value": "n/a"});
  24. $('#addInputQuota').val(max_new_mailbox_quota);
  25. }
  26. });
  27. }
  28. $('#addSelectDomain').on('change', function() {
  29. auto_fill_quota($('#addSelectDomain').val());
  30. });
  31. auto_fill_quota($('#addSelectDomain').val());
  32. $(".goto_checkbox").click(function( event ) {
  33. $("form[data-id='add_alias'] .goto_checkbox").not(this).prop('checked', false);
  34. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  35. $('#textarea_alias_goto').prop('disabled', true);
  36. }
  37. else {
  38. $("#textarea_alias_goto").removeAttr('disabled');
  39. }
  40. });
  41. $('#addAliasModal').on('show.bs.modal', function(e) {
  42. if ($("form[data-id='add_alias'] .goto_checkbox:checked").length > 0) {
  43. $('#textarea_alias_goto').prop('disabled', true);
  44. }
  45. else {
  46. $("#textarea_alias_goto").removeAttr('disabled');
  47. }
  48. });
  49. // Log modal
  50. $('#syncjobLogModal').on('show.bs.modal', function(e) {
  51. var syncjob_id = $(e.relatedTarget).data('syncjob-id');
  52. $.ajax({
  53. url: '/inc/ajax/syncjob_logs.php',
  54. data: { id: syncjob_id },
  55. dataType: 'text',
  56. success: function(data){
  57. $(e.currentTarget).find('#logText').text(data);
  58. },
  59. error: function(xhr, status, error) {
  60. $(e.currentTarget).find('#logText').text(xhr.responseText);
  61. }
  62. });
  63. });
  64. // Log modal
  65. $('#dnsInfoModal').on('show.bs.modal', function(e) {
  66. var domain = $(e.relatedTarget).data('domain');
  67. $('.dns-modal-body').html('<div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div>');
  68. $.ajax({
  69. url: '/inc/ajax/dns_diagnostics.php',
  70. data: { domain: domain },
  71. dataType: 'text',
  72. success: function(data){
  73. $('.dns-modal-body').html(data);
  74. },
  75. error: function(xhr, status, error) {
  76. $('.dns-modal-body').html(xhr.responseText);
  77. }
  78. });
  79. });
  80. // @Open Domain add modal
  81. $('#addDomainModal').on('show.bs.modal', function(e) {
  82. $.ajax({
  83. url: '/api/v1/get/domain/template/all',
  84. data: {},
  85. dataType: 'json',
  86. success: async function(data){
  87. $('#domain_templates').find('option').remove();
  88. $('#domain_templates').selectpicker('destroy');
  89. $('#domain_templates').selectpicker();
  90. for (var i = 0; i < data.length; i++){
  91. if (data[i].template === "Default"){
  92. $('#domain_templates').prepend($('<option>', {
  93. 'value': data[i].id,
  94. 'text': data[i].template,
  95. 'data-attributes': JSON.stringify(data[i].attributes),
  96. 'selected': true
  97. }));
  98. setDomainTemplateData(data[i].attributes);
  99. } else {
  100. $('#domain_templates').append($('<option>', {
  101. 'value': data[i].id,
  102. 'text': data[i].template,
  103. 'data-attributes': JSON.stringify(data[i].attributes),
  104. 'selected': false
  105. }));
  106. }
  107. };
  108. $('#domain_templates').selectpicker("refresh");
  109. // @selecting template
  110. $('#domain_templates').on('change', function(){
  111. var selected = $('#domain_templates option:selected');
  112. var attr = selected.data('attributes');
  113. setDomainTemplateData(attr);
  114. });
  115. },
  116. error: function(xhr, status, error) {
  117. console.log(error);
  118. }
  119. });
  120. });
  121. // @Open Mailbox add modal
  122. $('#addMailboxModal').on('show.bs.modal', function(e) {
  123. $.ajax({
  124. url: '/api/v1/get/mailbox/template/all',
  125. data: {},
  126. dataType: 'json',
  127. success: async function(data){
  128. $('#mailbox_templates').find('option').remove();
  129. $('#mailbox_templates').selectpicker('destroy');
  130. $('#mailbox_templates').selectpicker();
  131. for (var i = 0; i < data.length; i++){
  132. if (data[i].template === "Default"){
  133. $('#mailbox_templates').prepend($('<option>', {
  134. 'value': data[i].id,
  135. 'text': data[i].template,
  136. 'data-attributes': JSON.stringify(data[i].attributes),
  137. 'selected': true
  138. }));
  139. setMailboxTemplateData(data[i].attributes);
  140. } else {
  141. $('#mailbox_templates').append($('<option>', {
  142. value: data[i].id,
  143. text : data[i].template,
  144. 'data-attributes': JSON.stringify(data[i].attributes),
  145. 'selected': false
  146. }));
  147. }
  148. };
  149. $('#mailbox_templates').selectpicker("refresh");
  150. // @selecting template
  151. $('#mailbox_templates').on('change', function(){
  152. var selected = $('#mailbox_templates option:selected');
  153. var attr = selected.data('attributes');
  154. setMailboxTemplateData(attr);
  155. });
  156. },
  157. error: function(xhr, status, error) {
  158. console.log(error);
  159. }
  160. });
  161. });
  162. // Sieve data modal
  163. $('#sieveDataModal').on('show.bs.modal', function(e) {
  164. var sieveScript = $(e.relatedTarget).data('sieve-script');
  165. $(e.currentTarget).find('#sieveDataText').html('<pre style="font-size:14px;line-height:1.1">' + sieveScript + '</pre>');
  166. });
  167. // Disable submit button on script change
  168. $('.textarea-code').on('keyup', function() {
  169. // Disable all "save" buttons, could be a "related button only" function, todo
  170. $('.add_sieve_script').attr({"disabled": true});
  171. });
  172. // Validate script data
  173. $(".validate_sieve").click(function( event ) {
  174. event.preventDefault();
  175. var validation_button = $(this);
  176. // Get script_data textarea content from form the button was clicked in
  177. var script = $('textarea[name="script_data"]', $(this).parents('form:first')).val();
  178. $.ajax({
  179. dataType: 'json',
  180. url: "/inc/ajax/sieve_validation.php",
  181. type: "get",
  182. data: { script: script },
  183. complete: function(data) {
  184. var response = (data.responseText);
  185. response_obj = JSON.parse(response);
  186. if (response_obj.type == "success") {
  187. $(validation_button).next().attr({"disabled": false});
  188. }
  189. mailcow_alert_box(response_obj.msg, response_obj.type);
  190. },
  191. });
  192. });
  193. // $(document).on('DOMNodeInserted', '#prefilter_table', function () {
  194. // $("#active-script").closest('td').css('background-color','#b0f0a0');
  195. // $("#inactive-script").closest('td').css('background-color','#b0f0a0');
  196. // });
  197. $('#addResourceModal').on('shown.bs.modal', function() {
  198. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  199. if ($("#multiple_bookings").val() == "custom") {
  200. $("#multiple_bookings_custom_div").show();
  201. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  202. }
  203. })
  204. $("#multiple_bookings_select").change(function() {
  205. $("#multiple_bookings").val($("#multiple_bookings_select").val());
  206. if ($("#multiple_bookings").val() == "custom") {
  207. $("#multiple_bookings_custom_div").show();
  208. }
  209. else {
  210. $("#multiple_bookings_custom_div").hide();
  211. }
  212. });
  213. $("#multiple_bookings_custom").bind ("change keypress keyup blur", function () {
  214. $("#multiple_bookings").val($("#multiple_bookings_custom").val());
  215. });
  216. function setDomainTemplateData(template){
  217. $("#addDomain_max_aliases").val(template.max_num_aliases_for_domain);
  218. $("#addDomain_max_mailboxes").val(template.max_num_mboxes_for_domain);
  219. $("#addDomain_mailbox_quota_def").val(template.def_quota_for_mbox / 1048576);
  220. $("#addDomain_mailbox_quota_m").val(template.max_quota_for_mbox / 1048576);
  221. $("#addDomain_domain_quota_m").val(template.max_quota_for_domain / 1048576);
  222. if (template.gal == 1){
  223. $('#addDomain_gal').prop('checked', true);
  224. } else {
  225. $('#addDomain_gal').prop('checked', false);
  226. }
  227. if (template.active == 1){
  228. $('#addDomain_active').prop('checked', true);
  229. } else {
  230. $('#addDomain_active').prop('checked', false);
  231. }
  232. $("#addDomain_rl_value").val(template.rl_value);
  233. $('#addDomain_rl_frame').selectpicker('val', template.rl_frame);
  234. $("#dkim_selector").val(template.dkim_selector);
  235. if (!template.key_size)
  236. template.key_size = 2048;
  237. $('#key_size').selectpicker('val', template.key_size.toString());
  238. if (template.backupmx == 1){
  239. $('#addDomain_relay_domain').prop('checked', true);
  240. } else {
  241. $('#addDomain_relay_domain').prop('checked', false);
  242. }
  243. if (template.relay_all_recipients == 1){
  244. $('#addDomain_relay_all').prop('checked', true);
  245. } else {
  246. $('#addDomain_relay_all').prop('checked', false);
  247. }
  248. if (template.relay_unknown_only == 1){
  249. $('#addDomain_relay_unknown_only').prop('checked', true);
  250. } else {
  251. $('#addDomain_relay_unknown_only').prop('checked', false);
  252. }
  253. // load tags
  254. $('#addDomain_tags').val("");
  255. $($('#addDomain_tags').parent().find(".tag-values")[0]).val("");
  256. $('#addDomain_tags').parent().find(".tag-badge").remove();
  257. for (var i = 0; i < template.tags.length; i++)
  258. addTag($('#addDomain_tags'), template.tags[i]);
  259. }
  260. function setMailboxTemplateData(template){
  261. $("#addInputQuota").val(template.quota / 1048576);
  262. if (template.quarantine_notification === "never"){
  263. $('#quarantine_notification_never').prop('checked', true);
  264. $('#quarantine_notification_hourly').prop('checked', false);
  265. $('#quarantine_notification_daily').prop('checked', false);
  266. $('#quarantine_notification_weekly').prop('checked', false);
  267. } else if(template.quarantine_notification === "hourly"){
  268. $('#quarantine_notification_never').prop('checked', false);
  269. $('#quarantine_notification_hourly').prop('checked', true);
  270. $('#quarantine_notification_daily').prop('checked', false);
  271. $('#quarantine_notification_weekly').prop('checked', false);
  272. } else if(template.quarantine_notification === "daily"){
  273. $('#quarantine_notification_never').prop('checked', false);
  274. $('#quarantine_notification_hourly').prop('checked', false);
  275. $('#quarantine_notification_daily').prop('checked', true);
  276. $('#quarantine_notification_weekly').prop('checked', false);
  277. } else if(template.quarantine_notification === "weekly"){
  278. $('#quarantine_notification_never').prop('checked', false);
  279. $('#quarantine_notification_hourly').prop('checked', false);
  280. $('#quarantine_notification_daily').prop('checked', false);
  281. $('#quarantine_notification_weekly').prop('checked', true);
  282. } else {
  283. $('#quarantine_notification_never').prop('checked', false);
  284. $('#quarantine_notification_hourly').prop('checked', false);
  285. $('#quarantine_notification_daily').prop('checked', false);
  286. $('#quarantine_notification_weekly').prop('checked', false);
  287. }
  288. if (template.quarantine_category === "reject"){
  289. $('#quarantine_category_reject').prop('checked', true);
  290. $('#quarantine_category_add_header').prop('checked', false);
  291. $('#quarantine_category_all').prop('checked', false);
  292. } else if(template.quarantine_category === "add_header"){
  293. $('#quarantine_category_reject').prop('checked', false);
  294. $('#quarantine_category_add_header').prop('checked', true);
  295. $('#quarantine_category_all').prop('checked', false);
  296. } else if(template.quarantine_category === "all"){
  297. $('#quarantine_category_reject').prop('checked', false);
  298. $('#quarantine_category_add_header').prop('checked', false);
  299. $('#quarantine_category_all').prop('checked', true);
  300. }
  301. if (template.tls_enforce_in == 1){
  302. $('#tls_enforce_in').prop('checked', true);
  303. } else {
  304. $('#tls_enforce_in').prop('checked', false);
  305. }
  306. if (template.tls_enforce_out == 1){
  307. $('#tls_enforce_out').prop('checked', true);
  308. } else {
  309. $('#tls_enforce_out').prop('checked', false);
  310. }
  311. var protocol_access = [];
  312. if (template.imap_access == 1){
  313. protocol_access.push("imap");
  314. }
  315. if (template.pop3_access == 1){
  316. protocol_access.push("pop3");
  317. }
  318. if (template.smtp_access == 1){
  319. protocol_access.push("smtp");
  320. }
  321. if (template.sieve_access == 1){
  322. protocol_access.push("sieve");
  323. }
  324. $('#protocol_access').selectpicker('val', protocol_access);
  325. var acl = [];
  326. if (template.acl_spam_alias == 1){
  327. acl.push("spam_alias");
  328. }
  329. if (template.acl_tls_policy == 1){
  330. acl.push("tls_policy");
  331. }
  332. if (template.acl_spam_score == 1){
  333. acl.push("spam_score");
  334. }
  335. if (template.acl_spam_policy == 1){
  336. acl.push("spam_policy");
  337. }
  338. if (template.acl_delimiter_action == 1){
  339. acl.push("delimiter_action");
  340. }
  341. if (template.acl_syncjobs == 1){
  342. acl.push("syncjobs");
  343. }
  344. if (template.acl_eas_reset == 1){
  345. acl.push("eas_reset");
  346. }
  347. if (template.acl_sogo_profile_reset == 1){
  348. acl.push("sogo_profile_reset");
  349. }
  350. if (template.acl_pushover == 1){
  351. acl.push("pushover");
  352. }
  353. if (template.acl_quarantine == 1){
  354. acl.push("quarantine");
  355. }
  356. if (template.acl_quarantine_attachments == 1){
  357. acl.push("quarantine_attachments");
  358. }
  359. if (template.acl_quarantine_notification == 1){
  360. acl.push("quarantine_notification");
  361. }
  362. if (template.acl_quarantine_category == 1){
  363. acl.push("quarantine_category");
  364. }
  365. if (template.acl_app_passwds == 1){
  366. acl.push("app_passwds");
  367. }
  368. $('#user_acl').selectpicker('val', acl);
  369. $('#rl_value').val(template.rl_value);
  370. if (template.rl_frame){
  371. $('#rl_frame').selectpicker('val', template.rl_frame);
  372. }
  373. console.log(template.active)
  374. if (template.active){
  375. $('#mbox_active').selectpicker('val', template.active.toString());
  376. } else {
  377. $('#mbox_active').selectpicker('val', '');
  378. }
  379. if (template.force_pw_update == 1){
  380. $('#force_pw_update').prop('checked', true);
  381. } else {
  382. $('#force_pw_update').prop('checked', false);
  383. }
  384. if (template.sogo_access == 1){
  385. $('#sogo_access').prop('checked', true);
  386. } else {
  387. $('#sogo_access').prop('checked', false);
  388. }
  389. // load tags
  390. $('#addMailbox_tags').val("");
  391. $($('#addMailbox_tags').parent().find(".tag-values")[0]).val("");
  392. $('#addMailbox_tags').parent().find(".tag-badge").remove();
  393. for (var i = 0; i < template.tags.length; i++)
  394. addTag($('#addMailbox_tags'), template.tags[i]);
  395. }
  396. });
  397. jQuery(function($){
  398. // http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
  399. 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]}
  400. function unix_time_format(i){return""==i?'<i class="bi bi-x"></i>':new Date(i?1e3*i:0).toLocaleDateString(void 0,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"})}
  401. $(".refresh_table").on('click', function(e) {
  402. e.preventDefault();
  403. var table_name = $(this).data('table');
  404. if ($.fn.DataTable.isDataTable('#' + table_name))
  405. $('#' + table_name).DataTable().ajax.reload();
  406. });
  407. function draw_domain_table() {
  408. // just recalc width if instance already exists
  409. if ($.fn.DataTable.isDataTable('#domain_table') ) {
  410. $('#domain_table').DataTable().columns.adjust().responsive.recalc();
  411. return;
  412. }
  413. var table = $('#domain_table').DataTable({
  414. processing: true,
  415. serverSide: false,
  416. language: lang_datatables,
  417. ajax: {
  418. type: "GET",
  419. url: "/api/v1/get/domain/all",
  420. dataSrc: function(json){
  421. $.each(json, function(i, item) {
  422. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  423. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  424. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
  425. item.stats = item.msgs_total + "/" + item.bytes_total;
  426. if (!item.rl) item.rl = '∞';
  427. else {
  428. item.rl = $.map(item.rl, function(e){
  429. return e;
  430. }).join('/1');
  431. }
  432. item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
  433. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  434. item.chkbox = '<input type="checkbox" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  435. item.action = '<div class="btn-group">';
  436. if (role == "admin") {
  437. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  438. '<a href="#" data-action="delete_selected" data-id="single-domain" data-api-url="delete/domain" data-item="' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  439. '<a href="#dnsInfoModal" class="btn btn-sm btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
  440. }
  441. else {
  442. 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>' +
  443. '<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>';
  444. }
  445. if (Array.isArray(item.tags)){
  446. var tags = '';
  447. for (var i = 0; i < item.tags.length; i++)
  448. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  449. item.tags = tags;
  450. } else {
  451. item.tags = '';
  452. }
  453. if (item.backupmx == 1) {
  454. if (item.relay_unknown_only == 1) {
  455. item.domain_name = '<div class="badge fs-6 bg-info">Relay Non-Local</div> ' + item.domain_name;
  456. } else if (item.relay_all_recipients == 1) {
  457. item.domain_name = '<div class="badge fs-6 bg-info">Relay All</div> ' + item.domain_name;
  458. } else {
  459. item.domain_name = '<div class="badge fs-6 bg-info">Relay</div> ' + item.domain_name;
  460. }
  461. }
  462. });
  463. return json;
  464. }
  465. },
  466. columns: [
  467. {
  468. // placeholder, so checkbox will not block child row toggle
  469. title: '',
  470. data: null,
  471. searchable: false,
  472. orderable: false,
  473. defaultContent: '',
  474. responsivePriority: 1
  475. },
  476. {
  477. title: '',
  478. data: 'chkbox',
  479. searchable: false,
  480. orderable: false,
  481. defaultContent: '',
  482. responsivePriority: 2
  483. },
  484. {
  485. title: lang.domain,
  486. data: 'domain_name',
  487. responsivePriority: 3,
  488. defaultContent: ''
  489. },
  490. {
  491. title: lang.aliases,
  492. data: 'aliases',
  493. defaultContent: ''
  494. },
  495. {
  496. title: lang.mailboxes,
  497. data: 'mailboxes',
  498. responsivePriority: 4,
  499. defaultContent: ''
  500. },
  501. {
  502. title: lang.domain_quota,
  503. data: 'quota',
  504. defaultContent: '',
  505. render: function (data, type) {
  506. data = data.split("/");
  507. return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
  508. }
  509. },
  510. {
  511. title: lang.stats,
  512. data: 'stats',
  513. defaultContent: '',
  514. render: function (data, type) {
  515. data = data.split("/");
  516. return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
  517. }
  518. },
  519. {
  520. title: lang.mailbox_defquota,
  521. data: 'def_quota_for_mbox',
  522. defaultContent: ''
  523. },
  524. {
  525. title: lang.mailbox_quota,
  526. data: 'max_quota_for_mbox',
  527. defaultContent: ''
  528. },
  529. {
  530. title: 'RL',
  531. data: 'rl',
  532. defaultContent: ''
  533. },
  534. {
  535. title: lang.backup_mx,
  536. data: 'backupmx',
  537. defaultContent: '',
  538. redner: function (data, type){
  539. return 1==value ? '<i class="bi bi-check-lg"></i>' : 0==value && '<i class="bi bi-x-lg"></i>';
  540. }
  541. },
  542. {
  543. title: lang.domain_admins,
  544. data: 'domain_admins',
  545. defaultContent: '',
  546. className: 'none'
  547. },
  548. {
  549. title: 'Tags',
  550. data: 'tags',
  551. defaultContent: '',
  552. className: 'none'
  553. },
  554. {
  555. title: lang.active,
  556. data: 'active',
  557. defaultContent: '',
  558. responsivePriority: 6,
  559. render: function (data, type) {
  560. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  561. }
  562. },
  563. {
  564. title: lang.action,
  565. data: 'action',
  566. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  567. responsivePriority: 5,
  568. defaultContent: ''
  569. },
  570. ]
  571. });
  572. }
  573. function draw_templates_domain_table() {
  574. // just recalc width if instance already exists
  575. if ($.fn.DataTable.isDataTable('#templates_domain_table') ) {
  576. $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc();
  577. return;
  578. }
  579. $('#templates_domain_table').DataTable({
  580. responsive : true,
  581. processing: true,
  582. serverSide: false,
  583. language: lang_datatables,
  584. ajax: {
  585. type: "GET",
  586. url: "/api/v1/get/domain/template/all",
  587. dataSrc: function(json){
  588. console.log(json);
  589. $.each(json, function (i, item) {
  590. item.chkbox = '<input type="checkbox" data-id="domain_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  591. item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox);
  592. item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox);
  593. item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain);
  594. item.template = escapeHtml(item.template);
  595. if (item.attributes.rl_frame === "s"){
  596. item.attributes.rl_frame = lang_rl.second;
  597. } else if (item.attributes.rl_frame === "m"){
  598. item.attributes.rl_frame = lang_rl.minute;
  599. } else if (item.attributes.rl_frame === "h"){
  600. item.attributes.rl_frame = lang_rl.hour;
  601. } else if (item.attributes.rl_frame === "d"){
  602. item.attributes.rl_frame = lang_rl.day;
  603. }
  604. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  605. item.action = '<div class="btn-group">' +
  606. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  607. '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/domain/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  608. '</div>';
  609. if (Array.isArray(item.attributes.tags)){
  610. var tags = '';
  611. for (var i = 0; i < item.attributes.tags.length; i++)
  612. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  613. item.attributes.tags = tags;
  614. } else {
  615. item.attributes.tags = '';
  616. }
  617. });
  618. return json;
  619. }
  620. },
  621. columns: [
  622. {
  623. // placeholder, so checkbox will not block child row toggle
  624. title: '',
  625. data: null,
  626. searchable: false,
  627. orderable: false,
  628. defaultContent: '',
  629. responsivePriority: 1
  630. },
  631. {
  632. title: '',
  633. data: 'chkbox',
  634. searchable: false,
  635. orderable: false,
  636. defaultContent: '',
  637. responsivePriority: 1
  638. },
  639. {
  640. title: "ID",
  641. data: 'id',
  642. responsivePriority: 2,
  643. defaultContent: ''
  644. },
  645. {
  646. title: "Template",
  647. data: 'template',
  648. responsivePriority: 3,
  649. defaultContent: ''
  650. },
  651. {
  652. title: lang.max_aliases,
  653. data: 'attributes.max_num_aliases_for_domain',
  654. defaultContent: '',
  655. },
  656. {
  657. title: lang.max_mailboxes,
  658. data: 'attributes.max_num_mboxes_for_domain',
  659. defaultContent: '',
  660. },
  661. {
  662. title: lang.mailbox_defquota,
  663. data: 'attributes.def_quota_for_mbox',
  664. defaultContent: '',
  665. },
  666. {
  667. title: lang.max_quota,
  668. data: 'attributes.max_quota_for_mbox',
  669. defaultContent: '',
  670. },
  671. {
  672. title: lang.domain_quota_total,
  673. data: 'attributes.max_quota_for_domain',
  674. defaultContent: '',
  675. },
  676. {
  677. title: lang.gal,
  678. data: 'attributes.gal',
  679. defaultContent: '',
  680. render: function (data, type) {
  681. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  682. }
  683. },
  684. {
  685. title: lang.backup_mx,
  686. data: 'attributes.backupmx',
  687. defaultContent: '',
  688. render: function (data, type) {
  689. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  690. }
  691. },
  692. {
  693. title: lang.relay_all,
  694. data: 'attributes.relay_all_recipients',
  695. defaultContent: '',
  696. render: function (data, type) {
  697. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  698. }
  699. },
  700. {
  701. title: lang.relay_unknown,
  702. data: 'attributes.relay_unknown_only',
  703. defaultContent: '',
  704. render: function (data, type) {
  705. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  706. }
  707. },
  708. {
  709. title: lang.active,
  710. data: 'attributes.active',
  711. defaultContent: '',
  712. responsivePriority: 4,
  713. render: function (data, type) {
  714. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  715. }
  716. },
  717. {
  718. title: 'rl_frame',
  719. data: 'attributes.rl_frame',
  720. defaultContent: '',
  721. class: 'none',
  722. },
  723. {
  724. title: 'rl_value',
  725. data: 'attributes.rl_value',
  726. defaultContent: '',
  727. class: 'none',
  728. },
  729. {
  730. title: lang.dkim_domains_selector,
  731. data: 'attributes.dkim_selector',
  732. defaultContent: '',
  733. class: 'none',
  734. },
  735. {
  736. title: lang.dkim_key_length,
  737. data: 'attributes.key_size',
  738. defaultContent: '',
  739. class: 'none',
  740. },
  741. {
  742. title: 'Tags',
  743. data: 'attributes.tags',
  744. defaultContent: '',
  745. className: 'none'
  746. },
  747. {
  748. title: lang.action,
  749. data: 'action',
  750. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  751. responsivePriority: 6,
  752. defaultContent: ''
  753. },
  754. ]
  755. });
  756. }
  757. function draw_mailbox_table() {
  758. // just recalc width if instance already exists
  759. if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
  760. $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
  761. return;
  762. }
  763. $('#mailbox_table').DataTable({
  764. responsive : true,
  765. processing: true,
  766. serverSide: false,
  767. language: lang_datatables,
  768. ajax: {
  769. type: "GET",
  770. url: "/api/v1/get/mailbox/reduced",
  771. dataSrc: function(json){
  772. $.each(json, function (i, item) {
  773. item.quota = item.quota_used + "/" + item.quota;
  774. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  775. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  776. /*
  777. if (!item.rl) {
  778. item.rl = '∞';
  779. } else {
  780. item.rl = $.map(item.rl, function(e){
  781. return e;
  782. }).join('/1');
  783. if (item.rl_scope === 'domain') {
  784. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  785. }
  786. }
  787. */
  788. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  789. if (item.attributes.passwd_update != '0') {
  790. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  791. 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"});
  792. } else {
  793. item.last_pw_change = '-';
  794. }
  795. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  796. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  797. 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>';
  798. 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>';
  799. 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>';
  800. item.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  801. if (item.attributes.quarantine_notification === 'never') {
  802. item.quarantine_notification = lang.never;
  803. } else if (item.attributes.quarantine_notification === 'hourly') {
  804. item.quarantine_notification = lang.hourly;
  805. } else if (item.attributes.quarantine_notification === 'daily') {
  806. item.quarantine_notification = lang.daily;
  807. } else if (item.attributes.quarantine_notification === 'weekly') {
  808. item.quarantine_notification = lang.weekly;
  809. }
  810. if (item.attributes.quarantine_category === 'reject') {
  811. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  812. } else if (item.attributes.quarantine_category === 'add_header') {
  813. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  814. } else if (item.attributes.quarantine_category === 'all') {
  815. item.quarantine_category = lang.q_all;
  816. }
  817. if (acl_data.login_as === 1) {
  818. item.action = '<div class="btn-group">' +
  819. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  820. '<a href="#" data-action="delete_selected" data-id="single-mailbox" data-api-url="delete/mailbox" data-item="' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  821. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-half btn-success"><i class="bi bi-person-fill"></i> Login</a>';
  822. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  823. item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-half btn-primary" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>';
  824. }
  825. item.action += '</div>';
  826. }
  827. else {
  828. item.action = '<div class="btn-group">' +
  829. '<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>' +
  830. '<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>' +
  831. '</div>';
  832. }
  833. item.in_use = '<div class="progress">' +
  834. '<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" ' +
  835. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  836. item.username = escapeHtml(item.username);
  837. if (Array.isArray(item.tags)){
  838. var tags = '';
  839. for (var i = 0; i < item.tags.length; i++)
  840. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  841. item.tags = tags;
  842. } else {
  843. item.tags = '';
  844. }
  845. });
  846. return json;
  847. }
  848. },
  849. columns: [
  850. {
  851. // placeholder, so checkbox will not block child row toggle
  852. title: '',
  853. data: null,
  854. searchable: false,
  855. orderable: false,
  856. defaultContent: '',
  857. responsivePriority: 1
  858. },
  859. {
  860. title: '',
  861. data: 'chkbox',
  862. searchable: false,
  863. orderable: false,
  864. defaultContent: '',
  865. responsivePriority: 2
  866. },
  867. {
  868. title: lang.username,
  869. data: 'username',
  870. responsivePriority: 3,
  871. defaultContent: ''
  872. },
  873. {
  874. title: lang.domain_quota,
  875. data: 'quota',
  876. responsivePriority: 8,
  877. defaultContent: '',
  878. render: function (data, type) {
  879. data = data.split("/");
  880. var of_q = (data[1] == 0 ? "∞" : humanFileSize(data[1]));
  881. return humanFileSize(data[0]) + " / " + of_q;
  882. }
  883. },
  884. {
  885. title: lang.last_mail_login,
  886. data: 'last_mail_login',
  887. defaultContent: '',
  888. responsivePriority: 7,
  889. render: function (data, type) {
  890. res = data.split("/");
  891. return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
  892. '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
  893. '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
  894. }
  895. },
  896. {
  897. title: lang.last_pw_change,
  898. data: 'last_pw_change',
  899. defaultContent: ''
  900. },
  901. {
  902. title: lang.in_use,
  903. data: 'in_use',
  904. defaultContent: '',
  905. responsivePriority: 9,
  906. className: 'dt-data-w100'
  907. },
  908. {
  909. title: lang.fname,
  910. data: 'name',
  911. defaultContent: '',
  912. className: 'none'
  913. },
  914. {
  915. title: lang.domain,
  916. data: 'domain',
  917. defaultContent: '',
  918. className: 'none'
  919. },
  920. {
  921. title: lang.tls_enforce_in,
  922. data: 'tls_enforce_in',
  923. defaultContent: '',
  924. className: 'none'
  925. },
  926. {
  927. title: lang.tls_enforce_out,
  928. data: 'tls_enforce_out',
  929. defaultContent: '',
  930. className: 'none'
  931. },
  932. {
  933. title: 'SMTP',
  934. data: 'smtp_access',
  935. defaultContent: '',
  936. className: 'none'
  937. },
  938. {
  939. title: 'IMAP',
  940. data: 'imap_access',
  941. defaultContent: '',
  942. className: 'none'
  943. },
  944. {
  945. title: 'POP3',
  946. data: 'pop3_access',
  947. defaultContent: '',
  948. className: 'none'
  949. },
  950. {
  951. title: 'SIEVE',
  952. data: 'sieve_access',
  953. defaultContent: '',
  954. className: 'none'
  955. },
  956. {
  957. title: lang.quarantine_notification,
  958. data: 'quarantine_notification',
  959. defaultContent: '',
  960. className: 'none'
  961. },
  962. {
  963. title: lang.quarantine_category,
  964. data: 'quarantine_category',
  965. defaultContent: '',
  966. className: 'none'
  967. },
  968. {
  969. title: lang.msg_num,
  970. data: 'messages',
  971. defaultContent: '',
  972. responsivePriority: 5
  973. },
  974. {
  975. title: 'Tags',
  976. data: 'tags',
  977. defaultContent: '',
  978. className: 'none'
  979. },
  980. {
  981. title: lang.active,
  982. data: 'active',
  983. defaultContent: '',
  984. responsivePriority: 4,
  985. render: function (data, type) {
  986. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  987. }
  988. },
  989. {
  990. title: lang.action,
  991. data: 'action',
  992. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  993. responsivePriority: 6,
  994. defaultContent: ''
  995. },
  996. ]
  997. });
  998. }
  999. function draw_templates_mbox_table() {
  1000. // just recalc width if instance already exists
  1001. if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) {
  1002. $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc();
  1003. return;
  1004. }
  1005. $('#templates_mbox_table').DataTable({
  1006. responsive : true,
  1007. processing: true,
  1008. serverSide: false,
  1009. language: lang_datatables,
  1010. ajax: {
  1011. type: "GET",
  1012. url: "/api/v1/get/mailbox/template/all",
  1013. dataSrc: function(json){
  1014. $.each(json, function (i, item) {
  1015. item.chkbox = '<input type="checkbox" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1016. item.template = escapeHtml(item.template);
  1017. if (item.attributes.rl_frame === "s"){
  1018. item.attributes.rl_frame = lang_rl.second;
  1019. } else if (item.attributes.rl_frame === "m"){
  1020. item.attributes.rl_frame = lang_rl.minute;
  1021. } else if (item.attributes.rl_frame === "h"){
  1022. item.attributes.rl_frame = lang_rl.hour;
  1023. } else if (item.attributes.rl_frame === "d"){
  1024. item.attributes.rl_frame = lang_rl.day;
  1025. }
  1026. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  1027. item.attributes.quota = humanFileSize(item.attributes.quota);
  1028. item.attributes.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  1029. item.attributes.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  1030. item.attributes.pop3_access = '<i class="text-' + (item.attributes.pop3_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.pop3_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1031. item.attributes.imap_access = '<i class="text-' + (item.attributes.imap_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.imap_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1032. item.attributes.smtp_access = '<i class="text-' + (item.attributes.smtp_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.smtp_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1033. item.attributes.sieve_access = '<i class="text-' + (item.attributes.sieve_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sieve_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1034. item.attributes.sogo_access = '<i class="text-' + (item.attributes.sogo_access == 1 ? 'success' : 'danger') + ' bi bi-' + (item.attributes.sogo_access == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1035. if (item.attributes.quarantine_notification === 'never') {
  1036. item.attributes.quarantine_notification = lang.never;
  1037. } else if (item.attributes.quarantine_notification === 'hourly') {
  1038. item.attributes.quarantine_notification = lang.hourly;
  1039. } else if (item.attributes.quarantine_notification === 'daily') {
  1040. item.attributes.quarantine_notification = lang.daily;
  1041. } else if (item.attributes.quarantine_notification === 'weekly') {
  1042. item.attributes.quarantine_notification = lang.weekly;
  1043. }
  1044. if (item.attributes.quarantine_category === 'reject') {
  1045. item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  1046. } else if (item.attributes.quarantine_category === 'add_header') {
  1047. item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  1048. } else if (item.attributes.quarantine_category === 'all') {
  1049. item.attributes.quarantine_category = lang.q_all;
  1050. }
  1051. item.action = '<div class="btn-group">' +
  1052. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1053. '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/mailbox/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-xs btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1054. '</div>';
  1055. if (Array.isArray(item.attributes.tags)){
  1056. var tags = '';
  1057. for (var i = 0; i < item.attributes.tags.length; i++)
  1058. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  1059. item.attributes.tags = tags;
  1060. } else {
  1061. item.attributes.tags = '';
  1062. }
  1063. });
  1064. return json;
  1065. }
  1066. },
  1067. columns: [
  1068. {
  1069. // placeholder, so checkbox will not block child row toggle
  1070. title: '',
  1071. data: null,
  1072. searchable: false,
  1073. orderable: false,
  1074. defaultContent: '',
  1075. responsivePriority: 1
  1076. },
  1077. {
  1078. title: '',
  1079. data: 'chkbox',
  1080. searchable: false,
  1081. orderable: false,
  1082. defaultContent: '',
  1083. responsivePriority: 1
  1084. },
  1085. {
  1086. title: "ID",
  1087. data: 'id',
  1088. responsivePriority: 2,
  1089. defaultContent: ''
  1090. },
  1091. {
  1092. title: "Template",
  1093. data: 'template',
  1094. responsivePriority: 3,
  1095. defaultContent: ''
  1096. },
  1097. {
  1098. title: lang.domain_quota,
  1099. data: 'attributes.quota',
  1100. defaultContent: '',
  1101. },
  1102. {
  1103. title: lang.tls_enforce_in,
  1104. data: 'attributes.tls_enforce_in',
  1105. defaultContent: ''
  1106. },
  1107. {
  1108. title: lang.tls_enforce_out,
  1109. data: 'attributes.tls_enforce_out',
  1110. defaultContent: ''
  1111. },
  1112. {
  1113. title: 'SMTP',
  1114. data: 'attributes.smtp_access',
  1115. defaultContent: '',
  1116. },
  1117. {
  1118. title: 'IMAP',
  1119. data: 'attributes.imap_access',
  1120. defaultContent: '',
  1121. },
  1122. {
  1123. title: 'POP3',
  1124. data: 'attributes.pop3_access',
  1125. defaultContent: '',
  1126. },
  1127. {
  1128. title: 'SIEVE',
  1129. data: 'attributes.sieve_access',
  1130. defaultContent: '',
  1131. },
  1132. {
  1133. title: 'SOGO',
  1134. data: 'attributes.sogo_access',
  1135. defaultContent: '',
  1136. },
  1137. {
  1138. title: lang.quarantine_notification,
  1139. data: 'attributes.quarantine_notification',
  1140. defaultContent: '',
  1141. className: 'none'
  1142. },
  1143. {
  1144. title: lang.quarantine_category,
  1145. data: 'attributes.quarantine_category',
  1146. defaultContent: '',
  1147. className: 'none'
  1148. },
  1149. {
  1150. title: lang.force_pw_update,
  1151. data: 'attributes.force_pw_update',
  1152. defaultContent: '',
  1153. class: 'none',
  1154. render: function (data, type) {
  1155. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  1156. }
  1157. },
  1158. {
  1159. title: "rl_frame",
  1160. data: 'attributes.rl_frame',
  1161. defaultContent: '',
  1162. class: 'none',
  1163. },
  1164. {
  1165. title: 'rl_value',
  1166. data: 'attributes.rl_value',
  1167. defaultContent: '',
  1168. class: 'none',
  1169. },
  1170. {
  1171. title: 'Tags',
  1172. data: 'attributes.tags',
  1173. defaultContent: '',
  1174. className: 'none'
  1175. },
  1176. {
  1177. title: lang.active,
  1178. data: 'attributes.active',
  1179. defaultContent: '',
  1180. responsivePriority: 4,
  1181. render: function (data, type) {
  1182. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  1183. }
  1184. },
  1185. {
  1186. title: lang.action,
  1187. data: 'action',
  1188. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  1189. responsivePriority: 6,
  1190. defaultContent: ''
  1191. },
  1192. ]
  1193. });
  1194. }
  1195. function draw_resource_table() {
  1196. // just recalc width if instance already exists
  1197. if ($.fn.DataTable.isDataTable('#resource_table') ) {
  1198. $('#resource_table').DataTable().columns.adjust().responsive.recalc();
  1199. return;
  1200. }
  1201. $('#resource_table').DataTable({
  1202. processing: true,
  1203. serverSide: false,
  1204. language: lang_datatables,
  1205. ajax: {
  1206. type: "GET",
  1207. url: "/api/v1/get/resource/all",
  1208. dataSrc: function(json){
  1209. $.each(json, function (i, item) {
  1210. if (item.multiple_bookings == '0') {
  1211. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>';
  1212. } else if (item.multiple_bookings == '-1') {
  1213. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>';
  1214. } else {
  1215. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  1216. }
  1217. item.action = '<div class="btn-group">' +
  1218. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1219. '<a href="#" data-action="delete_selected" data-id="single-resource" data-api-url="delete/resource" data-item="' + item.name + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1220. '</div>';
  1221. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  1222. item.name = escapeHtml(item.name);
  1223. item.description = escapeHtml(item.description);
  1224. });
  1225. return json;
  1226. }
  1227. },
  1228. columns: [
  1229. {
  1230. // placeholder, so checkbox will not block child row toggle
  1231. title: '',
  1232. data: null,
  1233. searchable: false,
  1234. orderable: false,
  1235. defaultContent: '',
  1236. responsivePriority: 1
  1237. },
  1238. {
  1239. title: '',
  1240. data: 'chkbox',
  1241. searchable: false,
  1242. orderable: false,
  1243. defaultContent: '',
  1244. responsivePriority: 2
  1245. },
  1246. {
  1247. title: lang.description,
  1248. data: 'description',
  1249. responsivePriority: 3,
  1250. defaultContent: ''
  1251. },
  1252. {
  1253. title: lang.alias,
  1254. data: 'name',
  1255. defaultContent: ''
  1256. },
  1257. {
  1258. title: lang.kind,
  1259. data: 'kind',
  1260. defaultContent: ''
  1261. },
  1262. {
  1263. title: lang.domain,
  1264. data: 'domain',
  1265. responsivePriority: 4,
  1266. defaultContent: ''
  1267. },
  1268. {
  1269. title: lang.multiple_bookings,
  1270. data: 'multiple_bookings',
  1271. defaultContent: ''
  1272. },
  1273. {
  1274. title: lang.active,
  1275. data: 'active',
  1276. defaultContent: '',
  1277. render: function (data, type) {
  1278. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  1279. }
  1280. },
  1281. {
  1282. title: lang.action,
  1283. data: 'action',
  1284. responsivePriority: 5,
  1285. defaultContent: '',
  1286. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right'
  1287. },
  1288. ]
  1289. });
  1290. }
  1291. function draw_bcc_table() {
  1292. $.get("/api/v1/get/bcc-destination-options", function(data){
  1293. // Domains
  1294. var optgroup = "<optgroup label='" + lang.domains + "'>";
  1295. $.each(data.domains, function(index, domain){
  1296. optgroup += "<option value='" + domain + "'>" + domain + "</option>"
  1297. });
  1298. optgroup += "</optgroup>"
  1299. $('#bcc-local-dest').append(optgroup);
  1300. // Alias domains
  1301. var optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
  1302. $.each(data.alias_domains, function(index, alias_domain){
  1303. optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>"
  1304. });
  1305. optgroup += "</optgroup>"
  1306. $('#bcc-local-dest').append(optgroup);
  1307. // Mailboxes and aliases
  1308. $.each(data.mailboxes, function(mailbox, aliases){
  1309. var optgroup = "<optgroup label='" + mailbox + "'>";
  1310. $.each(aliases, function(index, alias){
  1311. optgroup += "<option value='" + alias + "'>" + alias + "</option>"
  1312. });
  1313. optgroup += "</optgroup>"
  1314. $('#bcc-local-dest').append(optgroup);
  1315. });
  1316. // Finish
  1317. $('#bcc-local-dest').selectpicker('refresh');
  1318. });
  1319. // just recalc width if instance already exists
  1320. if ($.fn.DataTable.isDataTable('#bcc_table') ) {
  1321. $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
  1322. return;
  1323. }
  1324. $('#bcc_table').DataTable({
  1325. processing: true,
  1326. serverSide: false,
  1327. language: lang_datatables,
  1328. ajax: {
  1329. type: "GET",
  1330. url: "/api/v1/get/bcc/all",
  1331. dataSrc: function(json){
  1332. $.each(json, function (i, item) {
  1333. item.action = '<div class="btn-group">' +
  1334. '<a href="/edit/bcc/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1335. '<a href="#" data-action="delete_selected" data-id="single-bcc" data-api-url="delete/bcc" data-item="' + item.id + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1336. '</div>';
  1337. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  1338. item.local_dest = escapeHtml(item.local_dest);
  1339. item.bcc_dest = escapeHtml(item.bcc_dest);
  1340. if (item.type == 'sender') {
  1341. item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>';
  1342. } else {
  1343. item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>';
  1344. }
  1345. });
  1346. return json;
  1347. }
  1348. },
  1349. columns: [
  1350. {
  1351. // placeholder, so checkbox will not block child row toggle
  1352. title: '',
  1353. data: null,
  1354. searchable: false,
  1355. orderable: false,
  1356. defaultContent: '',
  1357. responsivePriority: 1
  1358. },
  1359. {
  1360. title: '',
  1361. data: 'chkbox',
  1362. searchable: false,
  1363. orderable: false,
  1364. defaultContent: '',
  1365. responsivePriority: 2
  1366. },
  1367. {
  1368. title: 'ID',
  1369. data: 'id',
  1370. responsivePriority: 3,
  1371. defaultContent: ''
  1372. },
  1373. {
  1374. title: lang.bcc_type,
  1375. data: 'type',
  1376. defaultContent: ''
  1377. },
  1378. {
  1379. title: lang.bcc_local_dest,
  1380. data: 'local_dest',
  1381. defaultContent: ''
  1382. },
  1383. {
  1384. title: lang.bcc_destinations,
  1385. data: 'bcc_dest',
  1386. defaultContent: ''
  1387. },
  1388. {
  1389. title: lang.domain,
  1390. data: 'domain',
  1391. responsivePriority: 4,
  1392. defaultContent: ''
  1393. },
  1394. {
  1395. title: lang.active,
  1396. data: 'active',
  1397. defaultContent: '',
  1398. render: function (data, type) {
  1399. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  1400. }
  1401. },
  1402. {
  1403. title: lang.action,
  1404. data: 'action',
  1405. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1406. responsivePriority: 5,
  1407. defaultContent: ''
  1408. },
  1409. ]
  1410. });
  1411. }
  1412. function draw_recipient_map_table() {
  1413. // just recalc width if instance already exists
  1414. if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
  1415. $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
  1416. return;
  1417. }
  1418. $('#recipient_map_table').DataTable({
  1419. processing: true,
  1420. serverSide: false,
  1421. language: lang_datatables,
  1422. ajax: {
  1423. type: "GET",
  1424. url: "/api/v1/get/recipient_map/all",
  1425. dataSrc: function(json){
  1426. if (role !== "admin") return null;
  1427. $.each(json, function (i, item) {
  1428. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  1429. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  1430. item.action = '<div class="btn-group">' +
  1431. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1432. '<a href="#" data-action="delete_selected" data-id="single-recipient_map" data-api-url="delete/recipient_map" data-item="' + item.id + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1433. '</div>';
  1434. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  1435. });
  1436. return json;
  1437. }
  1438. },
  1439. columns: [
  1440. {
  1441. // placeholder, so checkbox will not block child row toggle
  1442. title: '',
  1443. data: null,
  1444. searchable: false,
  1445. orderable: false,
  1446. defaultContent: '',
  1447. responsivePriority: 1
  1448. },
  1449. {
  1450. title: '',
  1451. data: 'chkbox',
  1452. searchable: false,
  1453. orderable: false,
  1454. defaultContent: '',
  1455. responsivePriority: 2
  1456. },
  1457. {
  1458. title: 'ID',
  1459. data: 'id',
  1460. responsivePriority: 3,
  1461. defaultContent: ''
  1462. },
  1463. {
  1464. title: lang.recipient_map_old,
  1465. data: 'recipient_map_old',
  1466. defaultContent: ''
  1467. },
  1468. {
  1469. title: lang.recipient_map_new,
  1470. data: 'recipient_map_new',
  1471. defaultContent: '',
  1472. responsivePriority: 4
  1473. },
  1474. {
  1475. title: lang.active,
  1476. data: 'active',
  1477. defaultContent: '',
  1478. render: function (data, type) {
  1479. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1480. }
  1481. },
  1482. {
  1483. title: lang.action,
  1484. data: 'action',
  1485. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1486. responsivePriority: 5,
  1487. defaultContent: ''
  1488. },
  1489. ]
  1490. });
  1491. }
  1492. function draw_tls_policy_table() {
  1493. // just recalc width if instance already exists
  1494. if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
  1495. $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
  1496. return;
  1497. }
  1498. $('#tls_policy_table').DataTable({
  1499. processing: true,
  1500. serverSide: false,
  1501. language: lang_datatables,
  1502. ajax: {
  1503. type: "GET",
  1504. url: "/api/v1/get/tls-policy-map/all",
  1505. dataSrc: function(json){
  1506. console.log(json);
  1507. if (role !== "admin") return null;
  1508. $.each(json, function (i, item) {
  1509. item.dest = escapeHtml(item.dest);
  1510. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  1511. if (item.parameters == '') {
  1512. item.parameters = '<code>-</code>';
  1513. } else {
  1514. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  1515. }
  1516. item.action = '<div class="btn-group">' +
  1517. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1518. '<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-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1519. '</div>';
  1520. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  1521. });
  1522. return json;
  1523. }
  1524. },
  1525. columns: [
  1526. {
  1527. // placeholder, so checkbox will not block child row toggle
  1528. title: '',
  1529. data: null,
  1530. searchable: false,
  1531. orderable: false,
  1532. defaultContent: '',
  1533. responsivePriority: 1
  1534. },
  1535. {
  1536. title: '',
  1537. data: 'chkbox',
  1538. searchable: false,
  1539. orderable: false,
  1540. defaultContent: '',
  1541. responsivePriority: 2
  1542. },
  1543. {
  1544. title: 'ID',
  1545. data: 'id',
  1546. responsivePriority: 3,
  1547. defaultContent: ''
  1548. },
  1549. {
  1550. title: lang.tls_map_dest,
  1551. data: 'dest',
  1552. defaultContent: '',
  1553. responsivePriority: 4
  1554. },
  1555. {
  1556. title: lang.tls_map_policy,
  1557. data: 'policy',
  1558. defaultContent: ''
  1559. },
  1560. {
  1561. title: lang.tls_map_parameters,
  1562. data: 'parameters',
  1563. defaultContent: ''
  1564. },
  1565. {
  1566. title: lang.active,
  1567. data: 'active',
  1568. defaultContent: '',
  1569. render: function (data, type) {
  1570. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1571. }
  1572. },
  1573. {
  1574. title: lang.action,
  1575. data: 'action',
  1576. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1577. responsivePriority: 5,
  1578. defaultContent: ''
  1579. },
  1580. ]
  1581. });
  1582. }
  1583. function draw_alias_table() {
  1584. // just recalc width if instance already exists
  1585. if ($.fn.DataTable.isDataTable('#alias_table') ) {
  1586. $('#alias_table').DataTable().columns.adjust().responsive.recalc();
  1587. return;
  1588. }
  1589. $('#alias_table').DataTable({
  1590. processing: true,
  1591. serverSide: false,
  1592. language: lang_datatables,
  1593. ajax: {
  1594. type: "GET",
  1595. url: "/api/v1/get/alias/all",
  1596. dataSrc: function(json){
  1597. $.each(json, function (i, item) {
  1598. item.action = '<div class="btn-group">' +
  1599. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1600. '<a href="#" data-action="delete_selected" data-id="single-alias" data-api-url="delete/alias" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1601. '</div>';
  1602. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1603. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  1604. if (item.public_comment !== null) {
  1605. item.public_comment = escapeHtml(item.public_comment);
  1606. }
  1607. else {
  1608. item.public_comment = '-';
  1609. }
  1610. if (item.private_comment !== null) {
  1611. item.private_comment = escapeHtml(item.private_comment);
  1612. }
  1613. else {
  1614. item.private_comment = '-';
  1615. }
  1616. if (item.is_catch_all == 1) {
  1617. item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
  1618. }
  1619. else {
  1620. item.address = escapeHtml(item.address);
  1621. }
  1622. if (item.goto == "null@localhost") {
  1623. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  1624. }
  1625. else if (item.goto == "spam@localhost") {
  1626. item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
  1627. }
  1628. else if (item.goto == "ham@localhost") {
  1629. item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
  1630. }
  1631. if (item.in_primary_domain !== "") {
  1632. 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;
  1633. }
  1634. });
  1635. return json;
  1636. }
  1637. },
  1638. columns: [
  1639. {
  1640. // placeholder, so checkbox will not block child row toggle
  1641. title: '',
  1642. data: null,
  1643. searchable: false,
  1644. orderable: false,
  1645. defaultContent: '',
  1646. responsivePriority: 1
  1647. },
  1648. {
  1649. title: '',
  1650. data: 'chkbox',
  1651. searchable: false,
  1652. orderable: false,
  1653. defaultContent: '',
  1654. responsivePriority: 2
  1655. },
  1656. {
  1657. title: 'ID',
  1658. data: 'id',
  1659. responsivePriority: 3,
  1660. defaultContent: ''
  1661. },
  1662. {
  1663. title: lang.alias,
  1664. data: 'address',
  1665. responsivePriority: 4,
  1666. defaultContent: ''
  1667. },
  1668. {
  1669. title: lang.target_address,
  1670. data: 'goto',
  1671. defaultContent: ''
  1672. },
  1673. {
  1674. title: lang.domain,
  1675. data: 'domain',
  1676. defaultContent: '',
  1677. responsivePriority: 5,
  1678. },
  1679. {
  1680. title: lang.bcc_destinations,
  1681. data: 'bcc_dest',
  1682. defaultContent: ''
  1683. },
  1684. {
  1685. title: lang.sogo_visible,
  1686. data: 'sogo_visible',
  1687. defaultContent: '',
  1688. render: function(data, type){
  1689. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1690. }
  1691. },
  1692. {
  1693. title: lang.public_comment,
  1694. data: 'public_comment',
  1695. defaultContent: ''
  1696. },
  1697. {
  1698. title: lang.private_comment,
  1699. data: 'private_comment',
  1700. defaultContent: ''
  1701. },
  1702. {
  1703. title: lang.active,
  1704. data: 'active',
  1705. defaultContent: '',
  1706. responsivePriority: 6,
  1707. render: function (data, type) {
  1708. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1709. }
  1710. },
  1711. {
  1712. title: lang.action,
  1713. data: 'action',
  1714. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1715. responsivePriority: 5,
  1716. defaultContent: ''
  1717. },
  1718. ]
  1719. });
  1720. }
  1721. function draw_aliasdomain_table() {
  1722. // just recalc width if instance already exists
  1723. if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
  1724. $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
  1725. return;
  1726. }
  1727. $('#aliasdomain_table').DataTable({
  1728. processing: true,
  1729. serverSide: false,
  1730. language: lang_datatables,
  1731. ajax: {
  1732. type: "GET",
  1733. url: "/api/v1/get/alias-domain/all",
  1734. dataSrc: function(json){
  1735. $.each(json, function (i, item) {
  1736. item.action = '<div class="btn-group">' +
  1737. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1738. '<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-sm btn-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1739. '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-third btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><i class="bi bi-globe2"></i> DNS</a></div>' +
  1740. '</div>';
  1741. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  1742. if(item.parent_is_backupmx == '1') {
  1743. 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>';
  1744. } else {
  1745. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  1746. }
  1747. });
  1748. return json;
  1749. }
  1750. },
  1751. columns: [
  1752. {
  1753. // placeholder, so checkbox will not block child row toggle
  1754. title: '',
  1755. data: null,
  1756. searchable: false,
  1757. orderable: false,
  1758. defaultContent: '',
  1759. responsivePriority: 1
  1760. },
  1761. {
  1762. title: '',
  1763. data: 'chkbox',
  1764. searchable: false,
  1765. orderable: false,
  1766. defaultContent: '',
  1767. responsivePriority: 2
  1768. },
  1769. {
  1770. title: lang.alias,
  1771. data: 'alias_domain',
  1772. responsivePriority: 3,
  1773. defaultContent: ''
  1774. },
  1775. {
  1776. title: lang.target_domain,
  1777. data: 'target_domain',
  1778. responsivePriority: 4,
  1779. defaultContent: ''
  1780. },
  1781. {
  1782. title: lang.active,
  1783. data: 'active',
  1784. defaultContent: '',
  1785. render: function (data, type) {
  1786. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1787. }
  1788. },
  1789. {
  1790. title: lang.action,
  1791. data: 'action',
  1792. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1793. responsivePriority: 5,
  1794. defaultContent: ''
  1795. },
  1796. ]
  1797. });
  1798. }
  1799. function draw_sync_job_table() {
  1800. // just recalc width if instance already exists
  1801. if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
  1802. $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
  1803. return;
  1804. }
  1805. $('#sync_job_table').DataTable({
  1806. processing: true,
  1807. serverSide: false,
  1808. language: lang_datatables,
  1809. ajax: {
  1810. type: "GET",
  1811. url: "/api/v1/get/syncjobs/all/no_log",
  1812. dataSrc: function(json){
  1813. $.each(json, function (i, item) {
  1814. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
  1815. item.user2 = escapeHtml(item.user2);
  1816. if (!item.exclude > 0) {
  1817. item.exclude = '-';
  1818. } else {
  1819. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  1820. }
  1821. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  1822. item.action = '<div class="btn-group">' +
  1823. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1824. '<a href="#" data-action="delete_selected" data-id="single-syncjob" data-api-url="delete/syncjob" data-item="' + item.id + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1825. '</div>';
  1826. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  1827. if (item.is_running == 1) {
  1828. item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
  1829. } else {
  1830. item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
  1831. }
  1832. if (!item.last_run > 0) {
  1833. item.last_run = lang.waiting;
  1834. }
  1835. if (item.success == null) {
  1836. item.success = '-';
  1837. item.exit_status = '';
  1838. } else {
  1839. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1840. }
  1841. if (lang['syncjob_'+item.exit_status]) {
  1842. item.exit_status = lang['syncjob_'+item.exit_status];
  1843. } else if (item.success != '-') {
  1844. item.exit_status = lang.syncjob_check_log;
  1845. }
  1846. item.exit_status = item.success + ' ' + item.exit_status;
  1847. });
  1848. return json;
  1849. }
  1850. },
  1851. columns: [
  1852. {
  1853. // placeholder, so checkbox will not block child row toggle
  1854. title: '',
  1855. data: null,
  1856. searchable: false,
  1857. orderable: false,
  1858. defaultContent: '',
  1859. responsivePriority: 1
  1860. },
  1861. {
  1862. title: '',
  1863. data: 'chkbox',
  1864. searchable: false,
  1865. orderable: false,
  1866. defaultContent: '',
  1867. responsivePriority: 2
  1868. },
  1869. {
  1870. title: 'ID',
  1871. data: 'id',
  1872. responsivePriority: 3,
  1873. defaultContent: ''
  1874. },
  1875. {
  1876. title: lang.owner,
  1877. data: 'user2',
  1878. responsivePriority: 4,
  1879. defaultContent: ''
  1880. },
  1881. {
  1882. title: 'Server',
  1883. data: 'server_w_port',
  1884. defaultContent: ''
  1885. },
  1886. {
  1887. title: lang.last_run,
  1888. data: 'last_run',
  1889. defaultContent: ''
  1890. },
  1891. {
  1892. title: lang.syncjob_last_run_result,
  1893. data: 'exit_status',
  1894. defaultContent: ''
  1895. },
  1896. {
  1897. title: 'Log',
  1898. data: 'log',
  1899. defaultContent: ''
  1900. },
  1901. {
  1902. title: lang.active,
  1903. data: 'active',
  1904. defaultContent: '',
  1905. render: function (data, type) {
  1906. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1907. }
  1908. },
  1909. {
  1910. title: lang.status,
  1911. data: 'is_running',
  1912. defaultContent: ''
  1913. },
  1914. {
  1915. title: lang.excludes,
  1916. data: 'exclude',
  1917. defaultContent: '',
  1918. className: 'none'
  1919. },
  1920. {
  1921. title: lang.mins_interval,
  1922. data: 'mins_interval',
  1923. defaultContent: '',
  1924. className: 'none'
  1925. },
  1926. {
  1927. title: lang.action,
  1928. data: 'action',
  1929. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1930. responsivePriority: 5,
  1931. defaultContent: ''
  1932. },
  1933. ]
  1934. });
  1935. }
  1936. function draw_filter_table() {
  1937. // just recalc width if instance already exists
  1938. if ($.fn.DataTable.isDataTable('#filter_table') ) {
  1939. $('#filter_table').DataTable().columns.adjust().responsive.recalc();
  1940. return;
  1941. }
  1942. var table = $('#filter_table').DataTable({
  1943. autoWidth: false,
  1944. processing: true,
  1945. serverSide: false,
  1946. language: lang_datatables,
  1947. ajax: {
  1948. type: "GET",
  1949. url: "/api/v1/get/filters/all",
  1950. dataSrc: function(json){
  1951. $.each(json, function (i, item) {
  1952. if (item.active == 1) {
  1953. item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
  1954. } else {
  1955. item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
  1956. }
  1957. item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1958. item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1959. item.action = '<div class="btn-group">' +
  1960. '<a href="/edit/filter/' + item.id + '" class="btn btn-sm btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1961. '<a href="#" data-action="delete_selected" data-id="single-filter" data-api-url="delete/filter" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1962. '</div>';
  1963. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1964. });
  1965. return json;
  1966. }
  1967. },
  1968. columns: [
  1969. {
  1970. // placeholder, so checkbox will not block child row toggle
  1971. title: '',
  1972. data: null,
  1973. searchable: false,
  1974. orderable: false,
  1975. defaultContent: '',
  1976. responsivePriority: 1
  1977. },
  1978. {
  1979. title: '',
  1980. data: 'chkbox',
  1981. searchable: false,
  1982. orderable: false,
  1983. defaultContent: '',
  1984. responsivePriority: 2
  1985. },
  1986. {
  1987. title: 'ID',
  1988. data: 'id',
  1989. responsivePriority: 2,
  1990. defaultContent: ''
  1991. },
  1992. {
  1993. title: lang.active,
  1994. data: 'active',
  1995. responsivePriority: 3,
  1996. defaultContent: ''
  1997. },
  1998. {
  1999. title: 'Type',
  2000. data: 'filter_type',
  2001. responsivePriority: 4,
  2002. defaultContent: ''
  2003. },
  2004. {
  2005. title: lang.owner,
  2006. data: 'username',
  2007. defaultContent: ''
  2008. },
  2009. {
  2010. title: lang.description,
  2011. data: 'script_desc',
  2012. defaultContent: ''
  2013. },
  2014. {
  2015. title: 'Script',
  2016. data: 'script_data',
  2017. defaultContent: '',
  2018. className: 'none'
  2019. },
  2020. {
  2021. title: lang.action,
  2022. data: 'action',
  2023. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  2024. responsivePriority: 5,
  2025. defaultContent: ''
  2026. },
  2027. ]
  2028. });
  2029. };
  2030. // detect element visibility changes
  2031. function onVisible(element, callback) {
  2032. $(document).ready(function() {
  2033. element_object = document.querySelector(element);
  2034. if (element_object === null) return;
  2035. new IntersectionObserver((entries, observer) => {
  2036. entries.forEach(entry => {
  2037. if(entry.intersectionRatio > 0) {
  2038. callback(element_object);
  2039. }
  2040. });
  2041. }).observe(element_object);
  2042. });
  2043. }
  2044. // Load only if the tab is visible
  2045. onVisible("[id^=domain_table]", () => draw_domain_table());
  2046. onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table());
  2047. onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
  2048. onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table());
  2049. onVisible("[id^=resource_table]", () => draw_resource_table());
  2050. onVisible("[id^=alias_table]", () => draw_alias_table());
  2051. onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
  2052. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  2053. onVisible("[id^=filter_table]", () => draw_filter_table());
  2054. onVisible("[id^=bcc_table]", () => draw_bcc_table());
  2055. onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
  2056. onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
  2057. });