footer.inc.php 8.5 KB

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