mailbox.js 91 KB

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