mailbox.js 92 KB

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