@@ -69,7 +69,7 @@ if [[ "$sshport" =~ ^[0-9]+$ ]] && [ "$sshport" -ne "22" ]; then
6969fi
7070
7171# Load ipset lists before adding Hestia iptables rules
72- [ -x " $( which ipset ) " ] && $BIN /v-update-firewall-ipset
72+ $BIN /v-update-firewall-ipset
7373
7474# Creating temporary file
7575tmp=$( mktemp)
@@ -185,31 +185,25 @@ if [ -d "/etc/sysconfig" ]; then
185185 fi
186186else
187187 /sbin/iptables-save > /etc/iptables.rules
188- routable=" /usr/lib/networkd-dispatcher/routable.d/10-hestia-iptables"
189- preup=" /etc/network/if-pre-up.d/hestia-iptables"
190- # Recreate the Hestia iptables rules loading script
191- rm -f $routable $preup
192- if dpkg-query -W -f' ${Status}' " netplan*" 2> /dev/null | grep -q " ok installed" && [ -d /etc/netplan ] && [ -n " $( ls -A /etc/netplan 2> /dev/null) " ]; then
193- echo ' #!/bin/sh' > $routable
194- echo ' ' >> $routable
195- echo ' if [ "$IFACE" = "' $( ip route list | awk ' /default .+/ {print $5}' | uniq) ' " ]; then' >> $routable
196- echo ' [ -x "' $( which ipset) ' " ] && ' " ${HESTIA} /bin/v-update-firewall-ipset" >> $routable
197- echo ' /sbin/iptables-restore < /etc/iptables.rules' >> $routable
198- echo ' fi' >> $routable
199- echo ' ' >> $routable
200- echo " exit 0" >> $routable
201- chmod +x $routable
202- else
203- echo ' #!/bin/sh' > $preup
204- echo ' ' >> $preup
205- echo ' if [ "$IFACE" = "' $( ip route list | awk ' /default .+/ {print $5}' | uniq) ' " ]; then' >> $preup
206- echo ' [ -x "' $( which ipset) ' " ] && ' " ${HESTIA} /bin/v-update-firewall-ipset" >> $preup
207- echo ' /sbin/iptables-restore < /etc/iptables.rules' >> $preup
208- echo ' fi' >> $preup
209- echo ' ' >> $preup
210- echo " exit 0" >> $preup
211- chmod +x $preup
188+ sd_unit=" /lib/systemd/system/hestia-iptables.service"
189+ if [ ! -e " $sd_unit " ]; then
190+ echo " [Unit]" >> $sd_unit
191+ echo " Description=Loading Hestia firewall rules" >> $sd_unit
192+ echo " DefaultDependencies=no" >> $sd_unit
193+ echo " Wants=network-pre.target local-fs.target" >> $sd_unit
194+ echo " Before=network-pre.target" >> $sd_unit
195+ echo " After=local-fs.target" >> $sd_unit
196+ echo " " >> $sd_unit
197+ echo " [Service]" >> $sd_unit
198+ echo " Type=oneshot" >> $sd_unit
199+ echo " RemainAfterExit=yes" >> $sd_unit
200+ echo " ExecStartPre=-${HESTIA} /bin/v-update-firewall-ipset" >> $sd_unit
201+ echo " ExecStart=/sbin/iptables-restore /etc/iptables.rules" >> $sd_unit
202+ echo " " >> $sd_unit
203+ echo " [Install]" >> $sd_unit
204+ echo " WantedBy=multi-user.target" >> $sd_unit
212205 fi
206+ systemctl is-enabled hestia-iptables > /dev/null 2>&1 || systemctl enable hestia-iptables > /dev/null 2>&1
213207fi
214208
215209
0 commit comments