Skip to content

Commit 220a800

Browse files
author
Kristan Kenney
committed
Merge branch 'feature/867_addon-domain-support-ui' into origin/feature/867_addon-domain-support
2 parents 704b21e + cfe6c77 commit 220a800

File tree

9 files changed

+329
-7
lines changed

9 files changed

+329
-7
lines changed

bin/v-add-web-domain-backend

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ prepare_web_backend
4444
get_domain_values 'web'
4545

4646
# Checking backend configuration
47-
if [ -e "$pool/$backend_type.conf" ]; then
48-
exit
49-
fi
47+
#if [ -e "$pool/$backend_type.conf" ]; then
48+
# exit
49+
#fi
5050

5151
# Allocating backend port
5252
backend_port=9000

bin/v-list-web-domain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ json_list() {
4141
"BACKEND": "'$BACKEND'",
4242
"PROXY": "'$PROXY'",
4343
"PROXY_EXT": "'$PROXY_EXT'",
44+
"CUSTOM_DOCROOT": "'$CUSTOM_DOCROOT'",
4445
"SUSPENDED": "'$SUSPENDED'",
4546
"TIME": "'$TIME'",
4647
"DATE": "'$DATE'"

web/add/web/index.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@
9494
$v_stats = escapeshellarg($_POST['v_stats']);
9595
$v_stats_user = $data[$v_domain]['STATS_USER'];
9696
$v_stats_password = $data[$v_domain]['STATS_PASSWORD'];
97+
$v_custom_doc_domain = $_POST['v-custom-doc-domain'];
98+
$v_custom_doc_folder = $_POST['v-custom-doc-folder'];
99+
$v_custom_doc_root_prepath = '/home/'.$user.'/web/';
100+
97101
$v_ftp = $_POST['v_ftp'];
98102
$v_ftp_user = $_POST['v_ftp_user'];
99103
$v_ftp_password = $_POST['v_ftp_password'];
@@ -109,7 +113,8 @@
109113
if ((!empty($_POST['v_ssl_crt'])) || (!empty($_POST['v_ssl_key']))) $v_adv = 'yes';
110114
if ((!empty($_POST['v_ssl_ca'])) || ($_POST['v_stats'] != 'none')) $v_adv = 'yes';
111115
if ((!empty($_POST['v_letsencrypt']))) $v_adv = 'yes';
112-
116+
if (!empty($_POST['v_custom_doc_root_check'])){$v_adv = 'yes'; $v_custom_doc_root = 1; }
117+
113118
// Check advanced features
114119
if (empty($_POST['v_dns'])) $v_dns = 'off';
115120
if (empty($_POST['v_mail'])) $v_mail = 'off';
@@ -227,6 +232,24 @@
227232
unlink($v_stats_password);
228233
$v_stats_password = escapeshellarg($_POST['v_stats_password']);
229234
}
235+
236+
if ( !empty($_POST['v-custom-doc-domain']) && !empty($_POST['v_custom_doc_root_check']) && $v_custom_doc_root_prepath.$v_custom_doc_domain.'/public_html'.$v_custom_doc_folder != $v_custom_doc_root){
237+
if($_POST['v-custom-doc-domain'] == $v_domain && empty($_POST['v-custom-doc-folder'])){
238+
239+
}else{
240+
$v_custom_doc_domain = escapeshellarg($_POST['v-custom-doc-domain']);
241+
$v_custom_doc_folder = escapeshellarg($_POST['v-custom-doc-folder']);
242+
$v_domain = escapeshellarg(trim($_POST['v_domain']));
243+
244+
exec(HESTIA_CMD."v-change-web-domain-docroot ".$user." ".$v_domain." ".$v_custom_doc_domain." ".$v_custom_doc_folder, $output, $return_var);
245+
check_return_code($return_var,$output);
246+
unset($output);
247+
$v_custom_doc_root = 1;
248+
}
249+
}else{
250+
unset($v_custom_doc_root);
251+
}
252+
230253

231254
// Restart DNS server
232255
if (($_POST['v_dns'] == 'on') && (empty($_SESSION['error_msg']))) {
@@ -354,6 +377,7 @@
354377
// Define user variables
355378
$v_ftp_user_prepath = $panel[$user]['HOME'] . "/web";
356379
$v_ftp_email = $panel[$user]['CONTACT'];
380+
$v_custom_doc_root_prepath = '/home/'.$user.'/web/';
357381

358382
// List IP addresses
359383
exec (HESTIA_CMD."v-list-user-ips ".$user." json", $output, $return_var);
@@ -365,6 +389,12 @@
365389
$stats = json_decode(implode('', $output), true);
366390
unset($output);
367391

392+
// Get all user domains
393+
exec (HESTIA_CMD."v-list-web-domains ".escapeshellarg($user)." json", $output, $return_var);
394+
$user_domains = json_decode(implode('', $output), true);
395+
$user_domains = array_keys($user_domains);
396+
unset($output);
397+
368398
// Render page
369399
render_page($user, $TAB, 'add_web');
370400

web/edit/web/index.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,24 @@
7373
$v_stats = $data[$v_domain]['STATS'];
7474
$v_stats_user = $data[$v_domain]['STATS_USER'];
7575
if (!empty($v_stats_user)) $v_stats_password = "";
76+
$v_custom_doc_root_prepath = '/home/'.$v_username.'/web/';
77+
$v_custom_doc_root = $data[$v_domain]['CUSTOM_DOCROOT'];
78+
79+
$m = preg_match('/\/home\/'.$v_username.'\/web\/([A-Za-z0-9.-].*)\/([A-Za-z0-9.-\/].*)/', $v_custom_doc_root, $matches);
80+
$v_custom_doc_domain = $matches[1];
81+
$v_custom_doc_folder = str_replace('public_html/','',$matches[2]);
82+
7683
$v_ftp_user = $data[$v_domain]['FTP_USER'];
7784
$v_ftp_path = $data[$v_domain]['FTP_PATH'];
7885
if (!empty($v_ftp_user)) $v_ftp_password = "";
79-
$v_ftp_user_prepath = $data[$v_domain]['DOCUMENT_ROOT'];
80-
$v_ftp_user_prepath = str_replace('/public_html', '', $v_ftp_user_prepath, $occurance = 1);
86+
87+
if($v_custom_doc_domain != ''){
88+
$v_ftp_user_prepath = '/home/'.$v_username.'/web/'.$v_custom_doc_domain;
89+
}else{
90+
$v_ftp_user_prepath = '/home/'.$v_username.'/web/'.$v_domain;
91+
}
92+
93+
8194
$v_ftp_email = $panel[$user]['CONTACT'];
8295
$v_suspended = $data[$v_domain]['SUSPENDED'];
8396
if ( $v_suspended == 'yes' ) {
@@ -736,6 +749,31 @@
736749
}
737750
}
738751
}
752+
//custom docoot with check box disabled
753+
if( !empty($v_custom_doc_root) && empty($_POST['v_custom_doc_root_check']) ){
754+
exec(HESTIA_CMD."v-change-web-domain-docroot ".$v_username." ".escapeshellarg($v_domain)." default", $output, $return_var);
755+
check_return_code($return_var,$output);
756+
unset($output);
757+
unset($_POST['v-custom-doc-domain'], $_POST['v-custom-doc-folder']);
758+
}
759+
760+
if ( !empty($_POST['v-custom-doc-domain']) && !empty($_POST['v_custom_doc_root_check']) && $v_custom_doc_root_prepath.$v_custom_doc_domain.'/public_html'.$v_custom_doc_folder != $v_custom_doc_root){
761+
if($_POST['v-custom-doc-domain'] == $v_domain && empty($_POST['v-custom-doc-folder'])){
762+
exec(HESTIA_CMD."v-change-web-domain-docroot ".$v_username." ".escapeshellarg($v_domain)." default", $output, $return_var);
763+
check_return_code($return_var,$output);
764+
unset($output);
765+
}else{
766+
$v_custom_doc_domain = escapeshellarg($_POST['v-custom-doc-domain']);
767+
$v_custom_doc_folder = escapeshellarg($_POST['v-custom-doc-folder']);
768+
769+
exec(HESTIA_CMD."v-change-web-domain-docroot ".$v_username." ".escapeshellarg($v_domain)." ".$v_custom_doc_domain." ".$v_custom_doc_folder, $output, $return_var);
770+
check_return_code($return_var,$output);
771+
unset($output);
772+
$v_custom_doc_root = 1;
773+
}
774+
}else{
775+
unset($v_custom_doc_root);
776+
}
739777

740778
// Restart web server
741779
if (!empty($restart_web) && (empty($_SESSION['error_msg']))) {

web/js/pages/add_web.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
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+
console.log(domain, folder);
6+
$('.custom_docroot_hint').html(prepath+domain+'/public_html/'+folder);
7+
}
8+
App.Listeners.DB.keypress_custom_folder = function() {
9+
var ref = $('input[name="v-custom-doc-folder"]');
10+
var current_rec = ref.val();
11+
App.Actions.WEB.update_custom_doc_root(ref, current_rec);
12+
13+
ref.bind('keypress input', function(evt) {
14+
clearTimeout(window.frp_usr_tmt);
15+
window.frp_usr_tmt = setTimeout(function() {
16+
var elm = $(evt.target);
17+
App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
18+
});
19+
});
20+
}
21+
22+
App.Listeners.DB.change_custom_doc = function() {
23+
var ref = $('select[name="v-custom-doc-domain"]');
24+
var current_rec = ref.val();
25+
ref.bind('change select', function(evt) {
26+
clearTimeout(window.frp_usr_tmt);
27+
window.frp_usr_tmt = setTimeout(function() {
28+
var elm = $(evt.target);
29+
App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
30+
var domain = $('.ftp-path-prefix').text(GLOBAL.FTP_USER_PREPATH + '/' + $(evt.target));
31+
32+
});
33+
});
34+
}
35+
36+
// Page entry point
37+
// Trigger listeners
38+
App.Listeners.DB.keypress_custom_folder();
39+
App.Listeners.DB.change_custom_doc();
40+
141
App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
242
if (hint.trim() == '') {
343
$(elm).parent().find('.hint').html('');
@@ -38,6 +78,10 @@ App.Listeners.WEB.keypress_domain_name = function() {
3878
//var elm = $(evt.target);
3979
//App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
4080
var domain = $('.ftp-path-prefix').text(GLOBAL.FTP_USER_PREPATH + '/' + $('#v_domain').val());
81+
$('#v-custom-doc-domain-main').text($('#v_domain').val());
82+
$('#v-custom-doc-domain-main').val($('#v_domain').val());
83+
App.Actions.WEB.update_custom_doc_root(13, 12);
84+
4185
}, 100);
4286
});
4387
}

web/js/pages/edit_web.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
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+
console.log(domain, folder);
6+
$('.custom_docroot_hint').html(prepath+domain+'/public_html/'+folder);
7+
}
8+
App.Listeners.DB.keypress_custom_folder = function() {
9+
var ref = $('input[name="v-custom-doc-folder"]');
10+
var current_rec = ref.val();
11+
App.Actions.WEB.update_custom_doc_root(ref, current_rec);
12+
13+
14+
ref.bind('keypress input', function(evt) {
15+
clearTimeout(window.frp_usr_tmt);
16+
window.frp_usr_tmt = setTimeout(function() {
17+
var elm = $(evt.target);
18+
App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
19+
});
20+
});
21+
}
22+
23+
App.Listeners.DB.change_custom_doc = function() {
24+
var ref = $('select[name="v-custom-doc-domain"]');
25+
var current_rec = ref.val();
26+
ref.bind('change select', function(evt) {
27+
clearTimeout(window.frp_usr_tmt);
28+
window.frp_usr_tmt = setTimeout(function() {
29+
var elm = $(evt.target);
30+
App.Actions.WEB.update_custom_doc_root(elm, $(elm).val());
31+
});
32+
});
33+
}
34+
35+
// Page entry point
36+
// Trigger listeners
37+
App.Listeners.DB.keypress_custom_folder();
38+
App.Listeners.DB.change_custom_doc();
39+
140
App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
241
if (hint.trim() == '') {
342
$(elm).parent().find('.hint').html('');

web/templates/admin/add_web.html

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,63 @@
195195
</table>
196196
</td>
197197
</tr>
198-
198+
<tr>
199+
<td class="vst-text step-top">
200+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_custom_doc_root_check" <?php if (!empty($v_custom_doc_root)) echo "checked=yes" ?> onclick="javascript:elementHideShow('v_custom_doc_root');"> <?php print __('Custom document root');?></label>
201+
</td>
202+
</tr>
203+
<tr>
204+
<td class="step-left">
205+
<table style="display:<?php if (empty($v_custom_doc_root)) { echo 'none';} else {echo 'block';}?> ;" id="v_custom_doc_root">
206+
<tr>
207+
<td class="vst-text input-label">
208+
<?php print __('Point to');?>
209+
</td>
210+
</tr>
211+
<tr>
212+
<td>
213+
<input type="hidden" name="v-custom-doc-root_prepath" value="<?php echo $v_custom_doc_root_prepath;?>">
214+
<select class="vst-list" name="v-custom-doc-domain">
215+
<option value="<?=htmlentities(trim($v_domain, "'"))?>" id="v-custom-doc-domain-main"><?=htmlentities(trim($v_domain, "'"))?></option>
216+
<?php
217+
foreach ($user_domains as $domain) {
218+
if($domain != $v_domain ){
219+
if($v_custom_doc_domain == $domain){
220+
?>
221+
<option value="<?php echo $domain;?>" selected="selected"><?php echo $domain;?></option>
222+
<?php
223+
}else{
224+
?>
225+
<option value="<?php echo $domain;?>"><?php echo $domain;?></option>
226+
<?php
227+
}
228+
}
229+
}
230+
?>
231+
</select>
232+
</td>
233+
</tr>
234+
<tr>
235+
<td class="vst-text input-label">
236+
<?php print( __('Folder'));?> <span class="optional">(<?php print __('optional');?>)</span>
237+
</td>
238+
</tr>
239+
<tr>
240+
<td>
241+
<input type="text" size="20" class="vst-input"
242+
name="v-custom-doc-folder" value="<?=htmlentities(trim($v_custom_doc_folder, "'"))?>">
243+
</td>
244+
</tr>
245+
<tr>
246+
<td>
247+
<small class="custom_docroot_hint"></small>
248+
</td>
249+
</tr>
250+
251+
</table>
252+
</td>
253+
</tr>
254+
199255
<tr>
200256
<td class="step-top vst-text">
201257
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl" <?php if($v_ssl == 'yes' || $v_ssl == 'on') echo "checked=yes" ?> onclick="javascript:elementHideShow('ssltable');"> <?php print __('SSL Support');?></label>

web/templates/admin/edit_web.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,63 @@
243243
</td>
244244
</tr>
245245
<?php } ?>
246+
<tr>
247+
<td class="vst-text step-top">
248+
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_custom_doc_root_check" <?php if (!empty($v_custom_doc_root)) echo "checked=yes" ?> onclick="javascript:elementHideShow('v_custom_doc_root');"> <?php print __('Custom document root');?></label>
249+
</td>
250+
</tr>
251+
<tr>
252+
<td class="step-left">
253+
<table style="display:<?php if (empty($v_custom_doc_root)) { echo 'none';} else {echo 'block';}?> ;" id="v_custom_doc_root">
254+
<tr>
255+
<td class="vst-text input-label">
256+
<?php print __('Point to');?>
257+
</td>
258+
</tr>
259+
<tr>
260+
<td>
261+
<input type="hidden" name="v-custom-doc-root_prepath"" value="<?php echo $v_custom_doc_root_prepath;?>">
262+
<select class="vst-list" name="v-custom-doc-domain">
263+
<option value="<?php echo $v_domain;?>"><?php echo $v_domain;?></option>
264+
<?php
265+
foreach ($user_domains as $domain) {
266+
if($domain != $v_domain ){
267+
if($v_custom_doc_domain == $domain){
268+
?>
269+
<option value="<?php echo $domain;?>" selected="selected"><?php echo $domain;?></option>
270+
<?php
271+
}else{
272+
?>
273+
<option value="<?php echo $domain;?>"><?php echo $domain;?></option>
274+
<?php
275+
}
276+
}
277+
}
278+
?>
279+
</select>
280+
</td>
281+
</tr>
282+
<tr>
283+
<td class="vst-text input-label">
284+
<?php print( __('Folder'));?> <span class="optional">(<?php print __('optional');?>)</span>
285+
</td>
286+
</tr>
287+
<tr>
288+
<td>
289+
<input type="text" size="20" class="vst-input"
290+
name="v-custom-doc-folder" value="<?=htmlentities(trim($v_custom_doc_folder, "'"))?>">
291+
</td>
292+
</tr>
293+
<tr>
294+
<td>
295+
<small class="custom_docroot_hint"></small>
296+
</td>
297+
</tr>
298+
299+
</table>
300+
</td>
301+
</tr>
302+
246303
<tr>
247304
<td class="vst-text step-top">
248305
<label><input type="checkbox" size="20" class="vst-checkbox" name="v_ssl" <?php if ($v_ssl == 'yes') echo "checked=yes" ?> onclick="javascript:elementHideShow('ssltable');"> <?php print __('SSL Support');?></label>

0 commit comments

Comments
 (0)