footer.inc.php 9.1 KB

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