nodogsplash2: Add NDS Restart Hook for Firewall (#369)
authorRob White <rob@blue-wave.net>
Wed, 2 May 2018 18:42:19 +0000 (19:42 +0100)
committerMoritz Warning <moritzwarning@web.de>
Wed, 2 May 2018 18:42:19 +0000 (20:42 +0200)
NodogSplash iptables entries are overwritten if the OpenWrt Firewall is restarted.
This change adds a restart hook to firewall.user to restart NoDogSplash if firewall is restarted.
Author-name: Rob White
Signed-off-by: Rob White rob@blue-wave.net
nodogsplash2/Makefile
nodogsplash2/files/nodogsplash.config
nodogsplash2/files/nodogsplash.init

index badbe1ea25fe1806b931bf8d7dc9e063e9f66324..f17e5dabbd49534cca84fb60ac7985eea21dcfaa 100644 (file)
@@ -54,6 +54,12 @@ define Package/nodogsplash2/install
        $(CP) $(PKG_BUILD_DIR)/resources/splash.jpg $(1)/etc/nodogsplash/htdocs/images/
 endef
 
+define Package/nodogsplash2/postrm
+#!/bin/sh
+uci delete firewall.nodogsplash2
+uci commit firewall
+endef
+
 define Package/nodogsplash2/conffiles
 /etc/nodogsplash/nodogsplash.conf
 endef
index 37269bd886cadcb09dc987c0857d88d88fa9fa09..34afe8977e09184008771e3bc90c3725cbeeee51 100644 (file)
@@ -5,6 +5,10 @@
 config nodogsplash
   # Set to 0 to disable nodogsplash
   option enabled 1
+  
+  # Set to 0 to disable hook that makes Firewall restart nodogsplash when Firewall restarts
+  # This hook is needed as a restart of Firewall overwrites nodogsplash iptables entries
+  option fwhook_enabled '1'
 
   # Serve the file splash.html from this directory
   option webroot '/etc/nodogsplash/htdocs'
index 32dc1eb58d12490afaf392adebfb71406de4b2d9..87229c9a2e35679902d0a7a3afa6c5d67648ccdd 100755 (executable)
@@ -248,10 +248,42 @@ create_instance() {
   procd_close_instance
 }
 
+depends() {
+  if [ "$1" = "iptables" ] ; then
+    if [ $(uci get nodogsplash.@nodogsplash[0].fwhook_enabled) = "1" ] ; then
+      if $WD_DIR/ndsctl status > /dev/null; then
+       echo " * Restarting NodogSplash" 
+       /etc/init.d/nodogsplash restart
+      fi
+    else
+      echo " * NodogSplash fwhook is disabled"
+    fi
+  fi
+}
+
 start_service() {
   include /lib/functions
-
   mkdir -p /tmp/etc/
+  
+  if [ $(uci get nodogsplash.@nodogsplash[0].fwhook_enabled) = "1" ] ; then
+    if ! uci get firewall.nodogsplash2.path &> /dev/null ; then
+      if [ -f '/tmp/etc/ndshook.include' ] ; then
+        rm /tmp/etc/ndshook.include
+      fi
+      uci delete firewall.nodogsplash2 2> /dev/null
+      uci set firewall.nodogsplash2=include
+      uci set firewall.nodogsplash2.type=script
+      uci set firewall.nodogsplash2.path='/tmp/etc/ndshook.include'
+      uci commit firewall
+      /etc/init.d/firewall restart  2>&1 | logger
+    fi
+
+    if [ ! -f '/tmp/etc/ndshook.include' ] ; then
+      printf "if [ -f '/etc/init.d/nodogsplash' ] ; then /etc/init.d/nodogsplash depends iptables ; fi\n" > /tmp/etc/ndshook.include
+      chmod +x /tmp/etc/ndshook.include
+    fi
+  fi
+  
   config_load nodogsplash
 
   config_foreach create_instance nodogsplash