Przeglądaj źródła

Bugfix for not defined $user variable in func/main.sh (#3929)

* Correct representation of IP addresses in plain and csv mode

* Adaptation func/main.sh for correct working with IPV6 addresses

* Add hesita-nginx nginx.conf to ignore list

Check if we can improve the sed in the feature

* Update hestia-nginx nginx.conf file

* Bugfixing of empty  issue after change to user defined admin user

* Further corrections in some firewall scripts to generate correct relative path

---------

Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
Co-authored-by: asmcc <root@test.hestiacp.com>
asmcc 2 lat temu
rodzic
commit
e910ab833d

+ 1 - 1
bin/v-add-firewall-ipset

@@ -38,7 +38,7 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 check_hestia_demo_mode
 
 # Define variables for ipset configuration
-ipset_hstobject='../../data/firewall/ipset'
+ipset_hstobject='../../../data/firewall/ipset'
 IPSET_BIN="$(command -v ipset)"
 IPSET_PATH="$HESTIA/data/firewall/ipset"
 

+ 1 - 1
bin/v-add-firewall-rule

@@ -52,7 +52,7 @@ is_format_valid 'action' 'protocol' 'port_ext'
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 get_next_fw_rule
 is_format_valid 'rule'
-is_object_new '../../data/firewall/rules' 'RULE' "$rule"
+is_object_new '../../../data/firewall/rules' 'RULE' "$rule"
 if [ -n "$comment" ]; then
 	is_format_valid 'comment'
 fi

+ 1 - 1
bin/v-change-firewall-rule

@@ -46,7 +46,7 @@ if [ ! -z "$comment" ]; then
 	is_format_valid 'comment'
 fi
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
-is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
+is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
 
 if [[ "$ip" =~ ^ipset: ]]; then
 	ipset_name="${ip#ipset:}"

+ 1 - 1
bin/v-delete-firewall-ipset

@@ -29,7 +29,7 @@ is_format_valid 'ip_name'
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 
 # Define variables for ipset configuration
-ipset_hstobject='../../data/firewall/ipset'
+ipset_hstobject='../../../data/firewall/ipset'
 is_object_valid "$ipset_hstobject" 'LISTNAME' "$ip_name"
 ip_version="$(get_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$IP_VERSION')"
 

+ 1 - 1
bin/v-delete-firewall-rule

@@ -28,7 +28,7 @@ source_conf "$HESTIA/conf/hestia.conf"
 check_args '1' "$#" 'RULE'
 is_format_valid 'rule'
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
-is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
+is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
 
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode

+ 1 - 1
bin/v-list-firewall-rule

@@ -67,7 +67,7 @@ csv_list() {
 
 check_args '1' "$#" 'RULE [FORMAT]'
 is_number_format_valid "$rule" "rule id"
-is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
+is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
 
 #----------------------------------------------------------#
 #                       Action                             #

+ 3 - 3
bin/v-suspend-firewall-rule

@@ -28,8 +28,8 @@ source_conf "$HESTIA/conf/hestia.conf"
 check_args '1' "$#" 'RULE'
 is_format_valid 'rule'
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
-is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
-is_object_unsuspended '../../data/firewall/rules' 'RULE' "$rule"
+is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
+is_object_unsuspended '../../../data/firewall/rules' 'RULE' "$rule"
 
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
@@ -39,7 +39,7 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Suspending rule
-update_object_value ../../data/firewall/rules RULE "$rule" '$SUSPENDED' yes
+update_object_value '../../../data/firewall/rules' 'RULE' "$rule" '$SUSPENDED' yes
 
 # Updating system firewall
 $BIN/v-update-firewall

+ 3 - 3
bin/v-unsuspend-firewall-rule

@@ -28,8 +28,8 @@ source_conf "$HESTIA/conf/hestia.conf"
 check_args '1' "$#" 'RULE'
 is_format_valid 'rule'
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
-is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
-is_object_suspended '../../data/firewall/rules' 'RULE' "$rule"
+is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
+is_object_suspended '../../../data/firewall/rules' 'RULE' "$rule"
 
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
@@ -39,7 +39,7 @@ check_hestia_demo_mode
 #----------------------------------------------------------#
 
 # Suspending rule
-update_object_value ../../data/firewall/rules RULE "$rule" '$SUSPENDED' "no"
+update_object_value '../../../data/firewall/rules' 'RULE' "$rule" '$SUSPENDED' "no"
 
 # Updating system firewall
 $BIN/v-update-firewall

+ 1 - 1
bin/v-update-firewall-ipset

@@ -31,7 +31,7 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 # Perform verification if read-only mode is enabled
 check_hestia_demo_mode
 
-ipset_hstobject='../../data/firewall/ipset'
+ipset_hstobject='../../../data/firewall/ipset'
 
 for ipset_name in $(search_objects "$ipset_hstobject" 'SUSPENDED' 'no' 'LISTNAME' 2> /dev/null); do
 

+ 24 - 12
func/main.sh

@@ -6,6 +6,30 @@
 #                                                                           #
 #===========================================================================#
 
+# Source conf function for correct variable initialisation
+source_conf() {
+	while IFS='= ' read -r lhs rhs; do
+		if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
+			rhs="${rhs%%^\#*}" # Del in line right comments
+			rhs="${rhs%%*( )}" # Del trailing spaces
+			rhs="${rhs%\'*}"   # Del opening string quotes
+			rhs="${rhs#\'*}"   # Del closing string quotes
+			declare -g $lhs="$rhs"
+		fi
+	done < $1
+}
+
+if [ -z "$user" ]; then
+	if [ -z "$ROOT_USER" ]; then
+		if [ -z "$HESTIA" ]; then
+			# shellcheck source=/etc/hestiacp/hestia.conf
+			source /etc/hestiacp/hestia.conf
+		fi
+		source_conf "$HESTIA/conf/hestia.conf" # load config file
+	fi
+	user="$ROOT_USER"
+fi
+
 # Internal variables
 HOMEDIR='/home'
 BACKUP='/backup'
@@ -1570,18 +1594,6 @@ no_symlink_chmod() {
 	done
 }
 
-source_conf() {
-	while IFS='= ' read -r lhs rhs; do
-		if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
-			rhs="${rhs%%^\#*}" # Del in line right comments
-			rhs="${rhs%%*( )}" # Del trailing spaces
-			rhs="${rhs%\'*}"   # Del opening string quotes
-			rhs="${rhs#\'*}"   # Del closing string quotes
-			declare -g $lhs="$rhs"
-		fi
-	done < $1
-}
-
 format_no_quotes() {
 	exclude="['|\"]"
 	if [[ "$1" =~ $exclude ]]; then