Skip to content

Commit 6b5c63e

Browse files
author
Kristan Kenney
committed
Merge branch 'feature/867_addon-domain-support' into staging/features
2 parents eb96289 + 220a800 commit 6b5c63e

File tree

15 files changed

+524
-22
lines changed

15 files changed

+524
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ All notable changes to this project will be documented in this file.
5252
- Improved German translations (thanks **@ronald-at**)
5353
- Improved Russian translations (thanks **@Pleskan**)
5454

55+
5556
## [1.2.0] - Major Release (Feature / Quality Update)
5657
### Features
5758
- **NOTE:** Debian 8 is no longer supported as it has reached EOL (end-of-life) status.

bin/v-add-web-domain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ time=$(echo "$time_n_date" |cut -f 1 -d \ )
169169
date=$(echo "$time_n_date" |cut -f 2 -d \ )
170170

171171
# Adding domain in web.conf
172-
echo "DOMAIN='$domain' IP='$ip' IP6='' ALIAS='$ALIAS' TPL='$WEB_TEMPLATE'\
172+
echo "DOMAIN='$domain' IP='$ip' IP6='' CUSTOM_DOCROOT='' ALIAS='$ALIAS' TPL='$WEB_TEMPLATE'\
173173
SSL='no' SSL_FORCE='no' SSL_HOME='same' LETSENCRYPT='no' FTP_USER='' FTP_MD5=''\
174174
BACKEND='$BACKEND_TEMPLATE' PROXY='$PROXY_TEMPLATE' PROXY_EXT='$PROXY_EXT'\
175175
STATS='' STATS_USER='' STATS_CRYPT='' U_DISK='0' U_BANDWIDTH='0'\

bin/v-add-web-domain-backend

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ check_hestia_demo_mode
4141

4242
# Defining pool directory
4343
prepare_web_backend
44+
get_domain_values 'web'
4445

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

5051
# Allocating backend port
5152
backend_port=9000
@@ -65,6 +66,13 @@ cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
6566
-e "s|%backend%|$backend_type|g"\
6667
-e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
6768

69+
# Set correct document root path
70+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
71+
docroot="$CUSTOM_DOCROOT"
72+
sed -i "s|/home\/$user\/web\/$domain\/public_html|$docroot|g" $pool/$backend_type.conf
73+
else
74+
docroot="$HOMEDIR/$user/web/$domain/public_html/"
75+
fi
6876

6977
#----------------------------------------------------------#
7078
# Hestia #

bin/v-change-web-domain-backend-tpl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ is_object_unsuspended 'user' 'USER' "$user"
3939
is_object_valid 'web' 'DOMAIN' "$domain"
4040
is_object_unsuspended 'web' 'DOMAIN' "$domain"
4141
is_backend_template_valid $template
42+
get_domain_values 'web'
4243

4344
# Perform verification if read-only mode is enabled
4445
check_hestia_demo_mode
@@ -48,11 +49,12 @@ check_hestia_demo_mode
4849
# Action #
4950
#----------------------------------------------------------#
5051

51-
prepare_web_backend
52-
53-
# Deleting backend
52+
# Deleting current backend
5453
delete_web_backend
5554

55+
# Prepare new backend configuration
56+
prepare_web_backend
57+
5658
# Allocating backend port
5759
backend_port=9000
5860
ports=$(grep -v '^;' $pool/* 2>/dev/null |grep listen |grep -o :[0-9].*)
@@ -72,6 +74,12 @@ cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
7274
-e "s|%backend%|$backend_type|g"\
7375
-e "s|%backend_version%|$backend_version|g" > $pool/$backend_type.conf
7476

77+
# Set correct document root path
78+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
79+
docroot="$CUSTOM_DOCROOT"
80+
sed -i "s|/home\/$user\/web\/$domain\/public_html|$docroot|g" $pool/$backend_type.conf
81+
fi
82+
7583
# Checking backend pool configuration
7684
if [ "$backend_type" = "$user" ]; then
7785
conf=$USER_DATA/web.conf

bin/v-change-web-domain-docroot

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
# info: Changes the document root for an existing web domain
3+
4+
# options: USER DOMAIN TARGET_DOMAIN [DIRECTORY]
5+
# example usage:
6+
# add custom docroot: v-change-web-domain-docroot admin domain.tld otherdomain.tld
7+
# points domain.tld to otherdomain.tld's document root.
8+
#
9+
# remove custom docroot: v-change-web-domain-docroot admin test.local default
10+
# returns document root to default value for domain.
11+
12+
# This call changes the document root of a chosen web domain
13+
# to another available domain under the user context.
14+
15+
16+
#----------------------------------------------------------#
17+
# Variable&Function #
18+
#----------------------------------------------------------#
19+
20+
# Argument definition
21+
user=$1
22+
domain=$2
23+
24+
# Export target domain and directory
25+
# so they are correctly passed through to domain.sh
26+
export target_domain=$3
27+
export target_directory=$4
28+
29+
# Includes
30+
source $HESTIA/func/main.sh
31+
source $HESTIA/func/domain.sh
32+
source $HESTIA/conf/hestia.conf
33+
34+
# Additional argument formatting
35+
format_domain
36+
37+
#----------------------------------------------------------#
38+
# Verifications #
39+
#----------------------------------------------------------#
40+
41+
check_args '2' "$#" 'USER DOMAIN TARGET_DOMAIN [DIRECTORY]'
42+
is_system_enabled "$WEB_SYSTEM" 'WEB_SYSTEM'
43+
# Check to ensure that target domain is valid if we're
44+
# not setting the docroot value back to defaults
45+
if [ "$target_domain" != "default" ]; then
46+
is_format_valid 'user' 'domain' 'target_domain'
47+
is_object_valid 'web' 'DOMAIN' "$target_domain"
48+
else
49+
is_format_valid 'user' 'domain'
50+
fi
51+
is_object_valid 'user' 'USER' "$user" "$user"
52+
is_object_unsuspended 'user' 'USER' "$user"
53+
is_object_valid 'web' 'DOMAIN' "$domain"
54+
is_object_unsuspended 'web' 'DOMAIN' "$domain"
55+
is_object_value_empty 'web' 'DOMAIN' "$domain" '$docroot'
56+
is_dir_symlink "$HOMEDIR/$user/web"
57+
is_dir_symlink "$HOMEDIR/$user/web/$target_domain"
58+
59+
# Perform verification if read-only mode is enabled
60+
check_hestia_demo_mode
61+
62+
#----------------------------------------------------------#
63+
# Action #
64+
#----------------------------------------------------------#
65+
66+
# Unset existing custom document root path
67+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
68+
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT' ""
69+
fi
70+
71+
# If target domain value is 'default', remove the custom document root
72+
# value and rebuild web domain to restore default configuration.
73+
# Otherwise, set target document root path accordingly based on passed values.
74+
if [ "$target_domain" = "default" ]; then
75+
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT' ""
76+
else
77+
# Check for existence of specified directory under target domain's public_html folder
78+
if [ ! -z "$target_directory" ]; then
79+
if [ ! -e "$HOMEDIR/$user/web/$target_domain/public_html/$target_directory" ]; then
80+
echo "ERROR: Directory $target_directory does not exist under $HOMEDIR/$user/$target_domain/public_html/."
81+
exit 1
82+
else
83+
CUSTOM_DOCROOT="$HOMEDIR/$user/web/$target_domain/public_html/$target_directory/"
84+
fi
85+
else
86+
CUSTOM_DOCROOT="$HOMEDIR/$user/web/$target_domain/public_html/"
87+
fi
88+
add_object_key 'web' 'DOMAIN' "$domain" 'CUSTOM_DOCROOT' 'IP6'
89+
update_object_value 'web' 'DOMAIN' "$domain" '$CUSTOM_DOCROOT' "$CUSTOM_DOCROOT"
90+
fi
91+
92+
#----------------------------------------------------------#
93+
# Hestia #
94+
#----------------------------------------------------------#
95+
96+
# Rebuild domain configuration
97+
$BIN/v-rebuild-web-domain $user $domain
98+
99+
# Logging
100+
if [ "$target_domain" = "default" ]; then
101+
log_history "set web domain $domain to use default document root."
102+
else
103+
log_history "set web domain $domain to use document root from $target_domain."
104+
fi
105+
106+
log_event "$OK" "$ARGUMENTS"
107+
108+
# Unset variables
109+
unset target_domain
110+
unset target_directory
111+
112+
exit

bin/v-list-web-domain

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ json_list() {
2323
echo ' "'$DOMAIN'": {
2424
"IP": "'$IP'",
2525
"IP6": "'$IP6'",
26+
"DOCUMENT_ROOT": "'$DOCROOT'",
2627
"U_DISK": "'$U_DISK'",
2728
"U_BANDWIDTH": "'$U_BANDWIDTH'",
2829
"TPL": "'$TPL'",
@@ -40,7 +41,7 @@ json_list() {
4041
"BACKEND": "'$BACKEND'",
4142
"PROXY": "'$PROXY'",
4243
"PROXY_EXT": "'$PROXY_EXT'",
43-
"DOCUMENT_ROOT": "'$HOMEDIR/$user/web/$domain/public_html'",
44+
"CUSTOM_DOCROOT": "'$CUSTOM_DOCROOT'",
4445
"SUSPENDED": "'$SUSPENDED'",
4546
"TIME": "'$TIME'",
4647
"DATE": "'$DATE'"
@@ -50,10 +51,10 @@ json_list() {
5051

5152
# SHELL list function
5253
shell_list() {
53-
source $HESTIA/conf/hestia.conf
5454
echo "DOMAIN: $DOMAIN"
5555
echo "ALIAS: ${ALIAS//,/ }"
5656
echo "IP: $IP"
57+
echo "DOCUMENT_ROOT: $DOCROOT"
5758
if [ ! -z "$IP6" ]; then
5859
echo "IP6: $IP6"
5960
fi
@@ -95,18 +96,18 @@ shell_list() {
9596

9697
# PLAIN list function
9798
plain_list() {
98-
echo -ne "$DOMAIN\t$IP\t$IP6\t$U_DISK\t$U_BANDWIDTH\t$TPL\t"
99+
echo -ne "$DOMAIN\t$IP\t$IP6\t$DOCROOT\t$U_DISK\t$U_BANDWIDTH\t$TPL\t"
99100
echo -ne "$ALIAS\t$STATS\t$STATS_USER\t$SSL\t$SSL_FORCE\t$SSL_HSTS\t$SSL_HOME\t,$LETSENCRYPT"
100101
echo -ne "$FTP_USER\t$FTP_PATH\t$AUTH_USER\t$BACKEND\t$PROXY\t"
101102
echo -e "$PROXY_EXT\t$SUSPENDED\t$TIME\t$DATE"
102103
}
103104

104105
# CSV list function
105106
csv_list() {
106-
echo -n "DOMAIN,IP,IP6,U_DISK,U_BANDWIDTH,TPL,ALIAS,STATS,STATS_USER,SSL,"
107+
echo -n "DOMAIN,IP,IP6,DOCROOT,U_DISK,U_BANDWIDTH,TPL,ALIAS,STATS,STATS_USER,SSL,"
107108
echo -n "SSL_FORCE,SSL_HSTS,SSL_HOME,LETSENCRYPT,FTP_USER,FTP_PATH,AUTH_USER,BACKEND,PROXY,PROXY_EXT,"
108109
echo "SUSPENDED,TIME,DATE"
109-
echo -n "$DOMAIN,$IP,$IP6,$U_DISK,$U_BANDWIDTH,$TPL,\"$ALIAS\",$STATS"
110+
echo -n "$DOMAIN,$IP,$IP6,$DOCROOT,$U_DISK,$U_BANDWIDTH,$TPL,\"$ALIAS\",$STATS"
110111
echo -n "\"$STATS_USER\",$SSL,$SSL_FORCE,$SSL_HSTS,$SSL_HOME,$LETSENCRYPT,\"$FTP_USER\",\"$FTP_PATH\","
111112
echo -n "\"$AUTH_USER\",$BACKEND,$PROXY,\"$PROXY_EXT\",$SUSPENDED,$TIME,"
112113
echo "$DATE"
@@ -130,6 +131,12 @@ is_object_valid 'web' 'DOMAIN' "$domain"
130131
# Parsing domain
131132
parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
132133

134+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
135+
DOCROOT="$CUSTOM_DOCROOT"
136+
else
137+
DOCROOT="$HOMEDIR/$user/web/$DOMAIN/public_html/"
138+
fi
139+
133140
# Listing data
134141
case $format in
135142
json) json_list ;;
@@ -138,7 +145,6 @@ case $format in
138145
shell) shell_list ;;
139146
esac
140147

141-
142148
#----------------------------------------------------------#
143149
# Hestia #
144150
#----------------------------------------------------------#

bin/v-list-web-domains

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ json_list() {
2424
echo "{"
2525
while read str; do
2626
parse_object_kv_list "$str"
27+
# Set correct document root path
28+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
29+
DOCROOT="$CUSTOM_DOCROOT"
30+
else
31+
DOCROOT="$HOMEDIR/$user/web/$DOMAIN/public_html/"
32+
fi
2733
echo -n ' "'$DOMAIN'": {
2834
"IP": "'$IP'",
2935
"IP6": "'$IP6'",
36+
"DOCUMENT_ROOT": "'$DOCROOT'",
3037
"U_DISK": "'$U_DISK'",
3138
"U_BANDWIDTH": "'$U_BANDWIDTH'",
3239
"TPL": "'$TPL'",
@@ -72,7 +79,13 @@ plain_list() {
7279
IFS=$'\n'
7380
while read str; do
7481
parse_object_kv_list "$str"
75-
echo -ne "$DOMAIN\t$IP\t$IP6\t$U_DISK\t$U_BANDWIDTH\t$TPL\t"
82+
# Set correct document root path
83+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
84+
DOCROOT="$CUSTOM_DOCROOT"
85+
else
86+
DOCROOT="$HOMEDIR/$user/web/$DOMAIN/public_html/"
87+
fi
88+
echo -ne "$DOMAIN\t$IP\t$IP6\t$DOCROOT\t$U_DISK\t$U_BANDWIDTH\t$TPL\t"
7689
echo -ne "$ALIAS\t$STATS\t$STATS_USER\t$SSL\t$SSL_HOME\t$LETSENCRYPT\t"
7790
echo -ne "$FTP_USER\t$FTP_PATH\t$AUTH_USER\t$BACKEND\t$PROXY\t"
7891
echo -e "$PROXY_EXT\t$SUSPENDED\t$TIME\t$DATE"
@@ -82,12 +95,18 @@ plain_list() {
8295
# CSV list function
8396
csv_list() {
8497
IFS=$'\n'
85-
echo -n "DOMAIN,IP,IP6,U_DISK,U_BANDWIDTH,TPL,ALIAS,STATS,STATS_USER,"
98+
echo -n "DOMAIN,IP,IP6,DOCROOT,U_DISK,U_BANDWIDTH,TPL,ALIAS,STATS,STATS_USER,"
8699
echo -n "SSL,SSL_HOME,LETSENCRYPT,FTP_USER,FTP_PATH,AUTH_USER,BACKEND,PROXY,"
87100
echo "PROXY_EXT,SUSPENDED,TIME,DATE"
88101
while read str; do
89102
parse_object_kv_list "$str"
90-
echo -n "$DOMAIN,$IP,$IP6,$U_DISK,$U_BANDWIDTH,$TPL,"
103+
# Set correct document root path
104+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
105+
DOCROOT="$CUSTOM_DOCROOT"
106+
else
107+
DOCROOT="$HOMEDIR/$user/web/$DOMAIN/public_html/"
108+
fi
109+
echo -n "$DOMAIN,$IP,$IP6,$DOCROOT,$U_DISK,$U_BANDWIDTH,$TPL,"
91110
echo -n "\"$ALIAS\",$STATS,\"$STATS_USER\",$SSL,$SSL_HOME,$LETSENCRYPT,"
92111
echo -n "\"$FTP_USER\",\"$FTP_PATH\",\"$AUTH_USER\",$BACKEND,$PROXY,"
93112
echo "\"$PROXY_EXT\",$SUSPENDED,$TIME,$DATE"
@@ -113,9 +132,11 @@ case $format in
113132
json) json_list ;;
114133
plain) plain_list ;;
115134
csv) csv_list ;;
116-
shell) shell_list |column -t ;;
135+
shell) shell_list ;;
117136
esac
118137

138+
unset docroot
139+
119140

120141
#----------------------------------------------------------#
121142
# Hestia #

func/domain.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ prepare_web_domain_values() {
159159
docroot="$HOMEDIR/$user/web/$domain/public_html"
160160
sdocroot="$docroot"
161161
if [ "$SSL_HOME" = 'single' ]; then
162-
sdocroot="$HOMEDIR/$user/web/$domain/public_shtml" ;
162+
sdocroot="$HOMEDIR/$user/web/$domain/public_shtml"
163163
fi
164164

165165
if [ ! -z "$WEB_BACKEND" ]; then
@@ -179,6 +179,31 @@ prepare_web_domain_values() {
179179
if [ ! -e "$USER_DATA/ssl/$domain.ca" ]; then
180180
ssl_ca_str='#'
181181
fi
182+
183+
# Set correct document root
184+
if [ ! -z "$CUSTOM_DOCROOT" ]; then
185+
# Custom document root has been set by the user, import from configuration
186+
custom_docroot="$CUSTOM_DOCROOT"
187+
docroot="$custom_docroot"
188+
sdocroot="$docroot"
189+
elif [ ! -z "$CUSTOM_DOCROOT" ] && [ ! -z "$target_directory" ]; then
190+
# Custom document root has been specified with a different target than public_html
191+
if [ -d "$HOMEDIR/$user/web/$target_domain/public_html/$target_directory/" ]; then
192+
custom_docroot="$HOMEDIR/$user/web/$target_domain/public_html/$target_directory"
193+
docroot="$custom_docroot"
194+
sdocroot="$docroot"
195+
fi
196+
elif [ ! -z "$CUSTOM_DOCROOT" ] && [ -z "$target_directory" ]; then
197+
# Set custom document root to target domain's public_html folder
198+
custom_docroot="$HOMEDIR/$user/web/$target_domain/public_html"
199+
docroot="$custom_docroot"
200+
sdocroot="$docroot"
201+
else
202+
# No custom document root specified, use default
203+
docroot="$HOMEDIR/$user/web/$domain/public_html"
204+
sdocroot="$docroot"
205+
fi
206+
182207
if [ "$SUSPENDED" = 'yes' ]; then
183208
docroot="$HESTIA/data/templates/web/suspend"
184209
sdocroot="$HESTIA/data/templates/web/suspend"

0 commit comments

Comments
 (0)