Browse Source

IPV6: Unifying of change system IP scripts

bin/v-change-sys-ip-name

bin/v-change-sys-ip-nat

bin/v-change-sys-ip-owner

bin/v-change-sys-ip-status
asmcc 3 years ago
parent
commit
e95a05bc35
4 changed files with 78 additions and 27 deletions
  1. 16 4
      bin/v-change-sys-ip-name
  2. 24 11
      bin/v-change-sys-ip-nat
  3. 18 5
      bin/v-change-sys-ip-owner
  4. 20 7
      bin/v-change-sys-ip-status

+ 16 - 4
bin/v-change-sys-ip-name

@@ -11,8 +11,8 @@
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Argument definition
 # Argument definition
-ip=$1
-ip_name=$2
+ip46=${1}
+ip_name=${2}
 
 
 # Includes
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -29,9 +29,21 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 check_args '2' "$#" 'IP IP_NAME'
 check_args '2' "$#" 'IP IP_NAME'
-is_format_valid 'ip'
+ip_format="$(get_ip_format ${ip46})"	#	ip verification and format identification
+if [ -n "$ip_format" ]; then
+	if [ $ip_format -eq 6 ]; then
+		ip=""
+		ipv6="${ip46}"
+		is_format_valid 'ipv6'
+		is_ip_valid "$ipv6"
+	else
+		ip="${ip46}"
+		ipv6=""
+		is_format_valid 'ip'
+		is_ip_valid "$ip"
+	fi
+fi
 is_format_valid 'ip_name'
 is_format_valid 'ip_name'
-is_ip_valid "$ip"
 
 
 # Perform verification if read-only mode is enabled
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 check_hestia_demo_mode

+ 24 - 11
bin/v-change-sys-ip-nat

@@ -11,9 +11,9 @@
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Argument definition
 # Argument definition
-ip=$1
-nat_ip=$2
-restart=$3
+ip46=${1}
+nat_ip=${2}
+restart=${3}
 
 
 # Includes
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -30,9 +30,22 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 check_args '2' "$#" 'IP NAT_IP [RESTART]'
 check_args '2' "$#" 'IP NAT_IP [RESTART]'
-is_format_valid 'ip'
-is_format_valid 'nat_ip'
-is_ip_valid "$ip"
+ip_format="$(get_ip_format ${ip46})"	#	ip verification and format identification
+if [ -n "$ip_format" ]; then
+	if [ $ip_format -eq 6 ]; then
+		ip=""
+		ipv6="${ip46}"
+		is_format_valid 'ipv6'
+		is_ip_valid "$ipv6"
+		nat_ip=""
+	else
+		ip="${ip46}"
+		ipv6=""
+		is_format_valid 'ip'
+		is_ip_valid "$ip"
+		is_format_valid 'nat_ip'
+	fi
+fi
 
 
 # Perform verification if read-only mode is enabled
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 check_hestia_demo_mode
@@ -42,16 +55,16 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Updating IP
 # Updating IP
-if [ -z "$(grep NAT= $HESTIA/data/ips/$ip)" ]; then
-	sed -i "s/^TIME/NAT='$nat_ip'\nTIME/g" $HESTIA/data/ips/$ip
+if [ -z "$(grep NAT= $HESTIA/data/ips/${ip46})" ]; then
+	sed -i "s/^TIME/NAT='$nat_ip'\nTIME/g" $HESTIA/data/ips/${ip46}
 	old=''
 	old=''
 	new=$nat_ip
 	new=$nat_ip
 else
 else
 	old=$(get_ip_value '$NAT')
 	old=$(get_ip_value '$NAT')
 	new=$nat_ip
 	new=$nat_ip
-	sed -i "s/NAT=.*/NAT='$new'/" $HESTIA/data/ips/$ip
+	sed -i "s/NAT=.*/NAT='$new'/" $HESTIA/data/ips/${ip46}
 	if [ -z "$nat_ip" ]; then
 	if [ -z "$nat_ip" ]; then
-		new=$ip
+		new=${ip46}
 	fi
 	fi
 fi
 fi
 
 
@@ -113,7 +126,7 @@ fi
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Logging
 # Logging
-$BIN/v-log-action "system" "Info" "System" "IP NAT address changed (IP: $ip, NAT IP: $nat_ip)."
+$BIN/v-log-action "system" "Info" "System" "IP NAT address changed (IP: ${ip46}, NAT IP: $nat_ip)."
 log_event "$OK" "$ARGUMENTS"
 log_event "$OK" "$ARGUMENTS"
 
 
 exit
 exit

+ 18 - 5
bin/v-change-sys-ip-owner

@@ -11,7 +11,7 @@
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Argument definition
 # Argument definition
-ip=$1
+ip46=$1
 user=$2
 user=$2
 
 
 # shellcheck source=/etc/hestiacp/hestia.conf
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -28,10 +28,23 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 check_args '2' "$#" 'IP USER'
 check_args '2' "$#" 'IP USER'
-is_format_valid 'ip' 'user'
+ip_format="$(get_ip_format ${ip46})"	#	ip verification and format identification
+if [ -n "$ip_format" ]; then
+	if [ $ip_format -eq 6 ]; then
+		ip=""
+		ipv6="${ip46}"
+		is_format_valid 'ipv6'
+		is_ip_valid "$ipv6"
+	else
+		ip="${ip46}"
+		ipv6=""
+		is_format_valid 'ip'
+		is_ip_valid "$ip"
+	fi
+fi
+is_format_valid 'user'
 is_object_valid 'user' 'USER' "$user"
 is_object_valid 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
 is_object_unsuspended 'user' 'USER' "$user"
-is_ip_valid "$ip"
 is_ip_key_empty '$U_WEB_DOMAINS'
 is_ip_key_empty '$U_WEB_DOMAINS'
 is_ip_key_empty '$U_SYS_USERS'
 is_ip_key_empty '$U_SYS_USERS'
 
 
@@ -80,7 +93,7 @@ fi
 # Set status to dedicated if owner is not admin
 # Set status to dedicated if owner is not admin
 ip_status="$(get_ip_value '$STATUS')"
 ip_status="$(get_ip_value '$STATUS')"
 if [ "$user" != 'admin' ] && [ "$ip_status" == 'shared' ]; then
 if [ "$user" != 'admin' ] && [ "$ip_status" == 'shared' ]; then
-	$BIN/v-change-sys-ip-status "$ip" 'dedicated'
+	$BIN/v-change-sys-ip-status "${ip46}" 'dedicated'
 fi
 fi
 
 
 #----------------------------------------------------------#
 #----------------------------------------------------------#
@@ -88,7 +101,7 @@ fi
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Logging
 # Logging
-$BIN/v-log-action "system" "Info" "System" "IP address owner changed (IP: $ip, Owner: $user)"
+$BIN/v-log-action "system" "Info" "System" "IP address owner changed (IP: ${ip46}, Owner: $user)"
 log_event "$OK" "$ARGUMENTS"
 log_event "$OK" "$ARGUMENTS"
 
 
 exit
 exit

+ 20 - 7
bin/v-change-sys-ip-status

@@ -11,8 +11,8 @@
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Argument definition
 # Argument definition
-ip=$1
-ip_status=$2
+ip46=${1}
+ip_status=${2}
 
 
 # Includes
 # Includes
 # shellcheck source=/etc/hestiacp/hestia.conf
 # shellcheck source=/etc/hestiacp/hestia.conf
@@ -29,8 +29,21 @@ source_conf "$HESTIA/conf/hestia.conf"
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 check_args '2' "$#" 'IP IP_STATUS'
 check_args '2' "$#" 'IP IP_STATUS'
-is_format_valid 'ip' 'ip_status'
-is_ip_valid "$ip"
+ip_format="$(get_ip_format ${ip46})"	#	ip verification and format identification
+if [ -n "$ip_format" ]; then
+	if [ $ip_format -eq 6 ]; then
+		ip=""
+		ipv6="${ip46}"
+		is_format_valid 'ipv6'
+		is_ip_valid "$ipv6"
+	else
+		ip="${ip46}"
+		ipv6=""
+		is_format_valid 'ip'
+		is_ip_valid "$ip"
+	fi
+fi
+is_format_valid 'ip_status'
 if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then
 if [ "$ip_status" = "$(get_ip_value '$STATUS')" ]; then
 	check_result "$E_EXISTS" "status $ip_status is already set"
 	check_result "$E_EXISTS" "status $ip_status is already set"
 fi
 fi
@@ -38,10 +51,10 @@ web_domains=$(get_ip_value '$U_WEB_DOMAINS')
 sys_user=$(get_ip_value '$U_SYS_USERS')
 sys_user=$(get_ip_value '$U_SYS_USERS')
 ip_owner=$(get_ip_value '$OWNER')
 ip_owner=$(get_ip_value '$OWNER')
 if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
 if [ "$web_domains" -ne '0' ] && [ "$sys_user" != "$ip_owner" ]; then
-	check_result "$E_INUSE" "ip $ip is used"
+	check_result "$E_INUSE" "ip ${ip46} is used"
 fi
 fi
 if [ "$ip_owner" != "admin" ] && [ "$ip_status" == "shared" ]; then
 if [ "$ip_owner" != "admin" ] && [ "$ip_status" == "shared" ]; then
-	$BIN/v-change-sys-ip-owner "$ip" "admin"
+	$BIN/v-change-sys-ip-owner "${ip46}" "admin"
 fi
 fi
 
 
 # Perform verification if read-only mode is enabled
 # Perform verification if read-only mode is enabled
@@ -59,7 +72,7 @@ update_ip_value '$STATUS' "$ip_status"
 #----------------------------------------------------------#
 #----------------------------------------------------------#
 
 
 # Logging
 # Logging
-$BIN/v-log-action "system" "Info" "System" "IP address status changed (Status: $ip_status, IP: $ip)."
+$BIN/v-log-action "system" "Info" "System" "IP address status changed (Status: $ip_status, IP: ${ip46})."
 log_event "$OK" "$ARGUMENTS"
 log_event "$OK" "$ARGUMENTS"
 
 
 exit
 exit