2
0

mailbox.js 89 KB

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