footer.inc.php 5.4 KB

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