Ver Fonte

IPV6: Remove double IPV6 functions

Correction for wrong negative values during increase/decrease_ip_value
asmcc há 3 anos atrás
pai
commit
78f5579689

+ 1 - 1
bin/v-add-mail-domain

@@ -86,7 +86,7 @@ source_conf "$USER_DATA/user.conf"
 domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
 domain_ipv6=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP6')
 if [ -n "$domain_ipv6" ]; then
-	local_ipv6=$(get_real_ipv6 "$domain_ipv6")
+	local_ipv6=$(get_real_ip "$domain_ipv6")
 	is_ipv6_valid "$local_ipv6" "$user"
 fi
 if [ -n "$domain_ip" ]; then

+ 1 - 1
bin/v-add-mail-domain-webmail

@@ -81,7 +81,7 @@ check_hestia_demo_mode
 domain_ip=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP')
 domain_ipv6=$(get_object_value 'web' 'DOMAIN' "$domain" '$IP6')
 if [ -n "$domain_ipv6" ]; then
-	local_ipv6=$(get_real_ipv6 "$domain_ipv6")
+	local_ipv6=$(get_real_ip "$domain_ipv6")
 	is_ipv6_valid "$local_ipv6" "$user"
 	ipv6=$local_ipv6
 fi

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

@@ -178,13 +178,13 @@ else
 	fi
 
 	if [ -n "$local_ip" ]; then
-		ip_alias=$(get_ip_alias "$domain")
+		ip_alias=$(get_ip_alias "$domain" "$local_ip")
 		if [ -n "$ip_alias" ]; then
 			ALIAS="$ALIAS,$ip_alias"
 		fi
 	fi
 	if [ -n "$local_ipv6" ]; then
-		ipv6_alias=$(get_ipv6_alias "$domain")
+		ipv6_alias=$(get_ip_alias "$domain" "$local_ipv6")
 		if [ -n "$ipv6_alias" ]; then
 			ALIAS="$ALIAS,$ipv6_alias"
 		fi
@@ -224,7 +224,7 @@ fi
 
 # Increasing counters
 [ -n "$local_ip" ] && increase_ip_value "$local_ip"
-[ -n "$local_ipv6" ] && increase_ipv6_value "$local_ipv6"
+[ -n "$local_ipv6" ] && increase_ip_value "$local_ipv6"
 increase_user_value "$user" '$U_WEB_DOMAINS'
 increase_user_value "$user" '$U_WEB_ALIASES' "$alias_number"
 

+ 2 - 2
bin/v-change-web-domain-ipv6

@@ -96,8 +96,8 @@ fi
 update_object_value 'web' 'DOMAIN' "$domain" '$IP6' "$3"
 
 # Update counters
-[ -n "$new" ] && increase_ipv6_value "$new"
-[ -n "$old" ] && decrease_ipv6_value "$old"
+[ -n "$new" ] && increase_ip_value "$new"
+[ -n "$old" ] && decrease_ip_value "$old"
 
 # Restart web server
 $BIN/v-restart-web "$restart"

+ 1 - 1
bin/v-delete-web-domain

@@ -122,7 +122,7 @@ rm -rf $HOMEDIR/$user/conf/web/$domain
 
 # Decreasing user counters
 [ -n "$local_ip" ] && decrease_ip_value "$local_ip"
-[ -n "$local_ipv6" ] && decrease_ipv6_value "$local_ipv6"
+[ -n "$local_ipv6" ] && decrease_ip_value "$local_ipv6"
 decrease_user_value "$user" '$U_WEB_DOMAINS'
 if [ "$SSL" = 'yes' ]; then
 	decrease_user_value "$user" '$U_WEB_SSL'

+ 14 - 102
func/ip.sh

@@ -99,8 +99,10 @@ update_ip_value_new() {
 
 # Get ip name
 get_ip_alias() {
-	if [ -n "$local_ip"]; then
-		ip_name=$(grep "NAME=" $HESTIA/data/ips/$local_ip | cut -f 2 -d \')
+	# ip address (ipv4/ipv6) as second parameter, otherwise $local_ip (ipv4)
+	ip_for_test="${2-$local_ip}"
+	if [ -n "$ip_for_test"]; then
+		ip_name=$(grep "NAME=" $HESTIA/data/ips/${ip_for_test} | cut -f 2 -d \')
 		if [ -n "$ip_name" ]; then
 			echo "${1//./-}.$ip_name"
 		fi
@@ -122,7 +124,11 @@ increase_ip_value() {
 		log_event "$E_PARSING" "$ARGUMENTS"
 		exit "$E_PARSING"
 	fi
-	new_web=$((current_web + 1))
+	if (( $current_web <= 0 )); then
+		new_web=1
+	else
+		new_web=$((current_web + 1))
+	fi
 	if [ -z "$current_usr" ]; then
 		new_usr="$USER"
 	else
@@ -160,7 +166,11 @@ decrease_ip_value() {
 		check_result $E_PARSING "Parsing error"
 	fi
 
-	new_web=$((current_web - 1))
+	if (( $current_web <= 0 )); then
+		new_web=0
+	else
+		new_web=$((current_web - 1))
+	fi
 	check_ip=$(grep $sip $USER_DATA/web.conf | wc -l)
 	if [[ $check_ip = 0 ]]; then
 		new_usr=$(echo "$current_usr" \
@@ -315,104 +325,6 @@ get_ipv6_iface() {
     echo "$interface:$n"
 }
 
-# Get ipv6 name
-get_ipv6_alias() {
-	if [ -n "$local_ipv6" ]; then
-		ipv6_name=$(grep "NAME=" $HESTIA/data/ips/$local_ipv6 2> /dev/null |cut -f 2 -d \')
-		if [ -n "$ipv6_name" ]; then
-			echo "${1//./-}.$ipv6_name"
-		fi
-	else
-		ipv6_name=""
-	fi
-}
-
-# Increase ipv6 value
-increase_ipv6_value() {
-    sip=${1-ipv6}
-    if [ "$sip" != "no" ] && [ ! -z "$sip" ]; then
-        USER=$user
-        web_key='U_WEB_DOMAINS'
-        usr_key='U_SYS_USERS'
-        current_web=$(grep "$web_key=" $HESTIA/data/ips/$sip |cut -f 2 -d \')
-        current_usr=$(grep "$usr_key=" $HESTIA/data/ips/$sip |cut -f 2 -d \')
-        if [ -z "$current_web" ]; then
-            echo "Error: Parsing error"
-            log_event "$E_PARSING" "$ARGUMENTS"
-            exit $E_PARSING
-        fi
-        new_web=$((current_web + 1))
-        if [ -z "$current_usr" ]; then
-            new_usr="$USER"
-        else
-            check_usr=$(echo -e "${current_usr//,/\n}" |grep -w $USER)
-            if [ -z "$check_usr" ]; then
-                new_usr="$current_usr,$USER"
-            else
-                new_usr="$current_usr"
-            fi
-        fi
-
-        sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \
-            $HESTIA/data/ips/$sip
-        sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \
-            $HESTIA/data/ips/$sip
-    fi
-}
-
-# Decrease ipv6 value
-decrease_ipv6_value() {
-    sip=${1-ipv6}
-    if [ "$sip" != "no" ] && [ ! -z "$sip" ]; then
-        USER=$user
-        web_key='U_WEB_DOMAINS'
-        usr_key='U_SYS_USERS'
-
-        current_web=$(grep "$web_key=" $HESTIA/data/ips/$sip |cut -f 2 -d \')
-        current_usr=$(grep "$usr_key=" $HESTIA/data/ips/$sip |cut -f 2 -d \')
-
-        if [ -z "$current_web" ]; then
-            check_result $E_PARSING "Parsing error"
-        fi
-
-        new_web=$((current_web - 1))
-        check_ip=$(grep $sip $USER_DATA/web.conf |wc -l)
-        if [ "$check_ip" -lt 2 ]; then
-            new_usr=$(echo "$current_usr" |\
-                sed "s/,/\n/g"|\
-                sed "s/^$user$//g"|\
-                sed "/^$/d"|\
-                sed ':a;N;$!ba;s/\n/,/g')
-        else
-            new_usr="$current_usr"
-        fi
-
-        sed -i "s/$web_key='$current_web'/$web_key='$new_web'/g" \
-            $HESTIA/data/ips/$sip
-        sed -i "s/$usr_key='$current_usr'/$usr_key='$new_usr'/g" \
-            $HESTIA/data/ips/$sip
-    fi
-}
-
-# Get ipv6 address value
-get_ipv6_value() {
-    key="$1"
-    string=$(cat $HESTIA/data/ips/$ipv6)
-    eval $string
-    eval value="$key"
-    echo "$value"
-}
-
-
-# Get real ipv6 address
-get_real_ipv6() {
-    if [ -e "$HESTIA/data/ips/$1" ]; then
-        echo $1
-    else
-        check_result $E_NOTEXIST "IPV6 $1 doesn't exist"
-    fi
-}
-
 # Get user ip6s
 get_user_ip6s() {
     dedicated=$(grep -H -A10 "OWNER='$user'" $HESTIA/data/ips/* |grep "VERSION='6'")