mailbox.js 86 KB

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