footer.inc.php 6.9 KB

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