Эх сурвалжийг харах

Improved code as sugested @lupul

Jaap Marcus 4 жил өмнө
parent
commit
7efc5009e2

+ 5 - 3
bin/v-add-web-domain-alias

@@ -42,7 +42,7 @@ format_aliases
 #----------------------------------------------------------#
 
 # Parsing domain values as they are used to get the current alias usage
-get_domain_values 'web'
+
 
 if [ -z "$aliases" ]; then
     check_result $E_INVALID "invalid alias format: empty"
@@ -56,8 +56,6 @@ is_object_unsuspended 'user' 'USER' "$user"
 is_object_valid 'web' 'DOMAIN' "$domain"
 is_object_unsuspended 'web' 'DOMAIN' "$domain"
 is_domain_new 'web' "$aliases"
-is_package_full 'WEB_ALIASES'
-
 is_base_domain_owner "$aliases"
 
 # Perform verification if read-only mode is enabled
@@ -68,6 +66,8 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+get_domain_values 'web'
+
 # Preparing domain values for the template substitution
 local_ip=$(get_real_ip $IP)
 if [ -z "$ALIAS" ]; then
@@ -77,6 +77,8 @@ else
 fi
 prepare_web_domain_values
 
+is_package_full 'WEB_ALIASES'
+
 # Rebuilding vhost
 del_web_config "$WEB_SYSTEM" "$TPL.tpl"
 add_web_config "$WEB_SYSTEM" "$TPL.tpl"

+ 9 - 2
func/main.sh

@@ -179,8 +179,15 @@ is_package_full() {
     esac
     used=$(echo "$used"| cut -f 1 -d \ )
     limit=$(grep "^$1=" $USER_DATA/user.conf |cut -f 2 -d \')
-    if [ "$limit" != 'unlimited' ] && [[ "$used" -ge "$limit" ]]; then
-        check_result $E_LIMIT "$1 limit is reached :: upgrade user package"
+    if [ "$1" = WEB_ALIASES ]; then
+        # Used is always calculated with the new alias added
+        if [ "$limit" != 'unlimited' ] && [[ "$used" -gt "$limit" ]]; then
+            check_result $E_LIMIT "$1 limit is reached :: upgrade user package"
+        fi
+    else
+        if [ "$limit" != 'unlimited' ] && [[ "$used" -ge "$limit" ]]; then
+            check_result $E_LIMIT "$1 limit is reached :: upgrade user package"
+        fi
     fi
 }