Просмотр исходного кода

Merge pull request #2033 from hestiacp/fix/2029-idn-problems

Fix multiple bugs with IDN domains and Aliases
Raphael Schneeberger 4 лет назад
Родитель
Сommit
f5c3000867
4 измененных файлов с 87 добавлено и 31 удалено
  1. 36 29
      func/domain.sh
  2. 4 0
      install/hst-install-debian.sh
  3. 4 0
      install/hst-install-ubuntu.sh
  4. 43 2
      test/test.bats

+ 36 - 29
func/domain.sh

@@ -49,36 +49,43 @@ is_web_domain_new() {
 
 # Web alias existence check
 is_web_alias_new() {
-    web_alias=$(grep -wH "$1" $HESTIA/data/users/*/web.conf)
-    if [ ! -z "$web_alias" ]; then
-        a1=$(echo "$web_alias" |grep -F "'$1'" |cut -f 7 -d /)
-        if [ ! -z "$a1" ] && [ "$2" == "web"  ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
-        fi
-        if [ ! -z "$a1" ] && [ "$a1" != "$user" ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
-        fi
-        a2=$(echo "$web_alias" |grep -F "'$1," |cut -f 7 -d /)
-        if [ ! -z "$a2" ] && [ "$2" == "web"  ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
-        fi
-        if [ ! -z "$a2" ] && [ "$a2" != "$user" ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
-        fi
-        a3=$(echo "$web_alias" |grep -F ",$1," |cut -f 7 -d /)
-        if [ ! -z "$a3" ] && [ "$2" == "web"  ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
-        fi
-        if [ ! -z "$a3" ] && [ "$a3" != "$user" ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
-        fi
-        a4=$(echo "$web_alias" |grep -F ",$1'" |cut -f 7 -d /)
-        if [ ! -z "$a4" ] && [ "$2" == "web"  ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
-        fi
-        if [ ! -z "$a4" ] && [ "$a4" != "$user" ]; then
-            check_result $E_EXISTS "Web alias $1 exists"
+    grep -wH "$1" $HESTIA/data/users/*/web.conf | while read -r line ; do
+        user=$(echo $line |cut -f 7 -d /)
+        string=$(echo $line |cut -f 2- -d ':')
+        parse_object_kv_list  $string
+        if [ ! -z "$ALIAS" ]; then
+            a1=$(echo "'$ALIAS'" |grep -F "'$1'");
+            if [ ! -z "$a1" ] && [ "$2" == "web"  ]; then
+                return $E_EXISTS 
+            fi
+            if [ ! -z "$a1" ] && [ "$user" != "$user" ]; then
+                return $E_EXISTS 
+            fi
+            a2=$(echo "'$ALIAS'" |grep -F "'$1,")
+            if [ ! -z "$a2" ] && [ "$2" == "web"  ]; then
+                return $E_EXISTS
+            fi
+            if [ ! -z "$a2" ] && [ "$user" != "$user" ]; then
+                return $E_EXISTS
+            fi
+            a3=$(echo "'$ALIAS'" |grep -F ",$1," )
+            if [ ! -z "$a3" ] && [ "$2" == "web"  ]; then
+               return $E_EXISTS
+            fi
+            if [ ! -z "$a3" ] && [ "$user" != "$user" ]; then
+                return $E_EXISTS
+            fi
+            a4=$(echo "'$ALIAS'" |grep -F ",$1'")
+            if [ ! -z "$a4" ] && [ "$2" == "web"  ]; then
+                return $E_EXISTS
+            fi
+            if [ ! -z "$a4" ] && [ "$user" != "$user" ]; then
+                return $E_EXISTS
+            fi
         fi
+    done
+    if [ $? -ne 0 ]; then
+        check_result $E_EXISTS "Web alias $1 exists"
     fi
 }
 

+ 4 - 0
install/hst-install-debian.sh

@@ -285,6 +285,9 @@ fi
 if [ "$iptables" = 'no' ]; then
     fail2ban='no'
 fi
+if [ "$apache" = "no" ]; then
+    phpfpm='yes'
+fi
 
 # Checking root permissions
 if [ "x$(id -u)" != 'x0' ]; then
@@ -1232,6 +1235,7 @@ $HESTIA/bin/v-change-user-role admin admin
 $HESTIA/bin/v-change-user-language admin $lang
 $HESTIA/bin/v-change-sys-config-value 'POLICY_SYSTEM_PROTECTED_ADMIN' 'yes'
 
+locale-gen "en_US.utf8" > /dev/null 2>&1
 #----------------------------------------------------------#
 #                     Configure Nginx                      #
 #----------------------------------------------------------#

+ 4 - 0
install/hst-install-ubuntu.sh

@@ -266,6 +266,9 @@ fi
 if [ "$iptables" = 'no' ]; then
     fail2ban='no'
 fi
+if [ "$apache" = "no" ]; then
+    phpfpm='yes'
+fi
 
 # Checking root permissions
 if [ "x$(id -u)" != 'x0' ]; then
@@ -1271,6 +1274,7 @@ $HESTIA/bin/v-change-user-role admin admin
 $HESTIA/bin/v-change-user-language admin $lang
 $HESTIA/bin/v-change-sys-config-value 'POLICY_SYSTEM_PROTECTED_ADMIN' 'yes'
 
+locale-gen "en_US.utf8" > /dev/null 2>&1
 
 #----------------------------------------------------------#
 #                     Configure Nginx                      #

+ 43 - 2
test/test.bats

@@ -69,7 +69,9 @@ function validate_web_domain() {
     fi
 
     # Test HTTP
-    run curl --location --silent --show-error --insecure --resolve "${domain}:80:${domain_ip}" "http://${domain}/${webpath}"
+    # Curl hates UTF domains so convert them to ascci. 
+    domain_idn=$(idn -a $domain)
+    run curl --location --silent --show-error --insecure --resolve "${domain_idn}:80:${domain_ip}" "http://${domain_idn}/${webpath}"
     assert_success
     assert_output --partial "$webproof"
 
@@ -78,7 +80,7 @@ function validate_web_domain() {
         run v-list-web-domain-ssl $user $domain
         assert_success
 
-        run curl --location --silent --show-error --insecure --resolve "${domain}:443:${domain_ip}" "https://${domain}/${webpath}"
+        run curl --location --silent --show-error --insecure --resolve "${domain_idn}:443:${domain_ip}" "https://${domain_idn}/${webpath}"
         assert_success
         assert_output --partial "$webproof"
     fi
@@ -648,7 +650,46 @@ function validate_database(){
     assert_success
     refute_output
 }
+
+#----------------------------------------------------------#
+#                         IDN                              #
+#----------------------------------------------------------#
+
+@test "WEB: Add IDN domain UTF idn-tést.eu" {
+   run v-add-web-domain $user idn-tést.eu 198.18.0.125
+   assert_success
+   refute_output
+   
+   echo -e "<?php\necho 'Hestia Test:'.(4*3);" > $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
+   validate_web_domain $user idn-tést.eu 'Hestia Test:12' 'php-test.php'
+   rm $HOMEDIR/$user/web/idn-tést.eu/public_html/php-test.php
+}
+
+@test "WEB: Add IDN domain ASCII idn-tést.eu" {
+ # Expected to fail due to utf exists
+ run v-add-web-domain $user $( idn -a idn-tést.eu) 198.18.0.125
+ assert_failure $E_EXISTS
+
+}
+
+@test "WEB: Delete IDN domain idn-tést.eu" {
+ run v-delete-web-domain $user idn-tést.eu
+ assert_success
+ refute_output
+}
  
+@test "WEB: Add IDN domain UTF bløst.com" {
+ run v-add-web-domain $user bløst.com 198.18.0.125
+ assert_success
+ refute_output
+}
+
+@test "WEB: Delete IDN domain bløst.com" {
+ run v-delete-web-domain $user bløst.com
+ assert_success
+ refute_output
+}
+
 #----------------------------------------------------------#
 #                      MULTIPHP                            #
 #----------------------------------------------------------#