From 01f17f9cbbcba0f4fb3f2f2089f4b325f6782cd4 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 17:19:33 -0700 Subject: [PATCH 01/30] Reduce header verbosity. New header writer. --- advanced/Scripts/piholeDebug.sh | 118 +++++++++++++------------------- 1 file changed, 47 insertions(+), 71 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ea1e409b..8f8425df 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -50,31 +50,33 @@ log_write() { echo "${1}" >> "${DEBUG_LOG}" } +header_write() { + echo "" >> "${DEBUG_LOG}" + echo "::: ${1}" >> "${DEBUG_LOG}" + echo "" >> "${DEBUG_LOG}" +} + version_check() { - log_write "############################################################" - log_write "########## Installed Versions ##########" - log_write "############################################################" + header_write "Installed Package Versions" + echo "::: Detecting Pi-hole installed versions." - 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." + 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." + echo "::: Writing PHP version to logfile." php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." } files_check() { - log_write "############################################################" - log_write "########## Files Check ##########" - log_write "############################################################" + header_write "Files Check" #Check existence of setupVars.conf, and source it to get configured network interface for later use in script. - echo -n "::: Detecting existence setupVars.conf..." + echo -n "::: Detecting existence setupVars.conf..." setupVars=/etc/pihole/setupVars.conf if [[ -f ${setupVars} ]];then echo " found!" @@ -93,30 +95,26 @@ files_check() { piholeInterface="%${piholeInterface}" fi else - echo " NOT FOUND!" + echo " NOT FOUND!" log_write "/etc/pihole/setupVars.conf not found!" fi } distro_check() { - log_write "############################################################" - log_write "######## Installed OS Distribution #########" - log_write "############################################################" + header_write "Installed OS Distribution" - echo "::: Checking installed OS Distribution release." + echo "::: Checking installed OS Distribution release." TMP=$(cat /etc/*release || echo "Failed to find release") - echo "::: Writing OS Distribution release to logfile." + echo "::: Writing OS Distribution release to logfile." log_write "${TMP}" log_write "" } ip_check() { - log_write "############################################################" - log_write "######## IP Address Information #########" - log_write "############################################################" + header_write "IP Address Information" - echo "::: Writing local IPs to logfile" + echo "::: Writing local IPs to logfile" IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" log_write "${IPADDR}" @@ -124,10 +122,10 @@ ip_check() { && log_write "${IP6ADDR}" || log_write "No IPv6 addresses found." log_write "" - echo "::: Locating default gateway and checking connectivity" + echo "::: Locating default gateway and checking connectivity" GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv4 gateway..." + echo "::: Pinging default IPv4 gateway..." GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) if [[ $? = 0 ]]; then log_write "IPv4 Gateway check:" @@ -137,7 +135,7 @@ ip_check() { log_write "${GATEWAY_CHECK}" log_write "" - echo "::: Pinging Internet via IPv4..." + echo "::: Pinging Internet via IPv4..." INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) if [[ $? = 0 ]]; then log_write "IPv4 Internet check:" @@ -150,7 +148,7 @@ ip_check() { GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv6 gateway..." + echo "::: Pinging default IPv6 gateway..." GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}""${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Gateway check:" @@ -158,7 +156,7 @@ ip_check() { log_write "IPv6 Gateway check failed:" fi - echo "::: Pinging Internet via IPv6..." + echo "::: Pinging Internet via IPv6..." GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888"${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Internet check:" @@ -176,15 +174,13 @@ ip_check() { } hostnameCheck() { - log_write "############################################################" - log_write "######## Hostname Information #########" - log_write "############################################################" + header_write "Hostname Information" - echo "::: Writing locally configured hostnames to logfile" + echo "::: Writing locally configured hostnames to logfile" # Write the hostname output to compare against entries in /etc/hosts, which is logged next log_write "This Pi-hole is: $(hostname)" - echo "::: Writing hosts file to debug log..." + echo "::: Writing hosts file to debug log..." log_write "### Hosts ###" if [ -e "${HOSTSFILE}" ]; then @@ -197,11 +193,9 @@ hostnameCheck() { } portCheck() { - log_write "############################################################" - log_write "######## Open Port Information #########" - log_write "############################################################" + header_write "Open Port Information" - echo "::: Detecting local server port 80 and 53 processes." + echo "::: Detecting local server port 80 and 53 processes." lsof -i :80 >> ${DEBUG_LOG} lsof -i :53 >> ${DEBUG_LOG} @@ -209,10 +203,7 @@ portCheck() { } testResolver() { - log_write "############################################################" - log_write "############ Resolver Functions Check ############" - log_write "############################################################" - + header_write "Resolver Functions Check" # Find a blocked url that has not been whitelisted. TESTURL="doubleclick.com" @@ -269,11 +260,9 @@ testResolver() { } checkProcesses() { - log_write "#######################################" - log_write "########### Processes Check ###########" - log_write "#######################################" - log_write ":::" - echo "::: Logging status of lighttpd and dnsmasq..." + header_write "Processes Check" + + echo "::: Logging status of lighttpd and dnsmasq..." PROCESSES=( lighttpd dnsmasq ) for i in "${PROCESSES[@]}"; do log_write "" @@ -285,10 +274,8 @@ checkProcesses() { } debugLighttpd() { - log_write "::: Writing lighttpd to debug log..." - log_write "#######################################" - log_write "############ lighttpd.conf ############" - log_write "#######################################" + header_write "lighttpd.conf" + if [ -e "${LIGHTTPDFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then @@ -303,9 +290,10 @@ debugLighttpd() { fi if [ -e "${LIGHTTPDERRFILE}" ]; then - log_write "#######################################" - log_write "######### lighttpd error.log ##########" - log_write "#######################################" + log_write "" + log_write "::: lighttpd error.log" + log_write "" + cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG} else log_write "No lighttpd error.log file found!" @@ -327,9 +315,7 @@ testResolver debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." -log_write "#######################################" -log_write "############### Dnsmasq ###############" -log_write "#######################################" +header_write "Dnsmasq configuration" if [ -e "${DNSMASQFILE}" ]; then #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do @@ -345,9 +331,8 @@ else fi echo "::: Writing 01-pihole.conf to debug log..." -log_write "#######################################" -log_write "########### 01-pihole.conf ############" -log_write "#######################################" +header_write "01-pihole.conf" + if [ -e "${PIHOLECONFFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then @@ -362,9 +347,8 @@ else fi echo "::: Writing size of gravity.list to debug log..." -log_write "#######################################" -log_write "############ gravity.list #############" -log_write "#######################################" +header_write "gravity.list" + if [ -e "${GRAVITYFILE}" ]; then wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG} log_write "" @@ -376,9 +360,7 @@ fi ### Pi-hole application specific logging ### echo "::: Writing whitelist to debug log..." -log_write "#######################################" -log_write "############## Whitelist ##############" -log_write "#######################################" +header_write "Whitelist" if [ -e "${WHITELISTFILE}" ]; then cat "${WHITELISTFILE}" >> ${DEBUG_LOG} log_write @@ -388,9 +370,7 @@ else fi echo "::: Writing blacklist to debug log..." -log_write "#######################################" -log_write "############## Blacklist ##############" -log_write "#######################################" +header_write "Blacklist" if [ -e "${BLACKLISTFILE}" ]; then cat "${BLACKLISTFILE}" >> ${DEBUG_LOG} log_write @@ -400,9 +380,7 @@ else fi echo "::: Writing adlists.list to debug log..." -log_write "#######################################" -log_write "############ adlists.list #############" -log_write "#######################################" +header_write "adlists.list" if [ -e "${ADLISTSFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then @@ -421,9 +399,7 @@ fi 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)" - log_write "#######################################" - log_write "############# pihole.log ##############" - log_write "#######################################" + header_write "pihole.log" if [ -e "${PIHOLELOG}" ]; then while true; do tail -f "${PIHOLELOG}" >> ${DEBUG_LOG} From fb70fd77e8d0e05ebe7836d32c9bed3edd7eb0e7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 17:50:14 -0700 Subject: [PATCH 02/30] Prototype version_check, add helper functions for logging and echo. --- advanced/Scripts/piholeDebug.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8f8425df..c62aa1eb 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -56,20 +56,24 @@ header_write() { echo "" >> "${DEBUG_LOG}" } +log_echo() { + echo "::: ${1}" + log_write "${1}" +} + version_check() { header_write "Installed Package Versions" 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." + && log_echo "Pi-hole: $pi_hole_ver" || log_echo "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." + && log_echo "WebUI: $admin_ver" || log_echo "Pi-hole Admin Pages git repository not detected." + light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ + && log_echo "${light_ver}" || log_echo "lighttpd not installed." + php_ver="$(php -v |& head -n1)" \ + && log_echo "${php_ver}" || log_echo "PHP not installed." + echo ":::" } files_check() { From b0874fb23afba0a754c6c5bcc4bdaa8083a99bb9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 19:53:00 -0700 Subject: [PATCH 03/30] Temporarily get rid of gateway sourcing from setupVars, temporarily. --- advanced/Scripts/piholeDebug.sh | 54 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c62aa1eb..ef031108 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -65,43 +65,41 @@ version_check() { header_write "Installed Package Versions" echo "::: Detecting Pi-hole installed versions." - pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ + local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ && log_echo "Pi-hole: $pi_hole_ver" || log_echo "Pi-hole git repository not detected." - admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ + local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ && log_echo "WebUI: $admin_ver" || log_echo "Pi-hole Admin Pages git repository not detected." - light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ + local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ && log_echo "${light_ver}" || log_echo "lighttpd not installed." - php_ver="$(php -v |& head -n1)" \ + local php_ver="$(php -v |& head -n1)" \ && log_echo "${php_ver}" || log_echo "PHP not installed." echo ":::" } +source_variable() { + # Source file passed in as ${1} and add variable at ${2} to environment + source ${1} + echo $piholeInterface +} + files_check() { - header_write "Files Check" - - #Check existence of setupVars.conf, and source it to get configured network interface for later use in script. - echo -n "::: Detecting existence setupVars.conf..." - setupVars=/etc/pihole/setupVars.conf - if [[ -f ${setupVars} ]];then - echo " found!" - log_write "/etc/pihole/setupVars.conf exists! Contents:" - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue + header_write "File Check" + + #Check non-zero length existence of ${1} + echo "::: Detecting existence of ${1}..." + local searchFile=/etc/pihole/"${1}" + if [[ -s ${searchFile} ]]; then + log_echo "/etc/pihole/${1} exists!" + while read -r line; do + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${setupVars}" - log_write "" - - . "${setupVars}" - if [[ -n "${piholeInterface}" ]]; then - # prepend % to the beginning of piholeInterface for later use - piholeInterface="%${piholeInterface}" - fi - else - echo " NOT FOUND!" - log_write "/etc/pihole/setupVars.conf not found!" - fi + done < "${searchFile}" + else + log_echo "/etc/pihole/${1} not found!" + fi + echo ":::" } distro_check() { @@ -309,7 +307,7 @@ debugLighttpd() { ### END FUNCTIONS ### version_check -files_check +files_check "setupVars.conf" distro_check ip_check hostnameCheck From 2fa47aaf31607cb5c0364dcda298fedeb9c940fc Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 20:53:18 -0700 Subject: [PATCH 04/30] Source routing is deprecated by RFC5095 --- advanced/Scripts/piholeDebug.sh | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ef031108..1c060a92 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -115,27 +115,23 @@ distro_check() { ip_check() { header_write "IP Address Information" + echo $piholeInterface - echo "::: Writing local IPs to logfile" - IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" - log_write "${IPADDR}" + echo "::: Collecting local IP info." + local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ + && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." + + local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ + && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") || log_echo "No IPv6 addresses found." - IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ - && log_write "${IP6ADDR}" || log_write "No IPv6 addresses found." - log_write "" echo "::: Locating default gateway and checking connectivity" - GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) + local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo "::: Pinging default IPv4 gateway..." - GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) - if [[ $? = 0 ]]; then - log_write "IPv4 Gateway check:" - else - log_write "IPv4 Gateway check failed:" - fi - log_write "${GATEWAY_CHECK}" - log_write "" + local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ + && echo "::: IPv4 Default Gateway Responded." || echo "::: IPv4 Default Gateway did not respond." + log_write "${IPv4_def_gateway_check}" echo "::: Pinging Internet via IPv4..." INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) @@ -151,7 +147,7 @@ ip_check() { GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo "::: Pinging default IPv6 gateway..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}""${piholeInterface}" | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n "${GATEWAY6}" ) if [[ $? = 0 ]]; then log_write "IPv6 Gateway check:" else @@ -159,7 +155,7 @@ ip_check() { fi echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888"${piholeInterface}" | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Internet check:" else @@ -167,7 +163,7 @@ ip_check() { fi else - GATEWAY_CHECK="No IPv6 Gateway Detected" + GATEWAY6_CHECK="No IPv6 Gateway Detected" fi log_write "${GATEWAY_CHECK}" From f549618d127f3b2313c04581b9b730001c2d69ac Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 21:25:57 -0700 Subject: [PATCH 05/30] Move environment IPv6 interface check to `ip_check` and fix IPv6 source routing issue. --- advanced/Scripts/piholeDebug.sh | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1c060a92..c09dfed9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -115,7 +115,10 @@ distro_check() { ip_check() { header_write "IP Address Information" - echo $piholeInterface + # Get the current interface for Internet traffic + local IPv6_temp_interface=$(ip -6 r | grep default | cut -d ' ' -f 5) + # If declared in setupVars.conf use it, otherwise defer to default + local IPv6_interface=${piholeInterface:-$IPv6_temp_interface} echo "::: Collecting local IP info." local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ @@ -134,28 +137,20 @@ ip_check() { log_write "${IPv4_def_gateway_check}" echo "::: Pinging Internet via IPv4..." - INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) - if [[ $? = 0 ]]; then - log_write "IPv4 Internet check:" - else - log_write "IPv4 Internet check failed:" - fi - log_write "${INET_CHECK}" - log_write "" + local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ + && echo "::: IPv4 Internet query responded." || echo "::: IPv4 Internet query did not respond." + log_write "${IPv4_inet_check}" fi - GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) + local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo "::: Pinging default IPv6 gateway..." - GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n "${GATEWAY6}" ) - if [[ $? = 0 ]]; then - log_write "IPv6 Gateway check:" - else - log_write "IPv6 Gateway check failed:" - fi + local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ + && echo "::: IPv6 Default Gateway Responded." || echo "::: IPv6 Default Gateway did not respond." + log_write "${IPv6_def_gateway_check}" echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Internet check:" else @@ -165,7 +160,7 @@ ip_check() { else GATEWAY6_CHECK="No IPv6 Gateway Detected" fi - log_write "${GATEWAY_CHECK}" + log_write "${GATEWAY6_CHECK}" log_write "" From 8fa897aadb57f6a4a499b86c28e10181ab21338e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 21:39:28 -0700 Subject: [PATCH 06/30] Add back in sourcing files (setupVars.conf) and tweak `ip_check` --- advanced/Scripts/piholeDebug.sh | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c09dfed9..e71c34a8 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -76,26 +76,21 @@ version_check() { echo ":::" } -source_variable() { - # Source file passed in as ${1} and add variable at ${2} to environment - source ${1} - echo $piholeInterface -} - files_check() { header_write "File Check" #Check non-zero length existence of ${1} echo "::: Detecting existence of ${1}..." - local searchFile=/etc/pihole/"${1}" - if [[ -s ${searchFile} ]]; then + local search_file=/etc/pihole/"${1}" + if [[ -s ${search_file} ]]; then log_echo "/etc/pihole/${1} exists!" + source "${search_file}" &> /dev/null && log_echo "Successfully sourced ${search_file}" || log_echo "Could not source ${search_file}" while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${searchFile}" + done < "${search_file}" else log_echo "/etc/pihole/${1} not found!" fi @@ -150,20 +145,14 @@ ip_check() { log_write "${IPv6_def_gateway_check}" echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) - if [[ $? = 0 ]]; then - log_write "IPv6 Internet check:" - else - log_write "IPv6 Internet check failed:" - fi - + local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ + && echo "::: IPv6 Internet query responded." || echo "::: IPv6 Internet query did not respond." else - GATEWAY6_CHECK="No IPv6 Gateway Detected" + IPv6_inet_check="No IPv6 Gateway Detected" fi - log_write "${GATEWAY6_CHECK}" - - + log_write "${IPv6_inet_check}" log_write "" + echo ":::" } hostnameCheck() { From 4269626f5d426406f4ed98cb74322870b77aaef9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 21:53:41 -0700 Subject: [PATCH 07/30] Attribute source for bashism. --- advanced/Scripts/piholeDebug.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e71c34a8..e87703de 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -101,11 +101,8 @@ distro_check() { header_write "Installed OS Distribution" echo "::: Checking installed OS Distribution release." - TMP=$(cat /etc/*release || echo "Failed to find release") - - echo "::: Writing OS Distribution release to logfile." - log_write "${TMP}" - log_write "" + local distro="$(cat /etc/*release)" && log_write "${distro}" || log_write "Distribution details not found." + echo ":::" } ip_check() { @@ -113,6 +110,7 @@ ip_check() { # Get the current interface for Internet traffic local IPv6_temp_interface=$(ip -6 r | grep default | cut -d ' ' -f 5) # If declared in setupVars.conf use it, otherwise defer to default + # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash local IPv6_interface=${piholeInterface:-$IPv6_temp_interface} echo "::: Collecting local IP info." From 98db002770fd2862c484a8c98103f71c8262a4c9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 11:38:19 -0700 Subject: [PATCH 08/30] Tighten IP test reponse to user. --- advanced/Scripts/piholeDebug.sh | 39 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e87703de..8636ef52 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -124,27 +124,27 @@ ip_check() { echo "::: Locating default gateway and checking connectivity" local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv4 gateway..." + echo -n "::: Pinging default IPv4 gateway: " local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ - && echo "::: IPv4 Default Gateway Responded." || echo "::: IPv4 Default Gateway did not respond." + && echo "Gateway responded." || echo "Gateway did not respond." log_write "${IPv4_def_gateway_check}" - echo "::: Pinging Internet via IPv4..." + echo -n "::: Pinging Internet via IPv4: " local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ - && echo "::: IPv4 Internet query responded." || echo "::: IPv4 Internet query did not respond." + && echo "Query responded." || echo "Query did not respond." log_write "${IPv4_inet_check}" fi local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv6 gateway..." + echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ - && echo "::: IPv6 Default Gateway Responded." || echo "::: IPv6 Default Gateway did not respond." + && echo "Gateway Responded." || echo "Gateway did not respond." log_write "${IPv6_def_gateway_check}" - echo "::: Pinging Internet via IPv6..." + echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ - && echo "::: IPv6 Internet query responded." || echo "::: IPv6 Internet query did not respond." + && echo "Query responded." || echo "Query did not respond." else IPv6_inet_check="No IPv6 Gateway Detected" fi @@ -172,14 +172,18 @@ hostnameCheck() { fi } -portCheck() { - header_write "Open Port Information" - - echo "::: Detecting local server port 80 and 53 processes." - - lsof -i :80 >> ${DEBUG_LOG} - lsof -i :53 >> ${DEBUG_LOG} - log_write "" +daemon_check() { + # Check for daemon ${1} on port ${2} + header_write "Daemon Port Listening Information" + + echo "::: Checking port ${2} for ${1} listener." + local found_daemon=false + local ret_Val=$(lsof -i :${2} -FcL) \ + && (echo "::: Port ${2} is in use." && found_daemon=true) \ + || (echo "::: Port ${2} is not in use.") + if [[ found_daemon ]]; then + log_echo "Temporary holding place for evaluation code ${ret_Val}" + fi } testResolver() { @@ -289,7 +293,8 @@ files_check "setupVars.conf" distro_check ip_check hostnameCheck -portCheck +daemon_check lighttpd http +daemon_check dnsmasq domain checkProcesses testResolver debugLighttpd From fc360abe43fae7ecf868bb904cc51ca353b79ce9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 12:22:20 -0700 Subject: [PATCH 09/30] Only check IPv6 if system is enabled. --- advanced/Scripts/piholeDebug.sh | 61 +++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8636ef52..2e457e31 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -26,6 +26,9 @@ ADLISTSFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" +# Default to no IPv6, will check and enable if needed. +IPV6=ENABLED=false + # Header info and introduction cat << EOM ::: Beginning Pi-hole debug at $(date)! @@ -105,22 +108,30 @@ distro_check() { echo ":::" } +ipv6_check() { + # Check if system is IPv6 enabled, for use in other functions + if [[ -a /proc/net/if_inet6 ]]; then + IPV6_ENABLED=true + return 0 + else + return 1 + fi +} + ip_check() { header_write "IP Address Information" # Get the current interface for Internet traffic - local IPv6_temp_interface=$(ip -6 r | grep default | cut -d ' ' -f 5) + + # Check if IPv6 enabled + local IPv6_interface + ipv6_check && IPv6_interface=${piholeInterface:-$(ip -6 r | grep default | cut -d ' ' -f 5)} # If declared in setupVars.conf use it, otherwise defer to default # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash - local IPv6_interface=${piholeInterface:-$IPv6_temp_interface} echo "::: Collecting local IP info." local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." - local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ - && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") || log_echo "No IPv6 addresses found." - - echo "::: Locating default gateway and checking connectivity" local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then @@ -135,22 +146,28 @@ ip_check() { log_write "${IPv4_inet_check}" fi - local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]]; then - echo -n "::: Pinging default IPv6 gateway: " - local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ - && echo "Gateway Responded." || echo "Gateway did not respond." - log_write "${IPv6_def_gateway_check}" - - echo -n "::: Pinging Internet via IPv6: " - local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ - && echo "Query responded." || echo "Query did not respond." - else - IPv6_inet_check="No IPv6 Gateway Detected" - fi - log_write "${IPv6_inet_check}" - log_write "" - echo ":::" + if [[ IPV6_ENABLED ]]; then + local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ + && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") \ + || log_echo "No IPv6 addresses found." + + local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) + if [[ $? = 0 ]]; then + echo -n "::: Pinging default IPv6 gateway: " + local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ + && echo "Gateway Responded." || echo "Gateway did not respond." + log_write "${IPv6_def_gateway_check}" + + echo -n "::: Pinging Internet via IPv6: " + local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ + && echo "Query responded." || echo "Query did not respond." + else + IPv6_inet_check="No IPv6 Gateway Detected" + fi + log_write "${IPv6_inet_check}" + log_write "" + echo ":::" + fi } hostnameCheck() { From f73734acb06a4d82db8b38c8f156e13abfce37bc Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 13:57:57 -0700 Subject: [PATCH 10/30] Only check IPv6 Gateway if it exists. --- advanced/Scripts/piholeDebug.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 2e457e31..39431371 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -152,7 +152,7 @@ ip_check() { || log_echo "No IPv6 addresses found." local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]]; then + if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ && echo "Gateway Responded." || echo "Gateway did not respond." @@ -164,8 +164,7 @@ ip_check() { else IPv6_inet_check="No IPv6 Gateway Detected" fi - log_write "${IPv6_inet_check}" - log_write "" + log_echo "${IPv6_inet_check}" echo ":::" fi } From 60741298b7332931c9d6a8f2d5c3573718223703 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 14:33:47 -0700 Subject: [PATCH 11/30] Cut more verbosity. Prep for `lsof` parsing and daemon tests. --- advanced/Scripts/piholeDebug.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 39431371..3071df07 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -132,7 +132,6 @@ ip_check() { local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." - echo "::: Locating default gateway and checking connectivity" local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo -n "::: Pinging default IPv4 gateway: " @@ -161,10 +160,10 @@ ip_check() { echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ && echo "Query responded." || echo "Query did not respond." + log_write "${IPv6_inet_check}" else - IPv6_inet_check="No IPv6 Gateway Detected" + log_echo="No IPv6 Gateway Detected" fi - log_echo "${IPv6_inet_check}" echo ":::" fi } @@ -188,18 +187,29 @@ hostnameCheck() { fi } +lsof_parse() { + # Dummy function for now + echo "Dummy function lsof_parse got called" + log_echo ${1} +} + daemon_check() { # Check for daemon ${1} on port ${2} header_write "Daemon Port Listening Information" echo "::: Checking port ${2} for ${1} listener." local found_daemon=false - local ret_Val=$(lsof -i :${2} -FcL) \ - && (echo "::: Port ${2} is in use." && found_daemon=true) \ - || (echo "::: Port ${2} is not in use.") - if [[ found_daemon ]]; then - log_echo "Temporary holding place for evaluation code ${ret_Val}" + local lsof_value + + if [[ ${IPV6_ENABLED} ]]; then + lsof_value=$(lsof -i 6:${2} -FcL) \ + && (echo "::: Port ${2} is in use on IPv6." && found_daemon=true && echo "${lsof_value}") \ + || (echo "::: Port ${2} is not in use.") fi + + lsof_value=$(lsof -i 4:${2} -FcL) \ + && (echo "::: Port ${2} is in use on IPv4." && found_daemon=true && echo "${lsof_value}") \ + || (echo "::: Port ${2} is not in use.") } testResolver() { From f169da8fd086ff7f962c1e6ba6f7c7eb4243bb29 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 14:48:11 -0700 Subject: [PATCH 12/30] Set for quiet temporarily. --- advanced/Scripts/piholeDebug.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3071df07..a0385ceb 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -190,7 +190,6 @@ hostnameCheck() { lsof_parse() { # Dummy function for now echo "Dummy function lsof_parse got called" - log_echo ${1} } daemon_check() { @@ -202,12 +201,12 @@ daemon_check() { local lsof_value if [[ ${IPV6_ENABLED} ]]; then - lsof_value=$(lsof -i 6:${2} -FcL) \ + lsof_value=$(lsof -i 6:${2} -F0cL) \ && (echo "::: Port ${2} is in use on IPv6." && found_daemon=true && echo "${lsof_value}") \ || (echo "::: Port ${2} is not in use.") fi - lsof_value=$(lsof -i 4:${2} -FcL) \ + lsof_value=$(lsof -i 4:${2} -F0cL) \ && (echo "::: Port ${2} is in use on IPv4." && found_daemon=true && echo "${lsof_value}") \ || (echo "::: Port ${2} is not in use.") } From 13e488dacef0fcec941208cc0aed4d4062cb757f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Oct 2016 00:30:51 -0700 Subject: [PATCH 13/30] Daemon check for lighttpd and dnsmasq. --- advanced/Scripts/piholeDebug.sh | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index a0385ceb..ed22afa9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -188,10 +188,21 @@ hostnameCheck() { } lsof_parse() { - # Dummy function for now - echo "Dummy function lsof_parse got called" + local user + local process + local match + + user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) + process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) + if [[ ${2} -eq ${process} ]]; then + match="as required." + else + match="incorrectly." + fi + log_echo "by ${user} for ${process} ${match}" } + daemon_check() { # Check for daemon ${1} on port ${2} header_write "Daemon Port Listening Information" @@ -200,15 +211,19 @@ daemon_check() { local found_daemon=false local lsof_value + if [[ ${IPV6_ENABLED} ]]; then - lsof_value=$(lsof -i 6:${2} -F0cL) \ - && (echo "::: Port ${2} is in use on IPv6." && found_daemon=true && echo "${lsof_value}") \ - || (echo "::: Port ${2} is not in use.") + lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ + && (log_echo "Port ${2} is in use on IPv6" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + || (log_echo "Port ${2} is not in use on IPv6.") fi - lsof_value=$(lsof -i 4:${2} -F0cL) \ - && (echo "::: Port ${2} is in use on IPv4." && found_daemon=true && echo "${lsof_value}") \ - || (echo "::: Port ${2} is not in use.") + lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ + && (log_echo "Port ${2} is in use on IPv4" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + || (log_echo "Port ${2} is not in use on IPv4.") + if [[ "${found_daemon}" == false ]]; then + log_echo "Missing required daemon ${1}, please check configuration." + fi } testResolver() { From 36285ead57278c0ffd71f0f0a424fa66101a43eb Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Oct 2016 00:32:18 -0700 Subject: [PATCH 14/30] Just becuase this is bugging me, but I'll fix it later. --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ed22afa9..07557891 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -418,7 +418,7 @@ else log_write "No adlists.list file found... using adlists.default!" printf ":::\tNo adlists.list file found... using adlists.default!\n" fi - +echo # Continuously append the pihole.log file to the pihole_debug.log file dumpPiHoleLog() { From f9570a82ccb93427783aa6060ebc2354b757f60c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Oct 2016 00:58:24 -0700 Subject: [PATCH 15/30] Remove glitchy daemon detection. --- advanced/Scripts/piholeDebug.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 07557891..b9216191 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -211,19 +211,15 @@ daemon_check() { local found_daemon=false local lsof_value - if [[ ${IPV6_ENABLED} ]]; then lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv6" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + && (log_echo "Port ${2} is in use on IPv6" && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv6.") fi lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv4" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + && (log_echo "Port ${2} is in use on IPv4" && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") - if [[ "${found_daemon}" == false ]]; then - log_echo "Missing required daemon ${1}, please check configuration." - fi } testResolver() { From 0debbffa703e73ad83387588da524bbe9e53ca74 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 03:45:07 -0700 Subject: [PATCH 16/30] Add a couple of parsing utility functions. --- advanced/Scripts/piholeDebug.sh | 70 ++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b9216191..b80c9584 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -50,7 +50,7 @@ fi ### Private functions exist here ### log_write() { - echo "${1}" >> "${DEBUG_LOG}" + echo "${1}" >> "${DEBUG_LOG}" } header_write() { @@ -60,7 +60,31 @@ header_write() { } log_echo() { - echo "::: ${1}" + case ${1} in + -n) + echo -n "::: ${2}" + log_write ${2} + ;; + -l) + echo "${2}" + log_write "${2}" + ;; + *) + echo "::: ${1}" + log_write "${1}" + esac +} + +file_parse() { + while read -r line; do + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue + log_write "${line}" + fi + done < "${1}" +} + +block_parse() { log_write "${1}" } @@ -84,18 +108,13 @@ files_check() { #Check non-zero length existence of ${1} echo "::: Detecting existence of ${1}..." - local search_file=/etc/pihole/"${1}" + local search_file="${1}" if [[ -s ${search_file} ]]; then - log_echo "/etc/pihole/${1} exists!" - source "${search_file}" &> /dev/null && log_echo "Successfully sourced ${search_file}" || log_echo "Could not source ${search_file}" - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${search_file}" + log_echo -n "${1} exists" + source "${search_file}" &> /dev/null && log_echo -l " and successfully was sourced" || log_echo -l " and could not be sourced" + file_parse "${search_file}" else - log_echo "/etc/pihole/${1} not found!" + log_echo "${1} not found!" fi echo ":::" } @@ -104,7 +123,7 @@ distro_check() { header_write "Installed OS Distribution" echo "::: Checking installed OS Distribution release." - local distro="$(cat /etc/*release)" && log_write "${distro}" || log_write "Distribution details not found." + local distro="$(cat /etc/*release)" && block_parse "${distro}" || log_echo "Distribution details not found." echo ":::" } @@ -130,19 +149,22 @@ ip_check() { echo "::: Collecting local IP info." local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ - && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." + && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ + || log_echo "No IPv4 addresses found." local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo -n "::: Pinging default IPv4 gateway: " local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ - && echo "Gateway responded." || echo "Gateway did not respond." - log_write "${IPv4_def_gateway_check}" + && echo "Gateway responded." \ + || echo "Gateway did not respond." + block_parse "${IPv4_def_gateway_check}" echo -n "::: Pinging Internet via IPv4: " local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ - && echo "Query responded." || echo "Query did not respond." - log_write "${IPv4_inet_check}" + && echo "Query responded." \ + || echo "Query did not respond." + block_parse "${IPv4_inet_check}" fi if [[ IPV6_ENABLED ]]; then @@ -154,13 +176,15 @@ ip_check() { if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ - && echo "Gateway Responded." || echo "Gateway did not respond." - log_write "${IPv6_def_gateway_check}" + && echo "Gateway Responded." \ + || echo "Gateway did not respond." + block_parse "${IPv6_def_gateway_check}" echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ - && echo "Query responded." || echo "Query did not respond." - log_write "${IPv6_inet_check}" + && echo "Query responded." \ + || echo "Query did not respond." + block_parse "${IPv6_inet_check}" else log_echo="No IPv6 Gateway Detected" fi @@ -325,7 +349,7 @@ debugLighttpd() { ### END FUNCTIONS ### version_check -files_check "setupVars.conf" +files_check "/etc/pihole/setupVars.conf" distro_check ip_check hostnameCheck From e3c7a1f31f5d16fdb8543d3f523f021268fb630b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 03:49:03 -0700 Subject: [PATCH 17/30] Top half user output updated. --- advanced/Scripts/piholeDebug.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b80c9584..22a2a51a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -223,7 +223,7 @@ lsof_parse() { else match="incorrectly." fi - log_echo "by ${user} for ${process} ${match}" + log_echo -l "by ${user} for ${process} ${match}" } @@ -237,12 +237,12 @@ daemon_check() { if [[ ${IPV6_ENABLED} ]]; then lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv6" && lsof_parse "${lsof_value}" "${1}") \ + && (log_echo -n "IPv6 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv6.") fi lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv4" && lsof_parse "${lsof_value}" "${1}") \ + && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") } From 42bff1ce1bda887b9cc49752667a0caee8390ce2 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 03:53:53 -0700 Subject: [PATCH 18/30] Move parse utility to be near other parsing functions. --- advanced/Scripts/piholeDebug.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 22a2a51a..385ca230 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -88,6 +88,20 @@ block_parse() { log_write "${1}" } +lsof_parse() { + local user + local process + local match + + user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) + process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) + if [[ ${2} -eq ${process} ]]; then + match="as required." + else + match="incorrectly." + fi + log_echo -l "by ${user} for ${process} ${match}" +} version_check() { header_write "Installed Package Versions" echo "::: Detecting Pi-hole installed versions." @@ -209,21 +223,7 @@ hostnameCheck() { log_write "No hosts file found!" printf ":::\tNo hosts file found!\n" fi -} - -lsof_parse() { - local user - local process - local match - - user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) - process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) - if [[ ${2} -eq ${process} ]]; then - match="as required." - else - match="incorrectly." - fi - log_echo -l "by ${user} for ${process} ${match}" + echo ":::" } From 90ec0a610e66734d57af0614fe0550dd10df9d00 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 04:42:45 -0700 Subject: [PATCH 19/30] Tricorder is introduced. --- advanced/Scripts/piholeDebug.sh | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 385ca230..b9d18833 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -32,10 +32,15 @@ IPV6=ENABLED=false # Header info and introduction cat << EOM ::: Beginning Pi-hole debug at $(date)! -::: This debugging process will collect information from your running configuration, +::: +::: This debugging process will collect information from your Pi-hole, ::: and optionally upload the generated log to a unique and random directory on -::: Termbin.com. NOTE: All log files auto-delete after 1 month and you are the only -::: person who is given the unique URL. Please consider where you post this link. +::: tricorder.pi-hole.net. NOTE: All log files auto-delete after 24 hours and only +::: the Pi-hole developers can access your data via the generated token. We have taken +::: these extra steps to secure your data and we will work to further reduce any +::: personal information gathered. +::: +::: Please read and note any issues, and follow any directions advised during this process. ::: EOM @@ -214,15 +219,14 @@ hostnameCheck() { log_write "This Pi-hole is: $(hostname)" echo "::: Writing hosts file to debug log..." - log_write "### Hosts ###" + log_write "::: Hosts File Contents" - if [ -e "${HOSTSFILE}" ]; then - cat "${HOSTSFILE}" >> ${DEBUG_LOG} - log_write "" - else - log_write "No hosts file found!" - printf ":::\tNo hosts file found!\n" + if [[ -e "${HOSTSFILE}" ]]; then + file_parse "${HOSTSFILE}" + else + log_echo "No hosts file found!" fi + echo ":::" } @@ -244,6 +248,8 @@ daemon_check() { lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") + + echo ":::" } testResolver() { @@ -288,16 +294,10 @@ testResolver() { log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} - log_write "Insertions count:" - dig +short chaos txt insertions.bind >> ${DEBUG_LOG} - log_write "Evictions count:" - dig +short chaos txt evictions.bind >> ${DEBUG_LOG} log_write "Misses count:" dig +short chaos txt misses.bind >> ${DEBUG_LOG} log_write "Hits count:" dig +short chaos txt hits.bind >> ${DEBUG_LOG} - log_write "Auth count:" - dig +short chaos txt auth.bind >> ${DEBUG_LOG} log_write "Upstream Servers:" dig +short chaos txt servers.bind >> ${DEBUG_LOG} log_write "" @@ -458,24 +458,24 @@ dumpPiHoleLog() { # Anything to be done after capturing of pihole.log terminates finalWork() { + local tricorder echo "::: Finshed debugging!" - echo "::: The debug log can be uploaded to Termbin.com for easier sharing." + echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." read -r -p "::: Would you like to upload the log? [y/N] " response case ${response} in [yY][eE][sS]|[yY]) - TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) + tricorder=$(cat /var/log/pihole_debug.log | nc tricorder.pi-hole.net 9999) ;; *) - echo "::: Log will NOT be uploaded to Termbin." + echo "::: Log will NOT be uploaded to tricorder." ;; esac - # Check if termbin.com is reachable. When it's not, point to local log instead - if [ -n "${TERMBIN}" ]; then - echo "::: Debug log can be found at : ${TERMBIN}" - else - echo "::: Debug log can be found at : /var/log/pihole_debug.log" + # Check if tricorder.pi-hole.net is reachable and provide token. + if [ -n "${tricorder}" ]; then + echo "::: Your debug token is : ${tricorder}" fi + echo "::: Debug log can be found at : /var/log/pihole_debug.log" } trap finalWork EXIT From 01f10b56e8e4cc9a42f01d7571f8084bc16d2983 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 06:51:30 -0700 Subject: [PATCH 20/30] Refactor out some more reudndant code. --- advanced/Scripts/piholeDebug.sh | 49 ++++++++++++--------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b9d18833..fee8e87c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -107,6 +107,8 @@ lsof_parse() { fi log_echo -l "by ${user} for ${process} ${match}" } + + version_check() { header_write "Installed Package Versions" echo "::: Detecting Pi-hole installed versions." @@ -126,18 +128,25 @@ files_check() { header_write "File Check" #Check non-zero length existence of ${1} - echo "::: Detecting existence of ${1}..." + log_echo -n "Detecting existence of ${1}:" local search_file="${1}" if [[ -s ${search_file} ]]; then - log_echo -n "${1} exists" - source "${search_file}" &> /dev/null && log_echo -l " and successfully was sourced" || log_echo -l " and could not be sourced" - file_parse "${search_file}" + log_echo -l " exists" + file_parse "${search_file}" + return 0 else log_echo "${1} not found!" + return 1 fi echo ":::" } +source_file() { + local file_found=$(files_check "${1}") \ + && (source "${1}" &> /dev/null && log_echo -l "${file_found} and was successfully sourced") \ + || log_echo -l "${file_found} and could not be sourced" +} + distro_check() { header_write "Installed OS Distribution" @@ -318,38 +327,17 @@ checkProcesses() { } debugLighttpd() { - header_write "lighttpd.conf" - if [ -e "${LIGHTTPDFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${LIGHTTPDFILE}" - log_write "" - else - log_write "No lighttpd.conf file found!" - printf ":::\tNo lighttpd.conf file found\n" - fi - - if [ -e "${LIGHTTPDERRFILE}" ]; then - log_write "" - log_write "::: lighttpd error.log" - log_write "" - - cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG} - else - log_write "No lighttpd error.log file found!" - printf ":::\tNo lighttpd error.log file found\n" - fi - log_write "" + echo "::: Checking for necessary lighttpd files." + files_check "${LIGHTTPDFILE}" + files_check "${LIGHTTPDERRFILE}" + echo ":::" } ### END FUNCTIONS ### version_check -files_check "/etc/pihole/setupVars.conf" +source_file "/etc/pihole/setupVars.conf" distro_check ip_check hostnameCheck @@ -362,7 +350,6 @@ debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." header_write "Dnsmasq configuration" if [ -e "${DNSMASQFILE}" ]; then - #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue From c2cfc09f634c3d2a25028c2e07956a702c578927 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 07:06:05 -0700 Subject: [PATCH 21/30] Clean up more of the UX and log. Lots to go. --- 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 fee8e87c..0d9317bd 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -68,7 +68,7 @@ log_echo() { case ${1} in -n) echo -n "::: ${2}" - log_write ${2} + log_write "${2}" ;; -l) echo "${2}" @@ -131,7 +131,7 @@ files_check() { log_echo -n "Detecting existence of ${1}:" local search_file="${1}" if [[ -s ${search_file} ]]; then - log_echo -l " exists" + echo " exists" file_parse "${search_file}" return 0 else From 71e3a473d6043a25d91a465c177a0faa9a937e61 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 07:16:16 -0700 Subject: [PATCH 22/30] Fix = underbar --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 0d9317bd..370049bb 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -27,7 +27,7 @@ PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" # Default to no IPv6, will check and enable if needed. -IPV6=ENABLED=false +IPV6_ENABLED=false # Header info and introduction cat << EOM From d4a3a5c18000492d1511e9e1362dc382d9e73f14 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 10:42:30 -0700 Subject: [PATCH 23/30] Trying to implement The Brontide Idiom for design. --- advanced/Scripts/piholeDebug.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 370049bb..71a3ce27 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -111,17 +111,22 @@ lsof_parse() { version_check() { header_write "Installed Package Versions" + + local error_found + error_found=0 + echo "::: Detecting Pi-hole installed versions." local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_echo "Pi-hole: $pi_hole_ver" || log_echo "Pi-hole git repository not detected." + && log_echo "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ - && log_echo "WebUI: $admin_ver" || log_echo "Pi-hole Admin Pages git repository not detected." + && log_echo "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ - && log_echo "${light_ver}" || log_echo "lighttpd not installed." + && log_echo "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) local php_ver="$(php -v |& head -n1)" \ - && log_echo "${php_ver}" || log_echo "PHP not installed." + && log_echo "${php_ver}" || (log_echo "PHP not installed." && error_found=1) echo ":::" + return "${error_found}" } files_check() { @@ -242,7 +247,7 @@ hostnameCheck() { daemon_check() { # Check for daemon ${1} on port ${2} - header_write "Daemon Port Listening Information" + header_write "Daemon Process Information" echo "::: Checking port ${2} for ${1} listener." local found_daemon=false @@ -258,6 +263,8 @@ daemon_check() { && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") + echo "${1}file" + echo ":::" } @@ -327,7 +334,6 @@ checkProcesses() { } debugLighttpd() { - echo "::: Checking for necessary lighttpd files." files_check "${LIGHTTPDFILE}" files_check "${LIGHTTPDERRFILE}" @@ -336,11 +342,15 @@ debugLighttpd() { ### END FUNCTIONS ### -version_check +# Gather version of required packages / repositories +version_check || echo "REQUIRED FILES MISSING" + source_file "/etc/pihole/setupVars.conf" distro_check ip_check -hostnameCheck +#hostnameCheck + + daemon_check lighttpd http daemon_check dnsmasq domain checkProcesses From 85fbd66871f5d5e5a3a42556183600dfe0d520c1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 14:52:08 -0700 Subject: [PATCH 24/30] Good commit point, number of changes --- advanced/Scripts/piholeDebug.sh | 192 ++++++++++++++------------------ 1 file changed, 85 insertions(+), 107 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 71a3ce27..20abe318 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -13,73 +13,77 @@ set -o pipefail ######## GLOBAL VARS ######## +VARSFILE="/etc/pihole/setupVars.conf" DEBUG_LOG="/var/log/pihole_debug.log" DNSMASQFILE="/etc/dnsmasq.conf" -PIHOLECONFFILE="/etc/dnsmasq.d/01-pihole.conf" +DNSMASQCONFFILE="/etc/dnsmasq.d/01-pihole.conf" LIGHTTPDFILE="/etc/lighttpd/lighttpd.conf" LIGHTTPDERRFILE="/var/log/lighttpd/error.log" GRAVITYFILE="/etc/pihole/gravity.list" -HOSTSFILE="/etc/hosts" WHITELISTFILE="/etc/pihole/whitelist.txt" BLACKLISTFILE="/etc/pihole/blacklist.txt" -ADLISTSFILE="/etc/pihole/adlists.list" +ADLISTFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" -# Default to no IPv6, will check and enable if needed. -IPV6_ENABLED=false +IPV6_READY=false # Header info and introduction cat << EOM ::: Beginning Pi-hole debug at $(date)! ::: -::: This debugging process will collect information from your Pi-hole, -::: and optionally upload the generated log to a unique and random directory on -::: tricorder.pi-hole.net. NOTE: All log files auto-delete after 24 hours and only -::: the Pi-hole developers can access your data via the generated token. We have taken -::: these extra steps to secure your data and we will work to further reduce any -::: personal information gathered. +::: This process collects information from your Pi-hole, and optionally uploads +::: it to a unique and random directory on tricorder.pi-hole.net. ::: -::: Please read and note any issues, and follow any directions advised during this process. +::: NOTE: All log files auto-delete after 24 hours and ONLY the Pi-hole developers +::: can access your data via the given token. We have taken these extra steps to +::: secure your data and will work to further reduce any personal information gathered. ::: +::: Please read and note any issues, and follow any directions advised during this process. EOM # Ensure the file exists, create if not, clear if exists. -if [ ! -f "${DEBUG_LOG}" ]; then - touch ${DEBUG_LOG} - chmod 644 ${DEBUG_LOG} - chown "$USER":root ${DEBUG_LOG} -else - truncate -s 0 ${DEBUG_LOG} -fi +truncate --size=0 "${DEBUG_LOG}" +chmod 644 ${DEBUG_LOG} +chown "$USER":pihole ${DEBUG_LOG} + +source ${VARSFILE} ### Private functions exist here ### log_write() { echo "${1}" >> "${DEBUG_LOG}" } -header_write() { - echo "" >> "${DEBUG_LOG}" - echo "::: ${1}" >> "${DEBUG_LOG}" - echo "" >> "${DEBUG_LOG}" -} - log_echo() { case ${1} in -n) echo -n "::: ${2}" log_write "${2}" ;; + -r) + echo "::: ${2}" + log_write "${2}" + ;; -l) echo "${2}" log_write "${2}" ;; + -e) + echo "${2}" + log_write + ;; *) - echo "::: ${1}" + echo "::: ${1}" log_write "${1}" esac } +header_write() { + log_echo "" + log_echo "${1}" + log_write "" +} + file_parse() { while read -r line; do if [ ! -z "${line}" ]; then @@ -87,6 +91,7 @@ file_parse() { log_write "${line}" fi done < "${1}" + log_write "" } block_parse() { @@ -101,42 +106,37 @@ lsof_parse() { user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) if [[ ${2} -eq ${process} ]]; then - match="as required." + echo "::: Correctly configured." else - match="incorrectly." + log_echo "::: Failure: Incorrectly configured daemon." fi - log_echo -l "by ${user} for ${process} ${match}" + log_write "Found user ${user} with process ${process}" } version_check() { - header_write "Installed Package Versions" + header_write "Detecting Installed Package Versions:" local error_found error_found=0 - echo "::: Detecting Pi-hole installed versions." - local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_echo "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) + && log_echo -r "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ - && log_echo "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) + && log_echo -r "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ - && log_echo "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) + && log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) local php_ver="$(php -v |& head -n1)" \ - && log_echo "${php_ver}" || (log_echo "PHP not installed." && error_found=1) - echo ":::" + && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) return "${error_found}" } files_check() { - header_write "File Check" - #Check non-zero length existence of ${1} - log_echo -n "Detecting existence of ${1}:" + header_write "Detecting existence of ${1}:" local search_file="${1}" if [[ -s ${search_file} ]]; then - echo " exists" + echo "::: File exists" file_parse "${search_file}" return 0 else @@ -148,22 +148,31 @@ files_check() { source_file() { local file_found=$(files_check "${1}") \ - && (source "${1}" &> /dev/null && log_echo -l "${file_found} and was successfully sourced") \ + && (source "${1}" &> /dev/null && echo "${file_found} and was successfully sourced") \ || log_echo -l "${file_found} and could not be sourced" } distro_check() { - header_write "Installed OS Distribution" + local soft_fail + header_write "Detecting installed OS Distribution" + soft_fail=0 + local distro="$(cat /etc/*release)" && block_parse "${distro}" || (log_echo "Distribution details not found." && soft_fail=1) + return "${soft_fail}" +} - echo "::: Checking installed OS Distribution release." - local distro="$(cat /etc/*release)" && block_parse "${distro}" || log_echo "Distribution details not found." - echo ":::" +processor_check() { + local soft_fail + header_write "Checking processor variety" + + soft_fail=0 + log_write $(uname -m) || soft_fail=1 + return "${soft_fail}" } ipv6_check() { # Check if system is IPv6 enabled, for use in other functions - if [[ -a /proc/net/if_inet6 ]]; then - IPV6_ENABLED=true + if [[ $IPv6_address ]]; then + ls /proc/net/if_inet6 &>/dev/null && IPV6_READY=true return 0 else return 1 @@ -180,40 +189,39 @@ ip_check() { # If declared in setupVars.conf use it, otherwise defer to default # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash - echo "::: Collecting local IP info." - local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ +local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ || log_echo "No IPv4 addresses found." local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo -n "::: Pinging default IPv4 gateway: " + echo -n "::: Pinging default IPv4 gateway: " local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ && echo "Gateway responded." \ || echo "Gateway did not respond." block_parse "${IPv4_def_gateway_check}" - echo -n "::: Pinging Internet via IPv4: " + echo -n "::: Pinging Internet via IPv4: " local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ && echo "Query responded." \ || echo "Query did not respond." block_parse "${IPv4_inet_check}" fi - if [[ IPV6_ENABLED ]]; then + if [[ IPV6_READY ]]; then local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") \ || log_echo "No IPv6 addresses found." local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then - echo -n "::: Pinging default IPv6 gateway: " + echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ && echo "Gateway Responded." \ || echo "Gateway did not respond." block_parse "${IPv6_def_gateway_check}" - echo -n "::: Pinging Internet via IPv6: " + echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ && echo "Query responded." \ || echo "Query did not respond." @@ -221,51 +229,28 @@ ip_check() { else log_echo="No IPv6 Gateway Detected" fi - echo ":::" fi } -hostnameCheck() { - header_write "Hostname Information" - - echo "::: Writing locally configured hostnames to logfile" - # Write the hostname output to compare against entries in /etc/hosts, which is logged next - log_write "This Pi-hole is: $(hostname)" +port_check() { + local lsof_value - echo "::: Writing hosts file to debug log..." - log_write "::: Hosts File Contents" - - if [[ -e "${HOSTSFILE}" ]]; then - file_parse "${HOSTSFILE}" - else - log_echo "No hosts file found!" - fi - - echo ":::" + lsof_value=$(lsof -i ${1}:${2} -FcL | tr '\n' ' ') \ + && lsof_parse "${lsof_value}" "${3}" \ + || log_echo "Failure: IPv${1} Port not in use" } - daemon_check() { # Check for daemon ${1} on port ${2} header_write "Daemon Process Information" - echo "::: Checking port ${2} for ${1} listener." - local found_daemon=false - local lsof_value - - if [[ ${IPV6_ENABLED} ]]; then - lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ - && (log_echo -n "IPv6 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ - || (log_echo "Port ${2} is not in use on IPv6.") - fi + echo "::: Checking ${2} port for ${1} listener." + if [[ ${IPV6_READY} ]]; then + port_check 6 "${2}" "${1}" + fi lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ - && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ - || (log_echo "Port ${2} is not in use on IPv4.") - - echo "${1}file" - - echo ":::" + port_check 4 "${2}" "${1}" } testResolver() { @@ -344,9 +329,13 @@ debugLighttpd() { # Gather version of required packages / repositories version_check || echo "REQUIRED FILES MISSING" - +# Check for newer setupVars storage file source_file "/etc/pihole/setupVars.conf" -distro_check +# Gather information about the running distribution +distro_check || echo "Distro Check soft fail" +# Gather processor type +processor_check || echo "Processor Check soft fail" + ip_check #hostnameCheck @@ -357,31 +346,20 @@ checkProcesses testResolver debugLighttpd -echo "::: Writing dnsmasq.conf to debug log..." header_write "Dnsmasq configuration" -if [ -e "${DNSMASQFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${DNSMASQFILE}" - log_write "" -else - log_write "No dnsmasq.conf file found!" - printf ":::\tNo dnsmasq.conf file found!\n" -fi +files_check ${DNSMASQFILE} + echo "::: Writing 01-pihole.conf to debug log..." header_write "01-pihole.conf" -if [ -e "${PIHOLECONFFILE}" ]; then +if [ -e "${DNSMASQCONFFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${PIHOLECONFFILE}" + done < "${DNSMASQCONFFILE}" log_write else log_write "No 01-pihole.conf file found!" @@ -423,13 +401,13 @@ fi echo "::: Writing adlists.list to debug log..." header_write "adlists.list" -if [ -e "${ADLISTSFILE}" ]; then +if [ -e "${ADLISTFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${ADLISTSFILE}" + done < "${ADLISTFILE}" log_write else log_write "No adlists.list file found... using adlists.default!" From cb5c94ef5e5ab6e4c9b5b25b6559480b4c40e80c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:13:04 -0700 Subject: [PATCH 25/30] Sorry, left that gravity.list parser in. Big debug files. Cleared that up. --- advanced/Scripts/piholeDebug.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 20abe318..eac4a30f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -366,16 +366,12 @@ else printf ":::\tNo 01-pihole.conf file found\n" fi -echo "::: Writing size of gravity.list to debug log..." -header_write "gravity.list" -if [ -e "${GRAVITYFILE}" ]; then - wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG} - log_write "" -else - log_write "No gravity.list file found!" - printf ":::\tNo gravity.list file found\n" -fi +header_write "Analyzing gravity.list" + + gravity_length=$(wc -l "${GRAVITYFILE}") \ + && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ + || log_echo "Warning: No gravity.list file found!" ### Pi-hole application specific logging ### From d9a16b0ff406dba1ad68ed600eb80d3c821ce16b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:25:06 -0700 Subject: [PATCH 26/30] Clear up bottom half of script with fewer redundenicies. --- advanced/Scripts/piholeDebug.sh | 66 +++------------------------------ 1 file changed, 5 insertions(+), 61 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index eac4a30f..8ae9759c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -295,10 +295,6 @@ testResolver() { log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} - log_write "Misses count:" - dig +short chaos txt misses.bind >> ${DEBUG_LOG} - log_write "Hits count:" - dig +short chaos txt hits.bind >> ${DEBUG_LOG} log_write "Upstream Servers:" dig +short chaos txt servers.bind >> ${DEBUG_LOG} log_write "" @@ -346,25 +342,11 @@ checkProcesses testResolver debugLighttpd -header_write "Dnsmasq configuration" -files_check ${DNSMASQFILE} - - -echo "::: Writing 01-pihole.conf to debug log..." -header_write "01-pihole.conf" - -if [ -e "${DNSMASQCONFFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${DNSMASQCONFFILE}" - log_write -else - log_write "No 01-pihole.conf file found!" - printf ":::\tNo 01-pihole.conf file found\n" -fi +files_check "${DNSMASQFILE}" +files_check "${DNSMASQCONFFILE}" +files_check "${WHITELISTFILE}" +files_check "${BLACKLISTFILE}" +files_check "${ADLISTFILE}" header_write "Analyzing gravity.list" @@ -373,44 +355,6 @@ header_write "Analyzing gravity.list" && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ || log_echo "Warning: No gravity.list file found!" - -### Pi-hole application specific logging ### -echo "::: Writing whitelist to debug log..." -header_write "Whitelist" -if [ -e "${WHITELISTFILE}" ]; then - cat "${WHITELISTFILE}" >> ${DEBUG_LOG} - log_write -else - log_write "No whitelist.txt file found!" - printf ":::\tNo whitelist.txt file found!\n" -fi - -echo "::: Writing blacklist to debug log..." -header_write "Blacklist" -if [ -e "${BLACKLISTFILE}" ]; then - cat "${BLACKLISTFILE}" >> ${DEBUG_LOG} - log_write -else - log_write "No blacklist.txt file found!" - printf ":::\tNo blacklist.txt file found!\n" -fi - -echo "::: Writing adlists.list to debug log..." -header_write "adlists.list" -if [ -e "${ADLISTFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${ADLISTFILE}" - log_write -else - log_write "No adlists.list file found... using adlists.default!" - printf ":::\tNo adlists.list file found... using adlists.default!\n" -fi -echo - # Continuously append the pihole.log file to the pihole_debug.log file dumpPiHoleLog() { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT From 9cd830b6aa5b46a0e41cfbfe57bfac59b889c8b5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:37:45 -0700 Subject: [PATCH 27/30] Start to refine tests and clean up code. --- advanced/Scripts/piholeDebug.sh | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8ae9759c..e218d7f6 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -68,10 +68,6 @@ log_echo() { echo "${2}" log_write "${2}" ;; - -e) - echo "${2}" - log_write - ;; *) echo "::: ${1}" log_write "${1}" @@ -87,7 +83,7 @@ header_write() { file_parse() { while read -r line; do if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue + [[ "${line}" =~ ^#.*$ || ! "${line}" ]] && continue log_write "${line}" fi done < "${1}" @@ -101,15 +97,13 @@ block_parse() { lsof_parse() { local user local process - local match user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) - if [[ ${2} -eq ${process} ]]; then - echo "::: Correctly configured." - else - log_echo "::: Failure: Incorrectly configured daemon." - fi + [[ ${2} -eq ${process} ]] \ + && echo "::: Correctly configured." \ + || log_echo "::: Failure: Incorrectly configured daemon." + log_write "Found user ${user} with process ${process}" } @@ -333,8 +327,6 @@ distro_check || echo "Distro Check soft fail" processor_check || echo "Processor Check soft fail" ip_check -#hostnameCheck - daemon_check lighttpd http daemon_check dnsmasq domain From fad2d6b1d1da5a6c442c24d0ff978e9a8f0be163 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:53:18 -0700 Subject: [PATCH 28/30] Return values start showin up now. Logic operators too... --- advanced/Scripts/piholeDebug.sh | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e218d7f6..b228b0c9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -155,12 +155,8 @@ distro_check() { } processor_check() { - local soft_fail header_write "Checking processor variety" - - soft_fail=0 - log_write $(uname -m) || soft_fail=1 - return "${soft_fail}" + log_write $(uname -m) && return 0 || return 1 } ipv6_check() { @@ -173,34 +169,19 @@ ipv6_check() { fi } + ip_check() { header_write "IP Address Information" # Get the current interface for Internet traffic # Check if IPv6 enabled local IPv6_interface + local IPv4_interface ipv6_check && IPv6_interface=${piholeInterface:-$(ip -6 r | grep default | cut -d ' ' -f 5)} # If declared in setupVars.conf use it, otherwise defer to default # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash + IPv4_interface=${piholeInterface:-$(ip r | grep default | cut -d ' ' -f 5)} -local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ - && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ - || log_echo "No IPv4 addresses found." - - local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]]; then - echo -n "::: Pinging default IPv4 gateway: " - local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ - && echo "Gateway responded." \ - || echo "Gateway did not respond." - block_parse "${IPv4_def_gateway_check}" - - echo -n "::: Pinging Internet via IPv4: " - local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ - && echo "Query responded." \ - || echo "Query did not respond." - block_parse "${IPv4_inet_check}" - fi if [[ IPV6_READY ]]; then local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ @@ -223,6 +204,26 @@ local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet" else log_echo="No IPv6 Gateway Detected" fi + +local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ + && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ + || log_echo "No IPv4 addresses found." + + local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) + if [[ $? = 0 ]]; then + echo -n "::: Pinging default IPv4 gateway: " + local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" -I "${IPv4_interface}" | tail -n3)" \ + && echo "Gateway responded." \ + || echo "Gateway did not respond." + block_parse "${IPv4_def_gateway_check}" + + echo -n "::: Pinging Internet via IPv4: " + local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 -I "${IPv4_interface}" | tail -n3)" \ + && echo "Query responded." \ + || echo "Query did not respond." + block_parse "${IPv4_inet_check}" + fi + fi } From 908697a963c49ce9de0aa3178279c4fdb56fcb95 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 29 Oct 2016 12:04:18 -0700 Subject: [PATCH 29/30] User token instructions, and small bugfix for missing separator. --- advanced/Scripts/piholeDebug.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b228b0c9..665c1f28 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -302,7 +302,7 @@ checkProcesses() { PROCESSES=( lighttpd dnsmasq ) for i in "${PROCESSES[@]}"; do log_write "" - log_write -n "${i}" + log_write "${i}" log_write " processes status:" systemctl -l status "${i}" >> "${DEBUG_LOG}" done @@ -382,6 +382,8 @@ finalWork() { # Check if tricorder.pi-hole.net is reachable and provide token. if [ -n "${tricorder}" ]; then echo "::: Your debug token is : ${tricorder}" + echo "::: Please contact the Pi-hole team with your token to being assistance." + echo "::: Thank you." fi echo "::: Debug log can be found at : /var/log/pihole_debug.log" } From dcf6e6b14d35424923ec9b622d8ff8921fc6cafe Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 29 Oct 2016 12:24:22 -0700 Subject: [PATCH 30/30] Clarify user action required to end the scripts. --- advanced/Scripts/piholeDebug.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 665c1f28..6768a8ea 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -351,7 +351,9 @@ header_write "Analyzing gravity.list" # Continuously append the pihole.log file to the pihole_debug.log file 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 "::: " + echo "::: --= User Action Required =--" + echo -e "::: Try loading a site that you are having trouble with now from a client web browser.. \n:::\t(Press CTRL+C to finish logging.)" header_write "pihole.log" if [ -e "${PIHOLELOG}" ]; then while true; do