mailbox.js 81 KB

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