footer.inc.php 6.8 KB

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