edit_web.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. App.Actions.WEB.update_custom_doc_root = function () {
  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(Alpine.store('globals').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.randomPasswordGenerated = function (elm) {
  158. return App.Actions.WEB.passwordChanged(elm);
  159. };
  160. App.Actions.WEB.passwordChanged = function (elm) {
  161. var ref = $(elm).parents('.js-ftp-account');
  162. if (ref.find('.js-email-alert-on-psw').length == 0) {
  163. var inp_name = ref.find('.v-ftp-user-is-new').prop('name');
  164. inp_name = inp_name.replace('is_new', 'v_ftp_email');
  165. ref.find('div:last').after(
  166. `<div class="u-pl30 u-mb10">
  167. <label for="${inp_name}" class="form-label">
  168. Send FTP credentials to email
  169. </label>
  170. <input type="email" class="form-control js-email-alert-on-psw"
  171. value="" name="${inp_name}" id="${inp_name}">
  172. </div>`
  173. );
  174. }
  175. };
  176. //
  177. // Page entry point
  178. App.Listeners.WEB.keypress_ftp_username();
  179. App.Listeners.WEB.keypress_ftp_path();
  180. $(function () {
  181. $('.v-ftp-user-psw').on('keypress', function (evt) {
  182. var elm = $(evt.target);
  183. App.Actions.WEB.passwordChanged(elm);
  184. });
  185. $('input[name=v_letsencrypt]').change(function (evt) {
  186. var input = $(evt.target);
  187. if (input.prop('checked')) {
  188. $('#ssl-details').hide();
  189. } else {
  190. $('#ssl-details').show();
  191. }
  192. });
  193. $('select[name="v_stats"]').change(function (evt) {
  194. var select = $(evt.target);
  195. if (select.val() == 'none') {
  196. $('.stats-auth').hide();
  197. } else {
  198. $('.stats-auth').show();
  199. }
  200. });
  201. $('select[name="v_nginx_cache"]').change(function (evt) {
  202. var select = $(evt.target);
  203. if (select.val() != 'yes') {
  204. $('#v-clear-cache').hide();
  205. $('#v_nginx_cache_length').hide();
  206. } else {
  207. $('#v-clear-cache').show();
  208. $('#v_nginx_cache_length').show();
  209. }
  210. });
  211. $('select[name="v_proxy_template"]').change(function (evt) {
  212. var select = $(evt.target);
  213. if (select.val() != 'caching') {
  214. const re = new RegExp('caching-');
  215. if (re.test(select.val())) {
  216. $('#v-clear-cache').show();
  217. } else {
  218. $('#v-clear-cache').hide();
  219. }
  220. } else {
  221. $('#v-clear-cache').show();
  222. }
  223. });
  224. document.getElementById('vstobjects').addEventListener('submit', function () {
  225. $('input[disabled]').each(function (i, elm) {
  226. var copy_elm = $(elm).clone(true);
  227. $(copy_elm).attr('type', 'hidden');
  228. $(copy_elm).removeAttr('disabled');
  229. $(elm).after(copy_elm);
  230. });
  231. });
  232. });
  233. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  234. function WEBrandom() {
  235. document.v_edit_web.v_stats_password.value = randomString(16);
  236. }
  237. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  238. function FTPrandom(elm) {
  239. $(elm).parents('.js-ftp-account').find('.v-ftp-user-psw').val(randomString(16));
  240. App.Actions.WEB.randomPasswordGenerated && App.Actions.WEB.randomPasswordGenerated(elm);
  241. }
  242. $('.v-redirect-custom-value').change(function () {
  243. if (this.value == 'custom') {
  244. $('#custom_redirect').show();
  245. } else {
  246. $('#custom_redirect').hide();
  247. }
  248. });