mailbox.js 91 KB

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