mailbox.js 90 KB

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