mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 10:43:55 +00:00
Added test for nslookup
Checks the TESTURL for nslookup is not whitelisted
This commit is contained in:
parent
8f8dc66c70
commit
b4463bf42c
1 changed files with 40 additions and 6 deletions
|
@ -25,16 +25,17 @@ WHITELISTFILE="/etc/pihole/whitelist.txt"
|
||||||
BLACKLISTFILE="/etc/pihole/blacklist.txt"
|
BLACKLISTFILE="/etc/pihole/blacklist.txt"
|
||||||
ADLISTSFILE="/etc/pihole/adlists.list"
|
ADLISTSFILE="/etc/pihole/adlists.list"
|
||||||
PIHOLELOG="/var/log/pihole.log"
|
PIHOLELOG="/var/log/pihole.log"
|
||||||
|
WHITELISTMATCHES="/tmp/whitelistmatches.list"
|
||||||
|
|
||||||
|
|
||||||
######## 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."
|
||||||
|
@ -43,8 +44,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure the file exists, create if not, clear if exists.
|
# Ensure the file exists, create if not, clear if exists.
|
||||||
if [ ! -f "$DEBUG_LOG" ]
|
if [ ! -f "$DEBUG_LOG" ]; then
|
||||||
then
|
|
||||||
$SUDO touch $DEBUG_LOG
|
$SUDO touch $DEBUG_LOG
|
||||||
$SUDO chmod 644 $DEBUG_LOG
|
$SUDO chmod 644 $DEBUG_LOG
|
||||||
$SUDO chown "$USER":root $DEBUG_LOG
|
$SUDO chown "$USER":root $DEBUG_LOG
|
||||||
|
@ -54,11 +54,21 @@ fi
|
||||||
|
|
||||||
### Private functions exist here ###
|
### Private functions exist here ###
|
||||||
function compareWhitelist {
|
function compareWhitelist {
|
||||||
|
if [ ! -f "$WHITELISTMATCHES" ]; then
|
||||||
|
$SUDO touch $WHITELISTMATCHES
|
||||||
|
$SUDO chmod 644 $WHITELISTMATCHES
|
||||||
|
$SUDO chown "$USER":root $WHITELISTMATCHES
|
||||||
|
else
|
||||||
|
truncate -s 0 $WHITELISTMATCHES
|
||||||
|
fi
|
||||||
|
|
||||||
echo "#######################################" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
echo "######## Whitelist Comparison #########" >> $DEBUG_LOG
|
echo "######## Whitelist Comparison #########" >> $DEBUG_LOG
|
||||||
echo "#######################################" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG
|
TMP=$(grep -w ".* $line$" "$GRAVITYFILE")
|
||||||
|
echo "$TMP" >> $DEBUG_LOG
|
||||||
|
echo "$TMP" >> $WHITELISTMATCHES
|
||||||
done < "$WHITELISTFILE"
|
done < "$WHITELISTFILE"
|
||||||
echo >> $DEBUG_LOG
|
echo >> $DEBUG_LOG
|
||||||
}
|
}
|
||||||
|
@ -74,7 +84,28 @@ function compareBlacklist {
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNslookup {
|
function testNslookup {
|
||||||
# TODO: This will pull a non-matched entry from gravity.list to compare with the nslookup against Google's NS.
|
TESTURL=""
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
echo "############ NSLookup Test ############" >> $DEBUG_LOG
|
||||||
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
|
# Find a blocked url that has not been whitelisted.
|
||||||
|
while read -r line; do
|
||||||
|
CUTURL=$("$line" | cut -d " " -f2-)
|
||||||
|
if [ "$CUTURL" != "Pi-Hole.IsWorking.OK" ]; then
|
||||||
|
while read -r line2; do
|
||||||
|
CUTURL2=$("$line2" | cut -d " " -f2-)
|
||||||
|
if [ "$CUTURL" != "$CUTURL2" ]; then
|
||||||
|
TESTURL="$CUTURL"
|
||||||
|
fi
|
||||||
|
done < "WHITELISTMATCHES"
|
||||||
|
fi
|
||||||
|
done < "GRAVITYFILE"
|
||||||
|
|
||||||
|
echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG
|
||||||
|
echo nslookup "$TESTURL" >> $DEBUG_LOG
|
||||||
|
echo >> $DEBUG_LOG
|
||||||
|
echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG
|
||||||
|
echo nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG
|
||||||
echo >> $DEBUG_LOG
|
echo >> $DEBUG_LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +123,9 @@ echo "Gateway check:" >> $DEBUG_LOG
|
||||||
echo "$GATEWAY_CHECK" >> $DEBUG_LOG
|
echo "$GATEWAY_CHECK" >> $DEBUG_LOG
|
||||||
echo >> $DEBUG_LOG
|
echo >> $DEBUG_LOG
|
||||||
|
|
||||||
|
# Test the nslookup here
|
||||||
|
testNslookup
|
||||||
|
|
||||||
echo "Writing dnsmasq.conf to debug log..."
|
echo "Writing dnsmasq.conf to debug log..."
|
||||||
echo "#######################################" >> $DEBUG_LOG
|
echo "#######################################" >> $DEBUG_LOG
|
||||||
echo "############### Dnsmasq ###############" >> $DEBUG_LOG
|
echo "############### Dnsmasq ###############" >> $DEBUG_LOG
|
||||||
|
|
Loading…
Reference in a new issue