footer.inc.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php';
  3. logger();
  4. $hash = $js_minifier->getDataHash();
  5. $JSPath = '/tmp/' . $hash . '.js';
  6. if(!file_exists($JSPath)) {
  7. $js_minifier->minify($JSPath);
  8. cleanupJS($hash);
  9. }
  10. ?>
  11. <script src="/cache/<?=basename($JSPath)?>"></script>
  12. <script>
  13. <?php
  14. $lang_footer = json_encode($lang['footer']);
  15. $lang_acl = json_encode($lang['acl']);
  16. $lang_tfa = json_encode($lang['tfa']);
  17. echo "var lang_footer = ". $lang_footer . ";\n";
  18. echo "var lang_acl = ". $lang_acl . ";\n";
  19. echo "var lang_tfa = ". $lang_tfa . ";\n";
  20. echo "var docker_timeout = ". $DOCKER_TIMEOUT * 1000 . ";\n";
  21. ?>
  22. $(window).scroll(function() {
  23. sessionStorage.scrollTop = $(this).scrollTop();
  24. });
  25. // Select language and reopen active URL without POST
  26. function setLang(sel) {
  27. $.post( "<?= $_SERVER['REQUEST_URI']; ?>", {lang: sel} );
  28. window.location.href = window.location.pathname + window.location.search;
  29. }
  30. $(window).load(function() {
  31. $(".overlay").hide();
  32. });
  33. $(document).ready(function() {
  34. $(document).on('shown.bs.modal', function(e) {
  35. modal_id = $(e.relatedTarget).data('target');
  36. $(modal_id).attr("aria-hidden","false");
  37. });
  38. // TFA, CSRF, Alerts in footer.inc.php
  39. // Other general functions in mailcow.js
  40. <?php
  41. $alertbox_log_parser = alertbox_log_parser($_SESSION);
  42. if (is_array($alertbox_log_parser)) {
  43. foreach($alertbox_log_parser as $log) {
  44. ?>
  45. mailcow_alert_box(<?=$log['msg'];?>, <?=$log['type'];?>);
  46. <?php
  47. }
  48. unset($_SESSION['return']);
  49. }
  50. ?>
  51. // Confirm TFA modal
  52. <?php if (isset($_SESSION['pending_tfa_method'])):?>
  53. $('#ConfirmTFAModal').modal({
  54. backdrop: 'static',
  55. keyboard: false
  56. });
  57. $('#u2f_status_auth').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ' + lang_tfa.init_u2f + '</p>');
  58. $('#ConfirmTFAModal').on('shown.bs.modal', function(){
  59. $(this).find('input[name=token]').focus();
  60. // If U2F
  61. if(document.getElementById("u2f_auth_data") !== null) {
  62. $.ajax({
  63. type: "GET",
  64. cache: false,
  65. dataType: 'script',
  66. url: "/api/v1/get/u2f-authentication/<?= (isset($_SESSION['pending_mailcow_cc_username'])) ? rawurlencode($_SESSION['pending_mailcow_cc_username']) : null; ?>",
  67. complete: function(data){
  68. $('#u2f_status_auth').html(lang_tfa.waiting_usb_auth);
  69. data;
  70. setTimeout(function() {
  71. console.log("Ready to authenticate");
  72. u2f.sign(appId, challenge, registeredKeys, function(data) {
  73. var form = document.getElementById('u2f_auth_form');
  74. var auth = document.getElementById('u2f_auth_data');
  75. console.log("Authenticate callback", data);
  76. auth.value = JSON.stringify(data);
  77. form.submit();
  78. });
  79. }, 1000);
  80. }
  81. });
  82. }
  83. });
  84. $('#ConfirmTFAModal').on('hidden.bs.modal', function(){
  85. $.ajax({
  86. type: "GET",
  87. cache: false,
  88. dataType: 'script',
  89. url: '/inc/ajax/destroy_tfa_auth.php',
  90. complete: function(data){
  91. window.location = window.location.href.split("#")[0];
  92. }
  93. });
  94. });
  95. <?php endif; ?>
  96. // Set TFA modals
  97. $('#selectTFA').change(function () {
  98. if ($(this).val() == "yubi_otp") {
  99. $('#YubiOTPModal').modal('show');
  100. $("option:selected").prop("selected", false);
  101. }
  102. if ($(this).val() == "totp") {
  103. $('#TOTPModal').modal('show');
  104. request_token = $('#tfa-qr-img').data('totp-secret');
  105. $.ajax({
  106. url: '/inc/ajax/qr_gen.php',
  107. data: {
  108. token: request_token,
  109. },
  110. }).done(function (result) {
  111. $("#tfa-qr-img").attr("src", result);
  112. });
  113. $("option:selected").prop("selected", false);
  114. }
  115. if ($(this).val() == "u2f") {
  116. $('#U2FModal').modal('show');
  117. $("option:selected").prop("selected", false);
  118. $("#start_u2f_register").click(function(){
  119. $('#u2f_return_code').html('');
  120. $('#u2f_return_code').hide();
  121. $('#u2f_status_reg').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ' + lang_tfa.init_u2f + '</p>');
  122. $.ajax({
  123. type: "GET",
  124. cache: false,
  125. dataType: 'script',
  126. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? rawurlencode($_SESSION['mailcow_cc_username']) : null; ?>",
  127. complete: function(data){
  128. data;
  129. setTimeout(function() {
  130. console.log("Ready to register");
  131. $('#u2f_status_reg').html(lang_tfa.waiting_usb_register);
  132. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  133. var form = document.getElementById('u2f_reg_form');
  134. var reg = document.getElementById('u2f_register_data');
  135. console.log("Register callback: ", data);
  136. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  137. var u2f_return_code = document.getElementById('u2f_return_code');
  138. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  139. if (deviceResponse.errorCode == "4") {
  140. 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";
  141. }
  142. else if (deviceResponse.errorCode == "5") {
  143. deviceResponse.errorCode = "5 - Timeout reached before request could be satisfied.";
  144. }
  145. u2f_return_code.innerHTML = lang_tfa.error_code + ': ' + deviceResponse.errorCode + ' ' + lang_tfa.reload_retry;
  146. return;
  147. }
  148. reg.value = JSON.stringify(deviceResponse);
  149. form.submit();
  150. });
  151. }, 1000);
  152. }
  153. });
  154. });
  155. }
  156. if ($(this).val() == "none") {
  157. $('#DisableTFAModal').modal('show');
  158. $("option:selected").prop("selected", false);
  159. }
  160. });
  161. // Reload after session timeout
  162. var session_lifetime = <?=((int)$SESSION_LIFETIME * 1000) + 15000;?>;
  163. <?php
  164. if (isset($_SESSION['mailcow_cc_username'])):
  165. ?>
  166. setTimeout(function() {
  167. location.reload();
  168. }, session_lifetime);
  169. <?php
  170. endif;
  171. ?>
  172. // CSRF
  173. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('name', 'csrf_token').appendTo('form');
  174. if (sessionStorage.scrollTop != "undefined") {
  175. $(window).scrollTop(sessionStorage.scrollTop);
  176. }
  177. });
  178. </script>
  179. <div class="container footer">
  180. <?php
  181. if (!empty($UI_TEXTS['ui_footer'])):
  182. ?>
  183. <hr><?=$UI_TEXTS['ui_footer'];?>
  184. <?php
  185. endif;
  186. ?>
  187. </div>
  188. </body>
  189. </html>
  190. <?php
  191. $stmt = null;
  192. $pdo = null;