Browse Source

Fix: mod_rpaf config wasn't updated when add/removing system ips

- Don't leave a newline behind in mod_remoteip conf on every ip removal
Robert Zollner 5 years ago
parent
commit
a1343fe536
2 changed files with 6 additions and 2 deletions
  1. 1 0
      bin/v-add-sys-ip
  2. 5 2
      bin/v-delete-sys-ip

+ 1 - 0
bin/v-add-sys-ip

@@ -157,6 +157,7 @@ if [ ! -z "$PROXY_SYSTEM" ]; then
     rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
     rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
     if [ -e "$rpaf_conf" ]; then
     if [ -e "$rpaf_conf" ]; then
         rpaf_str=$(grep RPAFproxy_ips $rpaf_conf)
         rpaf_str=$(grep RPAFproxy_ips $rpaf_conf)
+        [ -z "$rpaf_str" ] && sed -i 's|</IfModule>|RPAFproxy_ips\n</IfModule>|' $rpaf_conf && rpaf_str='RPAFproxy_ips'
         rpaf_str="$rpaf_str $ip"
         rpaf_str="$rpaf_str $ip"
         sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
         sed -i "s/.*RPAFproxy_ips.*/$rpaf_str/" $rpaf_conf
     fi
     fi

+ 5 - 2
bin/v-delete-sys-ip

@@ -105,14 +105,17 @@ if [ ! -z "$PROXY_SYSTEM" ]; then
     rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
     rpaf_conf="/etc/$WEB_SYSTEM/mods-enabled/rpaf.conf"
     if [ -e "$rpaf_conf" ]; then
     if [ -e "$rpaf_conf" ]; then
         ips=$(grep RPAFproxy_ips $rpaf_conf)
         ips=$(grep RPAFproxy_ips $rpaf_conf)
-        new_ips=$(echo "$rpaf_str" | sed "s/$ip//")
+        new_ips=$(echo "$ips" | sed "s/ $ip//")
         sed -i "s/$ips/$new_ips/g" $rpaf_conf
         sed -i "s/$ips/$new_ips/g" $rpaf_conf
+
+        # Remove RPAFproxy_ips line when ip list is empty
+        [ "$(grep RPAFproxy_ips $rpaf_conf | sed 's/^[[:space:]]*//g')" = "RPAFproxy_ips" ] && sed -i "/RPAFproxy_ips/d" $rpaf_conf
     fi
     fi
     
     
     #mod_remoteip
     #mod_remoteip
     remoteip_conf="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
     remoteip_conf="/etc/$WEB_SYSTEM/mods-enabled/remoteip.conf"
     if [ -e "$remoteip_conf" ]; then
     if [ -e "$remoteip_conf" ]; then
-        sed -i "s/RemoteIPInternalProxy $ip//g" $remoteip_conf
+        sed -i "/RemoteIPInternalProxy $ip\$/d" $remoteip_conf
     fi
     fi
 fi
 fi