mailbox.js 90 KB

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