014-mailcow.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. $(document).ready(function() {
  2. // mailcow alert box generator
  3. window.mailcow_alert_box = function(message, type) {
  4. msg = $('<span/>').text(message).text();
  5. if (type == 'danger' || type == 'info') {
  6. auto_hide = 0;
  7. $('#' + localStorage.getItem("add_modal")).modal('show');
  8. localStorage.removeItem("add_modal");
  9. } else {
  10. auto_hide = 5000;
  11. }
  12. $.notify({message: msg},{z_index: 20000, delay: auto_hide, type: type,placement: {from: "bottom",align: "right"},animate: {enter: 'animated fadeInUp',exit: 'animated fadeOutDown'}});
  13. }
  14. $(".generate_password").click(function( event ) {
  15. event.preventDefault();
  16. $('[data-hibp]').trigger('input');
  17. if (typeof($(this).closest("form").data('pwgen-length')) == "number") {
  18. var random_passwd = GPW.pronounceable($(this).closest("form").data('pwgen-length'))
  19. }
  20. else {
  21. var random_passwd = GPW.pronounceable(8)
  22. }
  23. $(this).closest("form").find('[data-pwgen-field]').attr('type', 'text');
  24. $(this).closest("form").find('[data-pwgen-field]').val(random_passwd);
  25. });
  26. // https://stackoverflow.com/questions/4399005/implementing-jquerys-shake-effect-with-animate
  27. function shake(div,interval,distance,times) {
  28. if(typeof interval === 'undefined') {
  29. interval = 100;
  30. }
  31. if(typeof distance === 'undefined') {
  32. distance = 10;
  33. }
  34. if(typeof times === 'undefined') {
  35. times = 4;
  36. }
  37. $(div).css('position','relative');
  38. for(var iter=0;iter<(times+1);iter++){
  39. $(div).animate({ left: ((iter%2==0 ? distance : distance*-1))}, interval);
  40. }
  41. $(div).animate({ left: 0},interval);
  42. }
  43. // form cache
  44. $('[data-cached-form="true"]').formcache({key: $(this).data('id')});
  45. // tooltips
  46. $(function () {
  47. $('[data-toggle="tooltip"]').tooltip()
  48. });
  49. // remember last navigation pill
  50. (function () {
  51. 'use strict';
  52. if ($('a[data-toggle="tab"]').length) {
  53. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  54. if ($(this).data('dont-remember') == 1) {
  55. return true;
  56. }
  57. var id = $(this).parents('[role="tablist"]').attr('id');
  58. var key = 'lastTag';
  59. if (id) {
  60. key += ':' + id;
  61. }
  62. localStorage.setItem(key, $(e.target).attr('href'));
  63. });
  64. $('[role="tablist"]').each(function (idx, elem) {
  65. var id = $(elem).attr('id');
  66. var key = 'lastTag';
  67. if (id) {
  68. key += ':' + id;
  69. }
  70. var lastTab = localStorage.getItem(key);
  71. if (lastTab) {
  72. $('[href="' + lastTab + '"]').tab('show');
  73. }
  74. });
  75. }
  76. })();
  77. // IE fix to hide scrollbars when table body is empty
  78. $('tbody').filter(function (index) {
  79. return $(this).children().length < 1;
  80. }).remove();
  81. // selectpicker
  82. $('select').selectpicker();
  83. // haveibeenpwned?
  84. $('[data-hibp]').after('<p class="small haveibeenpwned">↪ Check against haveibeenpwned.com</p><span class="hibp-out"></span>');
  85. $('[data-hibp]').on('input', function() {
  86. out_field = $(this).next('.haveibeenpwned').next('.hibp-out').text('').attr('class', 'hibp-out');
  87. });
  88. $('.haveibeenpwned:not(.task-running)').on('click', function() {
  89. var hibp_field = $(this)
  90. $(hibp_field).addClass('task-running');
  91. var hibp_result = $(hibp_field).next('.hibp-out')
  92. var password_field = $(this).prev('[data-hibp]')
  93. if ($(password_field).val() == '') {
  94. shake(password_field);
  95. }
  96. else {
  97. $(hibp_result).attr('class', 'hibp-out label label-info');
  98. $(hibp_result).text(lang_footer.loading);
  99. var password_digest = $.sha1($(password_field).val())
  100. var digest_five = password_digest.substring(0, 5).toUpperCase();
  101. var queryURL = "https://api.pwnedpasswords.com/range/" + digest_five;
  102. var compl_digest = password_digest.substring(5, 41).toUpperCase();
  103. $.ajax({
  104. url: queryURL,
  105. type: 'GET',
  106. success: function(res) {
  107. if (res.search(compl_digest) > -1){
  108. $(hibp_result).removeClass('label label-info').addClass('label label-danger');
  109. $(hibp_result).text(lang_footer.hibp_nok)
  110. } else {
  111. $(hibp_result).removeClass('label label-info').addClass('label label-success');
  112. $(hibp_result).text(lang_footer.hibp_ok)
  113. }
  114. $(hibp_field).removeClass('task-running');
  115. },
  116. error: function(xhr, status, error) {
  117. $(hibp_result).removeClass('label label-info').addClass('label label-warning');
  118. $(hibp_result).text('API error: ' + xhr.responseText)
  119. $(hibp_field).removeClass('task-running');
  120. }
  121. });
  122. }
  123. });
  124. // Disable disallowed inputs
  125. $('[data-acl="0"]').each(function(event){
  126. if ($(this).is("a")) {
  127. $(this).removeAttr("data-toggle");
  128. $(this).removeAttr("data-target");
  129. $(this).removeAttr("data-action");
  130. $(this).click(function(event) {
  131. event.preventDefault();
  132. });
  133. }
  134. if ($(this).hasClass('btn-group')) {
  135. $(this).find('a').each(function(){
  136. $(this).removeClass('dropdown-toggle')
  137. .removeAttr('data-toggle')
  138. .removeAttr('data-target')
  139. .removeAttr('data-action')
  140. .removeAttr('id')
  141. .attr("disabled", true);
  142. $(this).click(function(event) {
  143. event.preventDefault();
  144. return;
  145. });
  146. });
  147. $(this).find('button').each(function() {
  148. $(this).attr("disabled", true);
  149. });
  150. } else if ($(this).hasClass('input-group')) {
  151. $(this).find('input').each(function() {
  152. $(this).removeClass('dropdown-toggle')
  153. .removeAttr('data-toggle')
  154. .attr("disabled", true);
  155. $(this).click(function(event) {
  156. event.preventDefault();
  157. });
  158. });
  159. $(this).find('button').each(function() {
  160. $(this).attr("disabled", true);
  161. });
  162. } else if ($(this).hasClass('form-group')) {
  163. $(this).find('input').each(function() {
  164. $(this).attr("disabled", true);
  165. });
  166. } else if ($(this).hasClass('btn')) {
  167. $(this).attr("disabled", true);
  168. } else if ($(this).attr('data-provide') == 'slider') {
  169. $(this).slider("disable");
  170. }
  171. $(this).data("toggle", "tooltip");
  172. $(this).attr("title", lang_acl.prohibited);
  173. $(this).tooltip();
  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. // Textarea line numbers
  187. $(".textarea-code").numberedtextarea({allowTabChar: true});
  188. // trigger container restart
  189. $('#RestartContainer').on('show.bs.modal', function(e) {
  190. var container = $(e.relatedTarget).data('container');
  191. $('#containerName').text(container);
  192. $('#triggerRestartContainer').click(function(){
  193. $(this).prop("disabled",true);
  194. $(this).html('<span class="glyphicon glyphicon-refresh glyphicon-spin"></span> ');
  195. $('#statusTriggerRestartContainer').html(lang_footer.restarting_container);
  196. $.ajax({
  197. method: 'get',
  198. url: '/inc/ajax/container_ctrl.php',
  199. timeout: docker_timeout,
  200. data: {
  201. 'service': container,
  202. 'action': 'restart'
  203. }
  204. })
  205. .always( function (data, status) {
  206. $('#statusTriggerRestartContainer').append(data);
  207. var htmlResponse = $.parseHTML(data)
  208. if ($(htmlResponse).find('span').hasClass('text-success')) {
  209. $('#triggerRestartContainer').html('<span class="glyphicon glyphicon-ok"></span> ');
  210. setTimeout(function(){
  211. $('#RestartContainer').modal('toggle');
  212. window.location = window.location.href.split("#")[0];
  213. }, 1200);
  214. } else {
  215. $('#triggerRestartContainer').html('<span class="glyphicon glyphicon-remove"></span> ');
  216. }
  217. })
  218. });
  219. })
  220. });