mailbox.js 83 KB

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