Skip to content

Commit f131010

Browse files
committed
Improve Alias exists detection hestiacp#2024
REDIRECT='domain.com' could trigger alias exists error
1 parent eb85b2c commit f131010

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

func/domain.sh

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,43 @@ is_web_domain_new() {
4949

5050
# Web alias existence check
5151
is_web_alias_new() {
52-
web_alias=$(grep -wH "$1" $HESTIA/data/users/*/web.conf)
53-
if [ ! -z "$web_alias" ]; then
54-
a1=$(echo "$web_alias" |grep -F "'$1'" |cut -f 7 -d /)
55-
if [ ! -z "$a1" ] && [ "$2" == "web" ]; then
56-
check_result $E_EXISTS "Web alias $1 exists"
57-
fi
58-
if [ ! -z "$a1" ] && [ "$a1" != "$user" ]; then
59-
check_result $E_EXISTS "Web alias $1 exists"
60-
fi
61-
a2=$(echo "$web_alias" |grep -F "'$1," |cut -f 7 -d /)
62-
if [ ! -z "$a2" ] && [ "$2" == "web" ]; then
63-
check_result $E_EXISTS "Web alias $1 exists"
64-
fi
65-
if [ ! -z "$a2" ] && [ "$a2" != "$user" ]; then
66-
check_result $E_EXISTS "Web alias $1 exists"
67-
fi
68-
a3=$(echo "$web_alias" |grep -F ",$1," |cut -f 7 -d /)
69-
if [ ! -z "$a3" ] && [ "$2" == "web" ]; then
70-
check_result $E_EXISTS "Web alias $1 exists"
71-
fi
72-
if [ ! -z "$a3" ] && [ "$a3" != "$user" ]; then
73-
check_result $E_EXISTS "Web alias $1 exists"
74-
fi
75-
a4=$(echo "$web_alias" |grep -F ",$1'" |cut -f 7 -d /)
76-
if [ ! -z "$a4" ] && [ "$2" == "web" ]; then
77-
check_result $E_EXISTS "Web alias $1 exists"
78-
fi
79-
if [ ! -z "$a4" ] && [ "$a4" != "$user" ]; then
80-
check_result $E_EXISTS "Web alias $1 exists"
52+
grep -wH "$1" $HESTIA/data/users/*/web.conf | while read -r line ; do
53+
user=$(echo $line |cut -f 7 -d /)
54+
string=$(echo $line |cut -f 2- -d ':')
55+
parse_object_kv_list $string
56+
if [ ! -z "$ALIAS" ]; then
57+
a1=$(echo "'$ALIAS'" |grep -F "'$1'");
58+
if [ ! -z "$a1" ] && [ "$2" == "web" ]; then
59+
return $E_EXISTS
60+
fi
61+
if [ ! -z "$a1" ] && [ "$user" != "$user" ]; then
62+
return $E_EXISTS
63+
fi
64+
a2=$(echo "'$ALIAS'" |grep -F "'$1,")
65+
if [ ! -z "$a2" ] && [ "$2" == "web" ]; then
66+
return $E_EXISTS
67+
fi
68+
if [ ! -z "$a2" ] && [ "$user" != "$user" ]; then
69+
return $E_EXISTS
70+
fi
71+
a3=$(echo "'$ALIAS'" |grep -F ",$1," )
72+
if [ ! -z "$a3" ] && [ "$2" == "web" ]; then
73+
return $E_EXISTS
74+
fi
75+
if [ ! -z "$a3" ] && [ "$user" != "$user" ]; then
76+
return $E_EXISTS
77+
fi
78+
a4=$(echo "'$ALIAS'" |grep -F ",$1'")
79+
if [ ! -z "$a4" ] && [ "$2" == "web" ]; then
80+
return $E_EXISTS
81+
fi
82+
if [ ! -z "$a4" ] && [ "$user" != "$user" ]; then
83+
return $E_EXISTS
84+
fi
8185
fi
86+
done
87+
if [ $? -ne 0 ]; then
88+
check_result $E_EXISTS "Web alias $1 exists"
8289
fi
8390
}
8491

0 commit comments

Comments
 (0)