footer.inc.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. $(document).on('shown.bs.modal', function(e) {
  30. modal_id = $(e.relatedTarget).data('target');
  31. $(modal_id).attr("aria-hidden","false");
  32. });
  33. // TFA, CSRF, Alerts in footer.inc.php
  34. // Other general functions in mailcow.js
  35. <?php
  36. $alertbox_log_parser = alertbox_log_parser($_SESSION);
  37. if (is_array($alertbox_log_parser)) {
  38. foreach($alertbox_log_parser as $log) {
  39. ?>
  40. mailcow_alert_box(<?=$log['msg'];?>, <?=$log['type'];?>);
  41. <?php
  42. }
  43. unset($_SESSION['return']);
  44. }
  45. ?>
  46. // Confirm TFA modal
  47. <?php if (isset($_SESSION['pending_tfa_method'])):?>
  48. $('#ConfirmTFAModal').modal({
  49. backdrop: 'static',
  50. keyboard: false
  51. });
  52. $('#u2f_status_auth').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  53. $('#ConfirmTFAModal').on('shown.bs.modal', function(){
  54. $(this).find('input[name=token]').focus();
  55. // If U2F
  56. if(document.getElementById("u2f_auth_data") !== null) {
  57. $.ajax({
  58. type: "GET",
  59. cache: false,
  60. dataType: 'script',
  61. url: "/api/v1/get/u2f-authentication/<?= (isset($_SESSION['pending_mailcow_cc_username'])) ? rawurlencode($_SESSION['pending_mailcow_cc_username']) : null; ?>",
  62. complete: function(data){
  63. $('#u2f_status_auth').html(lang_tfa.waiting_usb_auth);
  64. data;
  65. setTimeout(function() {
  66. console.log("Ready to authenticate");
  67. u2f.sign(appId, challenge, registeredKeys, function(data) {
  68. var form = document.getElementById('u2f_auth_form');
  69. var auth = document.getElementById('u2f_auth_data');
  70. console.log("Authenticate callback", data);
  71. auth.value = JSON.stringify(data);
  72. form.submit();
  73. });
  74. }, 1000);
  75. }
  76. });
  77. }
  78. });
  79. $('#ConfirmTFAModal').on('hidden.bs.modal', function(){
  80. $.ajax({
  81. type: "GET",
  82. cache: false,
  83. dataType: 'script',
  84. url: '/inc/ajax/destroy_tfa_auth.php',
  85. complete: function(data){
  86. window.location = window.location.href.split("#")[0];
  87. }
  88. });
  89. });
  90. <?php endif; ?>
  91. // Set TFA modals
  92. $('#selectTFA').change(function () {
  93. if ($(this).val() == "yubi_otp") {
  94. $('#YubiOTPModal').modal('show');
  95. $("option:selected").prop("selected", false);
  96. }
  97. if ($(this).val() == "totp") {
  98. $('#TOTPModal').modal('show');
  99. request_token = $('#tfa-qr-img').data('totp-secret');
  100. $.ajax({
  101. url: '/inc/ajax/qr_gen.php',
  102. data: {
  103. token: request_token,
  104. },
  105. }).done(function (result) {
  106. $("#tfa-qr-img").attr("src", result);
  107. });
  108. $("option:selected").prop("selected", false);
  109. }
  110. if ($(this).val() == "u2f") {
  111. $('#U2FModal').modal('show');
  112. $("option:selected").prop("selected", false);
  113. $('#u2f_status_reg').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  114. $.ajax({
  115. type: "GET",
  116. cache: false,
  117. dataType: 'script',
  118. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? rawurlencode($_SESSION['mailcow_cc_username']) : null; ?>",
  119. complete: function(data){
  120. data;
  121. setTimeout(function() {
  122. console.log("Ready to register");
  123. $('#u2f_status_reg').html(lang_tfa.waiting_usb_register);
  124. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  125. var form = document.getElementById('u2f_reg_form');
  126. var reg = document.getElementById('u2f_register_data');
  127. console.log("Register callback: ", data);
  128. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  129. var u2f_return_code = document.getElementById('u2f_return_code');
  130. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  131. 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"; }
  132. u2f_return_code.innerHTML = 'Error code: ' + deviceResponse.errorCode;
  133. return;
  134. }
  135. reg.value = JSON.stringify(deviceResponse);
  136. form.submit();
  137. });
  138. }, 1000);
  139. }
  140. });
  141. }
  142. if ($(this).val() == "none") {
  143. $('#DisableTFAModal').modal('show');
  144. $("option:selected").prop("selected", false);
  145. }
  146. });
  147. // Reload after session timeout
  148. var session_lifetime = <?=(intval($SESSION_LIFETIME) * 1000) + 15000;?>;
  149. <?php
  150. if (isset($_SESSION['mailcow_cc_username'])):
  151. ?>
  152. setTimeout(function() {
  153. location.reload();
  154. }, session_lifetime);
  155. <?php
  156. endif;
  157. ?>
  158. // CSRF
  159. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('name', 'csrf_token').appendTo('form');
  160. if (sessionStorage.scrollTop != "undefined") {
  161. $(window).scrollTop(sessionStorage.scrollTop);
  162. }
  163. });
  164. </script>
  165. </body>
  166. </html>
  167. <?php
  168. $stmt = null;
  169. $pdo = null;