mailbox.js 90 KB

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