footer.inc.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. require_once $_SERVER['DOCUMENT_ROOT'] . '/modals/footer.php';
  3. ?>
  4. <div style="margin-bottom: 100px;"></div>
  5. <script src="/js/bootstrap.min.js"></script>
  6. <script src="/js/bootstrap-switch.min.js"></script>
  7. <script src="/js/bootstrap-slider.min.js"></script>
  8. <script src="/js/bootstrap-select.min.js"></script>
  9. <script src="/js/bootstrap-filestyle.min.js"></script>
  10. <script src="/js/notifications.min.js"></script>
  11. <script src="/js/numberedtextarea.min.js"></script>
  12. <script src="/js/u2f-api.js"></script>
  13. <script src="/js/api.js"></script>
  14. <script>
  15. $(window).scroll(function() {
  16. sessionStorage.scrollTop = $(this).scrollTop();
  17. });
  18. // Select language and reopen active URL without POST
  19. function setLang(sel) {
  20. $.post( "<?= $_SERVER['REQUEST_URI']; ?>", {lang: sel} );
  21. window.location.href = window.location.pathname + window.location.search;
  22. }
  23. $(document).ready(function() {
  24. window.mailcow_alert_box = function(message, type) {
  25. msg = $('<span/>').html(message).text();
  26. if (type == 'danger') {
  27. auto_hide = 0;
  28. } else {
  29. auto_hide = 5000;
  30. }
  31. $.notify({message: msg},{z_index: 20000, delay: auto_hide, type: type,placement: {from: "bottom",align: "right"},animate: {enter: 'animated fadeInUp',exit: 'animated fadeOutDown'}});
  32. }
  33. <?php if (isset($_SESSION['return'])): ?>
  34. mailcow_alert_box(<?=json_encode($_SESSION['return']['msg']); ?>, "<?= $_SESSION['return']['type']; ?>");
  35. <?php endif; unset($_SESSION['return']); ?>
  36. // Confirm TFA modal
  37. <?php if (isset($_SESSION['pending_tfa_method'])):?>
  38. $('#ConfirmTFAModal').modal({
  39. backdrop: 'static',
  40. keyboard: false
  41. });
  42. $('#u2f_status_auth').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  43. $('#ConfirmTFAModal').on('shown.bs.modal', function(){
  44. $(this).find('#token').focus();
  45. // If U2F
  46. if(document.getElementById("u2f_auth_data") !== null) {
  47. $.ajax({
  48. type: "GET",
  49. cache: false,
  50. dataType: 'script',
  51. url: "/api/v1/get/u2f-authentication/<?= (isset($_SESSION['pending_mailcow_cc_username'])) ? $_SESSION['pending_mailcow_cc_username'] : null; ?>",
  52. complete: function(data){
  53. $('#u2f_status_auth').html('<?=$lang['tfa']['waiting_usb_auth'];?>');
  54. data;
  55. setTimeout(function() {
  56. console.log("Ready to authenticate");
  57. u2f.sign(appId, challenge, registeredKeys, function(data) {
  58. var form = document.getElementById('u2f_auth_form');
  59. var auth = document.getElementById('u2f_auth_data');
  60. console.log("Authenticate callback", data);
  61. auth.value = JSON.stringify(data);
  62. form.submit();
  63. });
  64. }, 1000);
  65. }
  66. });
  67. }
  68. });
  69. <?php endif; ?>
  70. // Set TFA modals
  71. $('#selectTFA').change(function () {
  72. if ($(this).val() == "yubi_otp") {
  73. $('#YubiOTPModal').modal('show');
  74. $("option:selected").prop("selected", false);
  75. }
  76. if ($(this).val() == "totp") {
  77. $('#TOTPModal').modal('show');
  78. $("option:selected").prop("selected", false);
  79. }
  80. if ($(this).val() == "u2f") {
  81. $('#U2FModal').modal('show');
  82. $("option:selected").prop("selected", false);
  83. $('#u2f_status_reg').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  84. $.ajax({
  85. type: "GET",
  86. cache: false,
  87. dataType: 'script',
  88. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? $_SESSION['mailcow_cc_username'] : null; ?>",
  89. complete: function(data){
  90. data;
  91. setTimeout(function() {
  92. console.log("Ready to register");
  93. $('#u2f_status_reg').html('<?=$lang['tfa']['waiting_usb_register'];?>');
  94. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  95. var form = document.getElementById('u2f_reg_form');
  96. var reg = document.getElementById('u2f_register_data');
  97. console.log("Register callback: ", data);
  98. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  99. var u2f_return_code = document.getElementById('u2f_return_code');
  100. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  101. 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"; }
  102. u2f_return_code.innerHTML = 'Error code: ' + deviceResponse.errorCode;
  103. return;
  104. }
  105. reg.value = JSON.stringify(deviceResponse);
  106. form.submit();
  107. });
  108. }, 1000);
  109. }
  110. });
  111. }
  112. if ($(this).val() == "none") {
  113. $('#DisableTFAModal').modal('show');
  114. $("option:selected").prop("selected", false);
  115. }
  116. });
  117. // Activate tooltips
  118. $(function () {
  119. $('[data-toggle="tooltip"]').tooltip()
  120. })
  121. // Hide alerts after n seconds
  122. $("#alert-fade").fadeTo(7000, 500).slideUp(500, function(){
  123. $("#alert-fade").alert('close');
  124. });
  125. // Remember last navigation pill
  126. (function () {
  127. 'use strict';
  128. if ($('a[data-toggle="tab"]').length) {
  129. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  130. var id = $(this).parents('[role="tablist"]').attr('id');
  131. var key = 'lastTag';
  132. if (id) {
  133. key += ':' + id;
  134. }
  135. localStorage.setItem(key, $(e.target).attr('href'));
  136. });
  137. $('[role="tablist"]').each(function (idx, elem) {
  138. var id = $(elem).attr('id');
  139. var key = 'lastTag';
  140. if (id) {
  141. key += ':' + id;
  142. }
  143. var lastTab = localStorage.getItem(key);
  144. if (lastTab) {
  145. $('[href="' + lastTab + '"]').tab('show');
  146. }
  147. });
  148. }
  149. })();
  150. // Disable submit after submitting form
  151. $('form').submit(function() {
  152. if ($('form button[type="submit"]').data('submitted') == '1') {
  153. return false;
  154. } else {
  155. $(this).find('button[type="submit"]').first().text('<?= $lang['footer']['loading']; ?>');
  156. $('form button[type="submit"]').attr('data-submitted', '1');
  157. function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
  158. $(document).on("keydown", disableF5);
  159. }
  160. });
  161. // IE fix to hide scrollbars when table body is empty
  162. $('tbody').filter(function (index) {
  163. return $(this).children().length < 1;
  164. }).remove();
  165. // Init Bootstrap Selectpicker
  166. $('select').selectpicker();
  167. // Trigger SOGo restart
  168. $('#triggerRestartSogo').click(function(){
  169. $(this).prop("disabled",true);
  170. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  171. $('#statusTriggerRestartSogo').text('Stopping SOGo workers, this may take a while... ');
  172. $.ajax({
  173. method: 'get',
  174. url: '/inc/ajax/sogo_ctrl.php',
  175. data: {
  176. 'ajax': true,
  177. 'ACTION': 'stop'
  178. },
  179. success: function(data) {
  180. $('#statusTriggerRestartSogo').append(data);
  181. $('#statusTriggerRestartSogo').append('<br>Starting SOGo...');
  182. $.ajax({
  183. method: 'get',
  184. url: '/inc/ajax/sogo_ctrl.php',
  185. data: {
  186. 'ajax': true,
  187. 'ACTION': 'start'
  188. },
  189. success: function(data) {
  190. $('#statusTriggerRestartSogo').append(data);
  191. $('#triggerRestartSogo').html('<span class="glyphicon glyphicon-ok"></span> ');
  192. }
  193. });
  194. }
  195. });
  196. });
  197. // CSRF
  198. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('id', 'csrf_token').attr('name', 'csrf_token').appendTo('form');
  199. if (sessionStorage.scrollTop != "undefined") {
  200. $(window).scrollTop(sessionStorage.scrollTop);
  201. }
  202. });
  203. </script>
  204. </body>
  205. </html>
  206. <?php
  207. $stmt = null;
  208. $pdo = null;