footer.inc.php 9.1 KB

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