mailbox.js 83 KB

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