From e9f1ca338ffe1a626eb868693f138430ff1ac67a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 22:49:47 -0700 Subject: [PATCH 1/5] Create temp files for working storage, log to working storage temps. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index df9ed4f0..3ecc3f4b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -52,7 +52,7 @@ source ${VARSFILE} ### Private functions exist here ### log_write() { - echo "${1}" >> "${DEBUG_LOG}" + printf "%b" "${@}" >&3 } log_echo() { @@ -417,7 +417,7 @@ dumpPiHoleLog() { if [ -e "${PIHOLELOG}" ]; then # Dummy process to use for flagging down tail to terminate countdown & - tail -n0 -f --pid=$! "${PIHOLELOG}" >> ${DEBUG_LOG} + tail -n0 -f --pid=$! "${PIHOLELOG}" >&4 else log_write "No pihole.log file found!" printf ":::\tNo pihole.log file found!\n" @@ -456,6 +456,17 @@ finalWork() { } ### END FUNCTIONS ### +# Create temporary file for log +TEMPLOG=$(mktemp /tmp/pihole_temp.XXXXXX) +# Open handle 3 for templog +exec 3>"$TEMPLOG" +# Delete templog, but allow for addressing via file handle. +rm "$TEMPLOG" + +# Create temporary file for logdump using file handle 4 +DUMPLOG=$(mktemp /tmp/pihole_temp.XXXXXX) +exec 4>"$DUMPLOG" +rm "$DUMPLOG" # Gather version of required packages / repositories version_check || echo "REQUIRED FILES MISSING" From 0a0c3a2fb76fdee1c6d01d32d0e18786e8df29f7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:20:12 -0700 Subject: [PATCH 2/5] Copy working temp to final location. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3ecc3f4b..8649bb90 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -43,16 +43,11 @@ cat << EOM ::: 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. -truncate --size=0 "${DEBUG_LOG}" -chmod 644 ${DEBUG_LOG} -chown "$USER":pihole ${DEBUG_LOG} - source ${VARSFILE} ### Private functions exist here ### log_write() { - printf "%b" "${@}" >&3 + echo "${@}" >&3 } log_echo() { @@ -363,9 +358,9 @@ testChaos(){ log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" - dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} + log_write $(dig +short chaos txt cachesize.bind) log_write "Upstream Servers:" - dig +short chaos txt servers.bind >> ${DEBUG_LOG} + log_write $(dig +short chaos txt servers.bind) log_write "" } @@ -378,7 +373,7 @@ checkProcesses() { log_write "" log_write "${i}" log_write " processes status:" - systemctl -l status "${i}" >> "${DEBUG_LOG}" + log_write $(systemctl -l status "${i}") done log_write "" } @@ -428,6 +423,14 @@ dumpPiHoleLog() { finalWork() { local tricorder echo "::: Finshed debugging!" + + # Ensure the file exists, create if not, clear if exists. + truncate --size=0 "${DEBUG_LOG}" + chmod 644 ${DEBUG_LOG} + chown "$USER":pihole ${DEBUG_LOG} + # copy working temp file to final log location + cp /proc/$$/fd/3 "$DEBUG_LOG" + echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." if [[ "${AUTOMATED}" ]]; then echo "::: Debug script running in automated mode, uploading log to tricorder..." From 160030b75f3ad6124001fe97cd8ba5468106c5e9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:27:18 -0700 Subject: [PATCH 3/5] Quiet systemctl output to just the current daemon status. Signed-off-by: Dan Schaper --- 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 8649bb90..136d92d1 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -72,7 +72,7 @@ log_echo() { header_write() { log_echo "" - log_echo "${1}" + log_echo "---= ${1}" log_write "" } @@ -370,10 +370,8 @@ checkProcesses() { echo "::: Logging status of lighttpd, dnsmasq and pihole-FTL..." PROCESSES=( lighttpd dnsmasq pihole-FTL ) for i in "${PROCESSES[@]}"; do - log_write "" - log_write "${i}" - log_write " processes status:" - log_write $(systemctl -l status "${i}") + log_write "Status for ${i} daemon:" + log_write $(systemctl is-active "${i}") done log_write "" } From 77378da70ad49f6467ac008e8e3f06dc3c543f8c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:43:41 -0700 Subject: [PATCH 4/5] Cat out temp files to final log. Signed-off-by: Dan Schaper --- 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 136d92d1..d3c85d3a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -427,7 +427,9 @@ finalWork() { chmod 644 ${DEBUG_LOG} chown "$USER":pihole ${DEBUG_LOG} # copy working temp file to final log location - cp /proc/$$/fd/3 "$DEBUG_LOG" + cat /proc/$$/fd/3 >> "${DEBUG_LOG}" + # Straight dump of tailing the logs, can sanitize later if needed. + cat /proc/$$/fd/4 >> "${DEBUG_LOG}" echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." if [[ "${AUTOMATED}" ]]; then From b1f769b671bfdfd424172b754ef2f6cc6cb31aee Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:50:29 -0700 Subject: [PATCH 5/5] Output cleaning, IP stack check headers. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index d3c85d3a..6274e04e 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -226,6 +226,7 @@ ipv6_check() { ip_check() { local protocol=${1} local gravity=${2} + header_write "Checking IPv${protocol} Stack" local ip_addr_list="$(ip -${protocol} addr show dev ${PIHOLE_INTERFACE} | awk -F ' ' '{ for(i=1;i<=NF;i++) if ($i ~ '/^inet/') print $(i+1) }')" if [[ -n ${ip_addr_list} ]]; then