Skip to content

Commit e910ab8

Browse files
asmccjaapmarcusasmcc
authored
Bugfix for not defined $user variable in func/main.sh (hestiacp#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>
1 parent e7157fa commit e910ab8

10 files changed

+37
-25
lines changed

bin/v-add-firewall-ipset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
3838
check_hestia_demo_mode
3939

4040
# Define variables for ipset configuration
41-
ipset_hstobject='../../data/firewall/ipset'
41+
ipset_hstobject='../../../data/firewall/ipset'
4242
IPSET_BIN="$(command -v ipset)"
4343
IPSET_PATH="$HESTIA/data/firewall/ipset"
4444

bin/v-add-firewall-rule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ is_format_valid 'action' 'protocol' 'port_ext'
5252
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
5353
get_next_fw_rule
5454
is_format_valid 'rule'
55-
is_object_new '../../data/firewall/rules' 'RULE' "$rule"
55+
is_object_new '../../../data/firewall/rules' 'RULE' "$rule"
5656
if [ -n "$comment" ]; then
5757
is_format_valid 'comment'
5858
fi

bin/v-change-firewall-rule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if [ ! -z "$comment" ]; then
4646
is_format_valid 'comment'
4747
fi
4848
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
49-
is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
49+
is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
5050

5151
if [[ "$ip" =~ ^ipset: ]]; then
5252
ipset_name="${ip#ipset:}"

bin/v-delete-firewall-ipset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ is_format_valid 'ip_name'
2929
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
3030

3131
# Define variables for ipset configuration
32-
ipset_hstobject='../../data/firewall/ipset'
32+
ipset_hstobject='../../../data/firewall/ipset'
3333
is_object_valid "$ipset_hstobject" 'LISTNAME' "$ip_name"
3434
ip_version="$(get_object_value "$ipset_hstobject" 'LISTNAME' "$ip_name" '$IP_VERSION')"
3535

bin/v-delete-firewall-rule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ source_conf "$HESTIA/conf/hestia.conf"
2828
check_args '1' "$#" 'RULE'
2929
is_format_valid 'rule'
3030
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
31-
is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
31+
is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
3232

3333
# Perform verification if read-only mode is enabled
3434
check_hestia_demo_mode

bin/v-list-firewall-rule

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ csv_list() {
6767

6868
check_args '1' "$#" 'RULE [FORMAT]'
6969
is_number_format_valid "$rule" "rule id"
70-
is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
70+
is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
7171

7272
#----------------------------------------------------------#
7373
# Action #

bin/v-suspend-firewall-rule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ source_conf "$HESTIA/conf/hestia.conf"
2828
check_args '1' "$#" 'RULE'
2929
is_format_valid 'rule'
3030
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
31-
is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
32-
is_object_unsuspended '../../data/firewall/rules' 'RULE' "$rule"
31+
is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
32+
is_object_unsuspended '../../../data/firewall/rules' 'RULE' "$rule"
3333

3434
# Perform verification if read-only mode is enabled
3535
check_hestia_demo_mode
@@ -39,7 +39,7 @@ check_hestia_demo_mode
3939
#----------------------------------------------------------#
4040

4141
# Suspending rule
42-
update_object_value ../../data/firewall/rules RULE "$rule" '$SUSPENDED' yes
42+
update_object_value '../../../data/firewall/rules' 'RULE' "$rule" '$SUSPENDED' yes
4343

4444
# Updating system firewall
4545
$BIN/v-update-firewall

bin/v-unsuspend-firewall-rule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ source_conf "$HESTIA/conf/hestia.conf"
2828
check_args '1' "$#" 'RULE'
2929
is_format_valid 'rule'
3030
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
31-
is_object_valid '../../data/firewall/rules' 'RULE' "$rule"
32-
is_object_suspended '../../data/firewall/rules' 'RULE' "$rule"
31+
is_object_valid '../../../data/firewall/rules' 'RULE' "$rule"
32+
is_object_suspended '../../../data/firewall/rules' 'RULE' "$rule"
3333

3434
# Perform verification if read-only mode is enabled
3535
check_hestia_demo_mode
@@ -39,7 +39,7 @@ check_hestia_demo_mode
3939
#----------------------------------------------------------#
4040

4141
# Suspending rule
42-
update_object_value ../../data/firewall/rules RULE "$rule" '$SUSPENDED' "no"
42+
update_object_value '../../../data/firewall/rules' 'RULE' "$rule" '$SUSPENDED' "no"
4343

4444
# Updating system firewall
4545
$BIN/v-update-firewall

bin/v-update-firewall-ipset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
3131
# Perform verification if read-only mode is enabled
3232
check_hestia_demo_mode
3333

34-
ipset_hstobject='../../data/firewall/ipset'
34+
ipset_hstobject='../../../data/firewall/ipset'
3535

3636
for ipset_name in $(search_objects "$ipset_hstobject" 'SUSPENDED' 'no' 'LISTNAME' 2> /dev/null); do
3737

func/main.sh

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@
66
# #
77
#===========================================================================#
88

9+
# Source conf function for correct variable initialisation
10+
source_conf() {
11+
while IFS='= ' read -r lhs rhs; do
12+
if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
13+
rhs="${rhs%%^\#*}" # Del in line right comments
14+
rhs="${rhs%%*( )}" # Del trailing spaces
15+
rhs="${rhs%\'*}" # Del opening string quotes
16+
rhs="${rhs#\'*}" # Del closing string quotes
17+
declare -g $lhs="$rhs"
18+
fi
19+
done < $1
20+
}
21+
22+
if [ -z "$user" ]; then
23+
if [ -z "$ROOT_USER" ]; then
24+
if [ -z "$HESTIA" ]; then
25+
# shellcheck source=/etc/hestiacp/hestia.conf
26+
source /etc/hestiacp/hestia.conf
27+
fi
28+
source_conf "$HESTIA/conf/hestia.conf" # load config file
29+
fi
30+
user="$ROOT_USER"
31+
fi
32+
933
# Internal variables
1034
HOMEDIR='/home'
1135
BACKUP='/backup'
@@ -1570,18 +1594,6 @@ no_symlink_chmod() {
15701594
done
15711595
}
15721596

1573-
source_conf() {
1574-
while IFS='= ' read -r lhs rhs; do
1575-
if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
1576-
rhs="${rhs%%^\#*}" # Del in line right comments
1577-
rhs="${rhs%%*( )}" # Del trailing spaces
1578-
rhs="${rhs%\'*}" # Del opening string quotes
1579-
rhs="${rhs#\'*}" # Del closing string quotes
1580-
declare -g $lhs="$rhs"
1581-
fi
1582-
done < $1
1583-
}
1584-
15851597
format_no_quotes() {
15861598
exclude="['|\"]"
15871599
if [[ "$1" =~ $exclude ]]; then

0 commit comments

Comments
 (0)