footer.inc.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. $('#ConfirmTFAModal').on('shown.bs.modal', function(){
  43. $(this).find('#token').focus();
  44. // If U2F
  45. if(document.getElementById("u2f_auth_data") !== null) {
  46. $.ajax({
  47. type: "GET",
  48. cache: false,
  49. dataType: 'script',
  50. url: "/api/v1/get/u2f-authentication/<?= (isset($_SESSION['pending_mailcow_cc_username'])) ? $_SESSION['pending_mailcow_cc_username'] : null; ?>",
  51. success: function(data){
  52. data;
  53. }
  54. });
  55. setTimeout(function() {
  56. console.log("sign: ", req);
  57. u2f.sign(req, 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. <?php endif; ?>
  68. // Set TFA modals
  69. $('#selectTFA').change(function () {
  70. if ($(this).val() == "yubi_otp") {
  71. $('#YubiOTPModal').modal('show');
  72. $("option:selected").prop("selected", false);
  73. }
  74. if ($(this).val() == "totp") {
  75. $('#TOTPModal').modal('show');
  76. $("option:selected").prop("selected", false);
  77. }
  78. if ($(this).val() == "u2f") {
  79. $('#U2FModal').modal('show');
  80. $("option:selected").prop("selected", false);
  81. $.ajax({
  82. type: "GET",
  83. cache: false,
  84. dataType: 'script',
  85. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? $_SESSION['mailcow_cc_username'] : null; ?>",
  86. success: function(data){
  87. data;
  88. }
  89. });
  90. setTimeout(function() {
  91. console.log("Register: ", req);
  92. u2f.register([req], sigs, function(data) {
  93. var form = document.getElementById('u2f_reg_form');
  94. var reg = document.getElementById('u2f_register_data');
  95. console.log("Register callback", data);
  96. if (data.errorCode && data.errorCode != 0) {
  97. var u2f_return_code = document.getElementById('u2f_return_code');
  98. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  99. 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"; }
  100. u2f_return_code.innerHTML = 'Error code: ' + data.errorCode;
  101. return;
  102. }
  103. reg.value = JSON.stringify(data);
  104. form.submit();
  105. });
  106. }, 1000);
  107. }
  108. if ($(this).val() == "none") {
  109. $('#DisableTFAModal').modal('show');
  110. $("option:selected").prop("selected", false);
  111. }
  112. });
  113. // Activate tooltips
  114. $(function () {
  115. $('[data-toggle="tooltip"]').tooltip()
  116. })
  117. // Hide alerts after n seconds
  118. $("#alert-fade").fadeTo(7000, 500).slideUp(500, function(){
  119. $("#alert-fade").alert('close');
  120. });
  121. // Remember last navigation pill
  122. (function () {
  123. 'use strict';
  124. if ($('a[data-toggle="tab"]').length) {
  125. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  126. var id = $(this).parents('[role="tablist"]').attr('id');
  127. var key = 'lastTag';
  128. if (id) {
  129. key += ':' + id;
  130. }
  131. localStorage.setItem(key, $(e.target).attr('href'));
  132. });
  133. $('[role="tablist"]').each(function (idx, elem) {
  134. var id = $(elem).attr('id');
  135. var key = 'lastTag';
  136. if (id) {
  137. key += ':' + id;
  138. }
  139. var lastTab = localStorage.getItem(key);
  140. if (lastTab) {
  141. $('[href="' + lastTab + '"]').tab('show');
  142. }
  143. });
  144. }
  145. })();
  146. // Disable submit after submitting form
  147. $('form').submit(function() {
  148. if ($('form button[type="submit"]').data('submitted') == '1') {
  149. return false;
  150. } else {
  151. $(this).find('button[type="submit"]').first().text('<?= $lang['footer']['loading']; ?>');
  152. $('form button[type="submit"]').attr('data-submitted', '1');
  153. function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
  154. $(document).on("keydown", disableF5);
  155. }
  156. });
  157. // IE fix to hide scrollbars when table body is empty
  158. $('tbody').filter(function (index) {
  159. return $(this).children().length < 1;
  160. }).remove();
  161. // Init Bootstrap Selectpicker
  162. $('select').selectpicker();
  163. // Trigger SOGo restart
  164. $('#triggerRestartSogo').click(function(){
  165. $(this).prop("disabled",true);
  166. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  167. $('#statusTriggerRestartSogo').text('Stopping SOGo workers, this may take a while... ');
  168. $.ajax({
  169. method: 'get',
  170. url: '/inc/ajax/sogo_ctrl.php',
  171. data: {
  172. 'ajax': true,
  173. 'ACTION': 'stop'
  174. },
  175. success: function(data) {
  176. $('#statusTriggerRestartSogo').append(data);
  177. $('#statusTriggerRestartSogo').append('<br>Starting SOGo...');
  178. $.ajax({
  179. method: 'get',
  180. url: '/inc/ajax/sogo_ctrl.php',
  181. data: {
  182. 'ajax': true,
  183. 'ACTION': 'start'
  184. },
  185. success: function(data) {
  186. $('#statusTriggerRestartSogo').append(data);
  187. $('#triggerRestartSogo').html('<span class="glyphicon glyphicon-ok"></span> ');
  188. }
  189. });
  190. }
  191. });
  192. });
  193. // CSRF
  194. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('id', 'csrf_token').attr('name', 'csrf_token').appendTo('form');
  195. if (sessionStorage.scrollTop != "undefined") {
  196. $(window).scrollTop(sessionStorage.scrollTop);
  197. }
  198. });
  199. </script>
  200. </body>
  201. </html>
  202. <?php
  203. $stmt = null;
  204. $pdo = null;