From a09f92f9cc664cc21381ab2d651c7803e7e361a0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 31 May 2019 22:12:54 -0700 Subject: [PATCH 01/23] Create FUNDING.yml Signed-off-by: Dan Schaper --- .github/FUNDING.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..3a75dc12 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms + +patreon: pihole +custom: https://pi-hole.net/donate From 91a2d052a7975d543e35d2d38aa65293e3b11e46 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 28 Jun 2019 20:49:56 -0700 Subject: [PATCH 02/23] Fix pihole -up showing FTL update when network is down Fixes #1877 Signed-off-by: Mcat12 --- automated install/basic-install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 1e87b943..baeaaa9d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2402,6 +2402,11 @@ FTLcheckUpdate() { local FTLlatesttag FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n') + if [[ $? != 0 ]]; then + # There was an issue while retrieving the latest version + return 3 + fi + if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then return 0 else From 37e7cd5211516e87fe84e5b908b93ae9aee6e2d5 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 28 Jun 2019 20:57:05 -0700 Subject: [PATCH 03/23] Fix ShellCheck issue by refactoring a bit Signed-off-by: Mcat12 --- automated install/basic-install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index baeaaa9d..380b424f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2399,14 +2399,16 @@ FTLcheckUpdate() { if [[ ${ftlLoc} ]]; then local FTLversion FTLversion=$(/usr/bin/pihole-FTL tag) + local FTLreleaseData local FTLlatesttag - FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n') - if [[ $? != 0 ]]; then + if ! FTLreleaseData=$(curl -sI https://github.com/pi-hole/FTL/releases/latest); then # There was an issue while retrieving the latest version return 3 fi + FTLlatesttag=$(grep 'Location' < "${FTLreleaseData}" | awk -F '/' '{print $NF}' | tr -d '\r\n') + if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then return 0 else From 7b2ac25a52b71fae5aac79742ad41c263cb402f0 Mon Sep 17 00:00:00 2001 From: Jeroen Baert <3607063+Forceflow@users.noreply.github.com> Date: Mon, 1 Jul 2019 03:42:02 +0200 Subject: [PATCH 04/23] Fix for 404 error when browsing to pi.hole (without /admin) Signed-off-by: Jeroen Baert <3607063+Forceflow@users.noreply.github.com> --- advanced/lighttpd.conf.debian | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 47bdbee0..2215bbdb 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -27,7 +27,7 @@ server.modules = ( ) server.document-root = "/var/www/html" -server.error-handler-404 = "pihole/index.php" +server.error-handler-404 = "/pihole/index.php" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) server.errorlog = "/var/log/lighttpd/error.log" server.pid-file = "/var/run/lighttpd.pid" From 9fedafed1595a2cb5fd9250b1e00e8088912e0da Mon Sep 17 00:00:00 2001 From: Jeroen Baert <3607063+Forceflow@users.noreply.github.com> Date: Wed, 3 Jul 2019 04:28:23 +0200 Subject: [PATCH 05/23] Fix 404 error when browsing to pi.hole (without /admin) (for fedora) Signed-off-by: Jeroen Baert <3607063+Forceflow@users.noreply.github.com> --- advanced/lighttpd.conf.fedora | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 27bc33cc..4232c90f 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -28,7 +28,7 @@ server.modules = ( ) server.document-root = "/var/www/html" -server.error-handler-404 = "pihole/index.php" +server.error-handler-404 = "/pihole/index.php" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) server.errorlog = "/var/log/lighttpd/error.log" server.pid-file = "/var/run/lighttpd.pid" From f1733f9c5d8a798b38e372abeba30c7ddc540a87 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Thu, 4 Jul 2019 13:11:46 -0700 Subject: [PATCH 06/23] Fetch adlists for the block page from gravity.db Signed-off-by: Mcat12 --- advanced/index.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index 78135e1a..b44a725d 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -111,11 +111,30 @@ if (is_file("/etc/pihole/adlists.list")) { die("[ERROR] File not found: /etc/pihole/adlists.list"); } -// Get all URLs starting with "http" or "www" from adlists and re-index array numerically -$adlistsUrls = array_values(preg_grep("/(^http)|(^www)/i", file($adLists, FILE_IGNORE_NEW_LINES))); +// Get possible non-standard location of FTL's database +$FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf"); +if(isset($FTLsettings["GRAVITYDB"])) { + $gravityDBFile = $FTLsettings["GRAVITYDB"]; +} else { + $gravityDBFile = "/etc/pihole/gravity.db"; +} + +// Connect to gravity.db +try { + $db = new SQLite3($gravityDBFile, SQLITE3_OPEN_READONLY); +} catch (Exception $exception) { + die("[ERROR]: Failed to connect to gravity.db"); +} + +// Get all adlist addresses +$adlistResults = $db->query("SELECT address FROM vw_adlist"); +$adlistsUrls = array(); +while($row = $adlistResults->fetchArray()) { + array_push($adlistsUrls, $row[0]); +} if (empty($adlistsUrls)) - die("[ERROR]: There are no adlist URL's found within $adLists"); + die("[ERROR]: There are no adlists configured"); // Get total number of blocklists (Including Whitelist, Blacklist & Wildcard lists) $adlistsCount = count($adlistsUrls) + 3; From 8d9ff550d469002b4aef323203f6ea7fd356f033 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Thu, 4 Jul 2019 13:44:14 -0700 Subject: [PATCH 07/23] Fix blockpage error if whitelisted, blacklisted, or regex filtered Signed-off-by: Mcat12 --- advanced/Scripts/query.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 4fc82744..6d061ba5 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -115,7 +115,9 @@ scanDatabaseTable() { wbMatch=true # Print table name - echo " ${matchType^} found in ${COL_BOLD}${table^}${COL_NC}" + if [[ -z "${blockpage}" ]]; then + echo " ${matchType^} found in ${COL_BOLD}${table^}${COL_NC}" + fi # Loop over results and print them mapfile -t results <<< "${result}" @@ -159,7 +161,7 @@ if [[ "${#regexList[@]}" -ne 0 ]]; then # shellcheck disable=SC2001 echo "${str_result}" | sed 's/^/ /' else - echo "π Regex list" + echo "π .wildcard" exit 0 fi fi From 2b5033e732e93be8e03a8049f1e83caa28a6bd25 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Thu, 4 Jul 2019 13:49:39 -0700 Subject: [PATCH 08/23] Add missing spaces found by linter Signed-off-by: Mcat12 --- advanced/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index b44a725d..ff13ec60 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -113,7 +113,7 @@ if (is_file("/etc/pihole/adlists.list")) { // Get possible non-standard location of FTL's database $FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf"); -if(isset($FTLsettings["GRAVITYDB"])) { +if (isset($FTLsettings["GRAVITYDB"])) { $gravityDBFile = $FTLsettings["GRAVITYDB"]; } else { $gravityDBFile = "/etc/pihole/gravity.db"; @@ -129,7 +129,7 @@ try { // Get all adlist addresses $adlistResults = $db->query("SELECT address FROM vw_adlist"); $adlistsUrls = array(); -while($row = $adlistResults->fetchArray()) { +while ($row = $adlistResults->fetchArray()) { array_push($adlistsUrls, $row[0]); } From c48b03584f315d20f8f05561709e59bd462ebb28 Mon Sep 17 00:00:00 2001 From: bcambl Date: Sat, 6 Jul 2019 10:57:57 -0600 Subject: [PATCH 09/23] update Fedora Dockerfile to 30 Signed-off-by: bcambl --- test/fedora.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fedora.Dockerfile b/test/fedora.Dockerfile index 8c27bbcc..a06fc007 100644 --- a/test/fedora.Dockerfile +++ b/test/fedora.Dockerfile @@ -1,4 +1,4 @@ -FROM fedora:29 +FROM fedora:30 ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From ec850dc82090683fd041673f489585e31e99569f Mon Sep 17 00:00:00 2001 From: bcambl Date: Sat, 6 Jul 2019 10:58:19 -0600 Subject: [PATCH 10/23] add chkconfig to INSTALLER_DEPS (CentOS/Fedora) chkconfig is a dependency of spawn-fcgi which is a dependency of lighttpd which is installed via PIHOLE_WEB_DEPS in phase 2 adding chkconfig to INSTALLER_DEPS to ensure /etc/init.d is present during the installation prompts (phase 1) Signed-off-by: bcambl --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 1e87b943..a4adac94 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -283,7 +283,7 @@ elif is_command rpm ; then UPDATE_PKG_CACHE=":" PKG_INSTALL=("${PKG_MANAGER}" install -y) PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" - INSTALLER_DEPS=(dialog git iproute newt procps-ng which) + INSTALLER_DEPS=(dialog git iproute newt procps-ng which chkconfig) PIHOLE_DEPS=(bind-utils cronie curl findutils nmap-ncat sudo unzip wget libidn2 psmisc sqlite libcap) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo) LIGHTTPD_USER="lighttpd" From 218476fab087a3fbd07170249a4b1371fb5f92f6 Mon Sep 17 00:00:00 2001 From: bcambl Date: Sat, 6 Jul 2019 11:06:08 -0600 Subject: [PATCH 11/23] ensure installation dependencies for FTL tests which rely on /etc/init.d Signed-off-by: bcambl --- test/test_automated_install.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 282c627d..4bfb0f6a 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -486,6 +486,13 @@ def test_FTL_download_aarch64_no_errors(Pihole): ''' confirms only aarch64 package is downloaded for FTL engine ''' + # mock whiptail answers and ensure installer dependencies + mock_command('whiptail', {'*': ('', '0')}, Pihole) + Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + install_dependent_packages ${INSTALLER_DEPS[@]} + ''') download_binary = Pihole.run(''' source /opt/pihole/basic-install.sh binary="pihole-FTL-aarch64-linux-gnu" @@ -501,6 +508,13 @@ def test_FTL_download_unknown_fails_no_errors(Pihole): ''' confirms unknown binary is not downloaded for FTL engine ''' + # mock whiptail answers and ensure installer dependencies + mock_command('whiptail', {'*': ('', '0')}, Pihole) + Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + install_dependent_packages ${INSTALLER_DEPS[@]} + ''') download_binary = Pihole.run(''' source /opt/pihole/basic-install.sh binary="pihole-FTL-mips" @@ -519,6 +533,13 @@ def test_FTL_download_binary_unset_no_errors(Pihole): ''' confirms unset binary variable does not download FTL engine ''' + # mock whiptail answers and ensure installer dependencies + mock_command('whiptail', {'*': ('', '0')}, Pihole) + Pihole.run(''' + source /opt/pihole/basic-install.sh + distro_check + install_dependent_packages ${INSTALLER_DEPS[@]} + ''') download_binary = Pihole.run(''' source /opt/pihole/basic-install.sh create_pihole_user From e8e5d4afda44f8d46d546cc12140b0dcc980aa39 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sun, 7 Jul 2019 18:10:39 -0700 Subject: [PATCH 12/23] Get file locations of FTL files from the config Instead of hardcoding the location of certain FTL files (`gravity.db`, `pihole-FTL.log`), read the configured location from FTL's config. The default location is used if no custom location has been configured. Signed-off-by: Mcat12 --- advanced/Scripts/piholeDebug.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 2bfeef2d..b9bd6e8c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -94,7 +94,35 @@ PIHOLE_RAW_BLOCKLIST_FILES="${PIHOLE_DIRECTORY}/list.*" PIHOLE_LOCAL_HOSTS_FILE="${PIHOLE_DIRECTORY}/local.list" PIHOLE_LOGROTATE_FILE="${PIHOLE_DIRECTORY}/logrotate" PIHOLE_SETUP_VARS_FILE="${PIHOLE_DIRECTORY}/setupVars.conf" -PIHOLE_GRAVITY_DB_FILE="${PIHOLE_DIRECTORY}/gravity.db" +PIHOLE_FTL_CONF_FILE="${PIHOLE_DIRECTORY}/pihole-FTL.conf" + +# Read the value of an FTL config key. The value is printed to stdout. +# +# Args: +# 1. The key to read +# 2. The default if the setting or config does not exist +get_ftl_conf_value() { + local key=$1 + local default=$2 + local value + + # Obtain key=... setting from pihole-FTL.conf + if [[ -e "$PIHOLE_FTL_CONF_FILE" ]]; then + # Constructed to return nothing when + # a) the setting is not present in the config file, or + # b) the setting is commented out (e.g. "#DBFILE=...") + value="$(sed -n -e "s/^\\s*$key=\\s*//p" ${PIHOLE_FTL_CONF_FILE})" + fi + + # Test for missing value. Use default value in this case. + if [[ -z "$value" ]]; then + value="$default" + fi + + echo "$value" +} + +PIHOLE_GRAVITY_DB_FILE=$(get_ftl_conf_value "GRAVITYDB" "${PIHOLE_DIRECTORY}/gravity.db") PIHOLE_COMMAND="${BIN_DIRECTORY}/pihole" PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE" @@ -105,7 +133,7 @@ FTL_PORT="${RUN_DIRECTORY}/pihole-FTL.port" PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log" PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*" PIHOLE_DEBUG_LOG="${LOG_DIRECTORY}/pihole_debug.log" -PIHOLE_FTL_LOG="${LOG_DIRECTORY}/pihole-FTL.log" +PIHOLE_FTL_LOG=$(get_ftl_conf_value "LOGFILE" "${LOG_DIRECTORY}/pihole-FTL.log") PIHOLE_WEB_SERVER_ACCESS_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/access.log" PIHOLE_WEB_SERVER_ERROR_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/error.log" From b154dd5f0792ff804ae5f1b5f8c704c00787a3ca Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 8 Jul 2019 19:48:50 -0700 Subject: [PATCH 13/23] Quote calls to read FTL config Signed-off-by: Mcat12 --- 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 b9bd6e8c..d1acb950 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -122,7 +122,7 @@ get_ftl_conf_value() { echo "$value" } -PIHOLE_GRAVITY_DB_FILE=$(get_ftl_conf_value "GRAVITYDB" "${PIHOLE_DIRECTORY}/gravity.db") +PIHOLE_GRAVITY_DB_FILE="$(get_ftl_conf_value "GRAVITYDB" "${PIHOLE_DIRECTORY}/gravity.db")" PIHOLE_COMMAND="${BIN_DIRECTORY}/pihole" PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE" @@ -133,7 +133,7 @@ FTL_PORT="${RUN_DIRECTORY}/pihole-FTL.port" PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log" PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*" PIHOLE_DEBUG_LOG="${LOG_DIRECTORY}/pihole_debug.log" -PIHOLE_FTL_LOG=$(get_ftl_conf_value "LOGFILE" "${LOG_DIRECTORY}/pihole-FTL.log") +PIHOLE_FTL_LOG="$(get_ftl_conf_value "LOGFILE" "${LOG_DIRECTORY}/pihole-FTL.log")" PIHOLE_WEB_SERVER_ACCESS_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/access.log" PIHOLE_WEB_SERVER_ERROR_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/error.log" From 5ff90522002576d9a0202a7d458d1d38117659e1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 9 Jul 2019 11:41:44 +0200 Subject: [PATCH 14/23] Review comments Signed-off-by: DL6ER --- advanced/Scripts/database_migration/gravity-db.sh | 7 +++++-- advanced/Scripts/webpage.sh | 5 +++-- gravity.sh | 7 +++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/database_migration/gravity-db.sh b/advanced/Scripts/database_migration/gravity-db.sh index 51a3480b..65b42b95 100644 --- a/advanced/Scripts/database_migration/gravity-db.sh +++ b/advanced/Scripts/database_migration/gravity-db.sh @@ -11,9 +11,12 @@ # Please see LICENSE file for your rights under this license. upgrade_gravityDB(){ - local database auditFile version + local database piholeDir auditFile version database="${1}" - auditFile="${2}" + piholeDir="${2}" + auditFile="${piholeDir}/auditlog.list" + + # Get database version version="$(sqlite3 "${database}" "SELECT \"value\" FROM \"info\" WHERE \"property\" = 'version';")" if [[ "$version" == "1" ]]; then diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 227363f0..9db10bda 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -560,8 +560,7 @@ addAudit() domains="" for domain in "$@" do - # Insert only the domain here. The date_added field will be - # filled with its default value (date_added = current timestamp) + # Check domain to be added. Only continue if it is valid validDomain="$(checkDomain "${domain}")" if [[ -n "${validDomain}" ]]; then # Put comma in between domains when there is @@ -574,6 +573,8 @@ addAudit() domains="${domains}('${domain}')" fi done + # Insert only the domain here. The date_added field will be + # filled with its default value (date_added = current timestamp) sqlite3 "${gravityDBfile}" "INSERT INTO domain_audit (domain) VALUES ${domains};" } diff --git a/gravity.sh b/gravity.sh index 89f77ce0..d7c66d68 100755 --- a/gravity.sh +++ b/gravity.sh @@ -30,7 +30,6 @@ whitelistFile="${piholeDir}/whitelist.txt" blacklistFile="${piholeDir}/blacklist.txt" regexFile="${piholeDir}/regex.list" adListFile="${piholeDir}/adlists.list" -auditFile="${piholeDir}/auditlog.list" localList="${piholeDir}/local.list" VPNList="/etc/openvpn/ipp.txt" @@ -123,8 +122,8 @@ database_table_from_file() { do # Only add non-empty lines if [[ -n "${domain}" ]]; then - if [[ "${table}" == "auditlist" ]]; then - # Auditlist table format + if [[ "${table}" == "domain_audit" ]]; then + # domain_audit table format (no enable or modified fields) echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}" else # White-, black-, and regexlist format @@ -188,7 +187,7 @@ migrate_to_database() { fi # Check if gravity database needs to be updated - upgrade_gravityDB "${gravityDBfile}" "${auditFile}" + upgrade_gravityDB "${gravityDBfile}" "${piholeDir}" } # Determine if DNS resolution is available before proceeding From 420f60b5c7748ccf939c104a77c9dbf30116f668 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 10 Jul 2019 11:56:39 +0200 Subject: [PATCH 15/23] Add timeout to migration script (1->2). Signed-off-by: DL6ER --- advanced/Scripts/database_migration/gravity/1_to_2.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/database_migration/gravity/1_to_2.sql b/advanced/Scripts/database_migration/gravity/1_to_2.sql index 90a48418..45b5fa02 100644 --- a/advanced/Scripts/database_migration/gravity/1_to_2.sql +++ b/advanced/Scripts/database_migration/gravity/1_to_2.sql @@ -1,3 +1,5 @@ +.timeout 30000 + CREATE TABLE domain_audit ( id INTEGER PRIMARY KEY AUTOINCREMENT, From fa8751f9ad89cbe1e9eb32784bdbb99e213ef390 Mon Sep 17 00:00:00 2001 From: Mark Drobnak Date: Wed, 10 Jul 2019 19:42:51 -0700 Subject: [PATCH 16/23] Fix error when checking if IP address is valid During install in `valid_ip`, we split up the IP address into octets to verify it is valid (each is <= 255). This validation was broken in #2743 when a variable usage was quoted where it should have stayed unquoted: ``` ./automated install/basic-install.sh: line 942: [[: 192.241.211.120: syntax error: invalid arithmetic operator (error token is ".241.211.120") ``` Due to this error, `127.0.0.1` would be used instead of the requested IP address. Also, this prevented the user from entering a custom DNS server as it would be marked as an invalid IP address. Signed-off-by: Mark Drobnak --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a4adac94..cb6783a2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -934,7 +934,7 @@ valid_ip() { # and set the new one to a dot (period) IFS='.' # Put the IP into an array - ip=("${ip}") + ip=(${ip}) # Restore the IFS to what it was IFS=${OIFS} ## Evaluate each octet by checking if it's less than or equal to 255 (the max for each octet) From c156af020c017e0a0429724cba695a4d1984bba1 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 10 Jul 2019 19:52:17 -0700 Subject: [PATCH 17/23] Use suggested array creation to fix linter error Signed-off-by: Mcat12 --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index cb6783a2..17bdde31 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -934,7 +934,7 @@ valid_ip() { # and set the new one to a dot (period) IFS='.' # Put the IP into an array - ip=(${ip}) + read -r -a ip <<< "${ip}" # Restore the IFS to what it was IFS=${OIFS} ## Evaluate each octet by checking if it's less than or equal to 255 (the max for each octet) From 1d5755a4c2712156bd16d30fe61fcaef229714c9 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Wed, 10 Jul 2019 21:18:58 -0700 Subject: [PATCH 18/23] Add tests for valid_ip Signed-off-by: Mcat12 --- test/test_automated_install.py | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 4bfb0f6a..cce11857 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -700,3 +700,42 @@ def test_IPv6_ULA_GUA_test(Pihole): ''') expected_stdout = 'Found IPv6 ULA address, using it for blocking IPv6 ads' assert expected_stdout in detectPlatform.stdout + + +def test_validate_ip_valid(Pihole): + ''' + Given a valid IP address, valid_ip returns success + ''' + + output = Pihole.run(''' + source /opt/pihole/basic-install.sh + valid_ip "192.168.1.1" + ''') + + assert output.rc == 0 + + +def test_validate_ip_invalid_octet(Pihole): + ''' + Given an invalid IP address (large octet), valid_ip returns an error + ''' + + output = Pihole.run(''' + source /opt/pihole/basic-install.sh + valid_ip "1092.168.1.1" + ''') + + assert output.rc == 1 + + +def test_validate_ip_invalid_letters(Pihole): + ''' + Given an invalid IP address (contains letters), valid_ip returns an error + ''' + + output = Pihole.run(''' + source /opt/pihole/basic-install.sh + valid_ip "not an IP" + ''') + + assert output.rc == 1 From c3ec2e68adf68b8d4ae169385e1158754e8a67d3 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 12 Jul 2019 20:03:36 -0700 Subject: [PATCH 19/23] Remove the ZeusTracker blocklist from the defaults It is no longer served. Fixes #2843. Signed-off-by: Mcat12 --- automated install/basic-install.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 17bdde31..65fb7c2e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1177,12 +1177,11 @@ chooseBlocklists() { mv "${adlistFile}" "${adlistFile}.old" fi # Let user select (or not) blocklists via a checklist - cmd=(whiptail --separate-output --checklist "Pi-hole relies on third party lists in order to block ads.\\n\\nYou can use the suggestions below, and/or add your own after installation\\n\\nTo deselect any list, use the arrow keys and spacebar" "${r}" "${c}" 7) + cmd=(whiptail --separate-output --checklist "Pi-hole relies on third party lists in order to block ads.\\n\\nYou can use the suggestions below, and/or add your own after installation\\n\\nTo deselect any list, use the arrow keys and spacebar" "${r}" "${c}" 6) # In an array, show the options available (all off by default): options=(StevenBlack "StevenBlack's Unified Hosts List" on MalwareDom "MalwareDomains" on Cameleon "Cameleon" on - ZeusTracker "ZeusTracker" on DisconTrack "Disconnect.me Tracking" on DisconAd "Disconnect.me Ads" on HostsFile "Hosts-file.net Ads" on) @@ -1205,7 +1204,6 @@ appendToListsFile() { StevenBlack ) echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >> "${adlistFile}";; MalwareDom ) echo "https://mirror1.malwaredomains.com/files/justdomains" >> "${adlistFile}";; Cameleon ) echo "http://sysctl.org/cameleon/hosts" >> "${adlistFile}";; - ZeusTracker ) echo "https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist" >> "${adlistFile}";; DisconTrack ) echo "https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt" >> "${adlistFile}";; DisconAd ) echo "https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt" >> "${adlistFile}";; HostsFile ) echo "https://hosts-file.net/ad_servers.txt" >> "${adlistFile}";; @@ -1223,7 +1221,6 @@ installDefaultBlocklists() { appendToListsFile StevenBlack appendToListsFile MalwareDom appendToListsFile Cameleon - appendToListsFile ZeusTracker appendToListsFile DisconTrack appendToListsFile DisconAd appendToListsFile HostsFile From 38ff3431340d3d35307aa7c6b18aebad9d1ff7e6 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 19 Jul 2019 17:35:21 -0700 Subject: [PATCH 20/23] Print an error message if the FTL release metadata download fails Signed-off-by: Mcat12 --- automated install/basic-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 380b424f..3641b961 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2404,6 +2404,7 @@ FTLcheckUpdate() { if ! FTLreleaseData=$(curl -sI https://github.com/pi-hole/FTL/releases/latest); then # There was an issue while retrieving the latest version + printf " %b Failed to retrieve latest FTL release metadata" "${CROSS}" return 3 fi From 3ebd43ebf00cd59b7ff8eef84885fd952a391acf Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Fri, 19 Jul 2019 17:39:00 -0700 Subject: [PATCH 21/23] Remove outdated adlists.list check and fix empty adlists error message Signed-off-by: Mcat12 --- advanced/index.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index ff13ec60..62e45091 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -102,15 +102,6 @@ if ($blocklistglob === array()) { die("[ERROR] There are no domain lists generated lists within /etc/pihole/! Please update gravity by running pihole -g, or repair Pi-hole using pihole -r."); } -// Set location of adlists file -if (is_file("/etc/pihole/adlists.list")) { - $adLists = "/etc/pihole/adlists.list"; -} elseif (is_file("/etc/pihole/adlists.default")) { - $adLists = "/etc/pihole/adlists.default"; -} else { - die("[ERROR] File not found: /etc/pihole/adlists.list"); -} - // Get possible non-standard location of FTL's database $FTLsettings = parse_ini_file("/etc/pihole/pihole-FTL.conf"); if (isset($FTLsettings["GRAVITYDB"])) { @@ -134,7 +125,7 @@ while ($row = $adlistResults->fetchArray()) { } if (empty($adlistsUrls)) - die("[ERROR]: There are no adlists configured"); + die("[ERROR]: There are no adlists enabled"); // Get total number of blocklists (Including Whitelist, Blacklist & Wildcard lists) $adlistsCount = count($adlistsUrls) + 3; From ecd6817aaf89e1c5012c9bbf0ac116ff6a79c4ab Mon Sep 17 00:00:00 2001 From: "B. Olausson" Date: Mon, 29 Jul 2019 18:34:00 +0200 Subject: [PATCH 22/23] This change fixes issue #145 "stty: standard input: Inappropriate ioctl for device ".It checks if a real terminal exist, if not it sets the screen size to a fixed value. This helps to avoid nasty and unnecessary logs when running "pihole -up" via e.g. cron. Signed-off-by: B. Olausson --- automated install/basic-install.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5b81f691..9891fd9d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -84,8 +84,13 @@ if [ -z "${USER}" ]; then fi -# Find the rows and columns will default to 80x24 if it can not be detected -screen_size=$(stty size || printf '%d %d' 24 80) +# Check if we are running on a real terminal and find the rows and columns +# If there is no real terminal, we will default to 80x24 +if [ -t 0 ] ; then + screen_size=$(stty size) +else + screen_size="24 80" +fi # Set rows variable to contain first number printf -v rows '%d' "${screen_size%% *}" # Set columns variable to contain second number From 63230cb72dbe4d7201aa68c6a5f3abe898f8de2d Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 4 Aug 2019 21:21:08 +0200 Subject: [PATCH 23/23] quick fix for when dig also returns a CNAME Signed-off-by: ryrun --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index d7c66d68..14b32827 100755 --- a/gravity.sh +++ b/gravity.sh @@ -349,7 +349,7 @@ gravity_DownloadBlocklistFromUrl() { else printf -v port "%s" "${PIHOLE_DNS_1#*#}" fi - ip=$(dig "@${ip_addr}" -p "${port}" +short "${domain}") + ip=$(dig "@${ip_addr}" -p "${port}" +short "${domain}" | tail -1) if [[ $(echo "${url}" | awk -F '://' '{print $1}') = "https" ]]; then port=443; else port=80