2
0

mailbox.js 90 KB

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