From 6009e869471f7f1da0593d91d82855340c8643b1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 1 Jul 2020 18:39:09 +0200 Subject: [PATCH] Fix pihole status to not rely on a TCP port test. The current test can fail even when there is no error i case the max. number of TCP workers is reached. Signed-off-by: DL6ER --- pihole | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/pihole b/pihole index 065fb385..159922b0 100755 --- a/pihole +++ b/pihole @@ -250,16 +250,52 @@ Options: echo -e "${OVER} ${TICK} ${str}" } +analyze_ports() { + # FTL is listening at least on at least one port when this + # function is getting called + if [[ $(grep -c "IPv4" <<< "${1}") -gt 1 ]] && \ + [[ $(grep -c "IPv6" <<< "${1}") -gt 1 ]]; then + echo -e " ${TICK} DNS service is listening" + else + echo -e " ${CROSS} DNS service is partially listening" + # Check individual address family/protocol combinations + # For a healthy Pi-hole, they should all be up (nothing printed) + if grep -q "IPv4.*UDP" <<< "${1}"; then + echo -e " ${TICK} UDP (IPv4)" + else + echo -e " ${CROSS} UDP (IPv4)" + fi + if grep -q "IPv4.*TCP" <<< "${1}"; then + echo -e " ${TICK} TCP (IPv4)" + else + echo -e " ${CROSS} TCP (IPv4)" + fi + if grep -q "IPv6.*UDP" <<< "${1}"; then + echo -e " ${TICK} UDP (IPv6)" + else + echo -e " ${CROSS} UDP (IPv6)" + fi + if grep -q "IPv6.*TCP" <<< "${1}"; then + echo -e " ${TICK} TCP (IPv6)" + else + echo -e " ${CROSS} TCP (IPv6)" + fi + echo "" + fi +} + statusFunc() { - # Determine if service is running on port 53 (Cr: https://superuser.com/a/806331) - if (echo > /dev/tcp/127.0.0.1/53) >/dev/null 2>&1; then + # Determine if there is a pihole service is listening on port 53 + local listening + listening="$(lsof -Pni:53)" + if grep -q "pihole" <<< "${listening}"; then if [[ "${1}" != "web" ]]; then - echo -e " ${TICK} DNS service is running" + analyze_ports "${listening}" fi else case "${1}" in "web") echo "-1";; - *) echo -e " ${CROSS} DNS service is NOT running";; + *) echo -e " ${CROSS} DNS service is NOT listening";; esac return 0 fi @@ -269,13 +305,13 @@ statusFunc() { # A config is commented out case "${1}" in "web") echo 0;; - *) echo -e " ${CROSS} Pi-hole blocking is Disabled";; + *) echo -e " ${CROSS} Pi-hole blocking is disabled";; esac elif grep -q "BLOCKING_ENABLED=true" /etc/pihole/setupVars.conf; then # Configs are set case "${1}" in "web") echo 1;; - *) echo -e " ${TICK} Pi-hole blocking is Enabled";; + *) echo -e " ${TICK} Pi-hole blocking is enabled";; esac else # No configs were found