edit_web.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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').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. $('.data-col2 .ftptable:last').after(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"]').attr('checked', false);
  122. }
  123. }
  124. App.Actions.WEB.toggle_additional_ftp_accounts = function(elm) {
  125. if ($(elm).attr('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).attr('checked')) {
  153. $('#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]').attr('disabled', 'disabled');
  154. $('#generate-csr').hide();
  155. if(!$('.lets-encrypt-note').hasClass('enabled')){
  156. $('.lets-encrypt-note').show();
  157. }
  158. }
  159. else {
  160. $('#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]').removeAttr('disabled');
  161. $('#generate-csr').show();
  162. $('.lets-encrypt-note').hide();
  163. }
  164. }
  165. App.Actions.WEB.randomPasswordGenerated = function(elm) {
  166. return App.Actions.WEB.passwordChanged(elm);
  167. }
  168. App.Actions.WEB.passwordChanged = function(elm) {
  169. var ref = $(elm).parents('.ftptable');
  170. if (ref.find('.vst-email-alert-on-psw').length == 0) {
  171. var inp_name = ref.find('.v-ftp-user-is-new').prop('name');
  172. inp_name = inp_name.replace('is_new', 'v_ftp_email');
  173. ref.find('tr:last').after('<tr>\
  174. <td class="vst-text step-left input-label">\
  175. Send FTP credentials to email\
  176. </td>\
  177. </tr>\
  178. <tr>\
  179. <td class="step-left">\
  180. <input type="text" value="" name="' + inp_name + '" class="vst-input vst-email-alert-on-psw">\
  181. </td>\
  182. </tr>');
  183. }
  184. }
  185. //
  186. // Page entry point
  187. App.Listeners.WEB.keypress_ftp_username();
  188. App.Listeners.WEB.keypress_ftp_path();
  189. $(function() {
  190. $('.v-ftp-user-psw').on('keypress', function (evt) {
  191. var elm = $(evt.target);
  192. App.Actions.WEB.passwordChanged(elm);
  193. });
  194. App.Actions.WEB.toggle_letsencrypt($('input[name=v_letsencrypt]'));
  195. $('select[name="v_stats"]').change(function(evt){
  196. var select = $(evt.target);
  197. if(select.val() == 'none'){
  198. $('.stats-auth').hide();
  199. } else {
  200. $('.stats-auth').show();
  201. }
  202. });
  203. $('select[name="v_nginx_cache"]').change(function(evt){
  204. var select = $(evt.target);
  205. if(select.val() != 'yes'){
  206. $('#v-clear-cache').hide();
  207. } else {
  208. $('#v-clear-cache').show();
  209. }
  210. });
  211. $('select[name="v_proxy_template"]').change(function(evt){
  212. var select = $(evt.target);
  213. if(select.val() != 'caching'){
  214. $('#v-clear-cache').hide();
  215. } else {
  216. $('#v-clear-cache').show();
  217. }
  218. });
  219. $('#vstobjects').on('submit', function(evt) {
  220. $('input[disabled]').each(function(i, elm) {
  221. var copy_elm = $(elm).clone(true);
  222. $(copy_elm).attr('type', 'hidden');
  223. $(copy_elm).removeAttr('disabled');
  224. $(elm).after(copy_elm);
  225. });
  226. });
  227. });
  228. function WEBrandom() {
  229. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  230. var string_length = 16;
  231. var webrandom = '';
  232. for (var i = 0; i < string_length; i++) {
  233. var rnum = Math.floor(Math.random() * chars.length);
  234. webrandom += chars.substr(rnum, 1);
  235. }
  236. document.v_edit_web.v_stats_password.value = webrandom;
  237. }
  238. function FTPrandom(elm) {
  239. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  240. var string_length = 16;
  241. var ftprandomstring = '';
  242. for (var i = 0; i < string_length; i++) {
  243. var rnum = Math.floor(Math.random() * chars.length);
  244. ftprandomstring += chars.substr(rnum, 1);
  245. }
  246. $(elm).parents('.ftptable').find('.v-ftp-user-psw').val(ftprandomstring);
  247. App.Actions.WEB.randomPasswordGenerated && App.Actions.WEB.randomPasswordGenerated(elm);
  248. }
  249. function elementHideShow(elementToHideOrShow){
  250. var el = document.getElementById(elementToHideOrShow);
  251. el.style.display = el.style.display === 'none' ? 'block' : 'none';
  252. }
  253. $('.v-redirect-custom-value').change( function(){
  254. if(this.value == "custom"){
  255. $('#custom_redirect').show();
  256. }else{
  257. $('#custom_redirect').hide();
  258. }
  259. })