footer.inc.php 6.9 KB

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