mailbox.js 83 KB

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