From 3affa73257bcd7cb711a1448019d8e6fc6f0cb0d Mon Sep 17 00:00:00 2001 From: diginc Date: Wed, 20 Jul 2016 12:43:30 -0500 Subject: [PATCH 1/2] Only re-block whitelist deletions if in adlists * Prevent blocking benign/untracked domains deleted off whitelist * Issue #581 --- advanced/Scripts/whitelist.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 266ac49e..d43f2e45 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -175,20 +175,23 @@ function ModifyHostFile(){ echo ":::" echo "::: Modifying HOSTS file to un-whitelist domains..." for rdom in "${domToRemoveList[@]}" - do - if [[ -n $piholeIPv6 ]];then - echo -n "::: Un-whitelisting $rdom on IPv4 and IPv6..." - echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList - echo " done!" - else - echo -n "::: Un-whitelisting $rdom on IPv4" - echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList - echo " done!" - fi - echo -n "::: Removing $rdom from $whitelist..." - echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist - echo " done!" - done + do + if grep -q "$rdom" /etc/pihole/*.domains; then + echo "::: AdLists contain $rdom, re-adding block" + if [[ -n $piholeIPv6 ]];then + echo -n "::: Restoring block for $rdom on IPv4 and IPv6..." + echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList + echo " done!" + else + echo -n "::: Restoring block for $rdom on IPv4" + echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList + echo " done!" + fi + fi + echo -n "::: Removing $rdom from $whitelist..." + echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist + echo " done!" + done fi } From 5fb6c5b01209fe7c99e3e6e271e814272c44a270 Mon Sep 17 00:00:00 2001 From: diginc Date: Wed, 20 Jul 2016 12:53:31 -0500 Subject: [PATCH 2/2] Making the whitelist re-block echo consistent with other WL/BL echos --- advanced/Scripts/whitelist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index d43f2e45..5195aa83 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -183,7 +183,7 @@ function ModifyHostFile(){ echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList echo " done!" else - echo -n "::: Restoring block for $rdom on IPv4" + echo -n "::: Restoring block for $rdom on IPv4..." echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList echo " done!" fi