footer.inc.php 9.0 KB

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