Skip to content

Commit 53ce337

Browse files
authored
Merge pull request hestiacp#1234 from hestiacp/fix/2020-09_custom_docroot_php_scripts_one_level_up
Issue with custom docroot php scripts one level up
2 parents 038df0d + 45885b0 commit 53ce337

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

bin/v-add-web-domain-backend

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,13 @@ cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
6666
-e "s|%backend%|$backend_type|g"\
6767
-e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
6868

69+
6970
# Set correct document root path
7071
if [ ! -z "$CUSTOM_DOCROOT" ]; then
7172
docroot="$CUSTOM_DOCROOT"
73+
if [ ! -z "$CUSTOM_PHPROOT" ]; then
74+
docroot="$CUSTOM_PHPROOT"
75+
fi
7276
sed -i "s|/home\/$user\/web\/$domain\/public_html|$docroot|g" $pool/$backend_type.conf
7377
else
7478
docroot="$HOMEDIR/$user/web/$domain/public_html/"

bin/v-change-web-domain-docroot

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# info: Changes the document root for an existing web domain
33

4-
# options: USER DOMAIN TARGET_DOMAIN [DIRECTORY]
4+
# options: USER DOMAIN TARGET_DOMAIN [DIRECTORY] [PHP]
55
# example usage:
66
# add custom docroot: v-change-web-domain-docroot admin domain.tld otherdomain.tld
77
# points domain.tld to otherdomain.tld's document root.
@@ -25,6 +25,7 @@ domain=$2
2525
# so they are correctly passed through to domain.sh
2626
export target_domain=$3
2727
export target_directory=$4
28+
export php=$5
2829

2930
# Includes
3031
source $HESTIA/func/main.sh
@@ -66,13 +67,15 @@ check_hestia_demo_mode
6667
# Unset existing custom document root path
6768
if [ ! -z "$CUSTOM_DOCROOT" ]; then
6869
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT' ""
70+
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_PHPROOT' ""
6971
fi
7072

7173
# If target domain value is 'default', remove the custom document root
7274
# value and rebuild web domain to restore default configuration.
7375
# Otherwise, set target document root path accordingly based on passed values.
7476
if [ "$target_domain" = "default" ]; then
7577
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT' ""
78+
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_PHPROOT' ""
7679
else
7780
# Check for existence of specified directory under target domain's public_html folder
7881
if [ ! -z "$target_directory" ]; then
@@ -81,12 +84,24 @@ else
8184
exit 1
8285
else
8386
CUSTOM_DOCROOT="$HOMEDIR/$user/web/$target_domain/public_html/$target_directory/"
87+
if [ ! -z "$php" ]; then
88+
custom_phproot="$HOMEDIR/$user/web/$target_domain/public_html/"
89+
else
90+
custom_phproot="$HOMEDIR/$user/web/$target_domain/public_html/$target_directory/"
91+
fi
8492
fi
8593
else
8694
CUSTOM_DOCROOT="$HOMEDIR/$user/web/$target_domain/public_html/"
95+
custom_phproot="$HOMEDIR/$user/web/$target_domain/public_html/"
8796
fi
97+
8898
add_object_key 'web' 'DOMAIN' "$domain" 'CUSTOM_DOCROOT' 'IP6'
99+
add_object_key 'web' 'DOMAIN' "$domain" 'CUSTOM_PHPROOT' 'IP6'
100+
89101
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT' "$CUSTOM_DOCROOT"
102+
# CUSTOM_PHPROOT got overwriten by default
103+
CUSTOM_PHPROOT=$custom_phproot
104+
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_PHPROOT' "$CUSTOM_PHPROOT"
90105
fi
91106

92107
#----------------------------------------------------------#

web/add/web/index.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,15 @@
238238

239239
}else{
240240
$v_custom_doc_domain = escapeshellarg($_POST['v-custom-doc-domain']);
241+
if(substr($_POST['v-custom-doc-folder'], -1) == '/'){
242+
$v_custom_doc_folder = escapeshellarg(substr($_POST['v-custom-doc-folder'],0,-1));
243+
}else{
244+
$v_custom_doc_folder = escapeshellarg($_POST['v-custom-doc-folder']);
245+
}
241246
$v_custom_doc_folder = escapeshellarg($_POST['v-custom-doc-folder']);
242247
$v_domain = escapeshellarg(trim($_POST['v_domain']));
243248

244-
exec(HESTIA_CMD."v-change-web-domain-docroot ".$user." ".$v_domain." ".$v_custom_doc_domain." ".$v_custom_doc_folder, $output, $return_var);
249+
exec(HESTIA_CMD."v-change-web-domain-docroot ".$user." ".$v_domain." ".$v_custom_doc_domain." ".$v_custom_doc_folder." yes", $output, $return_var);
245250
check_return_code($return_var,$output);
246251
unset($output);
247252
$v_custom_doc_root = 1;

web/edit/web/index.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@
7676
$v_custom_doc_root_prepath = '/home/'.$v_username.'/web/';
7777
$v_custom_doc_root = $data[$v_domain]['CUSTOM_DOCROOT'];
7878

79-
$m = preg_match('/\/home\/'.$v_username.'\/web\/([A-Za-z0-9.-].*)\/([A-Za-z0-9.-\/].*)/', $v_custom_doc_root, $matches);
79+
$m = preg_match('/\/home\/'.$v_username.'\/web\/([[:alnum:]].*)\/public_html\/([[:alnum:]].*)/', $v_custom_doc_root, $matches);
8080
$v_custom_doc_domain = $matches[1];
81-
$v_custom_doc_folder = str_replace('public_html/','',$matches[2]);
81+
$v_custom_doc_folder = $matches[2];
82+
if(substr($v_custom_doc_folder, -1) == '/'){
83+
$v_custom_doc_folder = substr($v_custom_doc_folder,0,-1);
84+
}
85+
8286

8387
$v_ftp_user = $data[$v_domain]['FTP_USER'];
8488
$v_ftp_path = $data[$v_domain]['FTP_PATH'];
@@ -763,10 +767,14 @@
763767
check_return_code($return_var,$output);
764768
unset($output);
765769
}else{
770+
if(substr($_POST['v-custom-doc-folder'], -1) == '/'){
771+
$v_custom_doc_folder = escapeshellarg(substr($_POST['v-custom-doc-folder'],0,-1));
772+
}else{
773+
$v_custom_doc_folder = escapeshellarg($_POST['v-custom-doc-folder']);
774+
}
766775
$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);
776+
777+
exec(HESTIA_CMD."v-change-web-domain-docroot ".$v_username." ".escapeshellarg($v_domain)." ".$v_custom_doc_domain." ".$v_custom_doc_folder ." yes", $output, $return_var);
770778
check_return_code($return_var,$output);
771779
unset($output);
772780
$v_custom_doc_root = 1;

0 commit comments

Comments
 (0)