mailbox.js 80 KB

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