footer.inc.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php';
  3. logger();
  4. ?>
  5. <div style="margin-bottom: 100px;"></div>
  6. <script type='text/javascript'><?=$js_minifier->minify();?></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. request_token = $('#tfa-qr-img').data('totp-secret');
  96. $.ajax({
  97. url: '/inc/ajax/qr_gen.php',
  98. data: {
  99. token: request_token,
  100. },
  101. }).done(function (result) {
  102. $("#tfa-qr-img").attr("src", result);
  103. });
  104. $("option:selected").prop("selected", false);
  105. }
  106. if ($(this).val() == "u2f") {
  107. $('#U2FModal').modal('show');
  108. $("option:selected").prop("selected", false);
  109. $('#u2f_status_reg').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  110. $.ajax({
  111. type: "GET",
  112. cache: false,
  113. dataType: 'script',
  114. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? rawurlencode($_SESSION['mailcow_cc_username']) : null; ?>",
  115. complete: function(data){
  116. data;
  117. setTimeout(function() {
  118. console.log("Ready to register");
  119. $('#u2f_status_reg').html(lang_tfa.waiting_usb_register);
  120. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  121. var form = document.getElementById('u2f_reg_form');
  122. var reg = document.getElementById('u2f_register_data');
  123. console.log("Register callback: ", data);
  124. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  125. var u2f_return_code = document.getElementById('u2f_return_code');
  126. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  127. 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"; }
  128. u2f_return_code.innerHTML = 'Error code: ' + deviceResponse.errorCode;
  129. return;
  130. }
  131. reg.value = JSON.stringify(deviceResponse);
  132. form.submit();
  133. });
  134. }, 1000);
  135. }
  136. });
  137. }
  138. if ($(this).val() == "none") {
  139. $('#DisableTFAModal').modal('show');
  140. $("option:selected").prop("selected", false);
  141. }
  142. });
  143. // CSRF
  144. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('name', 'csrf_token').appendTo('form');
  145. if (sessionStorage.scrollTop != "undefined") {
  146. $(window).scrollTop(sessionStorage.scrollTop);
  147. }
  148. });
  149. </script>
  150. </body>
  151. </html>
  152. <?php
  153. $stmt = null;
  154. $pdo = null;