mailbox.js 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428
  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. responsive: true,
  415. processing: true,
  416. serverSide: true,
  417. stateSave: true,
  418. pageLength: pagination_size,
  419. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  420. "tr" +
  421. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  422. language: lang_datatables,
  423. initComplete: function(){
  424. hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
  425. },
  426. ajax: {
  427. type: "GET",
  428. url: "/api/v1/get/domain/datatables",
  429. dataSrc: function(json){
  430. $.each(json.data, function(i, item) {
  431. item.domain_name = escapeHtml(item.domain_name);
  432. item.aliases = item.aliases_in_domain + " / " + item.max_num_aliases_for_domain;
  433. item.mailboxes = item.mboxes_in_domain + " / " + item.max_num_mboxes_for_domain;
  434. item.quota = item.quota_used_in_domain + "/" + item.max_quota_for_domain + "/" + item.bytes_total;
  435. item.stats = item.msgs_total + "/" + item.bytes_total;
  436. if (!item.rl) item.rl = '∞';
  437. else {
  438. item.rl = $.map(item.rl, function(e){
  439. return e;
  440. }).join('/1');
  441. }
  442. item.def_quota_for_mbox = humanFileSize(item.def_quota_for_mbox);
  443. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  444. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain" name="multi_select" value="' + encodeURIComponent(item.domain_name) + '" />';
  445. item.action = '<div class="btn-group">';
  446. if (role == "admin") {
  447. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  448. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  449. '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
  450. }
  451. else {
  452. item.action += '<a href="/edit/domain/' + encodeURIComponent(item.domain_name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  453. '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-half btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.domain_name) + '"><i class="bi bi-globe2"></i> DNS</a></div>';
  454. }
  455. if (Array.isArray(item.tags)){
  456. var tags = '';
  457. for (var i = 0; i < item.tags.length; i++)
  458. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  459. item.tags = tags;
  460. } else {
  461. item.tags = '';
  462. }
  463. if (item.backupmx == 1) {
  464. if (item.relay_unknown_only == 1) {
  465. item.domain_name = '<div class="badge fs-6 bg-info">Relay Non-Local</div> ' + item.domain_name;
  466. } else if (item.relay_all_recipients == 1) {
  467. item.domain_name = '<div class="badge fs-6 bg-info">Relay All</div> ' + item.domain_name;
  468. } else {
  469. item.domain_name = '<div class="badge fs-6 bg-info">Relay</div> ' + item.domain_name;
  470. }
  471. }
  472. });
  473. return json.data;
  474. }
  475. },
  476. columns: [
  477. {
  478. // placeholder, so checkbox will not block child row toggle
  479. title: '',
  480. data: null,
  481. searchable: false,
  482. orderable: false,
  483. defaultContent: '',
  484. responsivePriority: 1
  485. },
  486. {
  487. title: '',
  488. data: 'chkbox',
  489. searchable: false,
  490. orderable: false,
  491. defaultContent: '',
  492. responsivePriority: 2
  493. },
  494. {
  495. title: lang.domain,
  496. data: 'domain_name',
  497. responsivePriority: 3,
  498. defaultContent: ''
  499. },
  500. {
  501. title: lang.aliases,
  502. data: 'aliases',
  503. searchable: false,
  504. defaultContent: ''
  505. },
  506. {
  507. title: lang.mailboxes,
  508. data: 'mailboxes',
  509. searchable: false,
  510. responsivePriority: 4,
  511. defaultContent: ''
  512. },
  513. {
  514. title: lang.domain_quota,
  515. data: 'quota',
  516. searchable: false,
  517. defaultContent: '',
  518. render: function (data, type) {
  519. data = data.split("/");
  520. return humanFileSize(data[0]) + " / " + humanFileSize(data[1]);
  521. }
  522. },
  523. {
  524. title: lang.stats,
  525. data: 'stats',
  526. searchable: false,
  527. orderable: false,
  528. defaultContent: '',
  529. render: function (data, type) {
  530. data = data.split("/");
  531. return '<i class="bi bi-files"></i> ' + data[0] + ' / ' + humanFileSize(data[1]);
  532. }
  533. },
  534. {
  535. title: lang.mailbox_defquota,
  536. data: 'def_quota_for_mbox',
  537. searchable: false,
  538. orderable: false,
  539. defaultContent: ''
  540. },
  541. {
  542. title: lang.mailbox_quota,
  543. data: 'max_quota_for_mbox',
  544. searchable: false,
  545. orderable: false,
  546. defaultContent: ''
  547. },
  548. {
  549. title: 'RL',
  550. data: 'rl',
  551. searchable: false,
  552. orderable: false,
  553. defaultContent: ''
  554. },
  555. {
  556. title: lang.backup_mx,
  557. data: 'backupmx',
  558. searchable: false,
  559. orderable: false,
  560. defaultContent: '',
  561. redner: function (data, type){
  562. return 1==value ? '<i class="bi bi-check-lg"></i>' : 0==value && '<i class="bi bi-x-lg"></i>';
  563. }
  564. },
  565. {
  566. title: lang.domain_admins,
  567. data: 'domain_admins',
  568. searchable: false,
  569. orderable: false,
  570. defaultContent: '',
  571. className: 'none'
  572. },
  573. {
  574. title: lang.created_on,
  575. data: 'created',
  576. searchable: false,
  577. orderable: false,
  578. defaultContent: '',
  579. className: 'none'
  580. },
  581. {
  582. title: lang.last_modified,
  583. data: 'modified',
  584. searchable: false,
  585. orderable: false,
  586. defaultContent: '',
  587. className: 'none'
  588. },
  589. {
  590. title: 'Tags',
  591. data: 'tags',
  592. searchable: false,
  593. orderable: false,
  594. defaultContent: '',
  595. className: 'none'
  596. },
  597. {
  598. title: lang.active,
  599. data: 'active',
  600. searchable: false,
  601. orderable: false,
  602. defaultContent: '',
  603. responsivePriority: 6,
  604. render: function (data, type) {
  605. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  606. }
  607. },
  608. {
  609. title: lang.action,
  610. data: 'action',
  611. searchable: false,
  612. orderable: false,
  613. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  614. responsivePriority: 5,
  615. defaultContent: ''
  616. },
  617. ]
  618. });
  619. table.on('responsive-resize', function (e, datatable, columns){
  620. hideTableExpandCollapseBtn('#tab-domains', '#domain_table');
  621. });
  622. }
  623. function draw_templates_domain_table() {
  624. // just recalc width if instance already exists
  625. if ($.fn.DataTable.isDataTable('#templates_domain_table') ) {
  626. $('#templates_domain_table').DataTable().columns.adjust().responsive.recalc();
  627. return;
  628. }
  629. var table = $('#templates_domain_table').DataTable({
  630. responsive: true,
  631. processing: true,
  632. serverSide: false,
  633. stateSave: true,
  634. pageLength: pagination_size,
  635. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  636. "tr" +
  637. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  638. language: lang_datatables,
  639. order: [[2, 'desc']],
  640. initComplete: function(){
  641. hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
  642. },
  643. ajax: {
  644. type: "GET",
  645. url: "/api/v1/get/domain/template/all",
  646. dataSrc: function(json){
  647. $.each(json, function (i, item) {
  648. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="domain_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  649. item.attributes.def_quota_for_mbox = humanFileSize(item.attributes.def_quota_for_mbox);
  650. item.attributes.max_quota_for_mbox = humanFileSize(item.attributes.max_quota_for_mbox);
  651. item.attributes.max_quota_for_domain = humanFileSize(item.attributes.max_quota_for_domain);
  652. item.template = escapeHtml(item.template);
  653. if (item.attributes.rl_frame === "s"){
  654. item.attributes.rl_frame = lang_rl.second;
  655. } else if (item.attributes.rl_frame === "m"){
  656. item.attributes.rl_frame = lang_rl.minute;
  657. } else if (item.attributes.rl_frame === "h"){
  658. item.attributes.rl_frame = lang_rl.hour;
  659. } else if (item.attributes.rl_frame === "d"){
  660. item.attributes.rl_frame = lang_rl.day;
  661. }
  662. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  663. if (item.template.toLowerCase() == "default"){
  664. item.action = '<div class="btn-group">' +
  665. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  666. '</div>';
  667. }
  668. else {
  669. item.action = '<div class="btn-group">' +
  670. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  671. '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/domain/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  672. '</div>';
  673. }
  674. if (Array.isArray(item.attributes.tags)){
  675. var tags = '';
  676. for (var i = 0; i < item.attributes.tags.length; i++)
  677. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  678. item.attributes.tags = tags;
  679. } else {
  680. item.attributes.tags = '';
  681. }
  682. });
  683. return json;
  684. }
  685. },
  686. columns: [
  687. {
  688. // placeholder, so checkbox will not block child row toggle
  689. title: '',
  690. data: null,
  691. searchable: false,
  692. orderable: false,
  693. defaultContent: '',
  694. responsivePriority: 1
  695. },
  696. {
  697. title: '',
  698. data: 'chkbox',
  699. searchable: false,
  700. orderable: false,
  701. defaultContent: '',
  702. responsivePriority: 1
  703. },
  704. {
  705. title: "ID",
  706. data: 'id',
  707. responsivePriority: 2,
  708. defaultContent: ''
  709. },
  710. {
  711. title: lang.template,
  712. data: 'template',
  713. responsivePriority: 3,
  714. defaultContent: ''
  715. },
  716. {
  717. title: lang.max_aliases,
  718. data: 'attributes.max_num_aliases_for_domain',
  719. defaultContent: '',
  720. },
  721. {
  722. title: lang.max_mailboxes,
  723. data: 'attributes.max_num_mboxes_for_domain',
  724. defaultContent: '',
  725. },
  726. {
  727. title: lang.mailbox_defquota,
  728. data: 'attributes.def_quota_for_mbox',
  729. defaultContent: '',
  730. },
  731. {
  732. title: lang.max_quota,
  733. data: 'attributes.max_quota_for_mbox',
  734. defaultContent: '',
  735. },
  736. {
  737. title: lang.domain_quota_total,
  738. data: 'attributes.max_quota_for_domain',
  739. defaultContent: '',
  740. },
  741. {
  742. title: lang.gal,
  743. data: 'attributes.gal',
  744. defaultContent: '',
  745. render: function (data, type) {
  746. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  747. }
  748. },
  749. {
  750. title: lang.backup_mx,
  751. data: 'attributes.backupmx',
  752. defaultContent: '',
  753. render: function (data, type) {
  754. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  755. }
  756. },
  757. {
  758. title: lang.relay_all,
  759. data: 'attributes.relay_all_recipients',
  760. defaultContent: '',
  761. render: function (data, type) {
  762. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  763. }
  764. },
  765. {
  766. title: lang.relay_unknown,
  767. data: 'attributes.relay_unknown_only',
  768. defaultContent: '',
  769. render: function (data, type) {
  770. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  771. }
  772. },
  773. {
  774. title: lang.active,
  775. data: 'attributes.active',
  776. defaultContent: '',
  777. responsivePriority: 4,
  778. render: function (data, type) {
  779. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  780. }
  781. },
  782. {
  783. title: 'rl_frame',
  784. data: 'attributes.rl_frame',
  785. defaultContent: '',
  786. class: 'none',
  787. },
  788. {
  789. title: 'rl_value',
  790. data: 'attributes.rl_value',
  791. defaultContent: '',
  792. class: 'none',
  793. },
  794. {
  795. title: lang.dkim_domains_selector,
  796. data: 'attributes.dkim_selector',
  797. defaultContent: '',
  798. class: 'none',
  799. },
  800. {
  801. title: lang.dkim_key_length,
  802. data: 'attributes.key_size',
  803. defaultContent: '',
  804. class: 'none',
  805. },
  806. {
  807. title: 'Tags',
  808. data: 'attributes.tags',
  809. defaultContent: '',
  810. className: 'none'
  811. },
  812. {
  813. title: lang.action,
  814. data: 'action',
  815. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  816. responsivePriority: 6,
  817. defaultContent: ''
  818. },
  819. ]
  820. });
  821. table.on('responsive-resize', function (e, datatable, columns){
  822. hideTableExpandCollapseBtn('#tab-templates-domains', '#templates_domain_table');
  823. });
  824. }
  825. function draw_mailbox_table() {
  826. // just recalc width if instance already exists
  827. if ($.fn.DataTable.isDataTable('#mailbox_table') ) {
  828. $('#mailbox_table').DataTable().columns.adjust().responsive.recalc();
  829. return;
  830. }
  831. var table = $('#mailbox_table').DataTable({
  832. responsive: true,
  833. processing: true,
  834. serverSide: false,
  835. stateSave: true,
  836. pageLength: pagination_size,
  837. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  838. "tr" +
  839. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  840. language: lang_datatables,
  841. initComplete: function(settings, json){
  842. hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
  843. filterByDomain(json, 8, table);
  844. },
  845. ajax: {
  846. type: "GET",
  847. url: "/api/v1/get/mailbox/reduced",
  848. dataSrc: function(json){
  849. $.each(json, function (i, item) {
  850. item.quota = {
  851. sortBy: item.quota_used,
  852. value: item.quota
  853. }
  854. item.quota.value = (item.quota.value == 0 ? "∞" : humanFileSize(item.quota.value));
  855. item.quota.value = humanFileSize(item.quota_used) + "/" + item.quota.value;
  856. item.max_quota_for_mbox = humanFileSize(item.max_quota_for_mbox);
  857. item.last_mail_login = item.last_imap_login + '/' + item.last_pop3_login + '/' + item.last_smtp_login;
  858. /*
  859. if (!item.rl) {
  860. item.rl = '∞';
  861. } else {
  862. item.rl = $.map(item.rl, function(e){
  863. return e;
  864. }).join('/1');
  865. if (item.rl_scope === 'domain') {
  866. item.rl = '<i class="bi bi-arrow-return-right"></i> ' + item.rl + ' (via ' + item.domain + ')';
  867. }
  868. }
  869. */
  870. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox" name="multi_select" value="' + encodeURIComponent(item.username) + '" />';
  871. if (item.attributes.passwd_update != '0') {
  872. var last_pw_change = new Date(item.attributes.passwd_update.replace(/-/g, "/"));
  873. 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"});
  874. } else {
  875. item.last_pw_change = '-';
  876. }
  877. item.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  878. item.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"></i>';
  879. 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>';
  880. 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>';
  881. 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>';
  882. 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>';
  883. if (item.attributes.quarantine_notification === 'never') {
  884. item.quarantine_notification = lang.never;
  885. } else if (item.attributes.quarantine_notification === 'hourly') {
  886. item.quarantine_notification = lang.hourly;
  887. } else if (item.attributes.quarantine_notification === 'daily') {
  888. item.quarantine_notification = lang.daily;
  889. } else if (item.attributes.quarantine_notification === 'weekly') {
  890. item.quarantine_notification = lang.weekly;
  891. }
  892. if (item.attributes.quarantine_category === 'reject') {
  893. item.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  894. } else if (item.attributes.quarantine_category === 'add_header') {
  895. item.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  896. } else if (item.attributes.quarantine_category === 'all') {
  897. item.quarantine_category = lang.q_all;
  898. }
  899. if (acl_data.login_as === 1) {
  900. item.action = '<div class="btn-group">' +
  901. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  902. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  903. '<a href="/index.php?duallogin=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-success"><i class="bi bi-person-fill"></i> Login</a>';
  904. if (ALLOW_ADMIN_EMAIL_LOGIN) {
  905. item.action += '<a href="/sogo-auth.php?login=' + encodeURIComponent(item.username) + '" class="login_as btn btn-sm btn-xs-lg btn-xs-half btn-primary" target="_blank"><i class="bi bi-envelope-fill"></i> SOGo</a>';
  906. }
  907. item.action += '</div>';
  908. }
  909. else {
  910. item.action = '<div class="btn-group">' +
  911. '<a href="/edit/mailbox/' + encodeURIComponent(item.username) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  912. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  913. '</div>';
  914. }
  915. item.in_use = {
  916. sortBy: item.percent_in_use,
  917. value: '<div class="progress">' +
  918. '<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" ' +
  919. 'style="min-width:2em;width:' + item.percent_in_use + '%">' + item.percent_in_use + '%' + '</div></div>'
  920. };
  921. item.username = escapeHtml(item.username);
  922. if (Array.isArray(item.tags)){
  923. var tags = '';
  924. for (var i = 0; i < item.tags.length; i++)
  925. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.tags[i]) + '</span>';
  926. item.tags = tags;
  927. } else {
  928. item.tags = '';
  929. }
  930. });
  931. return json;
  932. }
  933. },
  934. columns: [
  935. {
  936. // placeholder, so checkbox will not block child row toggle
  937. title: '',
  938. data: null,
  939. searchable: false,
  940. orderable: false,
  941. defaultContent: '',
  942. responsivePriority: 1
  943. },
  944. {
  945. title: '',
  946. data: 'chkbox',
  947. searchable: false,
  948. orderable: false,
  949. defaultContent: '',
  950. responsivePriority: 2
  951. },
  952. {
  953. title: lang.username,
  954. data: 'username',
  955. responsivePriority: 3,
  956. defaultContent: ''
  957. },
  958. {
  959. title: lang.domain_quota,
  960. data: 'quota.value',
  961. responsivePriority: 8,
  962. defaultContent: '',
  963. orderData: 23
  964. },
  965. {
  966. title: lang.last_mail_login,
  967. data: 'last_mail_login',
  968. defaultContent: '',
  969. responsivePriority: 7,
  970. render: function (data, type) {
  971. res = data.split("/");
  972. return '<div class="badge bg-info mb-2">IMAP @ ' + unix_time_format(Number(res[0])) + '</div><br>' +
  973. '<div class="badge bg-info mb-2">POP3 @ ' + unix_time_format(Number(res[1])) + '</div><br>' +
  974. '<div class="badge bg-info">SMTP @ ' + unix_time_format(Number(res[2])) + '</div>';
  975. }
  976. },
  977. {
  978. title: lang.last_pw_change,
  979. data: 'last_pw_change',
  980. defaultContent: ''
  981. },
  982. {
  983. title: lang.in_use,
  984. data: 'in_use.value',
  985. defaultContent: '',
  986. responsivePriority: 9,
  987. className: 'dt-data-w100',
  988. orderData: 24
  989. },
  990. {
  991. title: lang.fname,
  992. data: 'name',
  993. defaultContent: '',
  994. className: 'none'
  995. },
  996. {
  997. title: lang.domain,
  998. data: 'domain',
  999. defaultContent: '',
  1000. className: 'none'
  1001. },
  1002. {
  1003. title: lang.tls_enforce_in,
  1004. data: 'tls_enforce_in',
  1005. defaultContent: '',
  1006. className: 'none'
  1007. },
  1008. {
  1009. title: lang.tls_enforce_out,
  1010. data: 'tls_enforce_out',
  1011. defaultContent: '',
  1012. className: 'none'
  1013. },
  1014. {
  1015. title: 'SMTP',
  1016. data: 'smtp_access',
  1017. defaultContent: '',
  1018. className: 'none'
  1019. },
  1020. {
  1021. title: 'IMAP',
  1022. data: 'imap_access',
  1023. defaultContent: '',
  1024. className: 'none'
  1025. },
  1026. {
  1027. title: 'POP3',
  1028. data: 'pop3_access',
  1029. defaultContent: '',
  1030. className: 'none'
  1031. },
  1032. {
  1033. title: 'SIEVE',
  1034. data: 'sieve_access',
  1035. defaultContent: '',
  1036. className: 'none'
  1037. },
  1038. {
  1039. title: lang.quarantine_notification,
  1040. data: 'quarantine_notification',
  1041. defaultContent: '',
  1042. className: 'none'
  1043. },
  1044. {
  1045. title: lang.quarantine_category,
  1046. data: 'quarantine_category',
  1047. defaultContent: '',
  1048. className: 'none'
  1049. },
  1050. {
  1051. title: lang.msg_num,
  1052. data: 'messages',
  1053. defaultContent: '',
  1054. responsivePriority: 5
  1055. },
  1056. {
  1057. title: lang.created_on,
  1058. data: 'created',
  1059. defaultContent: '',
  1060. className: 'none'
  1061. },
  1062. {
  1063. title: lang.last_modified,
  1064. data: 'modified',
  1065. defaultContent: '',
  1066. className: 'none'
  1067. },
  1068. {
  1069. title: 'Tags',
  1070. data: 'tags',
  1071. defaultContent: '',
  1072. className: 'none'
  1073. },
  1074. {
  1075. title: lang.active,
  1076. data: 'active',
  1077. defaultContent: '',
  1078. responsivePriority: 4,
  1079. render: function (data, type) {
  1080. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1081. }
  1082. },
  1083. {
  1084. title: lang.action,
  1085. data: 'action',
  1086. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1087. responsivePriority: 6,
  1088. defaultContent: ''
  1089. },
  1090. {
  1091. title: "",
  1092. data: 'quota.sortBy',
  1093. defaultContent: '',
  1094. className: "d-none"
  1095. },
  1096. {
  1097. title: "",
  1098. data: 'in_use.sortBy',
  1099. defaultContent: '',
  1100. className: "d-none"
  1101. },
  1102. ]
  1103. });
  1104. table.on('responsive-resize', function (e, datatable, columns){
  1105. hideTableExpandCollapseBtn('#tab-mailboxes', '#mailbox_table');
  1106. });
  1107. }
  1108. function draw_templates_mbox_table() {
  1109. // just recalc width if instance already exists
  1110. if ($.fn.DataTable.isDataTable('#templates_mbox_table') ) {
  1111. $('#templates_mbox_table').DataTable().columns.adjust().responsive.recalc();
  1112. return;
  1113. }
  1114. var table = $('#templates_mbox_table').DataTable({
  1115. responsive: true,
  1116. processing: true,
  1117. serverSide: false,
  1118. stateSave: true,
  1119. pageLength: pagination_size,
  1120. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1121. "tr" +
  1122. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1123. language: lang_datatables,
  1124. order: [[2, 'desc']],
  1125. initComplete: function(){
  1126. hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
  1127. },
  1128. ajax: {
  1129. type: "GET",
  1130. url: "/api/v1/get/mailbox/template/all",
  1131. dataSrc: function(json){
  1132. $.each(json, function (i, item) {
  1133. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="mailbox_template" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1134. item.template = escapeHtml(item.template);
  1135. if (item.attributes.rl_frame === "s"){
  1136. item.attributes.rl_frame = lang_rl.second;
  1137. } else if (item.attributes.rl_frame === "m"){
  1138. item.attributes.rl_frame = lang_rl.minute;
  1139. } else if (item.attributes.rl_frame === "h"){
  1140. item.attributes.rl_frame = lang_rl.hour;
  1141. } else if (item.attributes.rl_frame === "d"){
  1142. item.attributes.rl_frame = lang_rl.day;
  1143. }
  1144. item.attributes.rl_value = escapeHtml(item.attributes.rl_value);
  1145. item.attributes.quota = humanFileSize(item.attributes.quota);
  1146. item.attributes.tls_enforce_in = '<i class="text-' + (item.attributes.tls_enforce_in == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_in == 1 ? '1' : '0') + '</span></i>';
  1147. item.attributes.tls_enforce_out = '<i class="text-' + (item.attributes.tls_enforce_out == 1 ? 'success bi bi-lock-fill' : 'danger bi bi-unlock-fill') + '"><span class="sorting-value">' + (item.attributes.tls_enforce_out == 1 ? '1' : '0') + '</span></i>';
  1148. 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') + '"><span class="sorting-value">' + (item.attributes.pop3_access == 1 ? '1' : '0') + '</span></i>';
  1149. 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') + '"><span class="sorting-value">' + (item.attributes.imap_access == 1 ? '1' : '0') + '</span></i>';
  1150. 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') + '"><span class="sorting-value">' + (item.attributes.smtp_access == 1 ? '1' : '0') + '</span></i>';
  1151. 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') + '"><span class="sorting-value">' + (item.attributes.sieve_access == 1 ? '1' : '0') + '</span></i>';
  1152. 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') + '"><span class="sorting-value">' + (item.attributes.sogo_access == 1 ? '1' : '0') + '</span></i>';
  1153. if (item.attributes.quarantine_notification === 'never') {
  1154. item.attributes.quarantine_notification = lang.never;
  1155. } else if (item.attributes.quarantine_notification === 'hourly') {
  1156. item.attributes.quarantine_notification = lang.hourly;
  1157. } else if (item.attributes.quarantine_notification === 'daily') {
  1158. item.attributes.quarantine_notification = lang.daily;
  1159. } else if (item.attributes.quarantine_notification === 'weekly') {
  1160. item.attributes.quarantine_notification = lang.weekly;
  1161. }
  1162. if (item.attributes.quarantine_category === 'reject') {
  1163. item.attributes.quarantine_category = '<span class="text-danger">' + lang.q_reject + '</span>';
  1164. } else if (item.attributes.quarantine_category === 'add_header') {
  1165. item.attributes.quarantine_category = '<span class="text-warning">' + lang.q_add_header + '</span>';
  1166. } else if (item.attributes.quarantine_category === 'all') {
  1167. item.attributes.quarantine_category = lang.q_all;
  1168. }
  1169. if (item.template.toLowerCase() == "default"){
  1170. item.action = '<div class="btn-group">' +
  1171. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1172. '</div>';
  1173. }
  1174. else {
  1175. item.action = '<div class="btn-group">' +
  1176. '<a href="/edit/template/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1177. '<a href="#" data-action="delete_selected" data-id="single-template" data-api-url="delete/mailbox/template" data-item="' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1178. '</div>';
  1179. }
  1180. if (Array.isArray(item.attributes.tags)){
  1181. var tags = '';
  1182. for (var i = 0; i < item.attributes.tags.length; i++)
  1183. tags += '<span class="badge bg-primary tag-badge"><i class="bi bi-tag-fill"></i> ' + escapeHtml(item.attributes.tags[i]) + '</span>';
  1184. item.attributes.tags = tags;
  1185. } else {
  1186. item.attributes.tags = '';
  1187. }
  1188. });
  1189. return json;
  1190. }
  1191. },
  1192. columns: [
  1193. {
  1194. // placeholder, so checkbox will not block child row toggle
  1195. title: '',
  1196. data: null,
  1197. searchable: false,
  1198. orderable: false,
  1199. defaultContent: '',
  1200. responsivePriority: 1
  1201. },
  1202. {
  1203. title: '',
  1204. data: 'chkbox',
  1205. searchable: false,
  1206. orderable: false,
  1207. defaultContent: '',
  1208. responsivePriority: 1
  1209. },
  1210. {
  1211. title: "ID",
  1212. data: 'id',
  1213. responsivePriority: 2,
  1214. defaultContent: ''
  1215. },
  1216. {
  1217. title: lang.template,
  1218. data: 'template',
  1219. responsivePriority: 3,
  1220. defaultContent: ''
  1221. },
  1222. {
  1223. title: lang.domain_quota,
  1224. data: 'attributes.quota',
  1225. defaultContent: '',
  1226. },
  1227. {
  1228. title: lang.tls_enforce_in,
  1229. data: 'attributes.tls_enforce_in',
  1230. defaultContent: ''
  1231. },
  1232. {
  1233. title: lang.tls_enforce_out,
  1234. data: 'attributes.tls_enforce_out',
  1235. defaultContent: ''
  1236. },
  1237. {
  1238. title: 'SMTP',
  1239. data: 'attributes.smtp_access',
  1240. defaultContent: '',
  1241. },
  1242. {
  1243. title: 'IMAP',
  1244. data: 'attributes.imap_access',
  1245. defaultContent: '',
  1246. },
  1247. {
  1248. title: 'POP3',
  1249. data: 'attributes.pop3_access',
  1250. defaultContent: '',
  1251. },
  1252. {
  1253. title: 'SIEVE',
  1254. data: 'attributes.sieve_access',
  1255. defaultContent: '',
  1256. },
  1257. {
  1258. title: 'SOGO',
  1259. data: 'attributes.sogo_access',
  1260. defaultContent: '',
  1261. },
  1262. {
  1263. title: lang.quarantine_notification,
  1264. data: 'attributes.quarantine_notification',
  1265. defaultContent: '',
  1266. className: 'none'
  1267. },
  1268. {
  1269. title: lang.quarantine_category,
  1270. data: 'attributes.quarantine_category',
  1271. defaultContent: '',
  1272. className: 'none'
  1273. },
  1274. {
  1275. title: lang.force_pw_update,
  1276. data: 'attributes.force_pw_update',
  1277. defaultContent: '',
  1278. class: 'none',
  1279. render: function (data, type) {
  1280. return 1==data?'<i class="bi bi-check-lg"></i>':'<i class="bi bi-x-lg"></i>';
  1281. }
  1282. },
  1283. {
  1284. title: "rl_frame",
  1285. data: 'attributes.rl_frame',
  1286. defaultContent: '',
  1287. class: 'none',
  1288. },
  1289. {
  1290. title: 'rl_value',
  1291. data: 'attributes.rl_value',
  1292. defaultContent: '',
  1293. class: 'none',
  1294. },
  1295. {
  1296. title: 'Tags',
  1297. data: 'attributes.tags',
  1298. defaultContent: '',
  1299. className: 'none'
  1300. },
  1301. {
  1302. title: lang.active,
  1303. data: 'attributes.active',
  1304. defaultContent: '',
  1305. responsivePriority: 4,
  1306. render: function (data, type) {
  1307. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1308. }
  1309. },
  1310. {
  1311. title: lang.action,
  1312. data: 'action',
  1313. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1314. responsivePriority: 6,
  1315. defaultContent: ''
  1316. },
  1317. ]
  1318. });
  1319. table.on('responsive-resize', function (e, datatable, columns){
  1320. hideTableExpandCollapseBtn('#tab-templates-mbox', '#templates_mbox_table');
  1321. });
  1322. }
  1323. function draw_resource_table() {
  1324. // just recalc width if instance already exists
  1325. if ($.fn.DataTable.isDataTable('#resource_table') ) {
  1326. $('#resource_table').DataTable().columns.adjust().responsive.recalc();
  1327. return;
  1328. }
  1329. var table = $('#resource_table').DataTable({
  1330. responsive: true,
  1331. processing: true,
  1332. serverSide: false,
  1333. stateSave: true,
  1334. pageLength: pagination_size,
  1335. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1336. "tr" +
  1337. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1338. language: lang_datatables,
  1339. initComplete: function(settings, json){
  1340. hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
  1341. filterByDomain(json, 5, table);
  1342. },
  1343. ajax: {
  1344. type: "GET",
  1345. url: "/api/v1/get/resource/all",
  1346. dataSrc: function(json){
  1347. $.each(json, function (i, item) {
  1348. if (item.multiple_bookings == '0') {
  1349. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-success">' + lang.booking_0_short + '</span>';
  1350. } else if (item.multiple_bookings == '-1') {
  1351. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-warning">' + lang.booking_lt0_short + '</span>';
  1352. } else {
  1353. item.multiple_bookings = '<span id="active-script" class="badge fs-6 bg-danger">' + lang.booking_custom_short + ' (' + item.multiple_bookings + ')</span>';
  1354. }
  1355. item.action = '<div class="btn-group">' +
  1356. '<a href="/edit/resource/' + encodeURIComponent(item.name) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1357. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1358. '</div>';
  1359. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="resource" name="multi_select" value="' + encodeURIComponent(item.name) + '" />';
  1360. item.name = escapeHtml(item.name);
  1361. item.description = escapeHtml(item.description);
  1362. });
  1363. return json;
  1364. }
  1365. },
  1366. columns: [
  1367. {
  1368. // placeholder, so checkbox will not block child row toggle
  1369. title: '',
  1370. data: null,
  1371. searchable: false,
  1372. orderable: false,
  1373. defaultContent: '',
  1374. responsivePriority: 1
  1375. },
  1376. {
  1377. title: '',
  1378. data: 'chkbox',
  1379. searchable: false,
  1380. orderable: false,
  1381. defaultContent: '',
  1382. responsivePriority: 2
  1383. },
  1384. {
  1385. title: lang.description,
  1386. data: 'description',
  1387. responsivePriority: 3,
  1388. defaultContent: ''
  1389. },
  1390. {
  1391. title: lang.alias,
  1392. data: 'name',
  1393. defaultContent: ''
  1394. },
  1395. {
  1396. title: lang.kind,
  1397. data: 'kind',
  1398. defaultContent: ''
  1399. },
  1400. {
  1401. title: lang.domain,
  1402. data: 'domain',
  1403. responsivePriority: 4,
  1404. defaultContent: ''
  1405. },
  1406. {
  1407. title: lang.multiple_bookings,
  1408. data: 'multiple_bookings',
  1409. defaultContent: ''
  1410. },
  1411. {
  1412. title: lang.active,
  1413. data: 'active',
  1414. defaultContent: '',
  1415. render: function (data, type) {
  1416. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1417. }
  1418. },
  1419. {
  1420. title: lang.action,
  1421. data: 'action',
  1422. responsivePriority: 5,
  1423. defaultContent: '',
  1424. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right'
  1425. },
  1426. ]
  1427. });
  1428. table.on('responsive-resize', function (e, datatable, columns){
  1429. hideTableExpandCollapseBtn('#tab-resources', '#resource_table');
  1430. });
  1431. }
  1432. function draw_bcc_table() {
  1433. $.get("/api/v1/get/bcc-destination-options", function(data){
  1434. var optgroup = "";
  1435. // Domains
  1436. if (data.domains && data.domains.length > 0) {
  1437. optgroup = "<optgroup label='" + lang.domains + "'>";
  1438. $.each(data.domains, function(index, domain){
  1439. optgroup += "<option value='" + domain + "'>" + domain + "</option>";
  1440. });
  1441. optgroup += "</optgroup>";
  1442. $('#bcc-local-dest').append(optgroup);
  1443. }
  1444. // Alias domains
  1445. if (data.alias_domains && data.alias_domains.length > 0) {
  1446. optgroup = "<optgroup label='" + lang.domain_aliases + "'>";
  1447. $.each(data.alias_domains, function(index, alias_domain){
  1448. optgroup += "<option value='" + alias_domain + "'>" + alias_domain + "</option>";
  1449. });
  1450. optgroup += "</optgroup>"
  1451. $('#bcc-local-dest').append(optgroup);
  1452. }
  1453. // Mailboxes and aliases
  1454. if (data.mailboxes && Object.keys(data.mailboxes).length > 0) {
  1455. $.each(data.mailboxes, function(mailbox, aliases){
  1456. optgroup = "<optgroup label='" + mailbox + "'>";
  1457. $.each(aliases, function(index, alias){
  1458. optgroup += "<option value='" + alias + "'>" + alias + "</option>";
  1459. });
  1460. optgroup += "</optgroup>";
  1461. $('#bcc-local-dest').append(optgroup);
  1462. });
  1463. }
  1464. // Recreate picker
  1465. $('#bcc-local-dest').selectpicker('refresh');
  1466. });
  1467. // just recalc width if instance already exists
  1468. if ($.fn.DataTable.isDataTable('#bcc_table') ) {
  1469. $('#bcc_table').DataTable().columns.adjust().responsive.recalc();
  1470. return;
  1471. }
  1472. var table = $('#bcc_table').DataTable({
  1473. responsive: true,
  1474. processing: true,
  1475. serverSide: false,
  1476. stateSave: true,
  1477. pageLength: pagination_size,
  1478. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1479. "tr" +
  1480. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1481. language: lang_datatables,
  1482. order: [[2, 'desc']],
  1483. initComplete: function(settings, json){
  1484. hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
  1485. filterByDomain(json, 6, table);
  1486. },
  1487. ajax: {
  1488. type: "GET",
  1489. url: "/api/v1/get/bcc/all",
  1490. dataSrc: function(json){
  1491. $.each(json, function (i, item) {
  1492. item.action = '<div class="btn-group">' +
  1493. '<a href="/edit/bcc/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1494. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1495. '</div>';
  1496. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="bcc" name="multi_select" value="' + item.id + '" />';
  1497. item.local_dest = escapeHtml(item.local_dest);
  1498. item.bcc_dest = escapeHtml(item.bcc_dest);
  1499. if (item.type == 'sender') {
  1500. item.type = '<span id="active-script" class="badge fs-6 bg-success">' + lang.bcc_sender_map + '</span>';
  1501. } else {
  1502. item.type = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.bcc_rcpt_map + '</span>';
  1503. }
  1504. });
  1505. return json;
  1506. }
  1507. },
  1508. columns: [
  1509. {
  1510. // placeholder, so checkbox will not block child row toggle
  1511. title: '',
  1512. data: null,
  1513. searchable: false,
  1514. orderable: false,
  1515. defaultContent: '',
  1516. responsivePriority: 1
  1517. },
  1518. {
  1519. title: '',
  1520. data: 'chkbox',
  1521. searchable: false,
  1522. orderable: false,
  1523. defaultContent: '',
  1524. responsivePriority: 2
  1525. },
  1526. {
  1527. title: 'ID',
  1528. data: 'id',
  1529. responsivePriority: 3,
  1530. defaultContent: ''
  1531. },
  1532. {
  1533. title: lang.bcc_type,
  1534. data: 'type',
  1535. defaultContent: ''
  1536. },
  1537. {
  1538. title: lang.bcc_local_dest,
  1539. data: 'local_dest',
  1540. defaultContent: ''
  1541. },
  1542. {
  1543. title: lang.bcc_destinations,
  1544. data: 'bcc_dest',
  1545. defaultContent: ''
  1546. },
  1547. {
  1548. title: lang.domain,
  1549. data: 'domain',
  1550. responsivePriority: 4,
  1551. defaultContent: ''
  1552. },
  1553. {
  1554. title: lang.active,
  1555. data: 'active',
  1556. defaultContent: '',
  1557. render: function (data, type) {
  1558. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':(0==data?'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>':2==data&&'&#8212;');
  1559. }
  1560. },
  1561. {
  1562. title: lang.action,
  1563. data: 'action',
  1564. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1565. responsivePriority: 5,
  1566. defaultContent: ''
  1567. },
  1568. ]
  1569. });
  1570. table.on('responsive-resize', function (e, datatable, columns){
  1571. hideTableExpandCollapseBtn('#collapse-tab-bcc', '#bcc_table');
  1572. });
  1573. }
  1574. function draw_recipient_map_table() {
  1575. // just recalc width if instance already exists
  1576. if ($.fn.DataTable.isDataTable('#recipient_map_table') ) {
  1577. $('#recipient_map_table').DataTable().columns.adjust().responsive.recalc();
  1578. return;
  1579. }
  1580. var table = $('#recipient_map_table').DataTable({
  1581. responsive: true,
  1582. processing: true,
  1583. serverSide: false,
  1584. stateSave: true,
  1585. pageLength: pagination_size,
  1586. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1587. "tr" +
  1588. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1589. language: lang_datatables,
  1590. order: [[2, 'desc']],
  1591. initComplete: function(){
  1592. hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
  1593. },
  1594. ajax: {
  1595. type: "GET",
  1596. url: "/api/v1/get/recipient_map/all",
  1597. dataSrc: function(json){
  1598. if (role !== "admin") return null;
  1599. $.each(json, function (i, item) {
  1600. item.recipient_map_old = escapeHtml(item.recipient_map_old);
  1601. item.recipient_map_new = escapeHtml(item.recipient_map_new);
  1602. item.action = '<div class="btn-group">' +
  1603. '<a href="/edit/recipient_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1604. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1605. '</div>';
  1606. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="recipient_map" name="multi_select" value="' + item.id + '" />';
  1607. });
  1608. return json;
  1609. }
  1610. },
  1611. columns: [
  1612. {
  1613. // placeholder, so checkbox will not block child row toggle
  1614. title: '',
  1615. data: null,
  1616. searchable: false,
  1617. orderable: false,
  1618. defaultContent: '',
  1619. responsivePriority: 1
  1620. },
  1621. {
  1622. title: '',
  1623. data: 'chkbox',
  1624. searchable: false,
  1625. orderable: false,
  1626. defaultContent: '',
  1627. responsivePriority: 2
  1628. },
  1629. {
  1630. title: 'ID',
  1631. data: 'id',
  1632. responsivePriority: 3,
  1633. defaultContent: ''
  1634. },
  1635. {
  1636. title: lang.recipient_map_old,
  1637. data: 'recipient_map_old',
  1638. defaultContent: ''
  1639. },
  1640. {
  1641. title: lang.recipient_map_new,
  1642. data: 'recipient_map_new',
  1643. defaultContent: '',
  1644. responsivePriority: 4
  1645. },
  1646. {
  1647. title: lang.active,
  1648. data: 'active',
  1649. defaultContent: '',
  1650. render: function (data, type) {
  1651. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1652. }
  1653. },
  1654. {
  1655. title: lang.action,
  1656. data: 'action',
  1657. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1658. responsivePriority: 5,
  1659. defaultContent: ''
  1660. },
  1661. ]
  1662. });
  1663. table.on('responsive-resize', function (e, datatable, columns){
  1664. hideTableExpandCollapseBtn('#collapse-tab-bcc-filters', '#recipient_map_table');
  1665. });
  1666. }
  1667. function draw_tls_policy_table() {
  1668. // just recalc width if instance already exists
  1669. if ($.fn.DataTable.isDataTable('#tls_policy_table') ) {
  1670. $('#tls_policy_table').DataTable().columns.adjust().responsive.recalc();
  1671. return;
  1672. }
  1673. var table = $('#tls_policy_table').DataTable({
  1674. responsive: true,
  1675. processing: true,
  1676. serverSide: false,
  1677. stateSave: true,
  1678. pageLength: pagination_size,
  1679. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1680. "tr" +
  1681. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1682. language: lang_datatables,
  1683. order: [[2, 'desc']],
  1684. initComplete: function(){
  1685. hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
  1686. },
  1687. ajax: {
  1688. type: "GET",
  1689. url: "/api/v1/get/tls-policy-map/all",
  1690. dataSrc: function(json){
  1691. if (role !== "admin") return null;
  1692. $.each(json, function (i, item) {
  1693. item.dest = escapeHtml(item.dest);
  1694. item.policy = '<b>' + escapeHtml(item.policy) + '</b>';
  1695. if (item.parameters == '') {
  1696. item.parameters = '<code>-</code>';
  1697. } else {
  1698. item.parameters = '<code>' + escapeHtml(item.parameters) + '</code>';
  1699. }
  1700. item.action = '<div class="btn-group">' +
  1701. '<a href="/edit/tls_policy_map/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1702. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1703. '</div>';
  1704. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="tls-policy-map" name="multi_select" value="' + item.id + '" />';
  1705. });
  1706. return json;
  1707. }
  1708. },
  1709. columns: [
  1710. {
  1711. // placeholder, so checkbox will not block child row toggle
  1712. title: '',
  1713. data: null,
  1714. searchable: false,
  1715. orderable: false,
  1716. defaultContent: '',
  1717. responsivePriority: 1
  1718. },
  1719. {
  1720. title: '',
  1721. data: 'chkbox',
  1722. searchable: false,
  1723. orderable: false,
  1724. defaultContent: '',
  1725. responsivePriority: 2
  1726. },
  1727. {
  1728. title: 'ID',
  1729. data: 'id',
  1730. responsivePriority: 3,
  1731. defaultContent: ''
  1732. },
  1733. {
  1734. title: lang.tls_map_dest,
  1735. data: 'dest',
  1736. defaultContent: '',
  1737. responsivePriority: 4
  1738. },
  1739. {
  1740. title: lang.tls_map_policy,
  1741. data: 'policy',
  1742. defaultContent: ''
  1743. },
  1744. {
  1745. title: lang.tls_map_parameters,
  1746. data: 'parameters',
  1747. defaultContent: ''
  1748. },
  1749. {
  1750. title: lang.active,
  1751. data: 'active',
  1752. defaultContent: '',
  1753. render: function (data, type) {
  1754. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1755. }
  1756. },
  1757. {
  1758. title: lang.action,
  1759. data: 'action',
  1760. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1761. responsivePriority: 5,
  1762. defaultContent: ''
  1763. },
  1764. ]
  1765. });
  1766. table.on('responsive-resize', function (e, datatable, columns){
  1767. hideTableExpandCollapseBtn('#tab-tls-policy', '#tls_policy_table');
  1768. });
  1769. }
  1770. function draw_alias_table() {
  1771. // just recalc width if instance already exists
  1772. if ($.fn.DataTable.isDataTable('#alias_table') ) {
  1773. $('#alias_table').DataTable().columns.adjust().responsive.recalc();
  1774. return;
  1775. }
  1776. var table = $('#alias_table').DataTable({
  1777. responsive: true,
  1778. processing: true,
  1779. serverSide: false,
  1780. stateSave: true,
  1781. pageLength: pagination_size,
  1782. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1783. "tr" +
  1784. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1785. language: lang_datatables,
  1786. order: [[2, 'desc']],
  1787. initComplete: function(settings, json){
  1788. hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
  1789. filterByDomain(json, 5, table);
  1790. },
  1791. ajax: {
  1792. type: "GET",
  1793. url: "/api/v1/get/alias/all",
  1794. dataSrc: function(json){
  1795. $.each(json, function (i, item) {
  1796. item.action = '<div class="btn-group">' +
  1797. '<a href="/edit/alias/' + encodeURIComponent(item.id) + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1798. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1799. '</div>';
  1800. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias" name="multi_select" value="' + encodeURIComponent(item.id) + '" />';
  1801. item.goto = escapeHtml(item.goto.replace(/,/g, " "));
  1802. if (item.public_comment !== null) {
  1803. item.public_comment = escapeHtml(item.public_comment);
  1804. }
  1805. else {
  1806. item.public_comment = '-';
  1807. }
  1808. if (item.private_comment !== null) {
  1809. item.private_comment = escapeHtml(item.private_comment);
  1810. }
  1811. else {
  1812. item.private_comment = '-';
  1813. }
  1814. if (item.is_catch_all == 1) {
  1815. item.address = '<div class="badge fs-6 bg-secondary">' + lang.catch_all + '</div> ' + escapeHtml(item.address);
  1816. }
  1817. else {
  1818. item.address = escapeHtml(item.address);
  1819. }
  1820. if (item.goto == "null@localhost") {
  1821. item.goto = '⤷ <i class="bi bi-trash" style="font-size:12px"></i>';
  1822. }
  1823. else if (item.goto == "spam@localhost") {
  1824. item.goto = '<span class="badge fs-6 bg-danger">' + lang.goto_spam + '</span>';
  1825. }
  1826. else if (item.goto == "ham@localhost") {
  1827. item.goto = '<span class="badge fs-6 bg-success">' + lang.goto_ham + '</span>';
  1828. }
  1829. if (item.in_primary_domain !== "") {
  1830. 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;
  1831. }
  1832. });
  1833. return json;
  1834. }
  1835. },
  1836. columns: [
  1837. {
  1838. // placeholder, so checkbox will not block child row toggle
  1839. title: '',
  1840. data: null,
  1841. searchable: false,
  1842. orderable: false,
  1843. defaultContent: '',
  1844. responsivePriority: 1
  1845. },
  1846. {
  1847. title: '',
  1848. data: 'chkbox',
  1849. searchable: false,
  1850. orderable: false,
  1851. defaultContent: '',
  1852. responsivePriority: 2
  1853. },
  1854. {
  1855. title: 'ID',
  1856. data: 'id',
  1857. responsivePriority: 3,
  1858. defaultContent: ''
  1859. },
  1860. {
  1861. title: lang.alias,
  1862. data: 'address',
  1863. responsivePriority: 4,
  1864. defaultContent: ''
  1865. },
  1866. {
  1867. title: lang.target_address,
  1868. data: 'goto',
  1869. defaultContent: ''
  1870. },
  1871. {
  1872. title: lang.domain,
  1873. data: 'domain',
  1874. defaultContent: '',
  1875. responsivePriority: 5,
  1876. },
  1877. {
  1878. title: lang.bcc_destinations,
  1879. data: 'bcc_dest',
  1880. defaultContent: ''
  1881. },
  1882. {
  1883. title: lang.sogo_visible,
  1884. data: 'sogo_visible',
  1885. defaultContent: '',
  1886. render: function(data, type){
  1887. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1888. }
  1889. },
  1890. {
  1891. title: lang.public_comment,
  1892. data: 'public_comment',
  1893. defaultContent: ''
  1894. },
  1895. {
  1896. title: lang.private_comment,
  1897. data: 'private_comment',
  1898. defaultContent: ''
  1899. },
  1900. {
  1901. title: lang.active,
  1902. data: 'active',
  1903. defaultContent: '',
  1904. responsivePriority: 6,
  1905. render: function (data, type) {
  1906. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  1907. }
  1908. },
  1909. {
  1910. title: lang.action,
  1911. data: 'action',
  1912. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  1913. responsivePriority: 5,
  1914. defaultContent: ''
  1915. },
  1916. ]
  1917. });
  1918. table.on('responsive-resize', function (e, datatable, columns){
  1919. hideTableExpandCollapseBtn('#tab-mbox-aliases', '#alias_table');
  1920. });
  1921. table.on( 'draw', function (){
  1922. $('#alias_table [data-bs-toggle="tooltip"]').tooltip();
  1923. });
  1924. }
  1925. function draw_aliasdomain_table() {
  1926. // just recalc width if instance already exists
  1927. if ($.fn.DataTable.isDataTable('#aliasdomain_table') ) {
  1928. $('#aliasdomain_table').DataTable().columns.adjust().responsive.recalc();
  1929. return;
  1930. }
  1931. var table = $('#aliasdomain_table').DataTable({
  1932. responsive: true,
  1933. processing: true,
  1934. serverSide: false,
  1935. stateSave: true,
  1936. pageLength: pagination_size,
  1937. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  1938. "tr" +
  1939. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  1940. language: lang_datatables,
  1941. initComplete: function(){
  1942. hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
  1943. },
  1944. ajax: {
  1945. type: "GET",
  1946. url: "/api/v1/get/alias-domain/all",
  1947. dataSrc: function(json){
  1948. $.each(json, function (i, item) {
  1949. item.alias_domain = escapeHtml(item.alias_domain);
  1950. item.action = '<div class="btn-group">' +
  1951. '<a href="/edit/aliasdomain/' + encodeURIComponent(item.alias_domain) + '" class="btn btn-sm btn-xs-lg btn-xs-third btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  1952. '<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-lg btn-xs-third btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  1953. '<a href="#dnsInfoModal" class="btn btn-sm btn-xs-lg btn-xs-third btn-info" data-bs-toggle="modal" data-domain="' + encodeURIComponent(item.alias_domain) + '"><i class="bi bi-globe2"></i> DNS</a></div>' +
  1954. '</div>';
  1955. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="alias-domain" name="multi_select" value="' + encodeURIComponent(item.alias_domain) + '" />';
  1956. if(item.parent_is_backupmx == '1') {
  1957. 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>';
  1958. } else {
  1959. item.target_domain = '<span><a href="/edit/domain/' + item.target_domain + '">' + item.target_domain + '</a></span>';
  1960. }
  1961. });
  1962. return json;
  1963. }
  1964. },
  1965. columns: [
  1966. {
  1967. // placeholder, so checkbox will not block child row toggle
  1968. title: '',
  1969. data: null,
  1970. searchable: false,
  1971. orderable: false,
  1972. defaultContent: '',
  1973. responsivePriority: 1
  1974. },
  1975. {
  1976. title: '',
  1977. data: 'chkbox',
  1978. searchable: false,
  1979. orderable: false,
  1980. defaultContent: '',
  1981. responsivePriority: 2
  1982. },
  1983. {
  1984. title: lang.alias,
  1985. data: 'alias_domain',
  1986. responsivePriority: 3,
  1987. defaultContent: ''
  1988. },
  1989. {
  1990. title: lang.target_domain,
  1991. data: 'target_domain',
  1992. responsivePriority: 4,
  1993. defaultContent: ''
  1994. },
  1995. {
  1996. title: lang.active,
  1997. data: 'active',
  1998. defaultContent: '',
  1999. render: function (data, type) {
  2000. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  2001. }
  2002. },
  2003. {
  2004. title: lang.action,
  2005. data: 'action',
  2006. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  2007. responsivePriority: 5,
  2008. defaultContent: ''
  2009. },
  2010. ]
  2011. });
  2012. table.on('responsive-resize', function (e, datatable, columns){
  2013. hideTableExpandCollapseBtn('#tab-domain-aliases', '#aliasdomain_table');
  2014. });
  2015. }
  2016. function draw_sync_job_table() {
  2017. // just recalc width if instance already exists
  2018. if ($.fn.DataTable.isDataTable('#sync_job_table') ) {
  2019. $('#sync_job_table').DataTable().columns.adjust().responsive.recalc();
  2020. return;
  2021. }
  2022. var table = $('#sync_job_table').DataTable({
  2023. responsive: true,
  2024. processing: true,
  2025. serverSide: false,
  2026. stateSave: true,
  2027. pageLength: pagination_size,
  2028. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  2029. "tr" +
  2030. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  2031. language: lang_datatables,
  2032. order: [[2, 'desc']],
  2033. initComplete: function(){
  2034. hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
  2035. },
  2036. ajax: {
  2037. type: "GET",
  2038. url: "/api/v1/get/syncjobs/all/no_log",
  2039. dataSrc: function(json){
  2040. $.each(json, function (i, item) {
  2041. item.log = '<a href="#syncjobLogModal" data-bs-toggle="modal" data-syncjob-id="' + encodeURIComponent(item.id) + '">' + lang.open_logs + '</a>'
  2042. item.user2 = escapeHtml(item.user2);
  2043. if (!item.exclude > 0) {
  2044. item.exclude = '-';
  2045. } else {
  2046. item.exclude = '<code>' + escapeHtml(item.exclude) + '</code>';
  2047. }
  2048. item.server_w_port = escapeHtml(item.user1) + '@' + escapeHtml(item.host1) + ':' + escapeHtml(item.port1);
  2049. item.action = '<div class="btn-group">' +
  2050. '<a href="/edit/syncjob/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  2051. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  2052. '</div>';
  2053. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="syncjob" name="multi_select" value="' + item.id + '" />';
  2054. if (item.is_running == 1) {
  2055. item.is_running = '<span id="active-script" class="badge fs-6 bg-success">' + lang.running + '</span>';
  2056. } else {
  2057. item.is_running = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.waiting + '</span>';
  2058. }
  2059. if (!item.last_run > 0) {
  2060. item.last_run = lang.waiting;
  2061. }
  2062. if (item.success == null) {
  2063. item.success = '-';
  2064. item.exit_status = '';
  2065. } else {
  2066. item.success = '<i class="text-' + (item.success == 1 ? 'success' : 'danger') + ' bi bi-' + (item.success == 1 ? 'check-lg' : 'x-lg') + '"></i>';
  2067. }
  2068. if (lang['syncjob_'+item.exit_status]) {
  2069. item.exit_status = lang['syncjob_'+item.exit_status];
  2070. } else if (item.success != '-') {
  2071. item.exit_status = lang.syncjob_check_log;
  2072. }
  2073. item.exit_status = item.success + ' ' + item.exit_status;
  2074. });
  2075. return json;
  2076. }
  2077. },
  2078. columns: [
  2079. {
  2080. // placeholder, so checkbox will not block child row toggle
  2081. title: '',
  2082. data: null,
  2083. searchable: false,
  2084. orderable: false,
  2085. defaultContent: '',
  2086. responsivePriority: 1
  2087. },
  2088. {
  2089. title: '',
  2090. data: 'chkbox',
  2091. searchable: false,
  2092. orderable: false,
  2093. defaultContent: '',
  2094. responsivePriority: 2
  2095. },
  2096. {
  2097. title: 'ID',
  2098. data: 'id',
  2099. responsivePriority: 3,
  2100. defaultContent: ''
  2101. },
  2102. {
  2103. title: lang.owner,
  2104. data: 'user2',
  2105. responsivePriority: 4,
  2106. defaultContent: ''
  2107. },
  2108. {
  2109. title: 'Server',
  2110. data: 'server_w_port',
  2111. defaultContent: ''
  2112. },
  2113. {
  2114. title: lang.last_run,
  2115. data: 'last_run',
  2116. defaultContent: ''
  2117. },
  2118. {
  2119. title: lang.syncjob_last_run_result,
  2120. data: 'exit_status',
  2121. defaultContent: ''
  2122. },
  2123. {
  2124. title: 'Log',
  2125. data: 'log',
  2126. defaultContent: ''
  2127. },
  2128. {
  2129. title: lang.active,
  2130. data: 'active',
  2131. defaultContent: '',
  2132. render: function (data, type) {
  2133. return 1==data?'<i class="bi bi-check-lg"><span class="sorting-value">1</span></i>':0==data&&'<i class="bi bi-x-lg"><span class="sorting-value">0</span></i>';
  2134. }
  2135. },
  2136. {
  2137. title: lang.status,
  2138. data: 'is_running',
  2139. defaultContent: ''
  2140. },
  2141. {
  2142. title: lang.excludes,
  2143. data: 'exclude',
  2144. defaultContent: '',
  2145. className: 'none'
  2146. },
  2147. {
  2148. title: lang.mins_interval,
  2149. data: 'mins_interval',
  2150. defaultContent: '',
  2151. className: 'none'
  2152. },
  2153. {
  2154. title: lang.action,
  2155. data: 'action',
  2156. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  2157. responsivePriority: 5,
  2158. defaultContent: ''
  2159. },
  2160. ]
  2161. });
  2162. table.on('responsive-resize', function (e, datatable, columns){
  2163. hideTableExpandCollapseBtn('#tab-syncjobs', '#sync_job_table');
  2164. });
  2165. }
  2166. function draw_filter_table() {
  2167. // just recalc width if instance already exists
  2168. if ($.fn.DataTable.isDataTable('#filter_table') ) {
  2169. $('#filter_table').DataTable().columns.adjust().responsive.recalc();
  2170. return;
  2171. }
  2172. var table = $('#filter_table').DataTable({
  2173. responsive: true,
  2174. autoWidth: false,
  2175. processing: true,
  2176. serverSide: false,
  2177. stateSave: true,
  2178. pageLength: pagination_size,
  2179. dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
  2180. "tr" +
  2181. "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
  2182. language: lang_datatables,
  2183. order: [[2, 'desc']],
  2184. initComplete: function(){
  2185. hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
  2186. },
  2187. ajax: {
  2188. type: "GET",
  2189. url: "/api/v1/get/filters/all",
  2190. dataSrc: function(json){
  2191. $.each(json, function (i, item) {
  2192. if (item.active == 1) {
  2193. item.active = '<span id="active-script" class="badge fs-6 bg-success">' + lang.active + '</span>';
  2194. } else {
  2195. item.active = '<span id="inactive-script" class="badge fs-6 bg-warning">' + lang.inactive + '</span>';
  2196. }
  2197. item.script_desc = escapeHtml(item.script_desc);
  2198. item.script_data = '<pre class="text-break" style="margin:0px">' + escapeHtml(item.script_data) + '</pre>'
  2199. item.filter_type = '<div class="badge fs-6 bg-secondary">' + item.filter_type.charAt(0).toUpperCase() + item.filter_type.slice(1).toLowerCase() + '</div>'
  2200. item.action = '<div class="btn-group">' +
  2201. '<a href="/edit/filter/' + item.id + '" class="btn btn-sm btn-xs-lg btn-xs-half btn-secondary"><i class="bi bi-pencil-fill"></i> ' + lang.edit + '</a>' +
  2202. '<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-lg btn-xs-half btn-danger"><i class="bi bi-trash"></i> ' + lang.remove + '</a>' +
  2203. '</div>';
  2204. item.chkbox = '<input type="checkbox" class="form-check-input" data-id="filter_item" name="multi_select" value="' + item.id + '" />'
  2205. });
  2206. return json;
  2207. }
  2208. },
  2209. columns: [
  2210. {
  2211. // placeholder, so checkbox will not block child row toggle
  2212. title: '',
  2213. data: null,
  2214. searchable: false,
  2215. orderable: false,
  2216. defaultContent: '',
  2217. responsivePriority: 1
  2218. },
  2219. {
  2220. title: '',
  2221. data: 'chkbox',
  2222. searchable: false,
  2223. orderable: false,
  2224. defaultContent: '',
  2225. responsivePriority: 2
  2226. },
  2227. {
  2228. title: 'ID',
  2229. data: 'id',
  2230. responsivePriority: 2,
  2231. defaultContent: ''
  2232. },
  2233. {
  2234. title: lang.active,
  2235. data: 'active',
  2236. responsivePriority: 3,
  2237. defaultContent: ''
  2238. },
  2239. {
  2240. title: 'Type',
  2241. data: 'filter_type',
  2242. responsivePriority: 4,
  2243. defaultContent: ''
  2244. },
  2245. {
  2246. title: lang.owner,
  2247. data: 'username',
  2248. defaultContent: ''
  2249. },
  2250. {
  2251. title: lang.description,
  2252. data: 'script_desc',
  2253. defaultContent: ''
  2254. },
  2255. {
  2256. title: 'Script',
  2257. data: 'script_data',
  2258. defaultContent: '',
  2259. className: 'none'
  2260. },
  2261. {
  2262. title: lang.action,
  2263. data: 'action',
  2264. className: 'dt-sm-head-hidden dt-data-w100 dtr-col-md dt-text-right',
  2265. responsivePriority: 5,
  2266. defaultContent: ''
  2267. },
  2268. ]
  2269. });
  2270. table.on('responsive-resize', function (e, datatable, columns){
  2271. hideTableExpandCollapseBtn('#tab-filters', '#filter_table');
  2272. });
  2273. };
  2274. function hideTableExpandCollapseBtn(tab, table){
  2275. if ($(table).hasClass('collapsed'))
  2276. $(tab).find(".table_collapse_option").show();
  2277. else
  2278. $(tab).find(".table_collapse_option").hide();
  2279. }
  2280. function filterByDomain(json, column, table){
  2281. var tableId = $(table.table().container()).attr('id');
  2282. // Create the `select` element
  2283. var select = $('<select class="btn btn-sm btn-xs-lg btn-light text-start mx-2"><option value="">'+lang.all_domains+'</option></select>')
  2284. .insertBefore(
  2285. $('#'+tableId+' .dataTables_filter > label > input')
  2286. )
  2287. .on( 'change', function(){
  2288. table.column(column)
  2289. .search($(this).val())
  2290. .draw();
  2291. });
  2292. // get all domains
  2293. var domains = [];
  2294. json.forEach(obj => {
  2295. Object.entries(obj).forEach(([key, value]) => {
  2296. if(key === 'domain') {
  2297. domains.push(value)
  2298. }
  2299. });
  2300. });
  2301. // get unique domain list
  2302. domains = domains.filter(function(value, index, array) {
  2303. return array.indexOf(value) === index;
  2304. });
  2305. // add domains to select
  2306. domains.forEach(function(domain) {
  2307. select.append($('<option>' + domain + '</option>'));
  2308. });
  2309. }
  2310. // detect element visibility changes
  2311. function onVisible(element, callback) {
  2312. $(document).ready(function() {
  2313. let element_object = document.querySelector(element);
  2314. if (element_object === null) return;
  2315. let observer = new IntersectionObserver((entries, observer) => {
  2316. entries.forEach(entry => {
  2317. if(entry.intersectionRatio > 0) {
  2318. callback(element_object);
  2319. observer.unobserve(element_object);
  2320. }
  2321. });
  2322. })
  2323. observer.observe(element_object);
  2324. });
  2325. }
  2326. // Load only if the tab is visible
  2327. onVisible("[id^=domain_table]", () => draw_domain_table());
  2328. onVisible("[id^=templates_domain_table]", () => draw_templates_domain_table());
  2329. onVisible("[id^=mailbox_table]", () => draw_mailbox_table());
  2330. onVisible("[id^=templates_mbox_table]", () => draw_templates_mbox_table());
  2331. onVisible("[id^=resource_table]", () => draw_resource_table());
  2332. onVisible("[id^=alias_table]", () => draw_alias_table());
  2333. onVisible("[id^=aliasdomain_table]", () => draw_aliasdomain_table());
  2334. onVisible("[id^=sync_job_table]", () => draw_sync_job_table());
  2335. onVisible("[id^=filter_table]", () => draw_filter_table());
  2336. onVisible("[id^=bcc_table]", () => draw_bcc_table());
  2337. onVisible("[id^=recipient_map_table]", () => draw_recipient_map_table());
  2338. onVisible("[id^=tls_policy_table]", () => draw_tls_policy_table());
  2339. });