Skip to content

Commit d13b60a

Browse files
author
Kristan Kenney
authored
Fix for grep error when adding ipset for the first time (hestiacp#2307)
* Fix grep error when running v-add-firewall-ipset for the first time Additional notes: * Perform demo mode verification check sooner * Ensure ipset is installed before parsing config files * Fix incorrect variable spelling ($v_interace > $v_interface)
1 parent fe68ebe commit d13b60a

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

bin/v-add-firewall-ipset

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,29 @@ is_boolean_format_valid "$autoupdate" 'bool (yes/no)'
3434
is_boolean_format_valid "$force" 'bool (yes/no)'
3535
is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
3636

37-
ipset_hstobject='../../data/firewall/ipset'
37+
# Perform verification if read-only mode is enabled
38+
check_hestia_demo_mode
3839

40+
# Define variables for ipset configuration
41+
ipset_hstobject='../../data/firewall/ipset'
3942
IPSET_BIN="$(which ipset)"
4043
IPSET_PATH="$HESTIA/data/firewall/ipset"
4144

45+
# Ensure ipset is installed
46+
if [ -z "$IPSET_BIN" ]; then
47+
apt-get --quiet --yes install ipset > /dev/null
48+
check_result $? "Installing ipset package"
49+
50+
IPSET_BIN="$(which ipset)"
51+
check_result $? "ipset binary not found"
52+
fi
53+
54+
# Ensure ipset configuration path and master file exist before attempting to parse
55+
mkdir -p "$IPSET_PATH"
56+
if [ ! -f "$HESTIA/data/firewall/ipset.conf" ]; then
57+
touch $HESTIA/data/firewall/ipset.conf
58+
fi
59+
4260
if [ -z "$data_source" ]; then
4361
if [ ! -f "${IPSET_PATH}.conf" ] || [[ ! $(grep "LISTNAME='$ip_name'" "${IPSET_PATH}.conf") ]]; then
4462
check_args '2' "$#" 'NAME SOURCE [IPVERSION] [AUTOUPDATE] [FORCE]'
@@ -58,28 +76,13 @@ if ! echo "$data_source" | egrep -q '^(https?|script|file):'; then
5876
check_result "$E_INVALID" "invalid ipset source, valid: (http[s]://|script:|file:)"
5977
fi
6078

61-
6279
IPSET_FILE="${ip_name}.${ip_version}"
6380
IPSET_MIN_SIZE=10
6481

65-
# Perform verification if read-only mode is enabled
66-
check_hestia_demo_mode
67-
68-
# Install ipset package if missing
69-
if [ -z "$IPSET_BIN" ]; then
70-
apt-get --quiet --yes install ipset > /dev/null
71-
check_result $? "Installing ipset package"
72-
73-
IPSET_BIN="$(which ipset)"
74-
check_result $? "ipset binary not found"
75-
fi
76-
7782
#----------------------------------------------------------#
7883
# Action #
7984
#----------------------------------------------------------#
8085

81-
mkdir -p "$IPSET_PATH"
82-
8386
# Generate ip lists file if missing or when forced
8487
if [ ! -f "${IPSET_PATH}/${IPSET_FILE}.iplist" ] || [ "$force" = "yes" ]; then
8588

web/edit/ip/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
$v_username = $user;
3131
$v_ip = $_GET['ip'];
3232
$v_netmask = $data[$v_ip]['NETMASK'];
33-
$v_interace = $data[$v_ip]['INTERFACE'];
33+
$v_interface = $data[$v_ip]['INTERFACE'];
3434
$v_name = $data[$v_ip]['NAME'];
3535
$v_nat = $data[$v_ip]['NAT'];
3636
$v_ipstatus = $data[$v_ip]['STATUS'];

web/templates/pages/edit_ip.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
</tr>
8383
<tr>
8484
<td>
85-
<input type="text" size="20" class="vst-input" name="v_netmask" value="<?=htmlentities(trim($v_interace, "'"))?>" disabled>
85+
<input type="text" size="20" class="vst-input" name="v_netmask" value="<?=htmlentities(trim($v_interface, "'"))?>" disabled>
8686
</td>
8787
</tr>
8888
<tr>

0 commit comments

Comments
 (0)