mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Merge pull request #29 from Fourdee/master
Patch 3 - Dont use /etc/hosts
This commit is contained in:
commit
5ed08b44a5
4 changed files with 8 additions and 12 deletions
|
@ -11,13 +11,13 @@ do
|
||||||
uptime | cut -d' ' -f11-
|
uptime | cut -d' ' -f11-
|
||||||
echo "-------------------------------"
|
echo "-------------------------------"
|
||||||
# Uncomment to continually read the log file and display the current domain being blocked
|
# Uncomment to continually read the log file and display the current domain being blocked
|
||||||
#tail -f /var/log/pihole.log | awk '/\/etc\/hosts/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/hosts") print $7; else;}'
|
#tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}'
|
||||||
|
|
||||||
today=$(date "+%b %e")
|
today=$(date "+%b %e")
|
||||||
todaysQueryCount=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ {print $7}' | wc -l)
|
todaysQueryCount=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ {print $7}' | wc -l)
|
||||||
todaysQueryCountV4=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[A\]/ {print $7}' | wc -l)
|
todaysQueryCountV4=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[A\]/ {print $7}' | wc -l)
|
||||||
todaysQueryCountV6=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[AAAA\]/ {print $7}' | wc -l)
|
todaysQueryCountV6=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[AAAA\]/ {print $7}' | wc -l)
|
||||||
todaysAdsEliminated=$(cat /var/log/pihole.log | grep "$today" | awk '/\/etc\/hosts/ {print $7}' | wc -l)
|
todaysAdsEliminated=$(cat /var/log/pihole.log | grep "$today" | awk '/\/etc\/pihole\/gravity.list/ {print $7}' | wc -l)
|
||||||
dividend=$(echo "$todaysAdsEliminated/$todaysQueryCount" | bc -l)
|
dividend=$(echo "$todaysAdsEliminated/$todaysQueryCount" | bc -l)
|
||||||
fp=$(echo "$dividend*100" | bc -l)
|
fp=$(echo "$dividend*100" | bc -l)
|
||||||
percentAds=$(echo ${fp:0:4})
|
percentAds=$(echo ${fp:0:4})
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
for var in "$@"
|
for var in "$@"
|
||||||
do
|
do
|
||||||
echo "Whitelisting $var..."
|
echo "Whitelisting $var..."
|
||||||
# Use sed to search for the domain in /etc/hosts and remove it using an in-place edit
|
# Use sed to search for the domain in /etc/pihole/gravity.list and remove it using an in-place edit
|
||||||
sed -i "/$var/d" /etc/hosts
|
sed -i "/$var/d" /etc/pihole/gravity.list
|
||||||
# Also add the domain to the whitelist.txt in /etc/pihole
|
# Also add the domain to the whitelist.txt in /etc/pihole
|
||||||
echo "$var" >> /etc/pihole/whitelist.txt
|
echo "$var" >> /etc/pihole/whitelist.txt
|
||||||
done
|
done
|
||||||
echo "** $# domain(s) whitelisted."
|
echo "** $# domain(s) whitelisted."
|
||||||
# Force dnsmasq to reload /etc/hosts
|
# Force dnsmasq to reload /etc/pihole/gravity.list
|
||||||
kill -HUP $(pidof dnsmasq)
|
kill -HUP $(pidof dnsmasq)
|
|
@ -1,3 +1,4 @@
|
||||||
|
addn-hosts=/etc/pihole/gravity.list
|
||||||
domain-needed
|
domain-needed
|
||||||
bogus-priv
|
bogus-priv
|
||||||
no-resolv
|
no-resolv
|
||||||
|
|
|
@ -16,7 +16,7 @@ sources=('https://adaway.org/hosts.txt'
|
||||||
'http://winhelp2002.mvps.org/hosts.txt')
|
'http://winhelp2002.mvps.org/hosts.txt')
|
||||||
|
|
||||||
# Variables for various stages of downloading and formatting the list
|
# Variables for various stages of downloading and formatting the list
|
||||||
adList=/etc/hosts
|
adList=/etc/pihole/gravity.list
|
||||||
origin=/etc/pihole
|
origin=/etc/pihole
|
||||||
piholeDir=/etc/pihole
|
piholeDir=/etc/pihole
|
||||||
if [[ -f $piholeDir/pihole.conf ]];then
|
if [[ -f $piholeDir/pihole.conf ]];then
|
||||||
|
@ -101,12 +101,7 @@ function gravity_advanced()
|
||||||
# Format domain list as "192.168.x.x domain.com"
|
# Format domain list as "192.168.x.x domain.com"
|
||||||
echo "** Formatting domains into a HOSTS file..."
|
echo "** Formatting domains into a HOSTS file..."
|
||||||
cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"'" $0}' > $origin/$accretionDisc
|
cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"'" $0}' > $origin/$accretionDisc
|
||||||
# Put the default host entries at the top of the file
|
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
||||||
echo "::1 localhost" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc
|
|
||||||
echo "255.255.255.255 broadcasthost" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc
|
|
||||||
echo "127.0.0.1 localhost" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc
|
|
||||||
echo "127.0.0.1 $(hostname)" | cat - $origin/$accretionDisc > $origin/latent.$accretionDisc && mv $origin/latent.$accretionDisc $origin/$accretionDisc
|
|
||||||
# Copy the file over as /etc/hosts so dnsmasq can use it
|
|
||||||
sudo cp $origin/$accretionDisc $adList
|
sudo cp $origin/$accretionDisc $adList
|
||||||
kill -HUP $(pidof dnsmasq)
|
kill -HUP $(pidof dnsmasq)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue