Browse Source

Fix for grep error when adding ipset for the first time (#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)
Kristan Kenney 4 years ago
parent
commit
d13b60a571
3 changed files with 21 additions and 18 deletions
  1. 19 16
      bin/v-add-firewall-ipset
  2. 1 1
      web/edit/ip/index.php
  3. 1 1
      web/templates/pages/edit_ip.html

+ 19 - 16
bin/v-add-firewall-ipset

@@ -34,11 +34,29 @@ is_boolean_format_valid "$autoupdate" 'bool (yes/no)'
 is_boolean_format_valid "$force" 'bool (yes/no)'
 is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 
-ipset_hstobject='../../data/firewall/ipset'
+# Perform verification if read-only mode is enabled
+check_hestia_demo_mode
 
+# Define variables for ipset configuration
+ipset_hstobject='../../data/firewall/ipset'
 IPSET_BIN="$(which ipset)"
 IPSET_PATH="$HESTIA/data/firewall/ipset"
 
+# Ensure ipset is installed
+if [ -z "$IPSET_BIN" ]; then
+    apt-get --quiet --yes install ipset > /dev/null
+    check_result $? "Installing ipset package"
+
+    IPSET_BIN="$(which ipset)"
+    check_result $? "ipset binary not found"
+fi
+
+# Ensure ipset configuration path and master file exist before attempting to parse
+mkdir -p "$IPSET_PATH"
+if [ ! -f "$HESTIA/data/firewall/ipset.conf" ]; then 
+    touch $HESTIA/data/firewall/ipset.conf
+fi
+
 if [ -z "$data_source" ]; then
     if [ ! -f "${IPSET_PATH}.conf" ] || [[ ! $(grep "LISTNAME='$ip_name'" "${IPSET_PATH}.conf") ]]; then
         check_args '2' "$#" 'NAME SOURCE [IPVERSION] [AUTOUPDATE] [FORCE]'
@@ -58,28 +76,13 @@ if ! echo "$data_source" | egrep -q '^(https?|script|file):'; then
     check_result "$E_INVALID" "invalid ipset source, valid: (http[s]://|script:|file:)"
 fi
 
-
 IPSET_FILE="${ip_name}.${ip_version}"
 IPSET_MIN_SIZE=10
 
-# Perform verification if read-only mode is enabled
-check_hestia_demo_mode
-
-# Install ipset package if missing
-if [ -z "$IPSET_BIN" ]; then
-    apt-get --quiet --yes install ipset > /dev/null
-    check_result $? "Installing ipset package"
-
-    IPSET_BIN="$(which ipset)"
-    check_result $? "ipset binary not found"
-fi
-
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
 
-mkdir -p "$IPSET_PATH"
-
 # Generate ip lists file if missing or when forced
 if [ ! -f "${IPSET_PATH}/${IPSET_FILE}.iplist" ] || [ "$force" = "yes" ]; then
 

+ 1 - 1
web/edit/ip/index.php

@@ -30,7 +30,7 @@ unset($output);
 $v_username = $user;
 $v_ip = $_GET['ip'];
 $v_netmask = $data[$v_ip]['NETMASK'];
-$v_interace = $data[$v_ip]['INTERFACE'];
+$v_interface = $data[$v_ip]['INTERFACE'];
 $v_name = $data[$v_ip]['NAME'];
 $v_nat = $data[$v_ip]['NAT'];
 $v_ipstatus = $data[$v_ip]['STATUS'];

+ 1 - 1
web/templates/pages/edit_ip.html

@@ -82,7 +82,7 @@
 						</tr>
 						<tr>
 							<td>
-								<input type="text" size="20" class="vst-input" name="v_netmask" value="<?=htmlentities(trim($v_interace, "'"))?>" disabled>
+								<input type="text" size="20" class="vst-input" name="v_netmask" value="<?=htmlentities(trim($v_interface, "'"))?>" disabled>
 							</td>
 						</tr>
 						<tr>