footer.inc.php 8.2 KB

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