footer.inc.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php';
  3. logger();
  4. ?>
  5. <div style="margin-bottom: 100px;"></div>
  6. <script src="/js/bootstrap.min.js"></script>
  7. <script src="/js/bootstrap-switch.min.js"></script>
  8. <script src="/js/bootstrap-slider.min.js"></script>
  9. <script src="/js/bootstrap-select.min.js"></script>
  10. <script src="/js/bootstrap-filestyle.min.js"></script>
  11. <script src="/js/notifications.min.js"></script>
  12. <script src="/js/formcache.min.js"></script>
  13. <script src="/js/google.charts.loader.js"></script>
  14. <script src="/js/numberedtextarea.min.js"></script>
  15. <script src="/js/sha1.min.js"></script>
  16. <script src="/js/u2f-api.js"></script>
  17. <script src="/js/api.js"></script>
  18. <script src="/js/mailcow.js"></script>
  19. <script>
  20. <?php
  21. $lang_footer = json_encode($lang['footer']);
  22. $lang_acl = json_encode($lang['acl']);
  23. $lang_tfa = json_encode($lang['tfa']);
  24. echo "var lang_footer = ". $lang_footer . ";\n";
  25. echo "var lang_acl = ". $lang_acl . ";\n";
  26. echo "var lang_tfa = ". $lang_tfa . ";\n";
  27. echo "var docker_timeout = ". $DOCKER_TIMEOUT * 1000 . ";\n";
  28. ?>
  29. $(window).scroll(function() {
  30. sessionStorage.scrollTop = $(this).scrollTop();
  31. });
  32. // Select language and reopen active URL without POST
  33. function setLang(sel) {
  34. $.post( "<?= $_SERVER['REQUEST_URI']; ?>", {lang: sel} );
  35. window.location.href = window.location.pathname + window.location.search;
  36. }
  37. $(window).load(function() {
  38. $(".overlay").hide();
  39. });
  40. $(document).ready(function() {
  41. // TFA, CSRF, Alerts in footer.inc.php
  42. // Other general functions in mailcow.js
  43. <?php
  44. $alertbox_log_parser = alertbox_log_parser($_SESSION);
  45. if (is_array($alertbox_log_parser)) {
  46. foreach($alertbox_log_parser as $log) {
  47. ?>
  48. mailcow_alert_box(<?=$log['msg'];?>, <?=$log['type'];?>);
  49. <?php
  50. }
  51. unset($_SESSION['return']);
  52. }
  53. ?>
  54. // Confirm TFA modal
  55. <?php if (isset($_SESSION['pending_tfa_method'])):?>
  56. $('#ConfirmTFAModal').modal({
  57. backdrop: 'static',
  58. keyboard: false
  59. });
  60. $('#u2f_status_auth').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  61. $('#ConfirmTFAModal').on('shown.bs.modal', function(){
  62. $(this).find('#token').focus();
  63. // If U2F
  64. if(document.getElementById("u2f_auth_data") !== null) {
  65. $.ajax({
  66. type: "GET",
  67. cache: false,
  68. dataType: 'script',
  69. url: "/api/v1/get/u2f-authentication/<?= (isset($_SESSION['pending_mailcow_cc_username'])) ? rawurlencode($_SESSION['pending_mailcow_cc_username']) : null; ?>",
  70. complete: function(data){
  71. $('#u2f_status_auth').html(lang_tfa.waiting_usb_auth);
  72. data;
  73. setTimeout(function() {
  74. console.log("Ready to authenticate");
  75. u2f.sign(appId, challenge, registeredKeys, function(data) {
  76. var form = document.getElementById('u2f_auth_form');
  77. var auth = document.getElementById('u2f_auth_data');
  78. console.log("Authenticate callback", data);
  79. auth.value = JSON.stringify(data);
  80. form.submit();
  81. });
  82. }, 1000);
  83. }
  84. });
  85. }
  86. });
  87. $('#ConfirmTFAModal').on('hidden.bs.modal', function(){
  88. $.ajax({
  89. type: "GET",
  90. cache: false,
  91. dataType: 'script',
  92. url: '/inc/ajax/destroy_tfa_auth.php',
  93. complete: function(data){
  94. window.location = window.location.href.split("#")[0];
  95. }
  96. });
  97. });
  98. <?php endif; ?>
  99. // Set TFA modals
  100. $('#selectTFA').change(function () {
  101. if ($(this).val() == "yubi_otp") {
  102. $('#YubiOTPModal').modal('show');
  103. $("option:selected").prop("selected", false);
  104. }
  105. if ($(this).val() == "totp") {
  106. $('#TOTPModal').modal('show');
  107. $("option:selected").prop("selected", false);
  108. }
  109. if ($(this).val() == "u2f") {
  110. $('#U2FModal').modal('show');
  111. $("option:selected").prop("selected", false);
  112. $('#u2f_status_reg').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  113. $.ajax({
  114. type: "GET",
  115. cache: false,
  116. dataType: 'script',
  117. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? rawurlencode($_SESSION['mailcow_cc_username']) : null; ?>",
  118. complete: function(data){
  119. data;
  120. setTimeout(function() {
  121. console.log("Ready to register");
  122. $('#u2f_status_reg').html(lang_tfa.waiting_usb_register);
  123. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  124. var form = document.getElementById('u2f_reg_form');
  125. var reg = document.getElementById('u2f_register_data');
  126. console.log("Register callback: ", data);
  127. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  128. var u2f_return_code = document.getElementById('u2f_return_code');
  129. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  130. if (deviceResponse.errorCode == "4") { deviceResponse.errorCode = "4 - The presented device is not eligible for this request. For a registration request this may mean that the token is already registered, and for a sign request it may mean that the token does not know the presented key handle"; }
  131. u2f_return_code.innerHTML = 'Error code: ' + deviceResponse.errorCode;
  132. return;
  133. }
  134. reg.value = JSON.stringify(deviceResponse);
  135. form.submit();
  136. });
  137. }, 1000);
  138. }
  139. });
  140. }
  141. if ($(this).val() == "none") {
  142. $('#DisableTFAModal').modal('show');
  143. $("option:selected").prop("selected", false);
  144. }
  145. });
  146. // CSRF
  147. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('id', 'csrf_token').attr('name', 'csrf_token').appendTo('form');
  148. if (sessionStorage.scrollTop != "undefined") {
  149. $(window).scrollTop(sessionStorage.scrollTop);
  150. }
  151. });
  152. </script>
  153. </body>
  154. </html>
  155. <?php
  156. $stmt = null;
  157. $pdo = null;