mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-03 03:23:19 +00:00
Convert whitelist and blacklist to 0.0.0.0
This commit is contained in:
parent
b3376f1066
commit
615bb8f77b
2 changed files with 18 additions and 40 deletions
|
@ -27,12 +27,8 @@ versbose=true
|
||||||
domList=()
|
domList=()
|
||||||
domToRemoveList=()
|
domToRemoveList=()
|
||||||
|
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
piholeIP="0.0.0.0"
|
||||||
|
piholeIPv6="::"
|
||||||
# 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%/*}
|
|
||||||
|
|
||||||
modifyHost=false
|
modifyHost=false
|
||||||
|
|
||||||
|
@ -42,13 +38,6 @@ if [[ -r $piholeDir/pihole.conf ]];then
|
||||||
. $piholeDir/pihole.conf
|
. $piholeDir/pihole.conf
|
||||||
fi
|
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()
|
function helpFunc()
|
||||||
{
|
{
|
||||||
echo "::: Immediately blacklists one or more domains in the hosts file"
|
echo "::: Immediately blacklists one or more domains in the hosts file"
|
||||||
|
|
|
@ -27,12 +27,8 @@ versbose=true
|
||||||
domList=()
|
domList=()
|
||||||
domToRemoveList=()
|
domToRemoveList=()
|
||||||
|
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
piholeIP="0.0.0.0"
|
||||||
|
piholeIPv6="::"
|
||||||
# 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%/*}
|
|
||||||
|
|
||||||
modifyHost=false
|
modifyHost=false
|
||||||
|
|
||||||
|
@ -42,12 +38,6 @@ if [[ -r $piholeDir/pihole.conf ]];then
|
||||||
. $piholeDir/pihole.conf
|
. $piholeDir/pihole.conf
|
||||||
fi
|
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()
|
function helpFunc()
|
||||||
{
|
{
|
||||||
echo "::: Immediately whitelists one or more domains in the hosts file"
|
echo "::: Immediately whitelists one or more domains in the hosts file"
|
||||||
|
@ -133,20 +123,19 @@ function ModifyHostFile(){
|
||||||
if $addmode; then
|
if $addmode; then
|
||||||
#remove domains in from hosts file
|
#remove domains in from hosts file
|
||||||
if [[ -r $whitelist ]];then
|
if [[ -r $whitelist ]];then
|
||||||
# Remove whitelist entries
|
# Remove whitelist entries
|
||||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
echo ":::"
|
echo ":::"
|
||||||
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
|
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 "$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
|
awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
|
||||||
echo "l" >> /etc/pihole/whitelist.tmp
|
echo "l" >> /etc/pihole/whitelist.tmp
|
||||||
grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp
|
grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp
|
||||||
rm $adList
|
rm $adList
|
||||||
mv $piholeDir/gravity.tmp $adList
|
mv $piholeDir/gravity.tmp $adList
|
||||||
rm $piholeDir/whitelist.tmp
|
rm $piholeDir/whitelist.tmp
|
||||||
echo " done!"
|
echo " done!"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
#we need to add the removed domains to the hosts file
|
#we need to add the removed domains to the hosts file
|
||||||
|
@ -195,7 +184,7 @@ do
|
||||||
"-d" | "--delmode" ) addmode=false;;
|
"-d" | "--delmode" ) addmode=false;;
|
||||||
"-f" | "--force" ) force=true;;
|
"-f" | "--force" ) force=true;;
|
||||||
"-q" | "--quiet" ) versbose=false;;
|
"-q" | "--quiet" ) versbose=false;;
|
||||||
"-h" | "--help" ) helpFunc;;
|
"-h" | "--help" ) helpFunc;;
|
||||||
* ) HandleOther "$var";;
|
* ) HandleOther "$var";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue