footer.inc.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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> ' + lang_tfa.init_u2f + '</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. $("#start_u2f_register").click(function(){
  114. $('#u2f_return_code').html('');
  115. $('#u2f_return_code').hide();
  116. $('#u2f_status_reg').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ' + lang_tfa.init_u2f + '</p>');
  117. $.ajax({
  118. type: "GET",
  119. cache: false,
  120. dataType: 'script',
  121. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? rawurlencode($_SESSION['mailcow_cc_username']) : null; ?>",
  122. complete: function(data){
  123. data;
  124. setTimeout(function() {
  125. console.log("Ready to register");
  126. $('#u2f_status_reg').html(lang_tfa.waiting_usb_register);
  127. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  128. var form = document.getElementById('u2f_reg_form');
  129. var reg = document.getElementById('u2f_register_data');
  130. console.log("Register callback: ", data);
  131. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  132. var u2f_return_code = document.getElementById('u2f_return_code');
  133. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  134. if (deviceResponse.errorCode == "4") {
  135. 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";
  136. }
  137. else if (deviceResponse.errorCode == "5") {
  138. deviceResponse.errorCode = "5 - Timeout reached before request could be satisfied.";
  139. }
  140. u2f_return_code.innerHTML = lang_tfa.error_code + ': ' + deviceResponse.errorCode + ' ' + lang_tfa.reload_retry;
  141. return;
  142. }
  143. reg.value = JSON.stringify(deviceResponse);
  144. form.submit();
  145. });
  146. }, 1000);
  147. }
  148. });
  149. });
  150. }
  151. if ($(this).val() == "none") {
  152. $('#DisableTFAModal').modal('show');
  153. $("option:selected").prop("selected", false);
  154. }
  155. });
  156. // Reload after session timeout
  157. var session_lifetime = <?=(intval($SESSION_LIFETIME) * 1000) + 15000;?>;
  158. <?php
  159. if (isset($_SESSION['mailcow_cc_username'])):
  160. ?>
  161. setTimeout(function() {
  162. location.reload();
  163. }, session_lifetime);
  164. <?php
  165. endif;
  166. ?>
  167. // CSRF
  168. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('name', 'csrf_token').appendTo('form');
  169. if (sessionStorage.scrollTop != "undefined") {
  170. $(window).scrollTop(sessionStorage.scrollTop);
  171. }
  172. });
  173. </script>
  174. <?php
  175. if (!empty($UI_TEXTS['ui_impress'])):
  176. ?>
  177. <div class="container" style="margin-bottom:20px;color:#959595;">
  178. <hr>
  179. <?=$UI_TEXTS['ui_impress'];?>
  180. </div>
  181. <?php
  182. endif;
  183. ?>
  184. </body>
  185. </html>
  186. <?php
  187. $stmt = null;
  188. $pdo = null;