footer.inc.php 7.1 KB

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