From 615bb8f77bc6d0010759f2d013b927a05582c520 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 20 Apr 2016 16:26:34 -0400 Subject: [PATCH] Convert whitelist and blacklist to 0.0.0.0 --- advanced/Scripts/blacklist.sh | 15 ++---------- advanced/Scripts/whitelist.sh | 43 +++++++++++++---------------------- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index fe6d42f3..56749f92 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -27,12 +27,8 @@ versbose=true domList=() domToRemoveList=() -piholeIPv6file=/etc/pihole/.useIPv6 - -# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script -IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') -piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') -piholeIP=${piholeIPCIDR%/*} +piholeIP="0.0.0.0" +piholeIPv6="::" modifyHost=false @@ -42,13 +38,6 @@ if [[ -r $piholeDir/pihole.conf ]];then . $piholeDir/pihole.conf fi - -if [[ -f $piholeIPv6file ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') -fi - - function helpFunc() { echo "::: Immediately blacklists one or more domains in the hosts file" diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index bf58b100..e8506d64 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -27,12 +27,8 @@ versbose=true domList=() domToRemoveList=() -piholeIPv6file=/etc/pihole/.useIPv6 - -# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script -IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') -piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') -piholeIP=${piholeIPCIDR%/*} +piholeIP="0.0.0.0" +piholeIPv6="::" modifyHost=false @@ -42,12 +38,6 @@ if [[ -r $piholeDir/pihole.conf ]];then . $piholeDir/pihole.conf fi -if [[ -f $piholeIPv6file ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') -fi - - function helpFunc() { echo "::: Immediately whitelists one or more domains in the hosts file" @@ -133,20 +123,19 @@ function ModifyHostFile(){ if $addmode; then #remove domains in from hosts file if [[ -r $whitelist ]];then - # Remove whitelist entries - numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l) - plural=; [[ "$numberOf" != "1" ]] && plural=s - echo ":::" - echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." - awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp - awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp - echo "l" >> /etc/pihole/whitelist.tmp - grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp - rm $adList - mv $piholeDir/gravity.tmp $adList - rm $piholeDir/whitelist.tmp - echo " done!" - + # Remove whitelist entries + numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l) + plural=; [[ "$numberOf" != "1" ]] && plural=s + echo ":::" + echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." + awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp + awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp + echo "l" >> /etc/pihole/whitelist.tmp + grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp + rm $adList + mv $piholeDir/gravity.tmp $adList + rm $piholeDir/whitelist.tmp + echo " done!" fi else #we need to add the removed domains to the hosts file @@ -195,7 +184,7 @@ do "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; "-q" | "--quiet" ) versbose=false;; - "-h" | "--help" ) helpFunc;; + "-h" | "--help" ) helpFunc;; * ) HandleOther "$var";; esac done