forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_web.js
More file actions
222 lines (188 loc) · 6.93 KB
/
add_web.js
File metadata and controls
222 lines (188 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
if (hint.trim() == '') {
$(elm).parent().find('.hint').html('');
}
if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
}
hint = hint.replace(/[^\w\d]/gi, '');
$(elm).parent().find('.v-ftp-user').val(hint);
$(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint);
}
App.Listeners.WEB.keypress_ftp_username = function() {
var ftp_user_inputs = $('.v-ftp-user');
$.each(ftp_user_inputs, function(i, ref) {
var ref = $(ref);
var current_val = ref.val();
if (current_val.trim() != '') {
App.Actions.WEB.update_ftp_username_hint(ref, current_val);
}
ref.bind('keypress input', function(evt) {
clearTimeout(window.frp_usr_tmt);
window.frp_usr_tmt = setTimeout(function() {
var elm = $(evt.target);
App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
}, 100);
});
});
}
App.Listeners.WEB.keypress_domain_name = function() {
$('#v_domain').bind('keypress input', function(evt) {
clearTimeout(window.frp_usr_tmt);
window.frp_usr_tmt = setTimeout(function() {
//var elm = $(evt.target);
//App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
var domain = $('.ftp-path-prefix').text(GLOBAL.FTP_USER_PREPATH + '/' + $('#v_domain').val());
}, 100);
});
}
//
//
App.Actions.WEB.update_ftp_path_hint = function(elm, hint) {
if (hint.trim() == '') {
$(elm).parent().find('.v-ftp-path-hint').html('');
}
if (hint[0] != '/') {
hint = '/' + hint;
}
hint = hint.replace(/\/(\/+)/g, '/');
$(elm).parent().find('.v-ftp-path-hint').text(hint);
}
App.Listeners.WEB.keypress_ftp_path = function() {
var ftp_path_inputs = $('.v-ftp-path');
$.each(ftp_path_inputs, function(i, ref) {
var ref = $(ref);
var current_val = ref.val();
if (current_val.trim() != '') {
App.Actions.WEB.update_ftp_path_hint(ref, current_val);
}
ref.bind('keypress input', function(evt) {
clearTimeout(window.frp_usr_tmt);
window.frp_usr_tmt = setTimeout(function() {
var elm = $(evt.target);
App.Actions.WEB.update_ftp_path_hint(elm, $(elm).val());
}, 100);
});
});
}
//
//
App.Actions.WEB.add_ftp_user_form = function() {
var ref = $('#templates').find('.ftptable').clone(true);
var index = $('.data-col2 .ftptable').length + 1;
ref.find('input').each(function(i, elm) {
var attr_value = $(elm).prop('name').replace('%INDEX%', index);
$(elm).prop('name', attr_value);
});
ref.find('.ftp-user-number').text(index);
$('.data-col2 .ftptable:last').after(ref);
var index = 1;
$('.data-col2 .ftp-user-number:visible').each(function(i, o) {
$(o).text(index);
index += 1;
});
}
App.Actions.WEB.remove_ftp_user = function(elm) {
var ref = $(elm).parents('.ftptable');
ref.remove();
var index = 1;
$('.data-col2 .ftp-user-number:visible').each(function(i, o) {
$(o).text(index);
index += 1;
});
if ($('.ftptable-nrm:visible').length == 0) {
$('.v-add-new-user').hide();
$('input[name="v_ftp"]').attr('checked', false);
}
}
App.Actions.WEB.toggle_additional_ftp_accounts = function(elm) {
if ($(elm).attr('checked')) {
$('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').show();
$('.ftptable-nrm').each(function(i, elm) {
var login = $(elm).find('.v-ftp-user');
if (login.val().trim() != '') {
$(elm).find('.v-ftp-user-deleted').val(0);
}
});
}
else {
$('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').hide();
$('.ftptable-nrm').each(function(i, elm) {
var login = $(elm).find('.v-ftp-user');
if (login.val().trim() != '') {
$(elm).find('.v-ftp-user-deleted').val(1);
}
});
}
if ($('.ftptable-nrm:visible').length == 0) {
var ref = $('#templates').find('.ftptable').clone(true);
var index = $('.data-col2 .ftptable').length + 1;
ref.find('input').each(function(i, elm) {
var attr_value = $(elm).prop('name').replace('%INDEX%', index);
$(elm).prop('name', attr_value);
});
ref.find('.ftp-user-number').text(index);
$('.v-add-new-user').parent('tr').prev().find('td').html(ref);
}
}
App.Actions.WEB.toggle_letsencrypt = function(elm) {
if ($(elm).attr('checked')) {
$('#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]').attr('disabled', 'disabled');
$('#generate-csr').hide();
$('.lets-encrypt-note').show();
}
else {
$('#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]').removeAttr('disabled');
$('#generate-csr').show();
$('.lets-encrypt-note').hide();
}
}
//
// Page entry point
App.Listeners.WEB.keypress_ftp_username();
App.Listeners.WEB.keypress_ftp_path();
App.Listeners.WEB.keypress_domain_name();
$(function() {
$('#v_domain').change(function() {
var prefix = 'www.';
if (((document.getElementById('v_domain').value).split(".")).length > 2) {
document.getElementById('v_aliases').value = "";
} else {
document.getElementById('v_aliases').value = prefix + document.getElementById('v_domain').value;
}
});
App.Actions.WEB.toggle_letsencrypt($('input[name=v_letsencrypt]'))
$('select[name="v_stats"]').change(function(evt){
var select = $(evt.target);
if(select.val() == 'none'){
$('.stats-auth').hide();
} else {
$('.stats-auth').show();
}
});
});
function WEBrandom() {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
var string_length = 16;
var webrandom = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
webrandom += chars.substr(rnum, 1);
}
document.v_add_web.v_stats_password.value = webrandom;
}
function FTPrandom(elm) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
var string_length = 16;
var ftprandomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
ftprandomstring += chars.substr(rnum, 1);
}
$(elm).parents('.ftptable').find('.v-ftp-user-psw').val(ftprandomstring);
}
$('#vstobjects').on('submit', function(evt) {
$('input[disabled]').each(function(i, elm) {
$(elm).removeAttr('disabled');
});
});