edit_web.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. App.Actions.WEB.update_custom_doc_root = function (elm, hint) {
  2. var prepath = $('input[name="v-custom-doc-root_prepath"]').val();
  3. var domain = $('select[name="v-custom-doc-domain"]').val();
  4. var folder = $('input[name="v-custom-doc-folder"]').val();
  5. $('.custom_docroot_hint').html(prepath + domain + '/public_html/' + folder);
  6. };
  7. App.Listeners.DB.keypress_custom_folder = function () {
  8. var ref = $('input[name="v-custom-doc-folder"]');
  9. var current_rec = ref.val();
  10. App.Actions.WEB.update_custom_doc_root(ref, current_rec);
  11. ref.bind('keypress input', function (evt) {
  12. clearTimeout(window.frp_usr_tmt);
  13. window.frp_usr_tmt = setTimeout(function () {
  14. var elm = $(evt.target);
  15. App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
  16. });
  17. });
  18. };
  19. App.Listeners.DB.change_custom_doc = function () {
  20. var ref = $('select[name="v-custom-doc-domain"]');
  21. var current_rec = ref.val();
  22. ref.bind('change select', function (evt) {
  23. clearTimeout(window.frp_usr_tmt);
  24. window.frp_usr_tmt = setTimeout(function () {
  25. var elm = $(evt.target);
  26. App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
  27. });
  28. });
  29. };
  30. // Page entry point
  31. // Trigger listeners
  32. App.Listeners.DB.keypress_custom_folder();
  33. App.Listeners.DB.change_custom_doc();
  34. App.Actions.WEB.update_ftp_username_hint = function (elm, hint) {
  35. if (hint.trim() == '') {
  36. $(elm).parent().find('.hint').html('');
  37. }
  38. hint = hint.replace(/[^\w\d]/gi, '');
  39. $(elm).parent().find('.v-ftp-user').val(hint);
  40. $(elm)
  41. .parent()
  42. .find('.hint')
  43. .text(GLOBAL.FTP_USER_PREFIX + hint);
  44. };
  45. App.Listeners.WEB.keypress_ftp_username = function () {
  46. var ftp_user_inputs = $('.v-ftp-user');
  47. $.each(ftp_user_inputs, function (i, ref) {
  48. var ref = $(ref);
  49. var current_val = ref.val();
  50. if (current_val.trim() != '') {
  51. App.Actions.WEB.update_ftp_username_hint(ref, current_val);
  52. }
  53. ref.bind('keypress input', function (evt) {
  54. clearTimeout(window.frp_usr_tmt);
  55. window.frp_usr_tmt = setTimeout(function () {
  56. var elm = $(evt.target);
  57. App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
  58. }, 100);
  59. });
  60. });
  61. };
  62. //
  63. //
  64. App.Actions.WEB.update_ftp_path_hint = function (elm, hint) {
  65. if (hint.trim() == '') {
  66. $(elm).parent().find('.js-ftp-path-hint').html('');
  67. }
  68. if (hint[0] != '/') {
  69. hint = '/' + hint;
  70. }
  71. hint = hint.replace(/\/(\/+)/g, '/');
  72. $(elm).parent().find('.js-ftp-path-hint').text(hint);
  73. };
  74. App.Listeners.WEB.keypress_ftp_path = function () {
  75. var ftp_path_inputs = $('.js-ftp-path');
  76. $.each(ftp_path_inputs, function (i, ref) {
  77. var ref = $(ref);
  78. var current_val = ref.val();
  79. if (current_val.trim() != '') {
  80. App.Actions.WEB.update_ftp_path_hint(ref, current_val);
  81. }
  82. ref.bind('keypress input', function (evt) {
  83. clearTimeout(window.frp_usr_tmt);
  84. window.frp_usr_tmt = setTimeout(function () {
  85. var elm = $(evt.target);
  86. App.Actions.WEB.update_ftp_path_hint(elm, $(elm).val());
  87. }, 100);
  88. });
  89. });
  90. };
  91. //
  92. //
  93. App.Actions.WEB.add_ftp_user_form = function () {
  94. var ref = $('#templates').find('.js-ftp-account-nrm').clone(true);
  95. var index = $('.form-container .js-ftp-account').length + 1;
  96. ref.find('input').each(function (i, elm) {
  97. var name = $(elm).attr('name');
  98. var id = $(elm).attr('id');
  99. $(elm).attr('name', name.replace('%INDEX%', index));
  100. if (id) {
  101. $(elm).attr('id', id.replace('%INDEX%', index));
  102. }
  103. });
  104. ref
  105. .find('input')
  106. .prev('label')
  107. .each(function (i, elm) {
  108. var for_attr = $(elm).attr('for');
  109. $(elm).attr('for', for_attr.replace('%INDEX%', index));
  110. });
  111. ref.find('.ftp-user-number').text(index);
  112. $('#ftp_users').append(ref);
  113. var index = 1;
  114. $('.form-container .ftp-user-number:visible').each(function (i, o) {
  115. $(o).text(index);
  116. index += 1;
  117. });
  118. };
  119. App.Actions.WEB.remove_ftp_user = function (elm) {
  120. var ref = $(elm).parents('.js-ftp-account');
  121. ref.find('.v-ftp-user-deleted').val('1');
  122. if (ref.find('.v-ftp-user-is-new').val() == 1) {
  123. ref.remove();
  124. return true;
  125. }
  126. ref.removeClass('js-ftp-account-nrm');
  127. ref.hide();
  128. var index = 1;
  129. $('.form-container .ftp-user-number:visible').each(function (i, o) {
  130. $(o).text(index);
  131. index += 1;
  132. });
  133. if ($('.js-ftp-account-nrm:visible').length == 0) {
  134. $('.js-add-new-ftp-user-button').hide();
  135. $('input[name="v_ftp"]').prop('checked', false);
  136. }
  137. };
  138. App.Actions.WEB.toggle_additional_ftp_accounts = function (elm) {
  139. if ($(elm).prop('checked')) {
  140. $('.js-ftp-account-nrm, .v-add-new-user, .js-add-new-ftp-user-button').show();
  141. $('.js-ftp-account-nrm').each(function (i, elm) {
  142. var login = $(elm).find('.v-ftp-user');
  143. if (login.val().trim() != '') {
  144. $(elm).find('.v-ftp-user-deleted').val(0);
  145. }
  146. });
  147. } else {
  148. $('.js-ftp-account-nrm, .v-add-new-user, .js-add-new-ftp-user-button').hide();
  149. $('.js-ftp-account-nrm').each(function (i, elm) {
  150. var login = $(elm).find('.v-ftp-user');
  151. if (login.val().trim() != '') {
  152. $(elm).find('.v-ftp-user-deleted').val(1);
  153. }
  154. });
  155. }
  156. };
  157. App.Actions.WEB.toggle_ssl = function (elm) {
  158. elementHideShow('ssltable');
  159. if (
  160. $('#ssl_crt').val().length > 0 ||
  161. $('#ssl_hsts').prop('checked') ||
  162. $('#letsencrypt').prop('checked')
  163. ) {
  164. return false;
  165. }
  166. $('#v_ssl_forcessl').prop('checked', true);
  167. };
  168. App.Actions.WEB.toggle_letsencrypt = function (elm) {
  169. if ($(elm).prop('checked')) {
  170. $('#ssl-details').hide();
  171. $(
  172. '#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]'
  173. ).attr('disabled', 'disabled');
  174. $('#generate-csr').hide();
  175. if (!$('.lets-encrypt-note').hasClass('enabled')) {
  176. $('.lets-encrypt-note').show();
  177. }
  178. } else {
  179. $(
  180. '#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]'
  181. ).removeAttr('disabled');
  182. $('#generate-csr').show();
  183. $('#ssl-details').show();
  184. $('.lets-encrypt-note').hide();
  185. }
  186. };
  187. App.Actions.WEB.randomPasswordGenerated = function (elm) {
  188. return App.Actions.WEB.passwordChanged(elm);
  189. };
  190. App.Actions.WEB.passwordChanged = function (elm) {
  191. var ref = $(elm).parents('.js-ftp-account');
  192. if (ref.find('.js-email-alert-on-psw').length == 0) {
  193. var inp_name = ref.find('.v-ftp-user-is-new').prop('name');
  194. inp_name = inp_name.replace('is_new', 'v_ftp_email');
  195. ref.find('div:last').after(
  196. '<div class="u-pl30 u-mb10">\
  197. <label for="' +
  198. inp_name +
  199. '" class="form-label">Send FTP credentials to email</label>\
  200. <input type="email" class="form-control js-email-alert-on-psw" value="" name="' +
  201. inp_name +
  202. '" id="' +
  203. inp_name +
  204. '">\
  205. </div>'
  206. );
  207. }
  208. };
  209. //
  210. // Page entry point
  211. App.Listeners.WEB.keypress_ftp_username();
  212. App.Listeners.WEB.keypress_ftp_path();
  213. $(function () {
  214. $('.v-ftp-user-psw').on('keypress', function (evt) {
  215. var elm = $(evt.target);
  216. App.Actions.WEB.passwordChanged(elm);
  217. });
  218. App.Actions.WEB.toggle_letsencrypt($('input[name=v_letsencrypt]'));
  219. $('select[name="v_stats"]').change(function (evt) {
  220. var select = $(evt.target);
  221. if (select.val() == 'none') {
  222. $('.stats-auth').hide();
  223. } else {
  224. $('.stats-auth').show();
  225. }
  226. });
  227. $('select[name="v_nginx_cache"]').change(function (evt) {
  228. var select = $(evt.target);
  229. if (select.val() != 'yes') {
  230. $('#v-clear-cache').hide();
  231. $('#v_nginx_cache_length').hide();
  232. } else {
  233. $('#v-clear-cache').show();
  234. $('#v_nginx_cache_length').show();
  235. }
  236. });
  237. $('select[name="v_proxy_template"]').change(function (evt) {
  238. var select = $(evt.target);
  239. if (select.val() != 'caching') {
  240. const re = new RegExp('caching-');
  241. if (re.test(select.val())) {
  242. $('#v-clear-cache').show();
  243. } else {
  244. $('#v-clear-cache').hide();
  245. }
  246. } else {
  247. $('#v-clear-cache').show();
  248. }
  249. });
  250. $('#vstobjects').on('submit', function (evt) {
  251. $('input[disabled]').each(function (i, elm) {
  252. var copy_elm = $(elm).clone(true);
  253. $(copy_elm).attr('type', 'hidden');
  254. $(copy_elm).removeAttr('disabled');
  255. $(elm).after(copy_elm);
  256. });
  257. });
  258. });
  259. function WEBrandom() {
  260. document.v_edit_web.v_stats_password.value = randomString2(16);
  261. }
  262. function FTPrandom(elm) {
  263. $(elm).parents('.js-ftp-account').find('.v-ftp-user-psw').val(randomString2(16));
  264. App.Actions.WEB.randomPasswordGenerated && App.Actions.WEB.randomPasswordGenerated(elm);
  265. }
  266. function elementHideShow(element) {
  267. if (document.getElementById(element)) {
  268. var el = document.getElementById(element);
  269. el.style.display = el.style.display === 'none' ? 'block' : 'none';
  270. }
  271. }
  272. $('.v-redirect-custom-value').change(function () {
  273. if (this.value == 'custom') {
  274. $('#custom_redirect').show();
  275. } else {
  276. $('#custom_redirect').hide();
  277. }
  278. });