Procházet zdrojové kódy

Self heal firewall links if missing

cmstew před 5 roky
rodič
revize
837e5f1230

+ 4 - 0
bin/v-add-firewall-ban

@@ -24,6 +24,7 @@ iptables="/sbin/iptables"
 
 # Includes
 source $HESTIA/func/main.sh
+source $HESTIA/func/firewall.sh
 source $HESTIA/conf/hestia.conf
 
 
@@ -43,6 +44,9 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Self heal iptables links
+heal_iptables_links
+
 # Checking server ip
 if [ -e "$HESTIA/data/ips/$ip" ] || [ "$ip" = '127.0.0.1' ]; then
     exit

+ 4 - 0
bin/v-add-firewall-chain

@@ -32,6 +32,7 @@ fi
 
 # Includes
 source $HESTIA/func/main.sh
+source $HESTIA/func/firewall.sh
 source $HESTIA/conf/hestia.conf
 
 
@@ -50,6 +51,9 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Self heal iptables links
+heal_iptables_links
+
 # Checking known chains
 case $chain in
     SSH)        # Get ssh port by reading ssh config file.

+ 4 - 0
bin/v-delete-firewall-ban

@@ -24,6 +24,7 @@ iptables="/sbin/iptables"
 
 # Includes
 source $HESTIA/func/main.sh
+source $HESTIA/func/firewall.sh
 source $HESTIA/conf/hestia.conf
 
 
@@ -43,6 +44,9 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Self heal iptables links
+heal_iptables_links
+
 # Checking ip in banlist
 conf="$HESTIA/data/firewall/banlist.conf"
 check_ip=$(grep "IP='$ip' CHAIN='$chain'" $conf 2>/dev/null)

+ 4 - 0
bin/v-delete-firewall-chain

@@ -23,6 +23,7 @@ iptables="/sbin/iptables"
 
 # Includes
 source $HESTIA/func/main.sh
+source $HESTIA/func/firewall.sh
 source $HESTIA/conf/hestia.conf
 
 
@@ -42,6 +43,9 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Self heal iptables links
+heal_iptables_links
+
 # Deleting chain
 chains=$HESTIA/data/firewall/chains.conf
 banlist=$HESTIA/data/firewall/banlist.conf

+ 4 - 0
bin/v-stop-firewall

@@ -17,6 +17,7 @@ modprobe="/sbin/modprobe"
 # Includes
 source /etc/profile.d/hestia.sh
 source $HESTIA/func/main.sh
+source $HESTIA/func/firewall.sh
 source $HESTIA/conf/hestia.conf
 
 
@@ -34,6 +35,9 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Self heal iptables links
+heal_iptables_links
+
 # Creating temporary file
 tmp=$(mktemp)
 

+ 4 - 0
bin/v-update-firewall

@@ -18,6 +18,7 @@ sysctl="/sbin/sysctl"
 # Includes
 source /etc/profile.d/hestia.sh
 source $HESTIA/func/main.sh
+source $HESTIA/func/firewall.sh
 source $HESTIA/conf/hestia.conf
 
 
@@ -32,6 +33,9 @@ is_system_enabled "$FIREWALL_SYSTEM" 'FIREWALL_SYSTEM'
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Self heal iptables links
+heal_iptables_links
+
 # Checking local IPv4 rules
 rules="$HESTIA/data/firewall/rules.conf"
 

+ 18 - 0
func/firewall.sh

@@ -0,0 +1,18 @@
+
+heal_iptables_links() {
+    packages="iptables iptables-save iptables-restore"
+    for package in $packages; do
+        if [ ! -e "/sbin/${package}" ]; then
+            if which ${package}; then
+                ln -s "$(which ${package})" /sbin/${package}
+            elif [ -e "/usr/sbin/${package}" ]; then
+                ln -s /usr/sbin/${package} /sbin/${package}
+            elif whereis -B /bin /sbin /usr/bin /usr/sbin -f -b ${package}; then
+                autoiptables=$(whereis -B /bin /sbin /usr/bin /usr/sbin -f -b ${package} | cut -d '' -f 2)
+                if [ -x "$autoiptables" ]; then
+                    ln -s "$autoiptables" /sbin/${package}
+                fi
+            fi
+        fi
+    done
+}