mailbox.js 85 KB

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