From ef30a85afb1653df4d3ce393dd6b8d7ecbb29ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 26 Dec 2021 17:10:48 +0100 Subject: [PATCH 01/11] Include port in status function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 81 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/pihole b/pihole index 055bd702..faa9fc2e 100755 --- a/pihole +++ b/pihole @@ -312,42 +312,55 @@ analyze_ports() { } statusFunc() { - # 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 - analyze_ports "${listening}" - fi + # Determine if there is pihole-FTL service is listening on any UDP port + local listening pid port + + pid="$(getFTLPID)" + if [[ "$pid" -eq "-1" ]]; then + case "${1}" in + "web") echo "-1";; + *) echo -e " ${CROSS} DNS service is NOT running";; + esac + return 0 else - case "${1}" in - "web") echo "-1";; - *) echo -e " ${CROSS} DNS service is NOT listening";; - esac - return 0 - fi + #get the port pihole-FTL is listening on + port="$(lsof -Pni UDP -p ${pid} -a | grep -m1 : | awk -F ":" '{print $2}')" + listening="$(lsof -Pni:53)" + if [[ ! -z "$port" ]]; then + if [[ "${1}" != "web" ]]; then + analyze_ports "${listening}" + fi + else + case "${1}" in + "web") echo "-1";; + *) echo -e " ${CROSS} DNS service is NOT listening";; + esac + return 0 + fi + + # Determine if Pi-hole's blocking is enabled + if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then + # A config is commented out + case "${1}" in + "web") echo 0;; + *) 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 "$port";; + *) echo -e " ${TICK} Pi-hole blocking is enabled";; + esac + else + # No configs were found + case "${1}" in + "web") echo -2;; + *) echo -e " ${INFO} Pi-hole blocking will be enabled";; + esac + # Enable blocking + "${PI_HOLE_BIN_DIR}"/pihole enable + fi - # Determine if Pi-hole's blocking is enabled - if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then - # A config is commented out - case "${1}" in - "web") echo 0;; - *) 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";; - esac - else - # No configs were found - case "${1}" in - "web") echo 99;; - *) echo -e " ${INFO} Pi-hole blocking will be enabled";; - esac - # Enable blocking - "${PI_HOLE_BIN_DIR}"/pihole enable fi } From 9f0e0dbd378bc3989c63e7fd98e2ef34c2a541f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 26 Dec 2021 18:10:36 +0100 Subject: [PATCH 02/11] Fix analyse ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index faa9fc2e..c16f46e8 100755 --- a/pihole +++ b/pihole @@ -327,7 +327,7 @@ statusFunc() { port="$(lsof -Pni UDP -p ${pid} -a | grep -m1 : | awk -F ":" '{print $2}')" listening="$(lsof -Pni:53)" if [[ ! -z "$port" ]]; then - if [[ "${1}" != "web" ]]; then + if [[ "${1}" != "web" ]] && [[ "$port" -eq 53 ]]; then analyze_ports "${listening}" fi else From 71ebd64f4e9745ca5ea021d2bfb2035bd5c2c64b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 26 Dec 2021 18:13:14 +0100 Subject: [PATCH 03/11] mend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index c16f46e8..b0f3b02c 100755 --- a/pihole +++ b/pihole @@ -285,7 +285,7 @@ Options: analyze_ports() { # FTL is listening at least on at least one port when this # function is getting called - echo -e " ${TICK} DNS service is listening" + echo -e " ${TICK} DNS service is listening on port 53" # 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 From 5ef731fc576825d2dbb9d59aff937e1838aa5c06 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Tue, 28 Dec 2021 12:11:26 +0100 Subject: [PATCH 04/11] Fix indention Co-authored-by: DL6ER --- pihole | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pihole b/pihole index b0f3b02c..01bbaaed 100755 --- a/pihole +++ b/pihole @@ -317,11 +317,11 @@ statusFunc() { pid="$(getFTLPID)" if [[ "$pid" -eq "-1" ]]; then - case "${1}" in - "web") echo "-1";; - *) echo -e " ${CROSS} DNS service is NOT running";; - esac - return 0 + case "${1}" in + "web") echo "-1";; + *) echo -e " ${CROSS} DNS service is NOT running";; + esac + return 0 else #get the port pihole-FTL is listening on port="$(lsof -Pni UDP -p ${pid} -a | grep -m1 : | awk -F ":" '{print $2}')" From 4a2f4c1bcea5ba554a2e3831431bef043fd89761 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Tue, 28 Dec 2021 12:11:46 +0100 Subject: [PATCH 05/11] Fix indention_2 Co-authored-by: DL6ER --- pihole | 70 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/pihole b/pihole index 01bbaaed..c3bab4f1 100755 --- a/pihole +++ b/pihole @@ -323,43 +323,43 @@ statusFunc() { esac return 0 else - #get the port pihole-FTL is listening on - port="$(lsof -Pni UDP -p ${pid} -a | grep -m1 : | awk -F ":" '{print $2}')" - listening="$(lsof -Pni:53)" - if [[ ! -z "$port" ]]; then - if [[ "${1}" != "web" ]] && [[ "$port" -eq 53 ]]; then - analyze_ports "${listening}" - fi - else - case "${1}" in - "web") echo "-1";; - *) echo -e " ${CROSS} DNS service is NOT listening";; - esac - return 0 + #get the port pihole-FTL is listening on + port="$(lsof -Pni UDP -p ${pid} -a | grep -m1 : | awk -F ":" '{print $2}')" + listening="$(lsof -Pni:53)" + if [[ ! -z "$port" ]]; then + if [[ "${1}" != "web" ]] && [[ "$port" -eq 53 ]]; then + analyze_ports "${listening}" fi + else + case "${1}" in + "web") echo "-1";; + *) echo -e " ${CROSS} DNS service is NOT listening";; + esac + return 0 + fi - # Determine if Pi-hole's blocking is enabled - if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then - # A config is commented out - case "${1}" in - "web") echo 0;; - *) 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 "$port";; - *) echo -e " ${TICK} Pi-hole blocking is enabled";; - esac - else - # No configs were found - case "${1}" in - "web") echo -2;; - *) echo -e " ${INFO} Pi-hole blocking will be enabled";; - esac - # Enable blocking - "${PI_HOLE_BIN_DIR}"/pihole enable - fi + # Determine if Pi-hole's blocking is enabled + if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then + # A config is commented out + case "${1}" in + "web") echo 0;; + *) 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 "$port";; + *) echo -e " ${TICK} Pi-hole blocking is enabled";; + esac + else + # No configs were found + case "${1}" in + "web") echo -2;; + *) echo -e " ${INFO} Pi-hole blocking will be enabled";; + esac + # Enable blocking + "${PI_HOLE_BIN_DIR}"/pihole enable + fi fi } From 2a869419b4d7b958f98f685be8a96f4da7c594e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 28 Dec 2021 12:18:39 +0100 Subject: [PATCH 06/11] Add netcat to dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bd2bf4c3..6a9f9491 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -287,7 +287,7 @@ package_manager_detect() { # Packages required to run this install script (stored as an array) INSTALLER_DEPS=(git iproute2 whiptail ca-certificates) # Packages required to run Pi-hole (stored as an array) - PIHOLE_DEPS=(cron curl iputils-ping lsof psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2) + PIHOLE_DEPS=(cron curl iputils-ping lsof psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2 netcat) # Packages required for the Web admin interface (stored as an array) # It's useful to separate this from Pi-hole, since the two repos are also setup separately PIHOLE_WEB_DEPS=(lighttpd "${phpVer}-common" "${phpVer}-cgi" "${phpVer}-sqlite3" "${phpVer}-xml" "${phpVer}-intl") @@ -332,7 +332,7 @@ package_manager_detect() { PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" OS_CHECK_DEPS=(grep bind-utils) INSTALLER_DEPS=(git iproute newt procps-ng which chkconfig ca-certificates) - PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc sqlite libcap lsof) + PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc sqlite libcap lsof nmap-ncat) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl) LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd" From 5729f64ddc82d3ef477293c6d404a05d1a2ac82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 28 Dec 2021 12:21:31 +0100 Subject: [PATCH 07/11] Fix missing fi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index c3bab4f1..5b062267 100755 --- a/pihole +++ b/pihole @@ -337,7 +337,7 @@ statusFunc() { esac return 0 fi - + fi # Determine if Pi-hole's blocking is enabled if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then # A config is commented out From f45248df805c426f9d9e654c0f71eb1fd8b795e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 28 Dec 2021 13:39:45 +0100 Subject: [PATCH 08/11] Use FTL's new dns-port API endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pihole b/pihole index 5b062267..d9f8b5fa 100755 --- a/pihole +++ b/pihole @@ -312,7 +312,7 @@ analyze_ports() { } statusFunc() { - # Determine if there is pihole-FTL service is listening on any UDP port + # Determine if there is pihole-FTL service is listening local listening pid port pid="$(getFTLPID)" @@ -323,21 +323,22 @@ statusFunc() { esac return 0 else - #get the port pihole-FTL is listening on - port="$(lsof -Pni UDP -p ${pid} -a | grep -m1 : | awk -F ":" '{print $2}')" + #get the port pihole-FTL is listening on by using FTL's telnet API + port="$(echo ">dns-port >quit" | nc 127.0.0.1 4711)" listening="$(lsof -Pni:53)" - if [[ ! -z "$port" ]]; then - if [[ "${1}" != "web" ]] && [[ "$port" -eq 53 ]]; then - analyze_ports "${listening}" - fi - else + if [[ "${port}" == "0" ]]; then case "${1}" in "web") echo "-1";; *) echo -e " ${CROSS} DNS service is NOT listening";; esac return 0 + else + if [[ "${1}" != "web" ]] && [[ "$port" -eq 53 ]]; then + analyze_ports "${listening}" + fi fi fi + # Determine if Pi-hole's blocking is enabled if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then # A config is commented out @@ -361,7 +362,6 @@ statusFunc() { "${PI_HOLE_BIN_DIR}"/pihole enable fi - fi } tailFunc() { From 2b52f9264769e9b1254da9552bd65df46f198cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 28 Dec 2021 19:36:32 +0100 Subject: [PATCH 09/11] Inlcude port also in cli output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pihole b/pihole index d9f8b5fa..f93da52c 100755 --- a/pihole +++ b/pihole @@ -350,7 +350,8 @@ statusFunc() { # Configs are set case "${1}" in "web") echo "$port";; - *) echo -e " ${TICK} Pi-hole blocking is enabled";; + *) echo -e " ${TICK} Pi-hole blocking is enabled. FTL is listening on port ${port}" + ;; esac else # No configs were found From bcb59159ed659c7c8e2ccec8447285aede7f6845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 28 Dec 2021 19:52:11 +0100 Subject: [PATCH 10/11] Analyse port also on ports other than 53 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole b/pihole index f93da52c..a8f20b69 100755 --- a/pihole +++ b/pihole @@ -325,7 +325,7 @@ statusFunc() { else #get the port pihole-FTL is listening on by using FTL's telnet API port="$(echo ">dns-port >quit" | nc 127.0.0.1 4711)" - listening="$(lsof -Pni:53)" + listening="$(lsof -Pni:${port})" if [[ "${port}" == "0" ]]; then case "${1}" in "web") echo "-1";; @@ -333,7 +333,8 @@ statusFunc() { esac return 0 else - if [[ "${1}" != "web" ]] && [[ "$port" -eq 53 ]]; then + if [[ "${1}" != "web" ]]; then + echo -e " ${TICK} FTL is listening on port ${port}" analyze_ports "${listening}" fi fi @@ -350,8 +351,7 @@ statusFunc() { # Configs are set case "${1}" in "web") echo "$port";; - *) echo -e " ${TICK} Pi-hole blocking is enabled. FTL is listening on port ${port}" - ;; + *) echo -e " ${TICK} Pi-hole blocking is enabled";; esac else # No configs were found From 3989cc19e9a50a84fc996c870a94d044d1d152f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 28 Dec 2021 19:55:42 +0100 Subject: [PATCH 11/11] Remove double text output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 1 - 1 file changed, 1 deletion(-) diff --git a/pihole b/pihole index a8f20b69..cd18b273 100755 --- a/pihole +++ b/pihole @@ -285,7 +285,6 @@ Options: analyze_ports() { # FTL is listening at least on at least one port when this # function is getting called - echo -e " ${TICK} DNS service is listening on port 53" # 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