From 60c0e59a83f7d878535fbdce2a0d9bfac8c2ac9f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 18:06:31 -0700 Subject: [PATCH 01/18] Add IPv6 intelligence to debug --- advanced/Scripts/piholeDebug.sh | 85 ++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index d003c1a4..b63244c4 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -3,7 +3,7 @@ # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi # http://pi-hole.net -# Generates pihole_debug.log in /var/log/ to be used for troubleshooting. +# Generates pihole_debug.log to be used for troubleshooting. # # Pi-hole is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -25,18 +25,27 @@ ADLISTSFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" +# Header info and introduction +echo "::: Beginning Pi-hole debug at $(date)!" +echo "::: This debugging process will collect information from your running configuration," +echo "::: and optionally upload the generated log to a unique and random directory on" +echo "::: Termbin.com. NOTE: All log files auto-delete after 1 month and you are the only" +echo "::: person who is given the unique URL. Please consider where you post this link." +echo "::: " + ######## FIRST CHECK ######## # Must be root to debug if [[ $EUID -eq 0 ]]; then - echo "::: You are root... Beginning debug!" + echo "::: Script is executing as root user..." else - echo "::: Sudo will be used for debugging." + echo "::: Non-root user detected..." # Check if sudo is actually installed if [ -x "$(command -v sudo)" ]; then export SUDO="sudo" + echo "::: sudo command located, debug will run under sudo." else - echo "::: Please install sudo or run this as root." + echo "::: Unable to locate sudo command. Please install sudo or run this as root." exit 1 fi fi @@ -52,27 +61,57 @@ fi ### Private functions exist here ### function versionCheck { - echo "#######################################" >> ${DEBUG_LOG} - echo "########## Versions Section ###########" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} - + echo "############################################################" >> ${DEBUG_LOG} + echo "########## Installed Versions ##########" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} + + echo "::: Detecting Pi-hole installed versions." TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) echo "Pi-hole Version: $TMP" >> ${DEBUG_LOG} - + + echo "::: Writing Pi-hole installed version to logfile." TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0) echo "WebUI Version: $TMP" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} } function distroCheck { - echo "#######################################" >> ${DEBUG_LOG} - echo "######## Distribution Section #########" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} - + echo "############################################################" >> ${DEBUG_LOG} + echo "######## Installed OS Distribution #########" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} + + echo "::: Checking installed OS Distribution release." TMP=$(cat /etc/*release || echo "Failed to find release") - echo "Distribution Version: $TMP" >> ${DEBUG_LOG} + + echo "::: Writing OS Distribution release to logfile." + echo "$TMP" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} +} + +function ipCheck { + echo "############################################################" >> ${DEBUG_LOG} + echo "######## IP Address Information #########" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} + + IPADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }') + echo "::: Writing local IPs to debug log" + echo "$IPADDR" >> ${DEBUG_LOG} + IP6ADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }') + echo "$IP6ADDR" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + + echo "::: Locating default gateway and checking connectivity" + GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) + GATEWAY_CHECK=$(ping -q -w 1 -c 1 "${GATEWAY}" > /dev/null && echo ok || echo error) + echo "Gateway check at ${GATEWAY}:" >> ${DEBUG_LOG} + echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} + + GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) + GATEWAY6_CHECK=$(ping6 -q -w 1 -c 1 "${GATEWAY6}" > /dev/null && echo ok || echo error) + echo "IPv6 Gateway check at ${GATEWAY6}:" >> ${DEBUG_LOG} + echo "$GATEWAY6_CHECK" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } - function compareWhitelist { if [ ! -f "$WHITELISTMATCHES" ]; then ${SUDO} touch ${WHITELISTMATCHES} @@ -186,22 +225,10 @@ function debugLighttpd { ### END FUNCTIONS ### -### Check Pi internet connections ### -# Log the IP addresses of this Pi -IPADDR=$(${SUDO} ifconfig | perl -nle 's/dr:(\S+)/print $1/e') -echo "::: Writing local IPs to debug log" -echo "IP Addresses of this Pi:" >> ${DEBUG_LOG} -echo "$IPADDR" >> ${DEBUG_LOG} -echo >> ${DEBUG_LOG} - -# Check if we can connect to the local gateway -GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error) -echo "Gateway check:" >> ${DEBUG_LOG} -echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} -echo >> ${DEBUG_LOG} versionCheck distroCheck +ipCheck compareWhitelist compareBlacklist testNslookup @@ -319,7 +346,7 @@ fi # Continuously append the pihole.log file to the pihole_debug.log file function dumpPiHoleLog { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT - echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" + echo -e "::: Writing current pi-hole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" echo "#######################################" >> ${DEBUG_LOG} echo "############# pihole.log ##############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} From 7729ddab3081a1074109009d2dd32573974699c6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 18:21:58 -0700 Subject: [PATCH 02/18] Mode code realignment. Handle lack of IPv6 gateway gracefully. --- advanced/Scripts/piholeDebug.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b63244c4..cccf45d6 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -93,8 +93,8 @@ function ipCheck { echo "######## IP Address Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} + echo "::: Writing local IPs to logfile" IPADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }') - echo "::: Writing local IPs to debug log" echo "$IPADDR" >> ${DEBUG_LOG} IP6ADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }') echo "$IP6ADDR" >> ${DEBUG_LOG} @@ -107,9 +107,12 @@ function ipCheck { echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) + if [ -n "$GATEWAY6" ] + then GATEWAY6_CHECK=$(ping6 -q -w 1 -c 1 "${GATEWAY6}" > /dev/null && echo ok || echo error) echo "IPv6 Gateway check at ${GATEWAY6}:" >> ${DEBUG_LOG} echo "$GATEWAY6_CHECK" >> ${DEBUG_LOG} + fi echo >> ${DEBUG_LOG} } function compareWhitelist { From c41d543d811c0a684c45a62b323e6165185cbc4b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 18:27:02 -0700 Subject: [PATCH 03/18] Handle lack of IPv6 gracefully. --- advanced/Scripts/piholeDebug.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index cccf45d6..f38947b9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -96,8 +96,12 @@ function ipCheck { echo "::: Writing local IPs to logfile" IPADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }') echo "$IPADDR" >> ${DEBUG_LOG} + IP6ADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }') + if [ -n "$IP6ADDR" ] + then echo "$IP6ADDR" >> ${DEBUG_LOG} + fi echo >> ${DEBUG_LOG} echo "::: Locating default gateway and checking connectivity" From 274b71f8bc3ccc1b359a889a3d2526951a0fe6c0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 18:52:12 -0700 Subject: [PATCH 04/18] Relocate hostname checks --- advanced/Scripts/piholeDebug.sh | 37 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index f38947b9..05f3cff8 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -119,6 +119,26 @@ function ipCheck { fi echo >> ${DEBUG_LOG} } + +function hostnameCheck { + # 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 "::: Writing hosts file to debug log..." + echo "#######################################" >> ${DEBUG_LOG} + echo "################ Hosts ################" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} + if [ -e "$HOSTSFILE" ] + then + cat "$HOSTSFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + else + echo "No hosts file found!" >> ${DEBUG_LOG} + printf ":::\tNo hosts file found!\n" + fi +} + function compareWhitelist { if [ ! -f "$WHITELISTMATCHES" ]; then ${SUDO} touch ${WHITELISTMATCHES} @@ -236,6 +256,7 @@ function debugLighttpd { versionCheck distroCheck ipCheck +hostnameCheck compareWhitelist compareBlacklist testNslookup @@ -292,22 +313,6 @@ else printf ":::\tNo gravity.list file found\n" 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 "::: Writing hosts file to debug log..." -echo "#######################################" >> ${DEBUG_LOG} -echo "################ Hosts ################" >> ${DEBUG_LOG} -echo "#######################################" >> ${DEBUG_LOG} -if [ -e "$HOSTSFILE" ] -then - cat "$HOSTSFILE" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} -else - echo "No hosts file found!" >> ${DEBUG_LOG} - printf ":::\tNo hosts file found!\n" -fi ### PiHole application specific logging ### echo "::: Writing whitelist to debug log..." From 874853fe1846e429c6caf5da44cb4d1fc1fddc89 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 19:23:30 -0700 Subject: [PATCH 05/18] Add lighttpd to version check --- advanced/Scripts/piholeDebug.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 05f3cff8..acdb699a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -72,6 +72,15 @@ function versionCheck { echo "::: Writing Pi-hole installed version to logfile." TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0) echo "WebUI Version: $TMP" >> ${DEBUG_LOG} + + echo "::: Writing lighttpd version to logfile." + light_ver=$(lighttpd -v | head -n1) + if [ -n light_ver ] + then + echo "${light_ver}" >> ${DEBUG_LOG} + else + echo "lighttpd not installed." >> ${DEBUG_LOG} + fi echo >> ${DEBUG_LOG} } @@ -121,14 +130,17 @@ function ipCheck { } function hostnameCheck { + echo "############################################################" >> ${DEBUG_LOG} + echo "######## Hostname Information #########" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} + + echo "::: Writing locally configured hostnames to logfile" # 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 "This Pi-hole is: $(hostname)" >> ${DEBUG_LOG} echo "::: Writing hosts file to debug log..." - echo "#######################################" >> ${DEBUG_LOG} - echo "################ Hosts ################" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} + echo "### Hosts ###" >> ${DEBUG_LOG} + if [ -e "$HOSTSFILE" ] then cat "$HOSTSFILE" >> ${DEBUG_LOG} From 014bdf911a11b0e40c79808cc694fa2d88ec4eb5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 20:39:39 -0700 Subject: [PATCH 06/18] Add open port detection --- advanced/Scripts/piholeDebug.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index acdb699a..7e08b24e 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -81,6 +81,15 @@ function versionCheck { else echo "lighttpd not installed." >> ${DEBUG_LOG} fi + + echo "::: Writing PHP version to logfile." + php_ver=$(php -v | head -n1) + if [ -n php_ver ] + then + echo "${php_ver}" >> ${DEBUG_LOG} + else + echo "PHP not installed." >> ${DEBUG_LOG} + fi echo >> ${DEBUG_LOG} } @@ -151,6 +160,17 @@ function hostnameCheck { fi } +function portCheck { + echo "############################################################" >> ${DEBUG_LOG} + echo "######## Open Port Information #########" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} + + echo "::: Writing local server ports to logfile" + + ${SUDO} netstat -tulpn >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} +} + function compareWhitelist { if [ ! -f "$WHITELISTMATCHES" ]; then ${SUDO} touch ${WHITELISTMATCHES} @@ -269,6 +289,7 @@ versionCheck distroCheck ipCheck hostnameCheck +portCheck compareWhitelist compareBlacklist testNslookup From 5bbb3ac49acd97bf50943638a03c70a98d2e2ff7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 20:50:03 -0700 Subject: [PATCH 07/18] Standardize Pi-hole naming. --- advanced/Scripts/piholeDebug.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 7e08b24e..6ea16fdd 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -226,7 +226,7 @@ function testNslookup { done < "$GRAVITYFILE" fi - echo "NSLOOKUP of $TESTURL from PiHole:" >> ${DEBUG_LOG} + echo "NSLOOKUP of $TESTURL from Pi-hole:" >> ${DEBUG_LOG} nslookup "$TESTURL" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} @@ -347,7 +347,7 @@ else fi -### PiHole application specific logging ### +### Pi-hole application specific logging ### echo "::: Writing whitelist to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "############## Whitelist ##############" >> ${DEBUG_LOG} @@ -391,7 +391,7 @@ fi # Continuously append the pihole.log file to the pihole_debug.log file function dumpPiHoleLog { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT - echo -e "::: Writing current pi-hole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" + echo -e "::: Writing current Pi-hole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" echo "#######################################" >> ${DEBUG_LOG} echo "############# pihole.log ##############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} @@ -402,8 +402,8 @@ function dumpPiHoleLog { echo >> ${DEBUG_LOG} done else - echo "No pihole.log file found!" >> ${DEBUG_LOG} - printf ":::\tNo pihole.log file found!\n" + echo "No Pi-hole.log file found!" >> ${DEBUG_LOG} + printf ":::\tNo Pi-hole.log file found!\n" fi } From ac1c299369c0d299423ad91df0d25f3fd1c93c99 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Sep 2016 20:54:05 -0700 Subject: [PATCH 08/18] Revert overzealous renaming of Pi-hole in pihole.log detection. --- advanced/Scripts/piholeDebug.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 6ea16fdd..9a060572 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -402,8 +402,8 @@ function dumpPiHoleLog { echo >> ${DEBUG_LOG} done else - echo "No Pi-hole.log file found!" >> ${DEBUG_LOG} - printf ":::\tNo Pi-hole.log file found!\n" + echo "No pihole.log file found!" >> ${DEBUG_LOG} + printf ":::\tNo pihole.log file found!\n" fi } From 3df9c48012b570b186b66a91885adf45a956309c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 27 Sep 2016 19:30:37 -0700 Subject: [PATCH 09/18] Include ping statistics in default gateway checks. --- advanced/Scripts/piholeDebug.sh | 35 ++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 9a060572..ebeee470 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -10,6 +10,7 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +set -o pipefail ######## GLOBAL VARS ######## DEBUG_LOG="/var/log/pihole_debug.log" @@ -116,25 +117,45 @@ function ipCheck { echo "$IPADDR" >> ${DEBUG_LOG} IP6ADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }') - if [ -n "$IP6ADDR" ] + if [[ $? = 0 ]] then echo "$IP6ADDR" >> ${DEBUG_LOG} + else + echo "No IPv6 addresses found." >> ${DEBUG_LOG} fi echo >> ${DEBUG_LOG} echo "::: Locating default gateway and checking connectivity" GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) - GATEWAY_CHECK=$(ping -q -w 1 -c 1 "${GATEWAY}" > /dev/null && echo ok || echo error) - echo "Gateway check at ${GATEWAY}:" >> ${DEBUG_LOG} + if [[ $? = 0 ]] + then + echo "::: Pinging default IPv4 gateway..." + GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) + if [[ $? = 0 ]] + then + echo "IPv4 Gateway check:" >> ${DEBUG_LOG} + else + echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG} + fi echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} + fi GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) - if [ -n "$GATEWAY6" ] + if [[ $? = 0 ]] then - GATEWAY6_CHECK=$(ping6 -q -w 1 -c 1 "${GATEWAY6}" > /dev/null && echo ok || echo error) - echo "IPv6 Gateway check at ${GATEWAY6}:" >> ${DEBUG_LOG} - echo "$GATEWAY6_CHECK" >> ${DEBUG_LOG} + echo "::: Pinging default IPv4 gateway..." + GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3) + if [[ $? = 0 ]] + then + echo "IPv6 Gateway check:" >> ${DEBUG_LOG} + else + echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG} + fi + else + GATEWAY_CHECK="No IPv6 Gateway Detected" fi + echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } From dba1ab3fc0cf0d36003ba60dc9102b325555c89e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 27 Sep 2016 19:31:21 -0700 Subject: [PATCH 10/18] Remove compareWhitelist --- advanced/Scripts/piholeDebug.sh | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ebeee470..322de330 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -192,28 +192,6 @@ function portCheck { echo >> ${DEBUG_LOG} } -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 "######## Whitelist Comparison #########" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} - while read -r line; do - TMP=$(grep -w ".* $line$" "$GRAVITYFILE") - if [ ! -z "$TMP" ]; then - echo "$TMP" >> ${DEBUG_LOG} - echo "$TMP" >> ${WHITELISTMATCHES} - fi - done < "$WHITELISTFILE" - echo >> ${DEBUG_LOG} -} - function compareBlacklist { echo "#######################################" >> ${DEBUG_LOG} echo "######## Blacklist Comparison #########" >> ${DEBUG_LOG} @@ -311,7 +289,6 @@ distroCheck ipCheck hostnameCheck portCheck -compareWhitelist compareBlacklist testNslookup checkProcesses From edd7f28104ab572d955e55b27518da865089939b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 27 Sep 2016 19:39:28 -0700 Subject: [PATCH 11/18] Add internet checks to IP section --- advanced/Scripts/piholeDebug.sh | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 322de330..5b704f21 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -138,12 +138,24 @@ function ipCheck { echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG} fi echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + + echo "::: Pinging Internet via IPv4..." + INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) + if [[ $? = 0 ]] + then + echo "IPv4 Internet check:" >> ${DEBUG_LOG} + else + echo "IPv4 Internet check failed:" >> ${DEBUG_LOG} + fi + echo "$INET_CHECK" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} fi GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]] then - echo "::: Pinging default IPv4 gateway..." + echo "::: Pinging default IPv6 gateway..." GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3) if [[ $? = 0 ]] then @@ -151,11 +163,22 @@ function ipCheck { else echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG} fi + + echo "::: Pinging Internet via IPv6..." + GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) + if [[ $? = 0 ]] + then + echo "IPv6 Internet check:" >> ${DEBUG_LOG} + else + echo "IPv6 Internet check failed:" >> ${DEBUG_LOG} + fi + else GATEWAY_CHECK="No IPv6 Gateway Detected" fi echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } From 36e10595cc9d94799dbbf0ded660c7fec9547691 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 28 Sep 2016 09:51:14 -0700 Subject: [PATCH 12/18] Change netstat to lsof. --- advanced/Scripts/piholeDebug.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 5b704f21..67d2815e 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -209,9 +209,10 @@ function portCheck { echo "######## Open Port Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} - echo "::: Writing local server ports to logfile" + echo "::: Detecting local server port 80 and 53 processes." - ${SUDO} netstat -tulpn >> ${DEBUG_LOG} + ${SUDO} lsof -i :80 >> ${DEBUG_LOG} + ${SUDO} lsof -i :53 >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} } From 5de179f1eb2fa84d994d1fb990467ce28cc11ef7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 28 Sep 2016 09:52:11 -0700 Subject: [PATCH 13/18] Remove blacklist comparison. --- advanced/Scripts/piholeDebug.sh | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 67d2815e..488ed4a1 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -216,18 +216,6 @@ function portCheck { echo >> ${DEBUG_LOG} } -function compareBlacklist { - echo "#######################################" >> ${DEBUG_LOG} - echo "######## Blacklist Comparison #########" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} - while read -r line; do - if [ ! -z "$line" ]; then - grep -w ".* $line$" "$GRAVITYFILE" >> ${DEBUG_LOG} - fi - done < "$BLACKLISTFILE" - echo >> ${DEBUG_LOG} -} - function testNslookup { TESTURL="doubleclick.com" echo "#######################################" >> ${DEBUG_LOG} @@ -313,7 +301,6 @@ distroCheck ipCheck hostnameCheck portCheck -compareBlacklist testNslookup checkProcesses debugLighttpd From 8466d0b6818927d394f4edef9174178ff1e25b09 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 28 Sep 2016 10:14:47 -0700 Subject: [PATCH 14/18] Change NSLOOKUP to dig for resolver tests, add dnsmasq specific records check --- advanced/Scripts/piholeDebug.sh | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 488ed4a1..a4eec46d 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -216,12 +216,14 @@ function portCheck { echo >> ${DEBUG_LOG} } -function testNslookup { - TESTURL="doubleclick.com" - echo "#######################################" >> ${DEBUG_LOG} - echo "############ NSLookup Test ############" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} +function testResolver { + echo "############################################################" >> ${DEBUG_LOG} + echo "############ Resolver Functions Check ############" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} + + # Find a blocked url that has not been whitelisted. + TESTURL="doubleclick.com" if [ -s "$WHITELISTMATCHES" ]; then while read -r line; do CUTURL=${line#*" "} @@ -237,12 +239,19 @@ function testNslookup { done < "$GRAVITYFILE" fi - echo "NSLOOKUP of $TESTURL from Pi-hole:" >> ${DEBUG_LOG} - nslookup "$TESTURL" >> ${DEBUG_LOG} + echo "Resolution of $TESTURL from Pi-hole:" >> ${DEBUG_LOG} + dig "$TESTURL" @127.0.0.1>> ${DEBUG_LOG} echo >> ${DEBUG_LOG} - echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} - nslookup "$TESTURL" 8.8.8.8 >> ${DEBUG_LOG} + echo "Resolution of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} + dig "$TESTURL" @8.8.8.8 >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} + + echo "Pi-hole dnsmasq specific records lookups" >> ${DEBUG_LOG} + echo "Cache Size:" >> ${DEBUG_LOG} + dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} + echo "Upstream Servers:" >> ${DEBUG_LOG} + dig +short chaos txt servers.bind >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } function checkProcesses { @@ -259,6 +268,7 @@ function checkProcesses { echo " processes status:" >> ${DEBUG_LOG} ${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG" done + echo >> ${DEBUG_LOG} } function debugLighttpd { @@ -301,8 +311,8 @@ distroCheck ipCheck hostnameCheck portCheck -testNslookup checkProcesses +testResolver debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." From 5a3d319677422593aaf77282b32042d176e49573 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 28 Sep 2016 10:24:44 -0700 Subject: [PATCH 15/18] Add fail check to dig local and remote. --- advanced/Scripts/piholeDebug.sh | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index a4eec46d..faf1a295 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -240,15 +240,38 @@ function testResolver { fi echo "Resolution of $TESTURL from Pi-hole:" >> ${DEBUG_LOG} - dig "$TESTURL" @127.0.0.1>> ${DEBUG_LOG} + LOCALDIG=$(dig "$TESTURL" @127.0.0.1) + if [[ $? = 0 ]] + then + echo "$LOCALDIG" >> ${DEBUG_LOG} + else + echo "Failed to resolve $TESTURL on Pi-hole" >> ${DEBUG_LOG} + fi echo >> ${DEBUG_LOG} + + echo "Resolution of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} - dig "$TESTURL" @8.8.8.8 >> ${DEBUG_LOG} + REMOTEDIG=$(dig "$TESTURL" @8.8.8.8) + if [[ $? = 0 ]] + then + echo "$REMOTEDIG" >> ${DEBUG_LOG} + else + echo "Failed to resolve $TESTURL on 8.8.8.8" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} echo "Pi-hole dnsmasq specific records lookups" >> ${DEBUG_LOG} echo "Cache Size:" >> ${DEBUG_LOG} dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} + echo "Insertions count:" >> ${DEBUG_LOG} + dig +short chaos txt insertions.bind >> ${DEBUG_LOG} + echo "Evictions count:" >> ${DEBUG_LOG} + dig +short chaos txt evictions.bind >> ${DEBUG_LOG} + echo "Misses count:" >> ${DEBUG_LOG} + dig +short chaos txt misses.bind >> ${DEBUG_LOG} + echo "Hits count:" >> ${DEBUG_LOG} + dig +short chaos txt hits.bind >> ${DEBUG_LOG} + echo "Auth count:" >> ${DEBUG_LOG} + dig +short chaos txt auth.bind >> ${DEBUG_LOG} echo "Upstream Servers:" >> ${DEBUG_LOG} dig +short chaos txt servers.bind >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} From 7fcb40739d0fea406d96107fcca084f6ed197350 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 28 Sep 2016 10:25:37 -0700 Subject: [PATCH 16/18] Close IF statement --- advanced/Scripts/piholeDebug.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index faf1a295..0a02a1f7 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -257,6 +257,7 @@ function testResolver { echo "$REMOTEDIG" >> ${DEBUG_LOG} else echo "Failed to resolve $TESTURL on 8.8.8.8" >> ${DEBUG_LOG} + fi echo >> ${DEBUG_LOG} echo "Pi-hole dnsmasq specific records lookups" >> ${DEBUG_LOG} From a9c3e2c7ba4f5c3aedc611ea887273fa43b7ef08 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 28 Sep 2016 13:09:38 -0700 Subject: [PATCH 17/18] Add log_write function. Update version_check to use logical conditionals. --- advanced/Scripts/piholeDebug.sh | 76 +++++++++++++-------------------- 1 file changed, 30 insertions(+), 46 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 0a02a1f7..718b6c74 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -37,7 +37,7 @@ echo "::: " ######## FIRST CHECK ######## # Must be root to debug -if [[ $EUID -eq 0 ]]; then +if [[ "$EUID" -eq 0 ]]; then echo "::: Script is executing as root user..." else echo "::: Non-root user detected..." @@ -61,40 +61,30 @@ else fi ### Private functions exist here ### -function versionCheck { - echo "############################################################" >> ${DEBUG_LOG} - echo "########## Installed Versions ##########" >> ${DEBUG_LOG} - echo "############################################################" >> ${DEBUG_LOG} - - echo "::: Detecting Pi-hole installed versions." - TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - echo "Pi-hole Version: $TMP" >> ${DEBUG_LOG} - - echo "::: Writing Pi-hole installed version to logfile." - TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0) - echo "WebUI Version: $TMP" >> ${DEBUG_LOG} - - echo "::: Writing lighttpd version to logfile." - light_ver=$(lighttpd -v | head -n1) - if [ -n light_ver ] - then - echo "${light_ver}" >> ${DEBUG_LOG} - else - echo "lighttpd not installed." >> ${DEBUG_LOG} - fi - - echo "::: Writing PHP version to logfile." - php_ver=$(php -v | head -n1) - if [ -n php_ver ] - then - echo "${php_ver}" >> ${DEBUG_LOG} - else - echo "PHP not installed." >> ${DEBUG_LOG} - fi - echo >> ${DEBUG_LOG} +function log_write { + echo "$1" >> "${DEBUG_LOG}" } -function distroCheck { +function version_check { + log_write "############################################################" + log_write "########## Installed Versions ##########" + log_write "############################################################" + + echo "::: Detecting Pi-hole installed versions." + pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ + && log_write "Pi-hole Version: $pi_hole_ver" || log_write "Pi-hole git repository not detected." + admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ + && log_write "WebUI Version: $admin_ver" || log_write "Pi-hole Admin Pages git repository not detected." + + echo "::: Writing lighttpd version to logfile." + light_ver="$(lighttpd -v |& head -n1)" && log_write "${light_ver}" || log_write "lighttpd not installed." + + echo "::: Writing PHP version to logfile." + php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." + +} + +function distro_check { echo "############################################################" >> ${DEBUG_LOG} echo "######## Installed OS Distribution #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} @@ -107,22 +97,17 @@ function distroCheck { echo >> ${DEBUG_LOG} } -function ipCheck { +function ip_check { echo "############################################################" >> ${DEBUG_LOG} echo "######## IP Address Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} echo "::: Writing local IPs to logfile" - IPADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }') + IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" echo "$IPADDR" >> ${DEBUG_LOG} - IP6ADDR=$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }') - if [[ $? = 0 ]] - then - echo "$IP6ADDR" >> ${DEBUG_LOG} - else - echo "No IPv6 addresses found." >> ${DEBUG_LOG} - fi + IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ + && echo "$IP6ADDR" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} echo "::: Locating default gateway and checking connectivity" @@ -329,10 +314,9 @@ function debugLighttpd { ### END FUNCTIONS ### - -versionCheck -distroCheck -ipCheck +version_check +distro_check +ip_check hostnameCheck portCheck checkProcesses From 9a421d510a1cce8aef3a6b98991f467cc188e86a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 1 Oct 2016 13:16:58 -0700 Subject: [PATCH 18/18] Ignore comments in adlists.list section. --- advanced/Scripts/piholeDebug.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 718b6c74..aadb083b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -81,7 +81,6 @@ function version_check { echo "::: Writing PHP version to logfile." php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." - } function distro_check { @@ -190,7 +189,7 @@ function hostnameCheck { } function portCheck { - echo "############################################################" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} echo "######## Open Port Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} @@ -407,7 +406,12 @@ echo "############ adlists.list #############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} if [ -e "$ADLISTSFILE" ] then - cat "$ADLISTSFILE" >> ${DEBUG_LOG} + while read -r line; do + if [ ! -z "$line" ]; then + [[ "$line" =~ ^#.*$ ]] && continue + echo "$line" >> ${DEBUG_LOG} + fi + done < "$ADLISTSFILE" echo >> ${DEBUG_LOG} else echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG}