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@ubiquisoft.com
|
||||
# 3/19/2016
|
||||
# 3/24/2016
|
||||
|
||||
######## GLOBAL VARS ########
|
||||
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 ########
|
||||
# Must be root to debug
|
||||
if [[ $EUID -eq 0 ]];then
|
||||
echo "::: You are root... Beginning debug!"
|
||||
echo "You are root... Beginning debug!"
|
||||
else
|
||||
echo "::: sudo will be used for debugging."
|
||||
echo "sudo will be used for debugging."
|
||||
# Check if sudo is actually installed
|
||||
if [[ $(dpkg-query -s sudo) ]];then
|
||||
export SUDO="sudo"
|
||||
else
|
||||
echo "::: Please install sudo or run this as root."
|
||||
echo "Please install sudo or run this as root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
@ -42,6 +52,32 @@ else
|
|||
truncate -s 0 $DEBUG_LOG
|
||||
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 ###
|
||||
# Log the IP addresses of this Pi
|
||||
IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e')
|
||||
|
@ -57,20 +93,78 @@ echo "$GATEWAY_CHECK" >> $DEBUG_LOG
|
|||
echo >> $DEBUG_LOG
|
||||
|
||||
echo "Writing dnsmasq.conf to debug log..."
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############### Dnsmasq ###############" >> $DEBUG_LOG
|
||||
DNSMASQFILE="/etc/dnsmasq.conf"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
if [ -e "$DNSMASQFILE" ]
|
||||
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
|
||||
else
|
||||
echo "No dnsmasq.conf file found!" >> $DEBUG_LOG
|
||||
echo "No dnsmasq.conf file found!"
|
||||
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 "############### Hosts ###############" >> $DEBUG_LOG
|
||||
HOSTSFILE="/etc/hosts"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "################ Hosts ################" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
if [ -e "$HOSTSFILE" ]
|
||||
then
|
||||
cat "$HOSTSFILE" >> $DEBUG_LOG
|
||||
|
@ -83,8 +177,9 @@ fi
|
|||
### PiHole application specific logging ###
|
||||
# Write Pi-Hole logs to debug log
|
||||
echo "Writing whitelist to debug log..."
|
||||
echo "############### Whitelist ###############" >> $DEBUG_LOG
|
||||
WHITELISTFILE="/etc/pihole/whitelist.txt"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############## Whitelist ##############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
if [ -e "$WHITELISTFILE" ]
|
||||
then
|
||||
cat "$WHITELISTFILE" >> $DEBUG_LOG
|
||||
|
@ -95,8 +190,9 @@ else
|
|||
fi
|
||||
|
||||
echo "Writing blacklist to debug log..."
|
||||
echo "############### Blacklist ###############" >> $DEBUG_LOG
|
||||
BLACKLISTFILE="/etc/pihole/blacklist.txt"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############## Blacklist ##############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
if [ -e "$BLACKLISTFILE" ]
|
||||
then
|
||||
cat "$BLACKLISTFILE" >> $DEBUG_LOG
|
||||
|
@ -107,8 +203,9 @@ else
|
|||
fi
|
||||
|
||||
echo "Writing adlists.list to debug log..."
|
||||
echo "############### adlists.list ###############" >> $DEBUG_LOG
|
||||
ADLISTSFILE="/etc/pihole/adlists.list"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############ adlists.list #############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
if [ -e "$ADLISTSFILE" ]
|
||||
then
|
||||
cat "$ADLISTSFILE" >> $DEBUG_LOG
|
||||
|
@ -123,8 +220,9 @@ fi
|
|||
function dumpPiHoleLog {
|
||||
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 "############### pihole.log ###############" >> $DEBUG_LOG
|
||||
PIHOLELOG="/var/log/pihole.log"
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
echo "############# pihole.log ##############" >> $DEBUG_LOG
|
||||
echo "#######################################" >> $DEBUG_LOG
|
||||
if [ -e "$PIHOLELOG" ]
|
||||
then
|
||||
while true; do
|
||||
|
@ -137,33 +235,11 @@ function dumpPiHoleLog {
|
|||
fi
|
||||
}
|
||||
|
||||
function finalWrites {
|
||||
# Write the 01-pihole.conf from /etc/dnsmasq.d/ to the debug log
|
||||
echo "Writing 01-pihole.conf to debug log..."
|
||||
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
|
||||
# Anything to be done after capturing of pihole.log terminates
|
||||
function finalWork {
|
||||
echo "Finshed debugging!"
|
||||
}
|
||||
trap finalWrites EXIT
|
||||
trap finalWork EXIT
|
||||
|
||||
### Method calls for additinal logging ###
|
||||
### Method calls for additional logging ###
|
||||
dumpPiHoleLog
|
||||
|
|
Loading…
Reference in a new issue