Skip to content

Commit 1fb3062

Browse files
authored
* Fix: hestiacp#3438 Do not remove port / Check if redirect ends on / * hestiacp#3439 Remove spaces in domain * Update main.sh Only do leading / trailings spaces
1 parent affe0eb commit 1fb3062

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

bin/v-add-web-domain-redirect

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,36 @@ is_object_unsuspended 'user' 'USER' "$user"
4242
is_object_valid 'web' 'DOMAIN' "$domain"
4343
is_object_unsuspended 'web' 'DOMAIN' "$domain"
4444

45+
requesturi=0
4546
if [[ "$3" =~ http://|https:// ]]; then
4647
scheme_check=1
4748
scheme=$($HESTIA_PHP -r '$url=parse_url($argv[1]); echo $url["scheme"];' "$redirect")
4849
host=$($HESTIA_PHP -r '$url=parse_url($argv[1]); echo $url["host"];' "$redirect")
4950
path=$($HESTIA_PHP -r '$url=parse_url($argv[1]); if(!empty($url["path"])){echo $url["path"];}' "$redirect")
51+
port=$($HESTIA_PHP -r '$url=parse_url($argv[1]); if(!empty($url["port"])){echo $url["port"];}' "$redirect")
52+
5053
host=$(idn2 --quiet "$host")
5154
redirect="$scheme://$host$path"
55+
if [ -n "$port" ]; then
56+
redirect="$scheme://$host:$port$path"
57+
fi
58+
5259
isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "$redirect")
5360
if [ -z "$isValidUrl" ]; then
5461
check_result $E_INVALID "Invalid redirect"
5562
fi
5663
else
5764
host=$($HESTIA_PHP -r '$url=parse_url($argv[1]); echo $url["host"];' "http://$redirect")
5865
path=$($HESTIA_PHP -r '$url=parse_url($argv[1]); if(!empty($url["path"])){echo $url["path"];}' "http://$redirect")
66+
port=$($HESTIA_PHP -r '$url=parse_url($argv[1]); if(!empty($url["port"])){echo $url["port"];}' "$redirect")
67+
5968
host=$(idn2 --quiet "$host")
69+
6070
redirect="$host$path"
71+
if [ -n "$port" ]; then
72+
redirect="$host:$port$path"
73+
fi
74+
6175
isValidUrl=$(php -r '$url=$argv[1]; $url=filter_var($url,FILTER_VALIDATE_URL); echo $url;' "http://$redirect")
6276
if [ -z "$isValidUrl" ]; then
6377
check_result $E_INVALID "Invalid redirect"
@@ -77,16 +91,33 @@ if [ "$WEB_SYSTEM" = 'nginx' ] || [ "$PROXY_SYSTEM" = 'nginx' ]; then
7791
sconf="$HOMEDIR/$user/conf/web/$domain/nginx.ssl.conf_redirect"
7892
fi
7993

94+
# Prevent $request_uri being added if ends in .html
95+
requesturi=0
96+
if [ -n "$path" ]; then
97+
lastchr=${path#${path%?}}
98+
if [ "$lastchr" = "/" ]; then
99+
requesturi=1
100+
fi
101+
fi
102+
80103
# Insert redirect commands
81104
if [ -n "$PROXY_SYSTEM" ] || [ "$WEB_SYSTEM" = 'nginx' ]; then
82105
if [ "$scheme_check" = 1 ]; then
83-
echo " return $code $redirect\$request_uri;" > $conf
106+
if [ "$requesturi" = 1 ]; then
107+
echo " return $code $redirect\$request_uri;" > $conf
108+
else
109+
echo " return $code $redirect;" > $conf
110+
fi
84111
if [ ! -e "$sconf" ]; then
85112
ln -s "$conf" "$sconf"
86113
fi
87114
else
88115
echo "if (\$host != \"$redirect\") {" > $conf
89-
echo " return $code \$scheme://$redirect\$request_uri;" >> $conf
116+
if [ "$requesturi" = 1 ]; then
117+
echo " return $code \$scheme://$redirect\$request_uri;" >> $conf
118+
else
119+
echo " return $code \$scheme://$redirect;" >> $conf
120+
fi
90121
echo "}" >> $conf
91122

92123
if [ ! -e "$sconf" ]; then

func/main.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,8 @@ format_domain() {
13991399
if [[ "$domain" =~ ^\. ]]; then
14001400
domain=$(echo "$domain" | sed -e "s/^[.]*//")
14011401
fi
1402+
# Remove white spaces
1403+
domain=$(echo $domain | sed 's/^[ \t]*//;s/[ \t]*$//')
14021404
}
14031405

14041406
format_domain_idn() {

0 commit comments

Comments
 (0)