edit_web.js 9.9 KB

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