mailbox.js 80 KB

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