mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Added comparison of gravity.list with Whitelist.txt and Blacklist.txt.
Added additional echos to help read the debug file. TODO: testNslookup function
This commit is contained in:
parent
00f46dc149
commit
86eafe7a33
1 changed files with 119 additions and 43 deletions
|
@ -12,22 +12,32 @@
|
||||||
|
|
||||||
# Nate Brandeburg
|
# Nate Brandeburg
|
||||||
# nate@ubiquisoft.com
|
# nate@ubiquisoft.com
|
||||||
# 3/19/2016
|
# 3/24/2016
|
||||||
|
|
||||||
######## GLOBAL VARS ########
|
######## GLOBAL VARS ########
|
||||||
DEBUG_LOG="/var/log/pihole_debug.log"
|
DEBUG_LOG="/var/log/pihole_debug.log"
|
||||||
|
DNSMASQFILE="/etc/dnsmasq.conf"
|
||||||
|
PIHOLECONFFILE="/etc/dnsmasq.d/01-pihole.conf"
|
||||||
|
LIGHTTPDFILE="/etc/lighttpd/lighttpd.conf"
|
||||||
|
GRAVITYFILE="/etc/pihole/gravity.list"
|
||||||
|
HOSTSFILE="/etc/hosts"
|
||||||
|
WHITELISTFILE="/etc/pihole/whitelist.txt"
|
||||||
|
BLACKLISTFILE="/etc/pihole/blacklist.txt"
|
||||||
|
ADLISTSFILE="/etc/pihole/adlists.list"
|
||||||
|
PIHOLELOG="/var/log/pihole.log"
|
||||||
|
|
||||||
|
|
||||||
######## FIRST CHECK ########
|
######## FIRST CHECK ########
|
||||||
# Must be root to debug
|
# Must be root to debug
|
||||||
if [[ $EUID -eq 0 ]];then
|
if [[ $EUID -eq 0 ]];then
|
||||||
echo "::: You are root... Beginning debug!"
|
echo "You are root... Beginning debug!"
|
||||||
else
|
else
|
||||||
echo "::: sudo will be used for debugging."
|
echo "sudo will be used for debugging."
|
||||||
# Check if sudo is actually installed
|
# Check if sudo is actually installed
|
||||||
if [[ $(dpkg-query -s sudo) ]];then
|
if [[ $(dpkg-query -s sudo) ]];then
|
||||||
export SUDO="sudo"
|
export SUDO="sudo"
|
||||||
else
|
else
|
||||||
echo "::: Please install sudo or run this as root."
|
echo "Please install sudo or run this as root."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -42,6 +52,32 @@ else
|
||||||
truncate -s 0 $DEBUG_LOG
|
truncate -s 0 $DEBUG_LOG
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
### Private functions exist here ###
|
||||||
|
function compareWhitelist {
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
echo "######## Whitelist Comparison #########" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
while read -r line; do
|
||||||
|
grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG
|
||||||
|
done < "$WHITELISTFILE"
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
}
|
||||||
|
|
||||||
|
function compareBlacklist {
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
echo "######## Blacklist Comparison #########" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
while read -r line; do
|
||||||
|
grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG
|
||||||
|
done < "$BLACKLISTFILE"
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
}
|
||||||
|
|
||||||
|
function testNslookup {
|
||||||
|
# TODO: This will pull a non-matched entry from gravity.list to compare with the nslookup against Google's NS.
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
}
|
||||||
|
|
||||||
### Check Pi internet connections ###
|
### Check Pi internet connections ###
|
||||||
# Log the IP addresses of this Pi
|
# Log the IP addresses of this Pi
|
||||||
IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e')
|
IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e')
|
||||||
|
@ -57,20 +93,78 @@ echo "$GATEWAY_CHECK" >> $DEBUG_LOG
|
||||||
echo >> $DEBUG_LOG
|
echo >> $DEBUG_LOG
|
||||||
|
|
||||||
echo "Writing dnsmasq.conf to debug log..."
|
echo "Writing dnsmasq.conf to debug log..."
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
echo "############### Dnsmasq ###############" >> $DEBUG_LOG
|
echo "############### Dnsmasq ###############" >> $DEBUG_LOG
|
||||||
DNSMASQFILE="/etc/dnsmasq.conf"
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
if [ -e "$DNSMASQFILE" ]
|
if [ -e "$DNSMASQFILE" ]
|
||||||
then
|
then
|
||||||
cat $DNSMASQFILE >> $DEBUG_LOG
|
#cat $DNSMASQFILE >> $DEBUG_LOG
|
||||||
|
while read -r line; do
|
||||||
|
[[ "$line" =~ ^#.*$ ]] && continue
|
||||||
|
echo "$line" >> $DEBUG_LOG
|
||||||
|
done < "$DNSMASQFILE"
|
||||||
echo >> $DEBUG_LOG
|
echo >> $DEBUG_LOG
|
||||||
else
|
else
|
||||||
echo "No dnsmasq.conf file found!" >> $DEBUG_LOG
|
echo "No dnsmasq.conf file found!" >> $DEBUG_LOG
|
||||||
echo "No dnsmasq.conf file found!"
|
echo "No dnsmasq.conf file found!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Writing 01-pihole.conf to debug log..."
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
echo "########### 01-pihole.conf ############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
if [ -e "$PIHOLECONFFILE" ]
|
||||||
|
then
|
||||||
|
#cat "$PIHOLECONFFILE" >> $DEBUG_LOG
|
||||||
|
while read -r line; do
|
||||||
|
[[ "$line" =~ ^#.*$ ]] && continue
|
||||||
|
echo "$line" >> $DEBUG_LOG
|
||||||
|
done < "$PIHOLECONFFILE"
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
else
|
||||||
|
echo "No 01-pihole.conf file found!" >> $DEBUG_LOG
|
||||||
|
echo "No 01-pihole.conf file found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Writing lighttpd.conf to debug log..."
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
echo "############ lighttpd.conf ############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
if [ -e "$LIGHTTPDFILE" ]
|
||||||
|
then
|
||||||
|
#cat "$PIHOLECONFFILE" >> $DEBUG_LOG
|
||||||
|
while read -r line; do
|
||||||
|
[[ "$line" =~ ^#.*$ ]] && continue
|
||||||
|
echo "$line" >> $DEBUG_LOG
|
||||||
|
done < "$LIGHTTPDFILE"
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
else
|
||||||
|
echo "No lighttpd.conf file found!" >> $DEBUG_LOG
|
||||||
|
echo "No lighttpd.conf file found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Writing size of gravity.list to debug log..."
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
echo "############ gravity.list #############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
if [ -e "$GRAVITYFILE" ]
|
||||||
|
then
|
||||||
|
wc -l "$GRAVITYFILE" >> $DEBUG_LOG
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
else
|
||||||
|
echo "No gravity.list file found!" >> $DEBUG_LOG
|
||||||
|
echo "No gravity.list file found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Write the hostname output to compare against entries in /etc/hosts, which is logged next
|
||||||
|
echo "Hostname of this pihole is: " >> $DEBUG_LOG
|
||||||
|
hostname >> $DEBUG_LOG
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
|
||||||
echo "Writing hosts file to debug log..."
|
echo "Writing hosts file to debug log..."
|
||||||
echo "############### Hosts ###############" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
HOSTSFILE="/etc/hosts"
|
echo "################ Hosts ################" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
if [ -e "$HOSTSFILE" ]
|
if [ -e "$HOSTSFILE" ]
|
||||||
then
|
then
|
||||||
cat "$HOSTSFILE" >> $DEBUG_LOG
|
cat "$HOSTSFILE" >> $DEBUG_LOG
|
||||||
|
@ -83,8 +177,9 @@ fi
|
||||||
### PiHole application specific logging ###
|
### PiHole application specific logging ###
|
||||||
# Write Pi-Hole logs to debug log
|
# Write Pi-Hole logs to debug log
|
||||||
echo "Writing whitelist to debug log..."
|
echo "Writing whitelist to debug log..."
|
||||||
echo "############### Whitelist ###############" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
WHITELISTFILE="/etc/pihole/whitelist.txt"
|
echo "############## Whitelist ##############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
if [ -e "$WHITELISTFILE" ]
|
if [ -e "$WHITELISTFILE" ]
|
||||||
then
|
then
|
||||||
cat "$WHITELISTFILE" >> $DEBUG_LOG
|
cat "$WHITELISTFILE" >> $DEBUG_LOG
|
||||||
|
@ -95,8 +190,9 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Writing blacklist to debug log..."
|
echo "Writing blacklist to debug log..."
|
||||||
echo "############### Blacklist ###############" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
BLACKLISTFILE="/etc/pihole/blacklist.txt"
|
echo "############## Blacklist ##############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
if [ -e "$BLACKLISTFILE" ]
|
if [ -e "$BLACKLISTFILE" ]
|
||||||
then
|
then
|
||||||
cat "$BLACKLISTFILE" >> $DEBUG_LOG
|
cat "$BLACKLISTFILE" >> $DEBUG_LOG
|
||||||
|
@ -107,8 +203,9 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Writing adlists.list to debug log..."
|
echo "Writing adlists.list to debug log..."
|
||||||
echo "############### adlists.list ###############" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
ADLISTSFILE="/etc/pihole/adlists.list"
|
echo "############ adlists.list #############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
if [ -e "$ADLISTSFILE" ]
|
if [ -e "$ADLISTSFILE" ]
|
||||||
then
|
then
|
||||||
cat "$ADLISTSFILE" >> $DEBUG_LOG
|
cat "$ADLISTSFILE" >> $DEBUG_LOG
|
||||||
|
@ -123,8 +220,9 @@ fi
|
||||||
function dumpPiHoleLog {
|
function dumpPiHoleLog {
|
||||||
trap '{ echo -e "\nFinishing debug write from interrupt... Quitting!" ; exit 1; }' INT
|
trap '{ echo -e "\nFinishing debug write from interrupt... Quitting!" ; exit 1; }' INT
|
||||||
echo -e "Writing current pihole traffic to debug log...\nTry loading any/all sites that you are having trouble with now... (Press ctrl+C to finish)"
|
echo -e "Writing current pihole traffic to debug log...\nTry loading any/all sites that you are having trouble with now... (Press ctrl+C to finish)"
|
||||||
echo "############### pihole.log ###############" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
PIHOLELOG="/var/log/pihole.log"
|
echo "############# pihole.log ##############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
if [ -e "$PIHOLELOG" ]
|
if [ -e "$PIHOLELOG" ]
|
||||||
then
|
then
|
||||||
while true; do
|
while true; do
|
||||||
|
@ -137,33 +235,11 @@ function dumpPiHoleLog {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function finalWrites {
|
# Anything to be done after capturing of pihole.log terminates
|
||||||
# Write the 01-pihole.conf from /etc/dnsmasq.d/ to the debug log
|
function finalWork {
|
||||||
echo "Writing 01-pihole.conf to debug log..."
|
echo "Finshed debugging!"
|
||||||
echo "############### 01-pihole.conf ###############" >> $DEBUG_LOG
|
|
||||||
PIHOLECONFFILE="/etc/dnsmasq.d/01-pihole.conf"
|
|
||||||
if [ -e "$PIHOLECONFFILE" ]
|
|
||||||
then
|
|
||||||
cat "$PIHOLECONFFILE" >> $DEBUG_LOG
|
|
||||||
echo >> $DEBUG_LOG
|
|
||||||
else
|
|
||||||
echo "No 01-pihole.conf file found!" >> $DEBUG_LOG
|
|
||||||
echo "No 01-pihole.conf file found"
|
|
||||||
fi
|
|
||||||
# Write the gravity.list after the user is finished capturing the pihole.log output
|
|
||||||
echo "Writing gravity.list to debug log..."
|
|
||||||
echo "############### gravity.list ###############" >> $DEBUG_LOG
|
|
||||||
GRAVITYFILE="/etc/pihole/gravity.list"
|
|
||||||
if [ -e "$GRAVITYFILE" ]
|
|
||||||
then
|
|
||||||
cat "$GRAVITYFILE" >> $DEBUG_LOG
|
|
||||||
echo >> $DEBUG_LOG
|
|
||||||
else
|
|
||||||
echo "No gravity.list file found!" >> $DEBUG_LOG
|
|
||||||
echo "No gravity.list file found"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
trap finalWrites EXIT
|
trap finalWork EXIT
|
||||||
|
|
||||||
### Method calls for additinal logging ###
|
### Method calls for additional logging ###
|
||||||
dumpPiHoleLog
|
dumpPiHoleLog
|
||||||
|
|
Loading…
Reference in a new issue