footer.inc.php 6.9 KB

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