From 90a5a13197d9cb43d1f2daea39693a0e312d02cf Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 8 Apr 2020 15:35:07 +0200 Subject: [PATCH 001/297] Convert CONDITIONAL_FORWARDING to REV_SERVER settings. Try to detect intended CIDR range automatically. Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 56 +++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f0f8bc31..41e52747 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -210,8 +210,42 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 fi if [[ "${CONDITIONAL_FORWARDING}" == true ]]; then - add_dnsmasq_setting "server=/${CONDITIONAL_FORWARDING_DOMAIN}/${CONDITIONAL_FORWARDING_IP}" - add_dnsmasq_setting "server=/${CONDITIONAL_FORWARDING_REVERSE}/${CONDITIONAL_FORWARDING_IP}" + # Convert legacy "conditional forwarding" to rev-server configuration + REV_SERVER=true + add_setting "REV_SERVER" "true" + + REV_SERVER_DOMAIN="${CONDITIONAL_FORWARDING_DOMAIN}" + add_setting "REV_SERVER_DOMAIN" "${REV_SERVER_DOMAIN}" + + REV_SERVER_TARGET="${CONDITIONAL_FORWARDING_IP}" + add_setting "REV_SERVER_TARGET" "${REV_SERVER_TARGET}" + + # Remove obsolete settings from setupVars.conf + delete_setting "CONDITIONAL_FORWARDING" + delete_setting "CONDITIONAL_FORWARDING_REVERSE" + delete_setting "CONDITIONAL_FORWARDING_DOMAIN" + delete_setting "CONDITIONAL_FORWARDING_IP" + + # Try to detect intended CIDR by analyzing the target + if [[ "${REV_SERVER_TARGET}" =~ 10\..* ]]; then + # Private network, Class A (RFC 1597 + RFC 1918) + REV_SERVER_CIDR="10.0.0.0/8" + elif [[ "${REV_SERVER_TARGET}" =~ 192\.168\..* ]]; then + # Private network, Class C (RFC 1597 + RFC 1918) + REV_SERVER_CIDR="192.168.0.0/16" + else + # Something else. The user will have to adapt this + # as we cannot know how large their subnet is + REV_SERVER_CIDR="${REV_SERVER_TARGET}/32" + fi + add_setting "REV_SERVER_CIDR" "${REV_SERVER_CIDR}" + fi + + if [[ "${REV_SERVER}" == true ]]; then + add_dnsmasq_setting "rev-server=${REV_SERVER_CIDR},${REV_SERVER_TARGET}" + if [ -n "${REV_SERVER_DOMAIN}" ]; then + add_dnsmasq_setting "server=/${REV_SERVER_DOMAIN}/${REV_SERVER_TARGET}" + fi fi # Prevent Firefox from automatically switching over to DNS-over-HTTPS @@ -247,16 +281,16 @@ SetDNSServers() { change_setting "DNSSEC" "false" fi - if [[ "${args[6]}" == "conditional_forwarding" ]]; then - change_setting "CONDITIONAL_FORWARDING" "true" - change_setting "CONDITIONAL_FORWARDING_IP" "${args[7]}" - change_setting "CONDITIONAL_FORWARDING_DOMAIN" "${args[8]}" - change_setting "CONDITIONAL_FORWARDING_REVERSE" "${args[9]}" + if [[ "${args[6]}" == "rev-server" ]]; then + change_setting "REV_SERVER" "true" + change_setting "REV_SERVER_CIDR" "${args[7]}" + change_setting "REV_SERVER_TARGET" "${args[8]}" + change_setting "REV_SERVER_DOMAIN" "${args[9]}" else - change_setting "CONDITIONAL_FORWARDING" "false" - delete_setting "CONDITIONAL_FORWARDING_IP" - delete_setting "CONDITIONAL_FORWARDING_DOMAIN" - delete_setting "CONDITIONAL_FORWARDING_REVERSE" + change_setting "REV_SERVER" "false" + delete_setting "REV_SERVER_CIDR" + delete_setting "REV_SERVER_TARGET" + delete_setting "REV_SERVER_DOMAIN" fi ProcessDNSSettings From 4130af0aab17689c7295dbe90d1188fefd02874c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Apr 2020 09:05:43 +0200 Subject: [PATCH 002/297] Retain rev-server settings when the feature gets disabled. Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 41e52747..5e63f0cf 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -288,9 +288,6 @@ SetDNSServers() { change_setting "REV_SERVER_DOMAIN" "${args[9]}" else change_setting "REV_SERVER" "false" - delete_setting "REV_SERVER_CIDR" - delete_setting "REV_SERVER_TARGET" - delete_setting "REV_SERVER_DOMAIN" fi ProcessDNSSettings From 093054a1eb6bfc82968ab0c36f0dfc737514599b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Apr 2020 09:38:24 +0200 Subject: [PATCH 003/297] Automatically convert legacy IP range to Class C network Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5e63f0cf..d5bf46a4 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -231,12 +231,12 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 # Private network, Class A (RFC 1597 + RFC 1918) REV_SERVER_CIDR="10.0.0.0/8" elif [[ "${REV_SERVER_TARGET}" =~ 192\.168\..* ]]; then - # Private network, Class C (RFC 1597 + RFC 1918) + # Private network, Class B (RFC 1597 + RFC 1918) REV_SERVER_CIDR="192.168.0.0/16" else - # Something else. The user will have to adapt this - # as we cannot know how large their subnet is - REV_SERVER_CIDR="${REV_SERVER_TARGET}/32" + # Something else, convert to /24 subnet (preserves legacy behavior) + # This sed converts "192.168.1.2" to "192.168.1.0/24" + REV_SERVER_CIDR="$(sed "s+\\.[0-9]*$+\\.0/24+" <<< "${REV_SERVER_TARGET}")" fi add_setting "REV_SERVER_CIDR" "${REV_SERVER_CIDR}" fi From 4cf241b42bd86ce4344076518f99b963506d9cda Mon Sep 17 00:00:00 2001 From: Jeroen Baert <3607063+Forceflow@users.noreply.github.com> Date: Tue, 12 May 2020 19:59:19 +0200 Subject: [PATCH 004/297] Fix for pihole -w --nuke displaying help info even if command is executed correctly Signed-off-by: Jeroen Baert <3607063+Forceflow@users.noreply.github.com> --- advanced/Scripts/list.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 4f2e046f..7efd8758 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -222,6 +222,7 @@ Displaylist() { NukeList() { sqlite3 "${gravityDBfile}" "DELETE FROM domainlist WHERE type = ${typeId};" + exit 0; } for var in "$@"; do From af1129fc2878370d8b86b8fe40e2800534d2a98f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 25 May 2020 17:40:20 +0100 Subject: [PATCH 005/297] Add a check at the top of the script to determine if the script is being run on a supported OS Signed-off-by: Adam Warner --- automated install/basic-install.sh | 60 +++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 76b04457..a7024ca5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -174,6 +174,61 @@ is_command() { command -v "${check_command}" >/dev/null 2>&1 } +os_check() { + # This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net + # and determines whether or not the script is running on one of those systems + local remote_os_domain valid_os valid_version detected_os_pretty detected_os detected_version display_warning + remote_os_domain="versions.pi-hole.net" + valid_os=false + valid_version=false + display_warning=true + + detected_os_pretty=$(cat /etc/*release | grep PRETTY_NAME | cut -d '=' -f2- | tr -d '"') + detected_os=$(echo "${detected_os_pretty}" | sed 's/ .*//') + detected_version=$(cat /etc/*release | grep VERSION_ID | cut -d '=' -f2- | tr -d '"') + + mapfile -t supportedOS < <(dig +short -t txt ${remote_os_domain} | tr -d '"' | tr ' ' '\n') + + for i in "${supportedOS[@]}" + do + os_part=$(echo $i | cut -d '=' -f1) + versions_part=$(echo $i | cut -d '=' -f2-) + + if [[ "${detected_os}" =~ "${os_part}" ]]; then + valid_os=true + mapfile -t supportedVer < <(echo "${versions_part}" | tr ',' '\n') + for x in "${supportedVer[@]}" + do + if [[ "${detected_version}" =~ $x ]];then + valid_version=true + break + fi + done + break + fi + done + + if [ "$valid_os" = true ] && [ "$valid_version" = true ]; then + display_warning=false + fi + + if [ "$display_warning" = true ] && [ "$PIHOLE_SKIP_OS_CHECK" != true ]; then + printf " %b %bUnsupported OS detected%b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${COL_NC}" + printf " https://docs.pi-hole.net/main/prerequesites/#supported-operating-systems\\n" + printf "\\n" + printf " This check can be skipped by setting the environment variable %bPIHOLE_SKIP_OS_CHECK%b to %btrue%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" "${COL_LIGHT_RED}" "${COL_NC}" + printf " e.g: export PIHOLE_SKIP_OS_CHECK=true\\n" + printf " By setting this variable to true you acknowledge there may be issues with Pi-hole during or after the install\\n" + printf " If that is the case, you can feel free to ask the community on Discourse with the %bCommunity Help%b category:\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " https://discourse.pi-hole.net/c/bugs-problems-issues/community-help/\\n" + exit 1 + elif [ "$display_warning" = true ] && [ "$PIHOLE_SKIP_OS_CHECK" = true ]; then + printf " %b %bUnsupported OS detected%b. PIHOLE_SKIP_OS_CHECK env variable set to true - installer will continue\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}" + else + printf " %b %bSupported OS detected%b\\n" "${TICK}" "${COL_LIGHT_GREEN}" "${COL_NC}" + fi +} + # Compatibility distro_check() { # If apt-get is installed, then we know it's part of the Debian family @@ -608,7 +663,7 @@ verifyFreeDiskSpace() { printf " We were unable to determine available free disk space on this system.\\n" printf " You may override this check, however, it is not recommended.\\n" printf " The option '%b--i_do_not_follow_recommendations%b' can override this.\\n" "${COL_LIGHT_RED}" "${COL_NC}" - printf " e.g: curl -L https://install.pi-hole.net | bash /dev/stdin %b