footer.inc.php 9.0 KB

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