footer.inc.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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'])) ? rawurlencode($_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. $('#ConfirmTFAModal').on('hidden.bs.modal', function(){
  83. $.ajax({
  84. type: "GET",
  85. cache: false,
  86. dataType: 'script',
  87. url: '/inc/ajax/destroy_tfa_auth.php',
  88. complete: function(data){
  89. window.location = window.location.href.split("#")[0];
  90. }
  91. });
  92. });
  93. <?php endif; ?>
  94. // Set TFA modals
  95. $('#selectTFA').change(function () {
  96. if ($(this).val() == "yubi_otp") {
  97. $('#YubiOTPModal').modal('show');
  98. $("option:selected").prop("selected", false);
  99. }
  100. if ($(this).val() == "totp") {
  101. $('#TOTPModal').modal('show');
  102. $("option:selected").prop("selected", false);
  103. }
  104. if ($(this).val() == "u2f") {
  105. $('#U2FModal').modal('show');
  106. $("option:selected").prop("selected", false);
  107. $('#u2f_status_reg').html('<p><span class="glyphicon glyphicon-refresh glyphicon-spin"></span> Initializing, please wait...</p>');
  108. $.ajax({
  109. type: "GET",
  110. cache: false,
  111. dataType: 'script',
  112. url: "/api/v1/get/u2f-registration/<?= (isset($_SESSION['mailcow_cc_username'])) ? rawurlencode($_SESSION['mailcow_cc_username']) : null; ?>",
  113. complete: function(data){
  114. data;
  115. setTimeout(function() {
  116. console.log("Ready to register");
  117. $('#u2f_status_reg').html('<?=$lang['tfa']['waiting_usb_register'];?>');
  118. u2f.register(appId, registerRequests, registeredKeys, function(deviceResponse) {
  119. var form = document.getElementById('u2f_reg_form');
  120. var reg = document.getElementById('u2f_register_data');
  121. console.log("Register callback: ", data);
  122. if (deviceResponse.errorCode && deviceResponse.errorCode != 0) {
  123. var u2f_return_code = document.getElementById('u2f_return_code');
  124. u2f_return_code.style.display = u2f_return_code.style.display === 'none' ? '' : null;
  125. 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"; }
  126. u2f_return_code.innerHTML = 'Error code: ' + deviceResponse.errorCode;
  127. return;
  128. }
  129. reg.value = JSON.stringify(deviceResponse);
  130. form.submit();
  131. });
  132. }, 1000);
  133. }
  134. });
  135. }
  136. if ($(this).val() == "none") {
  137. $('#DisableTFAModal').modal('show');
  138. $("option:selected").prop("selected", false);
  139. }
  140. });
  141. $(function () {
  142. $('[data-toggle="tooltip"]').tooltip()
  143. });
  144. // Remember last navigation pill
  145. (function () {
  146. 'use strict';
  147. if ($('a[data-toggle="tab"]').length) {
  148. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  149. var id = $(this).parents('[role="tablist"]').attr('id');
  150. var key = 'lastTag';
  151. if (id) {
  152. key += ':' + id;
  153. }
  154. localStorage.setItem(key, $(e.target).attr('href'));
  155. });
  156. $('[role="tablist"]').each(function (idx, elem) {
  157. var id = $(elem).attr('id');
  158. var key = 'lastTag';
  159. if (id) {
  160. key += ':' + id;
  161. }
  162. var lastTab = localStorage.getItem(key);
  163. if (lastTab) {
  164. $('[href="' + lastTab + '"]').tab('show');
  165. }
  166. });
  167. }
  168. })();
  169. // Disable submit after submitting form (not API driven buttons)
  170. $('form').submit(function() {
  171. if ($('form button[type="submit"]').data('submitted') == '1') {
  172. return false;
  173. } else {
  174. $(this).find('button[type="submit"]').first().text('<?= $lang['footer']['loading']; ?>');
  175. $('form button[type="submit"]').attr('data-submitted', '1');
  176. function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
  177. $(document).on("keydown", disableF5);
  178. }
  179. });
  180. // IE fix to hide scrollbars when table body is empty
  181. $('tbody').filter(function (index) {
  182. return $(this).children().length < 1;
  183. }).remove();
  184. // Init Bootstrap Selectpicker
  185. $('select').selectpicker();
  186. // Trigger container restart
  187. $('#RestartContainer').on('show.bs.modal', function(e) {
  188. var container = $(e.relatedTarget).data('container');
  189. $('#containerName').text(container);
  190. $('#triggerRestartContainer').click(function(){
  191. $(this).prop("disabled",true);
  192. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  193. $('#statusTriggerRestartContainer').text('Restarting container, this may take a while... ');
  194. $('#statusTriggerRestartContainer2').text('Reloading webpage... ');
  195. $.ajax({
  196. method: 'get',
  197. url: '/inc/ajax/container_ctrl.php',
  198. timeout: 10000,
  199. data: {
  200. 'service': container,
  201. 'action': 'restart'
  202. },
  203. error: function() {
  204. window.location = window.location.href.split("#")[0];
  205. },
  206. success: function(data) {
  207. $('#statusTriggerRestartContainer').append(data);
  208. $('#triggerRestartContainer').html('<span class="glyphicon glyphicon-ok"></span> ');
  209. $('#statusTriggerRestartContainer2').append(data);
  210. $('#triggerRestartContainer').html('<span class="glyphicon glyphicon-ok"></span> ');
  211. window.location = window.location.href.split("#")[0];
  212. }
  213. });
  214. });
  215. })
  216. // CSRF
  217. $('<input type="hidden" value="<?= $_SESSION['CSRF']['TOKEN']; ?>">').attr('id', 'csrf_token').attr('name', 'csrf_token').appendTo('form');
  218. if (sessionStorage.scrollTop != "undefined") {
  219. $(window).scrollTop(sessionStorage.scrollTop);
  220. }
  221. });
  222. </script>
  223. </body>
  224. </html>
  225. <?php
  226. $stmt = null;
  227. $pdo = null;