mailbox.js 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149
  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: lang.created_on,
  550. data: 'created',
  551. defaultContent: '',
  552. className: 'none'
  553. },
  554. {
  555. title: lang.last_modified,
  556. data: 'modified',
  557. defaultContent: '',
  558. className: 'none'
  559. },
  560. {
  561. title: 'Tags',
  562. data: 'tags',
  563. defaultContent: '',
  564. className: 'none'
  565. },
  566. {
  567. title: lang.active,
  568. data: 'active',
  569. defaultContent: '',
  570. responsivePriority: 6,
  571. render: function (data, type) {
  572. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  573. }
  574. },
  575. {
  576. title: lang.action,
  577. data: 'action',
  578. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  579. responsivePriority: 5,
  580. defaultContent: ''
  581. },
  582. ]
  583. });
  584. }
  585. function draw_templates_domain_table() {
  586. // just recalc width if instance already exists
  587. if ($.fn.DataTable.isDataTable('#templates_domain_table') ) {
  588. $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc();
  589. return;
  590. }
  591. $('#templates_domain_table').DataTable({
  592. responsive : true,
  593. processing: true,
  594. serverSide: false,
  595. language: lang_datatables,
  596. ajax: {
  597. type: "GET",
  598. url: "/api/v1/get/domain/template/all",
  599. dataSrc: function(json){
  600. console.log(json);
  601. $.each(json, function (i, item) {
  602. item.chkbox = '<input type="checkbox" data-id="domain_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  603. item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox);
  604. item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox);
  605. item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain);
  606. item.template = escapeHtml(item.template);
  607. if (item.attributes.rl_frame === "s"){
  608. item.attributes.rl_frame = lang_rl.second;
  609. } else if (item.attributes.rl_frame === "m"){
  610. item.attributes.rl_frame = lang_rl.minute;
  611. } else if (item.attributes.rl_frame === "h"){
  612. item.attributes.rl_frame = lang_rl.hour;
  613. } else if (item.attributes.rl_frame === "d"){
  614. item.attributes.rl_frame = lang_rl.day;
  615. }
  616. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  617. item.action = '<div class="btn-group">' +
  618. '<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>' +
  619. '<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>' +
  620. '</div>';
  621. if (Array.isArray(item.attributes.tags)){
  622. var tags = '';
  623. for (var i = 0; i < item.attributes.tags.length; i++)
  624. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  625. item.attributes.tags = tags;
  626. } else {
  627. item.attributes.tags = '';
  628. }
  629. });
  630. return json;
  631. }
  632. },
  633. columns: [
  634. {
  635. // placeholder, so checkbox will not block child row toggle
  636. title: '',
  637. data: null,
  638. searchable: false,
  639. orderable: false,
  640. defaultContent: '',
  641. responsivePriority: 1
  642. },
  643. {
  644. title: '',
  645. data: 'chkbox',
  646. searchable: false,
  647. orderable: false,
  648. defaultContent: '',
  649. responsivePriority: 1
  650. },
  651. {
  652. title: "ID",
  653. data: 'id',
  654. responsivePriority: 2,
  655. defaultContent: ''
  656. },
  657. {
  658. title: "Template",
  659. data: 'template',
  660. responsivePriority: 3,
  661. defaultContent: ''
  662. },
  663. {
  664. title: lang.max_aliases,
  665. data: 'attributes.max_num_aliases_for_domain',
  666. defaultContent: '',
  667. },
  668. {
  669. title: lang.max_mailboxes,
  670. data: 'attributes.max_num_mboxes_for_domain',
  671. defaultContent: '',
  672. },
  673. {
  674. title: lang.mailbox_defquota,
  675. data: 'attributes.def_quota_for_mbox',
  676. defaultContent: '',
  677. },
  678. {
  679. title: lang.max_quota,
  680. data: 'attributes.max_quota_for_mbox',
  681. defaultContent: '',
  682. },
  683. {
  684. title: lang.domain_quota_total,
  685. data: 'attributes.max_quota_for_domain',
  686. defaultContent: '',
  687. },
  688. {
  689. title: lang.gal,
  690. data: 'attributes.gal',
  691. defaultContent: '',
  692. render: function (data, type) {
  693. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  694. }
  695. },
  696. {
  697. title: lang.backup_mx,
  698. data: 'attributes.backupmx',
  699. defaultContent: '',
  700. render: function (data, type) {
  701. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  702. }
  703. },
  704. {
  705. title: lang.relay_all,
  706. data: 'attributes.relay_all_recipients',
  707. defaultContent: '',
  708. render: function (data, type) {
  709. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  710. }
  711. },
  712. {
  713. title: lang.relay_unknown,
  714. data: 'attributes.relay_unknown_only',
  715. defaultContent: '',
  716. render: function (data, type) {
  717. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  718. }
  719. },
  720. {
  721. title: lang.active,
  722. data: 'attributes.active',
  723. defaultContent: '',
  724. responsivePriority: 4,
  725. render: function (data, type) {
  726. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  727. }
  728. },
  729. {
  730. title: 'rl_frame',
  731. data: 'attributes.rl_frame',
  732. defaultContent: '',
  733. class: 'none',
  734. },
  735. {
  736. title: 'rl_value',
  737. data: 'attributes.rl_value',
  738. defaultContent: '',
  739. class: 'none',
  740. },
  741. {
  742. title: lang.dkim_domains_selector,
  743. data: 'attributes.dkim_selector',
  744. defaultContent: '',
  745. class: 'none',
  746. },
  747. {
  748. title: lang.dkim_key_length,
  749. data: 'attributes.key_size',
  750. defaultContent: '',
  751. class: 'none',
  752. },
  753. {
  754. title: 'Tags',
  755. data: 'attributes.tags',
  756. defaultContent: '',
  757. className: 'none'
  758. },
  759. {
  760. title: lang.action,
  761. data: 'action',
  762. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  763. responsivePriority: 6,
  764. defaultContent: ''
  765. },
  766. ]
  767. });
  768. }
  769. function draw_mailbox_table() {
  770. // just recalc width if instance already exists
  771. if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
  772. $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
  773. return;
  774. }
  775. $('#mailbox_table').DataTable({
  776. responsive : true,
  777. processing: true,
  778. serverSide: false,
  779. language: lang_datatables,
  780. ajax: {
  781. type: "GET",
  782. url: "/api/v1/get/mailbox/reduced",
  783. dataSrc: function(json){
  784. $.each(json, function (i, item) {
  785. item.quota = item.quota_used + "/" + item.quota;
  786. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  787. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  788. /*
  789. if (!item.rl) {
  790. item.rl = '∞';
  791. } else {
  792. item.rl = $.map(item.rl, function(e){
  793. return e;
  794. }).join('/1');
  795. if (item.rl_scope === 'domain') {
  796. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  797. }
  798. }
  799. */
  800. item.chkbox = '<input type="checkbox" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  801. if (item.attributes.passwd_update != '0') {
  802. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  803. 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"});
  804. } else {
  805. item.last_pw_change = '-';
  806. }
  807. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  808. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  809. 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>';
  810. 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>';
  811. 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>';
  812. 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>';
  813. if (item.attributes.quarantine_notification === 'never') {
  814. item.quarantine_notification = lang.never;
  815. } else if (item.attributes.quarantine_notification === 'hourly') {
  816. item.quarantine_notification = lang.hourly;
  817. } else if (item.attributes.quarantine_notification === 'daily') {
  818. item.quarantine_notification = lang.daily;
  819. } else if (item.attributes.quarantine_notification === 'weekly') {
  820. item.quarantine_notification = lang.weekly;
  821. }
  822. if (item.attributes.quarantine_category === 'reject') {
  823. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  824. } else if (item.attributes.quarantine_category === 'add_header') {
  825. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  826. } else if (item.attributes.quarantine_category === 'all') {
  827. item.quarantine_category = lang.q_all;
  828. }
  829. if (acl_data.login_as === 1) {
  830. item.action = '<div class="btn-group">' +
  831. '<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>' +
  832. '<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>' +
  833. '<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>';
  834. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  835. 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>';
  836. }
  837. item.action += '</div>';
  838. }
  839. else {
  840. item.action = '<div class="btn-group">' +
  841. '<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>' +
  842. '<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>' +
  843. '</div>';
  844. }
  845. item.in_use = '<div class="progress">' +
  846. '<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" ' +
  847. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>';
  848. item.username = escapeHtml(item.username);
  849. if (Array.isArray(item.tags)){
  850. var tags = '';
  851. for (var i = 0; i < item.tags.length; i++)
  852. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  853. item.tags = tags;
  854. } else {
  855. item.tags = '';
  856. }
  857. });
  858. return json;
  859. }
  860. },
  861. columns: [
  862. {
  863. // placeholder, so checkbox will not block child row toggle
  864. title: '',
  865. data: null,
  866. searchable: false,
  867. orderable: false,
  868. defaultContent: '',
  869. responsivePriority: 1
  870. },
  871. {
  872. title: '',
  873. data: 'chkbox',
  874. searchable: false,
  875. orderable: false,
  876. defaultContent: '',
  877. responsivePriority: 2
  878. },
  879. {
  880. title: lang.username,
  881. data: 'username',
  882. responsivePriority: 3,
  883. defaultContent: ''
  884. },
  885. {
  886. title: lang.domain_quota,
  887. data: 'quota',
  888. responsivePriority: 8,
  889. defaultContent: '',
  890. render: function (data, type) {
  891. data = data.split("/");
  892. var of_q = (data[1] == 0 ? "∞" : humanFileSize(data[1]));
  893. return humanFileSize(data[0]) + " / " + of_q;
  894. }
  895. },
  896. {
  897. title: lang.last_mail_login,
  898. data: 'last_mail_login',
  899. defaultContent: '',
  900. responsivePriority: 7,
  901. render: function (data, type) {
  902. res = data.split("/");
  903. return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
  904. '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
  905. '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
  906. }
  907. },
  908. {
  909. title: lang.last_pw_change,
  910. data: 'last_pw_change',
  911. defaultContent: ''
  912. },
  913. {
  914. title: lang.in_use,
  915. data: 'in_use',
  916. defaultContent: '',
  917. responsivePriority: 9,
  918. className: 'dt-data-w100'
  919. },
  920. {
  921. title: lang.fname,
  922. data: 'name',
  923. defaultContent: '',
  924. className: 'none'
  925. },
  926. {
  927. title: lang.domain,
  928. data: 'domain',
  929. defaultContent: '',
  930. className: 'none'
  931. },
  932. {
  933. title: lang.tls_enforce_in,
  934. data: 'tls_enforce_in',
  935. defaultContent: '',
  936. className: 'none'
  937. },
  938. {
  939. title: lang.tls_enforce_out,
  940. data: 'tls_enforce_out',
  941. defaultContent: '',
  942. className: 'none'
  943. },
  944. {
  945. title: 'SMTP',
  946. data: 'smtp_access',
  947. defaultContent: '',
  948. className: 'none'
  949. },
  950. {
  951. title: 'IMAP',
  952. data: 'imap_access',
  953. defaultContent: '',
  954. className: 'none'
  955. },
  956. {
  957. title: 'POP3',
  958. data: 'pop3_access',
  959. defaultContent: '',
  960. className: 'none'
  961. },
  962. {
  963. title: 'SIEVE',
  964. data: 'sieve_access',
  965. defaultContent: '',
  966. className: 'none'
  967. },
  968. {
  969. title: lang.quarantine_notification,
  970. data: 'quarantine_notification',
  971. defaultContent: '',
  972. className: 'none'
  973. },
  974. {
  975. title: lang.quarantine_category,
  976. data: 'quarantine_category',
  977. defaultContent: '',
  978. className: 'none'
  979. },
  980. {
  981. title: lang.msg_num,
  982. data: 'messages',
  983. defaultContent: '',
  984. responsivePriority: 5
  985. },
  986. {
  987. title: lang.created_on,
  988. data: 'created',
  989. defaultContent: '',
  990. className: 'none'
  991. },
  992. {
  993. title: lang.last_modified,
  994. data: 'modified',
  995. defaultContent: '',
  996. className: 'none'
  997. },
  998. {
  999. title: 'Tags',
  1000. data: 'tags',
  1001. defaultContent: '',
  1002. className: 'none'
  1003. },
  1004. {
  1005. title: lang.active,
  1006. data: 'active',
  1007. defaultContent: '',
  1008. responsivePriority: 4,
  1009. render: function (data, type) {
  1010. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  1011. }
  1012. },
  1013. {
  1014. title: lang.action,
  1015. data: 'action',
  1016. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  1017. responsivePriority: 6,
  1018. defaultContent: ''
  1019. },
  1020. ]
  1021. });
  1022. }
  1023. function draw_templates_mbox_table() {
  1024. // just recalc width if instance already exists
  1025. if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) {
  1026. $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc();
  1027. return;
  1028. }
  1029. $('#templates_mbox_table').DataTable({
  1030. responsive : true,
  1031. processing: true,
  1032. serverSide: false,
  1033. language: lang_datatables,
  1034. ajax: {
  1035. type: "GET",
  1036. url: "/api/v1/get/mailbox/template/all",
  1037. dataSrc: function(json){
  1038. $.each(json, function (i, item) {
  1039. item.chkbox = '<input type="checkbox" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1040. item.template = escapeHtml(item.template);
  1041. if (item.attributes.rl_frame === "s"){
  1042. item.attributes.rl_frame = lang_rl.second;
  1043. } else if (item.attributes.rl_frame === "m"){
  1044. item.attributes.rl_frame = lang_rl.minute;
  1045. } else if (item.attributes.rl_frame === "h"){
  1046. item.attributes.rl_frame = lang_rl.hour;
  1047. } else if (item.attributes.rl_frame === "d"){
  1048. item.attributes.rl_frame = lang_rl.day;
  1049. }
  1050. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  1051. item.attributes.quota = humanFileSize(item.attributes.quota);
  1052. 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>';
  1053. 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>';
  1054. 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>';
  1055. 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>';
  1056. 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>';
  1057. 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>';
  1058. 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>';
  1059. if (item.attributes.quarantine_notification === 'never') {
  1060. item.attributes.quarantine_notification = lang.never;
  1061. } else if (item.attributes.quarantine_notification === 'hourly') {
  1062. item.attributes.quarantine_notification = lang.hourly;
  1063. } else if (item.attributes.quarantine_notification === 'daily') {
  1064. item.attributes.quarantine_notification = lang.daily;
  1065. } else if (item.attributes.quarantine_notification === 'weekly') {
  1066. item.attributes.quarantine_notification = lang.weekly;
  1067. }
  1068. if (item.attributes.quarantine_category === 'reject') {
  1069. item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  1070. } else if (item.attributes.quarantine_category === 'add_header') {
  1071. item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  1072. } else if (item.attributes.quarantine_category === 'all') {
  1073. item.attributes.quarantine_category = lang.q_all;
  1074. }
  1075. item.action = '<div class="btn-group">' +
  1076. '<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>' +
  1077. '<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>' +
  1078. '</div>';
  1079. if (Array.isArray(item.attributes.tags)){
  1080. var tags = '';
  1081. for (var i = 0; i < item.attributes.tags.length; i++)
  1082. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  1083. item.attributes.tags = tags;
  1084. } else {
  1085. item.attributes.tags = '';
  1086. }
  1087. });
  1088. return json;
  1089. }
  1090. },
  1091. columns: [
  1092. {
  1093. // placeholder, so checkbox will not block child row toggle
  1094. title: '',
  1095. data: null,
  1096. searchable: false,
  1097. orderable: false,
  1098. defaultContent: '',
  1099. responsivePriority: 1
  1100. },
  1101. {
  1102. title: '',
  1103. data: 'chkbox',
  1104. searchable: false,
  1105. orderable: false,
  1106. defaultContent: '',
  1107. responsivePriority: 1
  1108. },
  1109. {
  1110. title: "ID",
  1111. data: 'id',
  1112. responsivePriority: 2,
  1113. defaultContent: ''
  1114. },
  1115. {
  1116. title: "Template",
  1117. data: 'template',
  1118. responsivePriority: 3,
  1119. defaultContent: ''
  1120. },
  1121. {
  1122. title: lang.domain_quota,
  1123. data: 'attributes.quota',
  1124. defaultContent: '',
  1125. },
  1126. {
  1127. title: lang.tls_enforce_in,
  1128. data: 'attributes.tls_enforce_in',
  1129. defaultContent: ''
  1130. },
  1131. {
  1132. title: lang.tls_enforce_out,
  1133. data: 'attributes.tls_enforce_out',
  1134. defaultContent: ''
  1135. },
  1136. {
  1137. title: 'SMTP',
  1138. data: 'attributes.smtp_access',
  1139. defaultContent: '',
  1140. },
  1141. {
  1142. title: 'IMAP',
  1143. data: 'attributes.imap_access',
  1144. defaultContent: '',
  1145. },
  1146. {
  1147. title: 'POP3',
  1148. data: 'attributes.pop3_access',
  1149. defaultContent: '',
  1150. },
  1151. {
  1152. title: 'SIEVE',
  1153. data: 'attributes.sieve_access',
  1154. defaultContent: '',
  1155. },
  1156. {
  1157. title: 'SOGO',
  1158. data: 'attributes.sogo_access',
  1159. defaultContent: '',
  1160. },
  1161. {
  1162. title: lang.quarantine_notification,
  1163. data: 'attributes.quarantine_notification',
  1164. defaultContent: '',
  1165. className: 'none'
  1166. },
  1167. {
  1168. title: lang.quarantine_category,
  1169. data: 'attributes.quarantine_category',
  1170. defaultContent: '',
  1171. className: 'none'
  1172. },
  1173. {
  1174. title: lang.force_pw_update,
  1175. data: 'attributes.force_pw_update',
  1176. defaultContent: '',
  1177. class: 'none',
  1178. render: function (data, type) {
  1179. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  1180. }
  1181. },
  1182. {
  1183. title: "rl_frame",
  1184. data: 'attributes.rl_frame',
  1185. defaultContent: '',
  1186. class: 'none',
  1187. },
  1188. {
  1189. title: 'rl_value',
  1190. data: 'attributes.rl_value',
  1191. defaultContent: '',
  1192. class: 'none',
  1193. },
  1194. {
  1195. title: 'Tags',
  1196. data: 'attributes.tags',
  1197. defaultContent: '',
  1198. className: 'none'
  1199. },
  1200. {
  1201. title: lang.active,
  1202. data: 'attributes.active',
  1203. defaultContent: '',
  1204. responsivePriority: 4,
  1205. render: function (data, type) {
  1206. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  1207. }
  1208. },
  1209. {
  1210. title: lang.action,
  1211. data: 'action',
  1212. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md',
  1213. responsivePriority: 6,
  1214. defaultContent: ''
  1215. },
  1216. ]
  1217. });
  1218. }
  1219. function draw_resource_table() {
  1220. // just recalc width if instance already exists
  1221. if ($.fn.DataTable.isDataTable('#resource_table') ) {
  1222. $('#resource_table').DataTable().columns.adjust().responsive.recalc();
  1223. return;
  1224. }
  1225. $('#resource_table').DataTable({
  1226. processing: true,
  1227. serverSide: false,
  1228. language: lang_datatables,
  1229. ajax: {
  1230. type: "GET",
  1231. url: "/api/v1/get/resource/all",
  1232. dataSrc: function(json){
  1233. $.each(json, function (i, item) {
  1234. if (item.multiple_bookings == '0') {
  1235. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>';
  1236. } else if (item.multiple_bookings == '-1') {
  1237. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>';
  1238. } else {
  1239. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  1240. }
  1241. item.action = '<div class="btn-group">' +
  1242. '<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>' +
  1243. '<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>' +
  1244. '</div>';
  1245. item.chkbox = '<input type="checkbox" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  1246. item.name = escapeHtml(item.name);
  1247. item.description = escapeHtml(item.description);
  1248. });
  1249. return json;
  1250. }
  1251. },
  1252. columns: [
  1253. {
  1254. // placeholder, so checkbox will not block child row toggle
  1255. title: '',
  1256. data: null,
  1257. searchable: false,
  1258. orderable: false,
  1259. defaultContent: '',
  1260. responsivePriority: 1
  1261. },
  1262. {
  1263. title: '',
  1264. data: 'chkbox',
  1265. searchable: false,
  1266. orderable: false,
  1267. defaultContent: '',
  1268. responsivePriority: 2
  1269. },
  1270. {
  1271. title: lang.description,
  1272. data: 'description',
  1273. responsivePriority: 3,
  1274. defaultContent: ''
  1275. },
  1276. {
  1277. title: lang.alias,
  1278. data: 'name',
  1279. defaultContent: ''
  1280. },
  1281. {
  1282. title: lang.kind,
  1283. data: 'kind',
  1284. defaultContent: ''
  1285. },
  1286. {
  1287. title: lang.domain,
  1288. data: 'domain',
  1289. responsivePriority: 4,
  1290. defaultContent: ''
  1291. },
  1292. {
  1293. title: lang.multiple_bookings,
  1294. data: 'multiple_bookings',
  1295. defaultContent: ''
  1296. },
  1297. {
  1298. title: lang.active,
  1299. data: 'active',
  1300. defaultContent: '',
  1301. render: function (data, type) {
  1302. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  1303. }
  1304. },
  1305. {
  1306. title: lang.action,
  1307. data: 'action',
  1308. responsivePriority: 5,
  1309. defaultContent: '',
  1310. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right'
  1311. },
  1312. ]
  1313. });
  1314. }
  1315. function draw_bcc_table() {
  1316. $.get("/api/v1/get/bcc-destination-options", function(data){
  1317. // Domains
  1318. var optgroup = "<optgroup label='" + lang.domains + "'>";
  1319. $.each(data.domains, function(index, domain){
  1320. optgroup += "<option value='" + domain + "'>" + domain + "</option>"
  1321. });
  1322. optgroup += "</optgroup>"
  1323. $('#bcc-local-dest').append(optgroup);
  1324. // Alias domains
  1325. var optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
  1326. $.each(data.alias_domains, function(index, alias_domain){
  1327. optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>"
  1328. });
  1329. optgroup += "</optgroup>"
  1330. $('#bcc-local-dest').append(optgroup);
  1331. // Mailboxes and aliases
  1332. $.each(data.mailboxes, function(mailbox, aliases){
  1333. var optgroup = "<optgroup label='" + mailbox + "'>";
  1334. $.each(aliases, function(index, alias){
  1335. optgroup += "<option value='" + alias + "'>" + alias + "</option>"
  1336. });
  1337. optgroup += "</optgroup>"
  1338. $('#bcc-local-dest').append(optgroup);
  1339. });
  1340. // Finish
  1341. $('#bcc-local-dest').selectpicker('refresh');
  1342. });
  1343. // just recalc width if instance already exists
  1344. if ($.fn.DataTable.isDataTable('#bcc_table') ) {
  1345. $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
  1346. return;
  1347. }
  1348. $('#bcc_table').DataTable({
  1349. processing: true,
  1350. serverSide: false,
  1351. language: lang_datatables,
  1352. ajax: {
  1353. type: "GET",
  1354. url: "/api/v1/get/bcc/all",
  1355. dataSrc: function(json){
  1356. $.each(json, function (i, item) {
  1357. item.action = '<div class="btn-group">' +
  1358. '<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>' +
  1359. '<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>' +
  1360. '</div>';
  1361. item.chkbox = '<input type="checkbox" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  1362. item.local_dest = escapeHtml(item.local_dest);
  1363. item.bcc_dest = escapeHtml(item.bcc_dest);
  1364. if (item.type == 'sender') {
  1365. item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>';
  1366. } else {
  1367. item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>';
  1368. }
  1369. });
  1370. return json;
  1371. }
  1372. },
  1373. columns: [
  1374. {
  1375. // placeholder, so checkbox will not block child row toggle
  1376. title: '',
  1377. data: null,
  1378. searchable: false,
  1379. orderable: false,
  1380. defaultContent: '',
  1381. responsivePriority: 1
  1382. },
  1383. {
  1384. title: '',
  1385. data: 'chkbox',
  1386. searchable: false,
  1387. orderable: false,
  1388. defaultContent: '',
  1389. responsivePriority: 2
  1390. },
  1391. {
  1392. title: 'ID',
  1393. data: 'id',
  1394. responsivePriority: 3,
  1395. defaultContent: ''
  1396. },
  1397. {
  1398. title: lang.bcc_type,
  1399. data: 'type',
  1400. defaultContent: ''
  1401. },
  1402. {
  1403. title: lang.bcc_local_dest,
  1404. data: 'local_dest',
  1405. defaultContent: ''
  1406. },
  1407. {
  1408. title: lang.bcc_destinations,
  1409. data: 'bcc_dest',
  1410. defaultContent: ''
  1411. },
  1412. {
  1413. title: lang.domain,
  1414. data: 'domain',
  1415. responsivePriority: 4,
  1416. defaultContent: ''
  1417. },
  1418. {
  1419. title: lang.active,
  1420. data: 'active',
  1421. defaultContent: '',
  1422. render: function (data, type) {
  1423. return 1==data?'<i class="bi bi-check-lg"></i>':(0==data?'<i class="bi bi-x-lg"></i>':2==data&&'&#8212;');
  1424. }
  1425. },
  1426. {
  1427. title: lang.action,
  1428. data: 'action',
  1429. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1430. responsivePriority: 5,
  1431. defaultContent: ''
  1432. },
  1433. ]
  1434. });
  1435. }
  1436. function draw_recipient_map_table() {
  1437. // just recalc width if instance already exists
  1438. if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
  1439. $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
  1440. return;
  1441. }
  1442. $('#recipient_map_table').DataTable({
  1443. processing: true,
  1444. serverSide: false,
  1445. language: lang_datatables,
  1446. ajax: {
  1447. type: "GET",
  1448. url: "/api/v1/get/recipient_map/all",
  1449. dataSrc: function(json){
  1450. if (role !== "admin") return null;
  1451. $.each(json, function (i, item) {
  1452. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  1453. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  1454. item.action = '<div class="btn-group">' +
  1455. '<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>' +
  1456. '<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>' +
  1457. '</div>';
  1458. item.chkbox = '<input type="checkbox" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  1459. });
  1460. return json;
  1461. }
  1462. },
  1463. columns: [
  1464. {
  1465. // placeholder, so checkbox will not block child row toggle
  1466. title: '',
  1467. data: null,
  1468. searchable: false,
  1469. orderable: false,
  1470. defaultContent: '',
  1471. responsivePriority: 1
  1472. },
  1473. {
  1474. title: '',
  1475. data: 'chkbox',
  1476. searchable: false,
  1477. orderable: false,
  1478. defaultContent: '',
  1479. responsivePriority: 2
  1480. },
  1481. {
  1482. title: 'ID',
  1483. data: 'id',
  1484. responsivePriority: 3,
  1485. defaultContent: ''
  1486. },
  1487. {
  1488. title: lang.recipient_map_old,
  1489. data: 'recipient_map_old',
  1490. defaultContent: ''
  1491. },
  1492. {
  1493. title: lang.recipient_map_new,
  1494. data: 'recipient_map_new',
  1495. defaultContent: '',
  1496. responsivePriority: 4
  1497. },
  1498. {
  1499. title: lang.active,
  1500. data: 'active',
  1501. defaultContent: '',
  1502. render: function (data, type) {
  1503. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1504. }
  1505. },
  1506. {
  1507. title: lang.action,
  1508. data: 'action',
  1509. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1510. responsivePriority: 5,
  1511. defaultContent: ''
  1512. },
  1513. ]
  1514. });
  1515. }
  1516. function draw_tls_policy_table() {
  1517. // just recalc width if instance already exists
  1518. if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
  1519. $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
  1520. return;
  1521. }
  1522. $('#tls_policy_table').DataTable({
  1523. processing: true,
  1524. serverSide: false,
  1525. language: lang_datatables,
  1526. ajax: {
  1527. type: "GET",
  1528. url: "/api/v1/get/tls-policy-map/all",
  1529. dataSrc: function(json){
  1530. console.log(json);
  1531. if (role !== "admin") return null;
  1532. $.each(json, function (i, item) {
  1533. item.dest = escapeHtml(item.dest);
  1534. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  1535. if (item.parameters == '') {
  1536. item.parameters = '<code>-</code>';
  1537. } else {
  1538. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  1539. }
  1540. item.action = '<div class="btn-group">' +
  1541. '<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>' +
  1542. '<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>' +
  1543. '</div>';
  1544. item.chkbox = '<input type="checkbox" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  1545. });
  1546. return json;
  1547. }
  1548. },
  1549. columns: [
  1550. {
  1551. // placeholder, so checkbox will not block child row toggle
  1552. title: '',
  1553. data: null,
  1554. searchable: false,
  1555. orderable: false,
  1556. defaultContent: '',
  1557. responsivePriority: 1
  1558. },
  1559. {
  1560. title: '',
  1561. data: 'chkbox',
  1562. searchable: false,
  1563. orderable: false,
  1564. defaultContent: '',
  1565. responsivePriority: 2
  1566. },
  1567. {
  1568. title: 'ID',
  1569. data: 'id',
  1570. responsivePriority: 3,
  1571. defaultContent: ''
  1572. },
  1573. {
  1574. title: lang.tls_map_dest,
  1575. data: 'dest',
  1576. defaultContent: '',
  1577. responsivePriority: 4
  1578. },
  1579. {
  1580. title: lang.tls_map_policy,
  1581. data: 'policy',
  1582. defaultContent: ''
  1583. },
  1584. {
  1585. title: lang.tls_map_parameters,
  1586. data: 'parameters',
  1587. defaultContent: ''
  1588. },
  1589. {
  1590. title: lang.active,
  1591. data: 'active',
  1592. defaultContent: '',
  1593. render: function (data, type) {
  1594. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1595. }
  1596. },
  1597. {
  1598. title: lang.action,
  1599. data: 'action',
  1600. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1601. responsivePriority: 5,
  1602. defaultContent: ''
  1603. },
  1604. ]
  1605. });
  1606. }
  1607. function draw_alias_table() {
  1608. // just recalc width if instance already exists
  1609. if ($.fn.DataTable.isDataTable('#alias_table') ) {
  1610. $('#alias_table').DataTable().columns.adjust().responsive.recalc();
  1611. return;
  1612. }
  1613. $('#alias_table').DataTable({
  1614. processing: true,
  1615. serverSide: false,
  1616. language: lang_datatables,
  1617. ajax: {
  1618. type: "GET",
  1619. url: "/api/v1/get/alias/all",
  1620. dataSrc: function(json){
  1621. $.each(json, function (i, item) {
  1622. item.action = '<div class="btn-group">' +
  1623. '<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>' +
  1624. '<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>' +
  1625. '</div>';
  1626. item.chkbox = '<input type="checkbox" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1627. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  1628. if (item.public_comment !== null) {
  1629. item.public_comment = escapeHtml(item.public_comment);
  1630. }
  1631. else {
  1632. item.public_comment = '-';
  1633. }
  1634. if (item.private_comment !== null) {
  1635. item.private_comment = escapeHtml(item.private_comment);
  1636. }
  1637. else {
  1638. item.private_comment = '-';
  1639. }
  1640. if (item.is_catch_all == 1) {
  1641. item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
  1642. }
  1643. else {
  1644. item.address = escapeHtml(item.address);
  1645. }
  1646. if (item.goto == "null@localhost") {
  1647. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  1648. }
  1649. else if (item.goto == "spam@localhost") {
  1650. item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
  1651. }
  1652. else if (item.goto == "ham@localhost") {
  1653. item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
  1654. }
  1655. if (item.in_primary_domain !== "") {
  1656. 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;
  1657. }
  1658. });
  1659. return json;
  1660. }
  1661. },
  1662. columns: [
  1663. {
  1664. // placeholder, so checkbox will not block child row toggle
  1665. title: '',
  1666. data: null,
  1667. searchable: false,
  1668. orderable: false,
  1669. defaultContent: '',
  1670. responsivePriority: 1
  1671. },
  1672. {
  1673. title: '',
  1674. data: 'chkbox',
  1675. searchable: false,
  1676. orderable: false,
  1677. defaultContent: '',
  1678. responsivePriority: 2
  1679. },
  1680. {
  1681. title: 'ID',
  1682. data: 'id',
  1683. responsivePriority: 3,
  1684. defaultContent: ''
  1685. },
  1686. {
  1687. title: lang.alias,
  1688. data: 'address',
  1689. responsivePriority: 4,
  1690. defaultContent: ''
  1691. },
  1692. {
  1693. title: lang.target_address,
  1694. data: 'goto',
  1695. defaultContent: ''
  1696. },
  1697. {
  1698. title: lang.domain,
  1699. data: 'domain',
  1700. defaultContent: '',
  1701. responsivePriority: 5,
  1702. },
  1703. {
  1704. title: lang.bcc_destinations,
  1705. data: 'bcc_dest',
  1706. defaultContent: ''
  1707. },
  1708. {
  1709. title: lang.sogo_visible,
  1710. data: 'sogo_visible',
  1711. defaultContent: '',
  1712. render: function(data, type){
  1713. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1714. }
  1715. },
  1716. {
  1717. title: lang.public_comment,
  1718. data: 'public_comment',
  1719. defaultContent: ''
  1720. },
  1721. {
  1722. title: lang.private_comment,
  1723. data: 'private_comment',
  1724. defaultContent: ''
  1725. },
  1726. {
  1727. title: lang.active,
  1728. data: 'active',
  1729. defaultContent: '',
  1730. responsivePriority: 6,
  1731. render: function (data, type) {
  1732. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1733. }
  1734. },
  1735. {
  1736. title: lang.action,
  1737. data: 'action',
  1738. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1739. responsivePriority: 5,
  1740. defaultContent: ''
  1741. },
  1742. ]
  1743. });
  1744. }
  1745. function draw_aliasdomain_table() {
  1746. // just recalc width if instance already exists
  1747. if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
  1748. $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
  1749. return;
  1750. }
  1751. $('#aliasdomain_table').DataTable({
  1752. processing: true,
  1753. serverSide: false,
  1754. language: lang_datatables,
  1755. ajax: {
  1756. type: "GET",
  1757. url: "/api/v1/get/alias-domain/all",
  1758. dataSrc: function(json){
  1759. $.each(json, function (i, item) {
  1760. item.action = '<div class="btn-group">' +
  1761. '<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>' +
  1762. '<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>' +
  1763. '<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>' +
  1764. '</div>';
  1765. item.chkbox = '<input type="checkbox" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  1766. if(item.parent_is_backupmx == '1') {
  1767. 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>';
  1768. } else {
  1769. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  1770. }
  1771. });
  1772. return json;
  1773. }
  1774. },
  1775. columns: [
  1776. {
  1777. // placeholder, so checkbox will not block child row toggle
  1778. title: '',
  1779. data: null,
  1780. searchable: false,
  1781. orderable: false,
  1782. defaultContent: '',
  1783. responsivePriority: 1
  1784. },
  1785. {
  1786. title: '',
  1787. data: 'chkbox',
  1788. searchable: false,
  1789. orderable: false,
  1790. defaultContent: '',
  1791. responsivePriority: 2
  1792. },
  1793. {
  1794. title: lang.alias,
  1795. data: 'alias_domain',
  1796. responsivePriority: 3,
  1797. defaultContent: ''
  1798. },
  1799. {
  1800. title: lang.target_domain,
  1801. data: 'target_domain',
  1802. responsivePriority: 4,
  1803. defaultContent: ''
  1804. },
  1805. {
  1806. title: lang.active,
  1807. data: 'active',
  1808. defaultContent: '',
  1809. render: function (data, type) {
  1810. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1811. }
  1812. },
  1813. {
  1814. title: lang.action,
  1815. data: 'action',
  1816. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1817. responsivePriority: 5,
  1818. defaultContent: ''
  1819. },
  1820. ]
  1821. });
  1822. }
  1823. function draw_sync_job_table() {
  1824. // just recalc width if instance already exists
  1825. if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
  1826. $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
  1827. return;
  1828. }
  1829. $('#sync_job_table').DataTable({
  1830. processing: true,
  1831. serverSide: false,
  1832. language: lang_datatables,
  1833. ajax: {
  1834. type: "GET",
  1835. url: "/api/v1/get/syncjobs/all/no_log",
  1836. dataSrc: function(json){
  1837. $.each(json, function (i, item) {
  1838. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
  1839. item.user2 = escapeHtml(item.user2);
  1840. if (!item.exclude > 0) {
  1841. item.exclude = '-';
  1842. } else {
  1843. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  1844. }
  1845. item.server_w_port = escapeHtml(item.user1) + '@' + item.host1 + ':' + item.port1;
  1846. item.action = '<div class="btn-group">' +
  1847. '<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>' +
  1848. '<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>' +
  1849. '</div>';
  1850. item.chkbox = '<input type="checkbox" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  1851. if (item.is_running == 1) {
  1852. item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
  1853. } else {
  1854. item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
  1855. }
  1856. if (!item.last_run > 0) {
  1857. item.last_run = lang.waiting;
  1858. }
  1859. if (item.success == null) {
  1860. item.success = '-';
  1861. item.exit_status = '';
  1862. } else {
  1863. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  1864. }
  1865. if (lang['syncjob_'+item.exit_status]) {
  1866. item.exit_status = lang['syncjob_'+item.exit_status];
  1867. } else if (item.success != '-') {
  1868. item.exit_status = lang.syncjob_check_log;
  1869. }
  1870. item.exit_status = item.success + ' ' + item.exit_status;
  1871. });
  1872. return json;
  1873. }
  1874. },
  1875. columns: [
  1876. {
  1877. // placeholder, so checkbox will not block child row toggle
  1878. title: '',
  1879. data: null,
  1880. searchable: false,
  1881. orderable: false,
  1882. defaultContent: '',
  1883. responsivePriority: 1
  1884. },
  1885. {
  1886. title: '',
  1887. data: 'chkbox',
  1888. searchable: false,
  1889. orderable: false,
  1890. defaultContent: '',
  1891. responsivePriority: 2
  1892. },
  1893. {
  1894. title: 'ID',
  1895. data: 'id',
  1896. responsivePriority: 3,
  1897. defaultContent: ''
  1898. },
  1899. {
  1900. title: lang.owner,
  1901. data: 'user2',
  1902. responsivePriority: 4,
  1903. defaultContent: ''
  1904. },
  1905. {
  1906. title: 'Server',
  1907. data: 'server_w_port',
  1908. defaultContent: ''
  1909. },
  1910. {
  1911. title: lang.last_run,
  1912. data: 'last_run',
  1913. defaultContent: ''
  1914. },
  1915. {
  1916. title: lang.syncjob_last_run_result,
  1917. data: 'exit_status',
  1918. defaultContent: ''
  1919. },
  1920. {
  1921. title: 'Log',
  1922. data: 'log',
  1923. defaultContent: ''
  1924. },
  1925. {
  1926. title: lang.active,
  1927. data: 'active',
  1928. defaultContent: '',
  1929. render: function (data, type) {
  1930. return 1==data?'<i class="bi bi-check-lg"></i>':0==data&&'<i class="bi bi-x-lg"></i>';
  1931. }
  1932. },
  1933. {
  1934. title: lang.status,
  1935. data: 'is_running',
  1936. defaultContent: ''
  1937. },
  1938. {
  1939. title: lang.excludes,
  1940. data: 'exclude',
  1941. defaultContent: '',
  1942. className: 'none'
  1943. },
  1944. {
  1945. title: lang.mins_interval,
  1946. data: 'mins_interval',
  1947. defaultContent: '',
  1948. className: 'none'
  1949. },
  1950. {
  1951. title: lang.action,
  1952. data: 'action',
  1953. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  1954. responsivePriority: 5,
  1955. defaultContent: ''
  1956. },
  1957. ]
  1958. });
  1959. }
  1960. function draw_filter_table() {
  1961. // just recalc width if instance already exists
  1962. if ($.fn.DataTable.isDataTable('#filter_table') ) {
  1963. $('#filter_table').DataTable().columns.adjust().responsive.recalc();
  1964. return;
  1965. }
  1966. var table = $('#filter_table').DataTable({
  1967. autoWidth: false,
  1968. processing: true,
  1969. serverSide: false,
  1970. language: lang_datatables,
  1971. ajax: {
  1972. type: "GET",
  1973. url: "/api/v1/get/filters/all",
  1974. dataSrc: function(json){
  1975. $.each(json, function (i, item) {
  1976. if (item.active == 1) {
  1977. item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
  1978. } else {
  1979. item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
  1980. }
  1981. item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  1982. item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  1983. item.action = '<div class="btn-group">' +
  1984. '<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>' +
  1985. '<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>' +
  1986. '</div>';
  1987. item.chkbox = '<input type="checkbox" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  1988. });
  1989. return json;
  1990. }
  1991. },
  1992. columns: [
  1993. {
  1994. // placeholder, so checkbox will not block child row toggle
  1995. title: '',
  1996. data: null,
  1997. searchable: false,
  1998. orderable: false,
  1999. defaultContent: '',
  2000. responsivePriority: 1
  2001. },
  2002. {
  2003. title: '',
  2004. data: 'chkbox',
  2005. searchable: false,
  2006. orderable: false,
  2007. defaultContent: '',
  2008. responsivePriority: 2
  2009. },
  2010. {
  2011. title: 'ID',
  2012. data: 'id',
  2013. responsivePriority: 2,
  2014. defaultContent: ''
  2015. },
  2016. {
  2017. title: lang.active,
  2018. data: 'active',
  2019. responsivePriority: 3,
  2020. defaultContent: ''
  2021. },
  2022. {
  2023. title: 'Type',
  2024. data: 'filter_type',
  2025. responsivePriority: 4,
  2026. defaultContent: ''
  2027. },
  2028. {
  2029. title: lang.owner,
  2030. data: 'username',
  2031. defaultContent: ''
  2032. },
  2033. {
  2034. title: lang.description,
  2035. data: 'script_desc',
  2036. defaultContent: ''
  2037. },
  2038. {
  2039. title: 'Script',
  2040. data: 'script_data',
  2041. defaultContent: '',
  2042. className: 'none'
  2043. },
  2044. {
  2045. title: lang.action,
  2046. data: 'action',
  2047. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-body-right',
  2048. responsivePriority: 5,
  2049. defaultContent: ''
  2050. },
  2051. ]
  2052. });
  2053. };
  2054. // detect element visibility changes
  2055. function onVisible(element, callback) {
  2056. $(document).ready(function() {
  2057. element_object = document.querySelector(element);
  2058. if (element_object === null) return;
  2059. new IntersectionObserver((entries, observer) => {
  2060. entries.forEach(entry => {
  2061. if(entry.intersectionRatio > 0) {
  2062. callback(element_object);
  2063. }
  2064. });
  2065. }).observe(element_object);
  2066. });
  2067. }
  2068. // Load only if the tab is visible
  2069. onVisible("[id^=domain_table]", () => draw_domain_table());
  2070. onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table());
  2071. onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
  2072. onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table());
  2073. onVisible("[id^=resource_table]", () => draw_resource_table());
  2074. onVisible("[id^=alias_table]", () => draw_alias_table());
  2075. onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
  2076. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  2077. onVisible("[id^=filter_table]", () => draw_filter_table());
  2078. onVisible("[id^=bcc_table]", () => draw_bcc_table());
  2079. onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
  2080. onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
  2081. });