2
0

mailbox.js 90 KB

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