From 5b84cd0a618d2f4fe9ce3f84b52da0f9b1001c68 Mon Sep 17 00:00:00 2001 From: Omoeba <38597972+Omoeba@users.noreply.github.com> Date: Mon, 3 Jan 2022 04:02:01 -0800 Subject: [PATCH 001/638] Fix IPv6 support when Pi-hole is a router Signed-off-by: Omoeba <38597972+Omoeba@users.noreply.github.com> --- advanced/Scripts/webpage.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 4f44eca864..90cf08fc03 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -441,7 +441,6 @@ dhcp-leasefile=/etc/pihole/dhcp.leases #enable-ra dhcp-option=option6:dns-server,[::] dhcp-range=::100,::1ff,constructor:${interface},ra-names,slaac,64,3600 -ra-param=*,0,0 " >> "${dhcpconfig}" fi From d78c689e552d184b4e2d713f491fba93f9b4994a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 21 Apr 2022 19:56:21 +0100 Subject: [PATCH 002/638] no more alphabetical order Signed-off-by: Adam Warner --- advanced/Scripts/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index f0a7cc3739..bdd238c34a 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -12,7 +12,7 @@ # Basic Housekeeping rules # - Functions must be self contained -# - Functions must be added in alphabetical order +# - Functions should be grouped with other similar functions # - Functions must be documented # - New functions must have a test added for them in test/test_any_utils.py From 6a0c6c4a9b25e39ccf6c2580db2b3257ddc0b69e Mon Sep 17 00:00:00 2001 From: Leon <82407168+sed-i@users.noreply.github.com> Date: Mon, 25 Apr 2022 18:55:27 -0400 Subject: [PATCH 003/638] Add example for custom DNS server with port number Signed-off-by: sed-i <82407168+sed-i@users.noreply.github.com> --- 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 835f0efc75..f61f47ee98 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -946,7 +946,7 @@ setDNS() { fi # Prompt the user to enter custom upstream servers - piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\\n\\nFor example '8.8.8.8, 8.8.4.4'" "${r}" "${c}" "${prePopulate}" 3>&1 1>&2 2>&3) || \ + piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\\n\\nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335'" "${r}" "${c}" "${prePopulate}" 3>&1 1>&2 2>&3) || \ { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; exit 1; } # Clean user input and replace whitespace with comma. piholeDNS=$(sed 's/[, \t]\+/,/g' <<< "${piholeDNS}") From 2e2a3aa0482300320ead1ca7784da9eae06c256e Mon Sep 17 00:00:00 2001 From: yubiuser Date: Mon, 9 May 2022 17:14:16 +0200 Subject: [PATCH 004/638] Add port info to explanation text --- 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 f61f47ee98..2ac713e854 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -946,7 +946,7 @@ setDNS() { fi # Prompt the user to enter custom upstream servers - piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\\n\\nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335'" "${r}" "${c}" "${prePopulate}" 3>&1 1>&2 2>&3) || \ + piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma. If you want to specify a port other than 53, separate it with a hash.\\n\\nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335'" "${r}" "${c}" "${prePopulate}" 3>&1 1>&2 2>&3) || \ { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; exit 1; } # Clean user input and replace whitespace with comma. piholeDNS=$(sed 's/[, \t]\+/,/g' <<< "${piholeDNS}") From f7c800863e5ab02e56150a02f06b99de645bb84f Mon Sep 17 00:00:00 2001 From: Omoeba <38597972+Omoeba@users.noreply.github.com> Date: Wed, 11 May 2022 11:57:42 -0700 Subject: [PATCH 005/638] Remove DHCPv6, use leasetime from interface (#4507) Signed-off-by: Omoeba <38597972+Omoeba@users.noreply.github.com> --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index de06d60c38..aa5a28b1fd 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -440,7 +440,7 @@ dhcp-leasefile=/etc/pihole/dhcp.leases echo "#quiet-dhcp6 #enable-ra dhcp-option=option6:dns-server,[::] -dhcp-range=::100,::1ff,constructor:${interface},ra-names,slaac,64,3600 +dhcp-range=::,constructor:${interface},ra-names,ra-stateless,64 ra-param=*,0,0 " >> "${dhcpconfig}" fi From f2e1cc9dae40ce37449fc1c675d1b9b7f0f3c3c6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 11 May 2022 12:28:32 -0700 Subject: [PATCH 006/638] Typo fix on dependabot yaml. --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e10beb30f8..be18a8f3c4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,4 +7,4 @@ updates: day: saturday time: "10:00" open-pull-requests-limit: 10 - target-branch: developement \ No newline at end of file + target-branch: development From 0decc1252b75908f8d186ac060a6d819c4276dca Mon Sep 17 00:00:00 2001 From: yubiuser Date: Thu, 12 May 2022 01:03:44 +0200 Subject: [PATCH 007/638] Respect user configurable path for pid and port file in pihole-FTL.service (#4680) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use pid file in pihole-FTL.service Signed-off-by: Christian König Co-authored-by: MichaIng --- advanced/Templates/pihole-FTL.service | 68 ++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 41ab801811..c45d0dc1c3 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -9,8 +9,55 @@ # Description: Enable service provided by pihole-FTL daemon ### END INIT INFO +# Global variables +FTLCONFFILE="/etc/pihole/pihole-FTL.conf" +DEFAULT_PID_FILE="/run/pihole-FTL.pid" +DEFAULT_PORT_FILE="/run/pihole-FTL.port" +FTL_PID='' + +# Get the file path of the pihole-FTL.pid file +getFTLPIDFile() { + if [ -s "${FTLCONFFILE}" ]; then + # if PIDFILE is not set in pihole-FTL.conf, use the default path + FTL_PID_FILE="$({ grep '^PIDFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PID_FILE}"; } | cut -d'=' -f2-)" + else + # if there is no pihole-FTL.conf, use the default path + FTL_PID_FILE="${DEFAULT_PID_FILE}" + fi +} + +# Get the PID of the FTL process based on the content of the pihole-FTL.pid file +getFTLPID() { + if [ -s "${FTL_PID_FILE}" ]; then + # -s: FILE exists and has a size greater than zero + FTL_PID="$(cat "${FTL_PID_FILE}")" + # Exploit prevention: unset the variable if there is malicious content + # Verify that the value read from the file is numeric + expr "${FTL_PID}" : "[^[:digit:]]" > /dev/null && unset FTL_PID + fi + + # If FTL is not running, or the PID file contains malicious stuff, substitute + # negative PID to signal this + FTL_PID=${FTL_PID:=-1} +} + +# Get the file path of the pihole-FTL.port file +getFTLPortFile() { + if [ -s "${FTLCONFFILE}" ]; then + # if PORTFILE is not set in pihole-FTL.conf, use the default path + FTL_PORT_FILE="$({ grep '^PORTFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PORT_FILE}"; } | cut -d'=' -f2-)" + else + # if there is no pihole-FTL.conf, use the default path + FTL_PORT_FILE="${DEFAULT_PORT_FILE}" +fi +} + + is_running() { - pgrep -xo "pihole-FTL" > /dev/null + if [ -d "/proc/${FTL_PID}" ]; then + return 0 + fi + return 1 } @@ -21,8 +68,8 @@ start() { else # Touch files to ensure they exist (create if non-existing, preserve if existing) mkdir -pm 0755 /run/pihole - [ ! -f /run/pihole-FTL.pid ] && install -m 644 -o pihole -g pihole /dev/null /run/pihole-FTL.pid - [ ! -f /run/pihole-FTL.port ] && install -m 644 -o pihole -g pihole /dev/null /run/pihole-FTL.port + [ ! -f "${FTL_PID_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" + [ ! -f "${FTL_PORT_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" [ ! -f /var/log/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole-FTL.log [ ! -f /var/log/pihole.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole.log [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases @@ -47,7 +94,7 @@ start() { # Stop the service stop() { if is_running; then - pkill -xo "pihole-FTL" + kill "${FTL_PID}" for i in 1 2 3 4 5; do if ! is_running; then break @@ -60,8 +107,7 @@ stop() { if is_running; then echo "Not stopped; may still be shutting down or shutdown may have failed, killing now" - pkill -xo -9 "pihole-FTL" - exit 1 + kill -9 "${FTL_PID}" else echo "Stopped" fi @@ -69,7 +115,7 @@ stop() { echo "Not running" fi # Cleanup - rm -f /run/pihole/FTL.sock /dev/shm/FTL-* + rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}" "${FTL_PORT_FILE}" echo } @@ -86,6 +132,14 @@ status() { ### main logic ### + +# Get file paths +getFTLPIDFile +getFTLPortFile + +# Get FTL's current PID +getFTLPID + case "$1" in stop) stop From 1d033ef4416168a744bfeff9017b1f9f06c325a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 May 2022 07:23:57 +0000 Subject: [PATCH 008/638] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a4f67b81f4..486f027d4f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 5b9fa570e3..f79b69f2c4 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -11,7 +11,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Opening pull request id: pull uses: tretuna/sync-branches@1.4.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d39852dc2b..872be3d63b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Run Smoke Tests run: | @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Set up Python 3.8 uses: actions/setup-python@v3 From c5b3f6c27a6ec757c7a6fd116d8381ecce0abf12 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 May 2022 07:24:01 +0000 Subject: [PATCH 009/638] Bump actions/stale from 4 to 5 Bumps [actions/stale](https://github.com/actions/stale) from 4 to 5. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 783f141967..c10ed74426 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v4 + - uses: actions/stale@v5 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 From edec1220fc0802a68bac18314a1123c7f7dcaf29 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 May 2022 07:24:06 +0000 Subject: [PATCH 010/638] Bump github/codeql-action from 1 to 2 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1 to 2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v1...v2) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index a4f67b81f4..d6ffdaa11d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -29,12 +29,12 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: 'python' - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 From 2735481da8fac3cb521338b7af2259da7b621e88 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 14 May 2022 14:25:57 -0700 Subject: [PATCH 011/638] Logo for light and dark modes. (#4735) * Logo for light and dark modes. --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 20c707b141..dbe9197204 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,11 @@ #

- - Pi-hole + + Pi-hole + + + Pi-hole
Network-wide ad blocking via your own Linux hardware From 36dd533ef3716730378eb386acbd30a1300ff0c9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 5 Sep 2020 14:15:03 +0100 Subject: [PATCH 012/638] use directory /var/log/pihole/ for log storage Signed-off-by: Adam Warner --- advanced/01-pihole.conf | 2 +- advanced/Scripts/piholeLogFlush.sh | 18 +++++++++--------- advanced/Templates/logrotate | 4 ++-- advanced/Templates/pihole-FTL.service | 8 ++++---- advanced/Templates/pihole.cron | 2 +- manpages/pihole.8 | 6 +++--- pihole | 8 ++++---- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 02bc93bf35..1fb34905cd 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -37,6 +37,6 @@ interface=@INT@ cache-size=@CACHE_SIZE@ log-queries -log-facility=/var/log/pihole.log +log-facility=/var/log/pihole/pihole.log log-async diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 57f901f52d..60d5856b80 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -31,7 +31,7 @@ if [ -z "$DBFILE" ]; then fi if [[ "$@" != *"quiet"* ]]; then - echo -ne " ${INFO} Flushing /var/log/pihole.log ..." + echo -ne " ${INFO} Flushing /var/log/pihole/pihole.log ..." fi if [[ "$@" == *"once"* ]]; then # Nightly logrotation @@ -44,9 +44,9 @@ if [[ "$@" == *"once"* ]]; then # Note that moving the file is not an option, as # dnsmasq would happily continue writing into the # moved file (it will have the same file handler) - cp -p /var/log/pihole.log /var/log/pihole.log.1 - echo " " > /var/log/pihole.log - chmod 644 /var/log/pihole.log + cp -p /var/log/pihole/pihole.log /var/log/pihole/pihole.log.1 + echo " " > /var/log/pihole/pihole.log + chmod 644 /var/log/pihole/pihole.log fi else # Manual flushing @@ -56,10 +56,10 @@ else /usr/sbin/logrotate --force --state "${STATEFILE}" /etc/pihole/logrotate else # Flush both pihole.log and pihole.log.1 (if existing) - echo " " > /var/log/pihole.log - if [ -f /var/log/pihole.log.1 ]; then - echo " " > /var/log/pihole.log.1 - chmod 644 /var/log/pihole.log.1 + echo " " > /var/log/pihole/pihole.log + if [ -f /var/log/pihole/pihole.log.1 ]; then + echo " " > /var/log/pihole/pihole.log.1 + chmod 644 /var/log/pihole/pihole.log.1 fi fi # Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history) @@ -70,6 +70,6 @@ else fi if [[ "$@" != *"quiet"* ]]; then - echo -e "${OVER} ${TICK} Flushed /var/log/pihole.log" + echo -e "${OVER} ${TICK} Flushed /var/log/pihole/pihole.log" echo -e " ${TICK} Deleted ${deleted} queries from database" fi diff --git a/advanced/Templates/logrotate b/advanced/Templates/logrotate index ffed910b9d..eeeeeadd0d 100644 --- a/advanced/Templates/logrotate +++ b/advanced/Templates/logrotate @@ -1,4 +1,4 @@ -/var/log/pihole.log { +/var/log/pihole/pihole.log { # su # daily copytruncate @@ -9,7 +9,7 @@ nomail } -/var/log/pihole-FTL.log { +/var/log/pihole/pihole-FTL.log { # su # weekly copytruncate diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index c45d0dc1c3..448454e16b 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -70,13 +70,13 @@ start() { mkdir -pm 0755 /run/pihole [ ! -f "${FTL_PID_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" [ ! -f "${FTL_PORT_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" - [ ! -f /var/log/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole-FTL.log - [ ! -f /var/log/pihole.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole.log + [ ! -f /var/log/pihole/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole-FTL.log + [ ! -f /var/log/pihole/pihole.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit all necessary files - chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole.log /var/log/pihole.log /etc/pihole/dhcp.leases + chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit the files. We ignore errors as the file may not (yet) exist - chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole-FTL.log /var/log/pihole.log + chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log # Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist chown -f pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db /etc/pihole/macvendor.db # Chown database file permissions so that the pihole group (web interface) can edit the file. We ignore errors as the files may not (yet) exist diff --git a/advanced/Templates/pihole.cron b/advanced/Templates/pihole.cron index 37724d2e81..46640fbb32 100644 --- a/advanced/Templates/pihole.cron +++ b/advanced/Templates/pihole.cron @@ -18,7 +18,7 @@ # early morning. Download any updates from the adlists # Squash output to log, then splat the log to stdout on error to allow for # standard crontab job error handling. -59 1 * * 7 root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updateGravity >/var/log/pihole_updateGravity.log || cat /var/log/pihole_updateGravity.log +59 1 * * 7 root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updateGravity >/var/log/pihole/pihole_updateGravity.log || cat /var/log/pihole/pihole_updateGravity.log # Pi-hole: Flush the log daily at 00:00 # The flush script will use logrotate if available diff --git a/manpages/pihole.8 b/manpages/pihole.8 index aaaa8d7eb3..4b1e5154fe 100644 --- a/manpages/pihole.8 +++ b/manpages/pihole.8 @@ -187,12 +187,12 @@ Available commands and options: (Logging options): .br - on Enable the Pi-hole log at /var/log/pihole.log + on Enable the Pi-hole log at /var/log/pihole/pihole.log .br off Disable and flush the Pi-hole log at - /var/log/pihole.log + /var/log/pihole/pihole.log .br - off noflush Disable the Pi-hole log at /var/log/pihole.log + off noflush Disable the Pi-hole log at /var/log/pihole/pihole.log .br \fB-up, updatePihole\fR [--check-only] diff --git a/pihole b/pihole index f51fd9561b..965f628856 100755 --- a/pihole +++ b/pihole @@ -254,9 +254,9 @@ Example: 'pihole logging on' Specify whether the Pi-hole log should be used Options: - on Enable the Pi-hole log at /var/log/pihole.log - off Disable and flush the Pi-hole log at /var/log/pihole.log - off noflush Disable the Pi-hole log at /var/log/pihole.log" + on Enable the Pi-hole log at /var/log/pihole/pihole.log + off Disable and flush the Pi-hole log at /var/log/pihole/pihole.log + off noflush Disable the Pi-hole log at /var/log/pihole/pihole.log" exit 0 elif [[ "${1}" == "off" ]]; then # Disable logging @@ -382,7 +382,7 @@ tailFunc() { # Color blocklist/blacklist/wildcard entries as red # Color A/AAAA/DHCP strings as white # Color everything else as gray - tail -f /var/log/pihole.log | grep --line-buffered "${1}" | sed -E \ + tail -f /var/log/pihole/pihole.log | grep --line-buffered "${1}" | sed -E \ -e "s,($(date +'%b %d ')| dnsmasq\[[0-9]*\]),,g" \ -e "s,(.*(blacklisted |gravity blocked ).*),${COL_RED}&${COL_NC}," \ -e "s,.*(query\\[A|DHCP).*,${COL_NC}&${COL_NC}," \ From 82695aba7d2174a5bad4055bb46310e89ea5a687 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 5 Sep 2020 15:00:37 +0100 Subject: [PATCH 013/638] update LOG_DIRECTORY variable in debug script Signed-off-by: Adam Warner --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 844cbd237c..f9417d5e54 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -66,7 +66,7 @@ PIHOLE_DIRECTORY="/etc/pihole" PIHOLE_SCRIPTS_DIRECTORY="/opt/pihole" BIN_DIRECTORY="/usr/local/bin" RUN_DIRECTORY="/run" -LOG_DIRECTORY="/var/log" +LOG_DIRECTORY="/var/log/pihole" WEB_SERVER_LOG_DIRECTORY="${LOG_DIRECTORY}/lighttpd" WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd" HTML_DIRECTORY="/var/www/html" From 9b9acfd4a71fd98b9c31ab63f36e7f4a3292917e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 15 May 2022 20:22:06 +0200 Subject: [PATCH 014/638] Remove log files from new location during uninstalling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/uninstall.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 9d3fca31f5..a0bb2e5b00 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -146,6 +146,7 @@ removeNoPurge() { ${SUDO} rm -f /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm -f /etc/dnsmasq.d/06-rfc6761.conf &> /dev/null ${SUDO} rm -rf /var/log/*pihole* &> /dev/null + ${SUDO} rm -rf /var/log/pihole/*pihole* &> /dev/null ${SUDO} rm -rf /etc/pihole/ &> /dev/null ${SUDO} rm -rf /etc/.pihole/ &> /dev/null ${SUDO} rm -rf /opt/pihole/ &> /dev/null From 0fa94e0946be0347ac9287cbbae219736144bc5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 15 May 2022 20:26:25 +0200 Subject: [PATCH 015/638] Remove unused test which was commented since 5 years by PR 1244 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_automated_install.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 41a939e016..b31897a478 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -905,23 +905,6 @@ def test_FTL_binary_installed_and_responsive_no_errors(host): assert expected_stdout in installed_binary.stdout -# def test_FTL_support_files_installed(host): -# ''' -# confirms FTL support files are installed -# ''' -# support_files = host.run(''' -# source /opt/pihole/basic-install.sh -# FTLdetect -# stat -c '%a %n' /var/log/pihole-FTL.log -# stat -c '%a %n' /run/pihole-FTL.port -# stat -c '%a %n' /run/pihole-FTL.pid -# ls -lac /run -# ''') -# assert '644 /run/pihole-FTL.port' in support_files.stdout -# assert '644 /run/pihole-FTL.pid' in support_files.stdout -# assert '644 /var/log/pihole-FTL.log' in support_files.stdout - - def test_IPv6_only_link_local(host): ''' confirms IPv6 blocking is disabled for Link-local address From 09611039339f3534a0be4ece0ef666167f0f3294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 15 May 2022 22:10:40 +0200 Subject: [PATCH 016/638] Add backward compatibility to FTL service by creating symlinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Templates/pihole-FTL.service | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 448454e16b..f03047efbe 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -68,19 +68,26 @@ start() { else # Touch files to ensure they exist (create if non-existing, preserve if existing) mkdir -pm 0755 /run/pihole + mkdir -pm 0755 /var/log/pihole [ ! -f "${FTL_PID_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" [ ! -f "${FTL_PORT_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" [ ! -f /var/log/pihole/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole-FTL.log [ ! -f /var/log/pihole/pihole.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit all necessary files - chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases + chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit the files. We ignore errors as the file may not (yet) exist chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log # Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist chown -f pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db /etc/pihole/macvendor.db # Chown database file permissions so that the pihole group (web interface) can edit the file. We ignore errors as the files may not (yet) exist chmod -f 0664 /etc/pihole/pihole-FTL.db + + # Backward compatibility for user-scripts that still expect log files in /var/log instead of /var/log/pihole/ + # Should be removed with Pi-hole v6.0 + [ ! -f /var/log/pihole.log ] && ln -s /var/log/pihole/pihole.log /var/log/pihole.log + [ ! -f /var/log/pihole/pihole-FTL.log ] && ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log + if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole else From 110e7525523710f7dc29498b744828418a03b7c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 15 May 2022 22:30:17 +0200 Subject: [PATCH 017/638] Move existing log files 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2ac713e854..ace56789fd 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2528,6 +2528,14 @@ main() { # If no setting was found, default to 0 PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" fi + + # If this is an update from a previous Pi-hole installation + # we need to move any existing `pihole*` logs from `/var/log` to `/var/log/pihole` + # if /var/log/pihole.log is not a symlink (set durign FTL startup) move the files + # can be removed with Pi-hole v6.0 + if [ -f /var/log/pihole.log ] && [ ! -L /var/log/pihole.log ]; then + mv /var/log/pihole*.* /var/log/pihole/ 2>/dev/null + fi fi # Download or update the scripts by updating the appropriate git repos clone_or_update_repos From 2dd08f070e5c10fac9da9a780019eca7d7aa84ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 15 May 2022 23:30:02 +0200 Subject: [PATCH 018/638] Fix copy&paste error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Templates/pihole-FTL.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index f03047efbe..a70f37b53b 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -86,7 +86,7 @@ start() { # Backward compatibility for user-scripts that still expect log files in /var/log instead of /var/log/pihole/ # Should be removed with Pi-hole v6.0 [ ! -f /var/log/pihole.log ] && ln -s /var/log/pihole/pihole.log /var/log/pihole.log - [ ! -f /var/log/pihole/pihole-FTL.log ] && ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log + [ ! -f /var/log/pihole-FTL.log ] && ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole From 60615e60aa96797ee64a1bea0c8ddcbef0a1192d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 18 May 2022 21:11:38 +0200 Subject: [PATCH 019/638] Make sure FTL is stopped before old logfiles are moved 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 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ace56789fd..22abf60c95 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2528,14 +2528,6 @@ main() { # If no setting was found, default to 0 PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" fi - - # If this is an update from a previous Pi-hole installation - # we need to move any existing `pihole*` logs from `/var/log` to `/var/log/pihole` - # if /var/log/pihole.log is not a symlink (set durign FTL startup) move the files - # can be removed with Pi-hole v6.0 - if [ -f /var/log/pihole.log ] && [ ! -L /var/log/pihole.log ]; then - mv /var/log/pihole*.* /var/log/pihole/ 2>/dev/null - fi fi # Download or update the scripts by updating the appropriate git repos clone_or_update_repos @@ -2621,6 +2613,19 @@ main() { # Fixes a problem reported on Ubuntu 18.04 where trying to start # the service before enabling causes installer to exit enable_service pihole-FTL + + # If this is an update from a previous Pi-hole installation + # we need to move any existing `pihole*` logs from `/var/log` to `/var/log/pihole` + # if /var/log/pihole.log is not a symlink (set durign FTL startup) move the files + # can be removed with Pi-hole v6.0 + # To be sure FTL is not running when we move the files we explicitly stop it here + + stop_service pihole-FTL &> /dev/null + + if [ -f /var/log/pihole.log ] && [ ! -L /var/log/pihole.log ]; then + mv /var/log/pihole*.* /var/log/pihole/ 2>/dev/null + fi + restart_service pihole-FTL # Download and compile the aggregated block list From 08faf21b2e173094da6072b9276a63f0bf3ca6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 18 May 2022 22:06:36 +0200 Subject: [PATCH 020/638] Set file owner and permission to symlinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Templates/pihole-FTL.service | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index a70f37b53b..6ef57380f5 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -85,8 +85,17 @@ start() { # Backward compatibility for user-scripts that still expect log files in /var/log instead of /var/log/pihole/ # Should be removed with Pi-hole v6.0 - [ ! -f /var/log/pihole.log ] && ln -s /var/log/pihole/pihole.log /var/log/pihole.log - [ ! -f /var/log/pihole-FTL.log ] && ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log + if [ ! -f /var/log/pihole.log ]; then + ln -s /var/log/pihole/pihole.log /var/log/pihole.log + chown pihole:pihole /var/log/pihole.log + chmod -f 0644 /var/log/pihole.log + + fi + if [ ! -f /var/log/pihole-FTL.log ]; then + ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log + chown pihole:pihole /var/log/pihole-FTL.log + chmod -f 0644 /var/log/pihole-FTL.log + fi if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole From ce8731b74683ab1606c788e071154e1350774cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 18 May 2022 22:19:19 +0200 Subject: [PATCH 021/638] no-dereference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Templates/pihole-FTL.service | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 6ef57380f5..9b9b3a0a32 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -87,14 +87,12 @@ start() { # Should be removed with Pi-hole v6.0 if [ ! -f /var/log/pihole.log ]; then ln -s /var/log/pihole/pihole.log /var/log/pihole.log - chown pihole:pihole /var/log/pihole.log - chmod -f 0644 /var/log/pihole.log + chown -h pihole:pihole /var/log/pihole.log fi if [ ! -f /var/log/pihole-FTL.log ]; then ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log - chown pihole:pihole /var/log/pihole-FTL.log - chmod -f 0644 /var/log/pihole-FTL.log + chown -h pihole:pihole /var/log/pihole-FTL.log fi if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then From b7742ddb9bc2a166878fd7125eebfc75e09c3aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 19 May 2022 06:17:46 +0200 Subject: [PATCH 022/638] Always install pihole-FTL.service file 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2ac713e854..faa1fd61a9 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1326,6 +1326,9 @@ installConfigs() { fi fi + # Install pihole-FTL.service + install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL" + # If the user chose to install the dashboard, if [[ "${INSTALL_WEB_SERVER}" == true ]]; then # and if the Web server conf directory does not exist, @@ -2117,9 +2120,6 @@ FTLinstall() { # Move into the temp ftl directory pushd "$(mktemp -d)" > /dev/null || { printf "Unable to make temporary directory for FTL binary download\\n"; return 1; } - # Always replace pihole-FTL.service - install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL" - local ftlBranch local url From 52c3df1a8ec6fb606034cc5a7202c4d6188e1748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 28 May 2022 21:21:48 +0200 Subject: [PATCH 023/638] lighttpd log dir is now different than Pi-hole log dir MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index f9417d5e54..78b5379aff 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -67,7 +67,7 @@ PIHOLE_SCRIPTS_DIRECTORY="/opt/pihole" BIN_DIRECTORY="/usr/local/bin" RUN_DIRECTORY="/run" LOG_DIRECTORY="/var/log/pihole" -WEB_SERVER_LOG_DIRECTORY="${LOG_DIRECTORY}/lighttpd" +WEB_SERVER_LOG_DIRECTORY="/var/log/lighttpd" WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd" HTML_DIRECTORY="/var/www/html" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" From 3fa8f76d997cb6bb8caccbddff5fd9ac4b293783 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Sun, 29 May 2022 16:15:18 +0200 Subject: [PATCH 024/638] Combine mkdir in service file Co-authored-by: MichaIng --- advanced/Templates/pihole-FTL.service | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 9b9b3a0a32..11bbe1c923 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -67,8 +67,7 @@ start() { echo "pihole-FTL is already running" else # Touch files to ensure they exist (create if non-existing, preserve if existing) - mkdir -pm 0755 /run/pihole - mkdir -pm 0755 /var/log/pihole + mkdir -pm 0755 /run/pihole /var/log/pihole [ ! -f "${FTL_PID_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" [ ! -f "${FTL_PORT_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" [ ! -f /var/log/pihole/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole-FTL.log From dae96e738492cdb64380194405a52cfe0a50630c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 29 May 2022 21:04:18 +0200 Subject: [PATCH 025/638] Change lighttpd log file names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 4 ++-- advanced/lighttpd.conf.debian | 4 ++-- advanced/lighttpd.conf.fedora | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 844cbd237c..41da4215c5 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -131,8 +131,8 @@ 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_WEB_SERVER_ACCESS_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/access.log" -PIHOLE_WEB_SERVER_ERROR_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/error.log" +PIHOLE_WEB_SERVER_ACCESS_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/access-pihole.log" +PIHOLE_WEB_SERVER_ERROR_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/error-pihole.log" RESOLVCONF="${ETC}/resolv.conf" DNSMASQ_CONF="${ETC}/dnsmasq.conf" diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index b8656a2460..4231a0c993 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -28,12 +28,12 @@ server.modules = ( server.document-root = "/var/www/html" server.error-handler-404 = "/pihole/index.php" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) -server.errorlog = "/var/log/lighttpd/error.log" +server.errorlog = "/var/log/lighttpd/error-pihole.log" server.pid-file = "/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" server.port = 80 -accesslog.filename = "/var/log/lighttpd/access.log" +accesslog.filename = "/var/log/lighttpd/access-pihole.log" accesslog.format = "%{%s}t|%V|%r|%s|%b" # Allow streaming response diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 79d5f3b275..c3c949863a 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -29,12 +29,12 @@ server.modules = ( server.document-root = "/var/www/html" server.error-handler-404 = "/pihole/index.php" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) -server.errorlog = "/var/log/lighttpd/error.log" +server.errorlog = "/var/log/lighttpd/error-pihole.log" server.pid-file = "/run/lighttpd.pid" server.username = "lighttpd" server.groupname = "lighttpd" server.port = 80 -accesslog.filename = "/var/log/lighttpd/access.log" +accesslog.filename = "/var/log/lighttpd/access-pihole.log" accesslog.format = "%{%s}t|%V|%r|%s|%b" # Allow streaming response From 300c7b151815b97c5e9843bbef9c1295df1c7c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 31 May 2022 14:11:39 +0200 Subject: [PATCH 026/638] Do not hardcode webroot dir for teleporter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index aa5a28b1fd..da7b5a10de 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -650,7 +650,8 @@ Teleporter() { host="${host//./_}" filename="pi-hole-${host:-noname}-teleporter_${datetimestamp}.tar.gz" fi - php /var/www/html/admin/scripts/pi-hole/php/teleporter.php > "${filename}" + # webroot is sourced from basic-install above + php "${webroot}/admin/scripts/pi-hole/php/teleporter.php" > "${filename}" } checkDomain() From 0b9d4a47ad31d63e11823cd8823a3554cb762dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 2 Oct 2021 23:06:05 +0200 Subject: [PATCH 027/638] Remove IPv4 and IPv6 adresses from setupVars.conf 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 | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8a0cfd0aa8..1c88681e83 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1734,19 +1734,6 @@ create_pihole_user() { # This function saves any changes to the setup variables into the setupvars.conf file for future runs finalExports() { - # If the Web interface is not set to be installed, - if [[ "${INSTALL_WEB_INTERFACE}" == false ]]; then - # and if there is not an IPv4 address, - if [[ "${IPV4_ADDRESS}" ]]; then - # there is no block page, so set IPv4 to 0.0.0.0 (all IP addresses) - IPV4_ADDRESS="0.0.0.0" - fi - if [[ "${IPV6_ADDRESS}" ]]; then - # and IPv6 to ::/0 - IPV6_ADDRESS="::/0" - fi - fi - # If the setup variable file exists, if [[ -e "${setupVars}" ]]; then # update the variables in the file @@ -1755,8 +1742,6 @@ finalExports() { # echo the information to the user { echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}" - echo "IPV4_ADDRESS=${IPV4_ADDRESS}" - echo "IPV6_ADDRESS=${IPV6_ADDRESS}" echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}" echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}" echo "QUERY_LOGGING=${QUERY_LOGGING}" From 2c07d27ad7133b182d0a7f5c057f277cb9654fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 9 Jan 2022 06:56:24 +0100 Subject: [PATCH 028/638] Forgot two places 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 | 2 +- test/test_any_automated_install.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 1c88681e83..bf0bc9945e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1737,7 +1737,7 @@ finalExports() { # If the setup variable file exists, if [[ -e "${setupVars}" ]]; then # update the variables in the file - sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1\b/d;/PIHOLE_DNS_2\b/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;/CACHE_SIZE/d;/DNS_FQDN_REQUIRED/d;/DNS_BOGUS_PRIV/d;/DNSMASQ_LISTENING/d;' "${setupVars}" + sed -i.update.bak '/PIHOLE_INTERFACE/d;/PIHOLE_DNS_1\b/d;/PIHOLE_DNS_2\b/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;/CACHE_SIZE/d;/DNS_FQDN_REQUIRED/d;/DNS_BOGUS_PRIV/d;/DNSMASQ_LISTENING/d;' "${setupVars}" fi # echo the information to the user { diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index b31897a478..e7389006b2 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -483,7 +483,6 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): setup_var_file += "{}={}\n".format(k, v) setup_var_file += "INSTALL_WEB_SERVER=true\n" setup_var_file += "INSTALL_WEB_INTERFACE=true\n" - setup_var_file += "IPV4_ADDRESS=127.0.0.1\n" setup_var_file += "EOF\n" host.run(setup_var_file) installWeb = host.run(''' From fbc0b57dd112ca905f6ea4b3eb1f6d100da6cfde Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 12 Jun 2022 12:30:29 +0100 Subject: [PATCH 029/638] Update dependabot.yml Signed-off-by: Adam Warner --- .github/dependabot.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index be18a8f3c4..f91a9b82ef 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,3 +8,5 @@ updates: time: "10:00" open-pull-requests-limit: 10 target-branch: development + reviewers: + - "pi-hole/core-maintainers" From 50d14fb6dbbea2430bf9990dbb2b3cb774092534 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 12 Jun 2022 11:35:59 +0000 Subject: [PATCH 030/638] Bump actions/setup-python from 3 to 4 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3 to 4. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 872be3d63b..8eee30088c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: uses: actions/checkout@v3 - name: Set up Python 3.8 - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: 3.8 - From 1f26e853998650d2d56b596b440ab71bd8773dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 13 Jun 2022 15:06:15 +0200 Subject: [PATCH 031/638] Exit installer if no valid PHP version is found 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bf0bc9945e..6956484dd3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -301,8 +301,13 @@ package_manager_detect() { local phpVer="php" if is_command php ; then printf " %b Existing PHP installation detected : PHP version %s\\n" "${INFO}" "$(php <<< "")" - printf -v phpInsMajor "%d" "$(php <<< "")" - printf -v phpInsMinor "%d" "$(php <<< "")" + printf -v phpInsMajor "$(php <<< "")" + printf -v phpInsMinor "$(php <<< "")" + if [[ "$phpInsMajor" =~ [^[:digit:]] || "$phpInsMinor" =~ [^[:digit:]] ]]; then + printf " %b No valid PHP version detected\\n" "${CROSS}" + # so exit the installer + exit + fi phpVer="php$phpInsMajor.$phpInsMinor" fi # Packages required to perfom the os_check (stored as an array) From 7d731870e541897e20077a10b10b197627aaf847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 13 Jun 2022 16:06:59 +0200 Subject: [PATCH 032/638] Fix stickler 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 6956484dd3..a5c2d2f664 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -301,8 +301,8 @@ package_manager_detect() { local phpVer="php" if is_command php ; then printf " %b Existing PHP installation detected : PHP version %s\\n" "${INFO}" "$(php <<< "")" - printf -v phpInsMajor "$(php <<< "")" - printf -v phpInsMinor "$(php <<< "")" + printf -v phpInsMajor "%s" "$(php <<< "")" + printf -v phpInsMinor "%s" "$(php <<< "")" if [[ "$phpInsMajor" =~ [^[:digit:]] || "$phpInsMinor" =~ [^[:digit:]] ]]; then printf " %b No valid PHP version detected\\n" "${CROSS}" # so exit the installer From 5818f3f997207f73eeeefa8ceda6f92b170ae612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Jun 2022 00:05:27 +0200 Subject: [PATCH 033/638] Check for validity first 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 | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a5c2d2f664..9186eee262 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -298,17 +298,21 @@ package_manager_detect() { # Update package cache update_package_cache || exit 1 # Check for and determine version number (major and minor) of current php install - local phpVer="php" + local phpVer if is_command php ; then - printf " %b Existing PHP installation detected : PHP version %s\\n" "${INFO}" "$(php <<< "")" - printf -v phpInsMajor "%s" "$(php <<< "")" - printf -v phpInsMinor "%s" "$(php <<< "")" - if [[ "$phpInsMajor" =~ [^[:digit:]] || "$phpInsMinor" =~ [^[:digit:]] ]]; then - printf " %b No valid PHP version detected\\n" "${CROSS}" - # so exit the installer - exit + phpVer="$(php -v 2> /dev/null | head -n1 | cut -d '-' -f1 | cut -d ' ' -f2)" + # Check if the first character of the string is numeric + if [[ ${phpVer:0:1} =~ [1-9] ]]; then + printf " %b Existing PHP installation detected : PHP version %s\\n" "${INFO}" "${phpVer}" + printf -v phpInsMajor "%d" "$(php <<< "")" + printf -v phpInsMinor "%d" "$(php <<< "")" + phpVer="php$phpInsMajor.$phpInsMinor" + else + printf " %b No valid PHP installation detected!\\n" "${CROSS}" + printf " %b PHP version : %s\\n" "${INFO}" "${phpVer}" + printf " %b Aborting installation.\\n" "${CROSS}" + exit 1 fi - phpVer="php$phpInsMajor.$phpInsMinor" fi # Packages required to perfom the os_check (stored as an array) OS_CHECK_DEPS=(grep dnsutils) From 4b674ecfe3c6c2ab0c44a69285b17e709ee9c7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Jun 2022 00:58:10 +0200 Subject: [PATCH 034/638] Fix first install 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9186eee262..0c5c21ce9e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -298,7 +298,7 @@ package_manager_detect() { # Update package cache update_package_cache || exit 1 # Check for and determine version number (major and minor) of current php install - local phpVer + local phpVer="php" if is_command php ; then phpVer="$(php -v 2> /dev/null | head -n1 | cut -d '-' -f1 | cut -d ' ' -f2)" # Check if the first character of the string is numeric From ed8c6c04d4e9ae70364d4ff1447cf185bf5fea7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Jun 2022 23:04:31 +0200 Subject: [PATCH 035/638] Use PHP_VERSION 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0c5c21ce9e..f9ec95054d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -300,7 +300,7 @@ package_manager_detect() { # Check for and determine version number (major and minor) of current php install local phpVer="php" if is_command php ; then - phpVer="$(php -v 2> /dev/null | head -n1 | cut -d '-' -f1 | cut -d ' ' -f2)" + phpVer="$(php <<< "")" # Check if the first character of the string is numeric if [[ ${phpVer:0:1} =~ [1-9] ]]; then printf " %b Existing PHP installation detected : PHP version %s\\n" "${INFO}" "${phpVer}" From 954a0c2a14fd4b1a80f41bfcc333f7b6c39fe078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 19 Jun 2022 23:09:05 +0200 Subject: [PATCH 036/638] Remove read permission for others on senible log files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 2 +- advanced/Scripts/piholeLogFlush.sh | 4 ++-- advanced/Templates/pihole-FTL.service | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1f12e86875..ebab375ae3 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1394,7 +1394,7 @@ curl_to_tricorder() { upload_to_tricorder() { local username="pihole" # Set the permissions and owner - chmod 644 ${PIHOLE_DEBUG_LOG} + chmod 640 ${PIHOLE_DEBUG_LOG} chown "$USER":"${username}" ${PIHOLE_DEBUG_LOG} # Let the user know debugging is complete with something strikingly visual diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 60d5856b80..3473fad591 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -46,7 +46,7 @@ if [[ "$@" == *"once"* ]]; then # moved file (it will have the same file handler) cp -p /var/log/pihole/pihole.log /var/log/pihole/pihole.log.1 echo " " > /var/log/pihole/pihole.log - chmod 644 /var/log/pihole/pihole.log + chmod 640 /var/log/pihole/pihole.log fi else # Manual flushing @@ -59,7 +59,7 @@ else echo " " > /var/log/pihole/pihole.log if [ -f /var/log/pihole/pihole.log.1 ]; then echo " " > /var/log/pihole/pihole.log.1 - chmod 644 /var/log/pihole/pihole.log.1 + chmod 640 /var/log/pihole/pihole.log.1 fi fi # Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 11bbe1c923..941f1ee054 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -71,12 +71,13 @@ start() { [ ! -f "${FTL_PID_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" [ ! -f "${FTL_PORT_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" [ ! -f /var/log/pihole/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole-FTL.log - [ ! -f /var/log/pihole/pihole.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log + [ ! -f /var/log/pihole/pihole.log ] && install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit all necessary files chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit the files. We ignore errors as the file may not (yet) exist - chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log + chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/pihole-FTL.log + chmod -f 0640 /var/log/pihole/pihole.log # Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist chown -f pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db /etc/pihole/macvendor.db # Chown database file permissions so that the pihole group (web interface) can edit the file. We ignore errors as the files may not (yet) exist From 2c5907a8b1f58d091d16ab935cd91d5316f36deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 19 Jun 2022 23:25:53 +0200 Subject: [PATCH 037/638] Requiere sudo for pihole -t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pihole b/pihole index 965f628856..c54a319204 100755 --- a/pihole +++ b/pihole @@ -503,7 +503,7 @@ case "${1}" in "-c" | "chronometer" ) chronometerFunc "$@";; "-q" | "query" ) queryFunc "$@";; "status" ) statusFunc "$2";; - "-t" | "tail" ) tailFunc "$2";; + "tricorder" ) tricorderFunc;; # we need to add all arguments that require sudo power to not trigger the * argument @@ -527,6 +527,7 @@ case "${1}" in "checkout" ) ;; "updatechecker" ) ;; "arpflush" ) ;; + "-t" | "tail" ) ;; * ) helpFunc;; esac @@ -563,4 +564,5 @@ case "${1}" in "checkout" ) piholeCheckoutFunc "$@";; "updatechecker" ) updateCheckFunc "$@";; "arpflush" ) arpFunc "$@";; + "-t" | "tail" ) tailFunc "$2";; esac From f9d1893f9677a7797fde5f139c67aae1c6e4c46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 20 Jun 2022 10:33:32 +0200 Subject: [PATCH 038/638] Update test to reflect currently supported OS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 2 +- advanced/Scripts/piholeDebug.sh | 19 ------------------- test/_debian_9.Dockerfile | 17 ----------------- test/_fedora_33.Dockerfile | 18 ------------------ test/_ubuntu_16.Dockerfile | 17 ----------------- ...tu_21.Dockerfile => _ubuntu_22.Dockerfile} | 0 test/tox.debian_9.ini | 8 -------- test/tox.fedora_33.ini | 8 -------- test/tox.ubuntu_21.ini | 8 -------- test/{tox.ubuntu_16.ini => tox.ubuntu_22.ini} | 2 +- 10 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 test/_debian_9.Dockerfile delete mode 100644 test/_fedora_33.Dockerfile delete mode 100644 test/_ubuntu_16.Dockerfile rename test/{_ubuntu_21.Dockerfile => _ubuntu_22.Dockerfile} (100%) delete mode 100644 test/tox.debian_9.ini delete mode 100644 test/tox.fedora_33.ini delete mode 100644 test/tox.ubuntu_21.ini rename test/{tox.ubuntu_16.ini => tox.ubuntu_22.ini} (75%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8eee30088c..ed2821542f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: needs: smoke-test strategy: matrix: - distro: [debian_9, debian_10, debian_11, ubuntu_16, ubuntu_18, ubuntu_20, ubuntu_21, centos_7, centos_8, fedora_33, fedora_34] + distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_22, centos_8, fedora_34] env: DISTRO: ${{matrix.distro}} steps: diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1f12e86875..316ec399e5 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -137,28 +137,9 @@ PIHOLE_WEB_SERVER_ERROR_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/error-pihole.log" RESOLVCONF="${ETC}/resolv.conf" DNSMASQ_CONF="${ETC}/dnsmasq.conf" -# An array of operating system "pretty names" that we officially support -# We can loop through the array at any time to see if it matches a value -#SUPPORTED_OS=("Raspbian" "Ubuntu" "Fedora" "Debian" "CentOS") - # Store Pi-hole's processes in an array for easy use and parsing PIHOLE_PROCESSES=( "lighttpd" "pihole-FTL" ) -# Store the required directories in an array so it can be parsed through -#REQUIRED_DIRECTORIES=("${CORE_GIT_DIRECTORY}" -#"${CRON_D_DIRECTORY}" -#"${DNSMASQ_D_DIRECTORY}" -#"${PIHOLE_DIRECTORY}" -#"${PIHOLE_SCRIPTS_DIRECTORY}" -#"${BIN_DIRECTORY}" -#"${RUN_DIRECTORY}" -#"${LOG_DIRECTORY}" -#"${WEB_SERVER_LOG_DIRECTORY}" -#"${WEB_SERVER_CONFIG_DIRECTORY}" -#"${HTML_DIRECTORY}" -#"${WEB_GIT_DIRECTORY}" -#"${BLOCK_PAGE_DIRECTORY}") - # Store the required directories in an array so it can be parsed through REQUIRED_FILES=("${PIHOLE_CRON_FILE}" "${WEB_SERVER_CONFIG_FILE}" diff --git a/test/_debian_9.Dockerfile b/test/_debian_9.Dockerfile deleted file mode 100644 index c590a6576c..0000000000 --- a/test/_debian_9.Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM buildpack-deps:stretch-scm - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV PH_TEST true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_fedora_33.Dockerfile b/test/_fedora_33.Dockerfile deleted file mode 100644 index 5cdd66eeca..0000000000 --- a/test/_fedora_33.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM fedora:33 -RUN dnf install -y git - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV PH_TEST true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_ubuntu_16.Dockerfile b/test/_ubuntu_16.Dockerfile deleted file mode 100644 index e572efd149..0000000000 --- a/test/_ubuntu_16.Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM buildpack-deps:xenial-scm - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV PH_TEST true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ \ No newline at end of file diff --git a/test/_ubuntu_21.Dockerfile b/test/_ubuntu_22.Dockerfile similarity index 100% rename from test/_ubuntu_21.Dockerfile rename to test/_ubuntu_22.Dockerfile diff --git a/test/tox.debian_9.ini b/test/tox.debian_9.ini deleted file mode 100644 index 56b9d37f09..0000000000 --- a/test/tox.debian_9.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py38 - -[testenv] -whitelist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _debian_9.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.fedora_33.ini b/test/tox.fedora_33.ini deleted file mode 100644 index b17bd56323..0000000000 --- a/test/tox.fedora_33.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py38 - -[testenv] -whitelist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _fedora_33.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.ubuntu_21.ini b/test/tox.ubuntu_21.ini deleted file mode 100644 index 070d3a7218..0000000000 --- a/test/tox.ubuntu_21.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py38 - -[testenv] -whitelist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _ubuntu_21.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.ubuntu_16.ini b/test/tox.ubuntu_22.ini similarity index 75% rename from test/tox.ubuntu_16.ini rename to test/tox.ubuntu_22.ini index f8f6e92a73..2a3285aaec 100644 --- a/test/tox.ubuntu_16.ini +++ b/test/tox.ubuntu_22.ini @@ -4,5 +4,5 @@ envlist = py38 [testenv] whitelist_externals = docker deps = -rrequirements.txt -commands = docker build -f _ubuntu_16.Dockerfile -t pytest_pihole:test_container ../ +commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 287d5d37b1a70dd7f737eb929d6f010a38477a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 24 Jun 2022 08:33:21 +0200 Subject: [PATCH 039/638] Add stale-issue-reason: not planned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 783f141967..ccac651123 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -23,3 +23,4 @@ jobs: exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed' exempt-all-issue-assignees: true operations-per-run: 300 + stale-issue-reason: 'not_planned' From d88ab2ca600b9e548ee2eef4a81839c365c547b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 24 Jun 2022 19:57:44 +0200 Subject: [PATCH 040/638] Remove unnecassry file types from editorconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .editorconfig | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/.editorconfig b/.editorconfig index a50f2f70ba..33448755d0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,27 +12,3 @@ indent_size = tab tab_width = 4 charset = utf-8 trim_trailing_whitespace = true - -# Matches multiple files with brace expansion notation -# Set default charset -[*.{js,py}] -charset = utf-8 - -# 4 space indentation -[*.py] -indent_style = space -indent_size = 4 - -# Tab indentation (no size specified) -[Makefile] -indent_style = tab - -# Indentation override for all JS under lib directory -[scripts/**.js] -indent_style = space -indent_size = 2 - -# Matches the exact files either package.json or .travis.yml -[{package.json,.travis.yml}] -indent_style = space -indent_size = 2 From 8c498acd4c4c411920a56b29b1c57008a8d140de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 25 Jun 2022 23:04:16 +0200 Subject: [PATCH 041/638] Re-add Ubuntu21 tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 2 +- test/_ubuntu_21.Dockerfile | 18 ++++++++++++++++++ test/tox.ubuntu_21.ini | 8 ++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/_ubuntu_21.Dockerfile create mode 100644 test/tox.ubuntu_21.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ed2821542f..436976e13d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: needs: smoke-test strategy: matrix: - distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_22, centos_8, fedora_34] + distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_21, ubuntu_22, centos_8, fedora_34] env: DISTRO: ${{matrix.distro}} steps: diff --git a/test/_ubuntu_21.Dockerfile b/test/_ubuntu_21.Dockerfile new file mode 100644 index 0000000000..6d4d7fbc3a --- /dev/null +++ b/test/_ubuntu_21.Dockerfile @@ -0,0 +1,18 @@ +FROM buildpack-deps:impish-scm + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR +ENV DEBIAN_FRONTEND=noninteractive + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV PH_TEST true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.ubuntu_21.ini b/test/tox.ubuntu_21.ini new file mode 100644 index 0000000000..070d3a7218 --- /dev/null +++ b/test/tox.ubuntu_21.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py38 + +[testenv] +whitelist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _ubuntu_21.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From a33f71289d8e56a34f97640a4687597a1ec15655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 25 Jun 2022 23:09:10 +0200 Subject: [PATCH 042/638] Re-add centos_7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 436976e13d..94980562d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,7 +31,7 @@ jobs: needs: smoke-test strategy: matrix: - distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_21, ubuntu_22, centos_8, fedora_34] + distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_21, ubuntu_22, centos_7, centos_8, fedora_34] env: DISTRO: ${{matrix.distro}} steps: From f740e0fefbd4c1d71f3fa111d94c701cb4f3720d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 25 Jun 2022 23:11:16 +0200 Subject: [PATCH 043/638] Ubt22 is jammy not impish MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/_ubuntu_22.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/_ubuntu_22.Dockerfile b/test/_ubuntu_22.Dockerfile index 6d4d7fbc3a..f9876d5037 100644 --- a/test/_ubuntu_22.Dockerfile +++ b/test/_ubuntu_22.Dockerfile @@ -1,4 +1,4 @@ -FROM buildpack-deps:impish-scm +FROM buildpack-deps:jammy-scm ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From b70b895fc567e3131c56d273b338af5ab787f6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 29 Jun 2022 20:07:43 +0200 Subject: [PATCH 044/638] Add mkdown and yaml linters to stickler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .stickler.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.stickler.yml b/.stickler.yml index 8a2a1ce991..f094069689 100644 --- a/.stickler.yml +++ b/.stickler.yml @@ -1,6 +1,9 @@ +--- linters: shellcheck: shell: bash phpcs: flake8: max-line-length: 120 + yamllint: + remarklint: From 73d5902bedecba0e1ac5a5adc36c84d7fc1a233b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 27 Jun 2022 00:06:13 +0200 Subject: [PATCH 045/638] Add editorconfig-checker workflow Add yml style to editorconfig Add markdown styling to editorconfig MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .editorconfig | 6 ++++++ .github/workflows/editorconfig-checker.yml | 14 ++++++++++++++ CONTRIBUTING.md | 2 -- .../database_migration/gravity/11_to_12.sql | 2 +- .../database_migration/gravity/12_to_13.sql | 2 +- .../Scripts/database_migration/gravity/3_to_4.sql | 2 +- .../Scripts/database_migration/gravity/4_to_5.sql | 2 +- advanced/Scripts/utils.sh | 2 +- 8 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/editorconfig-checker.yml diff --git a/.editorconfig b/.editorconfig index 33448755d0..714ed210b9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,9 @@ indent_size = tab tab_width = 4 charset = utf-8 trim_trailing_whitespace = true + +[*.yml] +tab_width = 2 + +[*.md] +tab_width = 2 diff --git a/.github/workflows/editorconfig-checker.yml b/.github/workflows/editorconfig-checker.yml new file mode 100644 index 0000000000..37b20ba3f9 --- /dev/null +++ b/.github/workflows/editorconfig-checker.yml @@ -0,0 +1,14 @@ +name: editorconfig-checker + +on: + pull_request: + push: + +jobs: + build: + name: editorconfig-checker + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: editorconfig-checker/action-editorconfig-checker@main + - run: editorconfig-checker diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 018b8c5f51..1ea98df296 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,5 +3,3 @@ Please read and understand the contribution guide before creating an issue or pull request. The guide can be found here: [https://docs.pi-hole.net/guides/github/contributing/](https://docs.pi-hole.net/guides/github/contributing/) - - diff --git a/advanced/Scripts/database_migration/gravity/11_to_12.sql b/advanced/Scripts/database_migration/gravity/11_to_12.sql index 45fbc8451a..d480d46efc 100644 --- a/advanced/Scripts/database_migration/gravity/11_to_12.sql +++ b/advanced/Scripts/database_migration/gravity/11_to_12.sql @@ -16,4 +16,4 @@ CREATE TRIGGER tr_group_zero AFTER DELETE ON "group" UPDATE info SET value = 12 WHERE property = 'version'; -COMMIT; \ No newline at end of file +COMMIT; diff --git a/advanced/Scripts/database_migration/gravity/12_to_13.sql b/advanced/Scripts/database_migration/gravity/12_to_13.sql index d16791d60a..7d85cb05e2 100644 --- a/advanced/Scripts/database_migration/gravity/12_to_13.sql +++ b/advanced/Scripts/database_migration/gravity/12_to_13.sql @@ -15,4 +15,4 @@ CREATE TRIGGER tr_adlist_update AFTER UPDATE OF address,enabled,comment ON adlis UPDATE info SET value = 13 WHERE property = 'version'; -COMMIT; \ No newline at end of file +COMMIT; diff --git a/advanced/Scripts/database_migration/gravity/3_to_4.sql b/advanced/Scripts/database_migration/gravity/3_to_4.sql index 352b1baae3..05231f7299 100644 --- a/advanced/Scripts/database_migration/gravity/3_to_4.sql +++ b/advanced/Scripts/database_migration/gravity/3_to_4.sql @@ -93,4 +93,4 @@ CREATE VIEW vw_regex_blacklist AS SELECT domain, domainlist.id AS id, domainlist UPDATE info SET value = 4 WHERE property = 'version'; -COMMIT; \ No newline at end of file +COMMIT; diff --git a/advanced/Scripts/database_migration/gravity/4_to_5.sql b/advanced/Scripts/database_migration/gravity/4_to_5.sql index 2ad906fc12..4ae9f980fb 100644 --- a/advanced/Scripts/database_migration/gravity/4_to_5.sql +++ b/advanced/Scripts/database_migration/gravity/4_to_5.sql @@ -35,4 +35,4 @@ CREATE TABLE client_by_group UPDATE info SET value = 5 WHERE property = 'version'; -COMMIT; \ No newline at end of file +COMMIT; diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index bdd238c34a..cf24c09819 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -89,7 +89,7 @@ getFTLAPIPort(){ # -s: FILE exists and has a size greater than zero ftl_api_port=$(cat "${PORTFILE}") # Exploit prevention: unset the variable if there is malicious content - # Verify that the value read from the file is numeric + # Verify that the value read from the file is numeric expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port fi From 0be987239e3c5c6f88033844dc77c285bc73d185 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 2 Jul 2022 14:00:17 +0100 Subject: [PATCH 046/638] Adds spellcheck action to the smoke-tests (also moves editorconfig-checker to smoketests away from it's own action) Signed-off-by: Adam Warner --- .codespellignore | 3 +++ .github/workflows/editorconfig-checker.yml | 14 -------------- .github/workflows/test.yml | 21 ++++++++++++++++----- advanced/Scripts/piholeDebug.sh | 2 +- advanced/Scripts/webpage.sh | 2 +- advanced/dnsmasq.conf.original | 2 +- automated install/basic-install.sh | 6 +++--- gravity.sh | 2 +- test/test_any_automated_install.py | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 .codespellignore delete mode 100644 .github/workflows/editorconfig-checker.yml diff --git a/.codespellignore b/.codespellignore new file mode 100644 index 0000000000..501a3d6732 --- /dev/null +++ b/.codespellignore @@ -0,0 +1,3 @@ +doubleclick +wan +nwe diff --git a/.github/workflows/editorconfig-checker.yml b/.github/workflows/editorconfig-checker.yml deleted file mode 100644 index 37b20ba3f9..0000000000 --- a/.github/workflows/editorconfig-checker.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: editorconfig-checker - -on: - pull_request: - push: - -jobs: - build: - name: editorconfig-checker - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v3 - - uses: editorconfig-checker/action-editorconfig-checker@main - - run: editorconfig-checker diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 94980562d1..308997d746 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ permissions: contents: read jobs: - smoke-test: + smoke-tests: if: github.event.pull_request.draft == false runs-on: ubuntu-latest steps: @@ -16,19 +16,30 @@ jobs: name: Checkout repository uses: actions/checkout@v3 - - name: Run Smoke Tests + name: Check scripts in repository are executable run: | - # Ensure scripts in repository are executable IFS=$'\n'; for f in $(find . -name '*.sh'); do if [[ ! -x $f ]]; then echo "$f is not executable" && FAIL=1; fi ;done unset IFS; # If FAIL is 1 then we fail. - [[ $FAIL == 1 ]] && exit 1 || echo "Smoke Tests Passed" + [[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!" + - + name: Spell-Checking + uses: codespell-project/actions-codespell@master + with: + ignore_words_file: .codespellignore + - + name: Get editorconfig-checker + uses: editorconfig-checker/action-editorconfig-checker@main + - + name: Run editorconfig-checker + run: editorconfig-checker + distro-test: if: github.event.pull_request.draft == false runs-on: ubuntu-latest - needs: smoke-test + needs: smoke-tests strategy: matrix: distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_21, ubuntu_22, centos_7, centos_8, fedora_34] diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 473d6f1169..c00245b489 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -584,7 +584,7 @@ disk_usage() { # Additinal keywords can be added, separated by "|" hide="curlftpfs" - # only show those lines not containg a sensitive phrase + # only show those lines not containing a sensitive phrase for line in "${file_system[@]}"; do if [[ ! $line =~ $hide ]]; then log_write " ${line}" diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index b429e89802..279de9e939 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -296,7 +296,7 @@ trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC68345710423 # changes in the non-FQDN forwarding. This cannot be done in 01-pihole.conf # as we don't want to delete all local=/.../ lines so it's much safer to # simply rewrite the entire corresponding config file (which is what the - # DHCP settings subroutie is doing) + # DHCP settings subroutine is doing) ProcessDHCPSettings } diff --git a/advanced/dnsmasq.conf.original b/advanced/dnsmasq.conf.original index 6758f0b8e8..4aa5a8bfc8 100644 --- a/advanced/dnsmasq.conf.original +++ b/advanced/dnsmasq.conf.original @@ -507,7 +507,7 @@ # (using /etc/hosts) then that name can be specified as the # tftp_servername (the third option to dhcp-boot) and in that # case dnsmasq resolves this name and returns the resultant IP -# addresses in round robin fasion. This facility can be used to +# addresses in round robin fashion. This facility can be used to # load balance the tftp load among a set of servers. #dhcp-boot=/var/ftpd/pxelinux.0,boothost,tftp_server_name diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f9ec95054d..953e620321 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -195,7 +195,7 @@ os_check() { distro_part="${distro_and_versions%%=*}" versions_part="${distro_and_versions##*=}" - # If the distro part is a (case-insensistive) substring of the computer OS + # If the distro part is a (case-insensitive) substring of the computer OS if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then valid_os=true IFS="," read -r -a supportedVer <<<"${versions_part}" @@ -234,7 +234,7 @@ os_check() { printf " If you are seeing this message and you do have a supported OS, please contact support.\\n" fi printf "\\n" - printf " %bhttps://docs.pi-hole.net/main/prerequesites/#supported-operating-systems%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}" + printf " %bhttps://docs.pi-hole.net/main/prerequisites/#supported-operating-systems%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}" printf "\\n" printf " If you wish to attempt to continue anyway, you can try one of the following commands to skip this check:\\n" printf "\\n" @@ -314,7 +314,7 @@ package_manager_detect() { exit 1 fi fi - # Packages required to perfom the os_check (stored as an array) + # Packages required to perform the os_check (stored as an array) OS_CHECK_DEPS=(grep dnsutils) # Packages required to run this install script (stored as an array) INSTALLER_DEPS=(git iproute2 whiptail ca-certificates) diff --git a/gravity.sh b/gravity.sh index c5e9e41440..779746940d 100755 --- a/gravity.sh +++ b/gravity.sh @@ -540,7 +540,7 @@ parseList() { num_target_lines_new="$(grep -c "^" "${target}")" # Number of new correctly added lines num_correct_lines="$(( num_target_lines_new-num_target_lines ))" - # Upate number of lines in target file + # Update number of lines in target file num_target_lines="$num_target_lines_new" num_invalid="$(( num_source_lines-num_correct_lines ))" if [[ "${num_invalid}" -eq 0 ]]; then diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index e7389006b2..f42feef03b 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -150,7 +150,7 @@ def get_directories_recursive(host, directory): def test_installPihole_fresh_install_readableFiles(host): ''' - confirms all neccessary files are readable by pihole user + confirms all necessary files are readable by pihole user ''' # Whiptail dialog returns Cancel for user prompt mock_command('whiptail', {'*': ('', '0')}, host) From a783da823e6cb3140cd507934ad92110453ece05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 3 Jul 2022 14:37:47 +0200 Subject: [PATCH 047/638] Run stale workflow at 8:00 once per day MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 050d8ea5d9..3f54c1a5f7 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -2,7 +2,7 @@ name: Mark stale issues on: schedule: - - cron: '0 * * * *' + - cron: '0 8 * * *' workflow_dispatch: jobs: From 98c238064edf79f4609db11fbcc5f59024f5b5a6 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 3 Jul 2022 18:43:45 +0200 Subject: [PATCH 048/638] Change FTL's default log file path from /var/log/pihole/pihole-FTL.log to /var/log/pihole/FTL.log Signed-off-by: DL6ER --- advanced/Scripts/piholeDebug.sh | 2 +- advanced/Templates/logrotate | 2 +- advanced/Templates/pihole-FTL.service | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c00245b489..e71263d35a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -129,7 +129,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}/FTL.log")" PIHOLE_WEB_SERVER_ACCESS_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/access-pihole.log" PIHOLE_WEB_SERVER_ERROR_LOG_FILE="${WEB_SERVER_LOG_DIRECTORY}/error-pihole.log" diff --git a/advanced/Templates/logrotate b/advanced/Templates/logrotate index eeeeeadd0d..9a56b55297 100644 --- a/advanced/Templates/logrotate +++ b/advanced/Templates/logrotate @@ -9,7 +9,7 @@ nomail } -/var/log/pihole/pihole-FTL.log { +/var/log/pihole/FTL.log { # su # weekly copytruncate diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 941f1ee054..f5abfcea43 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -70,13 +70,13 @@ start() { mkdir -pm 0755 /run/pihole /var/log/pihole [ ! -f "${FTL_PID_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" [ ! -f "${FTL_PORT_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" - [ ! -f /var/log/pihole/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/pihole-FTL.log + [ ! -f /var/log/pihole/FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log [ ! -f /var/log/pihole/pihole.log ] && install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit all necessary files - chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole /var/log/pihole/pihole-FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases + chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole /var/log/pihole/FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases # Ensure that permissions are set so that pihole-FTL can edit the files. We ignore errors as the file may not (yet) exist - chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/pihole-FTL.log + chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/FTL.log chmod -f 0640 /var/log/pihole/pihole.log # Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist chown -f pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db /etc/pihole/macvendor.db @@ -91,7 +91,7 @@ start() { fi if [ ! -f /var/log/pihole-FTL.log ]; then - ln -s /var/log/pihole/pihole-FTL.log /var/log/pihole-FTL.log + ln -s /var/log/pihole/FTL.log /var/log/pihole-FTL.log chown -h pihole:pihole /var/log/pihole-FTL.log fi From bd8288d6ef8da46723bcf0662816a3735ea6197d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 3 Jul 2022 18:54:13 +0200 Subject: [PATCH 049/638] Special renaming for pihole-FTL.* to pihole/FTL.log.* Signed-off-by: DL6ER --- automated install/basic-install.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 953e620321..4522959be9 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2610,12 +2610,24 @@ main() { # If this is an update from a previous Pi-hole installation # we need to move any existing `pihole*` logs from `/var/log` to `/var/log/pihole` - # if /var/log/pihole.log is not a symlink (set durign FTL startup) move the files + # if /var/log/pihole.log is not a symlink (set during FTL startup) move the files # can be removed with Pi-hole v6.0 # To be sure FTL is not running when we move the files we explicitly stop it here stop_service pihole-FTL &> /dev/null + # Special handling for pihole-FTL.log -> pihole/FTL.log + if [ -f /var/log/pihole-FTL.log ] && [ ! -L /var/log/pihole-FTL.log ]; then + # /var/log/pihole-FTL.log -> /var/log/pihole/FTL.log + # /var/log/pihole-FTL.log.1 -> /var/log/pihole/FTL.log.1 + # /var/log/pihole-FTL.log.2.gz -> /var/log/pihole/FTL.log.2.gz + # /var/log/pihole-FTL.log.3.gz -> /var/log/pihole/FTL.log.3.gz + # /var/log/pihole-FTL.log.4.gz -> /var/log/pihole/FTL.log.4.gz + # /var/log/pihole-FTL.log.5.gz -> /var/log/pihole/FTL.log.5.gz + for f in /var/log/pihole-FTL.log*; do mv "$f" "$( sed "s/pihole-/pihole\//" <<< "$f")"; done + fi + + # Remaining log files if [ -f /var/log/pihole.log ] && [ ! -L /var/log/pihole.log ]; then mv /var/log/pihole*.* /var/log/pihole/ 2>/dev/null fi From 80bef5f6b6840253bc8fe5ec0941f15977623eed Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 2 Jul 2022 17:47:41 -0700 Subject: [PATCH 050/638] Direct pull for epel-release Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 14 ++++++++------ test/test_centos_common_support.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 953e620321..3f5c972f68 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -397,14 +397,16 @@ select_rpm_php(){ unset CENTOS7_PIHOLE_WEB_DEPS fi # CentOS requires the EPEL repository to gain access to Fedora packages - EPEL_PKG="epel-release" - rpm -q ${EPEL_PKG} &> /dev/null || rc=$? - if [[ $rc -ne 0 ]]; then - printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" - "${PKG_INSTALL[@]}" ${EPEL_PKG} &> /dev/null - printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" + if [[ CURRENT_CENTOS_VERSION -eq 7 ]]; then + EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" + elif [[ CURRENT_CENTOS_VERSION -eq 8 ]]; then + EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" fi + printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" + "${PKG_INSTALL[@]}" ${EPEL_PKG} &> /dev/null + printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" + # The default php on CentOS 7.x is 5.4 which is EOL # Check if the version of PHP available via installed repositories is >= to PHP 7 AVAILABLE_PHP_VERSION=$("${PKG_MANAGER}" info php | grep -i version | grep -o '[0-9]\+' | head -1) diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index 8903a7a07e..80ca2a85a9 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -36,7 +36,7 @@ def test_enable_epel_repository_centos(host): expected_stdout = info_box + (' Enabling EPEL package repository ' '(https://fedoraproject.org/wiki/EPEL)') assert expected_stdout in package_manager_detect.stdout - expected_stdout = tick_box + ' Installed epel-release' + expected_stdout = tick_box + ' Installed' assert expected_stdout in package_manager_detect.stdout epel_package = host.package('epel-release') assert epel_package.is_installed From bf57a786e6c80efd19573b626febdb928dd583b3 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 18 Jun 2022 17:17:10 -0700 Subject: [PATCH 051/638] Convert whiptail to dialog. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 678 ++++++++++++++++++----------- 1 file changed, 430 insertions(+), 248 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3f5c972f68..b1202d7517 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2,7 +2,7 @@ # shellcheck disable=SC1090 # Pi-hole: A black hole for Internet advertisements -# (c) 2017-2021 Pi-hole, LLC (https://pi-hole.net) +# (c) Pi-hole (https://pi-hole.net) # Network-wide ad blocking via your own hardware. # # Installs and Updates Pi-hole @@ -32,6 +32,14 @@ export PATH+=':/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' # Local variables will be in lowercase and will exist only within functions # It's still a work in progress, so you may see some variance in this guideline until it is complete +# Dialog result codes +# dialog code values can be set by environment variables, we only override if +# the env var is not set or empty. +: "${DIALOG_OK:=0}" +: "${DIALOG_CANCEL:=1}" +: "${DIALOG_ESC:=255}" + + # List of supported DNS servers DNS_SERVERS=$(cat << EOM Google (ECS, DNSSEC);8.8.8.8;8.8.4.4;2001:4860:4860:0:0:0:0:8888;2001:4860:4860:0:0:0:0:8844 @@ -93,7 +101,7 @@ if [ -z "${USER}" ]; then USER="$(id -un)" fi -# whiptail dialog dimensions: 20 rows and 70 chars width assures to fit on small screens and is known to hold all content. +# dialog dimensions: 20 rows and 70 chars width assures to fit on small screens and is known to hold all content. r=20 c=70 @@ -317,7 +325,7 @@ package_manager_detect() { # Packages required to perform the os_check (stored as an array) OS_CHECK_DEPS=(grep dnsutils) # Packages required to run this install script (stored as an array) - INSTALLER_DEPS=(git iproute2 whiptail ca-certificates) + INSTALLER_DEPS=(git iproute2 dialog ca-certificates) # Packages required to run Pi-hole (stored as an array) PIHOLE_DEPS=(cron curl iputils-ping psmisc sudo unzip idn2 libcap2-bin dns-root-data libcap2 netcat-openbsd procps) # Packages required for the Web admin interface (stored as an array) @@ -419,32 +427,74 @@ select_rpm_php(){ rpm -q ${REMI_PKG} &> /dev/null || rc=$? if [[ $rc -ne 0 ]]; then # The PHP version available via default repositories is older than version 7 - if ! whiptail --defaultno --title "PHP 7 Update (recommended)" --yesno "PHP 7.x is recommended for both security and language features.\\nWould you like to install PHP7 via Remi's RPM repository?\\n\\nSee: https://rpms.remirepo.net for more information" "${r}" "${c}"; then - # User decided to NOT update PHP from REMI, attempt to install the default available PHP version - printf " %b User opt-out of PHP 7 upgrade on CentOS. Deprecated PHP may be in use.\\n" "${INFO}" - : # continue with unsupported php version - else - printf " %b Enabling Remi's RPM repository (https://rpms.remirepo.net)\\n" "${INFO}" - "${PKG_INSTALL[@]}" "https://rpms.remirepo.net/enterprise/${REMI_PKG}-$(rpm -E '%{rhel}').rpm" &> /dev/null - # enable the PHP 7 repository via yum-config-manager (provided by yum-utils) - "${PKG_INSTALL[@]}" "yum-utils" &> /dev/null - yum-config-manager --enable ${REMI_REPO} &> /dev/null - printf " %b Remi's RPM repository has been enabled for PHP7\\n" "${TICK}" - # trigger an install/update of PHP to ensure previous version of PHP is updated from REMI - if "${PKG_INSTALL[@]}" "php-cli" &> /dev/null; then - printf " %b PHP7 installed/updated via Remi's RPM repository\\n" "${TICK}" - else - printf " %b There was a problem updating to PHP7 via Remi's RPM repository\\n" "${CROSS}" + dialog --no-shadow --clear \ + --title "PHP 7 Update (recommended)" \ + --defaultno \ + --yesno "PHP 7.x is recommended for both security and language features. \ + \\nWould you like to install PHP7 via Remi's RPM repository? \ + \\n\\nSee: https://rpms.remirepo.net for more information" \ + "${r}" "${c}" + + result=$? + case ${result} in + # User chose to install PHP 7 via Remi's RPM repository + "${DIALOG_OK}") + printf " %b Enabling Remi's RPM repository (https://rpms.remirepo.net)\\n" "${INFO}" + "${PKG_INSTALL[@]}" "https://rpms.remirepo.net/enterprise/${REMI_PKG}-$(rpm -E '%{rhel}').rpm" &> /dev/null + # enable the PHP 7 repository via yum-config-manager (provided by yum-utils) + "${PKG_INSTALL[@]}" "yum-utils" &> /dev/null + yum-config-manager --enable ${REMI_REPO} &> /dev/null + printf " %b Remi's RPM repository has been enabled for PHP7\\n" "${TICK}" + # trigger an install/update of PHP to ensure previous version of PHP is updated from REMI + if "${PKG_INSTALL[@]}" "php-cli" &> /dev/null; then + printf " %b PHP7 installed/updated via Remi's RPM repository\\n" "${TICK}" + else + printf " %b There was a problem updating to PHP7 via Remi's RPM repository\\n" "${CROSS}" + exit 1 + fi + ;; + + # User chose not to install PHP 7 via Remi's RPM repository + "${DIALOG_CANCEL}") + # User decided to NOT update PHP from REMI, attempt to install the default available PHP version + printf " %b User opt-out of PHP 7 upgrade on CentOS. Deprecated PHP may be in use.\\n" "${INFO}" + ;; + + # User closed the dialog window + "${DIALOG_ESC}") + printf " %b Escape pressed, exiting installer at Remi dialog window\\n" "${CROSS}" exit 1 - fi - fi - fi # Warn user of unsupported version of Fedora or CentOS - if ! whiptail --defaultno --title "Unsupported RPM based distribution" --yesno "Would you like to continue installation on an unsupported RPM based distribution?\\n\\nPlease ensure the following packages have been installed manually:\\n\\n- lighttpd\\n- lighttpd-fastcgi\\n- PHP version 7+" "${r}" "${c}"; then - printf " %b Aborting installation due to unsupported RPM based distribution\\n" "${CROSS}" - exit - else - printf " %b Continuing installation with unsupported RPM based distribution\\n" "${INFO}" + ;; + esac fi + + # Warn user of unsupported version of Fedora or CentOS + dialog --no-shadow --clear \ + --title "Unsupported RPM based distribution" \ + --defaultno \ + --no-button "Exit" \ + --yes-button "Continue" \ + --yesno "Would you like to continue installation on an unsupported RPM based distribution? \ + \\n\\nPlease ensure the following packages have been installed manually: \ + \\n\\n- lighttpd\\n- lighttpd-fastcgi\\n- PHP version 7+" \ + "${r}" "${c}" + + result=$? + case ${result} in + # User chose to continue installation on an unsupported RPM based distribution + "${DIALOG_OK}") + printf " %b User opted to continue installation on an unsupported RPM based distribution.\\n" "${INFO}" + ;; + # User chose not to continue installation on an unsupported RPM based distribution + "${DIALOG_CANCEL}") + printf " %b User opted not to continue installation on an unsupported RPM based distribution.\\n" "${INFO}" + exit 1 + ;; + "${DIALOG_ESC}") + printf " %b Escape pressed, exiting installer at unsupported RPM based distribution dialog window\\n" "${CROSS}" + exit 1 + ;; + esac fi fi } @@ -636,40 +686,46 @@ get_available_interfaces() { # A function for displaying the dialogs the user sees when first running the installer welcomeDialogs() { # Display the welcome dialog using an appropriately sized window via the calculation conducted earlier in the script - whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "\\n\\nThis installer will transform your device into a network-wide ad blocker!" "${r}" "${c}" - - # Request that users donate if they enjoy the software since we all work on it in our free time - whiptail --msgbox --backtitle "Plea" --title "Free and open source" "\\n\\nThe Pi-hole is free, but powered by your donations: https://pi-hole.net/donate/" "${r}" "${c}" - - # Explain the need for a static address - if whiptail --defaultno --backtitle "Initiating network interface" --title "Static IP Needed" --yesno "\\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly. - -IMPORTANT: If you have not already done so, you must ensure that this device has a static IP. Either through DHCP reservation, or by manually assigning one. Depending on your operating system, there are many ways to achieve this. - -Choose yes to indicate that you have understood this message, and wish to continue" "${r}" "${c}"; then - #Nothing to do, continue - echo - else - printf " %b Installer exited at static IP message.\\n" "${INFO}" - exit 1 - fi + dialog --no-shadow --clear \ + --backtitle "Welcome" \ + --title "Pi-hole Automated Installer" \ + --msgbox "\\n\\nThis installer will transform your device into a network-wide ad blocker!" \ + "${r}" "${c}" \ + --and-widget \ + --backtitle "Support Pi-hole" \ + --title "Open Source Software" \ + --msgbox "\\n\\nThe Pi-hole is free, but powered by your donations: https://pi-hole.net/donate/" \ + "${r}" "${c}" \ + --and-widget \ + --colors \ + --backtitle "Initiating network interface" \ + --title "Static IP Needed" \ + --no-button "Exit" --yes-button "Continue" \ + --defaultno \ + --yesno "\\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.\\n\\n \ + \\Zb\\Z1IMPORTANT:\\Zn If you have not already done so, you must ensure that this device has a static IP.\\n \ + Depending on your operating system, there are many ways to achieve this, through DHCP reservation, or by manually assigning one.\\n\\n \ + Please continue when the static addressing has been configured." \ + "${r}" "${c}" + + result=$? + case "${result}" in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %b Installer exited at static IP message.\\n" "${INFO}" + exit 1 + ;; + esac } # A function that lets the user pick an interface to use with Pi-hole chooseInterface() { - # Turn the available interfaces into an array so it can be used with a whiptail dialog - local interfacesArray=() + # Turn the available interfaces into a string so it can be used with dialog + local interfacesList # Number of available interfaces local interfaceCount - # Whiptail variable storage - local chooseInterfaceCmd - # Temporary Whiptail options storage - local chooseInterfaceOptions - # Loop sentinel variable - local firstLoop=1 - # Find out how many interfaces are available to choose from - interfaceCount=$(wc -l <<< "${availableInterfaces}") + # POSIX compliant way to get the number of elements in an array + interfaceCount=$(printf "%s\n" "${availableInterfaces}" | wc -l) # If there is one interface, if [[ "${interfaceCount}" -eq 1 ]]; then @@ -677,33 +733,32 @@ chooseInterface() { PIHOLE_INTERFACE="${availableInterfaces}" # Otherwise, else + # Set status for the first entry to be selected + status="ON" + # While reading through the available interfaces - while read -r line; do - # Use a variable to set the option as OFF to begin with - mode="OFF" - # If it's the first loop, - if [[ "${firstLoop}" -eq 1 ]]; then - # set this as the interface to use (ON) - firstLoop=0 - mode="ON" - fi - # Put all these interfaces into an array - interfacesArray+=("${line}" "available" "${mode}") - # Feed the available interfaces into this while loop - done <<< "${availableInterfaces}" - # The whiptail command that will be run, stored in a variable - chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to toggle selection)" "${r}" "${c}" 6) - # Now run the command using the interfaces saved into the array - chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) || \ - # If the user chooses Cancel, exit - { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; exit 1; } - # For each interface - for desiredInterface in ${chooseInterfaceOptions}; do - # Set the one the user selected as the interface to use - PIHOLE_INTERFACE=${desiredInterface} - # and show this information to the user - printf " %b Using interface: %s\\n" "${INFO}" "${PIHOLE_INTERFACE}" + for interface in ${availableInterfaces}; do + # Put all these interfaces into a string + interfacesList="${interfacesList}${interface} available ${status} " + # All further interfaces are deselected + status="OFF" done + # shellcheck disable=SC2086 + # Disable check for double quote here as we are passing a string with spaces + PIHOLE_INTERFACE=$(dialog --no-shadow --clear --output-fd 1 \ + --radiolist "Choose An Interface (press space to toggle selection)" \ + ${r} ${c} "${interfaceCount}" ${interfacesList}) + + result=$? + case ${result} in + "${DIALOG_CANCEL}"|"${DIALOG_ESC}") + # Show an error message and exit + printf " %b %s\\n" "${CROSS}" "No interface selected, exiting installer" + exit 1 + ;; + esac + + printf " %b Using interface: %s\\n" "${INFO}" "${PIHOLE_INTERFACE}" fi } @@ -789,57 +844,102 @@ getStaticIPv4Settings() { local ipSettingsCorrect local DHCPChoice # Ask if the user wants to use DHCP settings as their static IP - # This is useful for users that are using DHCP reservations; then we can just use the information gathered via our functions - DHCPChoice=$(whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --menu --separate-output "Do you want to use your current network settings as a static address? \\n - IP address: ${IPV4_ADDRESS} \\n - Gateway: ${IPv4gw} \\n" "${r}" "${c}" 3\ - "Yes" "Set static IP using current values" \ - "No" "Set static IP using custom values" \ - "Skip" "I will set a static IP later, or have already done so" 3>&2 2>&1 1>&3) || \ - { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; exit 1; } - - case ${DHCPChoice} in - "Yes") - # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. - whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. - If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. - It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." "${r}" "${c}" - # Nothing else to do since the variables are already set above - setDHCPCD - ;; - - "No") - # Otherwise, we need to ask the user to input their desired settings. - # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) - # Start a loop to let the user enter their information with the chance to go back and edit it if necessary - until [[ "${ipSettingsCorrect}" = True ]]; do - - # Ask for the IPv4 address - IPV4_ADDRESS=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" "${r}" "${c}" "${IPV4_ADDRESS}" 3>&1 1>&2 2>&3) || \ - # Canceling IPv4 settings window - { ipSettingsCorrect=False; echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; } - printf " %b Your static IPv4 address: %s\\n" "${INFO}" "${IPV4_ADDRESS}" - - # Ask for the gateway - IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" "${r}" "${c}" "${IPv4gw}" 3>&1 1>&2 2>&3) || \ - # Canceling gateway settings window - { ipSettingsCorrect=False; echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}"; exit 1; } - printf " %b Your static IPv4 gateway: %s\\n" "${INFO}" "${IPv4gw}" - - # Give the user a chance to review their settings before moving on - if whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? - IP address: ${IPV4_ADDRESS} - Gateway: ${IPv4gw}" "${r}" "${c}"; then + # This is useful for users that are using DHCP reservations; we can use the information gathered + DHCPChoice=$(dialog --no-shadow --clear --output-fd 1 \ + --backtitle "Calibrating network interface" \ + --title "Static IP Address" \ + --menu "Do you want to use your current network settings as a static address?\\n \ + IP address: ${IPV4_ADDRESS}\\n \ + Gateway: ${IPv4gw}\\n" \ + "${r}" "${c}" 3 \ + "Yes" "Set static IP using current values" \ + "No" "Set static IP using custom values" \ + "Skip" "I will set a static IP later, or have already done so") + + result=$? + case ${result} in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac + + case ${DHCPChoice} in + "Skip") + return + ;; + "Yes") + # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. + dialog --no-shadow --clear \ + --backtitle "IP information" \ + --title "FYI: IP Conflict" \ + --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict. \ + But in most cases the router is smart enough to not do that. \ + If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. \ + It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac + ;; + + "No") + # Otherwise, we need to ask the user to input their desired settings. + # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) + # Start a loop to let the user enter their information with the chance to go back and edit it if necessary + ipSettingsCorrect=false + until [[ "${ipSettingsCorrect}" = True ]]; do + + # Ask for the IPv4 address + _staticIPv4Temp=$(dialog --no-shadow --clear --output-fd 1 \ + --backtitle "Calibrating network interface" \ + --title "IPv4 Address" \ + --form "\\nEnter your desired IPv4 address" \ + "${r}" "${c}" 0 \ + "IPv4 Address:" 1 1 "${IPV4_ADDRESS}" 1 15 19 0 \ + "IPv4 Gateway:" 2 1 "${IPv4gw}" 2 15 19 0) + + result=$? + case ${result} in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac + + IPV4_ADDRESS=${_staticIPv4Temp%$'\n'*} + IPv4gw=${_staticIPv4Temp#*$'\n'} + + # Give the user a chance to review their settings before moving on + dialog --no-shadow --clear \ + --backtitle "Calibrating network interface" \ + --title "Static IP Address" \ + --defaultno \ + --yesno "Are these settings correct? + IP address: ${IPV4_ADDRESS} + Gateway: ${IPv4gw}" \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_OK}") # After that's done, the loop ends and we move on ipSettingsCorrect=True - else - # If the settings are wrong, the loop continues - ipSettingsCorrect=False - fi + ;; + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac done - setDHCPCD - ;; - esac + ;; + esac + setDHCPCD } # Configure networking via dhcpcd @@ -929,11 +1029,18 @@ setDNS() { DNSChooseOptions[DNSServerCount]="" # Restore the IFS to what it was IFS=${OIFS} - # In a whiptail dialog, show the options - DNSchoices=$(whiptail --separate-output --menu "Select Upstream DNS Provider. To use your own, select Custom." "${r}" "${c}" 7 \ - "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) || \ - # Exit if the user selects "Cancel" - { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; exit 1; } + # In a dialog, show the options + DNSchoices=$(dialog --no-shadow --clear --output-fd 1 \ + --menu "Select Upstream DNS Provider. To use your own, select Custom." "${r}" "${c}" 7 \ + "${DNSChooseOptions[@]}") + + result=$? + case ${result} in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac # Depending on the user's choice, set the GLOBAL variables to the IP of the respective provider if [[ "${DNSchoices}" == "Custom" ]] @@ -947,7 +1054,7 @@ setDNS() { # If the first and second upstream servers do not exist, do not prepopulate an IP address prePopulate="" else - # Otherwise, prepopulate the whiptail dialogue with the appropriate DNS value(s) + # Otherwise, prepopulate the dialogue with the appropriate DNS value(s) prePopulate=", ${PIHOLE_DNS_2}" fi elif [[ "${PIHOLE_DNS_1}" ]] && [[ ! "${PIHOLE_DNS_2}" ]]; then @@ -957,8 +1064,21 @@ setDNS() { fi # Prompt the user to enter custom upstream servers - piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), separated by a comma. If you want to specify a port other than 53, separate it with a hash.\\n\\nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335'" "${r}" "${c}" "${prePopulate}" 3>&1 1>&2 2>&3) || \ - { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; exit 1; } + piholeDNS=$(dialog --no-shadow --clear --output-fd 1 \ + --backtitle "Specify Upstream DNS Provider(s)" \ + --inputbox "Enter your desired upstream DNS provider(s), separated by a comma. \ + If you want to specify a port other than 53, separate it with a hash. \ + \\n\\nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335'" \ + "${r}" "${c}" "${prePopulate}") + + result=$? + case ${result} in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac + # Clean user input and replace whitespace with comma. piholeDNS=$(sed 's/[, \t]\+/,/g' <<< "${piholeDNS}") @@ -977,7 +1097,21 @@ setDNS() { # If either of the DNS servers are invalid, if [[ "${PIHOLE_DNS_1}" == "${strInvalid}" ]] || [[ "${PIHOLE_DNS_2}" == "${strInvalid}" ]]; then # explain this to the user, - whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\\n\\n DNS Server 1: $PIHOLE_DNS_1\\n DNS Server 2: ${PIHOLE_DNS_2}" ${r} ${c} + dialog --no-shadow --clear \ + --title "Invalid IP Address(es)" \ + --backtitle "Invalid IP" \ + --msgbox "\\nOne or both of the entered IP addresses were invalid. Please try again. \ + \\n\\nInvalid IPs: ${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}" \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac + # set the variables back to nothing, if [[ "${PIHOLE_DNS_1}" == "${strInvalid}" ]]; then PIHOLE_DNS_1="" @@ -988,12 +1122,25 @@ setDNS() { # and continue the loop. DNSSettingsCorrect=False else - # Otherwise, show the DNS setting to the user, and break the loop if they confirm them. - if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\\n DNS Server 1: $PIHOLE_DNS_1\\n DNS Server 2: ${PIHOLE_DNS_2}" "${r}" "${c}"); then - DNSSettingsCorrect=True - else - DNSSettingsCorrect=False - fi + dialog --no-shadow --clear \ + --backtitle "Specify Upstream DNS Provider(s)" \ + --title "Upstream DNS Provider(s)" \ + --yesno "Are these settings correct?\\n\\tDNS Server 1:\\t${PIHOLE_DNS_1}\\n\\tDNS Server 2:\\t${PIHOLE_DNS_2}" \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_OK}") + DNSSettingsCorrect=True + ;; + "${DIALOG_CANCEL}") + DNSSettingsCorrect=False + ;; + "${DIALOG_ESC}") + printf " %bEscape pressed, exiting installer at DNS Settings%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac fi done else @@ -1023,106 +1170,122 @@ setDNS() { # Allow the user to enable/disable logging setLogging() { - # Local, named variables - local LogToggleCommand - local LogChooseOptions - local LogChoices - - # Ask if the user wants to log queries - LogToggleCommand=(whiptail --separate-output --radiolist "Do you want to log queries?" "${r}" "${c}" 6) - # The default selection is on - LogChooseOptions=("On (Recommended)" "" on - Off "" off) - # Get the user's choice - LogChoices=$("${LogToggleCommand[@]}" "${LogChooseOptions[@]}" 2>&1 >/dev/tty) || (printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" && exit 1) - case ${LogChoices} in - # If it's on, - "On (Recommended)") - printf " %b Logging On.\\n" "${INFO}" - # set the GLOBAL variable setting to true + # Ask the user if they want to enable logging + dialog --no-shadow --clear \ + --backtitle "Pihole Installation" \ + --title "Enable Logging" \ + --yesno "\\n\\nWould you like to enable query logging?" \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_OK}") + # If they chose yes, + printf " %b Query Logging on.\\n" "${INFO}" QUERY_LOGGING=true ;; - # Otherwise, it's off, - Off) - printf " %b Logging Off.\\n" "${INFO}" - # set the GLOBAL variable setting to false + "${DIALOG_CANCEL}") + # If they chose no, + printf " %b Query Logging off.\\n" "${INFO}" QUERY_LOGGING=false ;; + "${DIALOG_ESC}") + # User pressed + printf " %bEscape pressed, exiting installer at Query Logging choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; esac } # Allow the user to set their FTL privacy level setPrivacyLevel() { - local LevelCommand - local LevelOptions - - LevelCommand=(whiptail --separate-output --radiolist "Select a privacy mode for FTL. https://docs.pi-hole.net/ftldns/privacylevels/" "${r}" "${c}" 6) - - # The default selection is level 0 - LevelOptions=( - "0" "Show everything" on - "1" "Hide domains" off - "2" "Hide domains and clients" off - "3" "Anonymous mode" off - ) - - # Get the user's choice - PRIVACY_LEVEL=$("${LevelCommand[@]}" "${LevelOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1) - - printf " %b Privacy level %d" "${INFO}" "${PRIVACY_LEVEL}" + PRIVACY_LEVEL=$(dialog --no-shadow --clear --output-fd 1 \ + --radiolist "Select a privacy mode for FTL. https://docs.pi-hole.net/ftldns/privacylevels/" \ + "${r}" "${c}" 6 \ + # The default selection is level 0 + "0" "Show everything" on \ + "1" "Hide domains" off \ + "2" "Hide domains and clients" off \ + "3" "Anonymous mode" off) + + result=$? + case ${result} in + "${DIALOG_OK}") + printf " %b Using privacy level: %s\\n" "${INFO}" "${PRIVACY_LEVEL}" + ;; + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %b Cancelled privacy level selection.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac } # Function to ask the user if they want to install the dashboard setAdminFlag() { - # Local, named variables - local WebToggleCommand - local WebChooseOptions - local WebChoices - # Similar to the logging function, ask what the user wants - WebToggleCommand=(whiptail --separate-output --radiolist "Do you wish to install the web admin interface?" "${r}" "${c}" 6) - # with the default being enabled - WebChooseOptions=("On (Recommended)" "" on - Off "" off) - WebChoices=$("${WebToggleCommand[@]}" "${WebChooseOptions[@]}" 2>&1 >/dev/tty) || (printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" && exit 1) - # Depending on their choice - case ${WebChoices} in - "On (Recommended)") - printf " %b Web Interface On\\n" "${INFO}" - # Set it to true + dialog --no-shadow --clear \ + --backtitle "Pihole Installation" \ + --title "Admin Web Interface" \ + --yesno "\\n\\nDo you want to install the Admin Web Interface?" \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_OK}") + # If they chose yes, + printf " %b Installing Admin Web Interface\\n" "${INFO}" + # Set the flag to install the web interface INSTALL_WEB_INTERFACE=true ;; - Off) - printf " %b Web Interface Off\\n" "${INFO}" - # or false + "${DIALOG_CANCEL}") + # If they chose no, + printf " %b Not installing Admin Web Interface\\n" "${INFO}" + # Set the flag to not install the web interface INSTALL_WEB_INTERFACE=false - # Deselect the web server as well, since it is obsolete then INSTALL_WEB_SERVER=false ;; + "${DIALOG_ESC}") + # User pressed + printf " %bEscape pressed, exiting installer at Admin Web Interface choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; esac # If the user wants to install the Web admin interface (i.e. it has not been deselected above) - if [[ "${INSTALL_WEB_SERVER}" == true ]]; then + if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then # Get list of required PHP modules, excluding base package (common) and handler (cgi) local i php_modules for i in "${PIHOLE_WEB_DEPS[@]}"; do [[ $i == 'php'* && $i != *'-common' && $i != *'-cgi' ]] && php_modules+=" ${i#*-}"; done - WebToggleCommand=(whiptail --separate-output --radiolist "Do you wish to install the web server (lighttpd) and required PHP modules?\\n\\nNB: If you disable this, and, do not have an existing web server and required PHP modules (${php_modules# }) installed, the web interface will not function. Additionally the web server user needs to be member of the \"pihole\" group for full functionality." "${r}" "${c}" 6) - # Enable as default and recommended option - WebChooseOptions=("On (Recommended)" "" on - Off "" off) - WebChoices=$("${WebToggleCommand[@]}" "${WebChooseOptions[@]}" 2>&1 >/dev/tty) || (printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" && exit 1) - # Depending on their choice - case ${WebChoices} in - "On (Recommended)") - printf " %b Web Server On\\n" "${INFO}" - # set it to true, as clearly seen below. + dialog --no-shadow --clear \ + --backtitle "Pi-hole Installation" \ + --title "Web Server" \ + --yesno "\\n\\nA web server is required for the Admin Web Interface. \ + \\n\\nDo you want to install lighttpd and the required PHP modules? \ + \\n\\nNB: If you disable this, and, do not have an existing web server \ + and required PHP modules (${php_modules# }) installed, the web interface \ + will not function. Additionally the web server user needs to be member of \ + the \"pihole\" group for full functionality." \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_OK}") + # If they chose yes, + printf " %b Installing lighttpd\\n" "${INFO}" + # Set the flag to install the web server INSTALL_WEB_SERVER=true ;; - Off) - printf " %b Web Server Off\\n" "${INFO}" - # or false + "${DIALOG_CANCEL}") + # If they chose no, + printf " %b Not installing lighttpd\\n" "${INFO}" + # Set the flag to not install the web server INSTALL_WEB_SERVER=false ;; + "${DIALOG_ESC}") + # User pressed + printf " %bEscape pressed, exiting installer at web server choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; esac fi } @@ -1133,18 +1296,33 @@ chooseBlocklists() { if [[ -f "${adlistFile}" ]]; then 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 suggestion below, and/or add your own after installation\\n\\nTo deselect the suggested list, use spacebar" "${r}" "${c}" 5) - # In an array, show the options available (all off by default): - options=(StevenBlack "StevenBlack's Unified Hosts List" on) - - # In a variable, show the choices available; exit if Cancel is selected - choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) || { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; rm "${adlistFile}" ;exit 1; } - # Add all selected choices to the lists file - for choice in ${choices} - do - appendToListsFile "${choice}" - done + # Let user select (or not) blocklists + dialog --no-shadow --clear \ + --backtitle "Pi-hole Installation" \ + --title "Blocklists" \ + --yesno "\\nPi-hole relies on third party lists in order to block ads. \ + \\n\\nYou can use the suggestion below, and/or add your own after installation. \ + \\n\\nSelect 'Yes' to include: \ + \\n\\nStevenBlack's Unified Hosts List" \ + "${r}" "${c}" + + result=$? + case ${result} in + "${DIALOG_OK}") + # If they chose yes, + printf " %b Installing StevenBlack's Unified Hosts List\\n" "${INFO}" + echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >> "${adlistFile}" + ;; + "${DIALOG_CANCEL}") + # If they chose no, + printf " %b Not installing StevenBlack's Unified Hosts List\\n" "${INFO}" + ;; + "${DIALOG_ESC}") + # User pressed + printf " %bEscape pressed, exiting installer at blocklist choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac # Create an empty adList file with appropriate permissions. if [ ! -f "${adlistFile}" ]; then install -m 644 /dev/null "${adlistFile}" @@ -1153,14 +1331,6 @@ chooseBlocklists() { fi } -# Accept a string parameter, it must be one of the default lists -# This function saves duplication between chooseBlocklists and installDefaultBlocklists -appendToListsFile() { - case $1 in - StevenBlack ) echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >> "${adlistFile}";; - esac -} - # Used only in unattended setup # If there is already the adListFile, we keep it, else we create it using all default lists installDefaultBlocklists() { @@ -1169,7 +1339,7 @@ installDefaultBlocklists() { if [[ -f "${adlistFile}" ]]; then return; fi - appendToListsFile StevenBlack + echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >> "${adlistFile}" } # Check if /etc/dnsmasq.conf is from pi-hole. If so replace with an original and install new in .d directory @@ -1940,14 +2110,14 @@ Your Admin Webpage login password is ${pwstring}" fi # Final completion message to user - whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using: - -IPv4: ${IPV4_ADDRESS%/*} -IPv6: ${IPV6_ADDRESS:-"Not Configured"} - -If you have not done so already, the above IP should be set to static. - -${additional}" "${r}" "${c}" + dialog --no-shadow --clear \ + --title "Installation Complete!" \ + --msgbox "Configure your devices to use the Pi-hole as their DNS server using: \ + \\n\\nIPv4: ${IPV4_ADDRESS%/*} \ + \\nIPv6: ${IPV6_ADDRESS:-"Not Configured"} \ + \\nIf you have not done so already, the above IP should be set to static. \ + \\n${additional}" + "${r}" "${c}" } update_dialogs() { @@ -1967,20 +2137,32 @@ update_dialogs() { opt2b="Resets Pi-hole and allows re-selecting settings." # Display the information to the user - UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\\n\\nWe have detected an existing install.\\n\\nPlease choose from the following options: \\n($strAdd)" "${r}" "${c}" 2 \ + UpdateCmd=$(dialog --no-shadow --clear --output-fd 1 \ + --title "Existing Install Detected!" \ + --menu "\\n\\nWe have detected an existing install. \ + \\n\\nPlease choose from the following options: \ + \\n($strAdd)" \ + "${r}" "${c}" 2 \ "${opt1a}" "${opt1b}" \ - "${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3) || \ - { printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}"; exit 1; } + "${opt2a}" "${opt2b}") + + result=$? + case ${result} in + "${DIALOG_CANCEL}" | "${DIALOG_ESC}") + printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + exit 1 + ;; + esac # Set the variable based on if the user chooses case ${UpdateCmd} in # repair, or - ${opt1a}) + "${opt1a}") printf " %b %s option selected\\n" "${INFO}" "${opt1a}" useUpdateVars=true ;; # reconfigure, - ${opt2a}) + "${opt2a}") printf " %b %s option selected\\n" "${INFO}" "${opt2a}" useUpdateVars=false ;; @@ -2478,7 +2660,7 @@ main() { if [[ -f "${setupVars}" ]]; then # if it's running unattended, if [[ "${runUnattended}" == true ]]; then - printf " %b Performing unattended setup, no whiptail dialogs will be displayed\\n" "${INFO}" + printf " %b Performing unattended setup, no dialogs will be displayed\\n" "${INFO}" # Use the setup variables useUpdateVars=true # also disable debconf-apt-progress dialogs From 1ed5ff306d21392f9da6566e5601110cb590e085 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 2 Jul 2022 12:36:16 -0700 Subject: [PATCH 052/638] Align dialog texts. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 78 +++++++++++++++--------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b1202d7517..f0a3396788 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -101,7 +101,7 @@ if [ -z "${USER}" ]; then USER="$(id -un)" fi -# dialog dimensions: 20 rows and 70 chars width assures to fit on small screens and is known to hold all content. +# dialog dimensions: Let dialog handle appropriate sizing. r=20 c=70 @@ -430,9 +430,9 @@ select_rpm_php(){ dialog --no-shadow --clear \ --title "PHP 7 Update (recommended)" \ --defaultno \ - --yesno "PHP 7.x is recommended for both security and language features. \ - \\nWould you like to install PHP7 via Remi's RPM repository? \ - \\n\\nSee: https://rpms.remirepo.net for more information" \ + --yesno "PHP 7.x is recommended for both security and language features.\ +\\n\\nWould you like to install PHP7 via Remi's RPM repository?\ +\\n\\nSee: https://rpms.remirepo.net for more information"\ "${r}" "${c}" result=$? @@ -474,9 +474,9 @@ select_rpm_php(){ --defaultno \ --no-button "Exit" \ --yes-button "Continue" \ - --yesno "Would you like to continue installation on an unsupported RPM based distribution? \ - \\n\\nPlease ensure the following packages have been installed manually: \ - \\n\\n- lighttpd\\n- lighttpd-fastcgi\\n- PHP version 7+" \ + --yesno "Would you like to continue installation on an unsupported RPM based distribution?\ +\\n\\nPlease ensure the following packages have been installed manually:\ +\\n\\n- lighttpd\\n- lighttpd-fastcgi\\n- PHP version 7+"\ "${r}" "${c}" result=$? @@ -702,10 +702,10 @@ welcomeDialogs() { --title "Static IP Needed" \ --no-button "Exit" --yes-button "Continue" \ --defaultno \ - --yesno "\\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.\\n\\n \ - \\Zb\\Z1IMPORTANT:\\Zn If you have not already done so, you must ensure that this device has a static IP.\\n \ - Depending on your operating system, there are many ways to achieve this, through DHCP reservation, or by manually assigning one.\\n\\n \ - Please continue when the static addressing has been configured." \ + --yesno "\\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.\\n\\n\ +\\Zb\\Z1IMPORTANT:\\Zn If you have not already done so, you must ensure that this device has a static IP.\\n\\n\ +Depending on your operating system, there are many ways to achieve this, through DHCP reservation, or by manually assigning one.\\n\\n\ +Please continue when the static addressing has been configured."\ "${r}" "${c}" result=$? @@ -873,10 +873,10 @@ getStaticIPv4Settings() { dialog --no-shadow --clear \ --backtitle "IP information" \ --title "FYI: IP Conflict" \ - --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict. \ - But in most cases the router is smart enough to not do that. \ - If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. \ - It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." \ + --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict\ +But in most cases the router is smart enough to not do that.\ +If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.\ +It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."\ "${r}" "${c}" result=$? @@ -1066,9 +1066,9 @@ setDNS() { # Prompt the user to enter custom upstream servers piholeDNS=$(dialog --no-shadow --clear --output-fd 1 \ --backtitle "Specify Upstream DNS Provider(s)" \ - --inputbox "Enter your desired upstream DNS provider(s), separated by a comma. \ - If you want to specify a port other than 53, separate it with a hash. \ - \\n\\nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335'" \ + --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\ +If you want to specify a port other than 53, separate it with a hash.\ +\\n\\nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335'"\ "${r}" "${c}" "${prePopulate}") result=$? @@ -1100,8 +1100,8 @@ setDNS() { dialog --no-shadow --clear \ --title "Invalid IP Address(es)" \ --backtitle "Invalid IP" \ - --msgbox "\\nOne or both of the entered IP addresses were invalid. Please try again. \ - \\n\\nInvalid IPs: ${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}" \ + --msgbox "\\nOne or both of the entered IP addresses were invalid. Please try again.\ +\\n\\nInvalid IPs: ${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}" \ "${r}" "${c}" result=$? @@ -1199,10 +1199,10 @@ setLogging() { # Allow the user to set their FTL privacy level setPrivacyLevel() { + # The default selection is level 0 PRIVACY_LEVEL=$(dialog --no-shadow --clear --output-fd 1 \ --radiolist "Select a privacy mode for FTL. https://docs.pi-hole.net/ftldns/privacylevels/" \ "${r}" "${c}" 6 \ - # The default selection is level 0 "0" "Show everything" on \ "1" "Hide domains" off \ "2" "Hide domains and clients" off \ @@ -1259,12 +1259,12 @@ setAdminFlag() { dialog --no-shadow --clear \ --backtitle "Pi-hole Installation" \ --title "Web Server" \ - --yesno "\\n\\nA web server is required for the Admin Web Interface. \ - \\n\\nDo you want to install lighttpd and the required PHP modules? \ - \\n\\nNB: If you disable this, and, do not have an existing web server \ - and required PHP modules (${php_modules# }) installed, the web interface \ - will not function. Additionally the web server user needs to be member of \ - the \"pihole\" group for full functionality." \ + --yesno "\\n\\nA web server is required for the Admin Web Interface.\ +\\n\\nDo you want to install lighttpd and the required PHP modules?\ +\\n\\nNB: If you disable this, and, do not have an existing web server\ +and required PHP modules (${php_modules# }) installed, the web interface\ +will not function. Additionally the web server user needs to be member of\ +the \"pihole\" group for full functionality." \ "${r}" "${c}" result=$? @@ -1300,10 +1300,10 @@ chooseBlocklists() { dialog --no-shadow --clear \ --backtitle "Pi-hole Installation" \ --title "Blocklists" \ - --yesno "\\nPi-hole relies on third party lists in order to block ads. \ - \\n\\nYou can use the suggestion below, and/or add your own after installation. \ - \\n\\nSelect 'Yes' to include: \ - \\n\\nStevenBlack's Unified Hosts List" \ + --yesno "\\nPi-hole relies on third party lists in order to block ads.\ +\\n\\nYou can use the suggestion below, and/or add your own after installation.\ +\\n\\nSelect 'Yes' to include:\ +\\n\\nStevenBlack's Unified Hosts List" \ "${r}" "${c}" result=$? @@ -2112,11 +2112,11 @@ Your Admin Webpage login password is ${pwstring}" # Final completion message to user dialog --no-shadow --clear \ --title "Installation Complete!" \ - --msgbox "Configure your devices to use the Pi-hole as their DNS server using: \ - \\n\\nIPv4: ${IPV4_ADDRESS%/*} \ - \\nIPv6: ${IPV6_ADDRESS:-"Not Configured"} \ - \\nIf you have not done so already, the above IP should be set to static. \ - \\n${additional}" + --msgbox "Configure your devices to use the Pi-hole as their DNS server using:\ +\\n\\nIPv4: ${IPV4_ADDRESS%/*}\ +\\nIPv6: ${IPV6_ADDRESS:-"Not Configured"}\ +\\nIf you have not done so already, the above IP should be set to static.\ +\\n${additional}" "${r}" "${c}" } @@ -2139,9 +2139,9 @@ update_dialogs() { # Display the information to the user UpdateCmd=$(dialog --no-shadow --clear --output-fd 1 \ --title "Existing Install Detected!" \ - --menu "\\n\\nWe have detected an existing install. \ - \\n\\nPlease choose from the following options: \ - \\n($strAdd)" \ + --menu "\\n\\nWe have detected an existing install.\ +\\n\\nPlease choose from the following options:\ +\\n($strAdd)"\ "${r}" "${c}" 2 \ "${opt1a}" "${opt1b}" \ "${opt2a}" "${opt2b}") From a650641da48410744e7bfb77f6d92437a9787282 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 2 Jul 2022 12:51:03 -0700 Subject: [PATCH 053/638] Change tests to mock dialog Signed-off-by: Dan Schaper --- test/test_any_automated_install.py | 18 +++++++++--------- test/test_centos_7_support.py | 8 ++++---- test/test_centos_8_support.py | 8 ++++---- test/test_centos_common_support.py | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index f42feef03b..61849f54a9 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -152,8 +152,8 @@ def test_installPihole_fresh_install_readableFiles(host): ''' confirms all necessary files are readable by pihole user ''' - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '0')}, host) + # dialog returns Cancel for user prompt + mock_command('dialog', {'*': ('', '0')}, host) # mock git pull mock_command_passthrough('git', {'pull': ('', '0')}, host) # mock systemctl to not start lighttpd and FTL @@ -393,8 +393,8 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): "127.0.0.1", # "pi.hole" ] - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '0')}, host) + # dialog returns Cancel for user prompt + mock_command('dialog', {'*': ('', '0')}, host) # mock git pull mock_command_passthrough('git', {'pull': ('', '0')}, host) @@ -870,8 +870,8 @@ def test_FTL_download_aarch64_no_errors(host): ''' confirms only aarch64 package is downloaded for FTL engine ''' - # mock whiptail answers and ensure installer dependencies - mock_command('whiptail', {'*': ('', '0')}, host) + # mock dialog answers and ensure installer dependencies + mock_command('dialog', {'*': ('', '0')}, host) host.run(''' source /opt/pihole/basic-install.sh package_manager_detect @@ -1100,7 +1100,7 @@ def test_os_check_passes(host): def test_package_manager_has_installer_deps(host): ''' Confirms OS is able to install the required packages for the installer''' - mock_command('whiptail', {'*': ('', '0')}, host) + mock_command('dialog', {'*': ('', '0')}, host) output = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect @@ -1113,7 +1113,7 @@ def test_package_manager_has_installer_deps(host): def test_package_manager_has_pihole_deps(host): ''' Confirms OS is able to install the required packages for Pi-hole ''' - mock_command('whiptail', {'*': ('', '0')}, host) + mock_command('dialog', {'*': ('', '0')}, host) output = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect @@ -1127,7 +1127,7 @@ def test_package_manager_has_pihole_deps(host): def test_package_manager_has_web_deps(host): ''' Confirms OS is able to install the required packages for web ''' - mock_command('whiptail', {'*': ('', '0')}, host) + mock_command('dialog', {'*': ('', '0')}, host) output = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect diff --git a/test/test_centos_7_support.py b/test/test_centos_7_support.py index f72740a6b8..c7e75813a1 100644 --- a/test/test_centos_7_support.py +++ b/test/test_centos_7_support.py @@ -26,8 +26,8 @@ def test_php_upgrade_user_optout_centos_eq_7(host): confirms installer behavior when user opt-out of installing PHP7 from REMI (php not currently installed) ''' - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '1')}, host) + # dialog returns Cancel for user prompt + mock_command('dialog', {'*': ('', '1')}, host) package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect @@ -45,8 +45,8 @@ def test_php_upgrade_user_optin_centos_eq_7(host): confirms installer behavior when user opt-in to installing PHP7 from REMI (php not currently installed) ''' - # Whiptail dialog returns Continue for user prompt - mock_command('whiptail', {'*': ('', '0')}, host) + # dialog returns Continue for user prompt + mock_command('dialog', {'*': ('', '0')}, host) package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect diff --git a/test/test_centos_8_support.py b/test/test_centos_8_support.py index 464055b412..9adbe841e4 100644 --- a/test/test_centos_8_support.py +++ b/test/test_centos_8_support.py @@ -29,8 +29,8 @@ def test_php_upgrade_user_optout_skipped_centos_gte_8(host): latest CentOS (should trigger on CentOS7 only) (php not currently installed) ''' - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '1')}, host) + # dialog dialog returns Cancel for user prompt + mock_command('dialog', {'*': ('', '1')}, host) package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect @@ -50,8 +50,8 @@ def test_php_upgrade_user_optin_skipped_centos_gte_8(host): latest CentOS (should trigger on CentOS7 only) (php not currently installed) ''' - # Whiptail dialog returns Continue for user prompt - mock_command('whiptail', {'*': ('', '0')}, host) + # dialog dialog returns Continue for user prompt + mock_command('dialog', {'*': ('', '0')}, host) package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index 80ca2a85a9..ac408e92f2 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -76,8 +76,8 @@ def test_php_version_lt_7_detected_upgrade_user_optout_centos(host): default_centos_php_version = php_package.version.split('.')[0] if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended pytest.skip("Test deprecated . Detected default PHP version >= 7") - # Whiptail dialog returns Cancel for user prompt - mock_command('whiptail', {'*': ('', '1')}, host) + # dialog returns Cancel for user prompt + mock_command('dialog', {'*': ('', '1')}, host) package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect @@ -101,8 +101,8 @@ def test_php_version_lt_7_detected_upgrade_user_optin_centos(host): default_centos_php_version = php_package.version.split('.')[0] if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended pytest.skip("Test deprecated . Detected default PHP version >= 7") - # Whiptail dialog returns Continue for user prompt - mock_command('whiptail', {'*': ('', '0')}, host) + # dialog returns Continue for user prompt + mock_command('dialog', {'*': ('', '0')}, host) package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect From 2845c72bde1aa741534d4cf7234203e39d52aff1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 2 Jul 2022 17:13:33 -0700 Subject: [PATCH 054/638] Add testing dependencies for CentOS7 and dialog Signed-off-by: Dan Schaper --- test/_centos_7.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/_centos_7.Dockerfile b/test/_centos_7.Dockerfile index 355f4fdb41..9542252572 100644 --- a/test/_centos_7.Dockerfile +++ b/test/_centos_7.Dockerfile @@ -1,5 +1,5 @@ FROM centos:7 -RUN yum install -y git +RUN yum install -y dialog git python3 ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From 6efb3a3372be2786c0ef14def511a25a572c22f0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 3 Jul 2022 11:40:31 -0700 Subject: [PATCH 055/638] Fix for epel mirror timeouts Signed-off-by: Dan Schaper --- test/_centos_7.Dockerfile | 1 + test/centos7.epel.override | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 test/centos7.epel.override diff --git a/test/_centos_7.Dockerfile b/test/_centos_7.Dockerfile index 355f4fdb41..f39f50e7f6 100644 --- a/test/_centos_7.Dockerfile +++ b/test/_centos_7.Dockerfile @@ -9,6 +9,7 @@ ADD . $GITDIR RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR +ADD test/centos7.epel.override /etc/yum/pluginconf.d/fastestmirror.conf RUN true && \ chmod +x $SCRIPTDIR/* diff --git a/test/centos7.epel.override b/test/centos7.epel.override new file mode 100644 index 0000000000..3451f17d4e --- /dev/null +++ b/test/centos7.epel.override @@ -0,0 +1,7 @@ +[main] +verbose = 0 +socket_timeout = 3 +enabled = 1 +hostfilepath = /var/cache/yum/timedhosts.txt +maxhostfileage = 1 +exclude=.edu From 44667b5ffb70ff72d3cdf4e3a3dcdde84427605f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 4 Jul 2022 12:35:08 -0700 Subject: [PATCH 056/638] Add dialog to RPM installer requirements. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f0a3396788..0e023215d1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -292,6 +292,9 @@ test_dpkg_lock() { # Compatibility package_manager_detect() { + # TODO - pull common packages for both distributions out into a common variable, then add + # the distro-specific ones below. + # First check to see if apt-get is installed. if is_command apt-get ; then # Set some global variables here @@ -355,7 +358,7 @@ package_manager_detect() { PKG_INSTALL=("${PKG_MANAGER}" install -y) 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) + INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl) LIGHTTPD_USER="lighttpd" From 72fcdb128a788adcfa74940611480d11d75cc6fa Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 4 Jul 2022 14:00:16 -0700 Subject: [PATCH 057/638] Rework cenos7 functions Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 157 +++++++++++++++-------------- 1 file changed, 80 insertions(+), 77 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0e023215d1..0cb0120607 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -356,7 +356,8 @@ package_manager_detect() { # These variable names match the ones for apt-get. See above for an explanation of what they are for. PKG_INSTALL=("${PKG_MANAGER}" install -y) - PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" + # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. + PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" OS_CHECK_DEPS=(grep bind-utils) INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat) @@ -407,16 +408,21 @@ select_rpm_php(){ PIHOLE_WEB_DEPS=("${CENTOS7_PIHOLE_WEB_DEPS[@]}") unset CENTOS7_PIHOLE_WEB_DEPS fi - # CentOS requires the EPEL repository to gain access to Fedora packages - if [[ CURRENT_CENTOS_VERSION -eq 7 ]]; then - EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" - elif [[ CURRENT_CENTOS_VERSION -eq 8 ]]; then - EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" + + if rpm -qa | grep -qi 'epel'; then + printf " %b EPEL repository already installed\\n" "${TICK}" + else + # CentOS requires the EPEL repository to gain access to Fedora packages + if [[ CURRENT_CENTOS_VERSION -eq 7 ]]; then + EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" + elif [[ CURRENT_CENTOS_VERSION -eq 8 ]]; then + EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" + fi + printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" + "${PKG_INSTALL[@]}" ${EPEL_PKG} + printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" fi - printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" - "${PKG_INSTALL[@]}" ${EPEL_PKG} &> /dev/null - printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" # The default php on CentOS 7.x is 5.4 which is EOL # Check if the version of PHP available via installed repositories is >= to PHP 7 @@ -424,38 +430,44 @@ select_rpm_php(){ if [[ $AVAILABLE_PHP_VERSION -ge $SUPPORTED_CENTOS_PHP_VERSION ]]; then # Since PHP 7 is available by default, install via default PHP package names : # do nothing as PHP is current + printf "PHP 7 is installed" else REMI_PKG="remi-release" REMI_REPO="remi-php72" - rpm -q ${REMI_PKG} &> /dev/null || rc=$? - if [[ $rc -ne 0 ]]; then - # The PHP version available via default repositories is older than version 7 - dialog --no-shadow --clear \ - --title "PHP 7 Update (recommended)" \ - --defaultno \ - --yesno "PHP 7.x is recommended for both security and language features.\ + REMI_REPO_URL="https://rpms.remirepo.net/enterprise/${REMI_PKG}-$(rpm -E '%{rhel}').rpm" + + # The PHP version available via default repositories is older than version 7 + dialog --no-shadow --keep-tite \ + --title "PHP 7 Update (recommended)" \ + --defaultno \ + --yesno "PHP 7.x is recommended for both security and language features.\ \\n\\nWould you like to install PHP7 via Remi's RPM repository?\ \\n\\nSee: https://rpms.remirepo.net for more information"\ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? - case ${result} in - # User chose to install PHP 7 via Remi's RPM repository - "${DIALOG_OK}") + case ${result} in + "${DIALOG_OK}" ) + printf " %b Installing PHP 7 via Remi's RPM repository\\n" "${INFO}" + "${PKG_INSTALL[@]}" "yum-utils" &> /dev/null + if rpm -q ${REMI_PKG} &> /dev/null; then + printf " %b Remi's RPM repository is already installed\\n" "${TICK}" + else printf " %b Enabling Remi's RPM repository (https://rpms.remirepo.net)\\n" "${INFO}" - "${PKG_INSTALL[@]}" "https://rpms.remirepo.net/enterprise/${REMI_PKG}-$(rpm -E '%{rhel}').rpm" &> /dev/null - # enable the PHP 7 repository via yum-config-manager (provided by yum-utils) - "${PKG_INSTALL[@]}" "yum-utils" &> /dev/null - yum-config-manager --enable ${REMI_REPO} &> /dev/null + yum -y install "${REMI_REPO_URL}" + printf " %b Installed %s from %s\\n" "${TICK}" "${REMI_PKG}" "${REMI_REPO_URL}" printf " %b Remi's RPM repository has been enabled for PHP7\\n" "${TICK}" - # trigger an install/update of PHP to ensure previous version of PHP is updated from REMI - if "${PKG_INSTALL[@]}" "php-cli" &> /dev/null; then - printf " %b PHP7 installed/updated via Remi's RPM repository\\n" "${TICK}" - else - printf " %b There was a problem updating to PHP7 via Remi's RPM repository\\n" "${CROSS}" - exit 1 - fi - ;; + fi + yum-config-manager --disable 'remi-php*' + yum-config-manager --enable "${REMI_REPO}" + + # trigger an install/update of PHP to ensure previous version of PHP is updated from REMI + if "${PKG_INSTALL[@]}" "php-cli" &> /dev/null; then + printf " %b PHP7 installed/updated via Remi's RPM repository\\n" "${TICK}" + else + printf " %b There was a problem updating to PHP7 via Remi's RPM repository\\n" "${CROSS}" + exit 1 + fi + ;; # User chose not to install PHP 7 via Remi's RPM repository "${DIALOG_CANCEL}") @@ -471,8 +483,9 @@ select_rpm_php(){ esac fi + else # Warn user of unsupported version of Fedora or CentOS - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --title "Unsupported RPM based distribution" \ --defaultno \ --no-button "Exit" \ @@ -480,9 +493,8 @@ select_rpm_php(){ --yesno "Would you like to continue installation on an unsupported RPM based distribution?\ \\n\\nPlease ensure the following packages have been installed manually:\ \\n\\n- lighttpd\\n- lighttpd-fastcgi\\n- PHP version 7+"\ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in # User chose to continue installation on an unsupported RPM based distribution "${DIALOG_OK}") @@ -498,7 +510,6 @@ select_rpm_php(){ exit 1 ;; esac - fi fi } @@ -689,17 +700,17 @@ get_available_interfaces() { # A function for displaying the dialogs the user sees when first running the installer welcomeDialogs() { # Display the welcome dialog using an appropriately sized window via the calculation conducted earlier in the script - dialog --no-shadow --clear \ + dialog --no-shadow --clear --keep-tite \ --backtitle "Welcome" \ --title "Pi-hole Automated Installer" \ --msgbox "\\n\\nThis installer will transform your device into a network-wide ad blocker!" \ "${r}" "${c}" \ - --and-widget \ + --and-widget --clear \ --backtitle "Support Pi-hole" \ --title "Open Source Software" \ --msgbox "\\n\\nThe Pi-hole is free, but powered by your donations: https://pi-hole.net/donate/" \ "${r}" "${c}" \ - --and-widget \ + --and-widget --clear \ --colors \ --backtitle "Initiating network interface" \ --title "Static IP Needed" \ @@ -709,9 +720,8 @@ welcomeDialogs() { \\Zb\\Z1IMPORTANT:\\Zn If you have not already done so, you must ensure that this device has a static IP.\\n\\n\ Depending on your operating system, there are many ways to achieve this, through DHCP reservation, or by manually assigning one.\\n\\n\ Please continue when the static addressing has been configured."\ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result="$?" - result=$? case "${result}" in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") printf " %b Installer exited at static IP message.\\n" "${INFO}" @@ -748,7 +758,7 @@ chooseInterface() { done # shellcheck disable=SC2086 # Disable check for double quote here as we are passing a string with spaces - PIHOLE_INTERFACE=$(dialog --no-shadow --clear --output-fd 1 \ + PIHOLE_INTERFACE=$(dialog --no-shadow --keep-tite --output-fd 1 \ --radiolist "Choose An Interface (press space to toggle selection)" \ ${r} ${c} "${interfaceCount}" ${interfacesList}) @@ -848,7 +858,7 @@ getStaticIPv4Settings() { local DHCPChoice # Ask if the user wants to use DHCP settings as their static IP # This is useful for users that are using DHCP reservations; we can use the information gathered - DHCPChoice=$(dialog --no-shadow --clear --output-fd 1 \ + DHCPChoice=$(dialog --no-shadow --keep-tite --output-fd 1 \ --backtitle "Calibrating network interface" \ --title "Static IP Address" \ --menu "Do you want to use your current network settings as a static address?\\n \ @@ -873,16 +883,15 @@ getStaticIPv4Settings() { ;; "Yes") # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --backtitle "IP information" \ --title "FYI: IP Conflict" \ --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict\ But in most cases the router is smart enough to not do that.\ If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.\ It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."\ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" @@ -899,7 +908,7 @@ It is also possible to use a DHCP reservation, but if you are going to do that, until [[ "${ipSettingsCorrect}" = True ]]; do # Ask for the IPv4 address - _staticIPv4Temp=$(dialog --no-shadow --clear --output-fd 1 \ + _staticIPv4Temp=$(dialog --no-shadow --keep-tite --output-fd 1 \ --backtitle "Calibrating network interface" \ --title "IPv4 Address" \ --form "\\nEnter your desired IPv4 address" \ @@ -919,16 +928,15 @@ It is also possible to use a DHCP reservation, but if you are going to do that, IPv4gw=${_staticIPv4Temp#*$'\n'} # Give the user a chance to review their settings before moving on - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --backtitle "Calibrating network interface" \ --title "Static IP Address" \ --defaultno \ --yesno "Are these settings correct? IP address: ${IPV4_ADDRESS} Gateway: ${IPv4gw}" \ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_OK}") # After that's done, the loop ends and we move on @@ -1033,7 +1041,7 @@ setDNS() { # Restore the IFS to what it was IFS=${OIFS} # In a dialog, show the options - DNSchoices=$(dialog --no-shadow --clear --output-fd 1 \ + DNSchoices=$(dialog --no-shadow --keep-tite --output-fd 1 \ --menu "Select Upstream DNS Provider. To use your own, select Custom." "${r}" "${c}" 7 \ "${DNSChooseOptions[@]}") @@ -1067,7 +1075,7 @@ setDNS() { fi # Prompt the user to enter custom upstream servers - piholeDNS=$(dialog --no-shadow --clear --output-fd 1 \ + piholeDNS=$(dialog --no-shadow --keep-tite --output-fd 1 \ --backtitle "Specify Upstream DNS Provider(s)" \ --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\ If you want to specify a port other than 53, separate it with a hash.\ @@ -1100,14 +1108,13 @@ If you want to specify a port other than 53, separate it with a hash.\ # If either of the DNS servers are invalid, if [[ "${PIHOLE_DNS_1}" == "${strInvalid}" ]] || [[ "${PIHOLE_DNS_2}" == "${strInvalid}" ]]; then # explain this to the user, - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --title "Invalid IP Address(es)" \ --backtitle "Invalid IP" \ --msgbox "\\nOne or both of the entered IP addresses were invalid. Please try again.\ \\n\\nInvalid IPs: ${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}" \ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" @@ -1125,13 +1132,12 @@ If you want to specify a port other than 53, separate it with a hash.\ # and continue the loop. DNSSettingsCorrect=False else - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --backtitle "Specify Upstream DNS Provider(s)" \ --title "Upstream DNS Provider(s)" \ --yesno "Are these settings correct?\\n\\tDNS Server 1:\\t${PIHOLE_DNS_1}\\n\\tDNS Server 2:\\t${PIHOLE_DNS_2}" \ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_OK}") DNSSettingsCorrect=True @@ -1174,13 +1180,12 @@ If you want to specify a port other than 53, separate it with a hash.\ # Allow the user to enable/disable logging setLogging() { # Ask the user if they want to enable logging - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --backtitle "Pihole Installation" \ --title "Enable Logging" \ --yesno "\\n\\nWould you like to enable query logging?" \ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_OK}") # If they chose yes, @@ -1203,7 +1208,7 @@ setLogging() { # Allow the user to set their FTL privacy level setPrivacyLevel() { # The default selection is level 0 - PRIVACY_LEVEL=$(dialog --no-shadow --clear --output-fd 1 \ + PRIVACY_LEVEL=$(dialog --no-shadow --keep-tite --output-fd 1 \ --radiolist "Select a privacy mode for FTL. https://docs.pi-hole.net/ftldns/privacylevels/" \ "${r}" "${c}" 6 \ "0" "Show everything" on \ @@ -1226,13 +1231,12 @@ setPrivacyLevel() { # Function to ask the user if they want to install the dashboard setAdminFlag() { # Similar to the logging function, ask what the user wants - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --backtitle "Pihole Installation" \ --title "Admin Web Interface" \ --yesno "\\n\\nDo you want to install the Admin Web Interface?" \ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_OK}") # If they chose yes, @@ -1259,7 +1263,7 @@ setAdminFlag() { # Get list of required PHP modules, excluding base package (common) and handler (cgi) local i php_modules for i in "${PIHOLE_WEB_DEPS[@]}"; do [[ $i == 'php'* && $i != *'-common' && $i != *'-cgi' ]] && php_modules+=" ${i#*-}"; done - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --backtitle "Pi-hole Installation" \ --title "Web Server" \ --yesno "\\n\\nA web server is required for the Admin Web Interface.\ @@ -1268,9 +1272,8 @@ setAdminFlag() { and required PHP modules (${php_modules# }) installed, the web interface\ will not function. Additionally the web server user needs to be member of\ the \"pihole\" group for full functionality." \ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_OK}") # If they chose yes, @@ -1300,16 +1303,15 @@ chooseBlocklists() { mv "${adlistFile}" "${adlistFile}.old" fi # Let user select (or not) blocklists - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --backtitle "Pi-hole Installation" \ --title "Blocklists" \ --yesno "\\nPi-hole relies on third party lists in order to block ads.\ \\n\\nYou can use the suggestion below, and/or add your own after installation.\ \\n\\nSelect 'Yes' to include:\ \\n\\nStevenBlack's Unified Hosts List" \ - "${r}" "${c}" + "${r}" "${c}" && result=0 || result=$? - result=$? case ${result} in "${DIALOG_OK}") # If they chose yes, @@ -2113,7 +2115,7 @@ Your Admin Webpage login password is ${pwstring}" fi # Final completion message to user - dialog --no-shadow --clear \ + dialog --no-shadow --keep-tite \ --title "Installation Complete!" \ --msgbox "Configure your devices to use the Pi-hole as their DNS server using:\ \\n\\nIPv4: ${IPV4_ADDRESS%/*}\ @@ -2140,14 +2142,14 @@ update_dialogs() { opt2b="Resets Pi-hole and allows re-selecting settings." # Display the information to the user - UpdateCmd=$(dialog --no-shadow --clear --output-fd 1 \ + UpdateCmd=$(dialog --no-shadow --keep-tite --output-fd 1 \ --title "Existing Install Detected!" \ --menu "\\n\\nWe have detected an existing install.\ \\n\\nPlease choose from the following options:\ \\n($strAdd)"\ "${r}" "${c}" 2 \ "${opt1a}" "${opt1b}" \ - "${opt2a}" "${opt2b}") + "${opt2a}" "${opt2b}" || true) result=$? case ${result} in @@ -2634,6 +2636,9 @@ main() { fi fi + # Check if SELinux is Enforcing and exit before doing anything else + checkSelinux + # Check for supported package managers so that we may install dependencies package_manager_detect @@ -2656,8 +2661,6 @@ main() { select_rpm_php fi - # Check if SELinux is Enforcing - checkSelinux # If the setup variable file exists, if [[ -f "${setupVars}" ]]; then From a39c470f2dd5881856e081abf297237510142e6a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 5 Jul 2022 00:06:12 -0700 Subject: [PATCH 058/638] Requested changes. Co-authored-by: MichaIng Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0cb0120607..0728900ece 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1268,9 +1268,9 @@ setAdminFlag() { --title "Web Server" \ --yesno "\\n\\nA web server is required for the Admin Web Interface.\ \\n\\nDo you want to install lighttpd and the required PHP modules?\ -\\n\\nNB: If you disable this, and, do not have an existing web server\ -and required PHP modules (${php_modules# }) installed, the web interface\ -will not function. Additionally the web server user needs to be member of\ +\\n\\nNB: If you disable this, and, do not have an existing web server \ +and required PHP modules (${php_modules# }) installed, the web interface \ +will not function. Additionally the web server user needs to be member of \ the \"pihole\" group for full functionality." \ "${r}" "${c}" && result=0 || result=$? From c058a511e6576b4154ac42a51a1d98a2b60e77cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 5 Jul 2022 10:15:18 +0200 Subject: [PATCH 059/638] Fix close-issue-reason MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 3f54c1a5f7..b9c4d8c1d0 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -23,4 +23,4 @@ jobs: exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed' exempt-all-issue-assignees: true operations-per-run: 300 - stale-issue-reason: 'not_planned' + close-issue-reason: 'not_planned' From 39cb1029e9ae804cd1912fc1a84048814e5ab830 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 5 Jul 2022 14:23:59 -0700 Subject: [PATCH 060/638] Clarify button labels Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 33 ++++++++++++------------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0728900ece..c3ff87cfff 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -759,6 +759,7 @@ chooseInterface() { # shellcheck disable=SC2086 # Disable check for double quote here as we are passing a string with spaces PIHOLE_INTERFACE=$(dialog --no-shadow --keep-tite --output-fd 1 \ + --cancel-label "Exit" --ok-label "Select" \ --radiolist "Choose An Interface (press space to toggle selection)" \ ${r} ${c} "${interfaceCount}" ${interfacesList}) @@ -859,6 +860,7 @@ getStaticIPv4Settings() { # Ask if the user wants to use DHCP settings as their static IP # This is useful for users that are using DHCP reservations; we can use the information gathered DHCPChoice=$(dialog --no-shadow --keep-tite --output-fd 1 \ + --cancel-label "Exit" --ok-label "Continue" \ --backtitle "Calibrating network interface" \ --title "Static IP Address" \ --menu "Do you want to use your current network settings as a static address?\\n \ @@ -884,6 +886,7 @@ getStaticIPv4Settings() { "Yes") # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. dialog --no-shadow --keep-tite \ + --cancel-label "Exit" \ --backtitle "IP information" \ --title "FYI: IP Conflict" \ --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict\ @@ -909,6 +912,8 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Ask for the IPv4 address _staticIPv4Temp=$(dialog --no-shadow --keep-tite --output-fd 1 \ + --cancer-label "Exit" \ + --ok-label "Continue" \ --backtitle "Calibrating network interface" \ --title "IPv4 Address" \ --form "\\nEnter your desired IPv4 address" \ @@ -929,24 +934,14 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Give the user a chance to review their settings before moving on dialog --no-shadow --keep-tite \ + --no-label "Edit IP" \ --backtitle "Calibrating network interface" \ --title "Static IP Address" \ --defaultno \ --yesno "Are these settings correct? IP address: ${IPV4_ADDRESS} Gateway: ${IPv4gw}" \ - "${r}" "${c}" && result=0 || result=$? - - case ${result} in - "${DIALOG_OK}") - # After that's done, the loop ends and we move on - ipSettingsCorrect=True - ;; - "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" - exit 1 - ;; - esac + "${r}" "${c}" && ipSettingsCorrect=True done ;; esac @@ -1042,6 +1037,7 @@ setDNS() { IFS=${OIFS} # In a dialog, show the options DNSchoices=$(dialog --no-shadow --keep-tite --output-fd 1 \ + --cancel-label "Exit" \ --menu "Select Upstream DNS Provider. To use your own, select Custom." "${r}" "${c}" 7 \ "${DNSChooseOptions[@]}") @@ -1076,6 +1072,7 @@ setDNS() { # Prompt the user to enter custom upstream servers piholeDNS=$(dialog --no-shadow --keep-tite --output-fd 1 \ + --cancel-label "Exit" \ --backtitle "Specify Upstream DNS Provider(s)" \ --inputbox "Enter your desired upstream DNS provider(s), separated by a comma.\ If you want to specify a port other than 53, separate it with a hash.\ @@ -1113,14 +1110,7 @@ If you want to specify a port other than 53, separate it with a hash.\ --backtitle "Invalid IP" \ --msgbox "\\nOne or both of the entered IP addresses were invalid. Please try again.\ \\n\\nInvalid IPs: ${PIHOLE_DNS_1}, ${PIHOLE_DNS_2}" \ - "${r}" "${c}" && result=0 || result=$? - - case ${result} in - "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" - exit 1 - ;; - esac + "${r}" "${c}" # set the variables back to nothing, if [[ "${PIHOLE_DNS_1}" == "${strInvalid}" ]]; then @@ -1209,6 +1199,8 @@ setLogging() { setPrivacyLevel() { # The default selection is level 0 PRIVACY_LEVEL=$(dialog --no-shadow --keep-tite --output-fd 1 \ + --cancel-label "Exit" \ + --ok-label "Continue" \ --radiolist "Select a privacy mode for FTL. https://docs.pi-hole.net/ftldns/privacylevels/" \ "${r}" "${c}" 6 \ "0" "Show everything" on \ @@ -2143,6 +2135,7 @@ update_dialogs() { # Display the information to the user UpdateCmd=$(dialog --no-shadow --keep-tite --output-fd 1 \ + --cancel-label Exit \ --title "Existing Install Detected!" \ --menu "\\n\\nWe have detected an existing install.\ \\n\\nPlease choose from the following options:\ From ad70ece73e541f576cf5cbdc8f36778f3a4185a4 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 5 Jul 2022 23:10:40 -0300 Subject: [PATCH 061/638] Fixing dialog line breaks Signed-off-by: RD WebDesign --- automated install/basic-install.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c3ff87cfff..18c4a068db 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2101,9 +2101,7 @@ displayFinalMessage() { # If the user wants to install the dashboard, if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then # Store a message in a variable and display it - additional="View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin - -Your Admin Webpage login password is ${pwstring}" + additional="View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin\\n\\nYour Admin Webpage login password is ${pwstring}" fi # Final completion message to user @@ -2113,8 +2111,7 @@ Your Admin Webpage login password is ${pwstring}" \\n\\nIPv4: ${IPV4_ADDRESS%/*}\ \\nIPv6: ${IPV6_ADDRESS:-"Not Configured"}\ \\nIf you have not done so already, the above IP should be set to static.\ -\\n${additional}" - "${r}" "${c}" +\\n${additional}" "${r}" "${c}" } update_dialogs() { From 46f991f578ade00749ed0acd76a62f50fb0f588b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 5 Jul 2022 20:11:00 -0700 Subject: [PATCH 062/638] Apply suggestions from code review Co-authored-by: yubiuser Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 18c4a068db..47749c5f13 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1179,12 +1179,12 @@ setLogging() { case ${result} in "${DIALOG_OK}") # If they chose yes, - printf " %b Query Logging on.\\n" "${INFO}" + printf " %b Query Logging on.\\n" "${INFO}" QUERY_LOGGING=true ;; "${DIALOG_CANCEL}") # If they chose no, - printf " %b Query Logging off.\\n" "${INFO}" + printf " %b Query Logging off.\\n" "${INFO}" QUERY_LOGGING=false ;; "${DIALOG_ESC}") @@ -1232,13 +1232,13 @@ setAdminFlag() { case ${result} in "${DIALOG_OK}") # If they chose yes, - printf " %b Installing Admin Web Interface\\n" "${INFO}" + printf " %b Installing Admin Web Interface\\n" "${INFO}" # Set the flag to install the web interface INSTALL_WEB_INTERFACE=true ;; "${DIALOG_CANCEL}") # If they chose no, - printf " %b Not installing Admin Web Interface\\n" "${INFO}" + printf " %b Not installing Admin Web Interface\\n" "${INFO}" # Set the flag to not install the web interface INSTALL_WEB_INTERFACE=false INSTALL_WEB_SERVER=false @@ -1269,13 +1269,13 @@ the \"pihole\" group for full functionality." \ case ${result} in "${DIALOG_OK}") # If they chose yes, - printf " %b Installing lighttpd\\n" "${INFO}" + printf " %b Installing lighttpd\\n" "${INFO}" # Set the flag to install the web server INSTALL_WEB_SERVER=true ;; "${DIALOG_CANCEL}") # If they chose no, - printf " %b Not installing lighttpd\\n" "${INFO}" + printf " %b Not installing lighttpd\\n" "${INFO}" # Set the flag to not install the web server INSTALL_WEB_SERVER=false ;; @@ -1307,12 +1307,12 @@ chooseBlocklists() { case ${result} in "${DIALOG_OK}") # If they chose yes, - printf " %b Installing StevenBlack's Unified Hosts List\\n" "${INFO}" + printf " %b Installing StevenBlack's Unified Hosts List\\n" "${INFO}" echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >> "${adlistFile}" ;; "${DIALOG_CANCEL}") # If they chose no, - printf " %b Not installing StevenBlack's Unified Hosts List\\n" "${INFO}" + printf " %b Not installing StevenBlack's Unified Hosts List\\n" "${INFO}" ;; "${DIALOG_ESC}") # User pressed From cfbc731eab83f8ad351f644b07902f00d33c712f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 5 Jul 2022 20:25:27 -0700 Subject: [PATCH 063/638] Apply suggestions from code review Co-authored-by: yubiuser Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 47749c5f13..3e18f8de11 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1136,7 +1136,7 @@ If you want to specify a port other than 53, separate it with a hash.\ DNSSettingsCorrect=False ;; "${DIALOG_ESC}") - printf " %bEscape pressed, exiting installer at DNS Settings%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Escape pressed, exiting installer at DNS Settings%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -1189,7 +1189,7 @@ setLogging() { ;; "${DIALOG_ESC}") # User pressed - printf " %bEscape pressed, exiting installer at Query Logging choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Escape pressed, exiting installer at Query Logging choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -1245,7 +1245,7 @@ setAdminFlag() { ;; "${DIALOG_ESC}") # User pressed - printf " %bEscape pressed, exiting installer at Admin Web Interface choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Escape pressed, exiting installer at Admin Web Interface choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -1281,7 +1281,7 @@ the \"pihole\" group for full functionality." \ ;; "${DIALOG_ESC}") # User pressed - printf " %bEscape pressed, exiting installer at web server choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Escape pressed, exiting installer at web server choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -1316,7 +1316,7 @@ chooseBlocklists() { ;; "${DIALOG_ESC}") # User pressed - printf " %bEscape pressed, exiting installer at blocklist choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Escape pressed, exiting installer at blocklist choice.%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac From 5c564e53cac899cd0032b3a0092c5a47409438d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 6 Jul 2022 12:29:03 +0200 Subject: [PATCH 064/638] Fix indention in install script output 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 | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index eb03968096..9680e9f946 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -874,7 +874,7 @@ getStaticIPv4Settings() { result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -897,7 +897,7 @@ It is also possible to use a DHCP reservation, but if you are going to do that, case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -924,7 +924,7 @@ It is also possible to use a DHCP reservation, but if you are going to do that, result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -1044,7 +1044,7 @@ setDNS() { result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -1082,7 +1082,7 @@ If you want to specify a port other than 53, separate it with a hash.\ result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -1491,7 +1491,7 @@ installConfigs() { if [[ ! -r "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then install -d -m 0755 ${PI_HOLE_CONFIG_DIR} if ! install -T -o pihole -m 664 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.conf" "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then - printf " %bError: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" + printf " %b Error: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" return 1 fi fi @@ -1499,7 +1499,7 @@ installConfigs() { # Install empty custom.list file if it does not exist if [[ ! -r "${PI_HOLE_CONFIG_DIR}/custom.list" ]]; then if ! install -o root -m 644 /dev/null "${PI_HOLE_CONFIG_DIR}/custom.list" &>/dev/null; then - printf " %bError: Unable to initialize configuration file %s/custom.list\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" + printf " %b Error: Unable to initialize configuration file %s/custom.list\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" return 1 fi fi @@ -1659,7 +1659,7 @@ disable_resolved_stublistener() { # Check if Systemd-resolved's DNSStubListener is enabled and active on port 53 if check_service_active "systemd-resolved"; then # Check if DNSStubListener is enabled - printf " %b %b Testing if systemd-resolved DNSStub-Listener is active" "${OVER}" "${INFO}" + printf " %b %b Testing if systemd-resolved DNSStub-Listener is active" "${OVER}" "${INFO}" if ( grep -E '#?DNSStubListener=yes' /etc/systemd/resolved.conf &> /dev/null ); then # Disable the DNSStubListener to unbind it from port 53 # Note that this breaks dns functionality on host until dnsmasq/ftl are up and running @@ -1696,7 +1696,7 @@ update_package_cache() { UPDATE_PKG_CACHE="apt update" fi printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" - printf " %bError: Unable to update package cache. Please try \"%s\"%b\\n" "${COL_LIGHT_RED}" "sudo ${UPDATE_PKG_CACHE}" "${COL_NC}" + printf " %b Error: Unable to update package cache. Please try \"%s\"%b\\n" "${COL_LIGHT_RED}" "sudo ${UPDATE_PKG_CACHE}" "${COL_NC}" return 1 fi } @@ -2144,7 +2144,7 @@ update_dialogs() { result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") - printf " %bCancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" + printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" exit 1 ;; esac @@ -2253,14 +2253,14 @@ clone_or_update_repos() { printf " %b Performing reconfiguration, skipping download of local repos\\n" "${INFO}" # Reset the Core repo resetRepo ${PI_HOLE_LOCAL_REPO} || \ - { printf " %bUnable to reset %s, exiting installer%b\\n" "${COL_LIGHT_RED}" "${PI_HOLE_LOCAL_REPO}" "${COL_NC}"; \ + { printf " %b Unable to reset %s, exiting installer%b\\n" "${COL_LIGHT_RED}" "${PI_HOLE_LOCAL_REPO}" "${COL_NC}"; \ exit 1; \ } # If the Web interface was installed, if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then # reset it's repo resetRepo ${webInterfaceDir} || \ - { printf " %bUnable to reset %s, exiting installer%b\\n" "${COL_LIGHT_RED}" "${webInterfaceDir}" "${COL_NC}"; \ + { printf " %b Unable to reset %s, exiting installer%b\\n" "${COL_LIGHT_RED}" "${webInterfaceDir}" "${COL_NC}"; \ exit 1; \ } fi @@ -2268,14 +2268,14 @@ clone_or_update_repos() { else # so get git files for Core getGitFiles ${PI_HOLE_LOCAL_REPO} ${piholeGitUrl} || \ - { printf " %bUnable to clone %s into %s, unable to continue%b\\n" "${COL_LIGHT_RED}" "${piholeGitUrl}" "${PI_HOLE_LOCAL_REPO}" "${COL_NC}"; \ + { printf " %b Unable to clone %s into %s, unable to continue%b\\n" "${COL_LIGHT_RED}" "${piholeGitUrl}" "${PI_HOLE_LOCAL_REPO}" "${COL_NC}"; \ exit 1; \ } # If the Web interface was installed, if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then # get the Web git files getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} || \ - { printf " %bUnable to clone %s into ${webInterfaceDir}, exiting installer%b\\n" "${COL_LIGHT_RED}" "${webInterfaceGitUrl}" "${COL_NC}"; \ + { printf " %b Unable to clone %s into ${webInterfaceDir}, exiting installer%b\\n" "${COL_LIGHT_RED}" "${webInterfaceGitUrl}" "${COL_NC}"; \ exit 1; \ } fi @@ -2339,7 +2339,7 @@ FTLinstall() { # Otherwise, the hash download failed, so print and exit. popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; } printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" - printf " %bError: Download of %s/%s failed (checksum error)%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}" + printf " %b Error: Download of %s/%s failed (checksum error)%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}" return 1 fi else @@ -2347,7 +2347,7 @@ FTLinstall() { popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; } printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" # The URL could not be found - printf " %bError: URL %s/%s not found%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}" + printf " %b Error: URL %s/%s not found%b\\n" "${COL_LIGHT_RED}" "${url}" "${binary}" "${COL_NC}" return 1 fi } From 469776afd6abd9055a2deddd159114baf9774607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 6 Jul 2022 19:27:16 +0200 Subject: [PATCH 065/638] Do not restrict RegEx added from CLI by length MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/list.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index f3f97da26f..b76a7ef7ac 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -100,21 +100,29 @@ Options: ValidateDomain() { # Convert to lowercase domain="${1,,}" + local str validDomain # Check validity of domain (don't check for regex entries) - if [[ "${#domain}" -le 253 ]]; then - if [[ ( "${typeId}" == "${regex_blacklist}" || "${typeId}" == "${regex_whitelist}" ) && "${wildcard}" == false ]]; then - validDomain="${domain}" - else + if [[ ( "${typeId}" == "${regex_blacklist}" || "${typeId}" == "${regex_whitelist}" ) && "${wildcard}" == false ]]; then + validDomain="${domain}" + else + # Check max length + if [[ "${#domain}" -le 253 ]]; then validDomain=$(grep -P "^((-|_)*[a-z\\d]((-|_)*[a-z\\d])*(-|_)*)(\\.(-|_)*([a-z\\d]((-|_)*[a-z\\d])*))*$" <<< "${domain}") # Valid chars check validDomain=$(grep -P "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$" <<< "${validDomain}") # Length of each label + # set error string + str="is not a valid argument or domain name!" + else + validDomain= + str="is too long!" + fi fi if [[ -n "${validDomain}" ]]; then domList=("${domList[@]}" "${validDomain}") else - echo -e " ${CROSS} ${domain} is not a valid argument or domain name!" + echo -e " ${CROSS} ${domain} ${str}" fi domaincount=$((domaincount+1)) From 0a8761ee68c4d6b79201d52793dd4d1aefe60e7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 6 Jul 2022 22:51:39 +0200 Subject: [PATCH 066/638] Rename PH_TEST to SKIP_INSTALL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 4 ++-- automated install/basic-install.sh | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 279de9e939..29c53bd671 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -24,8 +24,8 @@ readonly gravityDBfile="/etc/pihole/gravity.db" # Source install script for ${setupVars}, ${PI_HOLE_BIN_DIR} and valid_ip() readonly PI_HOLE_FILES_DIR="/etc/.pihole" -# shellcheck disable=SC2034 # used in basic-install -PH_TEST="true" +# shellcheck disable=SC2034 # used in basic-install to source the script without running it +SKIP_INSTALL="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" utilsfile="/opt/pihole/utils.sh" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9680e9f946..91f7f3927a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2860,6 +2860,8 @@ main() { fi } -if [[ "${PH_TEST}" != true ]] ; then +# allow to source this script without running it +# used in docker-pihole and webpage.sh +if [[ "${SKIP_INSTALL}" != true ]] ; then main "$@" fi From 518cbd10e0858c642be97b67af67b1598991e38d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 6 Jul 2022 22:58:14 +0200 Subject: [PATCH 067/638] Rename also in docker files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeCheckout.sh | 2 +- advanced/Scripts/update.sh | 2 +- automated install/basic-install.sh | 1 - automated install/uninstall.sh | 2 +- test/_centos_7.Dockerfile | 2 +- test/_centos_8.Dockerfile | 2 +- test/_debian_10.Dockerfile | 2 +- test/_debian_11.Dockerfile | 2 +- test/_fedora_34.Dockerfile | 2 +- test/_ubuntu_18.Dockerfile | 2 +- test/_ubuntu_20.Dockerfile | 2 +- test/_ubuntu_21.Dockerfile | 2 +- test/_ubuntu_22.Dockerfile | 2 +- 13 files changed, 12 insertions(+), 13 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 4c0a4f4042..7c4a1f77a8 100755 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,7 +9,7 @@ # Please see LICENSE file for your rights under this license. readonly PI_HOLE_FILES_DIR="/etc/.pihole" -PH_TEST="true" +SKIP_INSTALL="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # webInterfaceGitUrl set in basic-install.sh diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 9da85c89d7..609a054b56 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -17,7 +17,7 @@ readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_FILES_DIR="/etc/.pihole" # shellcheck disable=SC2034 -PH_TEST=true +SKIP_INSTALL=true # when --check-only is passed to this script, it will not perform the actual update CHECK_ONLY=false diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 91f7f3927a..047be76ed3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2861,7 +2861,6 @@ main() { } # allow to source this script without running it -# used in docker-pihole and webpage.sh if [[ "${SKIP_INSTALL}" != true ]] ; then main "$@" fi diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index a0bb2e5b00..a58ad7536d 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -36,7 +36,7 @@ else fi readonly PI_HOLE_FILES_DIR="/etc/.pihole" -PH_TEST="true" +SKIP_INSTALL="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # setupVars set in basic-install.sh source "${setupVars}" diff --git a/test/_centos_7.Dockerfile b/test/_centos_7.Dockerfile index ccffc00d7b..b97f167980 100644 --- a/test/_centos_7.Dockerfile +++ b/test/_centos_7.Dockerfile @@ -13,7 +13,7 @@ ADD test/centos7.epel.override /etc/yum/pluginconf.d/fastestmirror.conf RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_centos_8.Dockerfile b/test/_centos_8.Dockerfile index 86e5a7787d..2a89458719 100644 --- a/test/_centos_8.Dockerfile +++ b/test/_centos_8.Dockerfile @@ -12,7 +12,7 @@ ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_debian_10.Dockerfile b/test/_debian_10.Dockerfile index 54800d3c47..3b177cc89a 100644 --- a/test/_debian_10.Dockerfile +++ b/test/_debian_10.Dockerfile @@ -11,7 +11,7 @@ ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_debian_11.Dockerfile b/test/_debian_11.Dockerfile index 39be027eac..58c67e0f4d 100644 --- a/test/_debian_11.Dockerfile +++ b/test/_debian_11.Dockerfile @@ -11,7 +11,7 @@ ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_fedora_34.Dockerfile b/test/_fedora_34.Dockerfile index fbbaacd6da..9c90ce7d7b 100644 --- a/test/_fedora_34.Dockerfile +++ b/test/_fedora_34.Dockerfile @@ -12,7 +12,7 @@ ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_ubuntu_18.Dockerfile b/test/_ubuntu_18.Dockerfile index 592c5c3fba..47f1893e72 100644 --- a/test/_ubuntu_18.Dockerfile +++ b/test/_ubuntu_18.Dockerfile @@ -11,7 +11,7 @@ ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_ubuntu_20.Dockerfile b/test/_ubuntu_20.Dockerfile index 80e2e0071d..c63f883aad 100644 --- a/test/_ubuntu_20.Dockerfile +++ b/test/_ubuntu_20.Dockerfile @@ -12,7 +12,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_ubuntu_21.Dockerfile b/test/_ubuntu_21.Dockerfile index 6d4d7fbc3a..05801de850 100644 --- a/test/_ubuntu_21.Dockerfile +++ b/test/_ubuntu_21.Dockerfile @@ -12,7 +12,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_ubuntu_22.Dockerfile b/test/_ubuntu_22.Dockerfile index f9876d5037..d44518b4e1 100644 --- a/test/_ubuntu_22.Dockerfile +++ b/test/_ubuntu_22.Dockerfile @@ -12,7 +12,7 @@ ENV DEBIAN_FRONTEND=noninteractive RUN true && \ chmod +x $SCRIPTDIR/* -ENV PH_TEST true +ENV SKIP_INSTALL true ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net #sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ From edba325a3eb8f654d9b881c711ce9b9d9d3a3058 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 7 Jul 2022 19:05:27 +0100 Subject: [PATCH 068/638] Disable line length rule for yamllint - fix indentation in stale.yml Signed-off-by: Adam Warner --- .github/workflows/stale.yml | 22 +++++++++++----------- .stickler.yml | 1 + .yamllint.conf | 3 +++ 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 .yamllint.conf diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index b9c4d8c1d0..cd3c6ff6f4 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,14 +13,14 @@ jobs: issues: write steps: - - uses: actions/stale@v5 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - days-before-stale: 30 - days-before-close: 5 - stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.' - stale-issue-label: 'stale' - exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed' - exempt-all-issue-assignees: true - operations-per-run: 300 - close-issue-reason: 'not_planned' + - uses: actions/stale@v5 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + days-before-stale: 30 + days-before-close: 5 + stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.' + stale-issue-label: 'stale' + exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed' + exempt-all-issue-assignees: true + operations-per-run: 300 + close-issue-reason: 'not_planned' diff --git a/.stickler.yml b/.stickler.yml index f094069689..5fdbbf1ec1 100644 --- a/.stickler.yml +++ b/.stickler.yml @@ -6,4 +6,5 @@ linters: flake8: max-line-length: 120 yamllint: + config: ./.yamllint.conf remarklint: diff --git a/.yamllint.conf b/.yamllint.conf new file mode 100644 index 0000000000..d1b0953bdf --- /dev/null +++ b/.yamllint.conf @@ -0,0 +1,3 @@ +rules: + line-length: disable + document-start: disable From fd41801977746ee1b3845bd8908b4315784f384b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 7 Jul 2022 12:12:53 -0700 Subject: [PATCH 069/638] Create new log directory Signed-off-by: Dan Schaper --- 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 3f5c972f68..86f8c6c6ce 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2619,6 +2619,7 @@ main() { stop_service pihole-FTL &> /dev/null if [ -f /var/log/pihole.log ] && [ ! -L /var/log/pihole.log ]; then + mkdir -p /var/log/pihole/ mv /var/log/pihole*.* /var/log/pihole/ 2>/dev/null fi From 48d5d6bed2d1fe615ad42871b1b4315d261dd2bc Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 7 Jul 2022 13:23:13 -0700 Subject: [PATCH 070/638] Always create the log target directory before any movements Signed-off-by: Dan Schaper --- 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 939f4b452a..fa8934c43d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2796,6 +2796,11 @@ main() { stop_service pihole-FTL &> /dev/null + if [ -d /var/log/pihole/ ]; then + mkdir /var/log/pihole/ + chmod 0775 /var/log/pihole/ + fi + # Special handling for pihole-FTL.log -> pihole/FTL.log if [ -f /var/log/pihole-FTL.log ] && [ ! -L /var/log/pihole-FTL.log ]; then # /var/log/pihole-FTL.log -> /var/log/pihole/FTL.log From 56a32047b8e08e7520fae6915dc20f837dead50b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 7 Jul 2022 13:50:41 -0700 Subject: [PATCH 071/638] Logic fix Signed-off-by: Dan Schaper --- 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 fa8934c43d..a0a98b68c2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2796,7 +2796,7 @@ main() { stop_service pihole-FTL &> /dev/null - if [ -d /var/log/pihole/ ]; then + if [ ! -d /var/log/pihole/ ]; then mkdir /var/log/pihole/ chmod 0775 /var/log/pihole/ fi From b49db58ec2a3e838eb88aa8233fb3b6cba203413 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 8 Jul 2022 22:00:36 +0200 Subject: [PATCH 072/638] Fix spelling mistakes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 8 ++++---- advanced/Scripts/setupLCD.sh | 2 +- automated install/basic-install.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e71263d35a..601677e259 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -581,7 +581,7 @@ disk_usage() { # Some lines of df might contain sensitive information like usernames and passwords. # E.g. curlftpfs filesystems (https://www.looklinux.com/mount-ftp-share-on-linux-using-curlftps/) # We are not interested in those lines so we collect keyword, to remove them from the output - # Additinal keywords can be added, separated by "|" + # Additional keywords can be added, separated by "|" hide="curlftpfs" # only show those lines not containing a sensitive phrase @@ -990,7 +990,7 @@ make_array_from_file() { else # Otherwise, read the file line by line while IFS= read -r line;do - # Othwerise, strip out comments and blank lines + # Otherwise, strip out comments and blank lines new_line=$(echo "${line}" | sed -e 's/^\s*#.*$//' -e '/^$/d') # If the line still has content (a non-zero value) if [[ -n "${new_line}" ]]; then @@ -1048,7 +1048,7 @@ parse_file() { } check_name_resolution() { - # Check name resolution from localhost, Pi-hole's IP, and Google's name severs + # Check name resolution from localhost, Pi-hole's IP, and Google's name servers # using the function we created earlier dig_at 4 dig_at 6 @@ -1309,7 +1309,7 @@ obfuscated_pihole_log() { # If the variable does not a value (the current default behavior), so do not obfuscate anything if [[ -z ${OBFUSCATE} ]]; then log_write " ${line}" - # Othwerise, a flag was passed to this command to obfuscate domains in the log + # Otherwise, a flag was passed to this command to obfuscate domains in the log else # So first check if there are domains in the log that should be obfuscated if [[ -n ${line_to_obfuscate} ]]; then diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh index 8252364323..b4746dea7d 100755 --- a/advanced/Scripts/setupLCD.sh +++ b/advanced/Scripts/setupLCD.sh @@ -49,7 +49,7 @@ echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc # OR #$SUDO echo /usr/local/bin/chronometer.sh >> /etc/profile -# Set up the LCD screen based on Adafruits instuctions: +# Set up the LCD screen based on Adafruits instructions: # https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install curl -SLs https://apt.adafruit.com/add-pin | bash apt-get -y install raspberrypi-bootloader diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a0a98b68c2..d67985e57f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -395,7 +395,7 @@ select_rpm_php(){ exit fi # php-json is not required on CentOS 7 as it is already compiled into php - # verifiy via `php -m | grep json` + # verify via `php -m | grep json` if [[ $CURRENT_CENTOS_VERSION -eq 7 ]]; then # create a temporary array as arrays are not designed for use as mutable data structures CENTOS7_PIHOLE_WEB_DEPS=() From 3d8672bc59d9902e3b7d7c116048bc8e69f6a3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 8 Jul 2022 23:20:30 +0200 Subject: [PATCH 073/638] Clean consecutive mkdir 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, 1 insertion(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a0a98b68c2..97091e5ca1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2797,8 +2797,7 @@ main() { stop_service pihole-FTL &> /dev/null if [ ! -d /var/log/pihole/ ]; then - mkdir /var/log/pihole/ - chmod 0775 /var/log/pihole/ + mkdir -m 0755 /var/log/pihole/ fi # Special handling for pihole-FTL.log -> pihole/FTL.log @@ -2814,7 +2813,6 @@ main() { # Remaining log files if [ -f /var/log/pihole.log ] && [ ! -L /var/log/pihole.log ]; then - mkdir -p /var/log/pihole/ mv /var/log/pihole*.* /var/log/pihole/ 2>/dev/null fi From e4444ae6a5c75b8ea5e6324544af0c42e9dfd1b0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 9 Jul 2022 19:02:40 +0100 Subject: [PATCH 074/638] fixes "Set static IP using custom values results in error" (#4807) Signed-off-by: Adam Warner --- 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 95764b7d50..078307a6c5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -912,7 +912,7 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Ask for the IPv4 address _staticIPv4Temp=$(dialog --no-shadow --keep-tite --output-fd 1 \ - --cancer-label "Exit" \ + --cancel-label "Exit" \ --ok-label "Continue" \ --backtitle "Calibrating network interface" \ --title "IPv4 Address" \ From ecfb96d339ba739b04f2cbe5e6fbb782b6776092 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 10 Jul 2022 09:52:55 +0100 Subject: [PATCH 075/638] If old log paths exist in logrotate file, replace them with new ones Signed-off-by: Adam Warner --- automated install/basic-install.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 078307a6c5..22fe209a57 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1955,10 +1955,28 @@ installLogrotate() { printf "\\n %b %s..." "${INFO}" "${str}" if [[ -f ${target} ]]; then - printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" - # Return value isn't that important, using 2 to indicate that it's not a fatal error but - # the function did not complete. - return 2 + local touched=0 + + if grep -q "/var/log/pihole.log" ${target}; then + sed -i 's/\/var\/log\/pihole.log/\/var\/log\/pihole\/pihole.log/g' ${target} + touched=1 + fi + + if grep -q "/var/log/pihole-FTL.log" ${target}; then + sed -i 's/\/var\/log\/pihole-FTL.log/\/var\/log\/pihole\/FTL.log/g' ${target} + touched=1 + fi + + if [ "${touched}" -eq "0" ]; then + printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" + # Return value isn't that important, using 2 to indicate that it's not a fatal error but + # the function did not complete. + return 2 + else + printf "\\n\\t%b Old log file paths updated in existing logrotate file. \\n" "${INFO}" + return 3 + fi + fi # Copy the file over from the local repo install -D -m 644 -T "${PI_HOLE_LOCAL_REPO}"/advanced/Templates/logrotate ${target} From 59dab6a568c37ae8331472cf5f94da6531858b64 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 10 Jul 2022 11:50:09 +0100 Subject: [PATCH 076/638] Simplifications per @yubiuser's suggestion Co-authored-by: yubiuser Signed-off-by: Adam Warner --- automated install/basic-install.sh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 22fe209a57..30040a9917 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1955,28 +1955,20 @@ installLogrotate() { printf "\\n %b %s..." "${INFO}" "${str}" if [[ -f ${target} ]]; then - local touched=0 - if grep -q "/var/log/pihole.log" ${target}; then + # Account for changed logfile paths from /var/log -> /var/log/pihole/ made in core v5.11. + if grep -q "/var/log/pihole.log" ${target} || grep -q "/var/log/pihole-FTL.log" ${target}; then sed -i 's/\/var\/log\/pihole.log/\/var\/log\/pihole\/pihole.log/g' ${target} - touched=1 - fi - - if grep -q "/var/log/pihole-FTL.log" ${target}; then sed -i 's/\/var\/log\/pihole-FTL.log/\/var\/log\/pihole\/FTL.log/g' ${target} - touched=1 - fi - if [ "${touched}" -eq "0" ]; then - printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" - # Return value isn't that important, using 2 to indicate that it's not a fatal error but - # the function did not complete. - return 2 - else printf "\\n\\t%b Old log file paths updated in existing logrotate file. \\n" "${INFO}" return 3 fi + printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" "${INFO}" + # Return value isn't that important, using 2 to indicate that it's not a fatal error but + # the function did not complete. + return 2 fi # Copy the file over from the local repo install -D -m 644 -T "${PI_HOLE_LOCAL_REPO}"/advanced/Templates/logrotate ${target} From b25805348ffd1c642758bc0d2346e8427793f094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 10 Jul 2022 13:08:33 +0200 Subject: [PATCH 077/638] Print all SELINUX output in lowercase 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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 078307a6c5..6db15b0735 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2050,22 +2050,22 @@ checkSelinux() { DEFAULT_SELINUX=$(awk -F= '/^SELINUX=/ {print $2}' /etc/selinux/config) case "${DEFAULT_SELINUX,,}" in enforcing) - printf " %b %bDefault SELinux: %s%b\\n" "${CROSS}" "${COL_RED}" "${DEFAULT_SELINUX}" "${COL_NC}" + printf " %b %bDefault SELinux: %s%b\\n" "${CROSS}" "${COL_RED}" "${DEFAULT_SELINUX,,}" "${COL_NC}" SELINUX_ENFORCING=1 ;; *) # 'permissive' and 'disabled' - printf " %b %bDefault SELinux: %s%b\\n" "${TICK}" "${COL_GREEN}" "${DEFAULT_SELINUX}" "${COL_NC}" + printf " %b %bDefault SELinux: %s%b\\n" "${TICK}" "${COL_GREEN}" "${DEFAULT_SELINUX,,}" "${COL_NC}" ;; esac # Check the current state of SELinux CURRENT_SELINUX=$(getenforce) case "${CURRENT_SELINUX,,}" in enforcing) - printf " %b %bCurrent SELinux: %s%b\\n" "${CROSS}" "${COL_RED}" "${CURRENT_SELINUX}" "${COL_NC}" + printf " %b %bCurrent SELinux: %s%b\\n" "${CROSS}" "${COL_RED}" "${CURRENT_SELINUX,,}" "${COL_NC}" SELINUX_ENFORCING=1 ;; *) # 'permissive' and 'disabled' - printf " %b %bCurrent SELinux: %s%b\\n" "${TICK}" "${COL_GREEN}" "${CURRENT_SELINUX}" "${COL_NC}" + printf " %b %bCurrent SELinux: %s%b\\n" "${TICK}" "${COL_GREEN}" "${CURRENT_SELINUX,,}" "${COL_NC}" ;; esac else From 9f918972d214e0f284c2903a917b5f0e7a82a35a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 10 Jul 2022 13:54:55 +0200 Subject: [PATCH 078/638] Adjust tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_centos_fedora_common_support.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_centos_fedora_common_support.py b/test/test_centos_fedora_common_support.py index a2a13048fc..df8067719b 100644 --- a/test/test_centos_fedora_common_support.py +++ b/test/test_centos_fedora_common_support.py @@ -30,7 +30,7 @@ def test_selinux_enforcing_exit(host): source /opt/pihole/basic-install.sh checkSelinux ''') - expected_stdout = cross_box + ' Current SELinux: Enforcing' + expected_stdout = cross_box + ' Current SELinux: enforcing' assert expected_stdout in check_selinux.stdout expected_stdout = 'SELinux Enforcing detected, exiting installer' assert expected_stdout in check_selinux.stdout @@ -46,7 +46,7 @@ def test_selinux_permissive(host): source /opt/pihole/basic-install.sh checkSelinux ''') - expected_stdout = tick_box + ' Current SELinux: Permissive' + expected_stdout = tick_box + ' Current SELinux: permissive' assert expected_stdout in check_selinux.stdout assert check_selinux.rc == 0 @@ -60,6 +60,6 @@ def test_selinux_disabled(host): source /opt/pihole/basic-install.sh checkSelinux ''') - expected_stdout = tick_box + ' Current SELinux: Disabled' + expected_stdout = tick_box + ' Current SELinux: disabled' assert expected_stdout in check_selinux.stdout assert check_selinux.rc == 0 From b486786041cd235151e189e17f4c869751150e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 29 May 2022 09:51:33 +0200 Subject: [PATCH 079/638] Add database healthy checks to debug script Fix health check output comparison in gravity script as well Add note about waiting time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 69 +++++++++++++++++++++++++++++++-- gravity.sh | 12 ++++-- pihole | 28 ++++++------- 3 files changed, 88 insertions(+), 21 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 601677e259..2f4b0011a2 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1259,12 +1259,21 @@ show_messages() { show_FTL_db_entries "Pi-hole diagnosis messages" "SELECT count (message) as count, datetime(max(timestamp),'unixepoch','localtime') as 'last timestamp', type, message, blob1, blob2, blob3, blob4, blob5 FROM message GROUP BY type, message, blob1, blob2, blob3, blob4, blob5;" "6 19 20 60 20 20 20 20 20" } +database_permissions() { + local permissions + permissions=$(ls -lhd "${1}") + log_write "${COL_GREEN}${permissions}${COL_NC}" +} + analyze_gravity_list() { echo_current_diagnostic "Gravity Database" - local gravity_permissions - gravity_permissions=$(ls -lhd "${PIHOLE_GRAVITY_DB_FILE}") - log_write "${COL_GREEN}${gravity_permissions}${COL_NC}" + database_permissions "${PIHOLE_GRAVITY_DB_FILE}" + + # if users want to check database integrity + if [[ "${CHECK_DATABASE}" = true ]]; then + database_integrity_check "${PIHOLE_FTL_DB_FILE}" + fi show_db_entries "Info table" "SELECT property,value FROM info" "20 40" gravity_updated_raw="$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT value FROM info where property = 'updated'")" @@ -1286,6 +1295,57 @@ analyze_gravity_list() { IFS="$OLD_IFS" } +analyze_ftl_db() { + echo_current_diagnostic "Pi-hole FTL Query Database" + database_permissions "${PIHOLE_FTL_DB_FILE}" + # if users want to check database integrity + if [[ "${CHECK_DATABASE}" = true ]]; then + database_integrity_check "${PIHOLE_FTL_DB_FILE}" + fi +} + +database_integrity_check(){ + local result + local database="${1}" + + log_write "${INFO} Checking integrity of ${database} ... (this can take several minutes)" + result="$(pihole-FTL "${database}" "PRAGMA integrity_check" 2>&1)" + if [[ ${result} = "ok" ]]; then + log_write "${TICK} Integrity of ${database} intact" + + + log_write "${INFO} Checking foreign key constraints of ${database} ... (this can take several minutes)" + unset result + result="$(pihole-FTL sqlite3 "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1)" + if [[ -z ${result} ]]; then + log_write "${TICK} No foreign key errors in ${database}" + else + log_write "${CROSS} ${COL_RED}Foreign key errors in ${database} found.${COL_NC}" + while IFS= read -r line ; do + log_write " $line" + done <<< "$result" + fi + + else + log_write "${CROSS} ${COL_RED}Integrity errors in ${database} found.\n${COL_NC}" + while IFS= read -r line ; do + log_write " $line" + done <<< "$result" + fi + +} + +check_database_integrity() { + echo_current_diagnostic "Gravity Database" + database_permissions "${PIHOLE_GRAVITY_DB_FILE}" + database_integrity_check "${PIHOLE_GRAVITY_DB_FILE}" + + echo_current_diagnostic "Pi-hole FTL Query Database" + database_permissions "${PIHOLE_FTL_DB_FILE}" + database_integrity_check "${PIHOLE_FTL_DB_FILE}" +} + + obfuscated_pihole_log() { local pihole_log=("$@") local line @@ -1431,7 +1491,7 @@ upload_to_tricorder() { if [[ "${WEBCALL}" ]] && [[ ! "${AUTOMATED}" ]]; then : else - log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}" + log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}" log_write " * Please try again or contact the Pi-hole team for assistance." fi fi @@ -1460,6 +1520,7 @@ process_status ftl_full_status parse_setup_vars check_x_headers +analyze_ftl_db analyze_gravity_list show_groups show_domainlist diff --git a/gravity.sh b/gravity.sh index 779746940d..910940af1e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -870,15 +870,19 @@ gravity_Cleanup() { database_recovery() { local result - local str="Checking integrity of existing gravity database" + local str="Checking integrity of existing gravity database (this can take a while)" local option="${1}" echo -ne " ${INFO} ${str}..." - if result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA integrity_check" 2>&1)"; then + result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA integrity_check" 2>&1)" + + if [[ ${result} = "ok" ]]; then echo -e "${OVER} ${TICK} ${str} - no errors found" - str="Checking foreign keys of existing gravity database" + str="Checking foreign keys of existing gravity database (this can take a while)" echo -ne " ${INFO} ${str}..." - if result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA foreign_key_check" 2>&1)"; then + unset result + result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA foreign_key_check" 2>&1)" + if [[ -z ${result} ]]; then echo -e "${OVER} ${TICK} ${str} - no errors found" if [[ "${option}" != "force" ]]; then return diff --git a/pihole b/pihole index c54a319204..35f6c07bae 100755 --- a/pihole +++ b/pihole @@ -36,19 +36,20 @@ listFunc() { } debugFunc() { - local automated - local web - - # Pull off the `debug` leaving passed call augmentation flags in $1 - shift - if [[ "$@" == *"-a"* ]]; then - automated="true" - fi - if [[ "$@" == *"-w"* ]]; then - web="true" - fi - - AUTOMATED=${automated:-} WEBCALL=${web:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh + local automated + local web + local check_database_integrity + # Pull off the `debug` leaving passed call augmentation flags in $1 + shift + + for value in "$@"; do + [[ "$value" == *"-a"* ]] && automated="true" + [[ "$value" == *"-w"* ]] && web="true" + [[ "$value" == *"-c"* ]] && check_database_integrity="true" + [[ "$value" == *"--check_database"* ]] && check_database_integrity="true" + done + + AUTOMATED=${automated:-} WEBCALL=${web:-} CHECK_DATABASE=${check_database_integrity:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh exit 0 } @@ -455,6 +456,7 @@ Whitelist/Blacklist Options: Debugging Options: -d, debug Start a debugging session + Add '-c' or '--check-database' to include a Pi-hole database integrity check Add '-a' to automatically upload the log to tricorder.pi-hole.net -f, flush Flush the Pi-hole log -r, reconfigure Reconfigure or Repair Pi-hole subsystems From c4f9a475f3cc6d78deac5aa2fb61b191978cf638 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 11 Jul 2022 01:34:51 -0300 Subject: [PATCH 080/638] Debug log - add spinner for long processes Signed-off-by: RD WebDesign --- 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 2f4b0011a2..02b6ed64d5 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1230,7 +1230,7 @@ check_dhcp_servers() { OLD_IFS="$IFS" IFS=$'\n' local entries=() - mapfile -t entries < <(pihole-FTL dhcp-discover) + mapfile -t entries < <(pihole-FTL dhcp-discover & spinner) for line in "${entries[@]}"; do log_write " ${line}" @@ -1309,7 +1309,7 @@ database_integrity_check(){ local database="${1}" log_write "${INFO} Checking integrity of ${database} ... (this can take several minutes)" - result="$(pihole-FTL "${database}" "PRAGMA integrity_check" 2>&1)" + result="$(pihole-FTL "${database}" "PRAGMA integrity_check" 2>&1 & spinner)" if [[ ${result} = "ok" ]]; then log_write "${TICK} Integrity of ${database} intact" @@ -1345,6 +1345,34 @@ check_database_integrity() { database_integrity_check "${PIHOLE_FTL_DB_FILE}" } +# Show a text spinner during a long process run +# +spinner(){ + local PID=$! # PID of the most recent background process + local spin="/-\|" + local start=0 + local elapsed=0 + local i=1 + + start=$(date +%s) # Start the counter + + tput civis > /dev/tty # Hide the cursor + trap 'tput cnorm > /dev/tty' EXIT # ensures cursor is visible again, in case of premature exit + + while [ -d /proc/$PID ]; do + elapsed=$(( $(date +%s) - start )) + # print the spinner only on screen (tty) - use hours only if needed + if [ "$elapsed" -lt 3600 ]; then + printf "\r${spin:i++%${#spin}:1} %02d:%02d" $((elapsed/60)) $((elapsed%60)) >"$(tty)" + else + printf "\r${spin:i++%${#spin}:1} %02d:%02d:%02d" $((elapsed/3600)) $(((elapsed/60)%60)) $((elapsed%60)) >"$(tty)" + fi + sleep 0.25 + done + + printf "\r" >"$(tty)" # Return to the begin of the line after completion (the spinner will be overwritten) + tput cnorm > /dev/tty # Restore cursor visibility +} obfuscated_pihole_log() { local pihole_log=("$@") From cbcd12631d5674c2f508089a3e2056de592c460c Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 11 Jul 2022 01:53:30 -0300 Subject: [PATCH 081/638] Adding the spinner for foreign_key_check too Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 02b6ed64d5..2e902903ad 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1316,7 +1316,7 @@ database_integrity_check(){ log_write "${INFO} Checking foreign key constraints of ${database} ... (this can take several minutes)" unset result - result="$(pihole-FTL sqlite3 "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1)" + result="$(pihole-FTL sqlite3 "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1 & spinner)" if [[ -z ${result} ]]; then log_write "${TICK} No foreign key errors in ${database}" else From 4567f264b4b8002d58a9b57c4a10165d543afe91 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Mon, 11 Jul 2022 11:45:09 -0700 Subject: [PATCH 082/638] Fix errors in README.md Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dbe9197204..4cca6d44e7 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our versatile installer walks you through the process and takes less than ten minutes +- **Easy-to-install**: our versatile installer walks you through the installation process that takes less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) -- **Robust**: a command line interface that is quality assured for interoperability +- **Robust**: a command-line interface that is quality assured for interoperability - **Insightful**: a beautiful responsive Web Interface dashboard to view and control your Pi-hole - **Versatile**: can optionally function as a [DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026), ensuring *all* your devices are protected automatically - **Scalable**: [capable of handling hundreds of millions of queries](https://pi-hole.net/2017/05/24/how-much-traffic-can-pi-hole-handle/) when installed on server-grade hardware @@ -58,7 +58,7 @@ Please refer to the [Pi-hole docker repo](https://github.com/pi-hole/docker-pi-h ## [Post-install: Make your network take advantage of Pi-hole](https://docs.pi-hole.net/main/post-install/) -Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) which ensures that all devices connecting to your network will have content blocked without any further intervention. +Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245). This router configuration ensures that all devices connecting to your network will have content blocked without any further intervention. If your router does not support setting the DNS server, you can [use Pi-hole's built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026); be sure to disable DHCP on your router first (if it has that feature available). @@ -68,7 +68,7 @@ As a last resort, you can manually set each device to use Pi-hole as their DNS s ## Pi-hole is free but powered by your support -There are many reoccurring costs involved with maintaining free, open source, and privacy-respecting software; expenses which [our volunteer developers](https://github.com/orgs/pi-hole/people) pitch in to cover out-of-pocket. This is just one example of how strongly we feel about our software and the importance of keeping it maintained. +There are many reoccurring costs involved with maintaining free, open-source, and privacy-respecting software; expenses which [our volunteer developers](https://github.com/orgs/pi-hole/people) pitch in to cover out-of-pocket. This is just one example of how strongly we feel about our software and the importance of keeping it maintained. Make no mistake: **your support is absolutely vital to help keep us innovating!** @@ -130,9 +130,9 @@ Some of the statistics you can integrate include: Access the API via [`telnet`](https://github.com/pi-hole/FTL), the Web (`admin/api.php`) and Command Line (`pihole -c -j`). You can find out [more details over here](https://discourse.pi-hole.net/t/pi-hole-api/1863). -### The Command Line Interface +### The Command-Line Interface -The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the functionality necessary to fully administer the Pi-hole, without the need of the Web Interface. It's fast, user-friendly, and auditable by anyone with an understanding of `bash`. +The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the functionality necessary to fully administer the Pi-hole, without the need for the Web Interface. It's fast, user-friendly, and auditable by anyone with an understanding of `bash`. Some notable features include: From 3a226576450f6d652a529f016cca9a01866e7a28 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Mon, 11 Jul 2022 14:54:19 -0700 Subject: [PATCH 083/638] Update README.md Co-authored-by: Adam Warner Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cca6d44e7..a8eff73911 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Please refer to the [Pi-hole docker repo](https://github.com/pi-hole/docker-pi-h ## [Post-install: Make your network take advantage of Pi-hole](https://docs.pi-hole.net/main/post-install/) -Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245). This router configuration ensures that all devices connecting to your network will have content blocked without any further intervention. +Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245). This router configuration will ensure that all devices connecting to your network will have content blocked without any further intervention. If your router does not support setting the DNS server, you can [use Pi-hole's built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026); be sure to disable DHCP on your router first (if it has that feature available). From 7ab96642557e367b784cb7a2b31cc0226ff2b8f8 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Mon, 11 Jul 2022 14:55:15 -0700 Subject: [PATCH 084/638] Update README.md Co-authored-by: Adam Warner Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8eff73911..e4141d436b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our versatile installer walks you through the installation process that takes less than ten minutes +- **Easy-to-install**: our versatile installer walks you through the installation process, and takes less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) From c90d8284efb256d0c285fed7cc8e13e0edd1df59 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Tue, 12 Jul 2022 16:20:17 -0700 Subject: [PATCH 085/638] Update README.md Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e4141d436b..c95df26341 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our versatile installer walks you through the installation process, and takes less than ten minutes +- **Easy-to-install**: our dialogs walk you through simple installation process in less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) From a3f1317add4dbc786c083302fb1c1bfb078e22ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 15 Jul 2022 20:04:37 +0200 Subject: [PATCH 086/638] Don't fail if Alma or Rocky is detected 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 | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5fc61215cf..1d21bdc9dd 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -381,7 +381,7 @@ select_rpm_php(){ # all required packages should be available by default with the latest fedora release : # continue # or if host OS is CentOS, - elif grep -qiE 'centos|scientific' /etc/redhat-release; then + elif grep -qiE 'centos|scientific|alma|rocky' /etc/redhat-release; then # Pi-Hole currently supports CentOS 7+ with PHP7+ SUPPORTED_CENTOS_VERSION=7 SUPPORTED_CENTOS_PHP_VERSION=7 @@ -413,11 +413,7 @@ select_rpm_php(){ printf " %b EPEL repository already installed\\n" "${TICK}" else # CentOS requires the EPEL repository to gain access to Fedora packages - if [[ CURRENT_CENTOS_VERSION -eq 7 ]]; then - EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm" - elif [[ CURRENT_CENTOS_VERSION -eq 8 ]]; then - EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm" - fi + EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${CURRENT_CENTOS_VERSION}.noarch.rpm" printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" "${PKG_INSTALL[@]}" ${EPEL_PKG} printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" From bc8fcc744ce97012586e3d0767aa6d9723659d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 15 Jul 2022 20:40:11 +0200 Subject: [PATCH 087/638] Fix shellcheck warnings 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 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5fc61215cf..30585b7052 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -805,7 +805,7 @@ testIPv6() { find_IPv6_information() { # Detects IPv6 address used for communication to WAN addresses. - IPV6_ADDRESSES=($(ip -6 address | grep 'scope global' | awk '{print $2}')) + mapfile -t IPV6_ADDRESSES <<<"$(ip -6 address | grep 'scope global' | awk '{print $2}')" # For each address in the array above, determine the type of IPv6 address it is for i in "${IPV6_ADDRESSES[@]}"; do @@ -820,13 +820,13 @@ find_IPv6_information() { # Determine which address to be used: Prefer ULA over GUA or don't use any if none found # If the ULA_ADDRESS contains a value, - if [[ ! -z "${ULA_ADDRESS}" ]]; then + if [[ -n "${ULA_ADDRESS}" ]]; then # set the IPv6 address to the ULA address IPV6_ADDRESS="${ULA_ADDRESS}" # Show this info to the user printf " %b Found IPv6 ULA address\\n" "${INFO}" # Otherwise, if the GUA_ADDRESS has a value, - elif [[ ! -z "${GUA_ADDRESS}" ]]; then + elif [[ -n "${GUA_ADDRESS}" ]]; then # Let the user know printf " %b Found IPv6 GUA address\\n" "${INFO}" # And assign it to the global variable @@ -1751,9 +1751,9 @@ install_dependent_packages() { # Running apt-get install with minimal output can cause some issues with # requiring user input (e.g password for phpmyadmin see #218) printf " %b Processing %s install(s) for: %s, please wait...\\n" "${INFO}" "${PKG_MANAGER}" "${installArray[*]}" - printf '%*s\n' "$columns" '' | tr " " -; + printf '%*s\n' "${c}" '' | tr " " -; "${PKG_INSTALL[@]}" "${installArray[@]}" - printf '%*s\n' "$columns" '' | tr " " -; + printf '%*s\n' "${c}" '' | tr " " -; return fi printf "\\n" @@ -1774,9 +1774,9 @@ install_dependent_packages() { # If there's anything to install, install everything in the list. if [[ "${#installArray[@]}" -gt 0 ]]; then printf " %b Processing %s install(s) for: %s, please wait...\\n" "${INFO}" "${PKG_MANAGER}" "${installArray[*]}" - printf '%*s\n' "$columns" '' | tr " " -; + printf '%*s\n' "${c}" '' | tr " " -; "${PKG_INSTALL[@]}" "${installArray[@]}" - printf '%*s\n' "$columns" '' | tr " " -; + printf '%*s\n' "${c}" '' | tr " " -; return fi printf "\\n" @@ -1939,6 +1939,7 @@ finalExports() { # Bring in the current settings and the functions to manipulate them source "${setupVars}" + # shellcheck source=advanced/Scripts/webpage.sh source "${PI_HOLE_LOCAL_REPO}/advanced/Scripts/webpage.sh" # Look for DNS server settings which would have to be reapplied From 8d1f286f30d4415dac2f1efff38bb32491f26904 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sun, 24 Jul 2022 17:52:17 -0300 Subject: [PATCH 088/638] Only execute spinner function if there is a tty Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 49 +++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 2e902903ad..3434888511 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1348,30 +1348,33 @@ check_database_integrity() { # Show a text spinner during a long process run # spinner(){ - local PID=$! # PID of the most recent background process - local spin="/-\|" - local start=0 - local elapsed=0 - local i=1 - - start=$(date +%s) # Start the counter - - tput civis > /dev/tty # Hide the cursor - trap 'tput cnorm > /dev/tty' EXIT # ensures cursor is visible again, in case of premature exit - - while [ -d /proc/$PID ]; do - elapsed=$(( $(date +%s) - start )) - # print the spinner only on screen (tty) - use hours only if needed - if [ "$elapsed" -lt 3600 ]; then - printf "\r${spin:i++%${#spin}:1} %02d:%02d" $((elapsed/60)) $((elapsed%60)) >"$(tty)" - else - printf "\r${spin:i++%${#spin}:1} %02d:%02d:%02d" $((elapsed/3600)) $(((elapsed/60)%60)) $((elapsed%60)) >"$(tty)" - fi - sleep 0.25 - done + # Show the spinner only if there is a tty + if tty -s; then + local PID=$! # PID of the most recent background process + local spin="/-\|" + local start=0 + local elapsed=0 + local i=1 + + start=$(date +%s) # Start the counter + + tput civis > /dev/tty # Hide the cursor + trap 'tput cnorm > /dev/tty' EXIT # ensures cursor is visible again, in case of premature exit + + while [ -d /proc/$PID ]; do + elapsed=$(( $(date +%s) - start )) + # use hours only if needed + if [ "$elapsed" -lt 3600 ]; then + printf "\r${spin:i++%${#spin}:1} %02d:%02d" $((elapsed/60)) $((elapsed%60)) >"$(tty)" + else + printf "\r${spin:i++%${#spin}:1} %02d:%02d:%02d" $((elapsed/3600)) $(((elapsed/60)%60)) $((elapsed%60)) >"$(tty)" + fi + sleep 0.25 + done - printf "\r" >"$(tty)" # Return to the begin of the line after completion (the spinner will be overwritten) - tput cnorm > /dev/tty # Restore cursor visibility + printf "\r" >"$(tty)" # Return to the begin of the line after completion (the spinner will be overwritten) + tput cnorm > /dev/tty # Restore cursor visibility + fi } obfuscated_pihole_log() { From d89720330f7434254c52f094d1117f67aaa8cf1a Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sun, 24 Jul 2022 20:15:20 -0300 Subject: [PATCH 089/638] Address revision requests: - replace `local var` with `_var` (POSIX style); - move inline comments Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 39 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3434888511..1707b87229 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1346,34 +1346,41 @@ check_database_integrity() { } # Show a text spinner during a long process run -# spinner(){ # Show the spinner only if there is a tty if tty -s; then - local PID=$! # PID of the most recent background process - local spin="/-\|" - local start=0 - local elapsed=0 - local i=1 + # PID of the most recent background process + _PID=$! + _spin="/-\|" + _start=0 + _elapsed=0 + _i=1 + + # Start the counter + _start=$(date +%s) - start=$(date +%s) # Start the counter + # Hide the cursor + tput civis > /dev/tty - tput civis > /dev/tty # Hide the cursor - trap 'tput cnorm > /dev/tty' EXIT # ensures cursor is visible again, in case of premature exit + # ensures cursor is visible again, in case of premature exit + trap 'tput cnorm > /dev/tty' EXIT - while [ -d /proc/$PID ]; do - elapsed=$(( $(date +%s) - start )) + while [ -d /proc/$_PID ]; do + _elapsed=$(( $(date +%s) - _start )) # use hours only if needed - if [ "$elapsed" -lt 3600 ]; then - printf "\r${spin:i++%${#spin}:1} %02d:%02d" $((elapsed/60)) $((elapsed%60)) >"$(tty)" + if [ "$_elapsed" -lt 3600 ]; then + printf "\r${_spin:_i++%${#_spin}:1} %02d:%02d" $((_elapsed/60)) $((_elapsed%60)) >"$(tty)" else - printf "\r${spin:i++%${#spin}:1} %02d:%02d:%02d" $((elapsed/3600)) $(((elapsed/60)%60)) $((elapsed%60)) >"$(tty)" + printf "\r${_spin:_i++%${#_spin}:1} %02d:%02d:%02d" $((_elapsed/3600)) $(((_elapsed/60)%60)) $((_elapsed%60)) >"$(tty)" fi sleep 0.25 done - printf "\r" >"$(tty)" # Return to the begin of the line after completion (the spinner will be overwritten) - tput cnorm > /dev/tty # Restore cursor visibility + # Return to the begin of the line after completion (the spinner will be overwritten) + printf "\r" >"$(tty)" + + # Restore cursor visibility + tput cnorm > /dev/tty fi } From 2bd3366bb121e1d6f837a9d652cbf74835878436 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 25 Jul 2022 21:57:30 +0100 Subject: [PATCH 090/638] Disable fail fast, allowing tests to run despite failures on a particular distro - it is easier to retry failed tests these day --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 308997d746..4c1c596063 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,6 +41,7 @@ jobs: runs-on: ubuntu-latest needs: smoke-tests strategy: + fail-fast: false matrix: distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_21, ubuntu_22, centos_7, centos_8, fedora_34] env: From 21af75a2d2342d184d3a653cbe52fc11c83eebea Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 25 Jul 2022 22:27:56 +0100 Subject: [PATCH 091/638] Ubuntu 21 tests are failing entirely. apt-update does not work on an impish vm, either Signed-off-by: Adam Warner --- .github/workflows/test.yml | 2 +- test/_ubuntu_21.Dockerfile | 18 ------------------ test/tox.ubuntu_21.ini | 8 -------- 3 files changed, 1 insertion(+), 27 deletions(-) delete mode 100644 test/_ubuntu_21.Dockerfile delete mode 100644 test/tox.ubuntu_21.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c1c596063..e9a5d34d72 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,7 @@ jobs: strategy: fail-fast: false matrix: - distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_21, ubuntu_22, centos_7, centos_8, fedora_34] + distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_22, centos_7, centos_8, fedora_34] env: DISTRO: ${{matrix.distro}} steps: diff --git a/test/_ubuntu_21.Dockerfile b/test/_ubuntu_21.Dockerfile deleted file mode 100644 index 05801de850..0000000000 --- a/test/_ubuntu_21.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM buildpack-deps:impish-scm - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR -ENV DEBIAN_FRONTEND=noninteractive - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.ubuntu_21.ini b/test/tox.ubuntu_21.ini deleted file mode 100644 index 070d3a7218..0000000000 --- a/test/tox.ubuntu_21.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py38 - -[testenv] -whitelist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _ubuntu_21.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 64465510de08acf278db58b247ad85802afe3b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 26 Jul 2022 13:33:00 +0200 Subject: [PATCH 092/638] prefers-color-scheme for logo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index dbe9197204..cf6d80c086 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,15 @@ #

- - Pi-hole - - - Pi-hole - + + + + Pi-hole website +
Network-wide ad blocking via your own Linux hardware

+ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. @@ -22,7 +22,7 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) th - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) - **Robust**: a command line interface that is quality assured for interoperability - **Insightful**: a beautiful responsive Web Interface dashboard to view and control your Pi-hole -- **Versatile**: can optionally function as a [DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026), ensuring *all* your devices are protected automatically +- **Versatile**: can optionally function as a [DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026), ensuring _all_ your devices are protected automatically - **Scalable**: [capable of handling hundreds of millions of queries](https://pi-hole.net/2017/05/24/how-much-traffic-can-pi-hole-handle/) when installed on server-grade hardware - **Modern**: blocks ads over both IPv4 and IPv6 - **Free**: open source software that helps ensure _you_ are the sole person in control of your privacy @@ -53,7 +53,9 @@ sudo bash basic-install.sh wget -O basic-install.sh https://install.pi-hole.net sudo bash basic-install.sh ``` + ### Method 3: Using Docker to deploy Pi-hole + Please refer to the [Pi-hole docker repo](https://github.com/pi-hole/docker-pi-hole) to use the Official Docker Images. ## [Post-install: Make your network take advantage of Pi-hole](https://docs.pi-hole.net/main/post-install/) @@ -115,7 +117,7 @@ While we are primarily reachable on our [Discourse User Forum](https://discourse ### [Faster-than-light Engine](https://github.com/pi-hole/ftl) -[FTLDNS](https://github.com/pi-hole/ftl) is a lightweight, purpose-built daemon used to provide statistics needed for the Web Interface, and its API can be easily integrated into your own projects. As the name implies, FTLDNS does this all *very quickly*! +[FTLDNS](https://github.com/pi-hole/ftl) is a lightweight, purpose-built daemon used to provide statistics needed for the Web Interface, and its API can be easily integrated into your own projects. As the name implies, FTLDNS does this all _very quickly_! Some of the statistics you can integrate include: @@ -142,7 +144,7 @@ Some notable features include: - [Updating Ad Lists](https://docs.pi-hole.net/core/pihole-command/#gravity) - [Querying Ad Lists for blocked domains](https://docs.pi-hole.net/core/pihole-command/#query) - [Enabling and Disabling Pi-hole](https://docs.pi-hole.net/core/pihole-command/#enable-disable) -- ... and *many* more! +- ... and _many_ more! You can read our [Core Feature Breakdown](https://docs.pi-hole.net/core/pihole-command/#pi-hole-core) for more information. From 7b77d991df712722ae48568e325c5a0bc3df1c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 26 Jul 2022 14:38:03 +0200 Subject: [PATCH 093/638] Move FTL port and PID functions to utils.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/utils.sh | 95 ++++++++++++++++++++++----- advanced/Templates/pihole-FTL.service | 52 ++------------- pihole | 80 ++++++++++------------ test/test_any_utils.py | 7 +- 4 files changed, 123 insertions(+), 111 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index cf24c09819..a9e05692e4 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -71,28 +71,87 @@ removeKey() { } ####################### -# returns FTL's current telnet API port +# returns path of FTL's port file +####################### +getFTLAPIPortFile() { + local FTLCONFFILE="/etc/pihole/pihole-FTL.conf" + local DEFAULT_PORT_FILE="/run/pihole-FTL.port" + local FTL_APIPORT_FILE + + if [ -s "${FTLCONFFILE}" ]; then + # if PORTFILE is not set in pihole-FTL.conf, use the default path + FTL_APIPORT_FILE="$({ grep '^PORTFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PORT_FILE}"; } | cut -d'=' -f2-)" + else + # if there is no pihole-FTL.conf, use the default path + FTL_APIPORT_FILE="${DEFAULT_PORT_FILE}" + fi + + echo "${FTL_APIPORT_FILE}" +} + + +####################### +# returns FTL's current telnet API port based on the content of the pihole-FTL.port file +# +# Takes one argument: path to pihole-FTL.port +# Example getFTLAPIPort "/run/pihole-FTL.port" ####################### getFTLAPIPort(){ + local PORTFILE="${1}" + local DEFAULT_FTL_PORT=4711 + local ftl_api_port + + if [ -s "$PORTFILE" ]; then + # -s: FILE exists and has a size greater than zero + ftl_api_port=$(cat "${PORTFILE}") + # Exploit prevention: unset the variable if there is malicious content + # Verify that the value read from the file is numeric + expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port + fi + + # echo the port found in the portfile or default to the default port + echo "${ftl_api_port:=$DEFAULT_FTL_PORT}" +} + +####################### +# returns path of FTL's PID file +####################### +getFTLPIDFile() { local FTLCONFFILE="/etc/pihole/pihole-FTL.conf" - local DEFAULT_PORT_FILE="/run/pihole-FTL.port" - local DEFAULT_FTL_PORT=4711 - local PORTFILE - local ftl_api_port - - if [ -f "$FTLCONFFILE" ]; then - # if PORTFILE is not set in pihole-FTL.conf, use the default path - PORTFILE="$( (grep "^PORTFILE=" $FTLCONFFILE || echo "$DEFAULT_PORT_FILE") | cut -d"=" -f2-)" - fi + local DEFAULT_PID_FILE="/run/pihole-FTL.pid" + local FTL_PID_FILE - if [ -s "$PORTFILE" ]; then - # -s: FILE exists and has a size greater than zero - ftl_api_port=$(cat "${PORTFILE}") - # Exploit prevention: unset the variable if there is malicious content - # Verify that the value read from the file is numeric - expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port + if [ -s "${FTLCONFFILE}" ]; then + # if PIDFILE is not set in pihole-FTL.conf, use the default path + FTL_PID_FILE="$({ grep '^PIDFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PID_FILE}"; } | cut -d'=' -f2-)" + else + # if there is no pihole-FTL.conf, use the default path + FTL_PID_FILE="${DEFAULT_PID_FILE}" fi - # echo the port found in the portfile or default to the default port - echo "${ftl_api_port:=$DEFAULT_FTL_PORT}" + echo "${FTL_PID_FILE}" +} + +####################### +# returns FTL's PID based on the content of the pihole-FTL.pid file +# +# Takes one argument: path to pihole-FTL.pid +# Example getFTLPID "/run/pihole-FTL.pid" +####################### +getFTLPID() { + local FTL_PID_FILE="${1}" + local FTL_PID + + if [ -s "${FTL_PID_FILE}" ]; then + # -s: FILE exists and has a size greater than zero + FTL_PID="$(cat "${FTL_PID_FILE}")" + # Exploit prevention: unset the variable if there is malicious content + # Verify that the value read from the file is numeric + expr "${FTL_PID}" : "[^[:digit:]]" > /dev/null && unset FTL_PID + fi + + # If FTL is not running, or the PID file contains malicious stuff, substitute + # negative PID to signal this + FTL_PID=${FTL_PID:=-1} + echo "${FTL_PID}" } diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index f5abfcea43..7346dc206a 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -9,48 +9,10 @@ # Description: Enable service provided by pihole-FTL daemon ### END INIT INFO -# Global variables -FTLCONFFILE="/etc/pihole/pihole-FTL.conf" -DEFAULT_PID_FILE="/run/pihole-FTL.pid" -DEFAULT_PORT_FILE="/run/pihole-FTL.port" -FTL_PID='' - -# Get the file path of the pihole-FTL.pid file -getFTLPIDFile() { - if [ -s "${FTLCONFFILE}" ]; then - # if PIDFILE is not set in pihole-FTL.conf, use the default path - FTL_PID_FILE="$({ grep '^PIDFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PID_FILE}"; } | cut -d'=' -f2-)" - else - # if there is no pihole-FTL.conf, use the default path - FTL_PID_FILE="${DEFAULT_PID_FILE}" - fi -} - -# Get the PID of the FTL process based on the content of the pihole-FTL.pid file -getFTLPID() { - if [ -s "${FTL_PID_FILE}" ]; then - # -s: FILE exists and has a size greater than zero - FTL_PID="$(cat "${FTL_PID_FILE}")" - # Exploit prevention: unset the variable if there is malicious content - # Verify that the value read from the file is numeric - expr "${FTL_PID}" : "[^[:digit:]]" > /dev/null && unset FTL_PID - fi - - # If FTL is not running, or the PID file contains malicious stuff, substitute - # negative PID to signal this - FTL_PID=${FTL_PID:=-1} -} - -# Get the file path of the pihole-FTL.port file -getFTLPortFile() { - if [ -s "${FTLCONFFILE}" ]; then - # if PORTFILE is not set in pihole-FTL.conf, use the default path - FTL_PORT_FILE="$({ grep '^PORTFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PORT_FILE}"; } | cut -d'=' -f2-)" - else - # if there is no pihole-FTL.conf, use the default path - FTL_PORT_FILE="${DEFAULT_PORT_FILE}" -fi -} +#source utils.sh for getFTLPIDFile(), getFTLPID (), getFTLAPIPortFile() +PI_HOLE_SCRIPT_DIR="/opt/pihole" +utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" +. "${utilsfile}" is_running() { @@ -148,11 +110,11 @@ status() { ### main logic ### # Get file paths -getFTLPIDFile -getFTLPortFile +FTL_PID_FILE="$(getFTLPIDFile)" +FTL_PORT_FILE="$(getFTLAPIPortFile)" # Get FTL's current PID -getFTLPID +FTL_PID="$(getFTLPID ${FTL_PID_FILE})" case "$1" in stop) diff --git a/pihole b/pihole index 35f6c07bae..eb825965e4 100755 --- a/pihole +++ b/pihole @@ -16,7 +16,6 @@ readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" # error due to modifying a readonly variable. setupVars="/etc/pihole/setupVars.conf" PI_HOLE_BIN_DIR="/usr/local/bin" -readonly FTL_PID_FILE="/run/pihole-FTL.pid" readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE" source "${colfile}" @@ -101,25 +100,8 @@ versionFunc() { exec "${PI_HOLE_SCRIPT_DIR}"/version.sh "$@" } -# Get PID of main pihole-FTL process -getFTLPID() { - local pid - - if [ -s "${FTL_PID_FILE}" ]; then - # -s: FILE exists and has a size greater than zero - pid="$(<"$FTL_PID_FILE")" - # Exploit prevention: unset the variable if there is malicious content - # Verify that the value read from the file is numeric - [[ "$pid" =~ [^[:digit:]] ]] && unset pid - fi - - # If FTL is not running, or the PID file contains malicious stuff, substitute - # negative PID to signal this to the caller - echo "${pid:=-1}" -} - restartDNS() { - local svcOption svc str output status pid icon + local svcOption svc str output status pid icon FTL_PID_FILE svcOption="${1:-restart}" # Determine if we should reload or restart @@ -128,7 +110,11 @@ restartDNS() { # Note 1: This will NOT re-read any *.conf files # Note 2: We cannot use killall here as it does # not know about real-time signals - pid="$(getFTLPID)" + + # get the current path to the pihole-FTL.pid + FTL_PID_FILE="$(getFTLPIDFile)" + + pid="$(getFTLPID ${FTL_PID_FILE})" if [[ "$pid" -eq "-1" ]]; then svc="true" str="FTL is not running" @@ -141,7 +127,7 @@ restartDNS() { elif [[ "${svcOption}" =~ "reload" ]]; then # Reloading of the DNS cache has been requested # Note: This will NOT re-read any *.conf files - pid="$(getFTLPID)" + pid="$(getFTLPID ${FTL_PID_FILE})" if [[ "$pid" -eq "-1" ]]; then svc="true" str="FTL is not running" @@ -316,33 +302,37 @@ analyze_ports() { } statusFunc() { - # Determine if there is pihole-FTL service is listening - local pid port ftl_api_port + # Determine if there is pihole-FTL service is listening + local pid port ftl_api_port ftl_pid_file ftl_apiport_file - pid="$(getFTLPID)" - ftl_api_port="$(getFTLAPIPort)" - if [[ "$pid" -eq "-1" ]]; then - case "${1}" in - "web") echo "-1";; - *) echo -e " ${CROSS} DNS service is NOT running";; - esac - return 0 - else - #get the DNS port pihole-FTL is listening on by using FTL's telnet API - port="$(echo ">dns-port >quit" | nc 127.0.0.1 "$ftl_api_port")" - if [[ "${port}" == "0" ]]; then - case "${1}" in - "web") echo "-1";; - *) echo -e " ${CROSS} DNS service is NOT listening";; - esac - return 0 + ftl_pid_file="$(getFTLPIDFile)" + + pid="$(getFTLPID ${ftl_pid_file})" + + ftl_apiport_file="${getFTLAPIPortFile}" + ftl_api_port="$(getFTLAPIPort ${ftl_apiport_file})" + if [[ "$pid" -eq "-1" ]]; then + case "${1}" in + "web") echo "-1";; + *) echo -e " ${CROSS} DNS service is NOT running";; + esac + return 0 else - if [[ "${1}" != "web" ]]; then - echo -e " ${TICK} FTL is listening on port ${port}" - analyze_ports "${port}" - fi + #get the DNS port pihole-FTL is listening on by using FTL's telnet API + port="$(echo ">dns-port >quit" | nc 127.0.0.1 "$ftl_api_port")" + 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" ]]; then + echo -e " ${TICK} FTL is listening on port ${port}" + analyze_ports "${port}" + fi + fi fi - fi # Determine if Pi-hole's blocking is enabled if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then diff --git a/test/test_any_utils.py b/test/test_any_utils.py index b30ff7fded..aaa496cc8c 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -54,13 +54,13 @@ def test_getFTLAPIPort_default(host): ''' Confirms getFTLAPIPort returns the default API port ''' output = host.run(''' source /opt/pihole/utils.sh - getFTLAPIPort + getFTLAPIPort "/run/pihole-FTL.port" ''') expected_stdout = '4711\n' assert expected_stdout == output.stdout -def test_getFTLAPIPort_custom(host): +def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): ''' Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location ''' host.run(''' echo "PORTFILE=/tmp/port.file" > /etc/pihole/pihole-FTL.conf @@ -68,7 +68,8 @@ def test_getFTLAPIPort_custom(host): ''') output = host.run(''' source /opt/pihole/utils.sh - getFTLAPIPort + FTL_API_PORT=$(getFTLAPIPortFile) + getFTLAPIPort "${FTL_API_PORT}" ''') expected_stdout = '1234\n' assert expected_stdout == output.stdout From 2651abbe6c0d2e834907d161af99606e706c4dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 26 Jul 2022 16:57:06 +0200 Subject: [PATCH 094/638] Add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_utils.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/test_any_utils.py b/test/test_any_utils.py index aaa496cc8c..8ec8871c2d 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -49,6 +49,15 @@ def test_key_removal_works(host): expected_stdout = 'KEY_ONE=value1\nKEY_THREE=value3\n' assert expected_stdout == output.stdout +def test_getFTLAPIPortFile_default(host): + ''' Confirms getFTLAPIPortFile returns the default API port file path ''' + output = host.run(''' + source /opt/pihole/utils.sh + getFTLAPIPortFile + ''') + expected_stdout = '/run/pihole-FTL.port\n' + assert expected_stdout == output.stdout + def test_getFTLAPIPort_default(host): ''' Confirms getFTLAPIPort returns the default API port ''' @@ -73,3 +82,24 @@ def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): ''') expected_stdout = '1234\n' assert expected_stdout == output.stdout + +def test_getFTLPIDFile_default(host): + ''' Confirms getFTLPIDFile returns the default PID file path ''' + output = host.run(''' + source /opt/pihole/utils.sh + getFTLPIDFile + ''') + expected_stdout = '/run/pihole-FTL.pid\n' + assert expected_stdout == output.stdout + +def test_getFTLPIDFile_custom(host): + ''' Confirms getFTLPIDFile returns a custom PID file path ''' + host.run(''' + echo "PIDFILE=/tmp/pid.file" > /etc/pihole/pihole-FTL.conf + ''') + output = host.run(''' + source /opt/pihole/utils.sh + getFTLPIDFile + ''') + expected_stdout = '/tmp/pid.file\n' + assert expected_stdout == output.stdout From c8c4eb59b774de7ad7ae5b3afd017626de7c20f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 26 Jul 2022 17:34:42 +0200 Subject: [PATCH 095/638] Add getFTLPID() tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_utils.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 8ec8871c2d..0668b9d1eb 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -77,8 +77,8 @@ def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): ''') output = host.run(''' source /opt/pihole/utils.sh - FTL_API_PORT=$(getFTLAPIPortFile) - getFTLAPIPort "${FTL_API_PORT}" + FTL_API_PORT_FILE=$(getFTLAPIPortFile) + getFTLAPIPort "${FTL_API_PORT_FILE}" ''') expected_stdout = '1234\n' assert expected_stdout == output.stdout @@ -92,14 +92,26 @@ def test_getFTLPIDFile_default(host): expected_stdout = '/run/pihole-FTL.pid\n' assert expected_stdout == output.stdout -def test_getFTLPIDFile_custom(host): +def test_getFTLPID_default(host): + ''' Confirms getFTLPID returns the default value if FTL is not running ''' + output = host.run(''' + source /opt/pihole/utils.sh + getFTLPID + ''') + expected_stdout = '-1\n' + assert expected_stdout == output.stdout + +def test_getFTLPIDFile_and_getFTLPID_custom(host): ''' Confirms getFTLPIDFile returns a custom PID file path ''' host.run(''' echo "PIDFILE=/tmp/pid.file" > /etc/pihole/pihole-FTL.conf + echo "1234" > /tmp/pid.file ''') output = host.run(''' source /opt/pihole/utils.sh - getFTLPIDFile + FTL_PID_FILE=$(getFTLPIDFile) + getFTLPID "${FTL_PID_FILE}" ''') expected_stdout = '/tmp/pid.file\n' assert expected_stdout == output.stdout + From ab6b37bdcfab2c64683a6a7386f3afc749f1017e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 26 Jul 2022 19:33:38 +0200 Subject: [PATCH 096/638] Fix stickler and codefactor complaints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_utils.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 0668b9d1eb..5126f2638f 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -49,6 +49,7 @@ def test_key_removal_works(host): expected_stdout = 'KEY_ONE=value1\nKEY_THREE=value3\n' assert expected_stdout == output.stdout + def test_getFTLAPIPortFile_default(host): ''' Confirms getFTLAPIPortFile returns the default API port file path ''' output = host.run(''' @@ -72,8 +73,9 @@ def test_getFTLAPIPort_default(host): def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): ''' Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location ''' host.run(''' - echo "PORTFILE=/tmp/port.file" > /etc/pihole/pihole-FTL.conf - echo "1234" > /tmp/port.file + tmpfile=$(mktemp) + echo "PORTFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf + echo "1234" > ${tmpfile} ''') output = host.run(''' source /opt/pihole/utils.sh @@ -83,6 +85,7 @@ def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): expected_stdout = '1234\n' assert expected_stdout == output.stdout + def test_getFTLPIDFile_default(host): ''' Confirms getFTLPIDFile returns the default PID file path ''' output = host.run(''' @@ -92,6 +95,7 @@ def test_getFTLPIDFile_default(host): expected_stdout = '/run/pihole-FTL.pid\n' assert expected_stdout == output.stdout + def test_getFTLPID_default(host): ''' Confirms getFTLPID returns the default value if FTL is not running ''' output = host.run(''' @@ -101,17 +105,18 @@ def test_getFTLPID_default(host): expected_stdout = '-1\n' assert expected_stdout == output.stdout + def test_getFTLPIDFile_and_getFTLPID_custom(host): ''' Confirms getFTLPIDFile returns a custom PID file path ''' host.run(''' - echo "PIDFILE=/tmp/pid.file" > /etc/pihole/pihole-FTL.conf - echo "1234" > /tmp/pid.file + tmpfile=$(mktemp) + echo "PIDFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf + echo "1234" > ${tmpfile} ''') output = host.run(''' source /opt/pihole/utils.sh FTL_PID_FILE=$(getFTLPIDFile) getFTLPID "${FTL_PID_FILE}" ''') - expected_stdout = '/tmp/pid.file\n' + expected_stdout = '1234\n' assert expected_stdout == output.stdout - From 14e1eea22d250d9c800808b3bef4f692e0cbfbb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 24 Jul 2022 13:35:19 +0200 Subject: [PATCH 097/638] Fix spaces in dialog msg 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 02d312e75b..796f856b50 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -885,9 +885,9 @@ getStaticIPv4Settings() { --cancel-label "Exit" \ --backtitle "IP information" \ --title "FYI: IP Conflict" \ - --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict\ -But in most cases the router is smart enough to not do that.\ -If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.\ + --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict. \ +But in most cases the router is smart enough to not do that. \ +If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. \ It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."\ "${r}" "${c}" && result=0 || result=$? From d5c798d1a9107c05239a2b6094402ec1881ceb3a Mon Sep 17 00:00:00 2001 From: yubiuser Date: Sun, 24 Jul 2022 21:40:16 +0200 Subject: [PATCH 098/638] Apply reviewers suggestion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RD WebDesign Signed-off-by: yubiuser Signed-off-by: Christian König --- automated install/basic-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 796f856b50..342af9b410 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -885,10 +885,10 @@ getStaticIPv4Settings() { --cancel-label "Exit" \ --backtitle "IP information" \ --title "FYI: IP Conflict" \ - --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict. \ -But in most cases the router is smart enough to not do that. \ -If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. \ -It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."\ + --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict, \ +but in most cases the router is smart enough to not do that.\ +\n\nIf you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.\ +\n\nIt is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."\ "${r}" "${c}" && result=0 || result=$? case ${result} in From 8c778c14dcb9fb50ace4a849ffc1221394f86e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 26 Jul 2022 23:43:49 +0200 Subject: [PATCH 099/638] Move linebreaks 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 342af9b410..06694506ae 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -886,9 +886,9 @@ getStaticIPv4Settings() { --backtitle "IP information" \ --title "FYI: IP Conflict" \ --msgbox "\\nIt is possible your router could still try to assign this IP to a device, which would cause a conflict, \ -but in most cases the router is smart enough to not do that.\ -\n\nIf you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.\ -\n\nIt is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."\ +but in most cases the router is smart enough to not do that.\n\n\ +If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.\n\n\ +It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."\ "${r}" "${c}" && result=0 || result=$? case ${result} in From 68eddd2377268353e5cec355929e5b37c0695bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 29 Jul 2022 22:47:40 +0200 Subject: [PATCH 100/638] Add OS_CHECK_DEPS to uninstall script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/uninstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index a58ad7536d..0b516d0f26 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -44,8 +44,8 @@ source "${setupVars}" # package_manager_detect() sourced from basic-install.sh package_manager_detect -# Install packages used by the Pi-hole -DEPS=("${INSTALLER_DEPS[@]}" "${PIHOLE_DEPS[@]}") +# Uninstall packages used by the Pi-hole +DEPS=("${INSTALLER_DEPS[@]}" "${PIHOLE_DEPS[@]}" "${OS_CHECK_DEPS[@]}") if [[ "${INSTALL_WEB_SERVER}" == true ]]; then # Install the Web dependencies DEPS+=("${PIHOLE_WEB_DEPS[@]}") From 567a91533633af334375539b15595e297cee4d37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 29 Jul 2022 23:21:38 +0200 Subject: [PATCH 101/638] Remove unused and outdated files and scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/GIFs/25Bytes.gif | Bin 35 -> 0 bytes advanced/GIFs/26Bytes.gif | Bin 26 -> 0 bytes advanced/GIFs/37Bytes.gif | Bin 37 -> 0 bytes advanced/GIFs/43Bytes.gif | Bin 43 -> 0 bytes advanced/Scripts/setupLCD.sh | 74 ----------------------------------- advanced/cmdline.txt | 1 - advanced/console-setup | 17 -------- 7 files changed, 92 deletions(-) delete mode 100644 advanced/GIFs/25Bytes.gif delete mode 100644 advanced/GIFs/26Bytes.gif delete mode 100644 advanced/GIFs/37Bytes.gif delete mode 100644 advanced/GIFs/43Bytes.gif delete mode 100755 advanced/Scripts/setupLCD.sh delete mode 100644 advanced/cmdline.txt delete mode 100644 advanced/console-setup diff --git a/advanced/GIFs/25Bytes.gif b/advanced/GIFs/25Bytes.gif deleted file mode 100644 index 472727f293859cf3859f33a6bfbb0de9b609c4fb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 35 ncmZ?wbhEHbWMp7uXkcXc|NlP&1A`6_1Nn>$3`|Tej11NQg`Nf5 diff --git a/advanced/GIFs/26Bytes.gif b/advanced/GIFs/26Bytes.gif deleted file mode 100644 index 264e471abd04356be068ad9cc24fc181fde8ae7a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 26 ccmZ?wbhEHbWMp7uVEE6V!vF+eHWPz2062yN6#xJL diff --git a/advanced/GIFs/37Bytes.gif b/advanced/GIFs/37Bytes.gif deleted file mode 100644 index b3aa80d843a929ce4e5af18912072ba4157c115b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 37 kcmZ?wbhEHbWMp7u00PCIER0-0rVfY$7Gq-aVPvod09bhgj{pDw diff --git a/advanced/GIFs/43Bytes.gif b/advanced/GIFs/43Bytes.gif deleted file mode 100644 index 9884f476b9c7cec495c94005574d7eb7a39475fa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 43 ucmZ?wbhEHbWMp7uXkcXc|NlP&1B2pE7Dg_hfDVuiq!<|(n3#MR8LR=x#0L!k diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh deleted file mode 100755 index b4746dea7d..0000000000 --- a/advanced/Scripts/setupLCD.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env bash -# Pi-hole: A black hole for Internet advertisements -# (c) 2017 Pi-hole, LLC (https://pi-hole.net) -# Network-wide ad blocking via your own hardware. -# -# Automatically configures the Pi to use the 2.8 LCD screen to display stats on it (also works over ssh) -# -# This file is copyright under the latest version of the EUPL. -# Please see LICENSE file for your rights under this license. - - - -############ FUNCTIONS ########### - -# Borrowed from adafruit-pitft-helper < borrowed from raspi-config -# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L324-L334 -getInitSys() { - if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then - SYSTEMD=1 - elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then - SYSTEMD=0 - else - echo "Unrecognized init system" - return 1 - fi -} - -# Borrowed from adafruit-pitft-helper: -# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 -autoLoginPiToConsole() { - if [ -e /etc/init.d/lightdm ]; then - if [ ${SYSTEMD} -eq 1 ]; then - systemctl set-default multi-user.target - ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service - else - update-rc.d lightdm disable 2 - sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" - fi - fi -} - -######### SCRIPT ########### -# Set pi to log in automatically -getInitSys -autoLoginPiToConsole - -# Set chronomter to run automatically when pi logs in -echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc -# OR -#$SUDO echo /usr/local/bin/chronometer.sh >> /etc/profile - -# Set up the LCD screen based on Adafruits instructions: -# https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install -curl -SLs https://apt.adafruit.com/add-pin | bash -apt-get -y install raspberrypi-bootloader -apt-get -y install adafruit-pitft-helper -adafruit-pitft-helper -t 28r - -# Download the cmdline.txt file that prevents the screen from going blank after a period of time -mv /boot/cmdline.txt /boot/cmdline.orig -curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt - -# Back up the original file and download the new one -mv /etc/default/console-setup /etc/default/console-setup.orig -curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup - -# Instantly apply the font change to the LCD screen -setupcon - -reboot - -# Start showing the stats on the screen by running the command on another tty: -# https://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty -#setsid sh -c 'exec /usr/local/bin/chronometer.sh <> /dev/tty1 >&0 2>&1' diff --git a/advanced/cmdline.txt b/advanced/cmdline.txt deleted file mode 100644 index 84d52b79b0..0000000000 --- a/advanced/cmdline.txt +++ /dev/null @@ -1 +0,0 @@ -dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait fbcon=map:10 fbcon=font:VGA8x8 consoleblank=0 diff --git a/advanced/console-setup b/advanced/console-setup deleted file mode 100644 index f12be6eb44..0000000000 --- a/advanced/console-setup +++ /dev/null @@ -1,17 +0,0 @@ -# CONFIGURATION FILE FOR SETUPCON - -# Consult the console-setup(5) manual page. - -ACTIVE_CONSOLES="/dev/tty[1-6]" - -CHARMAP="UTF-8" - -# For best results with the Adafruit 2.8 LCD and Pi-hole's chronometer -CODESET="guess" -FONTFACE="Terminus" -FONTSIZE="10x20" - -VIDEOMODE= - -# The following is an example how to use a braille font -# FONT='lat9w-08.psf.gz brl-8x8.psf' From 26107396245681208509876c97641fbc8eb91591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 29 Jul 2022 23:43:20 +0200 Subject: [PATCH 102/638] Indent installation/update complete message 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 06694506ae..88dc9040a3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2863,7 +2863,7 @@ main() { # Display where the log file is printf "\\n %b The install log is located at: %s\\n" "${INFO}" "${installLogLoc}" - printf "%b%s Complete! %b\\n" "${COL_LIGHT_GREEN}" "${INSTALL_TYPE}" "${COL_NC}" + printf " %b %b%s complete! %b\\n" "${TICK}" "${COL_LIGHT_GREEN}" "${INSTALL_TYPE}" "${COL_NC}" if [[ "${INSTALL_TYPE}" == "Update" ]]; then printf "\\n" From e29aa4e2058e9f4d76289b75cebdb6ab781e693d Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 19 Jul 2022 18:33:36 +0100 Subject: [PATCH 103/638] First things first... --- .github/workflows/test.yml | 2 +- test/_centos_7.Dockerfile | 19 ----------- test/centos7.epel.override | 7 ---- test/test_centos_7_support.py | 63 ----------------------------------- test/tox.centos_7.ini | 8 ----- 5 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 test/_centos_7.Dockerfile delete mode 100644 test/centos7.epel.override delete mode 100644 test/test_centos_7_support.py delete mode 100644 test/tox.centos_7.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e9a5d34d72..8d496bbaf0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,7 @@ jobs: strategy: fail-fast: false matrix: - distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_22, centos_7, centos_8, fedora_34] + distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_22, centos_8, fedora_34] env: DISTRO: ${{matrix.distro}} steps: diff --git a/test/_centos_7.Dockerfile b/test/_centos_7.Dockerfile deleted file mode 100644 index b97f167980..0000000000 --- a/test/_centos_7.Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM centos:7 -RUN yum install -y dialog git python3 - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -ADD test/centos7.epel.override /etc/yum/pluginconf.d/fastestmirror.conf -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/centos7.epel.override b/test/centos7.epel.override deleted file mode 100644 index 3451f17d4e..0000000000 --- a/test/centos7.epel.override +++ /dev/null @@ -1,7 +0,0 @@ -[main] -verbose = 0 -socket_timeout = 3 -enabled = 1 -hostfilepath = /var/cache/yum/timedhosts.txt -maxhostfileage = 1 -exclude=.edu diff --git a/test/test_centos_7_support.py b/test/test_centos_7_support.py deleted file mode 100644 index c7e75813a1..0000000000 --- a/test/test_centos_7_support.py +++ /dev/null @@ -1,63 +0,0 @@ -from .conftest import ( - tick_box, - info_box, - mock_command, -) - - -def test_php_upgrade_default_optout_centos_eq_7(host): - ''' - confirms the default behavior to opt-out of installing PHP7 from REMI - ''' - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - select_rpm_php - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in package_manager_detect.stdout - remi_package = host.package('remi-release') - assert not remi_package.is_installed - - -def test_php_upgrade_user_optout_centos_eq_7(host): - ''' - confirms installer behavior when user opt-out of installing PHP7 from REMI - (php not currently installed) - ''' - # dialog returns Cancel for user prompt - mock_command('dialog', {'*': ('', '1')}, host) - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - select_rpm_php - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in package_manager_detect.stdout - remi_package = host.package('remi-release') - assert not remi_package.is_installed - - -def test_php_upgrade_user_optin_centos_eq_7(host): - ''' - confirms installer behavior when user opt-in to installing PHP7 from REMI - (php not currently installed) - ''' - # dialog returns Continue for user prompt - mock_command('dialog', {'*': ('', '0')}, host) - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - select_rpm_php - ''') - assert 'opt-out' not in package_manager_detect.stdout - expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' - '(https://rpms.remirepo.net)') - assert expected_stdout in package_manager_detect.stdout - expected_stdout = tick_box + (' Remi\'s RPM repository has ' - 'been enabled for PHP7') - assert expected_stdout in package_manager_detect.stdout - remi_package = host.package('remi-release') - assert remi_package.is_installed diff --git a/test/tox.centos_7.ini b/test/tox.centos_7.ini deleted file mode 100644 index 319465dd1a..0000000000 --- a/test/tox.centos_7.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py38 - -[testenv] -whitelist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _centos_7.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py ./test_centos_7_support.py From 9c03915cb0fae856e41bb441d4f719c2f9eeeda9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 19 Jul 2022 18:53:41 +0100 Subject: [PATCH 104/638] Remove special Centos7 hand holds. Move the unsupported dialog out to a further if block so that a user may still continue to install on centos7 (provided they have the pre-requisites installed) Signed-off-by: Adam Warner --- automated install/basic-install.sh | 89 ++----------------------- test/test_centos_common_support.py | 100 ----------------------------- 2 files changed, 7 insertions(+), 182 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 88dc9040a3..c43d0334ee 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -376,37 +376,19 @@ package_manager_detect() { } select_rpm_php(){ + local unsupported_dialog=0 # If the host OS is Fedora, if grep -qiE 'fedora|fedberry' /etc/redhat-release; then # all required packages should be available by default with the latest fedora release : # continue # or if host OS is CentOS, elif grep -qiE 'centos|scientific|alma|rocky' /etc/redhat-release; then - # Pi-Hole currently supports CentOS 7+ with PHP7+ - SUPPORTED_CENTOS_VERSION=7 - SUPPORTED_CENTOS_PHP_VERSION=7 + SUPPORTED_CENTOS_VERSION=8 # Check current CentOS major release version CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) # Check if CentOS version is supported if [[ $CURRENT_CENTOS_VERSION -lt $SUPPORTED_CENTOS_VERSION ]]; then - printf " %b CentOS %s is not supported.\\n" "${CROSS}" "${CURRENT_CENTOS_VERSION}" - printf " Please update to CentOS release %s or later.\\n" "${SUPPORTED_CENTOS_VERSION}" - # exit the installer - exit - fi - # php-json is not required on CentOS 7 as it is already compiled into php - # verify via `php -m | grep json` - if [[ $CURRENT_CENTOS_VERSION -eq 7 ]]; then - # create a temporary array as arrays are not designed for use as mutable data structures - CENTOS7_PIHOLE_WEB_DEPS=() - for i in "${!PIHOLE_WEB_DEPS[@]}"; do - if [[ ${PIHOLE_WEB_DEPS[i]} != "php-json" ]]; then - CENTOS7_PIHOLE_WEB_DEPS+=( "${PIHOLE_WEB_DEPS[i]}" ) - fi - done - # re-assign the clean dependency array back to PIHOLE_WEB_DEPS - PIHOLE_WEB_DEPS=("${CENTOS7_PIHOLE_WEB_DEPS[@]}") - unset CENTOS7_PIHOLE_WEB_DEPS + unsupported_dialog=1 fi if rpm -qa | grep -qi 'epel'; then @@ -418,68 +400,11 @@ select_rpm_php(){ "${PKG_INSTALL[@]}" ${EPEL_PKG} printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" fi - - - # The default php on CentOS 7.x is 5.4 which is EOL - # Check if the version of PHP available via installed repositories is >= to PHP 7 - AVAILABLE_PHP_VERSION=$("${PKG_MANAGER}" info php | grep -i version | grep -o '[0-9]\+' | head -1) - if [[ $AVAILABLE_PHP_VERSION -ge $SUPPORTED_CENTOS_PHP_VERSION ]]; then - # Since PHP 7 is available by default, install via default PHP package names - : # do nothing as PHP is current - printf "PHP 7 is installed" - else - REMI_PKG="remi-release" - REMI_REPO="remi-php72" - REMI_REPO_URL="https://rpms.remirepo.net/enterprise/${REMI_PKG}-$(rpm -E '%{rhel}').rpm" - - # The PHP version available via default repositories is older than version 7 - dialog --no-shadow --keep-tite \ - --title "PHP 7 Update (recommended)" \ - --defaultno \ - --yesno "PHP 7.x is recommended for both security and language features.\ -\\n\\nWould you like to install PHP7 via Remi's RPM repository?\ -\\n\\nSee: https://rpms.remirepo.net for more information"\ - "${r}" "${c}" && result=0 || result=$? - - case ${result} in - "${DIALOG_OK}" ) - printf " %b Installing PHP 7 via Remi's RPM repository\\n" "${INFO}" - "${PKG_INSTALL[@]}" "yum-utils" &> /dev/null - if rpm -q ${REMI_PKG} &> /dev/null; then - printf " %b Remi's RPM repository is already installed\\n" "${TICK}" - else - printf " %b Enabling Remi's RPM repository (https://rpms.remirepo.net)\\n" "${INFO}" - yum -y install "${REMI_REPO_URL}" - printf " %b Installed %s from %s\\n" "${TICK}" "${REMI_PKG}" "${REMI_REPO_URL}" - printf " %b Remi's RPM repository has been enabled for PHP7\\n" "${TICK}" - fi - yum-config-manager --disable 'remi-php*' - yum-config-manager --enable "${REMI_REPO}" - - # trigger an install/update of PHP to ensure previous version of PHP is updated from REMI - if "${PKG_INSTALL[@]}" "php-cli" &> /dev/null; then - printf " %b PHP7 installed/updated via Remi's RPM repository\\n" "${TICK}" - else - printf " %b There was a problem updating to PHP7 via Remi's RPM repository\\n" "${CROSS}" - exit 1 - fi - ;; - - # User chose not to install PHP 7 via Remi's RPM repository - "${DIALOG_CANCEL}") - # User decided to NOT update PHP from REMI, attempt to install the default available PHP version - printf " %b User opt-out of PHP 7 upgrade on CentOS. Deprecated PHP may be in use.\\n" "${INFO}" - ;; - - # User closed the dialog window - "${DIALOG_ESC}") - printf " %b Escape pressed, exiting installer at Remi dialog window\\n" "${CROSS}" - exit 1 - ;; - esac - fi - else + unsupported_dialog=1 + fi + + if [[ ${unsupported_dialog} -eq 1 ]];then # Warn user of unsupported version of Fedora or CentOS dialog --no-shadow --keep-tite \ --title "Unsupported RPM based distribution" \ diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index ac408e92f2..2a9b38222d 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -7,23 +7,6 @@ ) -def test_release_supported_version_check_centos(host): - ''' - confirms installer exits on unsupported releases of CentOS - ''' - # modify /etc/redhat-release to mock an unsupported CentOS release - host.run('echo "CentOS Linux release 6.9" > /etc/redhat-release') - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - select_rpm_php - ''') - expected_stdout = cross_box + (' CentOS 6 is not supported.') - assert expected_stdout in package_manager_detect.stdout - expected_stdout = 'Please update to CentOS release 7 or later' - assert expected_stdout in package_manager_detect.stdout - - def test_enable_epel_repository_centos(host): ''' confirms the EPEL package repository is enabled when installed on CentOS @@ -40,86 +23,3 @@ def test_enable_epel_repository_centos(host): assert expected_stdout in package_manager_detect.stdout epel_package = host.package('epel-release') assert epel_package.is_installed - - -def test_php_version_lt_7_detected_upgrade_default_optout_centos(host): - ''' - confirms the default behavior to opt-out of upgrading to PHP7 from REMI - ''' - # first we will install the default php version to test installer behavior - php_install = host.run('yum install -y php') - assert php_install.rc == 0 - php_package = host.package('php') - default_centos_php_version = php_package.version.split('.')[0] - if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended - pytest.skip("Test deprecated . Detected default PHP version >= 7") - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - select_rpm_php - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in package_manager_detect.stdout - remi_package = host.package('remi-release') - assert not remi_package.is_installed - - -def test_php_version_lt_7_detected_upgrade_user_optout_centos(host): - ''' - confirms installer behavior when user opt-out to upgrade to PHP7 via REMI - ''' - # first we will install the default php version to test installer behavior - php_install = host.run('yum install -y php') - assert php_install.rc == 0 - php_package = host.package('php') - default_centos_php_version = php_package.version.split('.')[0] - if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended - pytest.skip("Test deprecated . Detected default PHP version >= 7") - # dialog returns Cancel for user prompt - mock_command('dialog', {'*': ('', '1')}, host) - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - select_rpm_php - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout in package_manager_detect.stdout - remi_package = host.package('remi-release') - assert not remi_package.is_installed - - -def test_php_version_lt_7_detected_upgrade_user_optin_centos(host): - ''' - confirms installer behavior when user opt-in to upgrade to PHP7 via REMI - ''' - # first we will install the default php version to test installer behavior - php_install = host.run('yum install -y php') - assert php_install.rc == 0 - php_package = host.package('php') - default_centos_php_version = php_package.version.split('.')[0] - if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended - pytest.skip("Test deprecated . Detected default PHP version >= 7") - # dialog returns Continue for user prompt - mock_command('dialog', {'*': ('', '0')}, host) - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - select_rpm_php - install_dependent_packages PIHOLE_WEB_DEPS[@] - ''') - expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' - 'Deprecated PHP may be in use.') - assert expected_stdout not in package_manager_detect.stdout - expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' - '(https://rpms.remirepo.net)') - assert expected_stdout in package_manager_detect.stdout - expected_stdout = tick_box + (' Remi\'s RPM repository has ' - 'been enabled for PHP7') - assert expected_stdout in package_manager_detect.stdout - remi_package = host.package('remi-release') - assert remi_package.is_installed - updated_php_package = host.package('php') - updated_php_version = updated_php_package.version.split('.')[0] - assert int(updated_php_version) == 7 From b6137584194c8811db26cad855e54ef9b454ffec Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 30 Jul 2022 16:19:40 +0100 Subject: [PATCH 105/638] rename select_rpm_php and simplify it to remove code no longer needed (discussed internally removing the unsupported dialog here to match behaviour on non rpm distros) Signed-off-by: Adam Warner --- automated install/basic-install.sh | 50 +++--------------------------- test/test_any_automated_install.py | 4 +-- test/test_centos_8_support.py | 6 ++-- test/test_centos_common_support.py | 2 +- test/test_fedora_support.py | 2 +- 5 files changed, 11 insertions(+), 53 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c43d0334ee..93db81496c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -375,22 +375,11 @@ package_manager_detect() { fi } -select_rpm_php(){ - local unsupported_dialog=0 - # If the host OS is Fedora, - if grep -qiE 'fedora|fedberry' /etc/redhat-release; then - # all required packages should be available by default with the latest fedora release - : # continue - # or if host OS is CentOS, - elif grep -qiE 'centos|scientific|alma|rocky' /etc/redhat-release; then - SUPPORTED_CENTOS_VERSION=8 +check_epel_repo_required(){ + # If the host OS is centos (or a derivative), + if grep -qiE 'centos|scientific|alma|rocky' /etc/redhat-release; then # Check current CentOS major release version CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) - # Check if CentOS version is supported - if [[ $CURRENT_CENTOS_VERSION -lt $SUPPORTED_CENTOS_VERSION ]]; then - unsupported_dialog=1 - fi - if rpm -qa | grep -qi 'epel'; then printf " %b EPEL repository already installed\\n" "${TICK}" else @@ -400,37 +389,6 @@ select_rpm_php(){ "${PKG_INSTALL[@]}" ${EPEL_PKG} printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" fi - else - unsupported_dialog=1 - fi - - if [[ ${unsupported_dialog} -eq 1 ]];then - # Warn user of unsupported version of Fedora or CentOS - dialog --no-shadow --keep-tite \ - --title "Unsupported RPM based distribution" \ - --defaultno \ - --no-button "Exit" \ - --yes-button "Continue" \ - --yesno "Would you like to continue installation on an unsupported RPM based distribution?\ -\\n\\nPlease ensure the following packages have been installed manually:\ -\\n\\n- lighttpd\\n- lighttpd-fastcgi\\n- PHP version 7+"\ - "${r}" "${c}" && result=0 || result=$? - - case ${result} in - # User chose to continue installation on an unsupported RPM based distribution - "${DIALOG_OK}") - printf " %b User opted to continue installation on an unsupported RPM based distribution.\\n" "${INFO}" - ;; - # User chose not to continue installation on an unsupported RPM based distribution - "${DIALOG_CANCEL}") - printf " %b User opted not to continue installation on an unsupported RPM based distribution.\\n" "${INFO}" - exit 1 - ;; - "${DIALOG_ESC}") - printf " %b Escape pressed, exiting installer at unsupported RPM based distribution dialog window\\n" "${CROSS}" - exit 1 - ;; - esac fi } @@ -2580,7 +2538,7 @@ main() { #In case of RPM based distro, select the proper PHP version if [[ "$PKG_MANAGER" == "yum" || "$PKG_MANAGER" == "dnf" ]] ; then - select_rpm_php + check_epel_repo_required fi diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 61849f54a9..15608050b7 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -1117,7 +1117,7 @@ def test_package_manager_has_pihole_deps(host): output = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - select_rpm_php + check_epel_repo_required install_dependent_packages ${PIHOLE_DEPS[@]} ''') @@ -1131,7 +1131,7 @@ def test_package_manager_has_web_deps(host): output = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - select_rpm_php + check_epel_repo_required install_dependent_packages ${PIHOLE_WEB_DEPS[@]} ''') diff --git a/test/test_centos_8_support.py b/test/test_centos_8_support.py index 9adbe841e4..63f49360df 100644 --- a/test/test_centos_8_support.py +++ b/test/test_centos_8_support.py @@ -13,7 +13,7 @@ def test_php_upgrade_default_continue_centos_gte_8(host): package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - select_rpm_php + check_epel_repo_required ''') unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' ' Deprecated PHP may be in use.') @@ -34,7 +34,7 @@ def test_php_upgrade_user_optout_skipped_centos_gte_8(host): package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - select_rpm_php + check_epel_repo_required ''') unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' ' Deprecated PHP may be in use.') @@ -55,7 +55,7 @@ def test_php_upgrade_user_optin_skipped_centos_gte_8(host): package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - select_rpm_php + check_epel_repo_required ''') assert 'opt-out' not in package_manager_detect.stdout unexpected_stdout = info_box + (' Enabling Remi\'s RPM repository ' diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index 2a9b38222d..4be29c65e9 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -14,7 +14,7 @@ def test_enable_epel_repository_centos(host): package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - select_rpm_php + check_epel_repo_required ''') expected_stdout = info_box + (' Enabling EPEL package repository ' '(https://fedoraproject.org/wiki/EPEL)') diff --git a/test/test_fedora_support.py b/test/test_fedora_support.py index 63fde90e0d..45a7c2eb72 100644 --- a/test/test_fedora_support.py +++ b/test/test_fedora_support.py @@ -6,7 +6,7 @@ def test_epel_and_remi_not_installed_fedora(host): package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - select_rpm_php + check_epel_repo_required ''') assert package_manager_detect.stdout == '' From fc2a564cc0bc2f50e6c1d4848c0dc7dce126e679 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 30 Jul 2022 16:24:05 +0100 Subject: [PATCH 106/638] remove tests no longer needed Signed-off-by: Adam Warner --- test/test_centos_8_support.py | 68 ----------------------------------- test/tox.centos_8.ini | 2 +- 2 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 test/test_centos_8_support.py diff --git a/test/test_centos_8_support.py b/test/test_centos_8_support.py deleted file mode 100644 index 63f49360df..0000000000 --- a/test/test_centos_8_support.py +++ /dev/null @@ -1,68 +0,0 @@ -from .conftest import ( - tick_box, - info_box, - mock_command, -) - - -def test_php_upgrade_default_continue_centos_gte_8(host): - ''' - confirms the latest version of CentOS continues / does not optout - (should trigger on CentOS7 only) - ''' - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - check_epel_repo_required - ''') - unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' - ' Deprecated PHP may be in use.') - assert unexpected_stdout not in package_manager_detect.stdout - # ensure remi was not installed on latest CentOS - remi_package = host.package('remi-release') - assert not remi_package.is_installed - - -def test_php_upgrade_user_optout_skipped_centos_gte_8(host): - ''' - confirms installer skips user opt-out of installing PHP7 from REMI on - latest CentOS (should trigger on CentOS7 only) - (php not currently installed) - ''' - # dialog dialog returns Cancel for user prompt - mock_command('dialog', {'*': ('', '1')}, host) - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - check_epel_repo_required - ''') - unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' - ' Deprecated PHP may be in use.') - assert unexpected_stdout not in package_manager_detect.stdout - # ensure remi was not installed on latest CentOS - remi_package = host.package('remi-release') - assert not remi_package.is_installed - - -def test_php_upgrade_user_optin_skipped_centos_gte_8(host): - ''' - confirms installer skips user opt-in to installing PHP7 from REMI on - latest CentOS (should trigger on CentOS7 only) - (php not currently installed) - ''' - # dialog dialog returns Continue for user prompt - mock_command('dialog', {'*': ('', '0')}, host) - package_manager_detect = host.run(''' - source /opt/pihole/basic-install.sh - package_manager_detect - check_epel_repo_required - ''') - assert 'opt-out' not in package_manager_detect.stdout - unexpected_stdout = info_box + (' Enabling Remi\'s RPM repository ' - '(https://rpms.remirepo.net)') - assert unexpected_stdout not in package_manager_detect.stdout - unexpected_stdout = tick_box + (' Remi\'s RPM repository has ' - 'been enabled for PHP7') - assert unexpected_stdout not in package_manager_detect.stdout - remi_package = host.package('remi-release') - assert not remi_package.is_installed diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini index c792628994..e94c24337f 100644 --- a/test/tox.centos_8.ini +++ b/test/tox.centos_8.ini @@ -5,4 +5,4 @@ envlist = py38 whitelist_externals = docker deps = -rrequirements.txt commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py ./test_centos_8_support.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py From 313c0ddf288bbbd9818606204bbb80dce75ddcf6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 30 Jul 2022 18:59:57 +0100 Subject: [PATCH 107/638] Update automated install/basic-install.sh Co-authored-by: yubiuser Signed-off-by: Adam Warner --- 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 93db81496c..4623ee88a4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -376,7 +376,7 @@ package_manager_detect() { } check_epel_repo_required(){ - # If the host OS is centos (or a derivative), + # If the host OS is centos (or a derivative), epel is required for lighttpd if grep -qiE 'centos|scientific|alma|rocky' /etc/redhat-release; then # Check current CentOS major release version CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) From 0e8c1ec023f5b684c48ef1853e0ab33dffc4afac Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 30 Jul 2022 19:03:46 +0100 Subject: [PATCH 108/638] Flip logic on epel check - if _not_ fedora, then (try to, depending on supported OS) install EPEL. Signed-off-by: Adam Warner --- 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 4623ee88a4..ba93cf26c5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -377,7 +377,7 @@ package_manager_detect() { check_epel_repo_required(){ # If the host OS is centos (or a derivative), epel is required for lighttpd - if grep -qiE 'centos|scientific|alma|rocky' /etc/redhat-release; then + if ! grep -qiE 'fedora|fedberry' /etc/redhat-release; then # Check current CentOS major release version CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) if rpm -qa | grep -qi 'epel'; then From 9028898ba7b21cc8ca3838e9e68b5f6fe178af22 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 30 Jul 2022 19:18:33 +0100 Subject: [PATCH 109/638] Move code from `check_epel_repo_required` into the rpm branch of the if check on package_manager_detect(), adjust tests to accommodate Signed-off-by: Adam Warner --- automated install/basic-install.sh | 38 ++++++++++++------------------ test/test_any_automated_install.py | 8 +++---- test/test_centos_common_support.py | 1 - test/test_fedora_support.py | 3 --- 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ba93cf26c5..4b1fde626c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -366,6 +366,21 @@ package_manager_detect() { LIGHTTPD_GROUP="lighttpd" LIGHTTPD_CFG="lighttpd.conf.fedora" + # If the host OS is centos (or a derivative), epel is required for lighttpd + if ! grep -qiE 'fedora|fedberry' /etc/redhat-release; then + # Check current CentOS major release version + CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) + if rpm -qa | grep -qi 'epel'; then + printf " %b EPEL repository already installed\\n" "${TICK}" + else + # CentOS requires the EPEL repository to gain access to Fedora packages + EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${CURRENT_CENTOS_VERSION}.noarch.rpm" + printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" + "${PKG_INSTALL[@]}" "${EPEL_PKG}" + printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" + fi + fi + # If neither apt-get or yum/dnf package managers were found else # we cannot install required packages @@ -375,23 +390,6 @@ package_manager_detect() { fi } -check_epel_repo_required(){ - # If the host OS is centos (or a derivative), epel is required for lighttpd - if ! grep -qiE 'fedora|fedberry' /etc/redhat-release; then - # Check current CentOS major release version - CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) - if rpm -qa | grep -qi 'epel'; then - printf " %b EPEL repository already installed\\n" "${TICK}" - else - # CentOS requires the EPEL repository to gain access to Fedora packages - EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${CURRENT_CENTOS_VERSION}.noarch.rpm" - printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" - "${PKG_INSTALL[@]}" ${EPEL_PKG} - printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" - fi - fi -} - # A function for checking if a directory is a git repository is_repo() { # Use a named, local variable instead of the vague $1, which is the first argument passed to this function @@ -2536,12 +2534,6 @@ main() { printf " %b Checking for / installing Required dependencies for this install script...\\n" "${INFO}" install_dependent_packages "${INSTALLER_DEPS[@]}" - #In case of RPM based distro, select the proper PHP version - if [[ "$PKG_MANAGER" == "yum" || "$PKG_MANAGER" == "dnf" ]] ; then - check_epel_repo_required - fi - - # If the setup variable file exists, if [[ -f "${setupVars}" ]]; then # if it's running unattended, diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 15608050b7..717f6ea2b2 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -1107,7 +1107,7 @@ def test_package_manager_has_installer_deps(host): install_dependent_packages ${INSTALLER_DEPS[@]} ''') - assert 'No package' not in output.stdout # centos7 still exits 0... + assert 'No package' not in output.stdout assert output.rc == 0 @@ -1117,11 +1117,10 @@ def test_package_manager_has_pihole_deps(host): output = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - check_epel_repo_required install_dependent_packages ${PIHOLE_DEPS[@]} ''') - assert 'No package' not in output.stdout # centos7 still exits 0... + assert 'No package' not in output.stdout assert output.rc == 0 @@ -1131,9 +1130,8 @@ def test_package_manager_has_web_deps(host): output = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - check_epel_repo_required install_dependent_packages ${PIHOLE_WEB_DEPS[@]} ''') - assert 'No package' not in output.stdout # centos7 still exits 0... + assert 'No package' not in output.stdout assert output.rc == 0 diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index 4be29c65e9..3497267ada 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -14,7 +14,6 @@ def test_enable_epel_repository_centos(host): package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - check_epel_repo_required ''') expected_stdout = info_box + (' Enabling EPEL package repository ' '(https://fedoraproject.org/wiki/EPEL)') diff --git a/test/test_fedora_support.py b/test/test_fedora_support.py index 45a7c2eb72..57a6c5c433 100644 --- a/test/test_fedora_support.py +++ b/test/test_fedora_support.py @@ -6,11 +6,8 @@ def test_epel_and_remi_not_installed_fedora(host): package_manager_detect = host.run(''' source /opt/pihole/basic-install.sh package_manager_detect - check_epel_repo_required ''') assert package_manager_detect.stdout == '' epel_package = host.package('epel-release') assert not epel_package.is_installed - remi_package = host.package('remi-release') - assert not remi_package.is_installed From 99b7f996e2b2f4ce3bbac440582c140b54d10682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 24 Jul 2022 14:36:15 +0200 Subject: [PATCH 110/638] Explicite set minor and patch version on used actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/codeql-analysis.yml | 8 ++++---- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 4 ++-- .github/workflows/test.yml | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6e5a08863d..60486f52a3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,16 +25,16 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v3.0.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v2.0.0 with: languages: 'python' - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v2.0.0 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v2.0.0 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index cd3c6ff6f4..67b73f2606 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v5 + - uses: actions/stale@v5.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index f79b69f2c4..fecc7022d7 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -11,7 +11,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v3.0.0. - name: Opening pull request id: pull uses: tretuna/sync-branches@1.4.0 @@ -20,7 +20,7 @@ jobs: FROM_BRANCH: 'master' TO_BRANCH: 'development' - name: Label the pull request to ignore for release note generation - uses: actions-ecosystem/action-add-labels@v1 + uses: actions-ecosystem/action-add-labels@v1.0.0 with: labels: internal repo: ${{ github.repository }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e9a5d34d72..ccc9a8fe63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v3.0.0 - name: Check scripts in repository are executable run: | @@ -30,7 +30,7 @@ jobs: ignore_words_file: .codespellignore - name: Get editorconfig-checker - uses: editorconfig-checker/action-editorconfig-checker@main + uses: editorconfig-checker/action-editorconfig-checker@v1.0.0 - name: Run editorconfig-checker run: editorconfig-checker @@ -49,10 +49,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v3.0.0 - name: Set up Python 3.8 - uses: actions/setup-python@v4 + uses: actions/setup-python@v4.0.0 with: python-version: 3.8 - From 8f3e6f1a50267299910907aaf76e4fa2f19c38fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 24 Jul 2022 14:52:07 +0200 Subject: [PATCH 111/638] CodeQl does not use .minor.patch version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 60486f52a3..ae536540b7 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -29,12 +29,12 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2.0.0 + uses: github/codeql-action/init@v2 with: languages: 'python' - name: Autobuild - uses: github/codeql-action/autobuild@v2.0.0 + uses: github/codeql-action/autobuild@v2 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2.0.0 + uses: github/codeql-action/analyze@v2 From a3ac1caac6149acbabf65eaa27690b7b43fa1d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 25 Jul 2022 22:30:53 +0200 Subject: [PATCH 112/638] Update actions to latest versions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 4 ++-- .github/workflows/test.yml | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ae536540b7..2c844337ff 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3.0.2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 67b73f2606..9e622f4a84 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v5.0.0 + - uses: actions/stale@v5.1.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index fecc7022d7..27d966d244 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -11,7 +11,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.0.0. + uses: actions/checkout@v3.0.2 - name: Opening pull request id: pull uses: tretuna/sync-branches@1.4.0 @@ -20,7 +20,7 @@ jobs: FROM_BRANCH: 'master' TO_BRANCH: 'development' - name: Label the pull request to ignore for release note generation - uses: actions-ecosystem/action-add-labels@v1.0.0 + uses: actions-ecosystem/action-add-labels@v1.1.0 with: labels: internal repo: ${{ github.repository }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ccc9a8fe63..82e9d54975 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3.0.2 - name: Check scripts in repository are executable run: | @@ -30,7 +30,7 @@ jobs: ignore_words_file: .codespellignore - name: Get editorconfig-checker - uses: editorconfig-checker/action-editorconfig-checker@v1.0.0 + uses: editorconfig-checker/action-editorconfig-checker@main # tag v1.0.0 is really out of date - name: Run editorconfig-checker run: editorconfig-checker @@ -49,10 +49,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.0.0 + uses: actions/checkout@v3.0.2 - name: Set up Python 3.8 - uses: actions/setup-python@v4.0.0 + uses: actions/setup-python@v4.1.0 with: python-version: 3.8 - From c6da627b7dede50f0698eab0128df42df7fb67d4 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 31 Jul 2022 18:52:03 +0100 Subject: [PATCH 113/638] Move release version check inside the else block Signed-off-by: Adam Warner --- automated install/basic-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4b1fde626c..adf03dea02 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -368,13 +368,13 @@ package_manager_detect() { # If the host OS is centos (or a derivative), epel is required for lighttpd if ! grep -qiE 'fedora|fedberry' /etc/redhat-release; then - # Check current CentOS major release version - CURRENT_CENTOS_VERSION=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) if rpm -qa | grep -qi 'epel'; then printf " %b EPEL repository already installed\\n" "${TICK}" else - # CentOS requires the EPEL repository to gain access to Fedora packages - EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${CURRENT_CENTOS_VERSION}.noarch.rpm" + local RH_RELEASE EPEL_PKG + # EPEL not already installed, add it based on the release version + RH_RELEASE=$(grep -oP '(?<= )[0-9]+(?=\.?)' /etc/redhat-release) + EPEL_PKG="https://dl.fedoraproject.org/pub/epel/epel-release-latest-${RH_RELEASE}.noarch.rpm" printf " %b Enabling EPEL package repository (https://fedoraproject.org/wiki/EPEL)\\n" "${INFO}" "${PKG_INSTALL[@]}" "${EPEL_PKG}" printf " %b Installed %s\\n" "${TICK}" "${EPEL_PKG}" From 6c7a28a7b562bb8b3772e751efbac8861e7b43c5 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 1 Aug 2022 18:38:15 +0100 Subject: [PATCH 114/638] Dont use bash keywords/programs as variable names --- gravity.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gravity.sh b/gravity.sh index 910940af1e..a35ff8d7b2 100755 --- a/gravity.sh +++ b/gravity.sh @@ -139,9 +139,9 @@ update_gravity_timestamp() { # Import domains from file and store them in the specified database table database_table_from_file() { # Define locals - local table source backup_path backup_file tmpFile type + local table src backup_path backup_file tmpFile list_type table="${1}" - source="${2}" + src="${2}" backup_path="${piholeDir}/migration_backup" backup_file="${backup_path}/$(basename "${2}")" tmpFile="$(mktemp -p "/tmp" --suffix=".gravity")" @@ -155,13 +155,13 @@ database_table_from_file() { # Special handling for domains to be imported into the common domainlist table if [[ "${table}" == "whitelist" ]]; then - type="0" + list_type="0" table="domainlist" elif [[ "${table}" == "blacklist" ]]; then - type="1" + list_type="1" table="domainlist" elif [[ "${table}" == "regex" ]]; then - type="3" + list_type="3" table="domainlist" fi @@ -174,9 +174,9 @@ database_table_from_file() { rowid+=1 fi - # Loop over all domains in ${source} file + # Loop over all domains in ${src} file # Read file line by line - grep -v '^ *#' < "${source}" | while IFS= read -r domain + grep -v '^ *#' < "${src}" | while IFS= read -r domain do # Only add non-empty lines if [[ -n "${domain}" ]]; then @@ -185,10 +185,10 @@ database_table_from_file() { echo "${rowid},\"${domain}\",${timestamp}" >> "${tmpFile}" elif [[ "${table}" == "adlist" ]]; then # Adlist table format - echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\",,0,0,0" >> "${tmpFile}" + echo "${rowid},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${src}\",,0,0,0" >> "${tmpFile}" else # White-, black-, and regexlist table format - echo "${rowid},${type},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${source}\"" >> "${tmpFile}" + echo "${rowid},${list_type},\"${domain}\",1,${timestamp},${timestamp},\"Migrated from ${src}\"" >> "${tmpFile}" fi rowid+=1 fi @@ -201,14 +201,14 @@ database_table_from_file() { status="$?" if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to fill table ${table}${type} in database ${gravityDBfile}\\n ${output}" + echo -e "\\n ${CROSS} Unable to fill table ${table}${list_type} in database ${gravityDBfile}\\n ${output}" gravity_Cleanup "error" fi # Move source file to backup directory, create directory if not existing mkdir -p "${backup_path}" - mv "${source}" "${backup_file}" 2> /dev/null || \ - echo -e " ${CROSS} Unable to backup ${source} to ${backup_path}" + mv "${src}" "${backup_file}" 2> /dev/null || \ + echo -e " ${CROSS} Unable to backup ${src} to ${backup_path}" # Delete tmpFile rm "${tmpFile}" > /dev/null 2>&1 || \ From 64dc002c3f64f890d8fe80b23862b19e7b5ec80c Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 1 Aug 2022 20:38:31 +0100 Subject: [PATCH 115/638] Same per @rdwebdesign suggestion. Signed-off-by: Adam Warner --- gravity.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gravity.sh b/gravity.sh index a35ff8d7b2..6f96b8457e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -719,10 +719,10 @@ gravity_DownloadBlocklistFromUrl() { # Parse source files into domains format gravity_ParseFileIntoDomains() { - local source="${1}" destination="${2}" firstLine + local src="${1}" destination="${2}" firstLine # Determine if we are parsing a consolidated list - #if [[ "${source}" == "${piholeDir}/${matterAndLight}" ]]; then + #if [[ "${src}" == "${piholeDir}/${matterAndLight}" ]]; then # Remove comments and print only the domain name # Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous # This helps with that and makes it easier to read @@ -733,7 +733,7 @@ gravity_ParseFileIntoDomains() { # 4) Remove lines containing "/" # 5) Remove leading tabs, spaces, etc. # 6) Delete lines not matching domain names - < "${source}" tr -d '\r' | \ + < "${src}" tr -d '\r' | \ tr '[:upper:]' '[:lower:]' | \ sed 's/\s*#.*//g' | \ sed -r '/(\/).*$/d' | \ @@ -745,16 +745,16 @@ gravity_ParseFileIntoDomains() { # Individual file parsing: Keep comments, while parsing domains from each line # We keep comments to respect the list maintainer's licensing - read -r firstLine < "${source}" + read -r firstLine < "${src}" # Determine how to parse individual source file formats if [[ "${firstLine,,}" =~ (adblock|ublock|^!) ]]; then # Compare $firstLine against lower case words found in Adblock lists echo -e " ${CROSS} Format: Adblock (list type not supported)" - elif grep -q "^address=/" "${source}" &> /dev/null; then + elif grep -q "^address=/" "${src}" &> /dev/null; then # Parse Dnsmasq format lists echo -e " ${CROSS} Format: Dnsmasq (list type not supported)" - elif grep -q -E "^https?://" "${source}" &> /dev/null; then + elif grep -q -E "^https?://" "${src}" &> /dev/null; then # Parse URL list if source file contains "http://" or "https://" # Scanning for "^IPv4$" is too slow with large (1M) lists on low-end hardware echo -ne " ${INFO} Format: URL" @@ -770,13 +770,13 @@ gravity_ParseFileIntoDomains() { /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ { next } # Print if nonempty length { print } - ' "${source}" 2> /dev/null > "${destination}" + ' "${src}" 2> /dev/null > "${destination}" chmod 644 "${destination}" echo -e "${OVER} ${TICK} Format: URL" else # Default: Keep hosts/domains file in same format as it was downloaded - output=$( { mv "${source}" "${destination}"; } 2>&1 ) + output=$( { mv "${src}" "${destination}"; } 2>&1 ) chmod 644 "${destination}" if [[ ! -e "${destination}" ]]; then From 0b81dd387bbc4bf060a20b967aad882b485d6a03 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 1 Aug 2022 20:56:37 +0100 Subject: [PATCH 116/638] type -> list_type per @yubiuser suggestion Signed-off-by: Adam Warner --- advanced/Scripts/query.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 8f7bfea42d..5f25e5be7e 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -34,7 +34,7 @@ source "${colfile}" # Scan an array of files for matching strings scanList(){ # Escape full stops - local domain="${1}" esc_domain="${1//./\\.}" lists="${2}" type="${3:-}" + local domain="${1}" esc_domain="${1//./\\.}" lists="${2}" list_type="${3:-}" # Prevent grep from printing file path cd "$piholeDir" || exit 1 @@ -43,7 +43,7 @@ scanList(){ export LC_CTYPE=C # /dev/null forces filename to be printed when only one list has been generated - case "${type}" in + case "${list_type}" in "exact" ) grep -i -E -l "(^|(?/dev/null;; # Iterate through each regexp and check whether it matches the domainQuery # If it does, print the matching regexp and continue looping @@ -99,10 +99,10 @@ if [[ -n "${str:-}" ]]; then fi scanDatabaseTable() { - local domain table type querystr result extra + local domain table list_type querystr result extra domain="$(printf "%q" "${1}")" table="${2}" - type="${3:-}" + list_type="${3:-}" # As underscores are legitimate parts of domains, we escape them when using the LIKE operator. # Underscores are SQLite wildcards matching exactly one character. We obviously want to suppress this @@ -115,8 +115,8 @@ scanDatabaseTable() { esac else case "${exact}" in - "exact" ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${type}' AND domain = '${domain}'";; - * ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${type}' AND domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; + "exact" ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain = '${domain}'";; + * ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; esac fi @@ -158,13 +158,13 @@ scanDatabaseTable() { } scanRegexDatabaseTable() { - local domain list + local domain list list_type domain="${1}" list="${2}" - type="${3:-}" + list_type="${3:-}" # Query all regex from the corresponding database tables - mapfile -t regexList < <(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT domain FROM domainlist WHERE type = ${type}" 2> /dev/null) + mapfile -t regexList < <(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT domain FROM domainlist WHERE type = ${list_type}" 2> /dev/null) # If we have regexps to process if [[ "${#regexList[@]}" -ne 0 ]]; then From 3327df8d9c1822114a68a214ec911e9efb0e8143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 4 Aug 2022 14:47:43 +0200 Subject: [PATCH 117/638] Ensure user defined FTL_PID_FILE and FTL_PORT_FILE dirs are created on startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Templates/pihole-FTL.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 7346dc206a..7a541d0d70 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -30,8 +30,8 @@ start() { else # Touch files to ensure they exist (create if non-existing, preserve if existing) mkdir -pm 0755 /run/pihole /var/log/pihole - [ ! -f "${FTL_PID_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" - [ ! -f "${FTL_PORT_FILE}" ] && install -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" + [ ! -f "${FTL_PID_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" + [ ! -f "${FTL_PORT_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" [ ! -f /var/log/pihole/FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log [ ! -f /var/log/pihole/pihole.log ] && install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases From 989c52ef241baa110d6a588fa42348384453f702 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 4 Aug 2022 17:20:39 -0700 Subject: [PATCH 118/638] Exit with return code if ftl does not start Signed-off-by: Dan Schaper --- advanced/Templates/pihole-FTL.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 7a541d0d70..46e5c1f2dd 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -58,10 +58,10 @@ start() { fi if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then - su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole + su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole || exit $? else echo "Warning: Starting pihole-FTL as root because setting capabilities is not supported on this system" - /usr/bin/pihole-FTL + /usr/bin/pihole-FTL || exit $? fi echo fi From 6062df092382a3179a33921b48694b8bb087a9b4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Aug 2022 10:07:28 +0000 Subject: [PATCH 119/638] Bump actions/stale from 5.1.0 to 5.1.1 Bumps [actions/stale](https://github.com/actions/stale) from 5.1.0 to 5.1.1. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/v5.1.1/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v5.1.0...v5.1.1) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 9e622f4a84..c0f64bb41d 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v5.1.0 + - uses: actions/stale@v5.1.1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 From e50438dc11fb1ae26d40bdbcce326e5eddff3ad2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Aug 2022 10:07:31 +0000 Subject: [PATCH 120/638] Bump actions/setup-python from 4.1.0 to 4.2.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.1.0 to 4.2.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.1.0...v4.2.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 177a24ba62..835be1664f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,7 +52,7 @@ jobs: uses: actions/checkout@v3.0.2 - name: Set up Python 3.8 - uses: actions/setup-python@v4.1.0 + uses: actions/setup-python@v4.2.0 with: python-version: 3.8 - From 9e2e0019fbcd8503a58d9388c2152b369319b79e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Aug 2022 10:22:39 +0000 Subject: [PATCH 121/638] Bump actions-ecosystem/action-add-labels from 1.1.0 to 1.1.3 Bumps [actions-ecosystem/action-add-labels](https://github.com/actions-ecosystem/action-add-labels) from 1.1.0 to 1.1.3. - [Release notes](https://github.com/actions-ecosystem/action-add-labels/releases) - [Commits](https://github.com/actions-ecosystem/action-add-labels/compare/v1.1.0...v1.1.3) --- updated-dependencies: - dependency-name: actions-ecosystem/action-add-labels dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-back-to-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 27d966d244..dd66ebdca3 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -20,7 +20,7 @@ jobs: FROM_BRANCH: 'master' TO_BRANCH: 'development' - name: Label the pull request to ignore for release note generation - uses: actions-ecosystem/action-add-labels@v1.1.0 + uses: actions-ecosystem/action-add-labels@v1.1.3 with: labels: internal repo: ${{ github.repository }} From f418481b9f378cac1a9dc7509417a516ad5f967c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 6 Aug 2022 15:35:01 +0200 Subject: [PATCH 122/638] Add security-related headers to Pi-hole web interface Signed-off-by: DL6ER --- advanced/lighttpd.conf.debian | 15 +++++++++++++-- advanced/lighttpd.conf.fedora | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 4231a0c993..4545bb2e8f 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -78,10 +78,21 @@ include_shell "find /etc/lighttpd/conf-enabled -name '*.conf' -a ! -name 'letsen # If the URL starts with /admin, it is the Web interface $HTTP["url"] =~ "^/admin/" { - # Create a response header for debugging using curl -I + # X-Pi-hole is a response header for debugging using curl -I + # X-Frame-Options prevents clickjacking attacks and helps ensure your content is not embedded into other sites via < frame >, < iframe > or < object >. + # X-XSS-Protection sets the configuration for the cross-site scripting filters built into most browsers. This is important because it tells the browser to block the response if a malicious script has been inserted from a user input. + # X-Content-Type-Options stops a browser from trying to MIME-sniff the content type and forces it to stick with the declared content-type. This is important because the browser will only load external resources if their content-type matches what is expected, and not malicious hidden code. + # Content-Security-Policy tells the browser where resources are allowed to be loaded and if it’s allowed to parse/run inline styles or Javascript. This is important because it prevents content injection attacks, such as Cross Site Scripting (XSS). + # X-Permitted-Cross-Domain-Policies is an XML document that grants a web client, such as Adobe Flash Player or Adobe Acrobat (though not necessarily limited to these), permission to handle data across domains. + # Referrer-Policy allows control/restriction of the amount of information present in the referral header for links away from your page—the URL path or even if the header is sent at all. setenv.add-response-header = ( "X-Pi-hole" => "The Pi-hole Web interface is working!", - "X-Frame-Options" => "DENY" + "X-Frame-Options" => "DENY", + "X-XSS-Protection" => "1; mode=block", + "X-Content-Type-Options" => "nosniff", + "Content-Security-Policy" => "default-src 'self' 'unsafe-inline';", + "X-Permitted-Cross-Domain-Policies" => "none", + "Referrer-Policy" => "same-origin" ) } diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index c3c949863a..12930302e4 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -86,10 +86,21 @@ fastcgi.server = ( # If the URL starts with /admin, it is the Web interface $HTTP["url"] =~ "^/admin/" { - # Create a response header for debugging using curl -I + # X-Pi-hole is a response header for debugging using curl -I + # X-Frame-Options prevents clickjacking attacks and helps ensure your content is not embedded into other sites via < frame >, < iframe > or < object >. + # X-XSS-Protection sets the configuration for the cross-site scripting filters built into most browsers. This is important because it tells the browser to block the response if a malicious script has been inserted from a user input. + # X-Content-Type-Options stops a browser from trying to MIME-sniff the content type and forces it to stick with the declared content-type. This is important because the browser will only load external resources if their content-type matches what is expected, and not malicious hidden code. + # Content-Security-Policy tells the browser where resources are allowed to be loaded and if it’s allowed to parse/run inline styles or Javascript. This is important because it prevents content injection attacks, such as Cross Site Scripting (XSS). + # X-Permitted-Cross-Domain-Policies is an XML document that grants a web client, such as Adobe Flash Player or Adobe Acrobat (though not necessarily limited to these), permission to handle data across domains. + # Referrer-Policy allows control/restriction of the amount of information present in the referral header for links away from your page—the URL path or even if the header is sent at all. setenv.add-response-header = ( "X-Pi-hole" => "The Pi-hole Web interface is working!", - "X-Frame-Options" => "DENY" + "X-Frame-Options" => "DENY", + "X-XSS-Protection" => "1; mode=block", + "X-Content-Type-Options" => "nosniff", + "Content-Security-Policy" => "default-src 'self' 'unsafe-inline';", + "X-Permitted-Cross-Domain-Policies" => "none", + "Referrer-Policy" => "same-origin" ) } From 7320c10dd33f151ebc4cafa6a8b3e455e8a67a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 6 Aug 2022 21:44:19 +0200 Subject: [PATCH 123/638] Fix git indention 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index adf03dea02..8bf2315552 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2126,7 +2126,7 @@ checkout_pull_branch() { git_pull=$(git pull --no-rebase || return 1) - if [[ "$git_pull" == *"up-to-date"* ]]; then + if [[ "$git_pull" == *"up to date"* ]]; then printf " %b %s\\n" "${INFO}" "${git_pull}" else printf "%s\\n" "$git_pull" From c7410b0be966b53a20a8517b91503afe63ab6b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 7 Aug 2022 15:50:05 +0200 Subject: [PATCH 124/638] Always indent 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 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8bf2315552..f141df41bd 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2126,11 +2126,7 @@ checkout_pull_branch() { git_pull=$(git pull --no-rebase || return 1) - if [[ "$git_pull" == *"up to date"* ]]; then - printf " %b %s\\n" "${INFO}" "${git_pull}" - else - printf "%s\\n" "$git_pull" - fi + printf " %b %s\\n" "${INFO}" "${git_pull}" return 0 } From d77677312cb5f1a1db48f1aeba898362e70383f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 8 Aug 2022 13:52:20 +0200 Subject: [PATCH 125/638] Extend FTL information in debug log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1707b87229..e7f3cd488f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -332,17 +332,34 @@ compare_local_version_to_git_version() { check_ftl_version() { local ftl_name="FTL" + local FTL_VERSION FTL_COMMIT FTL_BRANCH echo_current_diagnostic "${ftl_name} version" # Use the built in command to check FTL's version - FTL_VERSION=$(pihole-FTL version) + FTL_VERSION=$(pihole-FTL -vv | grep -m 1 Version | awk '{printf $2}') + FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') + FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') + # Compare the current FTL version to the remote version if [[ "${FTL_VERSION}" == "$(pihole -v | awk '/FTL/ {print $6}' | cut -d ')' -f1)" ]]; then # If they are the same, FTL is up-to-date log_write "${TICK} ${ftl_name}: ${COL_GREEN}${FTL_VERSION}${COL_NC}" else # If not, show it in yellow, signifying there is an update - log_write "${TICK} ${ftl_name}: ${COL_YELLOW}${FTL_VERSION}${COL_NC} (${FAQ_UPDATE_PI_HOLE})" + log_write "${INFO} ${ftl_name}: ${COL_YELLOW}${FTL_VERSION}${COL_NC} (${FAQ_UPDATE_PI_HOLE})" fi + + # If they use the master branch, they are on the stable codebase + if [[ "${FTL_BRANCH}" == "master" ]]; then + # so the color of the text is green + log_write "${INFO} Branch: ${COL_GREEN}${FTL_BRANCH}${COL_NC}" + # If it is any other branch, they are in a development branch + else + # So show that in yellow, signifying it's something to take a look at, but not a critical error + log_write "${INFO} Branch: ${COL_YELLOW}${FTL_BRANCH}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" + fi + + # echo the current commit + log_write "${INFO} Commit: ${FTL_COMMIT}" } # Checks the core version of the Pi-hole codebase From c78cf82fc6dc2f4d612ce4c27a36b2f3a26353fd Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 5 Oct 2021 15:42:06 +0100 Subject: [PATCH 126/638] no need to declare $viewPort Signed-off-by: Adam Warner --- advanced/index.php | 369 +---------------------------- automated install/basic-install.sh | 18 +- 2 files changed, 21 insertions(+), 366 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index cf0ab854b0..3b320a3fb7 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -11,15 +11,6 @@ // Remove external ipv6 brackets if any $serverName = preg_replace('/^\[(.*)\]$/', '${1}', $serverName); -if (!is_file("/etc/pihole/setupVars.conf")) - die("[ERROR] File not found: /etc/pihole/setupVars.conf"); - -// Get values from setupVars.conf -$setupVars = parse_ini_file("/etc/pihole/setupVars.conf"); -$svPasswd = !empty($setupVars["WEBPASSWORD"]); -$svEmail = (!empty($setupVars["ADMIN_EMAIL"]) && filter_var($setupVars["ADMIN_EMAIL"], FILTER_VALIDATE_EMAIL)) ? $setupVars["ADMIN_EMAIL"] : ""; -unset($setupVars); - // Set landing page location, found within /var/www/html/ $landPage = "../landing.php"; @@ -34,21 +25,6 @@ array_push($authorizedHosts, $_SERVER["VIRTUAL_HOST"]); } -// Set which extension types render as Block Page (Including "" for index.ext) -$validExtTypes = array("asp", "htm", "html", "php", "rss", "xml", ""); - -// Get extension of current URL -$currentUrlExt = pathinfo($_SERVER["REQUEST_URI"], PATHINFO_EXTENSION); - -// Set mobile friendly viewport -$viewPort = ''; - -// Set response header -function setHeader($type = "x") { - header("X-Pi-hole: A black hole for Internet advertisements."); - if (isset($type) && $type === "js") header("Content-Type: application/javascript"); -} - // Determine block page type if ($serverName === "pi.hole" || (!empty($_SERVER["VIRTUAL_HOST"]) && $serverName === $_SERVER["VIRTUAL_HOST"])) { @@ -71,347 +47,26 @@ function setHeader($type = "x") { - $viewPort + ● $serverName - - + + -
- Pi-hole logo -

Pi-hole: Your black hole for Internet advertisements

- Did you mean to go to the admin panel? -
+ Pi-hole logo +
+

Pi-hole: Your black hole for Internet advertisements

+ Did you mean to go to the admin panel? EOT; exit($splashPage); -} elseif ($currentUrlExt === "js") { - // Serve Pi-hole JavaScript for blocked domains requesting JS - exit(setHeader("js").'var x = "Pi-hole: A black hole for Internet advertisements."'); -} elseif (strpos($_SERVER["REQUEST_URI"], "?") !== FALSE && isset($_SERVER["HTTP_REFERER"])) { - // Serve blank image upon receiving REQUEST_URI w/ query string & HTTP_REFERRER - // e.g: An iframe of a blocked domain - exit(setHeader().' - - - - - - - - '); -} elseif (!in_array($currentUrlExt, $validExtTypes) || substr_count($_SERVER["REQUEST_URI"], "?")) { - // Serve SVG upon receiving non $validExtTypes URL extension or query string - // e.g: Not an iframe of a blocked domain, such as when browsing to a file/query directly - // QoL addition: Allow the SVG to be clicked on in order to quickly show the full Block Page - $blockImg = ' - - - - - Blocked by Pi-hole - - - '; - exit(setHeader()." - - - - $viewPort - - $blockImg - "); } -/* Start processing Block Page from here */ - -// Define admin email address text based off $svEmail presence -$bpAskAdmin = !empty($svEmail) ? '' : ""; - -// 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 adlists enabled"); - -// Get total number of blocklists (Including Whitelist, Blacklist & Wildcard lists) -$adlistsCount = count($adlistsUrls) + 3; - -// Set query timeout -ini_set("default_socket_timeout", 3); - -// Logic for querying blocklists -function queryAds($serverName) { - // Determine the time it takes while querying adlists - $preQueryTime = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]; - - // Determine which protocol should be used - $protocol = "http"; - if ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || - (isset($_SERVER['REQUEST_SCHEME']) && $_SERVER['REQUEST_SCHEME'] === 'https') || - (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') - ) { - $protocol = "https"; - } - - // Format the URL - $queryAdsURL = sprintf( - "%s://127.0.0.1:%s/admin/scripts/pi-hole/php/queryads.php?domain=%s&bp", - $protocol, - $_SERVER["SERVER_PORT"], - $serverName - ); - - // Request the file and receive the response - $queryAdsFile = file($queryAdsURL, FILE_IGNORE_NEW_LINES); - - // $queryAdsFile must be an array (to avoid PHP 8.0+ error) - if (is_array($queryAdsFile)) { - $queryAds = array_values(array_filter(preg_replace("/data:\s+/", "", $queryAdsFile))); - } else { - // if not an array, return an error message - return array("0" => "error", "1" => "
(".gettype($queryAdsFile).")
".print_r($queryAdsFile, true)); - } +exit(header("HTTP/1.1 404 Not Found")); - $queryTime = sprintf("%.0f", (microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]) - $preQueryTime); - - // Exception Handling - try { - // Define Exceptions - if (strpos($queryAds[0], "No exact results") !== FALSE) { - // Return "none" into $queryAds array - return array("0" => "none"); - } else if ($queryTime >= ini_get("default_socket_timeout")) { - // Connection Timeout - throw new Exception ("Connection timeout (".ini_get("default_socket_timeout")."s)"); - } elseif (!strpos($queryAds[0], ".") !== false) { - // Unknown $queryAds output - throw new Exception ("Unhandled error message ($queryAds[0])"); - } - return $queryAds; - } catch (Exception $e) { - // Return exception as array - return array("0" => "error", "1" => $e->getMessage()); - } -} - -// Get results of queryads.php exact search -$queryAds = queryAds($serverName); - -// Pass error through to Block Page -if ($queryAds[0] === "error") - die("[ERROR]: Unable to parse results from queryads.php: ".$queryAds[1].""); - -// Count total number of matching blocklists -$featuredTotal = count($queryAds); - -// Place results into key => value array -$queryResults = null; -foreach ($queryAds as $str) { - $value = explode(" ", $str); - @$queryResults[$value[0]] .= "$value[1]"; -} - -// Determine if domain has been blacklisted, whitelisted, wildcarded or CNAME blocked -if (strpos($queryAds[0], "blacklist") !== FALSE) { - $notableFlagClass = "blacklist"; - $adlistsUrls = array("π" => substr($queryAds[0], 2)); -} elseif (strpos($queryAds[0], "whitelist") !== FALSE) { - $notableFlagClass = "noblock"; - $adlistsUrls = array("π" => substr($queryAds[0], 2)); - $wlInfo = "recentwl"; -} elseif (strpos($queryAds[0], "wildcard") !== FALSE) { - $notableFlagClass = "wildcard"; - $adlistsUrls = array("π" => substr($queryAds[0], 2)); -} elseif ($queryAds[0] === "none") { - $featuredTotal = "0"; - $notableFlagClass = "noblock"; - - // QoL addition: Determine appropriate info message if CNAME exists - // Suggests to the user that $serverName has a CNAME (alias) that may be blocked - $dnsRecord = dns_get_record("$serverName")[0]; - if (array_key_exists("target", $dnsRecord)) { - $wlInfo = $dnsRecord['target']; - } else { - $wlInfo = "unknown"; - } -} - -// Set #bpOutput notification -$wlOutputClass = (isset($wlInfo) && $wlInfo === "recentwl") ? $wlInfo : "hidden"; -$wlOutput = (isset($wlInfo) && $wlInfo !== "recentwl") ? "$wlInfo" : ""; - -// Get Pi-hole Core version -$phVersion = exec("cd /etc/.pihole/ && git describe --long --tags"); - -// Print $execTime on development branches -// Testing for - is marginally faster than "git rev-parse --abbrev-ref HEAD" -if (explode("-", $phVersion)[1] != "0") - $execTime = microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]; - -// Please Note: Text is added via CSS to allow an admin to provide a localized -// language without the need to edit this file - -setHeader(); ?> - - - - - - - - - - - ● <?=$serverName ?> - - - -
-
-

- -

-
- - -
-
-
-

Open Source Ad Blocker - Designed for Raspberry Pi -

-
- -
- -
- -
-
- -
-
-
-

-
- -
-

-
- -
-
- - 0) echo ''; ?> -
- -
- -
 0) foreach ($queryResults as $num => $value) { echo "[$num]:$adlistsUrls[$num]\n"; } ?>
- -
- - - -
-
-
- -
. Pi-hole ()
-
- - - diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f141df41bd..6b58afdfde 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -82,7 +82,7 @@ PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update versi PI_HOLE_INSTALL_DIR="/opt/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole" PI_HOLE_BIN_DIR="/usr/local/bin" -PI_HOLE_BLOCKPAGE_DIR="${webroot}/pihole" +PI_HOLE_404_DIR="${webroot}/pihole" if [ -z "$useUpdateVars" ]; then useUpdateVars=false fi @@ -1662,18 +1662,18 @@ install_dependent_packages() { # Install the Web interface dashboard installPiholeWeb() { - printf "\\n %b Installing blocking page...\\n" "${INFO}" + printf "\\n %b Installing 404 page...\\n" "${INFO}" - local str="Creating directory for blocking page, and copying files" + local str="Creating directory for 404 page, and copying files" printf " %b %s..." "${INFO}" "${str}" - # Install the directory, - install -d -m 0755 ${PI_HOLE_BLOCKPAGE_DIR} - # and the blockpage - install -D -m 644 ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* ${PI_HOLE_BLOCKPAGE_DIR}/ + # Install the directory + install -d -m 0755 ${PI_HOLE_404_DIR} + # and the 404 handler + install -D -m 644 ${PI_HOLE_LOCAL_REPO}/advanced/index.php ${PI_HOLE_404_DIR}/ # Remove superseded file - if [[ -e "${PI_HOLE_BLOCKPAGE_DIR}/index.js" ]]; then - rm "${PI_HOLE_BLOCKPAGE_DIR}/index.js" + if [[ -e "${PI_HOLE_404_DIR}/index.js" ]]; then + rm "${PI_HOLE_404_DIR}/index.js" fi printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" From 5d5a85b7b6a79df04f7eaa4177608153dca02401 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 5 Oct 2021 16:36:33 +0100 Subject: [PATCH 127/638] X-Pi-hole removed from blocking page... Signed-off-by: Adam Warner --- advanced/Scripts/piholeDebug.sh | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1707b87229..79452f0032 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -797,29 +797,13 @@ check_x_headers() { # server is operating correctly echo_current_diagnostic "Dashboard and block page" # Use curl -I to get the header and parse out just the X-Pi-hole one - local block_page - block_page=$(curl -Is localhost | awk '/X-Pi-hole/' | tr -d '\r') - # Do it for the dashboard as well, as the header is different than above local dashboard dashboard=$(curl -Is localhost/admin/ | awk '/X-Pi-hole/' | tr -d '\r') # Store what the X-Header should be in variables for comparison later - local block_page_working - block_page_working="X-Pi-hole: A black hole for Internet advertisements." local dashboard_working dashboard_working="X-Pi-hole: The Pi-hole Web interface is working!" - local full_curl_output_block_page - full_curl_output_block_page="$(curl -Is localhost)" local full_curl_output_dashboard full_curl_output_dashboard="$(curl -Is localhost/admin/)" - # If the X-header found by curl matches what is should be, - if [[ $block_page == "$block_page_working" ]]; then - # display a success message - log_write "$TICK Block page X-Header: ${COL_GREEN}${block_page}${COL_NC}" - else - # Otherwise, show an error - log_write "$CROSS Block page X-Header: ${COL_RED}X-Header does not match or could not be retrieved.${COL_NC}" - log_write "${COL_RED}${full_curl_output_block_page}${COL_NC}" - fi # Same logic applies to the dashboard as above, if the X-Header matches what a working system should have, if [[ $dashboard == "$dashboard_working" ]]; then From 5816f495f46ce9373e19469905d30b56a7958a20 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 26 Jul 2022 19:45:03 +0100 Subject: [PATCH 128/638] Fix test_installPiholeWeb_fresh_install_no_errors and test_installPihole_fresh_install_readableBlockpage Signed-off-by: Adam Warner --- test/test_any_automated_install.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 717f6ea2b2..c26380a1dd 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -116,9 +116,9 @@ def test_installPiholeWeb_fresh_install_no_errors(host): source /opt/pihole/basic-install.sh installPiholeWeb ''') - expected_stdout = info_box + ' Installing blocking page...' + expected_stdout = info_box + ' Installing 404 page...' assert expected_stdout in installWeb.stdout - expected_stdout = tick_box + (' Creating directory for blocking page, ' + expected_stdout = tick_box + (' Creating directory for 404 page, ' 'and copying files') assert expected_stdout in installWeb.stdout expected_stdout = info_box + ' Backing up index.lighttpd.html' @@ -130,7 +130,6 @@ def test_installPiholeWeb_fresh_install_no_errors(host): assert expected_stdout in installWeb.stdout web_directory = host.run('ls -r /var/www/html/pihole').stdout assert 'index.php' in web_directory - assert 'blockingpage.css' in web_directory def get_directories_recursive(host, directory): @@ -605,10 +604,6 @@ def is_ip(address): 'r', webroot + '/pihole/index.php', webuser) actual_rc = host.run(check_index).rc assert exit_status_success == actual_rc - check_blockpage = test_cmd.format( - 'r', webroot + '/pihole/blockingpage.css', webuser) - actual_rc = host.run(check_blockpage).rc - assert exit_status_success == actual_rc if test_webpage is True: # check webpage for unreadable files noPHPfopen = re.compile( From 6c9bd7a6328f892884b9e55064c61fa08b7682fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 26 Jul 2022 23:57:07 +0200 Subject: [PATCH 129/638] Remove blockingpage.css MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/blockingpage.css | 455 ----------------------------- automated install/basic-install.sh | 4 +- 2 files changed, 2 insertions(+), 457 deletions(-) delete mode 100644 advanced/blockingpage.css diff --git a/advanced/blockingpage.css b/advanced/blockingpage.css deleted file mode 100644 index 0cc7a65cb3..0000000000 --- a/advanced/blockingpage.css +++ /dev/null @@ -1,455 +0,0 @@ -/* Pi-hole: A black hole for Internet advertisements -* (c) 2017 Pi-hole, LLC (https://pi-hole.net) -* Network-wide ad blocking via your own hardware. -* -* This file is copyright under the latest version of the EUPL. -* Please see LICENSE file for your rights under this license. */ - -/* Text Customisation Options ======> */ -.title::before { content: "Website Blocked"; } -.altBtn::before { content: "Why am I here?"; } -.linkPH::before { content: "About Pi-hole"; } -.linkEmail::before { content: "Contact Admin"; } - -#bpOutput.add::before { content: "Info"; } -#bpOutput.add::after { content: "The domain is being whitelisted..."; } -#bpOutput.error::before, .unhandled::before { content: "Error"; } -#bpOutput.unhandled::after { content: "An unhandled exception occurred. This may happen when your browser is unable to load jQuery, or when the webserver is denying access to the Pi-hole API."; } -#bpOutput.success::before { content: "Success"; } -#bpOutput.success::after { content: "Website has been whitelisted! You may need to flush your DNS cache"; } - -.recentwl::before { content: "This site has been whitelisted. Please flush your DNS cache and/or restart your browser."; } -.unknown::before { content: "This website is not found in any of Pi-hole's blacklists. The reason you have arrived here is unknown."; } -.cname::before { content: "This site is an alias for "; } /* cname.com */ -.cname::after { content: ", which may be blocked by Pi-hole."; } - -.blacklist::before { content: "Manually Blacklisted"; } -.wildcard::before { content: "Manually Blacklisted by Wildcard"; } -.noblock::before { content: "Not found on any Blacklist"; } - -#bpBlock::before { content: "Access to the following website has been denied:"; } -#bpFlag::before { content: "This is primarily due to being flagged as:"; } - -#bpHelpTxt::before { content: "If you have an ongoing use for this website, please "; } -#bpHelpTxt a::before, #bpHelpTxt span::before { content: "ask the administrator"; } -#bpHelpTxt::after{ content: " of the Pi-hole on this network to have it whitelisted"; } - -#bpBack::before { content: "Back to safety"; } -#bpInfo::before { content: "Technical Info"; } -#bpFoundIn::before { content: "This site is found in "; } -#bpFoundIn span::after { content: " of "; } -#bpFoundIn::after { content: " lists:"; } -#bpWhitelist::before { content: "Whitelist"; } - -footer span::before { content: "Page generated on "; } - -/* Hide whitelisting form entirely */ -/* #bpWLButtons { display: none; } */ - -/* Text Customisation Options <=============================== */ - -/* http://necolas.github.io/normalize.css ======> */ -html { font-family: sans-serif; line-height: 1.15; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; } -body { margin: 0; } -article, aside, footer, header, nav, section { display: block; } -h1 { font-size: 2em; margin: 0.67em 0; } -figcaption, figure, main { display: block; } -figure { margin: 1em 40px; } -hr { box-sizing: content-box; height: 0; overflow: visible; } -pre { font-family: monospace, monospace; font-size: 1em; } -a { background-color: transparent; -webkit-text-decoration-skip: objects; } -a:active, a:hover { outline-width: 0; } -abbr[title] { border-bottom: none; text-decoration: underline; text-decoration: underline dotted; } -b, strong { font-weight: inherit; } -b, strong { font-weight: bolder; } -code, kbd, samp { font-family: monospace, monospace; font-size: 1em; } -dfn { font-style: italic; } -mark { background-color: #ff0; color: #000; } -small { font-size: 80%; } -sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } -sub { bottom: -0.25em; } -sup { top: -0.5em; } -audio, video { display: inline-block; } -audio:not([controls]) { display: none; height: 0; } -img { border-style: none; } -svg:not(:root) { overflow: hidden; } -button, input, optgroup, select, textarea { font-family: sans-serif; font-size: 100%; line-height: 1.15; margin: 0; } -button, input { overflow: visible; } -button, select { text-transform: none; } -button, html [type="button"], [type="reset"], [type="submit"] { -webkit-appearance: button; } -button::-moz-focus-inner, [type="button"]::-moz-focus-inner, [type="reset"]::-moz-focus-inner, [type="submit"]::-moz-focus-inner { border-style: none; padding: 0; } -button:-moz-focusring, [type="button"]:-moz-focusring, [type="reset"]:-moz-focusring, [type="submit"]:-moz-focusring { outline: 1px dotted ButtonText; } -fieldset { border: 1px solid #c0c0c0; margin: 0 2px; padding: 0.35em 0.625em 0.75em; } -legend { box-sizing: border-box; color: inherit; display: table; max-width: 100%; padding: 0; white-space: normal; } -progress { display: inline-block; vertical-align: baseline; } -textarea { overflow: auto; } -[type="checkbox"], [type="radio"] { box-sizing: border-box; padding: 0; } -[type="number"]::-webkit-inner-spin-button, [type="number"]::-webkit-outer-spin-button { height: auto; } -[type="search"] { -webkit-appearance: textfield; outline-offset: -2px; } -[type="search"]::-webkit-search-cancel-button, [type="search"]::-webkit-search-decoration { -webkit-appearance: none; } -::-webkit-file-upload-button { -webkit-appearance: button; font: inherit; } -details, menu { display: block; } -summary { display: list-item; } -canvas { display: inline-block; } -template { display: none; } -[hidden] { display: none; } -/* Normalize.css <=============================== */ - -html { font-size: 62.5%; } - -a { color: #3c8dbc; text-decoration: none; } -a:hover { color: #72afda; text-decoration: underline; } -b { color: rgb(68, 68, 68); } -p { margin: 0; } - -label, .buttons a { - -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; -} - -label, .buttons *:not([disabled]) { cursor: pointer; } - -/* Touch device dark tap highlight */ -header h1 a, label, .buttons * { -webkit-tap-highlight-color: transparent; } - -/* Webkit Focus Glow */ -textarea, input, button { outline: none; } - -@font-face { - font-family: "Source Sans Pro"; - font-style: normal; - font-weight: 400; - font-display: swap; - src: local("Source Sans Pro Regular"), local("SourceSansPro-Regular"), - url("/admin/style/vendor/SourceSansPro/source-sans-pro-v13-latin-regular.woff2") format("woff2"), - url("/admin/style/vendor/SourceSansPro/source-sans-pro-v13-latin-regular.woff") format("woff"); -} - -@font-face { - font-family: "Source Sans Pro"; - font-style: normal; - font-weight: 700; - font-display: swap; - src: local("Source Sans Pro Bold"), local("SourceSansPro-Bold"), - url("/admin/style/vendor/SourceSansPro/source-sans-pro-v13-latin-700.woff2") format("woff2"), - url("/admin/style/vendor/SourceSansPro/source-sans-pro-v13-latin-700.woff") format("woff"); -} - -body { - background: #dbdbdb url("/admin/img/boxed-bg.jpg") repeat fixed; - color: #333; - font: 1.4rem "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif; - line-height: 2.2rem; -} - -/* User is greeted with a splash page when browsing to Pi-hole IP address */ -#splashpage { - background: #222; - color: rgba(255, 255, 255, 0.7); - text-align: center; - width: 100%; - height: 100%; - display: flex; - align-items: center; - justify-content: center; -} - -#splashpage img { margin: 5px; width: 256px; } -#splashpage b { color: inherit; } - -#bpWrapper { - margin: 0 auto; - max-width: 1250px; - box-shadow: 0 0 8px rgba(0, 0, 0, 0.5); -} - -header { - background: #3c8dbc; - display: table; - position: relative; - width: 100%; -} - -header h1, header h1 a, header .spc, header #bpAlt label { - display: table-cell; - color: #fff; - white-space: nowrap; - vertical-align: middle; - height: 50px; /* Must match #bpAbout top value */ -} - -h1 a { - background-color: rgba(0, 0, 0, 0.1); - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - font-size: 2rem; - font-weight: 400; - min-width: 230px; - text-align: center; -} - -h1 a:hover, header #bpAlt:hover { background-color: rgba(0, 0, 0, 0.12); color: inherit; text-decoration: none; } - -header .spc { width: 100%; } - -header #bpAlt label { - background: url("/admin/img/logo.svg") no-repeat center left 15px; - background-size: 15px 23px; - padding: 0 15px; - text-indent: 30px; -} - -[type="checkbox"][id$="Toggle"] { display: none; } -[type="checkbox"][id$="Toggle"]:checked ~ #bpAbout, -[type="checkbox"][id$="Toggle"]:checked ~ #bpMoreInfo { - display: block; -} - -html, body { - height: 100%; -} - -#pihole_card { - width: 400px; - height: auto; - max-width: 400px; -} - - #pihole_card p, #pihole_card a { - font-size: 13pt; - text-align: center; - } - -#pihole_logo_splash { - height: auto; - width: 100%; -} - -/* Click anywhere else on screen to hide #bpAbout */ -#bpAboutToggle:checked { - display: block; - height: 300px; /* VH Fallback */ - height: 100vh; - left: 0; - top: 0; - opacity: 0; - position: absolute; - width: 100%; -} - -#bpAbout { - background: #3c8dbc; - border-bottom-left-radius: 5px; - border: 1px solid #fff; - border-right-width: 0; - box-shadow: -1px 1px 1px rgba(0, 0, 0, 0.12); - box-sizing: border-box; - display: none; - font-size: 1.7rem; - top: 50px; - position: absolute; - right: 0; - width: 280px; - z-index: 1; -} - -.aboutPH { - box-sizing: border-box; - color: rgba(255, 255, 255, 0.8); - display: block; - padding: 10px; - width: 100%; - text-align: center; -} - -.aboutImg { - background: url("/admin/img/logo.svg") no-repeat center; - background-size: 90px 90px; - height: 90px; - margin: 0 auto; - padding: 2px; - width: 90px; -} - -.aboutPH p { margin: 10px 0; } -.aboutPH small { display: block; font-size: 1.2rem; } - -.aboutLink { - background: #fff; - border-top: 1px solid #ddd; - display: table; - font-size: 1.4rem; - text-align: center; - width: 100%; -} - -.aboutLink a { - display: table-cell; - padding: 14px; - min-width: 50%; -} - -main { - background: #ecf0f5; - font-size: 1.65rem; - padding: 10px; -} - -#bpOutput { - background: #00c0ef; - border-radius: 3px; - border: 1px solid rgba(0, 0, 0, 0.1); - color: #fff; - font-size: 1.4rem; - margin-bottom: 10px; - margin-top: 5px; - padding: 15px; -} - -#bpOutput::before { - background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='7' height='14' viewBox='0 0 7 14'%3E%3Cpath fill='%23fff' d='M6 11a1.371 1.371 0 011 1v1a1.371 1.371 0 01-1 1H1a1.371 1.371 0 01-1-1v-1a1.371 1.371 0 011-1h1V8H1a1.371 1.371 0 01-1-1V6a1.371 1.371 0 011-1h3a1.371 1.371 0 011 1v5h1zM3.5 0A1.5 1.5 0 112 1.5 1.5 1.5 0 013.5 0z'/%3E%3C/svg%3E") no-repeat center left; - display: block; - font-size: 1.8rem; - text-indent: 15px; -} - -#bpOutput.hidden { display: none; } -#bpOutput.success { background: #00a65a; } -#bpOutput.error { background: #dd4b39; } - -.blockMsg, .flagMsg { - font: 700 1.8rem Consolas, Courier, monospace; - padding: 5px 10px 10px; - text-indent: 15px; -} - -#bpHelpTxt { padding-bottom: 10px; } - -.buttons { - border-spacing: 5px 0; - display: table; - width: 100%; -} - -.buttons * { - -moz-appearance: none; - -webkit-appearance: none; - border-radius: 3px; - border: 1px solid rgba(0, 0, 0, 0.1); - box-sizing: content-box; - display: table-cell; - font-size: 1.65rem; - margin-right: 5px; - min-height: 20px; - padding: 6px 12px; - position: relative; - text-align: center; - vertical-align: top; - white-space: nowrap; - width: auto; -} - -.buttons a:hover { text-decoration: none; } - -/* Button hover dark overlay */ -.buttons *:not(input):not([disabled]):hover { - background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.1)); - color: #fff; -} - -/* Button active shadow inset */ -.buttons *:not([disabled]):not(input):active { - box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); -} - -/* Input border color */ -.buttons *:not([disabled]):hover, .buttons input:focus { - border-color: rgba(0, 0, 0, 0.25); -} - -#bpButtons * { width: 50%; color: #fff; } -#bpBack { background-color: #00a65a; } -#bpInfo { background-color: #3c8dbc; } -#bpWhitelist { background-color: #dd4b39; } - -#blockpage .buttons [type="password"][disabled] { color: rgba(0, 0, 0, 1); } -#blockpage .buttons [disabled] { color: rgba(0, 0, 0, 0.55); background-color: #e3e3e3; } -#blockpage .buttons [type="password"]:-ms-input-placeholder { color: rgba(51, 51, 51, 0.8); } - -input[type="password"] { font-size: 1.5rem; } - -@-webkit-keyframes slidein { from { max-height: 0; opacity: 0; } to { max-height: 300px; opacity: 1; } } - -@keyframes slidein { from { max-height: 0; opacity: 0; } to { max-height: 300px; opacity: 1; } } -#bpMoreToggle:checked ~ #bpMoreInfo { display: block; margin-top: 8px; -webkit-animation: slidein 0.05s linear; animation: slidein 0.05s linear; } -#bpMoreInfo { display: none; margin-top: 10px; } - -#bpQueryOutput { - font-size: 1.2rem; - line-height: 1.65rem; - margin: 5px 0 0; - overflow: auto; - padding: 0 5px; - -webkit-overflow-scrolling: touch; -} - -#bpQueryOutput span { margin-right: 4px; } - -#bpWLButtons { width: auto; margin-top: 10px; } -#bpWLButtons * { display: inline-block; } -#bpWLDomain { display: none; } -#bpWLPassword { width: 160px; } -#bpWhitelist { color: #fff; } - -footer { - background: #fff; - border-top: 1px solid #d2d6de; - color: #444; - font: 1.2rem Consolas, Courier, monospace; - padding: 8px; -} - -/* Responsive Content */ -@media only screen and (max-width: 500px) { - h1 a { - font-size: 1.8rem; - min-width: 170px; - } - - footer span::before { - content: "Generated "; - } - - footer span { - display: block; - } -} - -@media only screen and (min-width: 1251px) { - #bpWrapper, footer { - border-radius: 0 0 5px 5px; - } - - #bpAbout { - border-right-width: 1px; - } -} - -@media only screen and (max-width: 400px) { - #pihole_card { - width: 100%; - height: auto; - } - - #pihole_card p, #pihole_card a { - font-size: 100%; - } -} - -@media only screen and (max-width: 256px) { - #pihole_logo_splash { - width: 90% !important; - height: auto; - } -} diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6b58afdfde..c290527a0e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1672,8 +1672,8 @@ installPiholeWeb() { install -D -m 644 ${PI_HOLE_LOCAL_REPO}/advanced/index.php ${PI_HOLE_404_DIR}/ # Remove superseded file - if [[ -e "${PI_HOLE_404_DIR}/index.js" ]]; then - rm "${PI_HOLE_404_DIR}/index.js" + if [[ -e "${PI_HOLE_404_DIR}/blockingpage.css" ]]; then + rm "${PI_HOLE_404_DIR}/blockingpage.css" fi printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" From b98e3313759034e3cfe60eb1a7830381b1cf4af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 27 Jul 2022 00:07:24 +0200 Subject: [PATCH 130/638] Only do one curl call in debug when checking the X-Header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 79452f0032..aff2ee9dd2 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -797,13 +797,13 @@ check_x_headers() { # server is operating correctly echo_current_diagnostic "Dashboard and block page" # Use curl -I to get the header and parse out just the X-Pi-hole one + local full_curl_output_dashboard local dashboard - dashboard=$(curl -Is localhost/admin/ | awk '/X-Pi-hole/' | tr -d '\r') + full_curl_output_dashboard="$(curl -Is localhost/admin/)" + dashboard=$(echo "${full_curl_output_dashboard}" | awk '/X-Pi-hole/' | tr -d '\r') # Store what the X-Header should be in variables for comparison later local dashboard_working dashboard_working="X-Pi-hole: The Pi-hole Web interface is working!" - local full_curl_output_dashboard - full_curl_output_dashboard="$(curl -Is localhost/admin/)" # Same logic applies to the dashboard as above, if the X-Header matches what a working system should have, if [[ $dashboard == "$dashboard_working" ]]; then @@ -812,6 +812,7 @@ check_x_headers() { else # Otherwise, it's a failure since the X-Headers either don't exist or have been modified in some way log_write "$CROSS Web interface X-Header: ${COL_RED}X-Header does not match or could not be retrieved.${COL_NC}" + log_write "${COL_RED}${full_curl_output_dashboard}${COL_NC}" fi } From 27fa284edac13953c32c905008270a694a5825b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 27 Jul 2022 00:34:22 +0200 Subject: [PATCH 131/638] Fix missing PI_HOLE_BLOCKPAGE_DIR 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c290527a0e..6d419e7f3d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1402,7 +1402,7 @@ installConfigs() { install -m 644 /dev/null /etc/lighttpd/external.conf fi # If there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config - if [[ -f "${PI_HOLE_BLOCKPAGE_DIR}/custom.php" ]]; then + if [[ -f "${PI_HOLE_404_DIR}/custom.php" ]]; then sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"\/pihole\/custom\.php"/' "${lighttpdConfig}" fi # Make the directories if they do not exist and set the owners From e6683803edc2242b69cbc8756971466f286811cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 27 Jul 2022 12:15:44 +0200 Subject: [PATCH 132/638] Use absolut asset paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index 3b320a3fb7..d9a5b33e68 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -49,7 +49,7 @@ ● $serverName - + - Pi-hole logo + Pi-hole logo

Pi-hole: Your black hole for Internet advertisements

Did you mean to go to the admin panel? From 49a9f6f2dbb61cfe9034c27f0ee239b69c1334d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 27 Jul 2022 14:31:48 +0200 Subject: [PATCH 133/638] Reproduce blockpage.css for $splashPage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/index.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index d9a5b33e68..675b50058d 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -51,16 +51,24 @@ ● $serverName +
Pi-hole logo

Pi-hole: Your black hole for Internet advertisements

Did you mean to go to the admin panel? +
EOT; From c67f313ee83996d8c8fe925d7e781deb392db7e3 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Fri, 29 Jul 2022 15:11:09 +0200 Subject: [PATCH 134/638] Apply reviewers suggestion for inline CSS Co-authored-by: RD WebDesign Signed-off-by: yubiuser --- advanced/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index 675b50058d..350eb602cc 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -52,12 +52,12 @@ From 97447b2f3beee11347f603d070dae46a9e84d9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 27 Jul 2022 00:32:50 +0200 Subject: [PATCH 135/638] Do not remove blockingpage.css from existing installations as some users might use them for custom.php 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 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6d419e7f3d..254e9c06d3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1671,11 +1671,6 @@ installPiholeWeb() { # and the 404 handler install -D -m 644 ${PI_HOLE_LOCAL_REPO}/advanced/index.php ${PI_HOLE_404_DIR}/ - # Remove superseded file - if [[ -e "${PI_HOLE_404_DIR}/blockingpage.css" ]]; then - rm "${PI_HOLE_404_DIR}/blockingpage.css" - fi - printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" local str="Backing up index.lighttpd.html" From e35a9da921aa10a4b51b8d80277481871420f8fd Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 8 Aug 2022 18:57:17 +0100 Subject: [PATCH 136/638] Remove the blockpage-focussed customisations to query.sh Signed-off-by: Adam Warner --- advanced/Scripts/query.sh | 46 ++++++++++++--------------------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 5f25e5be7e..ae266ec047 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -16,7 +16,6 @@ GRAVITYDB="${piholeDir}/gravity.db" options="$*" all="" exact="" -blockpage="" matchType="match" # Source pihole-FTL from install script pihole_FTL="${piholeDir}/pihole-FTL.conf" @@ -71,18 +70,14 @@ Options: fi # Handle valid options -if [[ "${options}" == *"-bp"* ]]; then - exact="exact"; blockpage=true -else - [[ "${options}" == *"-all"* ]] && all=true - if [[ "${options}" == *"-exact"* ]]; then - exact="exact"; matchType="exact ${matchType}" - fi +[[ "${options}" == *"-all"* ]] && all=true +if [[ "${options}" == *"-exact"* ]]; then + exact="exact"; matchType="exact ${matchType}" fi # Strip valid options, leaving only the domain and invalid options # This allows users to place the options before or after the domain -options=$(sed -E 's/ ?-(bp|adlists?|all|exact) ?//g' <<< "${options}") +options=$(sed -E 's/ ?-(adlists?|all|exact) ?//g' <<< "${options}") # Handle remaining options # If $options contain non ASCII characters, convert to punycode @@ -136,17 +131,11 @@ scanDatabaseTable() { wbMatch=true # Print table name - if [[ -z "${blockpage}" ]]; then - echo " ${matchType^} found in ${COL_BOLD}exact ${table}${COL_NC}" - fi + echo " ${matchType^} found in ${COL_BOLD}exact ${table}${COL_NC}" # Loop over results and print them mapfile -t results <<< "${result}" for result in "${results[@]}"; do - if [[ -n "${blockpage}" ]]; then - echo "π ${result}" - exit 0 - fi domain="${result/|*}" if [[ "${result#*|}" == "0" ]]; then extra=" (disabled)" @@ -181,18 +170,13 @@ scanRegexDatabaseTable() { # Form a "results" message str_result="${COL_BOLD}${str_regexMatches}${COL_NC}" # If we are displaying more than just the source of the block - if [[ -z "${blockpage}" ]]; then - # Set the wildcard match flag - wcMatch=true - # Echo the "matched" message, indented by one space - echo " ${str_message}" - # Echo the "results" message, each line indented by three spaces - # shellcheck disable=SC2001 - echo "${str_result}" | sed 's/^/ /' - else - echo "π .wildcard" - exit 0 - fi + # Set the wildcard match flag + wcMatch=true + # Echo the "matched" message, indented by one space + echo " ${str_message}" + # Echo the "results" message, each line indented by three spaces + # shellcheck disable=SC2001 + echo "${str_result}" | sed 's/^/ /' fi fi } @@ -222,7 +206,7 @@ elif [[ -z "${all}" ]] && [[ "${#results[*]}" -ge 100 ]]; then fi # Print "Exact matches for" title -if [[ -n "${exact}" ]] && [[ -z "${blockpage}" ]]; then +if [[ -n "${exact}" ]]; then plural=""; [[ "${#results[*]}" -gt 1 ]] && plural="es" echo " ${matchType^}${plural} for ${COL_BOLD}${domainQuery}${COL_NC} found in:" fi @@ -238,9 +222,7 @@ for result in "${results[@]}"; do extra="" fi - if [[ -n "${blockpage}" ]]; then - echo "0 ${adlistAddress}" - elif [[ -n "${exact}" ]]; then + if [[ -n "${exact}" ]]; then echo " - ${adlistAddress}${extra}" else if [[ ! "${adlistAddress}" == "${adlistAddress_prev:-}" ]]; then From b3c8045b529642d9bf8a909bdb15f7ac3d0e0228 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Thu, 28 Jul 2022 20:10:18 +0200 Subject: [PATCH 137/638] Skip web server dialog if --disable-install-webserver has been passed Prior to https://github.com/pi-hole/pi-hole/pull/4772, the web server dialog was skipped if --disable-install-webserver was passed (INSTALL_WEB_SERVER=false). This commit restores this behaviour. Signed-off-by: MichaIng --- 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 f141df41bd..0c7196ee5d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1127,8 +1127,8 @@ setAdminFlag() { ;; esac - # If the user wants to install the Web admin interface (i.e. it has not been deselected above) - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + # If the user wants to install the Web admin interface (i.e. it has not been deselected above) and did not deselect the web server via command-line argument + if [[ "${INSTALL_WEB_INTERFACE}" == true && "${INSTALL_WEB_SERVER}" == true ]]; then # Get list of required PHP modules, excluding base package (common) and handler (cgi) local i php_modules for i in "${PIHOLE_WEB_DEPS[@]}"; do [[ $i == 'php'* && $i != *'-common' && $i != *'-cgi' ]] && php_modules+=" ${i#*-}"; done From 8c4a9aa6e3306e1fe47cfc04fe579e26b51e758c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 17 Aug 2022 23:14:56 +0200 Subject: [PATCH 138/638] Remove the email function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 33 --------------------------------- advanced/bash-completion/pihole | 2 +- manpages/pihole.8 | 5 ----- 3 files changed, 1 insertion(+), 39 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 29c53bd671..3ee48aef2d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -46,7 +46,6 @@ Options: -c, celsius Set Celsius as preferred temperature unit -f, fahrenheit Set Fahrenheit as preferred temperature unit -k, kelvin Set Kelvin as preferred temperature unit - -e, email Set an administrative contact address for the Block Page -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -l, privacylevel Set privacy level (0 = lowest, 3 = highest) @@ -568,37 +567,6 @@ RemoveDHCPStaticAddress() { } -SetAdminEmail() { - if [[ "${1}" == "-h" ]] || [[ "${1}" == "--help" ]]; then - echo "Usage: pihole -a email
-Example: 'pihole -a email admin@address.com' -Set an administrative contact address for the Block Page - -Options: - \"\" Empty: Remove admin contact - -h, --help Show this help dialog" - exit 0 - fi - - if [[ -n "${args[2]}" ]]; then - - # Sanitize email address in case of security issues - # Regex from https://stackoverflow.com/a/2138832/4065967 - local regex - regex="^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\$" - if [[ ! "${args[2]}" =~ ${regex} ]]; then - echo -e " ${CROSS} Invalid email address" - exit 0 - fi - - addOrEditKeyValPair "${setupVars}" "ADMIN_EMAIL" "${args[2]}" - echo -e " ${TICK} Setting admin contact to ${args[2]}" - else - addOrEditKeyValPair "${setupVars}" "ADMIN_EMAIL" "" - echo -e " ${TICK} Removing admin contact" - fi -} - SetListeningMode() { source "${setupVars}" @@ -847,7 +815,6 @@ main() { "-h" | "--help" ) helpFunc;; "addstaticdhcp" ) AddDHCPStaticAddress;; "removestaticdhcp" ) RemoveDHCPStaticAddress;; - "-e" | "email" ) SetAdminEmail "$3";; "-i" | "interface" ) SetListeningMode "$@";; "-t" | "teleporter" ) Teleporter;; "adlist" ) CustomizeAdLists;; diff --git a/advanced/bash-completion/pihole b/advanced/bash-completion/pihole index 25208a3577..29a3270de1 100644 --- a/advanced/bash-completion/pihole +++ b/advanced/bash-completion/pihole @@ -15,7 +15,7 @@ _pihole() { COMPREPLY=( $(compgen -W "${opts_lists}" -- ${cur}) ) ;; "admin") - opts_admin="celsius email fahrenheit interface kelvin password privacylevel" + opts_admin="celsius fahrenheit interface kelvin password privacylevel" COMPREPLY=( $(compgen -W "${opts_admin}" -- ${cur}) ) ;; "checkout") diff --git a/manpages/pihole.8 b/manpages/pihole.8 index 4b1e5154fe..11c21b2844 100644 --- a/manpages/pihole.8 +++ b/manpages/pihole.8 @@ -11,8 +11,6 @@ Pi-hole : A black-hole for internet advertisements .br \fBpihole -a\fR (\fB-c|-f|-k\fR) .br -\fBpihole -a -e\fR email -.br \fBpihole -a -i\fR interface .br \fBpihole -a -l\fR privacylevel @@ -132,9 +130,6 @@ Available commands and options: -f, fahrenheit Set Fahrenheit as preferred temperature unit .br -k, kelvin Set Kelvin as preferred temperature unit -.br - -e, email Set an administrative contact address for the - Block Page .br -i, interface Specify dnsmasq's interface listening behavior .br From eeccfb27f85fdf82d9e9e05ab0ed457c10bac11e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 20 Aug 2022 23:07:38 +0200 Subject: [PATCH 139/638] Remove it also from index.php together with more unused variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index 350eb602cc..9a2b19e606 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -34,7 +34,7 @@ // When directly browsing via IP or authorized hostname // Render splash/landing page based off presence of $landPage file // Unset variables so as to not be included in $landPage or $splashPage - unset($svPasswd, $svEmail, $authorizedHosts, $validExtTypes, $currentUrlExt); + unset($authorizedHosts); // If $landPage file is present if (is_file(getcwd()."/$landPage")) { unset($serverName, $viewPort); // unset extra variables not to be included in $landpage From 5421aad03e1aa372199dd64ae8cb25dc5a9a23a6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 22 Aug 2022 18:53:46 +0100 Subject: [PATCH 140/638] Store versions as key/value pairs rather than space delimeted values Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 60 +++++++++++++++++++++--------- advanced/Scripts/version.sh | 11 +++--- test/test_any_automated_install.py | 14 +------ 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index afb03ebb7f..35986676b3 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -41,54 +41,78 @@ function get_local_version() { # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf +utilsfile="/opt/pihole/utils.sh" +source "${utilsfile}" + +# Remove the below three legacy files if they exist +GITHUB_VERSION_FILE="/etc/pihole/GitHubVersions" +LOCAL_BRANCH_FILE="/etc/pihole/localbranches" +LOCAL_VERSION_FILE="/etc/pihole/localversions" + +if [ -f "${GITHUB_VERSION_FILE}" ]; then + rm "${GITHUB_VERSION_FILE}" +fi + +if [ -f "${LOCAL_BRANCH_FILE}" ]; then + rm "${LOCAL_BRANCH_FILE}" +fi + +if [ -f "${LOCAL_VERSION_FILE}" ]; then + rm "${LOCAL_VERSION_FILE}" +fi + +# Create new versions file if it does not exist +VERSION_FILE="/etc/pihole/versions" + +if [ ! -f "${VERSION_FILE}" ]; then + touch "${VERSION_FILE}" + chmod 644 "${VERSION_FILE}" +fi + if [[ "$2" == "remote" ]]; then if [[ "$3" == "reboot" ]]; then sleep 30 fi - GITHUB_VERSION_FILE="/etc/pihole/GitHubVersions" - GITHUB_CORE_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null)")" - echo -n "${GITHUB_CORE_VERSION}" > "${GITHUB_VERSION_FILE}" - chmod 644 "${GITHUB_VERSION_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then GITHUB_WEB_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null)")" - echo -n " ${GITHUB_WEB_VERSION}" >> "${GITHUB_VERSION_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" fi GITHUB_FTL_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null)")" - echo -n " ${GITHUB_FTL_VERSION}" >> "${GITHUB_VERSION_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" -else + if [[ "${PIHOLE_DOCKER_TAG}" ]]; then + GITHUB_DOCKER_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null)")" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" + fi - LOCAL_BRANCH_FILE="/etc/pihole/localbranches" +else CORE_BRANCH="$(get_local_branch /etc/.pihole)" - echo -n "${CORE_BRANCH}" > "${LOCAL_BRANCH_FILE}" - chmod 644 "${LOCAL_BRANCH_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then WEB_BRANCH="$(get_local_branch /var/www/html/admin)" - echo -n " ${WEB_BRANCH}" >> "${LOCAL_BRANCH_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" fi FTL_BRANCH="$(pihole-FTL branch)" - echo -n " ${FTL_BRANCH}" >> "${LOCAL_BRANCH_FILE}" - - LOCAL_VERSION_FILE="/etc/pihole/localversions" + addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" CORE_VERSION="$(get_local_version /etc/.pihole)" - echo -n "${CORE_VERSION}" > "${LOCAL_VERSION_FILE}" - chmod 644 "${LOCAL_VERSION_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then WEB_VERSION="$(get_local_version /var/www/html/admin)" - echo -n " ${WEB_VERSION}" >> "${LOCAL_VERSION_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" fi FTL_VERSION="$(pihole-FTL version)" - echo -n " ${FTL_VERSION}" >> "${LOCAL_VERSION_FILE}" + addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" fi diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 0b7b29dd60..0bda197e4b 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -90,16 +90,17 @@ getRemoteVersion(){ local version local cachedVersions local arrCache - cachedVersions="/etc/pihole/GitHubVersions" + cachedVersions="/etc/pihole/versions" #If the above file exists, then we can read from that. Prevents overuse of GitHub API if [[ -f "$cachedVersions" ]]; then - IFS=' ' read -r -a arrCache < "$cachedVersions" + + source "$cachedVersions" case $daemon in - "pi-hole" ) echo "${arrCache[0]}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[1]}";; - "FTL" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${arrCache[2]}" || echo "${arrCache[1]}";; + "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";; + "FTL" ) echo "${GITHUB_FTL_VERSION}";; esac return 0 diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index c26380a1dd..1e2a849b40 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -239,24 +239,14 @@ def test_installPihole_fresh_install_readableFiles(host): 'r', '/etc/pihole/dns-servers.conf', piholeuser) actual_rc = host.run(check_servers).rc assert exit_status_success == actual_rc - # readable GitHubVersions - check_version = test_cmd.format( - 'r', '/etc/pihole/GitHubVersions', piholeuser) - actual_rc = host.run(check_version).rc - assert exit_status_success == actual_rc # readable install.log check_install = test_cmd.format( 'r', '/etc/pihole/install.log', piholeuser) actual_rc = host.run(check_install).rc assert exit_status_success == actual_rc - # readable localbranches - check_localbranch = test_cmd.format( - 'r', '/etc/pihole/localbranches', piholeuser) - actual_rc = host.run(check_localbranch).rc - assert exit_status_success == actual_rc - # readable localversions + # readable versions check_localversion = test_cmd.format( - 'r', '/etc/pihole/localversions', piholeuser) + 'r', '/etc/pihole/versions', piholeuser) actual_rc = host.run(check_localversion).rc assert exit_status_success == actual_rc # readable logrotate From a4b899c2566115d3e1faad2158a171c116dfb4f4 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 23 Aug 2022 19:10:12 +0100 Subject: [PATCH 141/638] Review suggestions (and shellcheck complaints) Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 30 ++++++++---------------------- advanced/Scripts/version.sh | 4 ++-- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 35986676b3..0c9f385eb4 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -41,33 +41,19 @@ function get_local_version() { # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf -utilsfile="/opt/pihole/utils.sh" -source "${utilsfile}" +# Source the utils file +# shellcheck disable=SC1091 +. /opt/pihole/utils.sh # Remove the below three legacy files if they exist -GITHUB_VERSION_FILE="/etc/pihole/GitHubVersions" -LOCAL_BRANCH_FILE="/etc/pihole/localbranches" -LOCAL_VERSION_FILE="/etc/pihole/localversions" - -if [ -f "${GITHUB_VERSION_FILE}" ]; then - rm "${GITHUB_VERSION_FILE}" -fi - -if [ -f "${LOCAL_BRANCH_FILE}" ]; then - rm "${LOCAL_BRANCH_FILE}" -fi - -if [ -f "${LOCAL_VERSION_FILE}" ]; then - rm "${LOCAL_VERSION_FILE}" -fi +rm -f "/etc/pihole/GitHubVersions" +rm -f "/etc/pihole/localbranches" +rm -f "/etc/pihole/localversions" # Create new versions file if it does not exist VERSION_FILE="/etc/pihole/versions" - -if [ ! -f "${VERSION_FILE}" ]; then - touch "${VERSION_FILE}" - chmod 644 "${VERSION_FILE}" -fi +touch "${VERSION_FILE}" +chmod 644 "${VERSION_FILE}" if [[ "$2" == "remote" ]]; then diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 0bda197e4b..7f44d35ea5 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -89,13 +89,13 @@ getRemoteVersion(){ local daemon="${1}" local version local cachedVersions - local arrCache cachedVersions="/etc/pihole/versions" #If the above file exists, then we can read from that. Prevents overuse of GitHub API if [[ -f "$cachedVersions" ]]; then - source "$cachedVersions" + # shellcheck disable=SC1090 + . "$cachedVersions" case $daemon in "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; From 9b5ea13a33f44d15a90bfda6c2a4b3b0089de57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 18 Aug 2022 17:08:52 +0200 Subject: [PATCH 142/638] Use utils.sh in install script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/01-pihole.conf | 7 --- automated install/basic-install.sh | 82 +++++++++++++++--------------- test/test_any_automated_install.py | 1 + 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 1fb34905cd..677910f654 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -29,13 +29,6 @@ bogus-priv no-resolv -server=@DNS1@ -server=@DNS2@ - -interface=@INT@ - -cache-size=@CACHE_SIZE@ - log-queries log-facility=/var/log/pihole/pihole.log diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4d860d33a8..998b9f15b5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -83,6 +83,7 @@ PI_HOLE_INSTALL_DIR="/opt/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole" PI_HOLE_BIN_DIR="/usr/local/bin" PI_HOLE_404_DIR="${webroot}/pihole" +FTL_CONFIG_FILE="${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" if [ -z "$useUpdateVars" ]; then useUpdateVars=false fi @@ -1264,35 +1265,30 @@ version_check_dnsmasq() { # Copy the new Pi-hole DNS config file into the dnsmasq.d directory install -D -m 644 -T "${dnsmasq_pihole_01_source}" "${dnsmasq_pihole_01_target}" printf "%b %b Installed %s\n" "${OVER}" "${TICK}" "${dnsmasq_pihole_01_target}" - # Replace our placeholder values with the GLOBAL DNS variables that we populated earlier - # First, swap in the interface to listen on, - sed -i "s/@INT@/$PIHOLE_INTERFACE/" "${dnsmasq_pihole_01_target}" + # Add settings with the GLOBAL DNS variables that we populated earlier + # First, set the interface to listen on + addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "interface" "$PIHOLE_INTERFACE" if [[ "${PIHOLE_DNS_1}" != "" ]]; then - # then swap in the primary DNS server. - sed -i "s/@DNS1@/$PIHOLE_DNS_1/" "${dnsmasq_pihole_01_target}" - else - # Otherwise, remove the line which sets DNS1. - sed -i '/^server=@DNS1@/d' "${dnsmasq_pihole_01_target}" + # then add in the primary DNS server. + addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "server" "$$PIHOLE_DNS_1" fi # Ditto if DNS2 is not empty if [[ "${PIHOLE_DNS_2}" != "" ]]; then - sed -i "s/@DNS2@/$PIHOLE_DNS_2/" "${dnsmasq_pihole_01_target}" - else - sed -i '/^server=@DNS2@/d' "${dnsmasq_pihole_01_target}" + addKey "${dnsmasq_pihole_01_target}" "server=$PIHOLE_DNS_2" fi # Set the cache size - sed -i "s/@CACHE_SIZE@/$CACHE_SIZE/" "${dnsmasq_pihole_01_target}" + addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "cache-size" "$$CACHE_SIZE" sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' "${dnsmasq_conf}" # If the user does not want to enable logging, if [[ "${QUERY_LOGGING}" == false ]] ; then - # disable it by commenting out the directive in the DNS config file - sed -i 's/^log-queries/#log-queries/' "${dnsmasq_pihole_01_target}" + # remove itfrom the DNS config file + removeKey "${dnsmasq_pihole_01_target}" "log-queries" else - # Otherwise, enable it by uncommenting the directive in the DNS config file - sed -i 's/^#log-queries/log-queries/' "${dnsmasq_pihole_01_target}" + # Otherwise, enable it by adding the directive to the DNS config file + addKey "${dnsmasq_pihole_01_target}" "log-queries" fi printf " %b Installing %s..." "${INFO}" "${dnsmasq_rfc6761_06_source}" @@ -1365,9 +1361,9 @@ installConfigs() { chmod 644 "${PI_HOLE_CONFIG_DIR}/dns-servers.conf" # Install template file if it does not exist - if [[ ! -r "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then + if [[ ! -r "${FTL_CONFIG_FILE}" ]]; then install -d -m 0755 ${PI_HOLE_CONFIG_DIR} - if ! install -T -o pihole -m 664 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.conf" "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then + if ! install -T -o pihole -m 664 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.conf" "${FTL_CONFIG_FILE}" &>/dev/null; then printf " %b Error: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" return 1 fi @@ -1784,30 +1780,24 @@ create_pihole_user() { # This function saves any changes to the setup variables into the setupvars.conf file for future runs finalExports() { - # If the setup variable file exists, - if [[ -e "${setupVars}" ]]; then - # update the variables in the file - sed -i.update.bak '/PIHOLE_INTERFACE/d;/PIHOLE_DNS_1\b/d;/PIHOLE_DNS_2\b/d;/QUERY_LOGGING/d;/INSTALL_WEB_SERVER/d;/INSTALL_WEB_INTERFACE/d;/LIGHTTPD_ENABLED/d;/CACHE_SIZE/d;/DNS_FQDN_REQUIRED/d;/DNS_BOGUS_PRIV/d;/DNSMASQ_LISTENING/d;' "${setupVars}" - fi - # echo the information to the user - { - echo "PIHOLE_INTERFACE=${PIHOLE_INTERFACE}" - echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}" - echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}" - echo "QUERY_LOGGING=${QUERY_LOGGING}" - echo "INSTALL_WEB_SERVER=${INSTALL_WEB_SERVER}" - echo "INSTALL_WEB_INTERFACE=${INSTALL_WEB_INTERFACE}" - echo "LIGHTTPD_ENABLED=${LIGHTTPD_ENABLED}" - echo "CACHE_SIZE=${CACHE_SIZE}" - echo "DNS_FQDN_REQUIRED=${DNS_FQDN_REQUIRED:-true}" - echo "DNS_BOGUS_PRIV=${DNS_BOGUS_PRIV:-true}" - echo "DNSMASQ_LISTENING=${DNSMASQ_LISTENING:-local}" - }>> "${setupVars}" + # set or update the variables in the file + + addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}" + addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}" + addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}" + addOrEditKeyValPair "${setupVars}" "QUERY_LOGGING" "${QUERY_LOGGING}" + addOrEditKeyValPair "${setupVars}" "INSTALL_WEB_SERVER" "${INSTALL_WEB_SERVER}" + addOrEditKeyValPair "${setupVars}" "INSTALL_WEB_INTERFACE" "${INSTALL_WEB_INTERFACE}" + addOrEditKeyValPair "${setupVars}" "LIGHTTPD_ENABLED" "${LIGHTTPD_ENABLED}" + addOrEditKeyValPair "${setupVars}" "CACHE_SIZE" "${CACHE_SIZE}" + addOrEditKeyValPair "${setupVars}" "DNS_FQDN_REQUIRED" "${DNS_FQDN_REQUIRED:-true}" + addOrEditKeyValPair "${setupVars}" "DNS_BOGUS_PRIV" "${DNS_BOGUS_PRIV:-true}" + addOrEditKeyValPair "${setupVars}" "DNSMASQ_LISTENING" "${DNSMASQ_LISTENING:-local}" + chmod 644 "${setupVars}" # Set the privacy level - sed -i '/PRIVACYLEVEL/d' "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" - echo "PRIVACYLEVEL=${PRIVACY_LEVEL}" >> "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" + addOrEditKeyValPair "${FTL_CONFIG_FILE}" "PRIVACYLEVEL" "${PRIVACY_LEVEL}" # Bring in the current settings and the functions to manipulate them source "${setupVars}" @@ -1895,6 +1885,16 @@ installPihole() { printf " %b Failure in dependent script copy function.\\n" "${CROSS}" exit 1 fi + + # /opt/pihole/utils.sh should be installed by installScripts now, so we can use it + if [ -f "${PI_HOLE_INSTALL_DIR}/utils.sh" ]; then + # shellcheck disable=SC1091 + source "${PI_HOLE_INSTALL_DIR}/utils.sh" + else + printf " %b Failure: /opt/pihole/utils.sh does not exist .\\n" "${CROSS}" + exit 1 + fi + # Install config files if ! installConfigs; then printf " %b Failure in dependent config copy function.\\n" "${CROSS}" @@ -2569,8 +2569,8 @@ main() { source "${setupVars}" # Get the privacy level if it exists (default is 0) - if [[ -f "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then - PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf") + if [[ -f "${FTL_CONFIG_FILE}" ]]; then + PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${FTL_CONFIG_FILE}") # If no setting was found, default to 0 PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 1e2a849b40..70b30b6f72 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -79,6 +79,7 @@ def test_setupVars_saved_to_file(host): echo start TERM=xterm source /opt/pihole/basic-install.sh + source /opt/pihole/utils.sh {} mkdir -p /etc/dnsmasq.d version_check_dnsmasq From 1335c44deba1df77ed4d369ec7524ac512fac738 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 24 Aug 2022 20:36:21 +0200 Subject: [PATCH 143/638] Add jq 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 4d860d33a8..a51f5d9aa3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -330,7 +330,7 @@ package_manager_detect() { # Packages required to run this install script (stored as an array) INSTALLER_DEPS=(git iproute2 dialog ca-certificates) # Packages required to run Pi-hole (stored as an array) - PIHOLE_DEPS=(cron curl iputils-ping psmisc sudo unzip idn2 libcap2-bin dns-root-data libcap2 netcat-openbsd procps) + PIHOLE_DEPS=(cron curl iputils-ping psmisc sudo unzip idn2 libcap2-bin dns-root-data libcap2 netcat-openbsd procps jq) # 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") @@ -360,7 +360,7 @@ package_manager_detect() { PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" OS_CHECK_DEPS=(grep bind-utils) INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) - PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat) + PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq) 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 49b9dc8888b399439cf983ae2796738882e83805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 24 Aug 2022 21:44:29 +0200 Subject: [PATCH 144/638] Remove json_extract function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 0c9f385eb4..37211cc68d 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -8,23 +8,6 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -# Credit: https://stackoverflow.com/a/46324904 -function json_extract() { - local key=$1 - local json=$2 - - local string_regex='"([^"\]|\\.)*"' - local number_regex='-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?' - local value_regex="${string_regex}|${number_regex}|true|false|null" - local pair_regex="\"${key}\"[[:space:]]*:[[:space:]]*(${value_regex})" - - if [[ ${json} =~ ${pair_regex} ]]; then - echo $(sed 's/^"\|"$//g' <<< "${BASH_REMATCH[1]}") - else - return 1 - fi -} - function get_local_branch() { # Return active branch cd "${1}" 2> /dev/null || return 1 @@ -61,19 +44,19 @@ if [[ "$2" == "remote" ]]; then sleep 30 fi - GITHUB_CORE_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null)")" + GITHUB_CORE_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - GITHUB_WEB_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null)")" + GITHUB_WEB_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" fi - GITHUB_FTL_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null)")" + GITHUB_FTL_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" if [[ "${PIHOLE_DOCKER_TAG}" ]]; then - GITHUB_DOCKER_VERSION="$(json_extract tag_name "$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null)")" + GITHUB_DOCKER_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi From 53c0982c8b52859062123ee041fb37fbf4b520a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 30 Aug 2022 20:03:38 +0200 Subject: [PATCH 145/638] Set connection timeout for curl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 6f96b8457e..2d0d0ff5df 100755 --- a/gravity.sh +++ b/gravity.sh @@ -641,7 +641,7 @@ gravity_DownloadBlocklistFromUrl() { fi # shellcheck disable=SC2086 - httpCode=$(curl -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null) + httpCode=$(curl --connect-timeout 10 -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null) case $url in # Did we "download" a local file? From 230d6a435fb2a5ea7f0afd99c28d764c072ba696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 31 Aug 2022 21:41:57 +0200 Subject: [PATCH 146/638] Semi hardcode the connection_timeout value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 2d0d0ff5df..7c831b224b 100755 --- a/gravity.sh +++ b/gravity.sh @@ -40,6 +40,7 @@ gravityDBschema="${piholeGitDir}/advanced/Templates/gravity.db.sql" gravityDBcopy="${piholeGitDir}/advanced/Templates/gravity_copy.sql" domainsExtension="domains" +curl_connect_timeout=10 # Source setupVars from install script setupVars="${piholeDir}/setupVars.conf" @@ -641,7 +642,7 @@ gravity_DownloadBlocklistFromUrl() { fi # shellcheck disable=SC2086 - httpCode=$(curl --connect-timeout 10 -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null) + httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null) case $url in # Did we "download" a local file? From 46e1a87e9e80b9e31c03cfd3b68c0812e27fb920 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 3 Sep 2022 12:09:37 +0100 Subject: [PATCH 147/638] Tweak FTL test to ensure we don't get false positives on incompatible OS (Will remote Ub18 in a separate commit) Signed-off-by: Adam Warner --- test/test_any_automated_install.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 1e2a849b40..7ec7507899 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -880,13 +880,14 @@ def test_FTL_binary_installed_and_responsive_no_errors(host): source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) + echo "development" > /etc/pihole/ftlbranch binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - pihole-FTL version ''') + version_check = host.run('pihole-FTL version') expected_stdout = 'v' - assert expected_stdout in installed_binary.stdout + assert expected_stdout in version_check.stdout def test_IPv6_only_link_local(host): From 0f74165c9d5ee23c951384dcefad8e7efa41249e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 3 Sep 2022 12:55:17 +0100 Subject: [PATCH 148/638] Drop Ubuntu 18 tests Tweek version_check to only output 1st char of the reported version Signed-off-by: Adam Warner --- .github/workflows/test.yml | 2 +- test/_ubuntu_18.Dockerfile | 17 ----------------- test/test_any_automated_install.py | 5 ++++- test/tox.ubuntu_18.ini | 8 -------- 4 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 test/_ubuntu_18.Dockerfile delete mode 100644 test/tox.ubuntu_18.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 835be1664f..318cfcc403 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -43,7 +43,7 @@ jobs: strategy: fail-fast: false matrix: - distro: [debian_10, debian_11, ubuntu_18, ubuntu_20, ubuntu_22, centos_8, fedora_34] + distro: [debian_10, debian_11, ubuntu_20, ubuntu_22, centos_8, fedora_34] env: DISTRO: ${{matrix.distro}} steps: diff --git a/test/_ubuntu_18.Dockerfile b/test/_ubuntu_18.Dockerfile deleted file mode 100644 index 47f1893e72..0000000000 --- a/test/_ubuntu_18.Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM buildpack-deps:bionic-scm - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 7ec7507899..7030024308 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -885,7 +885,10 @@ def test_FTL_binary_installed_and_responsive_no_errors(host): theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" ''') - version_check = host.run('pihole-FTL version') + version_check = host.run(''' + VERSION=$(pihole-FTL version) + echo ${VERSION:0:1} + ''') expected_stdout = 'v' assert expected_stdout in version_check.stdout diff --git a/test/tox.ubuntu_18.ini b/test/tox.ubuntu_18.ini deleted file mode 100644 index a2513dfdcd..0000000000 --- a/test/tox.ubuntu_18.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py38 - -[testenv] -whitelist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _ubuntu_18.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 8f1a3d48d35eb7175c44eecf9f37322478806520 Mon Sep 17 00:00:00 2001 From: Siddhu <693151+arevindh@users.noreply.github.com> Date: Sun, 4 Sep 2022 03:44:33 +0000 Subject: [PATCH 149/638] fix action erros --- README.md | 2 +- advanced/Scripts/version.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ec737123e..88e392610c 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,4 @@ We are not affiliated or endorced by [Pi-hole](https://github.com/pi-hole/AdminL ## Use Official CLI Mode for best results. -[Uninstall Instructions](https://github.com/arevindh/pihole-speedtest/wiki/Uninstalling-Speedtest-Mod) \ No newline at end of file +[Uninstall Instructions](https://github.com/arevindh/pihole-speedtest/wiki/Uninstalling-Speedtest-Mod) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 0c7216554c..d3936d4f32 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -105,7 +105,7 @@ getRemoteVersion(){ return 0 fi - + if [[ "$daemon" == "AdminLTE" ]]; then owner="arevindh" fi From d0c566bde92137ce7469c95e575e4465ed118941 Mon Sep 17 00:00:00 2001 From: Siddhu <693151+arevindh@users.noreply.github.com> Date: Mon, 5 Sep 2022 10:29:24 +0000 Subject: [PATCH 150/638] fix old issues --- advanced/Scripts/webpage.sh | 159 +++++++++++++----------------------- 1 file changed, 59 insertions(+), 100 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 0ec5da72a3..179ae4010a 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -502,94 +502,78 @@ SetWebUILayout() { addOrEditKeyValPair "${setupVars}" "WEBUIBOXEDLAYOUT" "${args[2]}" } - -ClearSpeedtestData(){ +ClearSpeedtestData() { mv $speedtestdb $speedtestdb"_old" cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb } -ChageSpeedTestSchedule(){ - if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then - change_setting "SPEEDTESTSCHEDULE" "${args[2]}" - SetCronTab ${args[2]} - fi - fi -} - -SpeedtestServer(){ - if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - change_setting "SPEEDTEST_SERVER" "${args[2]}" - # SetCronTab ${args[2]} - else - # Autoselect for invalid data - change_setting "SPEEDTEST_SERVER" "" - fi - -} - - -RunSpeedtestNow(){ - mkdir -p /tmp/speedtest - lockfile="/tmp/speedtest/lock" - if [ -f $speedtestdb ] - then - echo "" - else - cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb - sleep 2 - fi - if [ -f "$lockfile" ] - then - echo "Speedtest is already in progress, is something went wrong delete this file - "$lockfile - else - touch $lockfile - if [[ "${args[2]}" == "-n" ]]; then - speedtest-cli +ChageSpeedTestSchedule() { + if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then + if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" + SetCronTab ${args[2]} + fi + fi +} + + + +SpeedtestServer() { + if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "${args[2]}" else - echo "Testing Speed" - result=`$speedtestfile` - echo $result - rm $lockfile + # Autoselect for invalid data + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "" fi - fi } -SpeedtestMode(){ - if [[ "${args[2]}" ]]; then - change_setting "SPEEDTEST_MODE" "${args[2]}" - else - # Autoselect for invalid data - change_setting "SPEEDTEST_MODE" "python" - fi +RunSpeedtestNow() { + /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh +} + +SpeedtestMode() { + if [[ "${args[2]}" ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_MODE" "${args[2]}" + else + # Autoselect for invalid data + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_MODE" "" + fi } +function UpdateSpeedTestRange() { + if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then + if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 30 ]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" + fi + fi +} -SetCronTab() -{ - # Remove OLD - crontab -l > crontab.tmp || true +SetCronTab() { + # Remove OLD + crontab -l >crontab.tmp || true - if [[ "$1" == "0" ]]; then - sed -i '/speedtest/d' crontab.tmp - crontab crontab.tmp && rm -f crontab.tmp - else - sed -i '/speedtest/d' crontab.tmp + if [[ "$1" == "0" ]]; then + sed -i '/speedtest/d' crontab.tmp + crontab crontab.tmp && rm -f crontab.tmp + else + sed -i '/speedtest/d' crontab.tmp - mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) + mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) - if [[ "$mode" =~ "official" ]]; then - speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" - else - speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" - fi + if [[ "$mode" =~ "official" ]]; then + speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" + else + speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" + fi - newtab="0 */"${1}" * * * sudo \""${speedtest_file}"\" > /dev/null 2>&1" - printf '%s\n' "$newtab" >>crontab.tmp - crontab crontab.tmp && rm -f crontab.tmp - fi + newtab="0 */"${1}" * * * sudo \""${speedtest_file}"\" > /dev/null 2>&1" + printf '%s\n' "$newtab" >>crontab.tmp + crontab crontab.tmp && rm -f crontab.tmp + fi } + + SetWebUITheme() { addOrEditKeyValPair "${setupVars}" "WEBTHEME" "${args[2]}" } @@ -635,33 +619,6 @@ CustomizeAdLists() { fi } -function UpdateSpeedTestRange(){ - if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 30 ]; then - change_setting "SPEEDTEST_CHART_DAYS" "${args[2]}" - fi - fi -} - -SetPrivacyMode() { - if [[ "${args[2]}" == "true" ]]; then - change_setting "API_PRIVACY_MODE" "true" - else - change_setting "API_PRIVACY_MODE" "false" - fi -} - -ResolutionSettings() { - typ="${args[2]}" - state="${args[3]}" - - if [[ "${typ}" == "forward" ]]; then - change_setting "API_GET_UPSTREAM_DNS_HOSTNAME" "${state}" - elif [[ "${typ}" == "clients" ]]; then - change_setting "API_GET_CLIENT_HOSTNAME" "${state}" - fi -} - AddDHCPStaticAddress() { mac="${args[2]}" ip="${args[3]}" @@ -947,7 +904,7 @@ main() { "-s" | "speedtest" ) ChageSpeedTestSchedule;; "-sd" ) UpdateSpeedTestRange;; "-sn" ) RunSpeedtestNow;; - "-sm" ) SpeedtestMode;; + "-sm" ) SpeedtestMode;; "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; "addcustomdns" ) AddCustomDNSAddress;; @@ -957,8 +914,10 @@ main() { "ratelimit" ) SetRateLimit;; * ) helpFunc;; esac + shift - if [[ $# = 0 ]]; then + + if [[ $# = 0 ]]; then helpFunc fi } From 89b88416b363840e5a7afd72e9f0f5d65ddf5d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 6 Sep 2022 17:09:52 +0200 Subject: [PATCH 151/638] Fix 4898 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pihole b/pihole index eb825965e4..1047d15207 100755 --- a/pihole +++ b/pihole @@ -104,6 +104,9 @@ restartDNS() { local svcOption svc str output status pid icon FTL_PID_FILE svcOption="${1:-restart}" + # get the current path to the pihole-FTL.pid + FTL_PID_FILE="$(getFTLPIDFile)" + # Determine if we should reload or restart if [[ "${svcOption}" =~ "reload-lists" ]]; then # Reloading of the lists has been requested @@ -111,9 +114,6 @@ restartDNS() { # Note 2: We cannot use killall here as it does # not know about real-time signals - # get the current path to the pihole-FTL.pid - FTL_PID_FILE="$(getFTLPIDFile)" - pid="$(getFTLPID ${FTL_PID_FILE})" if [[ "$pid" -eq "-1" ]]; then svc="true" From bf256aa5a77ed94115eb7496a3128733fe0b3bf3 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 14 Sep 2022 22:38:41 +0100 Subject: [PATCH 152/638] If docker version env var is set, store it in /etc/pihole/versions file for later use Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 37211cc68d..f003739b7b 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -84,4 +84,8 @@ else FTL_VERSION="$(pihole-FTL version)" addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" + if [[ "${PIHOLE_DOCKER_TAG}" ]]; then + addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${PIHOLE_DOCKER_TAG}" + fi + fi From 760325eb76f3a518b818abfb6e546284e9fa66e1 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 14 Sep 2022 22:49:37 +0100 Subject: [PATCH 153/638] Update piholeDebug to source versions file for DOCKER_VERSION instead of reading PIHOLE_DOCKER_TAG Signed-off-by: Adam Warner --- advanced/Scripts/piholeDebug.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 6543efbbef..d016b24d78 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -41,6 +41,9 @@ else #OVER="\r\033[K" fi +# shellcheck disable=SC1091 +. /etc/pihole/versions + OBFUSCATED_PLACEHOLDER="" # FAQ URLs for use in showing the debug log @@ -465,8 +468,8 @@ diagnose_operating_system() { # Display the current test that is running echo_current_diagnostic "Operating system" - # If the PIHOLE_DOCKER_TAG variable is set, include this information in the debug output - [ -n "${PIHOLE_DOCKER_TAG}" ] && log_write "${INFO} Pi-hole Docker Container: ${PIHOLE_DOCKER_TAG}" + # If DOCKER_VERSION is set (Sourced from /etc/pihole/versions at start of script), include this information in the debug output + [ -n "${DOCKER_VERSION}" ] && log_write "${INFO} Pi-hole Docker Container: ${DOCKER_VERSION}" # If there is a /etc/*release file, it's probably a supported operating system, so we can if ls /etc/*release 1> /dev/null 2>&1; then @@ -802,7 +805,7 @@ check_networking() { ping_gateway "6" # Skip the following check if installed in docker container. Unpriv'ed containers do not have access to the information required # to resolve the service name listening - and the container should not start if there was a port conflict anyway - [ -z "${PIHOLE_DOCKER_TAG}" ] && check_required_ports + [ -z "${DOCKER_VERSION}" ] && check_required_ports } check_x_headers() { From c1a927fff1090c9d3dcc32138ba36cc858f6bc26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 15 Sep 2022 10:59:34 +0200 Subject: [PATCH 154/638] Run test workflows on python 3.10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 4 ++-- test/setup.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 318cfcc403..7725ecc37e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,10 +51,10 @@ jobs: name: Checkout repository uses: actions/checkout@v3.0.2 - - name: Set up Python 3.8 + name: Set up Python 3.10 uses: actions/setup-python@v4.2.0 with: - python-version: 3.8 + python-version: '3.10' - name: Install dependencies run: pip install -r test/requirements.txt diff --git a/test/setup.py b/test/setup.py index 0e393bc131..9f3b4b48e9 100644 --- a/test/setup.py +++ b/test/setup.py @@ -1,6 +1,7 @@ from setuptools import setup setup( + py_modules=[], setup_requires=['pytest-runner'], tests_require=['pytest'], ) From 8bc5b16527094ea823b4a6d536b26b7b5b2c7efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 15 Sep 2022 11:00:33 +0200 Subject: [PATCH 155/638] Set tox envlist to py3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/tox.centos_8.ini | 2 +- test/tox.debian_10.ini | 2 +- test/tox.debian_11.ini | 2 +- test/tox.fedora_34.ini | 2 +- test/tox.ubuntu_20.ini | 2 +- test/tox.ubuntu_22.ini | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini index e94c24337f..71b147c79a 100644 --- a/test/tox.centos_8.ini +++ b/test/tox.centos_8.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38 +envlist = py3 [testenv] whitelist_externals = docker diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini index 3b182cdccb..d21620dcbf 100644 --- a/test/tox.debian_10.ini +++ b/test/tox.debian_10.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38 +envlist = py3 [testenv] whitelist_externals = docker diff --git a/test/tox.debian_11.ini b/test/tox.debian_11.ini index c7e41a91cd..f25469226c 100644 --- a/test/tox.debian_11.ini +++ b/test/tox.debian_11.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38 +envlist = py3 [testenv] whitelist_externals = docker diff --git a/test/tox.fedora_34.ini b/test/tox.fedora_34.ini index 2685698467..f4115a6615 100644 --- a/test/tox.fedora_34.ini +++ b/test/tox.fedora_34.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38 +envlist = py3 [testenv] whitelist_externals = docker diff --git a/test/tox.ubuntu_20.ini b/test/tox.ubuntu_20.ini index fb3d20d7b4..80fb74854b 100644 --- a/test/tox.ubuntu_20.ini +++ b/test/tox.ubuntu_20.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38 +envlist = py3 [testenv] whitelist_externals = docker diff --git a/test/tox.ubuntu_22.ini b/test/tox.ubuntu_22.ini index 2a3285aaec..41007a9c18 100644 --- a/test/tox.ubuntu_22.ini +++ b/test/tox.ubuntu_22.ini @@ -1,5 +1,5 @@ [tox] -envlist = py38 +envlist = py3 [testenv] whitelist_externals = docker From 3d53bda1211f29312cf722d9bd95739675c2aacf Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 15 Sep 2022 17:54:54 +0100 Subject: [PATCH 156/638] Update advanced/Scripts/updatecheck.sh Co-authored-by: yubiuser Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index f003739b7b..b1e111aef4 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -84,6 +84,7 @@ else FTL_VERSION="$(pihole-FTL version)" addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" + # PIHOLE_DOCKER_TAG is set as env variable only on docker installations if [[ "${PIHOLE_DOCKER_TAG}" ]]; then addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${PIHOLE_DOCKER_TAG}" fi From 5cc317de5b4e1fee9f7db82c42996ba82c491f97 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 16 Sep 2022 02:31:52 -0300 Subject: [PATCH 157/638] Change texts after Block Page removal Signed-off-by: RD WebDesign --- 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 d016b24d78..fe75c4d3eb 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -815,7 +815,7 @@ check_x_headers() { # Similarly, it will show "X-Pi-hole: The Pi-hole Web interface is working!" if you view the header returned # when accessing the dashboard (i.e curl -I pi.hole/admin/) # server is operating correctly - echo_current_diagnostic "Dashboard and block page" + echo_current_diagnostic "Dashboard headers" # Use curl -I to get the header and parse out just the X-Pi-hole one local full_curl_output_dashboard local dashboard @@ -825,7 +825,7 @@ check_x_headers() { local dashboard_working dashboard_working="X-Pi-hole: The Pi-hole Web interface is working!" - # Same logic applies to the dashboard as above, if the X-Header matches what a working system should have, + # If the X-Header matches what a working system should have, if [[ $dashboard == "$dashboard_working" ]]; then # then we can show a success log_write "$TICK Web interface X-Header: ${COL_GREEN}${dashboard}${COL_NC}" From 7e6f81f814ddd04df1d4bad9b69c1395e95d1d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 17 Sep 2022 11:58:26 +0200 Subject: [PATCH 158/638] Add comment in lighttpd.conf how to change the server port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/lighttpd.conf.debian | 2 ++ advanced/lighttpd.conf.fedora | 2 ++ 2 files changed, 4 insertions(+) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 4545bb2e8f..21e48d6c40 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -32,6 +32,8 @@ server.errorlog = "/var/log/lighttpd/error-pihole.log" server.pid-file = "/run/lighttpd.pid" server.username = "www-data" server.groupname = "www-data" +# For lighttpd version 1.4.46 or above, the port can be overwritten in `/etc/lighttpd/external.conf` using the := operator +# e.g. server.port := 8000 server.port = 80 accesslog.filename = "/var/log/lighttpd/access-pihole.log" accesslog.format = "%{%s}t|%V|%r|%s|%b" diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 12930302e4..3da62839db 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -33,6 +33,8 @@ server.errorlog = "/var/log/lighttpd/error-pihole.log" server.pid-file = "/run/lighttpd.pid" server.username = "lighttpd" server.groupname = "lighttpd" +# For lighttpd version 1.4.46 or above, the port can be overwritten in `/etc/lighttpd/external.conf` using the := operator +# e.g. server.port := 8000 server.port = 80 accesslog.filename = "/var/log/lighttpd/access-pihole.log" accesslog.format = "%{%s}t|%V|%r|%s|%b" From 5fe170666ab13486f31937a4aaba17d30123826d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 17 Sep 2022 10:08:40 +0000 Subject: [PATCH 159/638] Bump actions/stale from 5.1.1 to 5.2.0 Bumps [actions/stale](https://github.com/actions/stale) from 5.1.1 to 5.2.0. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v5.1.1...v5.2.0) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index c0f64bb41d..6b70a153ef 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v5.1.1 + - uses: actions/stale@v5.2.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 From f90fb8b9467ae839509838af168fa909327cc9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 14 Sep 2022 09:00:35 +0200 Subject: [PATCH 160/638] Change wording in chronometer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/chronometer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index fddb393677..488bfd042e 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -503,11 +503,11 @@ chronoFunc() { fi printFunc " Pi-hole: " "$ph_status" "$ph_info" - printFunc " Ads Today: " "$ads_percentage_today%" "$ads_info" + printFunc " Blocked %: " "$ads_percentage_today%" "$ads_info" printFunc "Local Qrys: " "$queries_cached_percentage%" "$dns_info" - printFunc " Blocked: " "$recent_blocked" - printFunc "Top Advert: " "$top_ad" + printFunc "Last Blckd: " "$recent_blocked" + printFunc " Top Blckd: " "$top_ad" # Provide more stats on screens with more lines if [[ "$scr_lines" -eq 17 ]]; then From 00e51f32b5a3bb2a779f9147ad957b2dcc6d4044 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 17 Sep 2022 16:46:31 +0200 Subject: [PATCH 161/638] Blcked => Block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/chronometer.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 488bfd042e..af0079948d 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -503,11 +503,11 @@ chronoFunc() { fi printFunc " Pi-hole: " "$ph_status" "$ph_info" - printFunc " Blocked %: " "$ads_percentage_today%" "$ads_info" + printFunc " Blocked: " "$ads_percentage_today%" "$ads_info" printFunc "Local Qrys: " "$queries_cached_percentage%" "$dns_info" - printFunc "Last Blckd: " "$recent_blocked" - printFunc " Top Blckd: " "$top_ad" + printFunc "Last Block: " "$recent_blocked" + printFunc " Top Block: " "$top_ad" # Provide more stats on screens with more lines if [[ "$scr_lines" -eq 17 ]]; then From 40f00c6f0b41e3445e19210a9c45b7940d543914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 18 Sep 2022 09:01:22 +0200 Subject: [PATCH 162/638] Fix gravity database integrity check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index fe75c4d3eb..fc4dcc5264 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1277,7 +1277,7 @@ analyze_gravity_list() { # if users want to check database integrity if [[ "${CHECK_DATABASE}" = true ]]; then - database_integrity_check "${PIHOLE_FTL_DB_FILE}" + database_integrity_check "${PIHOLE_GRAVITY_DB_FILE}" fi show_db_entries "Info table" "SELECT property,value FROM info" "20 40" From 2c3fea321bcf51616d6ab1ddac70221151f09aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 18 Sep 2022 09:10:24 +0200 Subject: [PATCH 163/638] Remove FAQ_ULA as it is unused in `core` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index fc4dcc5264..1edb1e3864 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -53,7 +53,6 @@ FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisite FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" FAQ_GATEWAY="${COL_CYAN}https://discourse.pi-hole.net/t/why-is-a-default-gateway-important-for-pi-hole/3546${COL_NC}" -FAQ_ULA="${COL_CYAN}https://discourse.pi-hole.net/t/use-ipv6-ula-addresses-for-pi-hole/2127${COL_NC}" FAQ_FTL_COMPATIBILITY="${COL_CYAN}https://github.com/pi-hole/FTL#compatibility-list${COL_NC}" FAQ_BAD_ADDRESS="${COL_CYAN}https://discourse.pi-hole.net/t/why-do-i-see-bad-address-at-in-pihole-log/3972${COL_NC}" From 60c35cb93c3799df76dd277e7fa984f679144b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 18 Sep 2022 13:08:44 +0200 Subject: [PATCH 164/638] Remove unused check_database_integrity() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1edb1e3864..ab16d7ff49 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1339,16 +1339,6 @@ database_integrity_check(){ } -check_database_integrity() { - echo_current_diagnostic "Gravity Database" - database_permissions "${PIHOLE_GRAVITY_DB_FILE}" - database_integrity_check "${PIHOLE_GRAVITY_DB_FILE}" - - echo_current_diagnostic "Pi-hole FTL Query Database" - database_permissions "${PIHOLE_FTL_DB_FILE}" - database_integrity_check "${PIHOLE_FTL_DB_FILE}" -} - # Show a text spinner during a long process run spinner(){ # Show the spinner only if there is a tty From 73ca4ebdbc10b39b29ced4babc6238ff48c1d5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 19 Sep 2022 11:44:53 +0200 Subject: [PATCH 165/638] Update test requirements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/requirements.txt | 1 - test/tox.centos_8.ini | 2 +- test/tox.debian_10.ini | 2 +- test/tox.debian_11.ini | 2 +- test/tox.fedora_34.ini | 2 +- test/tox.ubuntu_20.ini | 2 +- test/tox.ubuntu_22.ini | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/requirements.txt b/test/requirements.txt index d65ee6a5cf..0eb22a1b59 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,5 @@ docker-compose pytest pytest-xdist -pytest-cov pytest-testinfra tox diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini index 71b147c79a..dc160d2a05 100644 --- a/test/tox.centos_8.ini +++ b/test/tox.centos_8.ini @@ -2,7 +2,7 @@ envlist = py3 [testenv] -whitelist_externals = docker +allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini index d21620dcbf..ef9fa7a061 100644 --- a/test/tox.debian_10.ini +++ b/test/tox.debian_10.ini @@ -2,7 +2,7 @@ envlist = py3 [testenv] -whitelist_externals = docker +allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.debian_11.ini b/test/tox.debian_11.ini index f25469226c..6d25a0c840 100644 --- a/test/tox.debian_11.ini +++ b/test/tox.debian_11.ini @@ -2,7 +2,7 @@ envlist = py3 [testenv] -whitelist_externals = docker +allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_11.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.fedora_34.ini b/test/tox.fedora_34.ini index f4115a6615..d58cb0d485 100644 --- a/test/tox.fedora_34.ini +++ b/test/tox.fedora_34.ini @@ -2,7 +2,7 @@ envlist = py3 [testenv] -whitelist_externals = docker +allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _fedora_34.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.ubuntu_20.ini b/test/tox.ubuntu_20.ini index 80fb74854b..4ae79a0cb1 100644 --- a/test/tox.ubuntu_20.ini +++ b/test/tox.ubuntu_20.ini @@ -2,7 +2,7 @@ envlist = py3 [testenv] -whitelist_externals = docker +allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.ubuntu_22.ini b/test/tox.ubuntu_22.ini index 41007a9c18..3ddf7eca5c 100644 --- a/test/tox.ubuntu_22.ini +++ b/test/tox.ubuntu_22.ini @@ -2,7 +2,7 @@ envlist = py3 [testenv] -whitelist_externals = docker +allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 0932c5c4983e247c85ff3553dc6fdb6eac39c391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 19 Sep 2022 12:45:36 +0200 Subject: [PATCH 166/638] Add black python code formatter action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7725ecc37e..c078353860 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,7 +34,11 @@ jobs: - name: Run editorconfig-checker run: editorconfig-checker - + - + name: Run black python code formatter + uses: psf/black@stable + with: + src: "./test" distro-test: if: github.event.pull_request.draft == false From 0df38cd64ef4f77674f87188018d11f9d8fcfbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 19 Sep 2022 14:44:10 +0200 Subject: [PATCH 167/638] Format all /test files with black MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/conftest.py | 179 +++-- test/setup.py | 4 +- test/test_any_automated_install.py | 902 +++++++++++----------- test/test_any_utils.py | 120 +-- test/test_centos_common_support.py | 19 +- test/test_centos_fedora_common_support.py | 54 +- test/test_fedora_support.py | 14 +- 7 files changed, 699 insertions(+), 593 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index fb7e1eea33..e395ec279f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -6,12 +6,12 @@ SETUPVARS = { - 'PIHOLE_INTERFACE': 'eth99', - 'PIHOLE_DNS_1': '4.2.2.1', - 'PIHOLE_DNS_2': '4.2.2.2' + "PIHOLE_INTERFACE": "eth99", + "PIHOLE_DNS_1": "4.2.2.1", + "PIHOLE_DNS_2": "4.2.2.2", } -IMAGE = 'pytest_pihole:test_container' +IMAGE = "pytest_pihole:test_container" tick_box = "[\x1b[1;32m\u2713\x1b[0m]" cross_box = "[\x1b[1;31m\u2717\x1b[0m]" @@ -38,132 +38,187 @@ def run_bash(self, command, *args, **kwargs): @pytest.fixture def host(): # run a container - docker_id = subprocess.check_output( - ['docker', 'run', '-t', '-d', '--cap-add=ALL', IMAGE]).decode().strip() + docker_id = ( + subprocess.check_output(["docker", "run", "-t", "-d", "--cap-add=ALL", IMAGE]) + .decode() + .strip() + ) # return a testinfra connection to the container docker_host = testinfra.get_host("docker://" + docker_id) yield docker_host # at the end of the test suite, destroy the container - subprocess.check_call(['docker', 'rm', '-f', docker_id]) + subprocess.check_call(["docker", "rm", "-f", docker_id]) # Helper functions def mock_command(script, args, container): - ''' + """ Allows for setup of commands we don't really want to have to run for real in unit tests - ''' - full_script_path = '/usr/local/bin/{}'.format(script) - mock_script = dedent(r'''\ + """ + full_script_path = "/usr/local/bin/{}".format(script) + mock_script = dedent( + r"""\ #!/bin/bash -e echo "\$0 \$@" >> /var/log/{script} - case "\$1" in'''.format(script=script)) + case "\$1" in""".format( + script=script + ) + ) for k, v in args.items(): - case = dedent(''' + case = dedent( + """ {arg}) echo {res} exit {retcode} - ;;'''.format(arg=k, res=v[0], retcode=v[1])) + ;;""".format( + arg=k, res=v[0], retcode=v[1] + ) + ) mock_script += case - mock_script += dedent(''' - esac''') - container.run(''' + mock_script += dedent( + """ + esac""" + ) + container.run( + """ cat < {script}\n{content}\nEOF chmod +x {script} - rm -f /var/log/{scriptlog}'''.format(script=full_script_path, - content=mock_script, - scriptlog=script)) + rm -f /var/log/{scriptlog}""".format( + script=full_script_path, content=mock_script, scriptlog=script + ) + ) def mock_command_passthrough(script, args, container): - ''' + """ Per other mock_command* functions, allows intercepting of commands we don't want to run for real in unit tests, however also allows only specific arguments to be mocked. Anything not defined will be passed through to the actual command. Example use-case: mocking `git pull` but still allowing `git clone` to work as intended - ''' - orig_script_path = container.check_output('command -v {}'.format(script)) - full_script_path = '/usr/local/bin/{}'.format(script) - mock_script = dedent(r'''\ + """ + orig_script_path = container.check_output("command -v {}".format(script)) + full_script_path = "/usr/local/bin/{}".format(script) + mock_script = dedent( + r"""\ #!/bin/bash -e echo "\$0 \$@" >> /var/log/{script} - case "\$1" in'''.format(script=script)) + case "\$1" in""".format( + script=script + ) + ) for k, v in args.items(): - case = dedent(''' + case = dedent( + """ {arg}) echo {res} exit {retcode} - ;;'''.format(arg=k, res=v[0], retcode=v[1])) + ;;""".format( + arg=k, res=v[0], retcode=v[1] + ) + ) mock_script += case - mock_script += dedent(r''' + mock_script += dedent( + r""" *) {orig_script_path} "\$@" - ;;'''.format(orig_script_path=orig_script_path)) - mock_script += dedent(''' - esac''') - container.run(''' + ;;""".format( + orig_script_path=orig_script_path + ) + ) + mock_script += dedent( + """ + esac""" + ) + container.run( + """ cat < {script}\n{content}\nEOF chmod +x {script} - rm -f /var/log/{scriptlog}'''.format(script=full_script_path, - content=mock_script, - scriptlog=script)) + rm -f /var/log/{scriptlog}""".format( + script=full_script_path, content=mock_script, scriptlog=script + ) + ) def mock_command_run(script, args, container): - ''' + """ Allows for setup of commands we don't really want to have to run for real in unit tests - ''' - full_script_path = '/usr/local/bin/{}'.format(script) - mock_script = dedent(r'''\ + """ + full_script_path = "/usr/local/bin/{}".format(script) + mock_script = dedent( + r"""\ #!/bin/bash -e echo "\$0 \$@" >> /var/log/{script} - case "\$1 \$2" in'''.format(script=script)) + case "\$1 \$2" in""".format( + script=script + ) + ) for k, v in args.items(): - case = dedent(''' + case = dedent( + """ \"{arg}\") echo {res} exit {retcode} - ;;'''.format(arg=k, res=v[0], retcode=v[1])) + ;;""".format( + arg=k, res=v[0], retcode=v[1] + ) + ) mock_script += case - mock_script += dedent(''' - esac''') - container.run(''' + mock_script += dedent( + """ + esac""" + ) + container.run( + """ cat < {script}\n{content}\nEOF chmod +x {script} - rm -f /var/log/{scriptlog}'''.format(script=full_script_path, - content=mock_script, - scriptlog=script)) + rm -f /var/log/{scriptlog}""".format( + script=full_script_path, content=mock_script, scriptlog=script + ) + ) def mock_command_2(script, args, container): - ''' + """ Allows for setup of commands we don't really want to have to run for real in unit tests - ''' - full_script_path = '/usr/local/bin/{}'.format(script) - mock_script = dedent(r'''\ + """ + full_script_path = "/usr/local/bin/{}".format(script) + mock_script = dedent( + r"""\ #!/bin/bash -e echo "\$0 \$@" >> /var/log/{script} - case "\$1 \$2" in'''.format(script=script)) + case "\$1 \$2" in""".format( + script=script + ) + ) for k, v in args.items(): - case = dedent(''' + case = dedent( + """ \"{arg}\") echo \"{res}\" exit {retcode} - ;;'''.format(arg=k, res=v[0], retcode=v[1])) + ;;""".format( + arg=k, res=v[0], retcode=v[1] + ) + ) mock_script += case - mock_script += dedent(''' - esac''') - container.run(''' + mock_script += dedent( + """ + esac""" + ) + container.run( + """ cat < {script}\n{content}\nEOF chmod +x {script} - rm -f /var/log/{scriptlog}'''.format(script=full_script_path, - content=mock_script, - scriptlog=script)) + rm -f /var/log/{scriptlog}""".format( + script=full_script_path, content=mock_script, scriptlog=script + ) + ) def run_script(Pihole, script): diff --git a/test/setup.py b/test/setup.py index 9f3b4b48e9..cdde20d393 100644 --- a/test/setup.py +++ b/test/setup.py @@ -2,6 +2,6 @@ setup( py_modules=[], - setup_requires=['pytest-runner'], - tests_require=['pytest'], + setup_requires=["pytest-runner"], + tests_require=["pytest"], ) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 7030024308..895db6dcfe 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -10,39 +10,42 @@ mock_command_run, mock_command_2, mock_command_passthrough, - run_script + run_script, ) def test_supported_package_manager(host): - ''' + """ confirm installer exits when no supported package manager found - ''' + """ # break supported package managers - host.run('rm -rf /usr/bin/apt-get') - host.run('rm -rf /usr/bin/rpm') - package_manager_detect = host.run(''' + host.run("rm -rf /usr/bin/apt-get") + host.run("rm -rf /usr/bin/rpm") + package_manager_detect = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect - ''') - expected_stdout = cross_box + ' No supported package manager found' + """ + ) + expected_stdout = cross_box + " No supported package manager found" assert expected_stdout in package_manager_detect.stdout # assert package_manager_detect.rc == 1 def test_setupVars_are_sourced_to_global_scope(host): - ''' + """ currently update_dialogs sources setupVars with a dot, then various other functions use the variables. This confirms the sourced variables are in scope between functions - ''' - setup_var_file = 'cat < /etc/pihole/setupVars.conf\n' + """ + setup_var_file = "cat < /etc/pihole/setupVars.conf\n" for k, v in SETUPVARS.items(): setup_var_file += "{}={}\n".format(k, v) setup_var_file += "EOF\n" host.run(setup_var_file) - script = dedent('''\ + script = dedent( + """\ set -e printSetupVars() { # Currently debug test function only @@ -56,7 +59,8 @@ def test_setupVars_are_sourced_to_global_scope(host): } update_dialogs printSetupVars - ''') + """ + ) output = run_script(host, script).stdout @@ -65,16 +69,17 @@ def test_setupVars_are_sourced_to_global_scope(host): def test_setupVars_saved_to_file(host): - ''' + """ confirm saved settings are written to a file for future updates to re-use - ''' + """ # dedent works better with this and padding matching script below - set_setup_vars = '\n' + set_setup_vars = "\n" for k, v in SETUPVARS.items(): set_setup_vars += " {}={}\n".format(k, v) host.run(set_setup_vars) - script = dedent('''\ + script = dedent( + """\ set -e echo start TERM=xterm @@ -85,7 +90,10 @@ def test_setupVars_saved_to_file(host): echo "" > /etc/pihole/pihole-FTL.conf finalExports cat /etc/pihole/setupVars.conf - '''.format(set_setup_vars)) + """.format( + set_setup_vars + ) + ) output = run_script(host, script).stdout @@ -94,48 +102,52 @@ def test_setupVars_saved_to_file(host): def test_selinux_not_detected(host): - ''' + """ confirms installer continues when SELinux configuration file does not exist - ''' - check_selinux = host.run(''' + """ + check_selinux = host.run( + """ rm -f /etc/selinux/config source /opt/pihole/basic-install.sh checkSelinux - ''') - expected_stdout = info_box + ' SELinux not detected' + """ + ) + expected_stdout = info_box + " SELinux not detected" assert expected_stdout in check_selinux.stdout assert check_selinux.rc == 0 def test_installPiholeWeb_fresh_install_no_errors(host): - ''' + """ confirms all web page assets from Core repo are installed on a fresh build - ''' - installWeb = host.run(''' + """ + installWeb = host.run( + """ umask 0027 source /opt/pihole/basic-install.sh installPiholeWeb - ''') - expected_stdout = info_box + ' Installing 404 page...' + """ + ) + expected_stdout = info_box + " Installing 404 page..." assert expected_stdout in installWeb.stdout - expected_stdout = tick_box + (' Creating directory for 404 page, ' - 'and copying files') + expected_stdout = tick_box + ( + " Creating directory for 404 page, " "and copying files" + ) assert expected_stdout in installWeb.stdout - expected_stdout = info_box + ' Backing up index.lighttpd.html' + expected_stdout = info_box + " Backing up index.lighttpd.html" assert expected_stdout in installWeb.stdout - expected_stdout = ('No default index.lighttpd.html file found... ' - 'not backing up') + expected_stdout = "No default index.lighttpd.html file found... " "not backing up" assert expected_stdout in installWeb.stdout - expected_stdout = tick_box + ' Installing sudoer file' + expected_stdout = tick_box + " Installing sudoer file" assert expected_stdout in installWeb.stdout - web_directory = host.run('ls -r /var/www/html/pihole').stdout - assert 'index.php' in web_directory + web_directory = host.run("ls -r /var/www/html/pihole").stdout + assert "index.php" in web_directory def get_directories_recursive(host, directory): if directory is None: return directory - ls = host.run('ls -d {}'.format(directory + '/*/')) + ls = host.run("ls -d {}".format(directory + "/*/")) directories = list(filter(bool, ls.stdout.splitlines())) dirs = directories for dirval in directories: @@ -148,61 +160,41 @@ def get_directories_recursive(host, directory): def test_installPihole_fresh_install_readableFiles(host): - ''' + """ confirms all necessary files are readable by pihole user - ''' + """ # dialog returns Cancel for user prompt - mock_command('dialog', {'*': ('', '0')}, host) + mock_command("dialog", {"*": ("", "0")}, host) # mock git pull - mock_command_passthrough('git', {'pull': ('', '0')}, host) + mock_command_passthrough("git", {"pull": ("", "0")}, host) # mock systemctl to not start lighttpd and FTL mock_command_2( - 'systemctl', + "systemctl", { - 'enable lighttpd': ( - '', - '0' - ), - 'restart lighttpd': ( - '', - '0' - ), - 'start lighttpd': ( - '', - '0' - ), - 'enable pihole-FTL': ( - '', - '0' - ), - 'restart pihole-FTL': ( - '', - '0' - ), - 'start pihole-FTL': ( - '', - '0' - ), - '*': ( - 'echo "systemctl call with $@"', - '0' - ), + "enable lighttpd": ("", "0"), + "restart lighttpd": ("", "0"), + "start lighttpd": ("", "0"), + "enable pihole-FTL": ("", "0"), + "restart pihole-FTL": ("", "0"), + "start pihole-FTL": ("", "0"), + "*": ('echo "systemctl call with $@"', "0"), }, - host + host, ) # try to install man - host.run('command -v apt-get > /dev/null && apt-get install -qq man') - host.run('command -v dnf > /dev/null && dnf install -y man') - host.run('command -v yum > /dev/null && yum install -y man') + host.run("command -v apt-get > /dev/null && apt-get install -qq man") + host.run("command -v dnf > /dev/null && dnf install -y man") + host.run("command -v yum > /dev/null && yum install -y man") # create configuration file - setup_var_file = 'cat < /etc/pihole/setupVars.conf\n' + setup_var_file = "cat < /etc/pihole/setupVars.conf\n" for k, v in SETUPVARS.items(): setup_var_file += "{}={}\n".format(k, v) setup_var_file += "INSTALL_WEB_SERVER=true\n" setup_var_file += "INSTALL_WEB_INTERFACE=true\n" setup_var_file += "EOF\n" host.run(setup_var_file) - install = host.run(''' + install = host.run( + """ export TERM=xterm export DEBIAN_FRONTEND=noninteractive umask 0027 @@ -212,183 +204,164 @@ def test_installPihole_fresh_install_readableFiles(host): runUnattended=true useUpdateVars=true main - ''') + """ + ) assert 0 == install.rc maninstalled = True - if (info_box + ' man not installed') in install.stdout: + if (info_box + " man not installed") in install.stdout: maninstalled = False - piholeuser = 'pihole' + piholeuser = "pihole" exit_status_success = 0 test_cmd = 'su --shell /bin/bash --command "test -{0} {1}" -p {2}' # check files in /etc/pihole for read, write and execute permission - check_etc = test_cmd.format('r', '/etc/pihole', piholeuser) + check_etc = test_cmd.format("r", "/etc/pihole", piholeuser) actual_rc = host.run(check_etc).rc assert exit_status_success == actual_rc - check_etc = test_cmd.format('x', '/etc/pihole', piholeuser) + check_etc = test_cmd.format("x", "/etc/pihole", piholeuser) actual_rc = host.run(check_etc).rc assert exit_status_success == actual_rc # readable and writable dhcp.leases - check_leases = test_cmd.format('r', '/etc/pihole/dhcp.leases', piholeuser) + check_leases = test_cmd.format("r", "/etc/pihole/dhcp.leases", piholeuser) actual_rc = host.run(check_leases).rc assert exit_status_success == actual_rc - check_leases = test_cmd.format('w', '/etc/pihole/dhcp.leases', piholeuser) + check_leases = test_cmd.format("w", "/etc/pihole/dhcp.leases", piholeuser) actual_rc = host.run(check_leases).rc # readable dns-servers.conf assert exit_status_success == actual_rc - check_servers = test_cmd.format( - 'r', '/etc/pihole/dns-servers.conf', piholeuser) + check_servers = test_cmd.format("r", "/etc/pihole/dns-servers.conf", piholeuser) actual_rc = host.run(check_servers).rc assert exit_status_success == actual_rc # readable install.log - check_install = test_cmd.format( - 'r', '/etc/pihole/install.log', piholeuser) + check_install = test_cmd.format("r", "/etc/pihole/install.log", piholeuser) actual_rc = host.run(check_install).rc assert exit_status_success == actual_rc # readable versions - check_localversion = test_cmd.format( - 'r', '/etc/pihole/versions', piholeuser) + check_localversion = test_cmd.format("r", "/etc/pihole/versions", piholeuser) actual_rc = host.run(check_localversion).rc assert exit_status_success == actual_rc # readable logrotate - check_logrotate = test_cmd.format( - 'r', '/etc/pihole/logrotate', piholeuser) + check_logrotate = test_cmd.format("r", "/etc/pihole/logrotate", piholeuser) actual_rc = host.run(check_logrotate).rc assert exit_status_success == actual_rc # readable macvendor.db - check_macvendor = test_cmd.format( - 'r', '/etc/pihole/macvendor.db', piholeuser) + check_macvendor = test_cmd.format("r", "/etc/pihole/macvendor.db", piholeuser) actual_rc = host.run(check_macvendor).rc assert exit_status_success == actual_rc # readable and writeable pihole-FTL.conf - check_FTLconf = test_cmd.format( - 'r', '/etc/pihole/pihole-FTL.conf', piholeuser) + check_FTLconf = test_cmd.format("r", "/etc/pihole/pihole-FTL.conf", piholeuser) actual_rc = host.run(check_FTLconf).rc assert exit_status_success == actual_rc - check_FTLconf = test_cmd.format( - 'w', '/etc/pihole/pihole-FTL.conf', piholeuser) + check_FTLconf = test_cmd.format("w", "/etc/pihole/pihole-FTL.conf", piholeuser) actual_rc = host.run(check_FTLconf).rc assert exit_status_success == actual_rc # readable setupVars.conf - check_setup = test_cmd.format( - 'r', '/etc/pihole/setupVars.conf', piholeuser) + check_setup = test_cmd.format("r", "/etc/pihole/setupVars.conf", piholeuser) actual_rc = host.run(check_setup).rc assert exit_status_success == actual_rc # check dnsmasq files # readable /etc/dnsmasq.conf - check_dnsmasqconf = test_cmd.format( - 'r', '/etc/dnsmasq.conf', piholeuser) + check_dnsmasqconf = test_cmd.format("r", "/etc/dnsmasq.conf", piholeuser) actual_rc = host.run(check_dnsmasqconf).rc assert exit_status_success == actual_rc # readable /etc/dnsmasq.d/01-pihole.conf - check_dnsmasqconf = test_cmd.format( - 'r', '/etc/dnsmasq.d', piholeuser) + check_dnsmasqconf = test_cmd.format("r", "/etc/dnsmasq.d", piholeuser) actual_rc = host.run(check_dnsmasqconf).rc assert exit_status_success == actual_rc - check_dnsmasqconf = test_cmd.format( - 'x', '/etc/dnsmasq.d', piholeuser) + check_dnsmasqconf = test_cmd.format("x", "/etc/dnsmasq.d", piholeuser) actual_rc = host.run(check_dnsmasqconf).rc assert exit_status_success == actual_rc check_dnsmasqconf = test_cmd.format( - 'r', '/etc/dnsmasq.d/01-pihole.conf', piholeuser) + "r", "/etc/dnsmasq.d/01-pihole.conf", piholeuser + ) actual_rc = host.run(check_dnsmasqconf).rc assert exit_status_success == actual_rc # check readable and executable /etc/init.d/pihole-FTL - check_init = test_cmd.format( - 'x', '/etc/init.d/pihole-FTL', piholeuser) + check_init = test_cmd.format("x", "/etc/init.d/pihole-FTL", piholeuser) actual_rc = host.run(check_init).rc assert exit_status_success == actual_rc - check_init = test_cmd.format( - 'r', '/etc/init.d/pihole-FTL', piholeuser) + check_init = test_cmd.format("r", "/etc/init.d/pihole-FTL", piholeuser) actual_rc = host.run(check_init).rc assert exit_status_success == actual_rc # check readable /etc/lighttpd/lighttpd.conf - check_lighttpd = test_cmd.format( - 'r', '/etc/lighttpd/lighttpd.conf', piholeuser) + check_lighttpd = test_cmd.format("r", "/etc/lighttpd/lighttpd.conf", piholeuser) actual_rc = host.run(check_lighttpd).rc assert exit_status_success == actual_rc # check readable and executable manpages if maninstalled is True: - check_man = test_cmd.format( - 'x', '/usr/local/share/man', piholeuser) + check_man = test_cmd.format("x", "/usr/local/share/man", piholeuser) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc - check_man = test_cmd.format( - 'r', '/usr/local/share/man', piholeuser) + check_man = test_cmd.format("r", "/usr/local/share/man", piholeuser) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc - check_man = test_cmd.format( - 'x', '/usr/local/share/man/man8', piholeuser) + check_man = test_cmd.format("x", "/usr/local/share/man/man8", piholeuser) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc - check_man = test_cmd.format( - 'r', '/usr/local/share/man/man8', piholeuser) + check_man = test_cmd.format("r", "/usr/local/share/man/man8", piholeuser) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc - check_man = test_cmd.format( - 'x', '/usr/local/share/man/man5', piholeuser) + check_man = test_cmd.format("x", "/usr/local/share/man/man5", piholeuser) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc - check_man = test_cmd.format( - 'r', '/usr/local/share/man/man5', piholeuser) + check_man = test_cmd.format("r", "/usr/local/share/man/man5", piholeuser) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc check_man = test_cmd.format( - 'r', '/usr/local/share/man/man8/pihole.8', piholeuser) + "r", "/usr/local/share/man/man8/pihole.8", piholeuser + ) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc check_man = test_cmd.format( - 'r', '/usr/local/share/man/man8/pihole-FTL.8', piholeuser) + "r", "/usr/local/share/man/man8/pihole-FTL.8", piholeuser + ) actual_rc = host.run(check_man).rc assert exit_status_success == actual_rc # check not readable sudoers file - check_sudo = test_cmd.format( - 'r', '/etc/sudoers.d/pihole', piholeuser) + check_sudo = test_cmd.format("r", "/etc/sudoers.d/pihole", piholeuser) actual_rc = host.run(check_sudo).rc assert exit_status_success != actual_rc # check not readable cron file - check_sudo = test_cmd.format( - 'x', '/etc/cron.d/', piholeuser) + check_sudo = test_cmd.format("x", "/etc/cron.d/", piholeuser) actual_rc = host.run(check_sudo).rc assert exit_status_success == actual_rc - check_sudo = test_cmd.format( - 'r', '/etc/cron.d/', piholeuser) + check_sudo = test_cmd.format("r", "/etc/cron.d/", piholeuser) actual_rc = host.run(check_sudo).rc assert exit_status_success == actual_rc - check_sudo = test_cmd.format( - 'r', '/etc/cron.d/pihole', piholeuser) + check_sudo = test_cmd.format("r", "/etc/cron.d/pihole", piholeuser) actual_rc = host.run(check_sudo).rc assert exit_status_success == actual_rc - directories = get_directories_recursive(host, '/etc/.pihole/') + directories = get_directories_recursive(host, "/etc/.pihole/") for directory in directories: - check_pihole = test_cmd.format('r', directory, piholeuser) + check_pihole = test_cmd.format("r", directory, piholeuser) actual_rc = host.run(check_pihole).rc - check_pihole = test_cmd.format('x', directory, piholeuser) + check_pihole = test_cmd.format("x", directory, piholeuser) actual_rc = host.run(check_pihole).rc findfiles = 'find "{}" -maxdepth 1 -type f -exec echo {{}} \\;;' filelist = host.run(findfiles.format(directory)) files = list(filter(bool, filelist.stdout.splitlines())) for file in files: - check_pihole = test_cmd.format('r', file, piholeuser) + check_pihole = test_cmd.format("r", file, piholeuser) actual_rc = host.run(check_pihole).rc @pytest.mark.parametrize("test_webpage", [True]) def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): - ''' + """ confirms all web page assets from Core repo are readable by $LIGHTTPD_USER on a fresh build - ''' + """ piholeWebpage = [ "127.0.0.1", # "pi.hole" ] # dialog returns Cancel for user prompt - mock_command('dialog', {'*': ('', '0')}, host) + mock_command("dialog", {"*": ("", "0")}, host) # mock git pull - mock_command_passthrough('git', {'pull': ('', '0')}, host) + mock_command_passthrough("git", {"pull": ("", "0")}, host) # mock systemctl to start lighttpd and FTL - ligthttpdcommand = dedent(r'''\"\" + ligthttpdcommand = dedent( + r'''\"\" echo 'starting lighttpd with {}' if [ command -v "apt-get" >/dev/null 2>&1 ]; then LIGHTTPD_USER="www-data" @@ -418,63 +391,45 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): /usr/sbin/lighttpd -tt -f '{config}' /usr/sbin/lighttpd -f '{config}' echo \"\"'''.format( - '{}', - usergroup='${{LIGHTTPD_USER}}:${{LIGHTTPD_GROUP}}', - chmodarg='{{}}', - config='/etc/lighttpd/lighttpd.conf', - run='/var/run/lighttpd', - cache='/var/cache/lighttpd', - uploads='/var/cache/lighttpd/uploads', - compress='/var/cache/lighttpd/compress' + "{}", + usergroup="${{LIGHTTPD_USER}}:${{LIGHTTPD_GROUP}}", + chmodarg="{{}}", + config="/etc/lighttpd/lighttpd.conf", + run="/var/run/lighttpd", + cache="/var/cache/lighttpd", + uploads="/var/cache/lighttpd/uploads", + compress="/var/cache/lighttpd/compress", ) ) - FTLcommand = dedent('''\"\" + FTLcommand = dedent( + '''\"\" set -x /etc/init.d/pihole-FTL restart - echo \"\"''') + echo \"\"''' + ) mock_command_run( - 'systemctl', + "systemctl", { - 'enable lighttpd': ( - '', - '0' - ), - 'restart lighttpd': ( - ligthttpdcommand.format('restart'), - '0' - ), - 'start lighttpd': ( - ligthttpdcommand.format('start'), - '0' - ), - 'enable pihole-FTL': ( - '', - '0' - ), - 'restart pihole-FTL': ( - FTLcommand, - '0' - ), - 'start pihole-FTL': ( - FTLcommand, - '0' - ), - '*': ( - 'echo "systemctl call with $@"', - '0' - ), + "enable lighttpd": ("", "0"), + "restart lighttpd": (ligthttpdcommand.format("restart"), "0"), + "start lighttpd": (ligthttpdcommand.format("start"), "0"), + "enable pihole-FTL": ("", "0"), + "restart pihole-FTL": (FTLcommand, "0"), + "start pihole-FTL": (FTLcommand, "0"), + "*": ('echo "systemctl call with $@"', "0"), }, - host + host, ) # create configuration file - setup_var_file = 'cat < /etc/pihole/setupVars.conf\n' + setup_var_file = "cat < /etc/pihole/setupVars.conf\n" for k, v in SETUPVARS.items(): setup_var_file += "{}={}\n".format(k, v) setup_var_file += "INSTALL_WEB_SERVER=true\n" setup_var_file += "INSTALL_WEB_INTERFACE=true\n" setup_var_file += "EOF\n" host.run(setup_var_file) - installWeb = host.run(''' + installWeb = host.run( + """ export TERM=xterm export DEBIAN_FRONTEND=noninteractive umask 0027 @@ -488,33 +443,32 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): echo "webroot=${webroot}" echo "INSTALL_WEB_INTERFACE=${INSTALL_WEB_INTERFACE}" echo "INSTALL_WEB_SERVER=${INSTALL_WEB_SERVER}" - ''') + """ + ) assert 0 == installWeb.rc - piholeuser = 'pihole' - webuser = '' - user = re.findall( - r"^\s*LIGHTTPD_USER=.*$", installWeb.stdout, re.MULTILINE) + piholeuser = "pihole" + webuser = "" + user = re.findall(r"^\s*LIGHTTPD_USER=.*$", installWeb.stdout, re.MULTILINE) for match in user: - webuser = match.replace('LIGHTTPD_USER=', '').strip() - webroot = '' - user = re.findall( - r"^\s*webroot=.*$", installWeb.stdout, re.MULTILINE) + webuser = match.replace("LIGHTTPD_USER=", "").strip() + webroot = "" + user = re.findall(r"^\s*webroot=.*$", installWeb.stdout, re.MULTILINE) for match in user: - webroot = match.replace('webroot=', '').strip() + webroot = match.replace("webroot=", "").strip() if not webroot.strip(): - webroot = '/var/www/html' + webroot = "/var/www/html" installWebInterface = True interface = re.findall( - r"^\s*INSTALL_WEB_INTERFACE=.*$", installWeb.stdout, re.MULTILINE) + r"^\s*INSTALL_WEB_INTERFACE=.*$", installWeb.stdout, re.MULTILINE + ) for match in interface: - testvalue = match.replace('INSTALL_WEB_INTERFACE=', '').strip().lower() + testvalue = match.replace("INSTALL_WEB_INTERFACE=", "").strip().lower() if not testvalue.strip(): installWebInterface = testvalue == "true" installWebServer = True - server = re.findall( - r"^\s*INSTALL_WEB_SERVER=.*$", installWeb.stdout, re.MULTILINE) + server = re.findall(r"^\s*INSTALL_WEB_SERVER=.*$", installWeb.stdout, re.MULTILINE) for match in server: - testvalue = match.replace('INSTALL_WEB_SERVER=', '').strip().lower() + testvalue = match.replace("INSTALL_WEB_SERVER=", "").strip().lower() if not testvalue.strip(): installWebServer = testvalue == "true" # if webserver install was not requested @@ -525,87 +479,88 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): test_cmd = 'su --shell /bin/bash --command "test -{0} {1}" -p {2}' # check files that need a running FTL to be created # readable and writeable pihole-FTL.db - check_FTLconf = test_cmd.format( - 'r', '/etc/pihole/pihole-FTL.db', piholeuser) + check_FTLconf = test_cmd.format("r", "/etc/pihole/pihole-FTL.db", piholeuser) actual_rc = host.run(check_FTLconf).rc assert exit_status_success == actual_rc - check_FTLconf = test_cmd.format( - 'w', '/etc/pihole/pihole-FTL.db', piholeuser) + check_FTLconf = test_cmd.format("w", "/etc/pihole/pihole-FTL.db", piholeuser) actual_rc = host.run(check_FTLconf).rc assert exit_status_success == actual_rc # check directories above $webroot for read and execute permission - check_var = test_cmd.format('r', '/var', webuser) + check_var = test_cmd.format("r", "/var", webuser) actual_rc = host.run(check_var).rc assert exit_status_success == actual_rc - check_var = test_cmd.format('x', '/var', webuser) + check_var = test_cmd.format("x", "/var", webuser) actual_rc = host.run(check_var).rc assert exit_status_success == actual_rc - check_www = test_cmd.format('r', '/var/www', webuser) + check_www = test_cmd.format("r", "/var/www", webuser) actual_rc = host.run(check_www).rc assert exit_status_success == actual_rc - check_www = test_cmd.format('x', '/var/www', webuser) + check_www = test_cmd.format("x", "/var/www", webuser) actual_rc = host.run(check_www).rc assert exit_status_success == actual_rc - check_html = test_cmd.format('r', '/var/www/html', webuser) + check_html = test_cmd.format("r", "/var/www/html", webuser) actual_rc = host.run(check_html).rc assert exit_status_success == actual_rc - check_html = test_cmd.format('x', '/var/www/html', webuser) + check_html = test_cmd.format("x", "/var/www/html", webuser) actual_rc = host.run(check_html).rc assert exit_status_success == actual_rc # check directories below $webroot for read and execute permission - check_admin = test_cmd.format('r', webroot + '/admin', webuser) + check_admin = test_cmd.format("r", webroot + "/admin", webuser) actual_rc = host.run(check_admin).rc assert exit_status_success == actual_rc - check_admin = test_cmd.format('x', webroot + '/admin', webuser) + check_admin = test_cmd.format("x", webroot + "/admin", webuser) actual_rc = host.run(check_admin).rc assert exit_status_success == actual_rc - directories = get_directories_recursive(host, webroot + '/admin/*/') + directories = get_directories_recursive(host, webroot + "/admin/*/") for directory in directories: - check_pihole = test_cmd.format('r', directory, webuser) + check_pihole = test_cmd.format("r", directory, webuser) actual_rc = host.run(check_pihole).rc - check_pihole = test_cmd.format('x', directory, webuser) + check_pihole = test_cmd.format("x", directory, webuser) actual_rc = host.run(check_pihole).rc findfiles = 'find "{}" -maxdepth 1 -type f -exec echo {{}} \\;;' filelist = host.run(findfiles.format(directory)) files = list(filter(bool, filelist.stdout.splitlines())) for file in files: - check_pihole = test_cmd.format('r', file, webuser) + check_pihole = test_cmd.format("r", file, webuser) actual_rc = host.run(check_pihole).rc # check web interface files # change nameserver to pi-hole # setting nameserver in /etc/resolv.conf to pi-hole does # not work here because of the way docker uses this file - ns = host.run( - r"sed -i 's/nameserver.*/nameserver 127.0.0.1/' /etc/resolv.conf") + ns = host.run(r"sed -i 's/nameserver.*/nameserver 127.0.0.1/' /etc/resolv.conf") pihole_is_ns = ns.rc == 0 def is_ip(address): m = re.match(r"(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})", address) return bool(m) + if installWebInterface is True: - check_pihole = test_cmd.format('r', webroot + '/pihole', webuser) + check_pihole = test_cmd.format("r", webroot + "/pihole", webuser) actual_rc = host.run(check_pihole).rc assert exit_status_success == actual_rc - check_pihole = test_cmd.format('x', webroot + '/pihole', webuser) + check_pihole = test_cmd.format("x", webroot + "/pihole", webuser) actual_rc = host.run(check_pihole).rc assert exit_status_success == actual_rc # check most important files in $webroot for read permission - check_index = test_cmd.format( - 'r', webroot + '/pihole/index.php', webuser) + check_index = test_cmd.format("r", webroot + "/pihole/index.php", webuser) actual_rc = host.run(check_index).rc assert exit_status_success == actual_rc if test_webpage is True: # check webpage for unreadable files noPHPfopen = re.compile( - (r"PHP Error(%d+):\s+fopen([^)]+):\s+" + - r"failed to open stream: " + - r"Permission denied in"), - re.I) + ( + r"PHP Error(%d+):\s+fopen([^)]+):\s+" + + r"failed to open stream: " + + r"Permission denied in" + ), + re.I, + ) # using cURL option --dns-servers is not possible status = ( - 'curl -s --head "{}" | ' + - 'head -n 1 | ' + - 'grep "HTTP/1.[01] [23].." > /dev/null') + 'curl -s --head "{}" | ' + + "head -n 1 | " + + 'grep "HTTP/1.[01] [23].." > /dev/null' + ) digcommand = r"dig A +short {} @127.0.0.1 | head -n 1" pagecontent = 'curl --verbose -L "{}"' for page in piholeWebpage: @@ -625,258 +580,285 @@ def is_ip(address): def test_update_package_cache_success_no_errors(host): - ''' + """ confirms package cache was updated without any errors - ''' - updateCache = host.run(''' + """ + updateCache = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect update_package_cache - ''') - expected_stdout = tick_box + ' Update local cache of available packages' + """ + ) + expected_stdout = tick_box + " Update local cache of available packages" assert expected_stdout in updateCache.stdout - assert 'error' not in updateCache.stdout.lower() + assert "error" not in updateCache.stdout.lower() def test_update_package_cache_failure_no_errors(host): - ''' + """ confirms package cache was not updated - ''' - mock_command('apt-get', {'update': ('', '1')}, host) - updateCache = host.run(''' + """ + mock_command("apt-get", {"update": ("", "1")}, host) + updateCache = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect update_package_cache - ''') - expected_stdout = cross_box + ' Update local cache of available packages' + """ + ) + expected_stdout = cross_box + " Update local cache of available packages" assert expected_stdout in updateCache.stdout - assert 'Error: Unable to update package cache.' in updateCache.stdout + assert "Error: Unable to update package cache." in updateCache.stdout def test_FTL_detect_aarch64_no_errors(host): - ''' + """ confirms only aarch64 package is downloaded for FTL engine - ''' + """ # mock uname to return aarch64 platform - mock_command('uname', {'-m': ('aarch64', '0')}, host) + mock_command("uname", {"-m": ("aarch64", "0")}, host) # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) + mock_command("which", {"sh": ("/bin/sh", "0")}, host) # mock ldd to respond with aarch64 shared library - mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-aarch64.so.1', '0')}, host) - detectPlatform = host.run(''' + mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = info_box + ' FTL Checks...' + """ + ) + expected_stdout = info_box + " FTL Checks..." assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Detected AArch64 (64 Bit ARM) processor' + expected_stdout = tick_box + " Detected AArch64 (64 Bit ARM) processor" assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Downloading and Installing FTL' + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in detectPlatform.stdout def test_FTL_detect_armv4t_no_errors(host): - ''' + """ confirms only armv4t package is downloaded for FTL engine - ''' + """ # mock uname to return armv4t platform - mock_command('uname', {'-m': ('armv4t', '0')}, host) + mock_command("uname", {"-m": ("armv4t", "0")}, host) # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) + mock_command("which", {"sh": ("/bin/sh", "0")}, host) # mock ldd to respond with armv4t shared library - mock_command('ldd', {'/bin/sh': ('/lib/ld-linux.so.3', '0')}, host) - detectPlatform = host.run(''' + mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = info_box + ' FTL Checks...' + """ + ) + expected_stdout = info_box + " FTL Checks..." assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + (' Detected ARMv4 processor') + expected_stdout = tick_box + (" Detected ARMv4 processor") assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Downloading and Installing FTL' + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in detectPlatform.stdout def test_FTL_detect_armv5te_no_errors(host): - ''' + """ confirms only armv5te package is downloaded for FTL engine - ''' + """ # mock uname to return armv5te platform - mock_command('uname', {'-m': ('armv5te', '0')}, host) + mock_command("uname", {"-m": ("armv5te", "0")}, host) # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) + mock_command("which", {"sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux shared library - mock_command('ldd', {'/bin/sh': ('/lib/ld-linux.so.3', '0')}, host) - detectPlatform = host.run(''' + mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = info_box + ' FTL Checks...' + """ + ) + expected_stdout = info_box + " FTL Checks..." assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + (' Detected ARMv5 (or newer) processor') + expected_stdout = tick_box + (" Detected ARMv5 (or newer) processor") assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Downloading and Installing FTL' + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in detectPlatform.stdout def test_FTL_detect_armv6l_no_errors(host): - ''' + """ confirms only armv6l package is downloaded for FTL engine - ''' + """ # mock uname to return armv6l platform - mock_command('uname', {'-m': ('armv6l', '0')}, host) + mock_command("uname", {"-m": ("armv6l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) - mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-armhf.so.3', '0')}, host) - detectPlatform = host.run(''' + mock_command("which", {"sh": ("/bin/sh", "0")}, host) + mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = info_box + ' FTL Checks...' + """ + ) + expected_stdout = info_box + " FTL Checks..." assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + (' Detected ARMv6 processor ' - '(with hard-float support)') + expected_stdout = tick_box + ( + " Detected ARMv6 processor " "(with hard-float support)" + ) assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Downloading and Installing FTL' + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in detectPlatform.stdout def test_FTL_detect_armv7l_no_errors(host): - ''' + """ confirms only armv7l package is downloaded for FTL engine - ''' + """ # mock uname to return armv7l platform - mock_command('uname', {'-m': ('armv7l', '0')}, host) + mock_command("uname", {"-m": ("armv7l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) - mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-armhf.so.3', '0')}, host) - detectPlatform = host.run(''' + mock_command("which", {"sh": ("/bin/sh", "0")}, host) + mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = info_box + ' FTL Checks...' + """ + ) + expected_stdout = info_box + " FTL Checks..." assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + (' Detected ARMv7 processor ' - '(with hard-float support)') + expected_stdout = tick_box + ( + " Detected ARMv7 processor " "(with hard-float support)" + ) assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Downloading and Installing FTL' + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in detectPlatform.stdout def test_FTL_detect_armv8a_no_errors(host): - ''' + """ confirms only armv8a package is downloaded for FTL engine - ''' + """ # mock uname to return armv8a platform - mock_command('uname', {'-m': ('armv8a', '0')}, host) + mock_command("uname", {"-m": ("armv8a", "0")}, host) # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) + mock_command("which", {"sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - mock_command('ldd', {'/bin/sh': ('/lib/ld-linux-armhf.so.3', '0')}, host) - detectPlatform = host.run(''' + mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = info_box + ' FTL Checks...' + """ + ) + expected_stdout = info_box + " FTL Checks..." assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Detected ARMv8 (or newer) processor' + expected_stdout = tick_box + " Detected ARMv8 (or newer) processor" assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Downloading and Installing FTL' + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in detectPlatform.stdout def test_FTL_detect_x86_64_no_errors(host): - ''' + """ confirms only x86_64 package is downloaded for FTL engine - ''' + """ # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) - detectPlatform = host.run(''' + mock_command("which", {"sh": ("/bin/sh", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = info_box + ' FTL Checks...' + """ + ) + expected_stdout = info_box + " FTL Checks..." assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Detected x86_64 processor' + expected_stdout = tick_box + " Detected x86_64 processor" assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Downloading and Installing FTL' + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in detectPlatform.stdout def test_FTL_detect_unknown_no_errors(host): - ''' confirms only generic package is downloaded for FTL engine ''' + """confirms only generic package is downloaded for FTL engine""" # mock uname to return generic platform - mock_command('uname', {'-m': ('mips', '0')}, host) + mock_command("uname", {"-m": ("mips", "0")}, host) # mock `which sh` to return `/bin/sh` - mock_command('which', {'sh': ('/bin/sh', '0')}, host) - detectPlatform = host.run(''' + mock_command("which", {"sh": ("/bin/sh", "0")}, host) + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - expected_stdout = 'Not able to detect processor (unknown: mips)' + """ + ) + expected_stdout = "Not able to detect processor (unknown: mips)" assert expected_stdout in detectPlatform.stdout def test_FTL_download_aarch64_no_errors(host): - ''' + """ confirms only aarch64 package is downloaded for FTL engine - ''' + """ # mock dialog answers and ensure installer dependencies - mock_command('dialog', {'*': ('', '0')}, host) - host.run(''' + mock_command("dialog", {"*": ("", "0")}, host) + host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect install_dependent_packages ${INSTALLER_DEPS[@]} - ''') - download_binary = host.run(''' + """ + ) + download_binary = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user FTLinstall "pihole-FTL-aarch64-linux-gnu" - ''') - expected_stdout = tick_box + ' Downloading and Installing FTL' + """ + ) + expected_stdout = tick_box + " Downloading and Installing FTL" assert expected_stdout in download_binary.stdout - assert 'error' not in download_binary.stdout.lower() + assert "error" not in download_binary.stdout.lower() def test_FTL_binary_installed_and_responsive_no_errors(host): - ''' + """ confirms FTL binary is copied and functional in installed location - ''' - installed_binary = host.run(''' + """ + installed_binary = host.run( + """ source /opt/pihole/basic-install.sh create_pihole_user funcOutput=$(get_binary_name) @@ -884,176 +866,189 @@ def test_FTL_binary_installed_and_responsive_no_errors(host): binary="pihole-FTL${funcOutput##*pihole-FTL}" theRest="${funcOutput%pihole-FTL*}" FTLdetect "${binary}" "${theRest}" - ''') - version_check = host.run(''' + """ + ) + version_check = host.run( + """ VERSION=$(pihole-FTL version) echo ${VERSION:0:1} - ''') - expected_stdout = 'v' + """ + ) + expected_stdout = "v" assert expected_stdout in version_check.stdout def test_IPv6_only_link_local(host): - ''' + """ confirms IPv6 blocking is disabled for Link-local address - ''' + """ # mock ip -6 address to return Link-local address mock_command_2( - 'ip', - { - '-6 address': ( - 'inet6 fe80::d210:52fa:fe00:7ad7/64 scope link', - '0' - ) - }, - host + "ip", + {"-6 address": ("inet6 fe80::d210:52fa:fe00:7ad7/64 scope link", "0")}, + host, ) - detectPlatform = host.run(''' + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh find_IPv6_information - ''') - expected_stdout = ('Unable to find IPv6 ULA/GUA address') + """ + ) + expected_stdout = "Unable to find IPv6 ULA/GUA address" assert expected_stdout in detectPlatform.stdout def test_IPv6_only_ULA(host): - ''' + """ confirms IPv6 blocking is enabled for ULA addresses - ''' + """ # mock ip -6 address to return ULA address mock_command_2( - 'ip', + "ip", { - '-6 address': ( - 'inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global', - '0' + "-6 address": ( + "inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global", + "0", ) }, - host + host, ) - detectPlatform = host.run(''' + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh find_IPv6_information - ''') - expected_stdout = 'Found IPv6 ULA address' + """ + ) + expected_stdout = "Found IPv6 ULA address" assert expected_stdout in detectPlatform.stdout def test_IPv6_only_GUA(host): - ''' + """ confirms IPv6 blocking is enabled for GUA addresses - ''' + """ # mock ip -6 address to return GUA address mock_command_2( - 'ip', + "ip", { - '-6 address': ( - 'inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global', - '0' + "-6 address": ( + "inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global", + "0", ) }, - host + host, ) - detectPlatform = host.run(''' + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh find_IPv6_information - ''') - expected_stdout = 'Found IPv6 GUA address' + """ + ) + expected_stdout = "Found IPv6 GUA address" assert expected_stdout in detectPlatform.stdout def test_IPv6_GUA_ULA_test(host): - ''' + """ confirms IPv6 blocking is enabled for GUA and ULA addresses - ''' + """ # mock ip -6 address to return GUA and ULA addresses mock_command_2( - 'ip', + "ip", { - '-6 address': ( - 'inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global\n' - 'inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global', - '0' + "-6 address": ( + "inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global\n" + "inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global", + "0", ) }, - host + host, ) - detectPlatform = host.run(''' + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh find_IPv6_information - ''') - expected_stdout = 'Found IPv6 ULA address' + """ + ) + expected_stdout = "Found IPv6 ULA address" assert expected_stdout in detectPlatform.stdout def test_IPv6_ULA_GUA_test(host): - ''' + """ confirms IPv6 blocking is enabled for GUA and ULA addresses - ''' + """ # mock ip -6 address to return ULA and GUA addresses mock_command_2( - 'ip', + "ip", { - '-6 address': ( - 'inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global\n' - 'inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global', - '0' + "-6 address": ( + "inet6 fda2:2001:5555:0:d210:52fa:fe00:7ad7/64 scope global\n" + "inet6 2003:12:1e43:301:d210:52fa:fe00:7ad7/64 scope global", + "0", ) }, - host + host, ) - detectPlatform = host.run(''' + detectPlatform = host.run( + """ source /opt/pihole/basic-install.sh find_IPv6_information - ''') - expected_stdout = 'Found IPv6 ULA address' + """ + ) + expected_stdout = "Found IPv6 ULA address" assert expected_stdout in detectPlatform.stdout def test_validate_ip(host): - ''' + """ Tests valid_ip for various IP addresses - ''' + """ def test_address(addr, success=True): - output = host.run(''' + output = host.run( + """ source /opt/pihole/basic-install.sh valid_ip "{addr}" - '''.format(addr=addr)) + """.format( + addr=addr + ) + ) assert output.rc == 0 if success else 1 - test_address('192.168.1.1') - test_address('127.0.0.1') - test_address('255.255.255.255') - test_address('255.255.255.256', False) - test_address('255.255.256.255', False) - test_address('255.256.255.255', False) - test_address('256.255.255.255', False) - test_address('1092.168.1.1', False) - test_address('not an IP', False) - test_address('8.8.8.8#', False) - test_address('8.8.8.8#0') - test_address('8.8.8.8#1') - test_address('8.8.8.8#42') - test_address('8.8.8.8#888') - test_address('8.8.8.8#1337') - test_address('8.8.8.8#65535') - test_address('8.8.8.8#65536', False) - test_address('8.8.8.8#-1', False) - test_address('00.0.0.0', False) - test_address('010.0.0.0', False) - test_address('001.0.0.0', False) - test_address('0.0.0.0#00', False) - test_address('0.0.0.0#01', False) - test_address('0.0.0.0#001', False) - test_address('0.0.0.0#0001', False) - test_address('0.0.0.0#00001', False) + test_address("192.168.1.1") + test_address("127.0.0.1") + test_address("255.255.255.255") + test_address("255.255.255.256", False) + test_address("255.255.256.255", False) + test_address("255.256.255.255", False) + test_address("256.255.255.255", False) + test_address("1092.168.1.1", False) + test_address("not an IP", False) + test_address("8.8.8.8#", False) + test_address("8.8.8.8#0") + test_address("8.8.8.8#1") + test_address("8.8.8.8#42") + test_address("8.8.8.8#888") + test_address("8.8.8.8#1337") + test_address("8.8.8.8#65535") + test_address("8.8.8.8#65536", False) + test_address("8.8.8.8#-1", False) + test_address("00.0.0.0", False) + test_address("010.0.0.0", False) + test_address("001.0.0.0", False) + test_address("0.0.0.0#00", False) + test_address("0.0.0.0#01", False) + test_address("0.0.0.0#001", False) + test_address("0.0.0.0#0001", False) + test_address("0.0.0.0#00001", False) def test_os_check_fails(host): - ''' Confirms install fails on unsupported OS ''' - host.run(''' + """Confirms install fails on unsupported OS""" + host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect install_dependent_packages ${OS_CHECK_DEPS[@]} @@ -1062,65 +1057,78 @@ def test_os_check_fails(host): ID=UnsupportedOS VERSION_ID="2" EOT - ''') - detectOS = host.run('''t + """ + ) + detectOS = host.run( + """t source /opt/pihole/basic-install.sh os_check - ''') - expected_stdout = 'Unsupported OS detected: UnsupportedOS' + """ + ) + expected_stdout = "Unsupported OS detected: UnsupportedOS" assert expected_stdout in detectOS.stdout def test_os_check_passes(host): - ''' Confirms OS meets the requirements ''' - host.run(''' + """Confirms OS meets the requirements""" + host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect install_dependent_packages ${OS_CHECK_DEPS[@]} install_dependent_packages ${INSTALLER_DEPS[@]} - ''') - detectOS = host.run(''' + """ + ) + detectOS = host.run( + """ source /opt/pihole/basic-install.sh os_check - ''') - expected_stdout = 'Supported OS detected' + """ + ) + expected_stdout = "Supported OS detected" assert expected_stdout in detectOS.stdout def test_package_manager_has_installer_deps(host): - ''' Confirms OS is able to install the required packages for the installer''' - mock_command('dialog', {'*': ('', '0')}, host) - output = host.run(''' + """Confirms OS is able to install the required packages for the installer""" + mock_command("dialog", {"*": ("", "0")}, host) + output = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect install_dependent_packages ${INSTALLER_DEPS[@]} - ''') + """ + ) - assert 'No package' not in output.stdout + assert "No package" not in output.stdout assert output.rc == 0 def test_package_manager_has_pihole_deps(host): - ''' Confirms OS is able to install the required packages for Pi-hole ''' - mock_command('dialog', {'*': ('', '0')}, host) - output = host.run(''' + """Confirms OS is able to install the required packages for Pi-hole""" + mock_command("dialog", {"*": ("", "0")}, host) + output = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect install_dependent_packages ${PIHOLE_DEPS[@]} - ''') + """ + ) - assert 'No package' not in output.stdout + assert "No package" not in output.stdout assert output.rc == 0 def test_package_manager_has_web_deps(host): - ''' Confirms OS is able to install the required packages for web ''' - mock_command('dialog', {'*': ('', '0')}, host) - output = host.run(''' + """Confirms OS is able to install the required packages for web""" + mock_command("dialog", {"*": ("", "0")}, host) + output = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect install_dependent_packages ${PIHOLE_WEB_DEPS[@]} - ''') + """ + ) - assert 'No package' not in output.stdout + assert "No package" not in output.stdout assert output.rc == 0 diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 5126f2638f..a2604dc288 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -1,22 +1,27 @@ def test_key_val_replacement_works(host): - ''' Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file ''' - host.run(''' + """Confirms addOrEditKeyValPair either adds or replaces a key value pair in a given file""" + host.run( + """ source /opt/pihole/utils.sh addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1" addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2" addOrEditKeyValPair "./testoutput" "KEY_ONE" "value3" addOrEditKeyValPair "./testoutput" "KEY_FOUR" "value4" - ''') - output = host.run(''' + """ + ) + output = host.run( + """ cat ./testoutput - ''') - expected_stdout = 'KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n' + """ + ) + expected_stdout = "KEY_ONE=value3\nKEY_TWO=value2\nKEY_FOUR=value4\n" assert expected_stdout == output.stdout def test_key_addition_works(host): - ''' Confirms addKey adds a key (no value) to a file without duplicating it ''' - host.run(''' + """Confirms addKey adds a key (no value) to a file without duplicating it""" + host.run( + """ source /opt/pihole/utils.sh addKey "./testoutput" "KEY_ONE" addKey "./testoutput" "KEY_ONE" @@ -24,17 +29,21 @@ def test_key_addition_works(host): addKey "./testoutput" "KEY_TWO" addKey "./testoutput" "KEY_THREE" addKey "./testoutput" "KEY_THREE" - ''') - output = host.run(''' + """ + ) + output = host.run( + """ cat ./testoutput - ''') - expected_stdout = 'KEY_ONE\nKEY_TWO\nKEY_THREE\n' + """ + ) + expected_stdout = "KEY_ONE\nKEY_TWO\nKEY_THREE\n" assert expected_stdout == output.stdout def test_key_removal_works(host): - ''' Confirms removeKey removes a key or key/value pair ''' - host.run(''' + """Confirms removeKey removes a key or key/value pair""" + host.run( + """ source /opt/pihole/utils.sh addOrEditKeyValPair "./testoutput" "KEY_ONE" "value1" addOrEditKeyValPair "./testoutput" "KEY_TWO" "value2" @@ -42,81 +51,100 @@ def test_key_removal_works(host): addKey "./testoutput" "KEY_FOUR" removeKey "./testoutput" "KEY_TWO" removeKey "./testoutput" "KEY_FOUR" - ''') - output = host.run(''' + """ + ) + output = host.run( + """ cat ./testoutput - ''') - expected_stdout = 'KEY_ONE=value1\nKEY_THREE=value3\n' + """ + ) + expected_stdout = "KEY_ONE=value1\nKEY_THREE=value3\n" assert expected_stdout == output.stdout def test_getFTLAPIPortFile_default(host): - ''' Confirms getFTLAPIPortFile returns the default API port file path ''' - output = host.run(''' + """Confirms getFTLAPIPortFile returns the default API port file path""" + output = host.run( + """ source /opt/pihole/utils.sh getFTLAPIPortFile - ''') - expected_stdout = '/run/pihole-FTL.port\n' + """ + ) + expected_stdout = "/run/pihole-FTL.port\n" assert expected_stdout == output.stdout def test_getFTLAPIPort_default(host): - ''' Confirms getFTLAPIPort returns the default API port ''' - output = host.run(''' + """Confirms getFTLAPIPort returns the default API port""" + output = host.run( + """ source /opt/pihole/utils.sh getFTLAPIPort "/run/pihole-FTL.port" - ''') - expected_stdout = '4711\n' + """ + ) + expected_stdout = "4711\n" assert expected_stdout == output.stdout def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): - ''' Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location ''' - host.run(''' + """Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location""" + host.run( + """ tmpfile=$(mktemp) echo "PORTFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf echo "1234" > ${tmpfile} - ''') - output = host.run(''' + """ + ) + output = host.run( + """ source /opt/pihole/utils.sh FTL_API_PORT_FILE=$(getFTLAPIPortFile) getFTLAPIPort "${FTL_API_PORT_FILE}" - ''') - expected_stdout = '1234\n' + """ + ) + expected_stdout = "1234\n" assert expected_stdout == output.stdout def test_getFTLPIDFile_default(host): - ''' Confirms getFTLPIDFile returns the default PID file path ''' - output = host.run(''' + """Confirms getFTLPIDFile returns the default PID file path""" + output = host.run( + """ source /opt/pihole/utils.sh getFTLPIDFile - ''') - expected_stdout = '/run/pihole-FTL.pid\n' + """ + ) + expected_stdout = "/run/pihole-FTL.pid\n" assert expected_stdout == output.stdout def test_getFTLPID_default(host): - ''' Confirms getFTLPID returns the default value if FTL is not running ''' - output = host.run(''' + """Confirms getFTLPID returns the default value if FTL is not running""" + output = host.run( + """ source /opt/pihole/utils.sh getFTLPID - ''') - expected_stdout = '-1\n' + """ + ) + expected_stdout = "-1\n" assert expected_stdout == output.stdout def test_getFTLPIDFile_and_getFTLPID_custom(host): - ''' Confirms getFTLPIDFile returns a custom PID file path ''' - host.run(''' + """Confirms getFTLPIDFile returns a custom PID file path""" + host.run( + """ tmpfile=$(mktemp) echo "PIDFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf echo "1234" > ${tmpfile} - ''') - output = host.run(''' + """ + ) + output = host.run( + """ source /opt/pihole/utils.sh FTL_PID_FILE=$(getFTLPIDFile) getFTLPID "${FTL_PID_FILE}" - ''') - expected_stdout = '1234\n' + """ + ) + expected_stdout = "1234\n" assert expected_stdout == output.stdout diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index 3497267ada..871fee2983 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -8,17 +8,20 @@ def test_enable_epel_repository_centos(host): - ''' + """ confirms the EPEL package repository is enabled when installed on CentOS - ''' - package_manager_detect = host.run(''' + """ + package_manager_detect = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect - ''') - expected_stdout = info_box + (' Enabling EPEL package repository ' - '(https://fedoraproject.org/wiki/EPEL)') + """ + ) + expected_stdout = info_box + ( + " Enabling EPEL package repository " "(https://fedoraproject.org/wiki/EPEL)" + ) assert expected_stdout in package_manager_detect.stdout - expected_stdout = tick_box + ' Installed' + expected_stdout = tick_box + " Installed" assert expected_stdout in package_manager_detect.stdout - epel_package = host.package('epel-release') + epel_package = host.package("epel-release") assert epel_package.is_installed diff --git a/test/test_centos_fedora_common_support.py b/test/test_centos_fedora_common_support.py index df8067719b..7e0bae4e7b 100644 --- a/test/test_centos_fedora_common_support.py +++ b/test/test_centos_fedora_common_support.py @@ -6,60 +6,70 @@ def mock_selinux_config(state, host): - ''' + """ Creates a mock SELinux config file with expected content - ''' + """ # validate state string - valid_states = ['enforcing', 'permissive', 'disabled'] + valid_states = ["enforcing", "permissive", "disabled"] assert state in valid_states # getenforce returns the running state of SELinux - mock_command('getenforce', {'*': (state.capitalize(), '0')}, host) + mock_command("getenforce", {"*": (state.capitalize(), "0")}, host) # create mock configuration with desired content - host.run(''' + host.run( + """ mkdir /etc/selinux echo "SELINUX={state}" > /etc/selinux/config - '''.format(state=state.lower())) + """.format( + state=state.lower() + ) + ) def test_selinux_enforcing_exit(host): - ''' + """ confirms installer prompts to exit when SELinux is Enforcing by default - ''' + """ mock_selinux_config("enforcing", host) - check_selinux = host.run(''' + check_selinux = host.run( + """ source /opt/pihole/basic-install.sh checkSelinux - ''') - expected_stdout = cross_box + ' Current SELinux: enforcing' + """ + ) + expected_stdout = cross_box + " Current SELinux: enforcing" assert expected_stdout in check_selinux.stdout - expected_stdout = 'SELinux Enforcing detected, exiting installer' + expected_stdout = "SELinux Enforcing detected, exiting installer" assert expected_stdout in check_selinux.stdout assert check_selinux.rc == 1 def test_selinux_permissive(host): - ''' + """ confirms installer continues when SELinux is Permissive - ''' + """ mock_selinux_config("permissive", host) - check_selinux = host.run(''' + check_selinux = host.run( + """ source /opt/pihole/basic-install.sh checkSelinux - ''') - expected_stdout = tick_box + ' Current SELinux: permissive' + """ + ) + expected_stdout = tick_box + " Current SELinux: permissive" assert expected_stdout in check_selinux.stdout assert check_selinux.rc == 0 def test_selinux_disabled(host): - ''' + """ confirms installer continues when SELinux is Disabled - ''' + """ mock_selinux_config("disabled", host) - check_selinux = host.run(''' + check_selinux = host.run( + """ source /opt/pihole/basic-install.sh checkSelinux - ''') - expected_stdout = tick_box + ' Current SELinux: disabled' + """ + ) + expected_stdout = tick_box + " Current SELinux: disabled" assert expected_stdout in check_selinux.stdout assert check_selinux.rc == 0 diff --git a/test/test_fedora_support.py b/test/test_fedora_support.py index 57a6c5c433..e7d31a5dbf 100644 --- a/test/test_fedora_support.py +++ b/test/test_fedora_support.py @@ -1,13 +1,15 @@ def test_epel_and_remi_not_installed_fedora(host): - ''' + """ confirms installer does not attempt to install EPEL/REMI repositories on Fedora - ''' - package_manager_detect = host.run(''' + """ + package_manager_detect = host.run( + """ source /opt/pihole/basic-install.sh package_manager_detect - ''') - assert package_manager_detect.stdout == '' + """ + ) + assert package_manager_detect.stdout == "" - epel_package = host.package('epel-release') + epel_package = host.package("epel-release") assert not epel_package.is_installed From 17ec88d96f2eaddd4f1836d5e2aa660b70f38ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 19 Sep 2022 14:48:58 +0200 Subject: [PATCH 168/638] Remove `installed_binary` variable which was leftover from https://github.com/pi-hole/pi-hole/pull/4893 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_automated_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 895db6dcfe..f3432575aa 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -857,7 +857,7 @@ def test_FTL_binary_installed_and_responsive_no_errors(host): """ confirms FTL binary is copied and functional in installed location """ - installed_binary = host.run( + host.run( """ source /opt/pihole/basic-install.sh create_pihole_user From b6d1bd7335ac1655b22d528b6006cfecf5071b14 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 19 Sep 2022 22:01:05 +0100 Subject: [PATCH 169/638] Read docker tag from file in root, not the previously set environment variable Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index b1e111aef4..550a71428c 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -37,6 +37,8 @@ rm -f "/etc/pihole/localversions" VERSION_FILE="/etc/pihole/versions" touch "${VERSION_FILE}" chmod 644 "${VERSION_FILE}" +# if /pihole.docker.tag file exists, we will use it's value later in this script +DOCKER_TAG=$(cat file 2>/dev/null) if [[ "$2" == "remote" ]]; then @@ -55,7 +57,7 @@ if [[ "$2" == "remote" ]]; then GITHUB_FTL_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" - if [[ "${PIHOLE_DOCKER_TAG}" ]]; then + if [[ "${DOCKER_TAG}" ]]; then GITHUB_DOCKER_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi @@ -84,9 +86,8 @@ else FTL_VERSION="$(pihole-FTL version)" addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" - # PIHOLE_DOCKER_TAG is set as env variable only on docker installations - if [[ "${PIHOLE_DOCKER_TAG}" ]]; then - addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${PIHOLE_DOCKER_TAG}" + if [[ "${DOCKER_TAG}" ]]; then + addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" fi fi From d4ce5b1c2a53fd2dee7299281ef499c054575ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 22 Sep 2022 14:49:25 +0200 Subject: [PATCH 170/638] Fix tabs in dialog boxes 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 a51f5d9aa3..337a304297 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -999,10 +999,10 @@ If you want to specify a port other than 53, separate it with a hash.\ # and continue the loop. DNSSettingsCorrect=False else - dialog --no-shadow --keep-tite \ + dialog --no-shadow --no-collapse --keep-tite \ --backtitle "Specify Upstream DNS Provider(s)" \ --title "Upstream DNS Provider(s)" \ - --yesno "Are these settings correct?\\n\\tDNS Server 1:\\t${PIHOLE_DNS_1}\\n\\tDNS Server 2:\\t${PIHOLE_DNS_2}" \ + --yesno "Are these settings correct?\\n"$'\t'"DNS Server 1:"$'\t'"${PIHOLE_DNS_1}\\n"$'\t'"DNS Server 2:"$'\t'"${PIHOLE_DNS_2}" \ "${r}" "${c}" && result=0 || result=$? case ${result} in From bb57a9e6168b52b91e3ac04e59734aa270d81e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 22 Sep 2022 22:33:11 +0200 Subject: [PATCH 171/638] Handle more than one default gateway in debug script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ab16d7ff49..074b2d1fca 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -680,17 +680,18 @@ ping_gateway() { # Check if we are using IPv4 or IPv6 # Find the default gateway using IPv4 or IPv6 local gateway - gateway="$(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3)" + mapfile -t gateway < <(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3) - # If the gateway variable has a value (meaning a gateway was found), - if [[ -n "${gateway}" ]]; then - log_write "${INFO} Default IPv${protocol} gateway: ${gateway}" + # If the gateway array is not empty (meaning a gateway was found), + if [[ ${#gateway[@]} -ne 0 ]]; then + log_write "${INFO} Default IPv${protocol} gateway(s):" + for i in "${gateway[@]}"; do log_write " $i"; done # Let the user know we will ping the gateway for a response - log_write " * Pinging ${gateway}..." + log_write " * Pinging first gateway ${gateway[0]}..." # Try to quietly ping the gateway 3 times, with a timeout of 3 seconds, using numeric output only, # on the pihole interface, and tail the last three lines of the output # If pinging the gateway is not successful, - if ! ${cmd} -c 1 -W 2 -n "${gateway}" -I "${PIHOLE_INTERFACE}" >/dev/null; then + if ! ${cmd} -c 1 -W 2 -n "${gateway[0]}" -I "${PIHOLE_INTERFACE}" >/dev/null; then # let the user know log_write "${CROSS} ${COL_RED}Gateway did not respond.${COL_NC} ($FAQ_GATEWAY)\\n" # and return an error code From ba8a50c82927f080ce2dce0d27fab311ad48edae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 24 Sep 2022 10:08:26 +0000 Subject: [PATCH 172/638] Bump actions/stale from 5.2.0 to 6.0.0 Bumps [actions/stale](https://github.com/actions/stale) from 5.2.0 to 6.0.0. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v5.2.0...v6.0.0) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 6b70a153ef..7b82bdbd52 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v5.2.0 + - uses: actions/stale@v6.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 From 755ec8bf2f7a500e691dd1ce4281e55f396054fd Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 24 Sep 2022 16:08:45 +0100 Subject: [PATCH 173/638] $$ != $ Signed-off-by: Adam Warner --- 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 c0abae8b8c..f3df72e659 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1270,7 +1270,7 @@ version_check_dnsmasq() { addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "interface" "$PIHOLE_INTERFACE" if [[ "${PIHOLE_DNS_1}" != "" ]]; then # then add in the primary DNS server. - addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "server" "$$PIHOLE_DNS_1" + addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "server" "$PIHOLE_DNS_1" fi # Ditto if DNS2 is not empty if [[ "${PIHOLE_DNS_2}" != "" ]]; then @@ -1278,7 +1278,7 @@ version_check_dnsmasq() { fi # Set the cache size - addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "cache-size" "$$CACHE_SIZE" + addOrEditKeyValPair "${dnsmasq_pihole_01_target}" "cache-size" "$CACHE_SIZE" sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' "${dnsmasq_conf}" From 951b4ed0029f8001f1ee0d4969f99b9f5b7f4b10 Mon Sep 17 00:00:00 2001 From: Peter Russell Date: Sat, 24 Sep 2022 17:14:44 +0200 Subject: [PATCH 174/638] Remove cronjob that checks local versions every 10 minutes - only check when required (#4939) * eliminate updatechecker local from pihole cron job Signed-off-by: jpgpi250 * resolving stickler-ci items Signed-off-by: jpgpi250 * undo changes to updatecheck.sh (request from PromoFaux) Signed-off-by: jpgpi250 * applied recommendation from PromoFaux Signed-off-by: jpgpi250 * Indent the code inside the function Signed-off-by: jpgpi250 * removed unnecessary updatecheck for core Signed-off-by: jpgpi250 * eliminate updatechecker local from pihole cron job Co-authored-by: jpgpi250 Signed-off-by: Adam Warner Signed-off-by: jpgpi250 Signed-off-by: Adam Warner Co-authored-by: Adam Warner --- advanced/Scripts/piholeCheckout.sh | 9 +++++++++ advanced/Templates/pihole.cron | 3 --- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 7c4a1f77a8..8c4c6db323 100755 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -42,6 +42,11 @@ warning1() { esac } +updateCheckFunc() { + /opt/pihole/updatecheck.sh + /opt/pihole/updatecheck.sh x remote +} + checkout() { local corebranches local webbranches @@ -164,6 +169,8 @@ checkout() { exit 1 fi checkout_pull_branch "${webInterfaceDir}" "${2}" + # Force an update of the updatechecker + updateCheckFunc elif [[ "${1}" == "ftl" ]] ; then local path local oldbranch @@ -178,6 +185,8 @@ checkout() { FTLinstall "${binary}" restart_service pihole-FTL enable_service pihole-FTL + # Force an update of the updatechecker + updateCheckFunc else echo " ${CROSS} Requested branch \"${2}\" is not available" ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') ) diff --git a/advanced/Templates/pihole.cron b/advanced/Templates/pihole.cron index 46640fbb32..336a66feec 100644 --- a/advanced/Templates/pihole.cron +++ b/advanced/Templates/pihole.cron @@ -28,9 +28,6 @@ @reboot root /usr/sbin/logrotate --state /var/lib/logrotate/pihole /etc/pihole/logrotate -# Pi-hole: Grab local version and branch every 10 minutes -*/10 * * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker local - # Pi-hole: Grab remote version every 24 hours 59 17 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote @reboot root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote reboot From 9debd221796b5b130994b2d9a2775fa814df40be Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 25 Sep 2022 15:51:09 +0100 Subject: [PATCH 175/638] If, after reading /pihole.docker.tag into DOCKER_TAG, it does not match an expected pattern, unset it - this should prevent arbitary code from being run Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 550a71428c..a9d7523e81 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -37,8 +37,14 @@ rm -f "/etc/pihole/localversions" VERSION_FILE="/etc/pihole/versions" touch "${VERSION_FILE}" chmod 644 "${VERSION_FILE}" + # if /pihole.docker.tag file exists, we will use it's value later in this script -DOCKER_TAG=$(cat file 2>/dev/null) +DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null) +regex='^([0-9]+\.){1,2}(\*|[0-9]+)(-.*)?$|(^nightly$)|(^dev.*$)' +if [[ ! "${DOCKER_TAG}" =~ $regex ]]; then + # DOCKER_TAG does not match the pattern (see https://regex101.com/r/RsENuz/1), so unset it. + unset DOCKER_TAG +fi if [[ "$2" == "remote" ]]; then From bf5fffaca776ee35d4d0c6ee4197b4faa81a7f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 25 Sep 2022 18:03:44 +0200 Subject: [PATCH 176/638] Better wording and test with color MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 76 +++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c078353860..543ccb0aba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,33 +12,28 @@ jobs: if: github.event.pull_request.draft == false runs-on: ubuntu-latest steps: - - - name: Checkout repository - uses: actions/checkout@v3.0.2 - - - name: Check scripts in repository are executable - run: | - IFS=$'\n'; - for f in $(find . -name '*.sh'); do if [[ ! -x $f ]]; then echo "$f is not executable" && FAIL=1; fi ;done - unset IFS; - # If FAIL is 1 then we fail. - [[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!" - - - name: Spell-Checking - uses: codespell-project/actions-codespell@master - with: - ignore_words_file: .codespellignore - - - name: Get editorconfig-checker - uses: editorconfig-checker/action-editorconfig-checker@main # tag v1.0.0 is really out of date - - - name: Run editorconfig-checker - run: editorconfig-checker - - - name: Run black python code formatter - uses: psf/black@stable - with: - src: "./test" + - name: Checkout repository + uses: actions/checkout@v3.0.2 + - name: Check scripts in repository are executable + run: | + IFS=$'\n'; + for f in $(find . -name '*.sh'); do if [[ ! -x $f ]]; then echo "$f is not executable" && FAIL=1; fi ;done + unset IFS; + # If FAIL is 1 then we fail. + [[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!" + - name: Spell-Checking + uses: codespell-project/actions-codespell@master + with: + ignore_words_file: .codespellignore + - name: Get editorconfig-checker + uses: editorconfig-checker/action-editorconfig-checker@main # tag v1.0.0 is really out of date + - name: Run editorconfig-checker + run: editorconfig-checker + - name: Check python code formatting with black + uses: psf/black@stable + with: + src: "./test" + options: "--check --diff --color" distro-test: if: github.event.pull_request.draft == false @@ -47,21 +42,18 @@ jobs: strategy: fail-fast: false matrix: - distro: [debian_10, debian_11, ubuntu_20, ubuntu_22, centos_8, fedora_34] + distro: + [debian_10, debian_11, ubuntu_20, ubuntu_22, centos_8, fedora_34] env: DISTRO: ${{matrix.distro}} steps: - - - name: Checkout repository - uses: actions/checkout@v3.0.2 - - - name: Set up Python 3.10 - uses: actions/setup-python@v4.2.0 - with: - python-version: '3.10' - - - name: Install dependencies - run: pip install -r test/requirements.txt - - - name: Test with tox - run: tox -c test/tox.${DISTRO}.ini + - name: Checkout repository + uses: actions/checkout@v3.0.2 + - name: Set up Python 3.10 + uses: actions/setup-python@v4.2.0 + with: + python-version: "3.10" + - name: Install dependencies + run: pip install -r test/requirements.txt + - name: Test with tox + run: tox -c test/tox.${DISTRO}.ini From 22ebf2148762178351541fd22f3af99755fba291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 25 Sep 2022 17:49:24 +0200 Subject: [PATCH 177/638] Use POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 074b2d1fca..91e16850a2 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -678,20 +678,24 @@ ping_gateway() { local protocol="${1}" ping_ipv4_or_ipv6 "${protocol}" # Check if we are using IPv4 or IPv6 - # Find the default gateway using IPv4 or IPv6 + # Find the default gateways using IPv4 or IPv6 local gateway - mapfile -t gateway < <(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3) - # If the gateway array is not empty (meaning a gateway was found), - if [[ ${#gateway[@]} -ne 0 ]]; then - log_write "${INFO} Default IPv${protocol} gateway(s):" - for i in "${gateway[@]}"; do log_write " $i"; done + log_write "${INFO} Default IPv${protocol} gateway(s):" + + while IFS= read -r gateway; do + log_write " ${gateway}" + done < <(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3) + + gateway=$(ip -"${protocol}" route | grep default | grep "${PIHOLE_INTERFACE}" | cut -d ' ' -f 3 | head -n 1) + # If there was at least one gateway + if [ -n "${gateway}" ]; then # Let the user know we will ping the gateway for a response - log_write " * Pinging first gateway ${gateway[0]}..." + log_write " * Pinging first gateway ${gateway}..." # Try to quietly ping the gateway 3 times, with a timeout of 3 seconds, using numeric output only, # on the pihole interface, and tail the last three lines of the output # If pinging the gateway is not successful, - if ! ${cmd} -c 1 -W 2 -n "${gateway[0]}" -I "${PIHOLE_INTERFACE}" >/dev/null; then + if ! ${cmd} -c 1 -W 2 -n "${gateway}" -I "${PIHOLE_INTERFACE}" >/dev/null; then # let the user know log_write "${CROSS} ${COL_RED}Gateway did not respond.${COL_NC} ($FAQ_GATEWAY)\\n" # and return an error code From e1a2591c4d76c8f6817cd2924757dfe61895bbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 26 Sep 2022 10:40:39 +0200 Subject: [PATCH 178/638] Format test.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 543ccb0aba..442f1c0ded 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,7 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3.0.2 + - name: Check scripts in repository are executable run: | IFS=$'\n'; @@ -21,14 +22,18 @@ jobs: unset IFS; # If FAIL is 1 then we fail. [[ $FAIL == 1 ]] && exit 1 || echo "Scripts are executable!" + - name: Spell-Checking uses: codespell-project/actions-codespell@master with: ignore_words_file: .codespellignore + - name: Get editorconfig-checker uses: editorconfig-checker/action-editorconfig-checker@main # tag v1.0.0 is really out of date + - name: Run editorconfig-checker run: editorconfig-checker + - name: Check python code formatting with black uses: psf/black@stable with: @@ -49,11 +54,14 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3.0.2 + - name: Set up Python 3.10 uses: actions/setup-python@v4.2.0 with: python-version: "3.10" + - name: Install dependencies run: pip install -r test/requirements.txt + - name: Test with tox run: tox -c test/tox.${DISTRO}.ini From 3d01e4d0cfffbfe61c03d4591ac9020917e9cada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 21 Sep 2022 09:24:44 +0200 Subject: [PATCH 179/638] No detour - use pihole-FTL.conf to get the API port number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/utils.sh | 47 +++++++++------------------ advanced/Templates/pihole-FTL.service | 6 ++-- pihole | 5 ++- test/test_any_utils.py | 34 ++++++++++--------- 4 files changed, 38 insertions(+), 54 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index a9e05692e4..511dfc13ca 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -32,8 +32,8 @@ addOrEditKeyValPair() { local value="${3}" if grep -q "^${key}=" "${file}"; then - # Key already exists in file, modify the value - sed -i "/^${key}=/c\\${key}=${value}" "${file}" + # Key already exists in file, modify the value + sed -i "/^${key}=/c\\${key}=${value}" "${file}" else # Key does not already exist, add it and it's value echo "${key}=${value}" >> "${file}" @@ -52,8 +52,8 @@ addKey(){ local key="${2}" if ! grep -q "^${key}" "${file}"; then - # Key does not exist, add it. - echo "${key}" >> "${file}" + # Key does not exist, add it. + echo "${key}" >> "${file}" fi } @@ -70,47 +70,32 @@ removeKey() { sed -i "/^${key}/d" "${file}" } -####################### -# returns path of FTL's port file -####################### -getFTLAPIPortFile() { - local FTLCONFFILE="/etc/pihole/pihole-FTL.conf" - local DEFAULT_PORT_FILE="/run/pihole-FTL.port" - local FTL_APIPORT_FILE - - if [ -s "${FTLCONFFILE}" ]; then - # if PORTFILE is not set in pihole-FTL.conf, use the default path - FTL_APIPORT_FILE="$({ grep '^PORTFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PORT_FILE}"; } | cut -d'=' -f2-)" - else - # if there is no pihole-FTL.conf, use the default path - FTL_APIPORT_FILE="${DEFAULT_PORT_FILE}" - fi - - echo "${FTL_APIPORT_FILE}" -} - ####################### -# returns FTL's current telnet API port based on the content of the pihole-FTL.port file +# returns FTL's current telnet API port based on the setting in /etc/pihole-FTL.conf # # Takes one argument: path to pihole-FTL.port # Example getFTLAPIPort "/run/pihole-FTL.port" ####################### getFTLAPIPort(){ - local PORTFILE="${1}" + local FTLCONFFILE="/etc/pihole/pihole-FTL.conf" local DEFAULT_FTL_PORT=4711 local ftl_api_port - if [ -s "$PORTFILE" ]; then - # -s: FILE exists and has a size greater than zero - ftl_api_port=$(cat "${PORTFILE}") + if [ -s "$FTLCONFFILE" ]; then + # if FTLPORT is not set in pihole-FTL.conf, use the default port + ftl_api_port="$({ grep '^FTLPORT=' "${FTLCONFFILE}" || echo "${DEFAULT_FTL_PORT}"; } | cut -d'=' -f2-)" # Exploit prevention: unset the variable if there is malicious content # Verify that the value read from the file is numeric - expr "$ftl_api_port" : "[^[:digit:]]" > /dev/null && unset ftl_api_port + expr "${ftl_api_port}" : "[^[:digit:]]" > /dev/null && unset ftl_api_port + else + # if there is no pihole-FTL.conf, use the default port + ftl_api_port="${DEFAULT_FTL_PORT}" fi - # echo the port found in the portfile or default to the default port - echo "${ftl_api_port:=$DEFAULT_FTL_PORT}" + # If the ftl_api_port contained malicious stuff, substitute with -1 + ftl_api_port=${ftl_api_port:=-1} + echo "${ftl_api_port}" } ####################### diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 46e5c1f2dd..bc1b1d20e0 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -9,7 +9,7 @@ # Description: Enable service provided by pihole-FTL daemon ### END INIT INFO -#source utils.sh for getFTLPIDFile(), getFTLPID (), getFTLAPIPortFile() +#source utils.sh for getFTLPIDFile(), getFTLPID () PI_HOLE_SCRIPT_DIR="/opt/pihole" utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" . "${utilsfile}" @@ -31,7 +31,6 @@ start() { # Touch files to ensure they exist (create if non-existing, preserve if existing) mkdir -pm 0755 /run/pihole /var/log/pihole [ ! -f "${FTL_PID_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" - [ ! -f "${FTL_PORT_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PORT_FILE}" [ ! -f /var/log/pihole/FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log [ ! -f /var/log/pihole/pihole.log ] && install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases @@ -91,7 +90,7 @@ stop() { echo "Not running" fi # Cleanup - rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}" "${FTL_PORT_FILE}" + rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}" echo } @@ -111,7 +110,6 @@ status() { # Get file paths FTL_PID_FILE="$(getFTLPIDFile)" -FTL_PORT_FILE="$(getFTLAPIPortFile)" # Get FTL's current PID FTL_PID="$(getFTLPID ${FTL_PID_FILE})" diff --git a/pihole b/pihole index 1047d15207..aad8345186 100755 --- a/pihole +++ b/pihole @@ -303,14 +303,13 @@ analyze_ports() { statusFunc() { # Determine if there is pihole-FTL service is listening - local pid port ftl_api_port ftl_pid_file ftl_apiport_file + local pid port ftl_api_port ftl_pid_file ftl_pid_file="$(getFTLPIDFile)" pid="$(getFTLPID ${ftl_pid_file})" - ftl_apiport_file="${getFTLAPIPortFile}" - ftl_api_port="$(getFTLAPIPort ${ftl_apiport_file})" + ftl_api_port="$(getFTLAPIPort)" if [[ "$pid" -eq "-1" ]]; then case "${1}" in "web") echo "-1";; diff --git a/test/test_any_utils.py b/test/test_any_utils.py index a2604dc288..6a1146eefe 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -62,47 +62,49 @@ def test_key_removal_works(host): assert expected_stdout == output.stdout -def test_getFTLAPIPortFile_default(host): - """Confirms getFTLAPIPortFile returns the default API port file path""" +def test_getFTLAPIPort_default(host): + """Confirms getFTLAPIPort returns the default API port""" output = host.run( """ source /opt/pihole/utils.sh - getFTLAPIPortFile + getFTLAPIPort """ ) - expected_stdout = "/run/pihole-FTL.port\n" + expected_stdout = "4711\n" assert expected_stdout == output.stdout -def test_getFTLAPIPort_default(host): - """Confirms getFTLAPIPort returns the default API port""" +def test_getFTLAPIPort_custom(host): + """Confirms getFTLAPIPort returns a custom API port""" + host.run( + """ + echo "FTLPORT=1234" > /etc/pihole/pihole-FTL.conf + """ + ) output = host.run( """ source /opt/pihole/utils.sh - getFTLAPIPort "/run/pihole-FTL.port" + getFTLAPIPort """ ) - expected_stdout = "4711\n" + expected_stdout = "1234\n" assert expected_stdout == output.stdout -def test_getFTLAPIPortFile_and_getFTLAPIPort_custom(host): - """Confirms getFTLAPIPort returns a custom API port in a custom PORTFILE location""" +def test_getFTLAPIPort_malicious(host): + """Confirms getFTLAPIPort returns -1 if the setting in pihole-FTL.conf contains non-digits""" host.run( """ - tmpfile=$(mktemp) - echo "PORTFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf - echo "1234" > ${tmpfile} + echo "FTLPORT=*$ssdfsd" > /etc/pihole/pihole-FTL.conf """ ) output = host.run( """ source /opt/pihole/utils.sh - FTL_API_PORT_FILE=$(getFTLAPIPortFile) - getFTLAPIPort "${FTL_API_PORT_FILE}" + getFTLAPIPort """ ) - expected_stdout = "1234\n" + expected_stdout = "-1\n" assert expected_stdout == output.stdout From 25ba68104b1b9c6300d45920514a06c1cccdb516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 25 Sep 2022 18:16:20 +0200 Subject: [PATCH 180/638] Remove last traces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/chronometer.sh | 4 +++- advanced/Scripts/piholeDebug.sh | 2 -- advanced/Scripts/utils.sh | 5 +---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index af0079948d..d69a56d33c 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -14,7 +14,9 @@ LC_NUMERIC=C # Retrieve stats from FTL engine pihole-FTL() { local ftl_port LINE - ftl_port=$(cat /run/pihole-FTL.port 2> /dev/null) + # shellcheck disable=SC1091 + . /opt/pihole/utils.sh + ftl_port=$(getFTLAPIPort) if [[ -n "$ftl_port" ]]; then # Open connection to FTL exec 3<>"/dev/tcp/127.0.0.1/$ftl_port" diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 91e16850a2..dbf567094b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -126,7 +126,6 @@ PIHOLE_COMMAND="${BIN_DIRECTORY}/pihole" PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE" FTL_PID="${RUN_DIRECTORY}/pihole-FTL.pid" -FTL_PORT="${RUN_DIRECTORY}/pihole-FTL.port" PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log" PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*" @@ -155,7 +154,6 @@ REQUIRED_FILES=("${PIHOLE_CRON_FILE}" "${PIHOLE_COMMAND}" "${PIHOLE_COLTABLE_FILE}" "${FTL_PID}" -"${FTL_PORT}" "${PIHOLE_LOG}" "${PIHOLE_LOG_GZIPS}" "${PIHOLE_DEBUG_LOG}" diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 511dfc13ca..ef7ad219dc 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -73,10 +73,7 @@ removeKey() { ####################### # returns FTL's current telnet API port based on the setting in /etc/pihole-FTL.conf -# -# Takes one argument: path to pihole-FTL.port -# Example getFTLAPIPort "/run/pihole-FTL.port" -####################### +######################## getFTLAPIPort(){ local FTLCONFFILE="/etc/pihole/pihole-FTL.conf" local DEFAULT_FTL_PORT=4711 From 276c480f5001465d994dacf6e30d1e1c2d0a3b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 26 Sep 2022 23:40:09 +0200 Subject: [PATCH 181/638] Return default port if non-numeric characters are set in pihole-FTL.conf for FTLPORT. FTL does the same in such case and provide the API on 4711 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/utils.sh | 8 +++----- test/test_any_utils.py | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index ef7ad219dc..1174fa62e2 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -82,16 +82,14 @@ getFTLAPIPort(){ if [ -s "$FTLCONFFILE" ]; then # if FTLPORT is not set in pihole-FTL.conf, use the default port ftl_api_port="$({ grep '^FTLPORT=' "${FTLCONFFILE}" || echo "${DEFAULT_FTL_PORT}"; } | cut -d'=' -f2-)" - # Exploit prevention: unset the variable if there is malicious content - # Verify that the value read from the file is numeric - expr "${ftl_api_port}" : "[^[:digit:]]" > /dev/null && unset ftl_api_port + # Exploit prevention: set the port to the default port if there is malicious (non-numeric) + # content set in pihole-FTL.conf + expr "${ftl_api_port}" : "[^[:digit:]]" > /dev/null && ftl_api_port="${DEFAULT_FTL_PORT}" else # if there is no pihole-FTL.conf, use the default port ftl_api_port="${DEFAULT_FTL_PORT}" fi - # If the ftl_api_port contained malicious stuff, substitute with -1 - ftl_api_port=${ftl_api_port:=-1} echo "${ftl_api_port}" } diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 6a1146eefe..5b4075d9b9 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -92,7 +92,7 @@ def test_getFTLAPIPort_custom(host): def test_getFTLAPIPort_malicious(host): - """Confirms getFTLAPIPort returns -1 if the setting in pihole-FTL.conf contains non-digits""" + """Confirms getFTLAPIPort returns 4711 if the setting in pihole-FTL.conf contains non-digits""" host.run( """ echo "FTLPORT=*$ssdfsd" > /etc/pihole/pihole-FTL.conf @@ -104,7 +104,7 @@ def test_getFTLAPIPort_malicious(host): getFTLAPIPort """ ) - expected_stdout = "-1\n" + expected_stdout = "4711\n" assert expected_stdout == output.stdout From a705fbca7323ab7a134600aa662b187e23b25ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 29 Sep 2022 19:13:23 +0200 Subject: [PATCH 182/638] Add Fedora 35 and 36 to the test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 11 ++++++++++- test/_fedora_35.Dockerfile | 18 ++++++++++++++++++ test/_fedora_36.Dockerfile | 18 ++++++++++++++++++ test/tox.fedora_35.ini | 8 ++++++++ test/tox.fedora_36.ini | 8 ++++++++ 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 test/_fedora_35.Dockerfile create mode 100644 test/_fedora_36.Dockerfile create mode 100644 test/tox.fedora_35.ini create mode 100644 test/tox.fedora_36.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 442f1c0ded..1f83c1b81a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -48,7 +48,16 @@ jobs: fail-fast: false matrix: distro: - [debian_10, debian_11, ubuntu_20, ubuntu_22, centos_8, fedora_34] + [ + debian_10, + debian_11, + ubuntu_20, + ubuntu_22, + centos_8, + fedora_34, + fedora_35, + fedora_36, + ] env: DISTRO: ${{matrix.distro}} steps: diff --git a/test/_fedora_35.Dockerfile b/test/_fedora_35.Dockerfile new file mode 100644 index 0000000000..eb3623d5e2 --- /dev/null +++ b/test/_fedora_35.Dockerfile @@ -0,0 +1,18 @@ +FROM fedora:35 +RUN dnf install -y git + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/_fedora_36.Dockerfile b/test/_fedora_36.Dockerfile new file mode 100644 index 0000000000..e0504538ad --- /dev/null +++ b/test/_fedora_36.Dockerfile @@ -0,0 +1,18 @@ +FROM fedora:36 +RUN dnf install -y git + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.fedora_35.ini b/test/tox.fedora_35.ini new file mode 100644 index 0000000000..5e90426def --- /dev/null +++ b/test/tox.fedora_35.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _fedora_35.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.fedora_36.ini b/test/tox.fedora_36.ini new file mode 100644 index 0000000000..1d250f823c --- /dev/null +++ b/test/tox.fedora_36.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _fedora_36.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From d48c55713450739073cd19d738031ccd03bb7175 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 30 Sep 2022 17:13:08 -0300 Subject: [PATCH 183/638] Fix Deepsource warning message for index.php file Signed-off-by: RD WebDesign --- advanced/index.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index 9a2b19e606..f3f2ce1cac 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -29,7 +29,8 @@ if ($serverName === "pi.hole" || (!empty($_SERVER["VIRTUAL_HOST"]) && $serverName === $_SERVER["VIRTUAL_HOST"])) { // Redirect to Web Interface - exit(header("Location: /admin")); + header("Location: /admin"); + exit(); } elseif (filter_var($serverName, FILTER_VALIDATE_IP) || in_array($serverName, $authorizedHosts)) { // When directly browsing via IP or authorized hostname // Render splash/landing page based off presence of $landPage file @@ -75,6 +76,6 @@ exit($splashPage); } -exit(header("HTTP/1.1 404 Not Found")); - +header("HTTP/1.1 404 Not Found"); +exit(); ?> From 0749de3d1fad31b7c49e546bf338ea46fe29b9ae Mon Sep 17 00:00:00 2001 From: David Beitey Date: Fri, 30 Sep 2022 23:36:38 +0000 Subject: [PATCH 184/638] Update Amazon support URL to HTTPS in README Signed-off-by: David Beitey --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cf6d80c086..6badd277e8 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ If you'd rather not donate (_which is okay!_), there are other ways you can help - [Hetzner Cloud](https://hetzner.cloud/?ref=7aceisRX3AzA) _affiliate link_ - [Digital Ocean](https://www.digitalocean.com/?refcode=344d234950e1) _affiliate link_ - [Stickermule](https://www.stickermule.com/unlock?ref_id=9127301701&utm_medium=link&utm_source=invite) _earn a $10 credit after your first purchase_ -- [Amazon US](http://www.amazon.com/exec/obidos/redirect-home/pihole09-20) _affiliate link_ +- [Amazon US](https://www.amazon.com/exec/obidos/redirect-home/pihole09-20) _affiliate link_ - Spreading the word about our software and how you have benefited from it ### Contributing via GitHub From 6057b134ae34c44131cd4648b957819d85bb2da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 1 Oct 2022 10:03:13 +0200 Subject: [PATCH 185/638] Add initscripts to Fedora 35 and 36 dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/_fedora_35.Dockerfile | 2 +- test/_fedora_36.Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/_fedora_35.Dockerfile b/test/_fedora_35.Dockerfile index eb3623d5e2..83c1765052 100644 --- a/test/_fedora_35.Dockerfile +++ b/test/_fedora_35.Dockerfile @@ -1,5 +1,5 @@ FROM fedora:35 -RUN dnf install -y git +RUN dnf install -y git initscripts ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole diff --git a/test/_fedora_36.Dockerfile b/test/_fedora_36.Dockerfile index e0504538ad..847767e790 100644 --- a/test/_fedora_36.Dockerfile +++ b/test/_fedora_36.Dockerfile @@ -1,5 +1,5 @@ FROM fedora:36 -RUN dnf install -y git +RUN dnf install -y git initscripts ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From 3731b65bd59ce73115c8f55c548b01f3c0495af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 1 Oct 2022 10:04:26 +0200 Subject: [PATCH 186/638] Remoce Fedora 34 from tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 1 - test/_fedora_34.Dockerfile | 18 ------------------ test/tox.fedora_34.ini | 8 -------- 3 files changed, 27 deletions(-) delete mode 100644 test/_fedora_34.Dockerfile delete mode 100644 test/tox.fedora_34.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f83c1b81a..bb2d68d529 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,7 +54,6 @@ jobs: ubuntu_20, ubuntu_22, centos_8, - fedora_34, fedora_35, fedora_36, ] diff --git a/test/_fedora_34.Dockerfile b/test/_fedora_34.Dockerfile deleted file mode 100644 index 9c90ce7d7b..0000000000 --- a/test/_fedora_34.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM fedora:34 -RUN dnf install -y git - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.fedora_34.ini b/test/tox.fedora_34.ini deleted file mode 100644 index d58cb0d485..0000000000 --- a/test/tox.fedora_34.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py3 - -[testenv] -allowlist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _fedora_34.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From 34b66002e9c41caa70025ab12160733d5d4b8b78 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 1 Oct 2022 17:11:54 +0100 Subject: [PATCH 187/638] `leasetime` (local) should have an `h` after it to signify 24h lease, else it will be read as two minutes (minimum integer value) Signed-off-by: Adam Warner --- 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 3ee48aef2d..020d5f84b0 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -393,13 +393,13 @@ ProcessDHCPSettings() { if [[ "${DHCP_LEASETIME}" == "0" ]]; then leasetime="infinite" elif [[ "${DHCP_LEASETIME}" == "" ]]; then - leasetime="24" - addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "${leasetime}" + leasetime="24h" + addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "24" elif [[ "${DHCP_LEASETIME}" == "24h" ]]; then #Installation is affected by known bug, introduced in a previous version. #This will automatically clean up setupVars.conf and remove the unnecessary "h" - leasetime="24" - addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "${leasetime}" + leasetime="24h" + addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "24" else leasetime="${DHCP_LEASETIME}h" fi From b7b5ffa8dd9d1c2f8a99271394f9ad4722b66345 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 1 Oct 2022 20:05:22 +0100 Subject: [PATCH 188/638] remove old code per review from @yubiuser and @dschaper Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 020d5f84b0..e02e03f940 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -395,11 +395,6 @@ ProcessDHCPSettings() { elif [[ "${DHCP_LEASETIME}" == "" ]]; then leasetime="24h" addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "24" - elif [[ "${DHCP_LEASETIME}" == "24h" ]]; then - #Installation is affected by known bug, introduced in a previous version. - #This will automatically clean up setupVars.conf and remove the unnecessary "h" - leasetime="24h" - addOrEditKeyValPair "${setupVars}" "DHCP_LEASETIME" "24" else leasetime="${DHCP_LEASETIME}h" fi From 56527e5dd94d3878bf0b467abef7c4bbe9c5491d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 5 Oct 2022 23:13:25 +0200 Subject: [PATCH 189/638] Add get_remote_version() to updatechecker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index a9d7523e81..32e41880f5 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -20,6 +20,10 @@ function get_local_version() { git describe --long --dirty --tags 2> /dev/null || return 1 } +function get_remote_version() { + curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 +} + # Source the setupvars config file # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf @@ -52,19 +56,19 @@ if [[ "$2" == "remote" ]]; then sleep 30 fi - GITHUB_CORE_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - GITHUB_WEB_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" fi - GITHUB_FTL_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_FTL_VERSION="$(get_remote_version FTL)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" if [[ "${DOCKER_TAG}" ]]; then - GITHUB_DOCKER_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi From 18d28533eb30b15e0a1b8a99af2cdc8fc13567a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 12:36:17 +0200 Subject: [PATCH 190/638] Update local and remote versions at the same time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeCheckout.sh | 13 ++---- advanced/Scripts/update.sh | 3 +- advanced/Scripts/updatecheck.sh | 75 +++++++++++++++--------------- advanced/Templates/pihole.cron | 6 +-- automated install/basic-install.sh | 3 +- 5 files changed, 47 insertions(+), 53 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 8c4c6db323..cf57800c4c 100755 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -42,11 +42,6 @@ warning1() { esac } -updateCheckFunc() { - /opt/pihole/updatecheck.sh - /opt/pihole/updatecheck.sh x remote -} - checkout() { local corebranches local webbranches @@ -169,8 +164,8 @@ checkout() { exit 1 fi checkout_pull_branch "${webInterfaceDir}" "${2}" - # Force an update of the updatechecker - updateCheckFunc + # Update local and remote versions via updatechecker + /opt/pihole/updatecheck.sh elif [[ "${1}" == "ftl" ]] ; then local path local oldbranch @@ -185,8 +180,8 @@ checkout() { FTLinstall "${binary}" restart_service pihole-FTL enable_service pihole-FTL - # Force an update of the updatechecker - updateCheckFunc + # Update local and remote versions via updatechecker + /opt/pihole/updatecheck.sh else echo " ${CROSS} Requested branch \"${2}\" is not available" ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') ) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 609a054b56..c41c923230 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -216,9 +216,8 @@ main() { fi if [[ "${FTL_update}" == true || "${core_update}" == true || "${web_update}" == true ]]; then - # Force an update of the updatechecker + # Update local and remote versions via updatechecker /opt/pihole/updatecheck.sh - /opt/pihole/updatecheck.sh x remote echo -e " ${INFO} Local version file information updated." fi diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 32e41880f5..64f1e7ef15 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -28,7 +28,7 @@ function get_remote_version() { # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf -# Source the utils file +# Source the utils file for addOrEditKeyValPair() # shellcheck disable=SC1091 . /opt/pihole/utils.sh @@ -50,54 +50,55 @@ if [[ ! "${DOCKER_TAG}" =~ $regex ]]; then unset DOCKER_TAG fi -if [[ "$2" == "remote" ]]; then - - if [[ "$3" == "reboot" ]]; then +# used in cronjob +if [[ "$1" == "reboot" ]]; then sleep 30 - fi +fi + + +# get local versions - GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" +CORE_BRANCH="$(get_local_branch /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" - fi +if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + WEB_BRANCH="$(get_local_branch /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" +fi - GITHUB_FTL_VERSION="$(get_remote_version FTL)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" +FTL_BRANCH="$(pihole-FTL branch)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" - if [[ "${DOCKER_TAG}" ]]; then - GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" - fi +CORE_VERSION="$(get_local_version /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" -else +if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + WEB_VERSION="$(get_local_version /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" +fi - CORE_BRANCH="$(get_local_branch /etc/.pihole)" - addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" +FTL_VERSION="$(pihole-FTL version)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - WEB_BRANCH="$(get_local_branch /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" - fi +if [[ "${DOCKER_TAG}" ]]; then + addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" +fi - FTL_BRANCH="$(pihole-FTL branch)" - addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" - CORE_VERSION="$(get_local_version /etc/.pihole)" - addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" +# get remote versions - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - WEB_VERSION="$(get_local_version /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" - fi +GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" - FTL_VERSION="$(pihole-FTL version)" - addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" +if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" +fi - if [[ "${DOCKER_TAG}" ]]; then - addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" - fi +GITHUB_FTL_VERSION="$(get_remote_version FTL)" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" +if [[ "${DOCKER_TAG}" ]]; then + GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi diff --git a/advanced/Templates/pihole.cron b/advanced/Templates/pihole.cron index 336a66feec..c62d31ab3b 100644 --- a/advanced/Templates/pihole.cron +++ b/advanced/Templates/pihole.cron @@ -28,6 +28,6 @@ @reboot root /usr/sbin/logrotate --state /var/lib/logrotate/pihole /etc/pihole/logrotate -# Pi-hole: Grab remote version every 24 hours -59 17 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote -@reboot root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote reboot +# Pi-hole: Grab remote and local version every 24 hours +59 17 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker +@reboot root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker reboot diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f3df72e659..f128a7c997 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2694,9 +2694,8 @@ main() { # Download and compile the aggregated block list runGravity - # Force an update of the updatechecker + # Update local and remote versions via updatechecker /opt/pihole/updatecheck.sh - /opt/pihole/updatecheck.sh x remote if [[ "${useUpdateVars}" == false ]]; then displayFinalMessage "${pw}" From 888e44e53d81f505f958322f411cfcc96269f4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 14:17:28 +0200 Subject: [PATCH 191/638] Add hash functions to updatecheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 64f1e7ef15..85bba45d1e 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -15,15 +15,25 @@ function get_local_branch() { } function get_local_version() { - # Return active branch + # Return active version cd "${1}" 2> /dev/null || return 1 git describe --long --dirty --tags 2> /dev/null || return 1 } +function get_local_hash() { + cd "${1}" 2> /dev/null || return 1 + git rev-parse --short HEAD || return 1 +} + function get_remote_version() { curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 } + +function get_remote_hash(){ + git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,9);}' || return 1 +} + # Source the setupvars config file # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf @@ -61,14 +71,23 @@ fi CORE_BRANCH="$(get_local_branch /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" +CORE_HASH="$(get_local_hash /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_HASH" "${CORE_HASH}" + if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then WEB_BRANCH="$(get_local_branch /var/www/html/admin)" addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" + + WEB_HASH="$(get_local_hash /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" fi FTL_BRANCH="$(pihole-FTL branch)" addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" +FTL_HASH="$(pihole-FTL -v | cut -d "-" -f2)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}" + CORE_VERSION="$(get_local_version /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" @@ -90,14 +109,23 @@ fi GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" +GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}" + if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" + + GITHUB_WEB_HASH="$(get_remote_hash AdminLTE "${WEB_BRANCH}")" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}" fi GITHUB_FTL_VERSION="$(get_remote_version FTL)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" +GITHUB_FTL_HASH="$(get_remote_hash FTL "${FTL_BRANCH}")" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_HASH" "${GITHUB_FTL_HASH}" + if [[ "${DOCKER_TAG}" ]]; then GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" From d7f7ef99652c5b91a3b6fc3c9134d6c4e9fe55bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 14:37:56 +0200 Subject: [PATCH 192/638] Only create VERSION_FILE if it does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 85bba45d1e..7241cddb35 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -49,8 +49,10 @@ rm -f "/etc/pihole/localversions" # Create new versions file if it does not exist VERSION_FILE="/etc/pihole/versions" -touch "${VERSION_FILE}" -chmod 644 "${VERSION_FILE}" +if [ ! -f ${VERSION_FILE} ]; then + touch "${VERSION_FILE}" + chmod 644 "${VERSION_FILE}" +fi # if /pihole.docker.tag file exists, we will use it's value later in this script DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null) From 2dc599f266d06ac2ec11af77c307da1504041078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 17:58:58 +0200 Subject: [PATCH 193/638] Simplify version.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 175 ++++++++++-------------------------- 1 file changed, 47 insertions(+), 128 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 7f44d35ea5..72bfd6322c 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -8,140 +8,63 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -# Variables -DEFAULT="-1" -COREGITDIR="/etc/.pihole/" -WEBGITDIR="/var/www/html/admin/" - # Source the setupvars config file # shellcheck disable=SC1091 source /etc/pihole/setupVars.conf -getLocalVersion() { - # FTL requires a different method - if [[ "$1" == "FTL" ]]; then - pihole-FTL version - return 0 - fi +# Sourece the versions file poupulated by updatechecker.sh +cachedVersions="/etc/pihole/versions" - # Get the tagged version of the local repository - local directory="${1}" - local version +if [ -f ${cachedVersions} ]; then + # shellcheck disable=SC1090 + . "$cachedVersions" +else + echo "Could not find /etc/pihole/versons. Exiting." + exit 1 +fi - cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } - version=$(git describe --tags --always || echo "$DEFAULT") - if [[ "${version}" =~ ^v ]]; then - echo "${version}" - elif [[ "${version}" == "${DEFAULT}" ]]; then - echo "ERROR" - return 1 - else - echo "Untagged" - fi +getLocalVersion() { + case ${1} in + "pi-hole" ) echo "${CORE_VERSION}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_VERSION}";; + "FTL" ) echo "${FTL_VERSION}";; + esac return 0 } getLocalHash() { - # Local FTL hash does not exist on filesystem - if [[ "$1" == "FTL" ]]; then - echo "N/A" - return 0 - fi - - # Get the short hash of the local repository - local directory="${1}" - local hash - - cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } - hash=$(git rev-parse --short HEAD || echo "$DEFAULT") - if [[ "${hash}" == "${DEFAULT}" ]]; then - echo "ERROR" - return 1 - else - echo "${hash}" - fi + case ${1} in + "pi-hole" ) echo "${CORE_HASH}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_HASH}";; + "FTL" ) echo "${FTL_HASH}";; + esac return 0 } getRemoteHash(){ - # Remote FTL hash is not applicable - if [[ "$1" == "FTL" ]]; then - echo "N/A" - return 0 - fi - - local daemon="${1}" - local branch="${2}" - - hash=$(git ls-remote --heads "https://github.com/pi-hole/${daemon}" | \ - awk -v bra="$branch" '$0~bra {print substr($0,0,8);exit}') - if [[ -n "$hash" ]]; then - echo "$hash" - else - echo "ERROR" - return 1 - fi + case ${1} in + "pi-hole" ) echo "${GITHUB_CORE_HASH}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_HASH}";; + "FTL" ) echo "${GITHUB_FTL_HASH}";; + esac return 0 } getRemoteVersion(){ - # Get the version from the remote origin - local daemon="${1}" - local version - local cachedVersions - cachedVersions="/etc/pihole/versions" - - #If the above file exists, then we can read from that. Prevents overuse of GitHub API - if [[ -f "$cachedVersions" ]]; then - - # shellcheck disable=SC1090 - . "$cachedVersions" - - case $daemon in - "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";; - "FTL" ) echo "${GITHUB_FTL_VERSION}";; - esac - - return 0 - fi - - version=$(curl --silent --fail "https://api.github.com/repos/pi-hole/${daemon}/releases/latest" | \ - awk -F: '$1 ~/tag_name/ { print $2 }' | \ - tr -cd '[[:alnum:]]._-') - if [[ "${version}" =~ ^v ]]; then - echo "${version}" - else - echo "ERROR" - return 1 - fi + case ${1} in + "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";; + "FTL" ) echo "${GITHUB_FTL_VERSION}";; + esac return 0 } getLocalBranch(){ - # Get the checked out branch of the local directory - local directory="${1}" - local branch - - # Local FTL btranch is stored in /etc/pihole/ftlbranch - if [[ "$1" == "FTL" ]]; then - branch="$(pihole-FTL branch)" - else - cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } - branch=$(git rev-parse --abbrev-ref HEAD || echo "$DEFAULT") - fi - if [[ ! "${branch}" =~ ^v ]]; then - if [[ "${branch}" == "master" ]]; then - echo "" - elif [[ "${branch}" == "HEAD" ]]; then - echo "in detached HEAD state at " - else - echo "${branch} " - fi - else - # Branch started in "v" - echo "release " - fi + case ${1} in + "pi-hole" ) echo "${CORE_BRANCH}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_BRANCH}";; + "FTL" ) echo "${FTL_BRANCH}";; + esac return 0 } @@ -151,30 +74,26 @@ versionOutput() { return 1 fi - [[ "$1" == "pi-hole" ]] && GITDIR=$COREGITDIR - [[ "$1" == "AdminLTE" ]] && GITDIR=$WEBGITDIR - [[ "$1" == "FTL" ]] && GITDIR="FTL" - - [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR) && branch=$(getLocalBranch $GITDIR) - [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "$1") + [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}") + [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "${1}") if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then - [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "$GITDIR") && branch=$(getLocalBranch $GITDIR) - [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "$1" "$(cd "$GITDIR" 2> /dev/null && git rev-parse --abbrev-ref HEAD)") + [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") + [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "${1}") fi if [[ -n "$current" ]] && [[ -n "$latest" ]]; then - output="${1^} version is $branch$current (Latest: $latest)" + output="${1^} version is $branch $current (Latest: $latest)" elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then - output="Current ${1^} version is $branch$current" + output="Current ${1^} version is $branch $current (Latest: N/A)" elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then - output="Latest ${1^} version is $latest" - elif [[ "$curHash" == "N/A" ]] || [[ "$latHash" == "N/A" ]]; then - output="${1^} hash is not applicable" + output="Latest ${1^} version is $latest (Current: N/A)" + elif [[ -z "$curHash" ]] && [[ -z "$latHash" ]]; then + output="No hash info available" elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then - output="${1^} hash is $curHash (Latest: $latHash)" + output="Local ${1^} hash of branch $branch is $curHash (Remote: $latHash)" elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then - output="Current ${1^} hash is $curHash" + output="Current local ${1^} hash of branch $branch is $curHash (Remote: N/A)" elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then - output="Latest ${1^} hash is $latHash" + output="Latest remote ${1^} hash of branch $branch is $latHash (Local: N/A)" else errorOutput return 1 From a478f2460b33d3298d0ee1d9f5bf564c0fc68e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 21:50:07 +0200 Subject: [PATCH 194/638] POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 79 +++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 72bfd6322c..e91a66e531 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Pi-hole: A black hole for Internet advertisements # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. @@ -10,7 +10,7 @@ # Source the setupvars config file # shellcheck disable=SC1091 -source /etc/pihole/setupVars.conf +. /etc/pihole/setupVars.conf # Sourece the versions file poupulated by updatechecker.sh cachedVersions="/etc/pihole/versions" @@ -25,81 +25,76 @@ fi getLocalVersion() { case ${1} in - "pi-hole" ) echo "${CORE_VERSION}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_VERSION}";; + "Pi-hole" ) echo "${CORE_VERSION}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION}";; "FTL" ) echo "${FTL_VERSION}";; esac - return 0 } getLocalHash() { case ${1} in - "pi-hole" ) echo "${CORE_HASH}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_HASH}";; + "Pi-hole" ) echo "${CORE_HASH}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH}";; "FTL" ) echo "${FTL_HASH}";; esac - return 0 } getRemoteHash(){ case ${1} in - "pi-hole" ) echo "${GITHUB_CORE_HASH}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_HASH}";; + "Pi-hole" ) echo "${GITHUB_CORE_HASH}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH}";; "FTL" ) echo "${GITHUB_FTL_HASH}";; esac - return 0 } getRemoteVersion(){ case ${1} in - "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";; + "Pi-hole" ) echo "${GITHUB_CORE_VERSION}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION}";; "FTL" ) echo "${GITHUB_FTL_VERSION}";; esac - return 0 } getLocalBranch(){ case ${1} in - "pi-hole" ) echo "${CORE_BRANCH}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_BRANCH}";; + "Pi-hole" ) echo "${CORE_BRANCH}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH}";; "FTL" ) echo "${FTL_BRANCH}";; esac - return 0 } versionOutput() { - if [[ "$1" == "AdminLTE" && "${INSTALL_WEB_INTERFACE}" != true ]]; then + if [ "$1" = "AdminLTE" ] && [ "${INSTALL_WEB_INTERFACE}" != true ]; then echo " WebAdmin not installed" return 1 fi - [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}") - [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "${1}") - if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then - [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") - [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "${1}") + [ "$2" = "-c" ] || [ "$2" = "--current" ] || [ -z "$2" ] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}") + [ "$2" = "-l" ] || [ "$2" = "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "${1}") + if [ "$2" = "--hash" ]; then + [ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") + [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") fi - if [[ -n "$current" ]] && [[ -n "$latest" ]]; then - output="${1^} version is $branch $current (Latest: $latest)" - elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then - output="Current ${1^} version is $branch $current (Latest: N/A)" - elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then - output="Latest ${1^} version is $latest (Current: N/A)" - elif [[ -z "$curHash" ]] && [[ -z "$latHash" ]]; then - output="No hash info available" - elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then - output="Local ${1^} hash of branch $branch is $curHash (Remote: $latHash)" - elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then - output="Current local ${1^} hash of branch $branch is $curHash (Remote: N/A)" - elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then - output="Latest remote ${1^} hash of branch $branch is $latHash (Local: N/A)" + if [ -n "$current" ] && [ -n "$latest" ]; then + output="${1} version is $branch $current (Latest: $latest)" + elif [ -n "$current" ] && [ -z "$latest" ]; then + output="Current ${1} version is $branch $current" + elif [ -z "$current" ] && [ -n "$latest" ]; then + output="Latest ${1} version is $latest" + elif [ -n "$curHash" ] && [ -n "$latHash" ]; then + output="Local ${1} hash of branch $branch is $curHash (Remote: $latHash)" + elif [ -n "$curHash" ] && [ -z "$latHash" ]; then + output="Current local ${1} hash of branch $branch is $curHash" + elif [ -z "$curHash" ] && [ -n "$latHash" ]; then + output="Latest remote ${1} hash of branch $branch is $latHash" + elif [ -z "$curHash" ] && [ -z "$latHash" ]; then + output="Hashes for ${1} not available" else errorOutput return 1 fi - [[ -n "$output" ]] && echo " $output" + [ -n "$output" ] && echo " $output" } errorOutput() { @@ -108,9 +103,9 @@ errorOutput() { } defaultOutput() { - versionOutput "pi-hole" "$@" + versionOutput "Pi-hole" "$@" - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + if [ "${INSTALL_WEB_INTERFACE}" = true ]; then versionOutput "AdminLTE" "$@" fi @@ -118,7 +113,7 @@ defaultOutput() { } helpFunc() { - echo "Usage: pihole -v [repo | option] [option] + echo "Usage: piho && lle -v [repo | option] [option] Example: 'pihole -v -p -l' Show Pi-hole, Admin Console & FTL versions @@ -136,7 +131,7 @@ Options: } case "${1}" in - "-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";; + "-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";; "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";; "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; "-h" | "--help" ) helpFunc;; From 79c0b446e194c4d7f2be249a9e250be987e7601b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 21:55:49 +0200 Subject: [PATCH 195/638] Set missing data to N/A MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index e91a66e531..1044d63fa0 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -25,41 +25,41 @@ fi getLocalVersion() { case ${1} in - "Pi-hole" ) echo "${CORE_VERSION}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION}";; - "FTL" ) echo "${FTL_VERSION}";; + "Pi-hole" ) echo "${CORE_VERSION:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION:=N/A}";; + "FTL" ) echo "${FTL_VERSION:=N/A}";; esac } getLocalHash() { case ${1} in - "Pi-hole" ) echo "${CORE_HASH}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH}";; - "FTL" ) echo "${FTL_HASH}";; + "Pi-hole" ) echo "${CORE_HASH:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH:=N/A}";; + "FTL" ) echo "${FTL_HASH:=N/A}";; esac } getRemoteHash(){ case ${1} in - "Pi-hole" ) echo "${GITHUB_CORE_HASH}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH}";; - "FTL" ) echo "${GITHUB_FTL_HASH}";; + "Pi-hole" ) echo "${GITHUB_CORE_HASH:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH:=N/A}";; + "FTL" ) echo "${GITHUB_FTL_HASH:=N/A}";; esac } getRemoteVersion(){ case ${1} in - "Pi-hole" ) echo "${GITHUB_CORE_VERSION}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION}";; - "FTL" ) echo "${GITHUB_FTL_VERSION}";; + "Pi-hole" ) echo "${GITHUB_CORE_VERSION:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION:=N/A}";; + "FTL" ) echo "${GITHUB_FTL_VERSION:=N/A}";; esac } getLocalBranch(){ case ${1} in - "Pi-hole" ) echo "${CORE_BRANCH}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH}";; - "FTL" ) echo "${FTL_BRANCH}";; + "Pi-hole" ) echo "${CORE_BRANCH:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH:=N/A}";; + "FTL" ) echo "${FTL_BRANCH:=N/A}";; esac } @@ -73,7 +73,7 @@ versionOutput() { [ "$2" = "-l" ] || [ "$2" = "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "${1}") if [ "$2" = "--hash" ]; then [ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") - [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") + [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") && branch=$(getLocalBranch "${1}") fi if [ -n "$current" ] && [ -n "$latest" ]; then output="${1} version is $branch $current (Latest: $latest)" From 9471c69882ff549598f4f92735bd031532991ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 22:08:57 +0200 Subject: [PATCH 196/638] Fix spelling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 1044d63fa0..cef2132a20 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -12,14 +12,14 @@ # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf -# Sourece the versions file poupulated by updatechecker.sh +# Source the versions file poupulated by updatechecker.sh cachedVersions="/etc/pihole/versions" if [ -f ${cachedVersions} ]; then # shellcheck disable=SC1090 . "$cachedVersions" else - echo "Could not find /etc/pihole/versons. Exiting." + echo "Could not find /etc/pihole/versions. Exiting." exit 1 fi @@ -113,7 +113,7 @@ defaultOutput() { } helpFunc() { - echo "Usage: piho && lle -v [repo | option] [option] + echo "Usage: pihole -v [repo | option] [option] Example: 'pihole -v -p -l' Show Pi-hole, Admin Console & FTL versions From 4265bcb178906265044a841fd27ce1a1f13ed99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 8 Oct 2022 22:08:39 +0200 Subject: [PATCH 197/638] Add initscripts to CentOS8 dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/_centos_8.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/_centos_8.Dockerfile b/test/_centos_8.Dockerfile index 2a89458719..a07a67e9ee 100644 --- a/test/_centos_8.Dockerfile +++ b/test/_centos_8.Dockerfile @@ -1,5 +1,5 @@ FROM quay.io/centos/centos:stream8 -RUN yum install -y git +RUN yum install -y git initscripts ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From cf467db61def94a703cf1b01eae540cdad34b92e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Oct 2022 18:45:54 +0000 Subject: [PATCH 198/638] Bump actions/stale from 6.0.0 to 6.0.1 Bumps [actions/stale](https://github.com/actions/stale) from 6.0.0 to 6.0.1. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v6.0.0...v6.0.1) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 7b82bdbd52..a17d5a94c2 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v6.0.0 + - uses: actions/stale@v6.0.1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 From 223ef72250b258b74eeb27228eb14579632831fa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Oct 2022 18:46:02 +0000 Subject: [PATCH 199/638] Bump actions/checkout from 3.0.2 to 3.1.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.0.2 to 3.1.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.0.2...v3.1.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2c844337ff..b0ebb90e3d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index dd66ebdca3..f689ae364c 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -11,7 +11,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 - name: Opening pull request id: pull uses: tretuna/sync-branches@1.4.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb2d68d529..ff3af99439 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 - name: Check scripts in repository are executable run: | @@ -61,7 +61,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.0.2 + uses: actions/checkout@v3.1.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.2.0 From c5b3b8dd680c9a288fc6ce6e974e2797de9ce9b7 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sat, 8 Oct 2022 16:29:10 -0300 Subject: [PATCH 200/638] Fix `pihole -r` dialog exit - if an option is selected: Get option (repair/reconfigure); - if exit or ESC: Get exit code (1/255) Signed-off-by: RD WebDesign --- automated install/basic-install.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f3df72e659..d4c1ce7799 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2022,9 +2022,8 @@ update_dialogs() { \\n($strAdd)"\ "${r}" "${c}" 2 \ "${opt1a}" "${opt1b}" \ - "${opt2a}" "${opt2b}" || true) + "${opt2a}" "${opt2b}") || result=$? - result=$? case ${result} in "${DIALOG_CANCEL}" | "${DIALOG_ESC}") printf " %b Cancel was selected, exiting installer%b\\n" "${COL_LIGHT_RED}" "${COL_NC}" From 9c51050283cc357543cc26df82a6596f5dc3dfdf Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 13 Sep 2022 00:58:10 +0000 Subject: [PATCH 201/638] basic-install.sh: Use `grep -E` instead of `egrep` Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- 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 d4c1ce7799..99fac2cf90 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -358,7 +358,7 @@ package_manager_detect() { # These variable names match the ones for apt-get. See above for an explanation of what they are for. PKG_INSTALL=("${PKG_MANAGER}" install -y) # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. - PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" + PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" OS_CHECK_DEPS=(grep bind-utils) INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq) From e3db5fc601fe2536b818032cb4d3cbc59760200d Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 13 Sep 2022 00:20:01 +0000 Subject: [PATCH 202/638] basic-install.sh: Use `command -v` instead of `which` `command -v` is the standardized version of `which` and doesn't require any extra packages Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- 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 99fac2cf90..a29f3bd16f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2267,7 +2267,7 @@ get_binary_name() { local rev rev=$(uname -m | sed "s/[^0-9]//g;") local lib - lib=$(ldd "$(which sh)" | grep -E '^\s*/lib' | awk '{ print $1 }') + lib=$(ldd "$(command -v sh)" | grep -E '^\s*/lib' | awk '{ print $1 }') if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then printf "%b %b Detected AArch64 (64 Bit ARM) processor\\n" "${OVER}" "${TICK}" # set the binary to be used From e5695f862f52de00723ea87a875c9a2de2ce9971 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 11 Oct 2022 14:35:11 +0000 Subject: [PATCH 203/638] test_any_automated_install.py: Use `command -v` instead of `which` Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- test/test_any_automated_install.py | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 0fd80f7e3c..56c492dad9 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -619,8 +619,8 @@ def test_FTL_detect_aarch64_no_errors(host): """ # mock uname to return aarch64 platform mock_command("uname", {"-m": ("aarch64", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with aarch64 shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0")}, host) detectPlatform = host.run( @@ -647,8 +647,8 @@ def test_FTL_detect_armv4t_no_errors(host): """ # mock uname to return armv4t platform mock_command("uname", {"-m": ("armv4t", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with armv4t shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) detectPlatform = host.run( @@ -675,8 +675,8 @@ def test_FTL_detect_armv5te_no_errors(host): """ # mock uname to return armv5te platform mock_command("uname", {"-m": ("armv5te", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) detectPlatform = host.run( @@ -704,8 +704,8 @@ def test_FTL_detect_armv6l_no_errors(host): # mock uname to return armv6l platform mock_command("uname", {"-m": ("armv6l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( """ @@ -734,8 +734,8 @@ def test_FTL_detect_armv7l_no_errors(host): # mock uname to return armv7l platform mock_command("uname", {"-m": ("armv7l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( """ @@ -763,8 +763,8 @@ def test_FTL_detect_armv8a_no_errors(host): """ # mock uname to return armv8a platform mock_command("uname", {"-m": ("armv8a", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( @@ -789,8 +789,8 @@ def test_FTL_detect_x86_64_no_errors(host): """ confirms only x86_64 package is downloaded for FTL engine """ - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -813,8 +813,8 @@ def test_FTL_detect_unknown_no_errors(host): """confirms only generic package is downloaded for FTL engine""" # mock uname to return generic platform mock_command("uname", {"-m": ("mips", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh From 5c090d25e1df555a8723347916fd305f5c0f6a6c Mon Sep 17 00:00:00 2001 From: MichaIng Date: Tue, 11 Oct 2022 22:18:31 +0200 Subject: [PATCH 204/638] Fix ldd sh mock in tests Since "command" is a shell internal, it cannot be mocked, done via /usr/local/bin override. Since Debian containers ship without /bin => /usr/bin symlink, while all other containers do, the "ldd" mock needs to be applied for both paths, then. Signed-off-by: MichaIng --- test/test_any_automated_install.py | 70 ++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 56c492dad9..e6673bb50f 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -619,10 +619,15 @@ def test_FTL_detect_aarch64_no_errors(host): """ # mock uname to return aarch64 platform mock_command("uname", {"-m": ("aarch64", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with aarch64 shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"), + "/usr/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -647,10 +652,15 @@ def test_FTL_detect_armv4t_no_errors(host): """ # mock uname to return armv4t platform mock_command("uname", {"-m": ("armv4t", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with armv4t shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -675,10 +685,15 @@ def test_FTL_detect_armv5te_no_errors(host): """ # mock uname to return armv5te platform mock_command("uname", {"-m": ("armv5te", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -704,9 +719,14 @@ def test_FTL_detect_armv6l_no_errors(host): # mock uname to return armv6l platform mock_command("uname", {"-m": ("armv6l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -734,9 +754,14 @@ def test_FTL_detect_armv7l_no_errors(host): # mock uname to return armv7l platform mock_command("uname", {"-m": ("armv7l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -763,10 +788,15 @@ def test_FTL_detect_armv8a_no_errors(host): """ # mock uname to return armv8a platform mock_command("uname", {"-m": ("armv8a", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -789,8 +819,6 @@ def test_FTL_detect_x86_64_no_errors(host): """ confirms only x86_64 package is downloaded for FTL engine """ - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -813,8 +841,6 @@ def test_FTL_detect_unknown_no_errors(host): """confirms only generic package is downloaded for FTL engine""" # mock uname to return generic platform mock_command("uname", {"-m": ("mips", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh From 4c0a94d2b987016df3b80f1533046c9a8ade7e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 13 Oct 2022 14:16:56 +0200 Subject: [PATCH 205/638] Don't rely on pihole -v output but query github to get the lastest versions in debug script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 51 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index dbf567094b..d2b1cc3cd5 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -242,12 +242,12 @@ compare_local_version_to_git_version() { local pihole_component="${2}" # If we are checking the Core versions, if [[ "${pihole_component}" == "Core" ]]; then - # We need to search for "Pi-hole" when using pihole -v - local search_term="Pi-hole" + # set the github repo name + local repo_name="pi-hole" elif [[ "${pihole_component}" == "Web" ]]; then - # We need to search for "AdminLTE" so store it in a variable as well + # set the github repo name #shellcheck disable=2034 - local search_term="AdminLTE" + local repo_name="adminlte" fi # Display what we are checking echo_current_diagnostic "${pihole_component} version" @@ -261,26 +261,28 @@ compare_local_version_to_git_version() { log_write "${COL_RED}Could not cd into ${git_dir}$COL_NC" if git status &> /dev/null; then # The current version the user is on - local remote_version - remote_version=$(git describe --tags --abbrev=0); + local local_version + local_version=$(git describe --tags --abbrev=0); # What branch they are on - local remote_branch - remote_branch=$(git rev-parse --abbrev-ref HEAD); + local local_branch + local_branch=$(git rev-parse --abbrev-ref HEAD); # The commit they are on - local remote_commit - remote_commit=$(git describe --long --dirty --tags --always) + local local_commit + local_commit=$(git describe --long --dirty --tags --always) # Status of the repo local local_status local_status=$(git status -s) + local remote_version + remote_version=$(curl -s "https://api.github.com/repos/pi-hole/${repo_name}/releases/latest" 2> /dev/null | jq --raw-output .tag_name) # echo this information out to the user in a nice format - # If the current version matches what pihole -v produces, the user is up-to-date - if [[ "${remote_version}" == "$(pihole -v | awk '/${search_term}/ {print $6}' | cut -d ')' -f1)" ]]; then - log_write "${TICK} ${pihole_component}: ${COL_GREEN}${remote_version}${COL_NC}" + # If the current version matches the lastest tag, the user is up-to-date + if [[ "${local_version}" == "${remote_version}" ]]; then + log_write "${TICK} Version: ${COL_GREEN}${local_version}${COL_NC} [Latest: ${remote_version}]" # If not, else # echo the current version in yellow, signifying it's something to take a look at, but not a critical error # Also add a URL to an FAQ - log_write "${INFO} ${pihole_component}: ${COL_YELLOW}${remote_version:-Untagged}${COL_NC} (${FAQ_UPDATE_PI_HOLE})" + log_write "${INFO} Version: ${COL_YELLOW}${local_version:-Untagged}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" fi # Print the repo upstreams @@ -288,16 +290,16 @@ compare_local_version_to_git_version() { log_write "${INFO} Remotes: ${remotes//$'\n'/'\n '}" # If the repo is on the master branch, they are on the stable codebase - if [[ "${remote_branch}" == "master" ]]; then + if [[ "${local_branch}" == "master" ]]; then # so the color of the text is green - log_write "${INFO} Branch: ${COL_GREEN}${remote_branch}${COL_NC}" + log_write "${INFO} Branch: ${COL_GREEN}${local_branch}${COL_NC}" # If it is any other branch, they are in a development branch else # So show that in yellow, signifying it's something to take a look at, but not a critical error - log_write "${INFO} Branch: ${COL_YELLOW}${remote_branch:-Detached}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" + log_write "${INFO} Branch: ${COL_YELLOW}${local_branch:-Detached}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" fi # echo the current commit - log_write "${INFO} Commit: ${remote_commit}" + log_write "${INFO} Commit: ${local_commit}" # if `local_status` is non-null, then the repo is not clean, display details here if [[ ${local_status} ]]; then # Replace new lines in the status with 12 spaces to make the output cleaner @@ -331,21 +333,22 @@ compare_local_version_to_git_version() { } check_ftl_version() { - local ftl_name="FTL" - local FTL_VERSION FTL_COMMIT FTL_BRANCH - echo_current_diagnostic "${ftl_name} version" + local FTL_VERSION FTL_COMMIT FTL_BRANCH remote_version + echo_current_diagnostic "FTL version" # Use the built in command to check FTL's version FTL_VERSION=$(pihole-FTL -vv | grep -m 1 Version | awk '{printf $2}') FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') + remote_version=$(curl -s 'https://api.github.com/repos/pi-hole/ftl/releases/latest' 2> /dev/null | jq --raw-output .tag_name) + # Compare the current FTL version to the remote version - if [[ "${FTL_VERSION}" == "$(pihole -v | awk '/FTL/ {print $6}' | cut -d ')' -f1)" ]]; then + if [[ "${FTL_VERSION}" == "${remote_version}" ]]; then # If they are the same, FTL is up-to-date - log_write "${TICK} ${ftl_name}: ${COL_GREEN}${FTL_VERSION}${COL_NC}" + log_write "${TICK} Version: ${COL_GREEN}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}]" else # If not, show it in yellow, signifying there is an update - log_write "${INFO} ${ftl_name}: ${COL_YELLOW}${FTL_VERSION}${COL_NC} (${FAQ_UPDATE_PI_HOLE})" + log_write "${INFO} Version: ${COL_YELLOW}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" fi # If they use the master branch, they are on the stable codebase From 5c61f6cb65e32c2d96d10bdf31efe5440b1e01cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 08:43:39 +0200 Subject: [PATCH 206/638] Remove checkout hint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- 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 d2b1cc3cd5..3799448b0c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -48,7 +48,6 @@ OBFUSCATED_PLACEHOLDER="" # FAQ URLs for use in showing the debug log FAQ_UPDATE_PI_HOLE="${COL_CYAN}https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249${COL_NC}" -FAQ_CHECKOUT_COMMAND="${COL_CYAN}https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#checkout${COL_NC}" FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" @@ -73,7 +72,6 @@ WEB_SERVER_LOG_DIRECTORY="/var/log/lighttpd" WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd" HTML_DIRECTORY="/var/www/html" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" -#BLOCK_PAGE_DIRECTORY="${HTML_DIRECTORY}/pihole" SHM_DIRECTORY="/dev/shm" ETC="/etc" @@ -275,7 +273,7 @@ compare_local_version_to_git_version() { local remote_version remote_version=$(curl -s "https://api.github.com/repos/pi-hole/${repo_name}/releases/latest" 2> /dev/null | jq --raw-output .tag_name) # echo this information out to the user in a nice format - # If the current version matches the lastest tag, the user is up-to-date + # If the current version matches the latest tag, the user is up-to-date if [[ "${local_version}" == "${remote_version}" ]]; then log_write "${TICK} Version: ${COL_GREEN}${local_version}${COL_NC} [Latest: ${remote_version}]" # If not, @@ -296,7 +294,7 @@ compare_local_version_to_git_version() { # If it is any other branch, they are in a development branch else # So show that in yellow, signifying it's something to take a look at, but not a critical error - log_write "${INFO} Branch: ${COL_YELLOW}${local_branch:-Detached}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" + log_write "${INFO} Branch: ${COL_YELLOW}${local_branch:-Detached}${COL_NC}" fi # echo the current commit log_write "${INFO} Commit: ${local_commit}" @@ -358,7 +356,7 @@ check_ftl_version() { # If it is any other branch, they are in a development branch else # So show that in yellow, signifying it's something to take a look at, but not a critical error - log_write "${INFO} Branch: ${COL_YELLOW}${FTL_BRANCH}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" + log_write "${INFO} Branch: ${COL_YELLOW}${FTL_BRANCH}${COL_NC}" fi # echo the current commit From d85982dc515282da985f87f60ca0dd36ae51e3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 10:29:14 +0200 Subject: [PATCH 207/638] Use versions file instead of github api to get latest version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3799448b0c..59b2af8bcc 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -238,14 +238,19 @@ compare_local_version_to_git_version() { local git_dir="${1}" # The named component of the project (Core or Web) local pihole_component="${2}" + # If we are checking the Core versions, if [[ "${pihole_component}" == "Core" ]]; then - # set the github repo name - local repo_name="pi-hole" + local remote_version + # remote version is taken from /etc/pihole/versions (sourced above) + remote_version="${GITHUB_CORE_VERSION}" elif [[ "${pihole_component}" == "Web" ]]; then - # set the github repo name - #shellcheck disable=2034 - local repo_name="adminlte" + local remote_version + # remote version is taken from /etc/pihole/versions (sourced above) + remote_version="${GITHUB_WEB_VERSION}" + fi + if [ -z "${remote_version}" ]; then + remote_version="N/A" fi # Display what we are checking echo_current_diagnostic "${pihole_component} version" @@ -270,8 +275,6 @@ compare_local_version_to_git_version() { # Status of the repo local local_status local_status=$(git status -s) - local remote_version - remote_version=$(curl -s "https://api.github.com/repos/pi-hole/${repo_name}/releases/latest" 2> /dev/null | jq --raw-output .tag_name) # echo this information out to the user in a nice format # If the current version matches the latest tag, the user is up-to-date if [[ "${local_version}" == "${remote_version}" ]]; then @@ -338,7 +341,11 @@ check_ftl_version() { FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') - remote_version=$(curl -s 'https://api.github.com/repos/pi-hole/ftl/releases/latest' 2> /dev/null | jq --raw-output .tag_name) + # remote version is taken from /etc/pihole/versions (sourced above) + remote_version="${GITHUB_FTL_VERSION}" + if [ -z "${remote_version}" ]; then + remote_version="N/A" + fi # Compare the current FTL version to the remote version if [[ "${FTL_VERSION}" == "${remote_version}" ]]; then From c84be5de61210f9466552d2b6b6c25afd9797fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 13:18:12 +0200 Subject: [PATCH 208/638] Reorganize by component rather then source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 67 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 7241cddb35..938be6cd4a 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -49,10 +49,8 @@ rm -f "/etc/pihole/localversions" # Create new versions file if it does not exist VERSION_FILE="/etc/pihole/versions" -if [ ! -f ${VERSION_FILE} ]; then - touch "${VERSION_FILE}" - chmod 644 "${VERSION_FILE}" -fi +touch "${VERSION_FILE}" +chmod 644 "${VERSION_FILE}" # if /pihole.docker.tag file exists, we will use it's value later in this script DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null) @@ -68,7 +66,10 @@ if [[ "$1" == "reboot" ]]; then fi -# get local versions +# get Core versions + +CORE_VERSION="$(get_local_version /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" CORE_BRANCH="$(get_local_branch /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" @@ -76,59 +77,57 @@ addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" CORE_HASH="$(get_local_hash /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_HASH" "${CORE_HASH}" -if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - WEB_BRANCH="$(get_local_branch /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" - - WEB_HASH="$(get_local_hash /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" -fi +GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" -FTL_BRANCH="$(pihole-FTL branch)" -addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" +GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}" -FTL_HASH="$(pihole-FTL -v | cut -d "-" -f2)" -addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}" -CORE_VERSION="$(get_local_version /etc/.pihole)" -addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" +# get Web versions if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + WEB_VERSION="$(get_local_version /var/www/html/admin)" addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" -fi - -FTL_VERSION="$(pihole-FTL version)" -addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" - -if [[ "${DOCKER_TAG}" ]]; then - addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" -fi - - -# get remote versions -GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" -addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" + WEB_BRANCH="$(get_local_branch /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" -GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")" -addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}" + WEB_HASH="$(get_local_hash /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" -if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" GITHUB_WEB_HASH="$(get_remote_hash AdminLTE "${WEB_BRANCH}")" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}" + fi +# get FTL versions + +FTL_VERSION="$(pihole-FTL version)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" + +FTL_BRANCH="$(pihole-FTL branch)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" + +FTL_HASH="$(pihole-FTL -v | cut -d "-" -f2)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}" + GITHUB_FTL_VERSION="$(get_remote_version FTL)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" GITHUB_FTL_HASH="$(get_remote_hash FTL "${FTL_BRANCH}")" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_HASH" "${GITHUB_FTL_HASH}" + +# get Docker versions + if [[ "${DOCKER_TAG}" ]]; then + addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" + GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi From 52283478c842c03301d737ccc0da177d6f84bf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 13:21:31 +0200 Subject: [PATCH 209/638] Run pihole updatechecker if versions file is not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index cef2132a20..5c74fa05a4 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -19,8 +19,10 @@ if [ -f ${cachedVersions} ]; then # shellcheck disable=SC1090 . "$cachedVersions" else - echo "Could not find /etc/pihole/versions. Exiting." - exit 1 + echo "Could not find /etc/pihole/versions. Running update now." + pihole updatechecker + # shellcheck disable=SC1090 + . "$cachedVersions" fi getLocalVersion() { From d737948f64f9f638a5c0d7d58330f3065699c446 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 14 Oct 2022 14:11:19 -0300 Subject: [PATCH 210/638] Add `versions` file to the REQUIRED_FILES list Signed-off-by: RD WebDesign --- 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 dbf567094b..51994dc746 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -91,6 +91,7 @@ PIHOLE_LOGROTATE_FILE="${PIHOLE_DIRECTORY}/logrotate" PIHOLE_SETUP_VARS_FILE="${PIHOLE_DIRECTORY}/setupVars.conf" PIHOLE_FTL_CONF_FILE="${PIHOLE_DIRECTORY}/pihole-FTL.conf" PIHOLE_CUSTOM_HOSTS_FILE="${PIHOLE_DIRECTORY}/custom.list" +PIHOLE_VERSIONS_FILE="${PIHOLE_DIRECTORY}/versions" # Read the value of an FTL config key. The value is printed to stdout. # @@ -162,7 +163,8 @@ REQUIRED_FILES=("${PIHOLE_CRON_FILE}" "${PIHOLE_WEB_SERVER_ERROR_LOG_FILE}" "${RESOLVCONF}" "${DNSMASQ_CONF}" -"${PIHOLE_CUSTOM_HOSTS_FILE}") +"${PIHOLE_CUSTOM_HOSTS_FILE}" +"${PIHOLE_VERSIONS_FILE}") DISCLAIMER="This process collects information from your Pi-hole, and optionally uploads it to a unique and random directory on tricorder.pi-hole.net. From 235673dac8433a5ce2ffa0ac13b5f281a9745f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 13 Oct 2022 21:21:40 +0200 Subject: [PATCH 211/638] Remove unused possibility to obfuscate pihole.log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 60 ++------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index dbf567094b..7f4c5eb0e3 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -44,8 +44,6 @@ fi # shellcheck disable=SC1091 . /etc/pihole/versions -OBFUSCATED_PLACEHOLDER="" - # FAQ URLs for use in showing the debug log FAQ_UPDATE_PI_HOLE="${COL_CYAN}https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249${COL_NC}" FAQ_CHECKOUT_COMMAND="${COL_CYAN}https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#checkout${COL_NC}" @@ -54,7 +52,6 @@ FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prereq FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" FAQ_GATEWAY="${COL_CYAN}https://discourse.pi-hole.net/t/why-is-a-default-gateway-important-for-pi-hole/3546${COL_NC}" FAQ_FTL_COMPATIBILITY="${COL_CYAN}https://github.com/pi-hole/FTL#compatibility-list${COL_NC}" -FAQ_BAD_ADDRESS="${COL_CYAN}https://discourse.pi-hole.net/t/why-do-i-see-bad-address-at-in-pihole-log/3972${COL_NC}" # Other URLs we may use FORUMS_URL="${COL_CYAN}https://discourse.pi-hole.net${COL_NC}" @@ -1381,49 +1378,8 @@ spinner(){ fi } -obfuscated_pihole_log() { - local pihole_log=("$@") - local line - local error_to_check_for - local line_to_obfuscate - local obfuscated_line - for line in "${pihole_log[@]}"; do - # A common error in the pihole.log is when there is a non-hosts formatted file - # that the DNS server is attempting to read. Since it's not formatted - # correctly, there will be an entry for "bad address at line n" - # So we can check for that here and highlight it in red so the user can see it easily - error_to_check_for=$(echo "${line}" | grep 'bad address at') - # Some users may not want to have the domains they visit sent to us - # To that end, we check for lines in the log that would contain a domain name - line_to_obfuscate=$(echo "${line}" | grep ': query\|: forwarded\|: reply') - # If the variable contains a value, it found an error in the log - if [[ -n ${error_to_check_for} ]]; then - # So we can print it in red to make it visible to the user - log_write " ${CROSS} ${COL_RED}${line}${COL_NC} (${FAQ_BAD_ADDRESS})" - else - # If the variable does not a value (the current default behavior), so do not obfuscate anything - if [[ -z ${OBFUSCATE} ]]; then - log_write " ${line}" - # Otherwise, a flag was passed to this command to obfuscate domains in the log - else - # So first check if there are domains in the log that should be obfuscated - if [[ -n ${line_to_obfuscate} ]]; then - # If there are, we need to use awk to replace only the domain name (the 6th field in the log) - # so we substitute the domain for the placeholder value - obfuscated_line=$(echo "${line_to_obfuscate}" | awk -v placeholder="${OBFUSCATED_PLACEHOLDER}" '{sub($6,placeholder); print $0}') - log_write " ${obfuscated_line}" - else - log_write " ${line}" - fi - fi - fi - done -} - analyze_pihole_log() { echo_current_diagnostic "Pi-hole log" - local pihole_log_head=() - local pihole_log_tail=() local pihole_log_permissions local logging_enabled @@ -1433,22 +1389,10 @@ analyze_pihole_log() { log_write "${INFO} Query logging is disabled" log_write "" fi - # Put the current Internal Field Separator into another variable so it can be restored later - OLD_IFS="$IFS" - # Get the lines that are in the file(s) and store them in an array for parsing later - IFS=$'\r\n' + pihole_log_permissions=$(ls -lhd "${PIHOLE_LOG}") log_write "${COL_GREEN}${pihole_log_permissions}${COL_NC}" - mapfile -t pihole_log_head < <(head -n 20 ${PIHOLE_LOG}) - log_write " ${COL_CYAN}-----head of $(basename ${PIHOLE_LOG})------${COL_NC}" - obfuscated_pihole_log "${pihole_log_head[@]}" - log_write "" - mapfile -t pihole_log_tail < <(tail -n 20 ${PIHOLE_LOG}) - log_write " ${COL_CYAN}-----tail of $(basename ${PIHOLE_LOG})------${COL_NC}" - obfuscated_pihole_log "${pihole_log_tail[@]}" - log_write "" - # Set the IFS back to what it was - IFS="$OLD_IFS" + head_tail_log "${PIHOLE_LOG}" 20 } curl_to_tricorder() { From 4c9401175c6273085e7c8d3e960a4fffaab28b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 15 Oct 2022 09:06:57 +0200 Subject: [PATCH 212/638] Remove check for latest version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 40 +++------------------------------ 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 59b2af8bcc..22406af1a8 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -47,7 +47,6 @@ fi OBFUSCATED_PLACEHOLDER="" # FAQ URLs for use in showing the debug log -FAQ_UPDATE_PI_HOLE="${COL_CYAN}https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249${COL_NC}" FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" @@ -239,19 +238,6 @@ compare_local_version_to_git_version() { # The named component of the project (Core or Web) local pihole_component="${2}" - # If we are checking the Core versions, - if [[ "${pihole_component}" == "Core" ]]; then - local remote_version - # remote version is taken from /etc/pihole/versions (sourced above) - remote_version="${GITHUB_CORE_VERSION}" - elif [[ "${pihole_component}" == "Web" ]]; then - local remote_version - # remote version is taken from /etc/pihole/versions (sourced above) - remote_version="${GITHUB_WEB_VERSION}" - fi - if [ -z "${remote_version}" ]; then - remote_version="N/A" - fi # Display what we are checking echo_current_diagnostic "${pihole_component} version" # Store the error message in a variable in case we want to change and/or reuse it @@ -276,15 +262,7 @@ compare_local_version_to_git_version() { local local_status local_status=$(git status -s) # echo this information out to the user in a nice format - # If the current version matches the latest tag, the user is up-to-date - if [[ "${local_version}" == "${remote_version}" ]]; then - log_write "${TICK} Version: ${COL_GREEN}${local_version}${COL_NC} [Latest: ${remote_version}]" - # If not, - else - # echo the current version in yellow, signifying it's something to take a look at, but not a critical error - # Also add a URL to an FAQ - log_write "${INFO} Version: ${COL_YELLOW}${local_version:-Untagged}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" - fi + log_write "${TICK} Version: ${local_version}" # Print the repo upstreams remotes=$(git remote -v) @@ -334,27 +312,15 @@ compare_local_version_to_git_version() { } check_ftl_version() { - local FTL_VERSION FTL_COMMIT FTL_BRANCH remote_version + local FTL_VERSION FTL_COMMIT FTL_BRANCH echo_current_diagnostic "FTL version" # Use the built in command to check FTL's version FTL_VERSION=$(pihole-FTL -vv | grep -m 1 Version | awk '{printf $2}') FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') - # remote version is taken from /etc/pihole/versions (sourced above) - remote_version="${GITHUB_FTL_VERSION}" - if [ -z "${remote_version}" ]; then - remote_version="N/A" - fi - # Compare the current FTL version to the remote version - if [[ "${FTL_VERSION}" == "${remote_version}" ]]; then - # If they are the same, FTL is up-to-date - log_write "${TICK} Version: ${COL_GREEN}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}]" - else - # If not, show it in yellow, signifying there is an update - log_write "${INFO} Version: ${COL_YELLOW}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" - fi + log_write "${TICK} Version: ${FTL_VERSION}" # If they use the master branch, they are on the stable codebase if [[ "${FTL_BRANCH}" == "master" ]]; then From 429510e168ef585f22b5b63e3f21f5ca5150f291 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 15 Oct 2022 15:03:35 +0100 Subject: [PATCH 213/638] Update README.md Signed-off-by: Adam Warner --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c95df26341..9e0503bad4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our dialogs walk you through simple installation process in less than ten minutes +- **Easy-to-install**: our dialogs walk you through the simple installation process in less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) From 0cf59cf0fa635cdb231d258fd12f798e4376d40c Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 15 Oct 2022 15:36:20 +0100 Subject: [PATCH 214/638] Bump actions/setup-python from 4.2.0 to 4.3.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.2.0 to 4.3.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](actions/setup-python@v4.2.0...v4.3.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: Adam Warner --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff3af99439..d1709bbf99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -64,7 +64,7 @@ jobs: uses: actions/checkout@v3.1.0 - name: Set up Python 3.10 - uses: actions/setup-python@v4.2.0 + uses: actions/setup-python@v4.3.0 with: python-version: "3.10" From 8b98fd06ed2be16dafb283b42810ec7171e81e4f Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sun, 16 Oct 2022 15:54:24 -0300 Subject: [PATCH 215/638] Remove unused old code Signed-off-by: RD WebDesign --- gravity.sh | 86 +++++++++++++----------------------------------------- 1 file changed, 20 insertions(+), 66 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7c831b224b..ea3160fe8d 100755 --- a/gravity.sh +++ b/gravity.sh @@ -720,72 +720,26 @@ gravity_DownloadBlocklistFromUrl() { # Parse source files into domains format gravity_ParseFileIntoDomains() { - local src="${1}" destination="${2}" firstLine - - # Determine if we are parsing a consolidated list - #if [[ "${src}" == "${piholeDir}/${matterAndLight}" ]]; then - # Remove comments and print only the domain name - # Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous - # This helps with that and makes it easier to read - # It also helps with debugging so each stage of the script can be researched more in depth - # 1) Remove carriage returns - # 2) Convert all characters to lowercase - # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) - # 4) Remove lines containing "/" - # 5) Remove leading tabs, spaces, etc. - # 6) Delete lines not matching domain names - < "${src}" tr -d '\r' | \ - tr '[:upper:]' '[:lower:]' | \ - sed 's/\s*#.*//g' | \ - sed -r '/(\/).*$/d' | \ - sed -r 's/^.*\s+//g' | \ - sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}" - chmod 644 "${destination}" - return 0 - #fi - - # Individual file parsing: Keep comments, while parsing domains from each line - # We keep comments to respect the list maintainer's licensing - read -r firstLine < "${src}" - - # Determine how to parse individual source file formats - if [[ "${firstLine,,}" =~ (adblock|ublock|^!) ]]; then - # Compare $firstLine against lower case words found in Adblock lists - echo -e " ${CROSS} Format: Adblock (list type not supported)" - elif grep -q "^address=/" "${src}" &> /dev/null; then - # Parse Dnsmasq format lists - echo -e " ${CROSS} Format: Dnsmasq (list type not supported)" - elif grep -q -E "^https?://" "${src}" &> /dev/null; then - # Parse URL list if source file contains "http://" or "https://" - # Scanning for "^IPv4$" is too slow with large (1M) lists on low-end hardware - echo -ne " ${INFO} Format: URL" - - awk ' - # Remove URL scheme, optional "username:password@", and ":?/;" - # The scheme must be matched carefully to avoid blocking the wrong URL - # in cases like: - # http://www.evil.com?http://www.good.com - # See RFC 3986 section 3.1 for details. - /[:?\/;]/ { gsub(/(^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(.*:.*@)?|[:?\/;].*)/, "", $0) } - # Skip lines which are only IPv4 addresses - /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ { next } - # Print if nonempty - length { print } - ' "${src}" 2> /dev/null > "${destination}" - chmod 644 "${destination}" - - echo -e "${OVER} ${TICK} Format: URL" - else - # Default: Keep hosts/domains file in same format as it was downloaded - output=$( { mv "${src}" "${destination}"; } 2>&1 ) - chmod 644 "${destination}" - - if [[ ! -e "${destination}" ]]; then - echo -e "\\n ${CROSS} Unable to move tmp file to ${piholeDir} - ${output}" - gravity_Cleanup "error" - fi - fi + local src="${1}" destination="${2}" + + # Remove comments and print only the domain name + # Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous + # This helps with that and makes it easier to read + # It also helps with debugging so each stage of the script can be researched more in depth + # 1) Remove carriage returns + # 2) Convert all characters to lowercase + # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) + # 4) Remove lines containing "/" + # 5) Remove leading tabs, spaces, etc. + # 6) Delete lines not matching domain names + < "${src}" tr -d '\r' | \ + tr '[:upper:]' '[:lower:]' | \ + sed 's/\s*#.*//g' | \ + sed -r '/(\/).*$/d' | \ + sed -r 's/^.*\s+//g' | \ + sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}" + chmod 644 "${destination}" + return 0 } # Report number of entries in a table From 528abc9c97b343bbfeba924b9b72bec560d11907 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sun, 16 Oct 2022 19:36:56 -0300 Subject: [PATCH 216/638] Adding CentOS Stream 9 tests Signed-off-by: RD WebDesign --- .github/workflows/test.yml | 1 + test/_centos_9.Dockerfile | 18 ++++++++++++++++++ test/tox.centos_9.ini | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/_centos_9.Dockerfile create mode 100644 test/tox.centos_9.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d1709bbf99..daa18c8578 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,6 +54,7 @@ jobs: ubuntu_20, ubuntu_22, centos_8, + centos_9, fedora_35, fedora_36, ] diff --git a/test/_centos_9.Dockerfile b/test/_centos_9.Dockerfile new file mode 100644 index 0000000000..befa15844b --- /dev/null +++ b/test/_centos_9.Dockerfile @@ -0,0 +1,18 @@ +FROM quay.io/centos/centos:stream9 +RUN yum install -y git initscripts + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.centos_9.ini b/test/tox.centos_9.ini new file mode 100644 index 0000000000..633fc5c4d2 --- /dev/null +++ b/test/tox.centos_9.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _centos_9.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py From 85ffbcf05ee0083347d0ab1ce87cfdc19942c70f Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 17 Oct 2022 14:58:42 -0300 Subject: [PATCH 217/638] Allow replacing conflicting existing packages from testing image Signed-off-by: RD WebDesign --- test/_centos_9.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/_centos_9.Dockerfile b/test/_centos_9.Dockerfile index befa15844b..6ccd18b649 100644 --- a/test/_centos_9.Dockerfile +++ b/test/_centos_9.Dockerfile @@ -1,5 +1,5 @@ FROM quay.io/centos/centos:stream9 -RUN yum install -y git initscripts +RUN yum install -y --allowerasing curl git initscripts ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From 090727b1d34d485906c540442be2ebcad1904a6d Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 17 Oct 2022 15:24:49 -0300 Subject: [PATCH 218/638] Remove unnecessary return Signed-off-by: RD WebDesign --- gravity.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index ea3160fe8d..14732f3141 100755 --- a/gravity.sh +++ b/gravity.sh @@ -739,7 +739,6 @@ gravity_ParseFileIntoDomains() { sed -r 's/^.*\s+//g' | \ sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}" chmod 644 "${destination}" - return 0 } # Report number of entries in a table From 21be1bd58e6e378ac0f5b8cd4069d78a68e4d836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 20 Oct 2022 06:53:13 +0200 Subject: [PATCH 219/638] Prevent CNAME loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e02e03f940..2dc2d4c584 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -729,7 +729,12 @@ AddCustomCNAMERecord() { if [[ -n "${validDomain}" ]]; then validTarget="$(checkDomain "${target}")" if [[ -n "${validTarget}" ]]; then - echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}" + if [ "${validDomain}" = "${validTarget}" ]; then + echo " ${CROSS} Domain and target are the same!" + exit 1 + else + echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}" + fi else echo " ${CROSS} Invalid Target Passed!" exit 1 From c322458dcb568604c94b6c359863b21fd88dc13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 21 Oct 2022 12:25:23 +0200 Subject: [PATCH 220/638] Escape dots in local DNS records/CNAMES before removing them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e02e03f940..f4a452fe27 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -627,6 +627,12 @@ checkDomain() echo "${validDomain}" } +escapeDots() +{ + escaped=$(sed 's/\./\\./g' <<< "$1" ) + echo "${escaped}" +} + addAudit() { shift # skip "-a" @@ -702,6 +708,7 @@ RemoveCustomDNSAddress() { validHost="$(checkDomain "${host}")" if [[ -n "${validHost}" ]]; then if valid_ip "${ip}" || valid_ip6 "${ip}" ; then + validHost=$(escapeDots "${validHost}") sed -i "/^${ip} ${validHost}$/Id" "${dnscustomfile}" else echo -e " ${CROSS} Invalid IP has been passed" @@ -755,7 +762,9 @@ RemoveCustomCNAMERecord() { if [[ -n "${validDomain}" ]]; then validTarget="$(checkDomain "${target}")" if [[ -n "${validTarget}" ]]; then - sed -i "/cname=${validDomain},${validTarget}$/Id" "${dnscustomcnamefile}" + validDomain=$(escapeDots "${validDomain}") + validTarget=$(escapeDots "${validTarget}") + sed -i "/^cname=${validDomain},${validTarget}$/Id" "${dnscustomcnamefile}" else echo " ${CROSS} Invalid Target Passed!" exit 1 From df3e9e5f5108636404e3dea80201868f02fc739c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 21 Oct 2022 14:31:16 +0200 Subject: [PATCH 221/638] Disable shellcheck as it suggests a bashism MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f4a452fe27..7c112d0000 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -629,6 +629,8 @@ checkDomain() escapeDots() { + # shellcheck disable=SC2001 + # SH suggest bashism ${variable//search/replace} escaped=$(sed 's/\./\\./g' <<< "$1" ) echo "${escaped}" } From 128a3ab1becbdd4815a85a35ebeefeec1f7f6e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 22 Oct 2022 22:37:05 +0200 Subject: [PATCH 222/638] Go POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7c112d0000..53d631cd08 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -629,9 +629,9 @@ checkDomain() escapeDots() { + # SC suggest bashism ${variable//search/replace} # shellcheck disable=SC2001 - # SH suggest bashism ${variable//search/replace} - escaped=$(sed 's/\./\\./g' <<< "$1" ) + escaped=$(echo "$1" | sed 's/\./\\./g') echo "${escaped}" } From c8c6533440126a4abf0dc4e2e1f4316e3ceb7d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 29 Oct 2022 15:09:14 +0200 Subject: [PATCH 223/638] Add small explanation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 2dc2d4c584..aec8917e25 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -730,7 +730,7 @@ AddCustomCNAMERecord() { validTarget="$(checkDomain "${target}")" if [[ -n "${validTarget}" ]]; then if [ "${validDomain}" = "${validTarget}" ]; then - echo " ${CROSS} Domain and target are the same!" + echo " ${CROSS} Domain and target are the same. This would cause a DNS loop." exit 1 else echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}" From 81927334f25313f0807588a91fbfa061a9665932 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 18 Sep 2022 21:44:06 +0200 Subject: [PATCH 224/638] Add native systemd service Inspired by: https://github.com/pi-hole/pi-hole/pull/2112 A pre-start and a post-stop script are added to reduce doubled setup and cleanup code. Since systemd services do not natively support dynamic users, test once whether capabilities are supported during install/update, and remove User=pihole otherwise. Signed-off-by: MichaIng Co-authored-by: DL6ER --- advanced/Templates/pihole-FTL-poststop.sh | 13 +++++++ advanced/Templates/pihole-FTL-prestart.sh | 38 +++++++++++++++++++++ advanced/Templates/pihole-FTL.service | 40 +++++----------------- advanced/Templates/pihole-FTL.systemd | 41 +++++++++++++++++++++++ automated install/basic-install.sh | 25 ++++++++++++-- 5 files changed, 123 insertions(+), 34 deletions(-) create mode 100755 advanced/Templates/pihole-FTL-poststop.sh create mode 100755 advanced/Templates/pihole-FTL-prestart.sh create mode 100644 advanced/Templates/pihole-FTL.systemd diff --git a/advanced/Templates/pihole-FTL-poststop.sh b/advanced/Templates/pihole-FTL-poststop.sh new file mode 100755 index 0000000000..ac3898d2f0 --- /dev/null +++ b/advanced/Templates/pihole-FTL-poststop.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# Source utils.sh for getFTLPIDFile() +PI_HOLE_SCRIPT_DIR='/opt/pihole' +utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" +# shellcheck disable=SC1090 +. "${utilsfile}" + +# Get file paths +FTL_PID_FILE="$(getFTLPIDFile)" + +# Cleanup +rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}" diff --git a/advanced/Templates/pihole-FTL-prestart.sh b/advanced/Templates/pihole-FTL-prestart.sh new file mode 100755 index 0000000000..ff4abf3abe --- /dev/null +++ b/advanced/Templates/pihole-FTL-prestart.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env sh + +# Source utils.sh for getFTLPIDFile() +PI_HOLE_SCRIPT_DIR='/opt/pihole' +utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" +# shellcheck disable=SC1090 +. "${utilsfile}" + +# Get file paths +FTL_PID_FILE="$(getFTLPIDFile)" + +# Touch files to ensure they exist (create if non-existing, preserve if existing) +# shellcheck disable=SC2174 +mkdir -pm 0755 /run/pihole /var/log/pihole +[ -f "${FTL_PID_FILE}" ] || install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" +[ -f /var/log/pihole/FTL.log ] || install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log +[ -f /var/log/pihole/pihole.log ] || install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log +[ -f /etc/pihole/dhcp.leases ] || install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases +# Ensure that permissions are set so that pihole-FTL can edit all necessary files +chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole /var/log/pihole/FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases +# Ensure that permissions are set so that pihole-FTL can edit the files. We ignore errors as the file may not (yet) exist +chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/FTL.log +chmod -f 0640 /var/log/pihole/pihole.log +# Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist +chown -f pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db /etc/pihole/macvendor.db +# Chmod database file permissions so that the pihole group (web interface) can edit the file. We ignore errors as the files may not (yet) exist +chmod -f 0664 /etc/pihole/pihole-FTL.db + +# Backward compatibility for user-scripts that still expect log files in /var/log instead of /var/log/pihole +# Should be removed with Pi-hole v6.0 +if [ ! -f /var/log/pihole.log ]; then + ln -sf /var/log/pihole/pihole.log /var/log/pihole.log + chown -h pihole:pihole /var/log/pihole.log +fi +if [ ! -f /var/log/pihole-FTL.log ]; then + ln -sf /var/log/pihole/FTL.log /var/log/pihole-FTL.log + chown -h pihole:pihole /var/log/pihole-FTL.log +fi diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index bc1b1d20e0..15096972df 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -9,9 +9,10 @@ # Description: Enable service provided by pihole-FTL daemon ### END INIT INFO -#source utils.sh for getFTLPIDFile(), getFTLPID () +# Source utils.sh for getFTLPIDFile(), getFTLPID() PI_HOLE_SCRIPT_DIR="/opt/pihole" utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" +# shellcheck disable=SC1090 . "${utilsfile}" @@ -28,33 +29,8 @@ start() { if is_running; then echo "pihole-FTL is already running" else - # Touch files to ensure they exist (create if non-existing, preserve if existing) - mkdir -pm 0755 /run/pihole /var/log/pihole - [ ! -f "${FTL_PID_FILE}" ] && install -D -m 644 -o pihole -g pihole /dev/null "${FTL_PID_FILE}" - [ ! -f /var/log/pihole/FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole/FTL.log - [ ! -f /var/log/pihole/pihole.log ] && install -m 640 -o pihole -g pihole /dev/null /var/log/pihole/pihole.log - [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases - # Ensure that permissions are set so that pihole-FTL can edit all necessary files - chown pihole:pihole /run/pihole /etc/pihole /var/log/pihole /var/log/pihole/FTL.log /var/log/pihole/pihole.log /etc/pihole/dhcp.leases - # Ensure that permissions are set so that pihole-FTL can edit the files. We ignore errors as the file may not (yet) exist - chmod -f 0644 /etc/pihole/macvendor.db /etc/pihole/dhcp.leases /var/log/pihole/FTL.log - chmod -f 0640 /var/log/pihole/pihole.log - # Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist - chown -f pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db /etc/pihole/macvendor.db - # Chown database file permissions so that the pihole group (web interface) can edit the file. We ignore errors as the files may not (yet) exist - chmod -f 0664 /etc/pihole/pihole-FTL.db - - # Backward compatibility for user-scripts that still expect log files in /var/log instead of /var/log/pihole/ - # Should be removed with Pi-hole v6.0 - if [ ! -f /var/log/pihole.log ]; then - ln -s /var/log/pihole/pihole.log /var/log/pihole.log - chown -h pihole:pihole /var/log/pihole.log - - fi - if [ ! -f /var/log/pihole-FTL.log ]; then - ln -s /var/log/pihole/FTL.log /var/log/pihole-FTL.log - chown -h pihole:pihole /var/log/pihole-FTL.log - fi + # Run pre-start script, which pre-creates all expected files with correct permissions + sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-prestart.sh" if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole || exit $? @@ -89,8 +65,8 @@ stop() { else echo "Not running" fi - # Cleanup - rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}" + # Run post-stop script, which does cleanup among runtime files + sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-poststop.sh" echo } @@ -108,11 +84,11 @@ status() { ### main logic ### -# Get file paths +# Get FTL's PID file path FTL_PID_FILE="$(getFTLPIDFile)" # Get FTL's current PID -FTL_PID="$(getFTLPID ${FTL_PID_FILE})" +FTL_PID="$(getFTLPID "${FTL_PID_FILE}")" case "$1" in stop) diff --git a/advanced/Templates/pihole-FTL.systemd b/advanced/Templates/pihole-FTL.systemd new file mode 100644 index 0000000000..2a11419906 --- /dev/null +++ b/advanced/Templates/pihole-FTL.systemd @@ -0,0 +1,41 @@ +[Unit] +Description=Pi-hole FTL +# This unit is supposed to indicate when network functionality is available, but it is only +# very weakly defined what that is supposed to mean, with one exception: at shutdown, a unit +# that is ordered after network-online.target will be stopped before the network +Wants=network-online.target +After=network-online.target +# A target that should be used as synchronization point for all host/network name service lookups. +# All services for which the availability of full host/network name resolution is essential should +# be ordered after this target, but not pull it in. +Wants=nss-lookup.target +Before=nss-lookup.target + +# Limit (re)start loop to 5 within 1 minute +StartLimitBurst=5 +StartLimitIntervalSec=60s + +[Service] +User=pihole +PermissionsStartOnly=true +AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_NET_ADMIN CAP_SYS_NICE CAP_IPC_LOCK CAP_CHOWN + +ExecStartPre=/opt/pihole/pihole-FTL-prestart.sh +ExecStart=/usr/bin/pihole-FTL -f +Restart=on-failure +RestartSec=5s +ExecReload=/bin/kill -HUP $MAINPID +ExecStopPost=/opt/pihole/pihole-FTL-poststop.sh + +# Use graceful shutdown with a reasonable timeout +TimeoutStopSec=10s + +# Make /usr, /boot, /etc and possibly some more folders read-only... +ProtectSystem=full +# ... except /etc/pihole +# This merely retains r/w access rights, it does not add any new. +# Must still be writable on the host! +ReadWriteDirectories=/etc/pihole + +[Install] +WantedBy=multi-user.target diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d4c1ce7799..2831e7ec24 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1377,8 +1377,29 @@ installConfigs() { fi fi - # Install pihole-FTL.service - install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" "/etc/init.d/pihole-FTL" + # Install pihole-FTL systemd or init.d service, based on whether systemd is the init system or not + # Follow debhelper logic, which checks for /run/systemd/system to derive whether systemd is the init system + if [[ -d '/run/systemd/system' ]]; then + install -T -m 0644 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.systemd" '/etc/systemd/system/pihole-FTL.service' + + # Set net admin permissions so that FTL can serve DNS, DHCP and IMAP (for DHCPv6). If this does not work, run FTL as root user. + if ! setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip '/usr/bin/pihole-FTL'; then + sed -i '/^User=/d' '/etc/systemd/system/pihole-FTL.service' + fi + + # Remove init.d service if present + if [[ -e '/etc/init.d/pihole-FTL' ]]; then + rm '/etc/init.d/pihole-FTL' + update-rc.d pihole-FTL remove + fi + + # Load final service + systemctl daemon-reload + else + install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.service" '/etc/init.d/pihole-FTL' + fi + install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-prestart.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-prestart.sh" + install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-poststop.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-poststop.sh" # If the user chose to install the dashboard, if [[ "${INSTALL_WEB_SERVER}" == true ]]; then From 06cf7afbc2646706186f74694d223c392135824a Mon Sep 17 00:00:00 2001 From: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> Date: Sat, 29 Oct 2022 17:52:24 +0200 Subject: [PATCH 225/638] Fix static IP not set Signed-off-by: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> --- automated install/basic-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d4c1ce7799..0fda391d53 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -828,8 +828,11 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Configure networking via dhcpcd setDHCPCD() { - # Check if the IP is already in the file - if grep -q "${IPV4_ADDRESS}" /etc/dhcpcd.conf; then + # Regex for matching a non-commented static ip address setting + local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}[ \t]*$" + + # Check if static IP is already set in file + if grep -xq "${regex}" /etc/dhcpcd.conf; then printf " %b Static IP already configured\\n" "${INFO}" # If it's not, else From 122bc6b927faded08757e603f33ba560dbb2c8b5 Mon Sep 17 00:00:00 2001 From: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> Date: Wed, 2 Nov 2022 22:35:39 +0100 Subject: [PATCH 226/638] Fix static IP not set because of in-line comment Signed-off-by: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> --- 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 0fda391d53..8edd493686 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -829,10 +829,10 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Configure networking via dhcpcd setDHCPCD() { # Regex for matching a non-commented static ip address setting - local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}[ \t]*$" + local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}" # Check if static IP is already set in file - if grep -xq "${regex}" /etc/dhcpcd.conf; then + if grep -q "${regex}" /etc/dhcpcd.conf; then printf " %b Static IP already configured\\n" "${INFO}" # If it's not, else From 2fd5b944ad4294d7894ff93a23f18db6baa12e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 3 Nov 2022 22:01:37 +0100 Subject: [PATCH 227/638] Touch setupVars before writing to it 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8edd493686..ea7052f39e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1785,6 +1785,9 @@ create_pihole_user() { finalExports() { # set or update the variables in the file + # create the file if it does not exist + touch "${setupVars}" + addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}" From 67385b7ed43a2c68bc851b3329c72c838849beea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 9 Nov 2022 21:25:09 +0100 Subject: [PATCH 228/638] Touch files before addKey or addOrEditKeyValPair MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/utils.sh | 6 ++++++ automated install/basic-install.sh | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 1174fa62e2..3751647292 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -31,6 +31,9 @@ addOrEditKeyValPair() { local key="${2}" local value="${3}" + # touch file to prevent grep error if file does not exist yet + touch "${file}" + if grep -q "^${key}=" "${file}"; then # Key already exists in file, modify the value sed -i "/^${key}=/c\\${key}=${value}" "${file}" @@ -51,6 +54,9 @@ addKey(){ local file="${1}" local key="${2}" + # touch file to prevent grep error if file does not exist yet + touch "${file}" + if ! grep -q "^${key}" "${file}"; then # Key does not exist, add it. echo "${key}" >> "${file}" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ea7052f39e..8edd493686 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1785,9 +1785,6 @@ create_pihole_user() { finalExports() { # set or update the variables in the file - # create the file if it does not exist - touch "${setupVars}" - addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}" From 7536c312ee7148734a520254f30c01050d04b416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 13 Nov 2022 21:53:59 +0100 Subject: [PATCH 229/638] Correctly identify process status in debug script on docker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 99ab6cbea1..7ad9241238 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -925,10 +925,21 @@ process_status(){ else # Otherwise, use the service command and mock the output of `systemctl is-active` local status_of_process - if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then - status_of_process="active" + + # If DOCKER_VERSION is set, the output is slightly different (s6 init system on Docker) + if [ -n "${DOCKER_VERSION}" ]; then + if service "${i}" status | grep -E '^up' &> /dev/null; then + status_of_process="active" + else + status_of_process="inactive" + fi else - status_of_process="inactive" + # non-Docker system + if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then + status_of_process="active" + else + status_of_process="inactive" + fi fi fi # and print it out to the user From cdbe4c9b861d3a2daa92593cfe093d95379877b9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 14 Nov 2022 20:39:34 +0000 Subject: [PATCH 230/638] Get only the precise tag number when getting local version, do not show branch name when on master branch(es) Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 2 +- advanced/Scripts/version.sh | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 938be6cd4a..6a5324c7e0 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -17,7 +17,7 @@ function get_local_branch() { function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - git describe --long --dirty --tags 2> /dev/null || return 1 + git describe --tags --always 2> /dev/null || return 1 } function get_local_hash() { diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 5c74fa05a4..946c69fe56 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -77,18 +77,27 @@ versionOutput() { [ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") && branch=$(getLocalBranch "${1}") fi + + # We do not want to show the branch name when we are on master, + # blank out the variable in this case + if [ "$branch" = "master" ]; then + branch="" + else + branch="$branch " + fi + if [ -n "$current" ] && [ -n "$latest" ]; then - output="${1} version is $branch $current (Latest: $latest)" + output="${1} version is $branch$current (Latest: $latest)" elif [ -n "$current" ] && [ -z "$latest" ]; then - output="Current ${1} version is $branch $current" + output="Current ${1} version is $branch$current" elif [ -z "$current" ] && [ -n "$latest" ]; then output="Latest ${1} version is $latest" elif [ -n "$curHash" ] && [ -n "$latHash" ]; then - output="Local ${1} hash of branch $branch is $curHash (Remote: $latHash)" + output="Local ${1} hash is $curHash (Remote: $latHash)" elif [ -n "$curHash" ] && [ -z "$latHash" ]; then - output="Current local ${1} hash of branch $branch is $curHash" + output="Current local ${1} hash is $curHash" elif [ -z "$curHash" ] && [ -n "$latHash" ]; then - output="Latest remote ${1} hash of branch $branch is $latHash" + output="Latest remote ${1} hash is $latHash" elif [ -z "$curHash" ] && [ -z "$latHash" ]; then output="Hashes for ${1} not available" else From ba74051502dd64b8bccc1f4ec1d74587202d902f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 14 Nov 2022 22:09:26 +0000 Subject: [PATCH 231/638] Grab local FTL hash correctly from FTL's own version output, and grab one digit less for remote hashes (also in debug log) Signed-off-by: Adam Warner --- advanced/Scripts/piholeDebug.sh | 6 +++--- advanced/Scripts/updatecheck.sh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 7ad9241238..3cd782bfa7 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -314,9 +314,9 @@ check_ftl_version() { local FTL_VERSION FTL_COMMIT FTL_BRANCH echo_current_diagnostic "FTL version" # Use the built in command to check FTL's version - FTL_VERSION=$(pihole-FTL -vv | grep -m 1 Version | awk '{printf $2}') - FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') - FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') + FTL_VERSION=$(pihole-FTL version) + FTL_BRANCH=$(pihole-FTL branch) + FTL_COMMIT=$(pihole-FTL --hash) log_write "${TICK} Version: ${FTL_VERSION}" diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 6a5324c7e0..0ce9ad5d30 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -31,7 +31,7 @@ function get_remote_version() { function get_remote_hash(){ - git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,9);}' || return 1 + git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || return 1 } # Source the setupvars config file @@ -113,7 +113,7 @@ addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" FTL_BRANCH="$(pihole-FTL branch)" addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" -FTL_HASH="$(pihole-FTL -v | cut -d "-" -f2)" +FTL_HASH="$(pihole-FTL --hash)" addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}" GITHUB_FTL_VERSION="$(get_remote_version FTL)" From 38775cffdf6fb849643ffac1913e97b4d88e67f5 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 14 Nov 2022 22:51:39 +0000 Subject: [PATCH 232/638] Ensure local hash is always of length 8, for consistency. Signed-off-by: Adam Warner --- advanced/Scripts/updatecheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 0ce9ad5d30..0cc652188e 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -22,7 +22,7 @@ function get_local_version() { function get_local_hash() { cd "${1}" 2> /dev/null || return 1 - git rev-parse --short HEAD || return 1 + git rev-parse --short=8 HEAD || return 1 } function get_remote_version() { From 6d8abc2e30aecc98c5807a3ec4a409f4b3568580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 18 Nov 2022 23:50:34 +0100 Subject: [PATCH 233/638] Don't install `which` 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b9a6142b2a..841a04f424 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -360,7 +360,7 @@ package_manager_detect() { # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" OS_CHECK_DEPS=(grep bind-utils) - INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) + INSTALLER_DEPS=(git dialog iproute newt procps-ng chkconfig ca-certificates) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl) LIGHTTPD_USER="lighttpd" From f3c27f706f3b2007b9cdbbab4747a4ff4834d8ed Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 23 Nov 2022 14:07:30 -0300 Subject: [PATCH 234/638] Pass only the correct argument Signed-off-by: RD WebDesign --- pihole | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index aad8345186..ed8eb85600 100755 --- a/pihole +++ b/pihole @@ -425,7 +425,7 @@ tricorderFunc() { } updateCheckFunc() { - "${PI_HOLE_SCRIPT_DIR}"/updatecheck.sh "$@" + "${PI_HOLE_SCRIPT_DIR}"/updatecheck.sh "$1" exit 0 } @@ -553,7 +553,7 @@ case "${1}" in "restartdns" ) restartDNS "$2";; "-a" | "admin" ) webpageFunc "$@";; "checkout" ) piholeCheckoutFunc "$@";; - "updatechecker" ) updateCheckFunc "$@";; + "updatechecker" ) updateCheckFunc "$2";; "arpflush" ) arpFunc "$@";; "-t" | "tail" ) tailFunc "$2";; esac From 233453267e20a3baedc350324daa73311a26c0ed Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 23 Nov 2022 15:33:49 -0300 Subject: [PATCH 235/638] Using `shift` to allow passing multiple arguments Signed-off-by: RD WebDesign --- pihole | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index ed8eb85600..ca80bff841 100755 --- a/pihole +++ b/pihole @@ -425,7 +425,7 @@ tricorderFunc() { } updateCheckFunc() { - "${PI_HOLE_SCRIPT_DIR}"/updatecheck.sh "$1" + "${PI_HOLE_SCRIPT_DIR}"/updatecheck.sh "$@" exit 0 } @@ -553,7 +553,7 @@ case "${1}" in "restartdns" ) restartDNS "$2";; "-a" | "admin" ) webpageFunc "$@";; "checkout" ) piholeCheckoutFunc "$@";; - "updatechecker" ) updateCheckFunc "$2";; + "updatechecker" ) shift; updateCheckFunc "$@";; "arpflush" ) arpFunc "$@";; "-t" | "tail" ) tailFunc "$2";; esac From ea26171c187f07efed8a1233859d35afe9c5b7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 24 Nov 2022 20:39:02 +0100 Subject: [PATCH 236/638] Do not require man pages to be present in test script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_automated_install.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index e6673bb50f..2ea619f704 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -211,6 +211,8 @@ def test_installPihole_fresh_install_readableFiles(host): maninstalled = True if (info_box + " man not installed") in install.stdout: maninstalled = False + if (info_box + " man pages not installed") in install.stdout: + maninstalled = False piholeuser = "pihole" exit_status_success = 0 test_cmd = 'su --shell /bin/bash --command "test -{0} {1}" -p {2}' From 33d2163f1901b8abf5e8409d9e4b1610c5797558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 24 Nov 2022 22:06:04 +0100 Subject: [PATCH 237/638] Explicitly create group pihole on installation 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 | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 841a04f424..4d663282b9 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1760,20 +1760,35 @@ create_pihole_user() { else # If the pihole user doesn't exist, printf "%b %b %s" "${OVER}" "${CROSS}" "${str}" - local str="Creating user 'pihole'" - printf "%b %b %s..." "${OVER}" "${INFO}" "${str}" - # create her with the useradd command, + local str="Checking for group 'pihole'" + printf " %b %s..." "${INFO}" "${str}" if getent group pihole > /dev/null 2>&1; then - # then add her to the pihole group (as it already exists) + # group pihole exists + printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" + # then create and add her to the pihole group + local str="Creating user 'pihole'" + printf "%b %b %s..." "${OVER}" "${INFO}" "${str}" if useradd -r --no-user-group -g pihole -s /usr/sbin/nologin pihole; then printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" else printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" fi else - # add user pihole with default group settings - if useradd -r -s /usr/sbin/nologin pihole; then + # group pihole does not exist + printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" + local str="Creating group 'pihole'" + # if group can be created + if groupadd pihole; then printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" + # create and add pihole user to the pihole group + local str="Creating user 'pihole'" + printf "%b %b %s..." "${OVER}" "${INFO}" "${str}" + if useradd -r --no-user-group -g pihole -s /usr/sbin/nologin pihole; then + printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" + else + printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" + fi + else printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${str}" fi From 06de1729525f82da44ba924e8232197877fd613a Mon Sep 17 00:00:00 2001 From: MichaIng Date: Mon, 28 Nov 2022 19:28:51 +0100 Subject: [PATCH 238/638] Skip setcap on installs with systemd since the systemd unit uses "AmbientCapabilities" to grant capabilities. Signed-off-by: MichaIng Signed-off-by: MichaIng --- automated install/basic-install.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bdb354ec79..c715eb526f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1385,11 +1385,6 @@ installConfigs() { if [[ -d '/run/systemd/system' ]]; then install -T -m 0644 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.systemd" '/etc/systemd/system/pihole-FTL.service' - # Set net admin permissions so that FTL can serve DNS, DHCP and IMAP (for DHCPv6). If this does not work, run FTL as root user. - if ! setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip '/usr/bin/pihole-FTL'; then - sed -i '/^User=/d' '/etc/systemd/system/pihole-FTL.service' - fi - # Remove init.d service if present if [[ -e '/etc/init.d/pihole-FTL' ]]; then rm '/etc/init.d/pihole-FTL' From e0e0baf0766a6aff5f98cae94d15caff86bf6154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 4 Dec 2022 09:32:23 +0100 Subject: [PATCH 239/638] Install wheel before other python packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index daa18c8578..7a4cc9b75a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -70,7 +70,7 @@ jobs: python-version: "3.10" - name: Install dependencies - run: pip install -r test/requirements.txt + run: pip install wheel && pip install -r test/requirements.txt - name: Test with tox run: tox -c test/tox.${DISTRO}.ini From 6b146ed2d1a2e94ebb9a3882facdc46ebe884af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 5 Dec 2022 23:13:24 +0100 Subject: [PATCH 240/638] Use two-step approach MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a4cc9b75a..45c44e24e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -69,8 +69,11 @@ jobs: with: python-version: "3.10" + - name: Install wheel + run: pip install wheel + - name: Install dependencies - run: pip install wheel && pip install -r test/requirements.txt + run: pip install -r test/requirements.txt - name: Test with tox run: tox -c test/tox.${DISTRO}.ini From f713b14ba09cafa489593da07a5f3ddf66b813f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 8 Dec 2022 09:49:02 +0100 Subject: [PATCH 241/638] Cleanup if startup failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Templates/pihole-FTL.service | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 15096972df..dc7649e7a6 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -23,6 +23,11 @@ is_running() { return 1 } +cleanup() { + # Run post-stop script, which does cleanup among runtime files + sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-poststop.sh" +} + # Start the service start() { @@ -33,10 +38,15 @@ start() { sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-prestart.sh" if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then - su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole || exit $? + su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole || ec=$? else echo "Warning: Starting pihole-FTL as root because setting capabilities is not supported on this system" - /usr/bin/pihole-FTL || exit $? + /usr/bin/pihole-FTL || ec=$? + fi + # Cleanup if startup failed + if [ -n "${ec}" ] && [ "${ec}" != 0 ]; then + cleanup + exit $ec fi echo fi @@ -65,8 +75,7 @@ stop() { else echo "Not running" fi - # Run post-stop script, which does cleanup among runtime files - sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-poststop.sh" + cleanup echo } @@ -84,6 +93,9 @@ status() { ### main logic ### +# catch sudden termination +trap 'cleanup; exit 1' INT HUP TERM ABRT + # Get FTL's PID file path FTL_PID_FILE="$(getFTLPIDFile)" From 126da094bdaf8374a5f4dac0bb19d987eb2ea819 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 10 Dec 2022 10:00:58 +0000 Subject: [PATCH 242/638] Bump actions/setup-python from 4.3.0 to 4.3.1 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.3.0 to 4.3.1. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.3.0...v4.3.1) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 45c44e24e8..d78f92c8a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -65,7 +65,7 @@ jobs: uses: actions/checkout@v3.1.0 - name: Set up Python 3.10 - uses: actions/setup-python@v4.3.0 + uses: actions/setup-python@v4.3.1 with: python-version: "3.10" From b8eae60fcc6a3ca7b0b91aaf60cded3fb912e162 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 11 Dec 2022 11:39:11 +0000 Subject: [PATCH 243/638] Disable a few commands for Docker. Currently this is done by monkeypatching the the `pihole` file on Docker install, however if someone was to run pihole checkout, these patches are removed. Signed-off-by: Adam Warner --- pihole | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/pihole b/pihole index ca80bff841..a99a37e738 100755 --- a/pihole +++ b/pihole @@ -23,6 +23,9 @@ source "${colfile}" utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" source "${utilsfile}" +versionsfile="/etc/pihole/versions" +source "${versionsfile}" + webpageFunc() { source "${PI_HOLE_SCRIPT_DIR}/webpage.sh" main "$@" @@ -63,14 +66,22 @@ arpFunc() { } updatePiholeFunc() { - shift - "${PI_HOLE_SCRIPT_DIR}"/update.sh "$@" - exit 0 + if [ -n "${DOCKER_VERSION}" ]; then + unsupportedFunc + else + shift + "${PI_HOLE_SCRIPT_DIR}"/update.sh "$@" + exit 0 + fi } reconfigurePiholeFunc() { - /etc/.pihole/automated\ install/basic-install.sh --reconfigure - exit 0; + if [ -n "${DOCKER_VERSION}" ]; then + unsupportedFunc + else + /etc/.pihole/automated\ install/basic-install.sh --reconfigure + exit 0; + fi } updateGravityFunc() { @@ -91,8 +102,12 @@ chronometerFunc() { uninstallFunc() { - "${PI_HOLE_SCRIPT_DIR}"/uninstall.sh - exit 0 + if [ -n "${DOCKER_VERSION}" ]; then + unsupportedFunc + else + "${PI_HOLE_SCRIPT_DIR}"/uninstall.sh + exit 0 + fi } versionFunc() { @@ -429,6 +444,11 @@ updateCheckFunc() { exit 0 } +unsupportedFunc(){ + echo "Function not supported in Docker images" + exit 0 +} + helpFunc() { echo "Usage: pihole [options] Example: 'pihole -w -h' From 4004a93d1a9ba1f927e4ed62c54b033296f0214d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 9 Nov 2022 19:10:37 +0100 Subject: [PATCH 244/638] Don't double check for lines containing no domains in gravity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 14732f3141..9063e7d8c4 100755 --- a/gravity.sh +++ b/gravity.sh @@ -731,13 +731,11 @@ gravity_ParseFileIntoDomains() { # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) # 4) Remove lines containing "/" # 5) Remove leading tabs, spaces, etc. - # 6) Delete lines not matching domain names < "${src}" tr -d '\r' | \ tr '[:upper:]' '[:lower:]' | \ sed 's/\s*#.*//g' | \ sed -r '/(\/).*$/d' | \ - sed -r 's/^.*\s+//g' | \ - sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}" + sed -r 's/^.*\s+//g' > "${destination}" chmod 644 "${destination}" } From 372070ab391660720d345c4a90b489e989ad5fa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 28 Nov 2022 23:33:13 +0100 Subject: [PATCH 245/638] Improve detection of incorrecr lines during gravity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/gravity.sh b/gravity.sh index 9063e7d8c4..a342cb2774 100755 --- a/gravity.sh +++ b/gravity.sh @@ -524,15 +524,20 @@ num_target_lines=0 num_source_lines=0 num_invalid=0 parseList() { - local adlistID="${1}" src="${2}" target="${3}" incorrect_lines + local adlistID="${1}" src="${2}" target="${3}" incorrect_lines sample_incorrect_lines # This sed does the following things: + # 0. Remove all lines containing no domains # 1. Remove all domains containing invalid characters. Valid are: a-z, A-Z, 0-9, dot (.), minus (-), underscore (_) # 2. Append ,adlistID to every line # 3. Remove trailing period (see https://github.com/pi-hole/pi-hole/issues/4701) # 4. Ensures there is a newline on the last line - sed -e "/[^a-zA-Z0-9.\_-]/d;s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${src}" >> "${target}" - # Find (up to) five domains containing invalid characters (see above) - incorrect_lines="$(sed -e "/[^a-zA-Z0-9.\_-]/!d" "${src}" | head -n 5)" + sed -r "/([^\.]+\.)+[^\.]{2,}/!d;/[^a-zA-Z0-9.\_-]/d;s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${src}" >> "${target}" + + # Find lines containing no domains or with invalid characters (see above) + # Remove duplicates and limit to 5 domains + mapfile -t incorrect_lines <<< "$(sed -r "/([^\.]+\.)+[^\.]{2,}/d" < "${src}")" + mapfile -t -O "${#incorrect_lines[@]}" incorrect_lines <<< "$(sed -r "/[^a-zA-Z0-9.\_-]/!d" < "${src}")" + IFS=" " read -r -a sample_incorrect_lines <<< "$(tr ' ' '\n' <<< "${incorrect_lines[@]}" | sort -u | head -n 5| tr '\n' ' ')" local num_target_lines_new num_correct_lines # Get number of lines in source file @@ -551,11 +556,12 @@ parseList() { fi # Display sample of invalid lines if we found some - if [[ -n "${incorrect_lines}" ]]; then + if [ ${#sample_incorrect_lines[@]} -ne 0 ]; then echo " Sample of invalid domains:" - while IFS= read -r line; do - echo " - ${line}" - done <<< "${incorrect_lines}" + for each in "${sample_incorrect_lines[@]}" + do + echo " - ${each}" + done fi } compareLists() { @@ -731,11 +737,13 @@ gravity_ParseFileIntoDomains() { # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) # 4) Remove lines containing "/" # 5) Remove leading tabs, spaces, etc. + # 6) Remove empty lines < "${src}" tr -d '\r' | \ tr '[:upper:]' '[:lower:]' | \ sed 's/\s*#.*//g' | \ sed -r '/(\/).*$/d' | \ - sed -r 's/^.*\s+//g' > "${destination}" + sed -r 's/^.*\s+//g' | \ + sed '/^$/d'> "${destination}" chmod 644 "${destination}" } From 14ab58660306d9f15ee7396ef4992f9eb70539a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 11 Dec 2022 15:12:11 +0100 Subject: [PATCH 246/638] Start counting with 1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gravity.sh b/gravity.sh index a342cb2774..a5c944ce89 100755 --- a/gravity.sh +++ b/gravity.sh @@ -526,11 +526,11 @@ num_invalid=0 parseList() { local adlistID="${1}" src="${2}" target="${3}" incorrect_lines sample_incorrect_lines # This sed does the following things: - # 0. Remove all lines containing no domains - # 1. Remove all domains containing invalid characters. Valid are: a-z, A-Z, 0-9, dot (.), minus (-), underscore (_) - # 2. Append ,adlistID to every line - # 3. Remove trailing period (see https://github.com/pi-hole/pi-hole/issues/4701) - # 4. Ensures there is a newline on the last line + # 1. Remove all lines containing no domains + # 2. Remove all domains containing invalid characters. Valid are: a-z, A-Z, 0-9, dot (.), minus (-), underscore (_) + # 3. Append ,adlistID to every line + # 4. Remove trailing period (see https://github.com/pi-hole/pi-hole/issues/4701) + # 5. Ensures there is a newline on the last line sed -r "/([^\.]+\.)+[^\.]{2,}/!d;/[^a-zA-Z0-9.\_-]/d;s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${src}" >> "${target}" # Find lines containing no domains or with invalid characters (see above) From 67f04787d6fc687809bc07d2d69e07ac8a265456 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 14:39:06 -0300 Subject: [PATCH 247/638] Only compare OS versions if `dig` was successful Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 63 ++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3cd782bfa7..979f5fb39d 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -394,41 +394,46 @@ os_check() { # Extract dig response response="${cmdResult%%$'\n'*}" - IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') - for distro_and_versions in "${supportedOS[@]}" - do - distro_part="${distro_and_versions%%=*}" - versions_part="${distro_and_versions##*=}" - - if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then - valid_os=true - IFS="," read -r -a supportedVer <<<"${versions_part}" - for version in "${supportedVer[@]}" - do - if [[ "${detected_version}" =~ $version ]]; then - valid_version=true - break - fi - done - break - fi - done - log_write "${INFO} dig return code: ${digReturnCode}" log_write "${INFO} dig response: ${response}" - if [ "$valid_os" = true ]; then - log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}" + if [ "${response}" -ne 0 ]; then + log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" + log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" + else + IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') + for distro_and_versions in "${supportedOS[@]}" + do + distro_part="${distro_and_versions%%=*}" + versions_part="${distro_and_versions##*=}" + + if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then + valid_os=true + IFS="," read -r -a supportedVer <<<"${versions_part}" + for version in "${supportedVer[@]}" + do + if [[ "${detected_version}" =~ $version ]]; then + valid_version=true + break + fi + done + break + fi + done + + if [ "$valid_os" = true ]; then + log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}" - if [ "$valid_version" = true ]; then - log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}" + if [ "$valid_version" = true ]; then + log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}" + else + log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" + log_write "${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + fi else - log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" + log_write "${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi - else - log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi } From b4349b41ce88beeeabadc212cf05dd01bceb6f18 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 15:42:36 -0300 Subject: [PATCH 248/638] Use the correct variable `digReturnCode` also use INFO instead of CROSS, because it's not an error. Signed-off-by: RD WebDesign --- 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 979f5fb39d..174478735a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -397,8 +397,8 @@ os_check() { log_write "${INFO} dig return code: ${digReturnCode}" log_write "${INFO} dig response: ${response}" - if [ "${response}" -ne 0 ]; then - log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" + if [ "${digReturnCode}" -ne 0 ]; then + log_write "${INFO} Distro: ${COL_RED}${detected_os^}${COL_NC}" log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" else IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') From 8c2f56b0e6b6f65189af942b7fabb78610c49277 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 17:38:38 -0300 Subject: [PATCH 249/638] Imporving the output from `os_check()` function - add red color to dig errors - reorder some output lines - add "Distro and version supported" on success Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 174478735a..f370bd9f02 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -394,12 +394,11 @@ os_check() { # Extract dig response response="${cmdResult%%$'\n'*}" - log_write "${INFO} dig return code: ${digReturnCode}" - log_write "${INFO} dig response: ${response}" - if [ "${digReturnCode}" -ne 0 ]; then - log_write "${INFO} Distro: ${COL_RED}${detected_os^}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" + log_write "${INFO} Distro: ${detected_os^}" + log_write "${CROSS} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" + log_write "${CROSS} dig response: ${response}" + log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" else IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') for distro_and_versions in "${supportedOS[@]}" @@ -421,19 +420,26 @@ os_check() { fi done + local finalmsg if [ "$valid_os" = true ]; then log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}" if [ "$valid_version" = true ]; then log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}" + finalmsg="${TICK} ${COL_GREEN}Distro and version supported${COL_NC}" else log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi else log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi + + # Print dig response and the final check result + log_write "${INFO} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" + log_write "${INFO} dig response: ${response}" + log_write "${finalmsg}" fi } From a2069802426857b5ef788996d824dd6abcbeb3f4 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 20:34:18 -0300 Subject: [PATCH 250/638] Fix parenthesis color Signed-off-by: RD WebDesign --- 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 f370bd9f02..c067682b36 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -429,11 +429,11 @@ os_check() { finalmsg="${TICK} ${COL_GREEN}Distro and version supported${COL_NC}" else log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" - finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi else log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" - finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi # Print dig response and the final check result From 1550f29f06a1925b51d183316f383d52b45e99f6 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Thu, 8 Dec 2022 19:58:00 -0300 Subject: [PATCH 251/638] Use GREEN if dig was successful Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c067682b36..9042e71808 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -437,7 +437,7 @@ os_check() { fi # Print dig response and the final check result - log_write "${INFO} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" + log_write "${INFO} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}" log_write "${INFO} dig response: ${response}" log_write "${finalmsg}" fi From fc83883934fab83cb6ec04978f711ef58701ac6e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 11 Dec 2022 14:31:44 +0000 Subject: [PATCH 252/638] Apply suggestions from code review Co-authored-by: yubiuser Signed-off-by: Adam Warner --- advanced/Scripts/piholeDebug.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 9042e71808..c0264d1ad9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -396,6 +396,7 @@ os_check() { if [ "${digReturnCode}" -ne 0 ]; then log_write "${INFO} Distro: ${detected_os^}" + log_write "${INFO} Version: ${detected_version}" log_write "${CROSS} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" log_write "${CROSS} dig response: ${response}" log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" @@ -437,7 +438,7 @@ os_check() { fi # Print dig response and the final check result - log_write "${INFO} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}" + log_write "${TICK} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}" log_write "${INFO} dig response: ${response}" log_write "${finalmsg}" fi From 095696ec04011f3a275bff049ab9c1857ac238fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 13 Dec 2022 23:01:35 +0100 Subject: [PATCH 253/638] Use github cli to sync master back to development MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/sync-back-to-dev.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index f689ae364c..3a5133f9f7 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -13,15 +13,6 @@ jobs: - name: Checkout uses: actions/checkout@v3.1.0 - name: Opening pull request - id: pull - uses: tretuna/sync-branches@1.4.0 - with: + run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' + env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - FROM_BRANCH: 'master' - TO_BRANCH: 'development' - - name: Label the pull request to ignore for release note generation - uses: actions-ecosystem/action-add-labels@v1.1.3 - with: - labels: internal - repo: ${{ github.repository }} - number: ${{ steps.pull.outputs.PULL_REQUEST_NUMBER }} From d245226053b3db5ba820a9fc115aa6a9a4123409 Mon Sep 17 00:00:00 2001 From: Neill Wolf Date: Fri, 16 Dec 2022 15:37:19 -0600 Subject: [PATCH 254/638] set X-XSS-Protection headers to 0 in lighttpd.conf Signed-off-by: Neill Wolf --- advanced/lighttpd.conf.debian | 2 +- advanced/lighttpd.conf.fedora | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 21e48d6c40..7476130368 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -90,7 +90,7 @@ $HTTP["url"] =~ "^/admin/" { setenv.add-response-header = ( "X-Pi-hole" => "The Pi-hole Web interface is working!", "X-Frame-Options" => "DENY", - "X-XSS-Protection" => "1; mode=block", + "X-XSS-Protection" => "0", "X-Content-Type-Options" => "nosniff", "Content-Security-Policy" => "default-src 'self' 'unsafe-inline';", "X-Permitted-Cross-Domain-Policies" => "none", diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 3da62839db..7a6a39c530 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -98,7 +98,7 @@ $HTTP["url"] =~ "^/admin/" { setenv.add-response-header = ( "X-Pi-hole" => "The Pi-hole Web interface is working!", "X-Frame-Options" => "DENY", - "X-XSS-Protection" => "1; mode=block", + "X-XSS-Protection" => "0", "X-Content-Type-Options" => "nosniff", "Content-Security-Policy" => "default-src 'self' 'unsafe-inline';", "X-Permitted-Cross-Domain-Policies" => "none", From e7e7a817bb332361c703ef623c00586cf57940f4 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Thu, 15 Dec 2022 00:31:34 -0500 Subject: [PATCH 255/638] add Fedora 37 to distro-test Signed-off-by: Glenn Strauss --- .github/workflows/test.yml | 1 + test/_fedora_37.Dockerfile | 18 ++++++++++++++++++ test/tox.fedora_37.ini | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/_fedora_37.Dockerfile create mode 100644 test/tox.fedora_37.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d78f92c8a7..82d96524e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,6 +57,7 @@ jobs: centos_9, fedora_35, fedora_36, + fedora_37, ] env: DISTRO: ${{matrix.distro}} diff --git a/test/_fedora_37.Dockerfile b/test/_fedora_37.Dockerfile new file mode 100644 index 0000000000..b4f939ba39 --- /dev/null +++ b/test/_fedora_37.Dockerfile @@ -0,0 +1,18 @@ +FROM fedora:37 +RUN dnf install -y git initscripts + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.fedora_37.ini b/test/tox.fedora_37.ini new file mode 100644 index 0000000000..d6f445335d --- /dev/null +++ b/test/tox.fedora_37.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _fedora_37.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From 661433c1158843fc19f0166ef1a1bd69bcdd8277 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 17 Dec 2022 10:00:40 +0000 Subject: [PATCH 256/638] Bump actions/checkout from 3.1.0 to 3.2.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.1.0...v3.2.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b0ebb90e3d..41fd5b1b38 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 3a5133f9f7..889f9622b4 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -11,7 +11,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d78f92c8a7..7195144459 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 - name: Check scripts in repository are executable run: | @@ -62,7 +62,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.1.0 + uses: actions/checkout@v3.2.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.3.1 From 7562376373b6550a8f15668f99af3bb5c167f50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 12 Dec 2022 22:26:50 +0100 Subject: [PATCH 257/638] Add merge-conflict workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/merge-conflict.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/merge-conflict.yml diff --git a/.github/workflows/merge-conflict.yml b/.github/workflows/merge-conflict.yml new file mode 100644 index 0000000000..5674fca1c2 --- /dev/null +++ b/.github/workflows/merge-conflict.yml @@ -0,0 +1,21 @@ +name: "Check for merge conflicts" +on: + # So that PRs touching the same files as the push are updated + push: + # So that the `dirtyLabel` is removed if conflicts are resolve + # We recommend `pull_request_target` so that github secrets are available. + # In `pull_request` we wouldn't be able to change labels of fork PRs + pull_request_target: + types: [synchronize] + +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: Check if PRs are have merge conflicts + uses: eps1lon/actions-label-merge-conflict@v2.1.0 + with: + dirtyLabel: "PR: Merge Conflict" + repoToken: "${{ secrets.GITHUB_TOKEN }}" + commentOnDirty: "This pull request has conflicts, please resolve those before we can evaluate the pull request." + commentOnClean: "Conflicts have been resolved. A maintainer will review the pull request shortly." From da8893f47709e68f7da62667cf7541c5e4079372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 18 Dec 2022 12:45:14 +0100 Subject: [PATCH 258/638] Try bandaid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 0eb22a1b59..9315800c6f 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,4 +2,4 @@ docker-compose pytest pytest-xdist pytest-testinfra -tox +tox <= 4.0.12 From c8e69c61392f0841b8f1026ceca80874d2d0700c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 18 Dec 2022 14:22:44 +0100 Subject: [PATCH 259/638] Set testenv explicitly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/tox.centos_8.ini | 6 +++--- test/tox.centos_9.ini | 2 +- test/tox.debian_10.ini | 2 +- test/tox.debian_11.ini | 2 +- test/tox.fedora_35.ini | 2 +- test/tox.fedora_36.ini | 2 +- test/tox.ubuntu_20.ini | 2 +- test/tox.ubuntu_22.ini | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini index dc160d2a05..dac10e97e4 100644 --- a/test/tox.centos_8.ini +++ b/test/tox.centos_8.ini @@ -1,8 +1,8 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py +commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.centos_9.ini b/test/tox.centos_9.ini index 633fc5c4d2..aa7009e109 100644 --- a/test/tox.centos_9.ini +++ b/test/tox.centos_9.ini @@ -1,7 +1,7 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _centos_9.Dockerfile -t pytest_pihole:test_container ../ diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini index ef9fa7a061..a012bda4ff 100644 --- a/test/tox.debian_10.ini +++ b/test/tox.debian_10.ini @@ -1,7 +1,7 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ diff --git a/test/tox.debian_11.ini b/test/tox.debian_11.ini index 6d25a0c840..48dc9df1e7 100644 --- a/test/tox.debian_11.ini +++ b/test/tox.debian_11.ini @@ -1,7 +1,7 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_11.Dockerfile -t pytest_pihole:test_container ../ diff --git a/test/tox.fedora_35.ini b/test/tox.fedora_35.ini index 5e90426def..c571a5647c 100644 --- a/test/tox.fedora_35.ini +++ b/test/tox.fedora_35.ini @@ -1,7 +1,7 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _fedora_35.Dockerfile -t pytest_pihole:test_container ../ diff --git a/test/tox.fedora_36.ini b/test/tox.fedora_36.ini index 1d250f823c..0cc6f29cef 100644 --- a/test/tox.fedora_36.ini +++ b/test/tox.fedora_36.ini @@ -1,7 +1,7 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _fedora_36.Dockerfile -t pytest_pihole:test_container ../ diff --git a/test/tox.ubuntu_20.ini b/test/tox.ubuntu_20.ini index 4ae79a0cb1..88ee0b541b 100644 --- a/test/tox.ubuntu_20.ini +++ b/test/tox.ubuntu_20.ini @@ -1,7 +1,7 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ diff --git a/test/tox.ubuntu_22.ini b/test/tox.ubuntu_22.ini index 3ddf7eca5c..cb5527aba3 100644 --- a/test/tox.ubuntu_22.ini +++ b/test/tox.ubuntu_22.ini @@ -1,7 +1,7 @@ [tox] envlist = py3 -[testenv] +[testenv:py3] allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ From dafc9983f56177b4c831d193ceaf8dcf13fadd5b Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Fri, 7 Aug 2020 23:53:14 -0400 Subject: [PATCH 260/638] lighttpd include external.conf using file glob lighttpd 1.4.40 and later support 'include' using file glob (The prior code for compatibility was presumably for Debian Jessie and earlier, now obsolete. Debian Stretch -- currently oldstable -- ships with lighttpd 1.4.45) Signed-off-by: Glenn Strauss --- advanced/lighttpd.conf.debian | 5 ++--- advanced/lighttpd.conf.fedora | 5 ++--- automated install/basic-install.sh | 4 ---- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 7476130368..f57bad2dba 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -67,9 +67,8 @@ mimetype.assign = ( ".woff2" => "font/woff2" ) -# Add user chosen options held in external file -# This uses include_shell instead of an include wildcard for compatibility -include_shell "cat external.conf 2>/dev/null" +# Add user chosen options held in (optional) external file +include "external*.conf" # default listening port for IPv6 falls back to the IPv4 port include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 7a6a39c530..34056672c1 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -68,9 +68,8 @@ mimetype.assign = ( ".woff2" => "font/woff2" ) -# Add user chosen options held in external file -# This uses include_shell instead of an include wildcard for compatibility -include_shell "cat external.conf 2>/dev/null" +# Add user chosen options held in (optional) external file +include "external*.conf" # default listening port for IPv6 falls back to the IPv4 port #include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 50ce584dda..7462e2f09a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1412,10 +1412,6 @@ installConfigs() { fi # and copy in the config file Pi-hole needs install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" - # Make sure the external.conf file exists, as lighttpd v1.4.50 crashes without it - if [ ! -f /etc/lighttpd/external.conf ]; then - install -m 644 /dev/null /etc/lighttpd/external.conf - fi # If there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config if [[ -f "${PI_HOLE_404_DIR}/custom.php" ]]; then sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"\/pihole\/custom\.php"/' "${lighttpdConfig}" From 62bf9957dc39f6bfbb1fb4d493c657889793cdf1 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Fri, 7 Aug 2020 23:57:20 -0400 Subject: [PATCH 261/638] lighttpd conf: collect ^/admin/ conditions move a sub-condition to be a nested condition under ^/admin/ Signed-off-by: Glenn Strauss --- advanced/lighttpd.conf.debian | 18 +++++++++--------- advanced/lighttpd.conf.fedora | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index f57bad2dba..cb52cf3829 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -95,17 +95,17 @@ $HTTP["url"] =~ "^/admin/" { "X-Permitted-Cross-Domain-Policies" => "none", "Referrer-Policy" => "same-origin" ) -} -# Block . files from being served, such as .git, .github, .gitignore -$HTTP["url"] =~ "^/admin/\.(.*)" { - url.access-deny = ("") -} + # Block . files from being served, such as .git, .github, .gitignore + $HTTP["url"] =~ "^/admin/\." { + url.access-deny = ("") + } -# allow teleporter and API qr code iframe on settings page -$HTTP["url"] =~ "/(teleporter|api_token)\.php$" { - $HTTP["referer"] =~ "/admin/settings\.php" { - setenv.add-response-header = ( "X-Frame-Options" => "SAMEORIGIN" ) + # allow teleporter and API qr code iframe on settings page + $HTTP["url"] =~ "/(teleporter|api_token)\.php$" { + $HTTP["referer"] =~ "/admin/settings\.php" { + setenv.add-response-header = ( "X-Frame-Options" => "SAMEORIGIN" ) + } } } diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 34056672c1..39c665f57b 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -103,17 +103,17 @@ $HTTP["url"] =~ "^/admin/" { "X-Permitted-Cross-Domain-Policies" => "none", "Referrer-Policy" => "same-origin" ) -} -# Block . files from being served, such as .git, .github, .gitignore -$HTTP["url"] =~ "^/admin/\.(.*)" { - url.access-deny = ("") -} + # Block . files from being served, such as .git, .github, .gitignore + $HTTP["url"] =~ "^/admin/\." { + url.access-deny = ("") + } -# allow teleporter and API qr code iframe on settings page -$HTTP["url"] =~ "/(teleporter|api_token)\.php$" { - $HTTP["referer"] =~ "/admin/settings\.php" { - setenv.add-response-header = ( "X-Frame-Options" => "SAMEORIGIN" ) + # allow teleporter and API qr code iframe on settings page + $HTTP["url"] =~ "/(teleporter|api_token)\.php$" { + $HTTP["referer"] =~ "/admin/settings\.php" { + setenv.add-response-header = ( "X-Frame-Options" => "SAMEORIGIN" ) + } } } From 08c7691d1eef900feeda8a8fa2353a8aef5280a6 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 14 Dec 2022 21:18:04 -0500 Subject: [PATCH 262/638] lighttpd pihole-admin.conf for admin interface Signed-off-by: Glenn Strauss --- advanced/lighttpd.conf.debian | 35 -------------- advanced/lighttpd.conf.fedora | 35 +------------- advanced/pihole-admin.conf | 75 ++++++++++++++++++++++++++++++ automated install/basic-install.sh | 14 ++++++ automated install/uninstall.sh | 13 ++++++ 5 files changed, 103 insertions(+), 69 deletions(-) create mode 100644 advanced/pihole-admin.conf diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index cb52cf3829..706b00a879 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -76,38 +76,3 @@ include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port # Prevent Lighttpd from enabling Let's Encrypt SSL for every blocked domain #include_shell "/usr/share/lighttpd/include-conf-enabled.pl" include_shell "find /etc/lighttpd/conf-enabled -name '*.conf' -a ! -name 'letsencrypt.conf' -printf 'include \"%p\"\n' 2>/dev/null" - -# If the URL starts with /admin, it is the Web interface -$HTTP["url"] =~ "^/admin/" { - # X-Pi-hole is a response header for debugging using curl -I - # X-Frame-Options prevents clickjacking attacks and helps ensure your content is not embedded into other sites via < frame >, < iframe > or < object >. - # X-XSS-Protection sets the configuration for the cross-site scripting filters built into most browsers. This is important because it tells the browser to block the response if a malicious script has been inserted from a user input. - # X-Content-Type-Options stops a browser from trying to MIME-sniff the content type and forces it to stick with the declared content-type. This is important because the browser will only load external resources if their content-type matches what is expected, and not malicious hidden code. - # Content-Security-Policy tells the browser where resources are allowed to be loaded and if it’s allowed to parse/run inline styles or Javascript. This is important because it prevents content injection attacks, such as Cross Site Scripting (XSS). - # X-Permitted-Cross-Domain-Policies is an XML document that grants a web client, such as Adobe Flash Player or Adobe Acrobat (though not necessarily limited to these), permission to handle data across domains. - # Referrer-Policy allows control/restriction of the amount of information present in the referral header for links away from your page—the URL path or even if the header is sent at all. - setenv.add-response-header = ( - "X-Pi-hole" => "The Pi-hole Web interface is working!", - "X-Frame-Options" => "DENY", - "X-XSS-Protection" => "0", - "X-Content-Type-Options" => "nosniff", - "Content-Security-Policy" => "default-src 'self' 'unsafe-inline';", - "X-Permitted-Cross-Domain-Policies" => "none", - "Referrer-Policy" => "same-origin" - ) - - # Block . files from being served, such as .git, .github, .gitignore - $HTTP["url"] =~ "^/admin/\." { - url.access-deny = ("") - } - - # allow teleporter and API qr code iframe on settings page - $HTTP["url"] =~ "/(teleporter|api_token)\.php$" { - $HTTP["referer"] =~ "/admin/settings\.php" { - setenv.add-response-header = ( "X-Frame-Options" => "SAMEORIGIN" ) - } - } -} - -# Default expire header -expire.url = ( "" => "access plus 0 seconds" ) diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 39c665f57b..05dfc7ec08 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -85,37 +85,4 @@ fastcgi.server = ( ) ) -# If the URL starts with /admin, it is the Web interface -$HTTP["url"] =~ "^/admin/" { - # X-Pi-hole is a response header for debugging using curl -I - # X-Frame-Options prevents clickjacking attacks and helps ensure your content is not embedded into other sites via < frame >, < iframe > or < object >. - # X-XSS-Protection sets the configuration for the cross-site scripting filters built into most browsers. This is important because it tells the browser to block the response if a malicious script has been inserted from a user input. - # X-Content-Type-Options stops a browser from trying to MIME-sniff the content type and forces it to stick with the declared content-type. This is important because the browser will only load external resources if their content-type matches what is expected, and not malicious hidden code. - # Content-Security-Policy tells the browser where resources are allowed to be loaded and if it’s allowed to parse/run inline styles or Javascript. This is important because it prevents content injection attacks, such as Cross Site Scripting (XSS). - # X-Permitted-Cross-Domain-Policies is an XML document that grants a web client, such as Adobe Flash Player or Adobe Acrobat (though not necessarily limited to these), permission to handle data across domains. - # Referrer-Policy allows control/restriction of the amount of information present in the referral header for links away from your page—the URL path or even if the header is sent at all. - setenv.add-response-header = ( - "X-Pi-hole" => "The Pi-hole Web interface is working!", - "X-Frame-Options" => "DENY", - "X-XSS-Protection" => "0", - "X-Content-Type-Options" => "nosniff", - "Content-Security-Policy" => "default-src 'self' 'unsafe-inline';", - "X-Permitted-Cross-Domain-Policies" => "none", - "Referrer-Policy" => "same-origin" - ) - - # Block . files from being served, such as .git, .github, .gitignore - $HTTP["url"] =~ "^/admin/\." { - url.access-deny = ("") - } - - # allow teleporter and API qr code iframe on settings page - $HTTP["url"] =~ "/(teleporter|api_token)\.php$" { - $HTTP["referer"] =~ "/admin/settings\.php" { - setenv.add-response-header = ( "X-Frame-Options" => "SAMEORIGIN" ) - } - } -} - -# Default expire header -expire.url = ( "" => "access plus 0 seconds" ) +include "/etc/lighttpd/conf.d/pihole-admin.conf" diff --git a/advanced/pihole-admin.conf b/advanced/pihole-admin.conf new file mode 100644 index 0000000000..7d3218317d --- /dev/null +++ b/advanced/pihole-admin.conf @@ -0,0 +1,75 @@ +# Pi-hole: A black hole for Internet advertisements +# (c) 2017 Pi-hole, LLC (https://pi-hole.net) +# Network-wide ad blocking via your own hardware. +# +# Lighttpd config for Pi-hole +# +# This file is copyright under the latest version of the EUPL. +# Please see LICENSE file for your rights under this license. + +############################################################################### +# FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE INSTALL/UPDATE PROCEDURE. # +# ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # +############################################################################### + +$HTTP["url"] =~ "^/admin/" { + server.document-root = "/var/www/html" + server.stream-response-body = 1 + fastcgi.server = ( + ".php" => ( + "localhost" => ( + "socket" => "/tmp/pihole-php-fastcgi.socket", + "bin-path" => "/usr/bin/php-cgi", + "min-procs" => 0, + "max-procs" => 1, + ) + ) + ) + + # X-Pi-hole is a response header for debugging using curl -I + # X-Frame-Options prevents clickjacking attacks and helps ensure your content is not embedded into other sites via < frame >, < iframe > or < object >. + # X-XSS-Protection sets the configuration for the cross-site scripting filters built into most browsers. This is important because it tells the browser to block the response if a malicious script has been inserted from a user input. (deprecated; disabled) + # X-Content-Type-Options stops a browser from trying to MIME-sniff the content type and forces it to stick with the declared content-type. This is important because the browser will only load external resources if their content-type matches what is expected, and not malicious hidden code. + # Content-Security-Policy tells the browser where resources are allowed to be loaded and if it’s allowed to parse/run inline styles or Javascript. This is important because it prevents content injection attacks, such as Cross Site Scripting (XSS). + # X-Permitted-Cross-Domain-Policies is an XML document that grants a web client, such as Adobe Flash Player or Adobe Acrobat (though not necessarily limited to these), permission to handle data across domains. + # Referrer-Policy allows control/restriction of the amount of information present in the referral header for links away from your page—the URL path or even if the header is sent at all. + setenv.add-response-header = ( + "X-Pi-hole" => "The Pi-hole Web interface is working!", + "X-Frame-Options" => "DENY", + "X-XSS-Protection" => "0", + "X-Content-Type-Options" => "nosniff", + "Content-Security-Policy" => "default-src 'self' 'unsafe-inline';", + "X-Permitted-Cross-Domain-Policies" => "none", + "Referrer-Policy" => "same-origin" + ) + + # Block . files from being served, such as .git, .github, .gitignore + $HTTP["url"] =~ "^/admin/\." { + url.access-deny = ("") + } + + # allow teleporter and API qr code iframe on settings page + $HTTP["url"] =~ "/(teleporter|api_token)\.php$" { + $HTTP["referer"] =~ "/admin/settings\.php" { + setenv.set-response-header = ( "X-Frame-Options" => "SAMEORIGIN" ) + } + } +} +else $HTTP["url"] == "/admin" { + url.redirect = ("" => "/admin/") +} + +$HTTP["host"] == "pi.hole" { + $HTTP["url"] == "/" { + url.redirect = ("" => "/admin/") + } +} + +# (safe to enable after pihole ceases to support Debian 10 (Buster)) +# (For lighttpd 1.4.56+ which ignores duplicated server.modules entries) +#server.modules += ( +# "mod_access", +# "mod_redirect", +# "mod_fastcgi", +# "mod_setenv", +#) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7462e2f09a..39d7ced41c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1416,6 +1416,20 @@ installConfigs() { if [[ -f "${PI_HOLE_404_DIR}/custom.php" ]]; then sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"\/pihole\/custom\.php"/' "${lighttpdConfig}" fi + # Copy the config file to include for pihole admin interface + if [[ -d "/etc/lighttpd/conf.d" ]]; then + install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/pihole-admin.conf /etc/lighttpd/conf.d/pihole-admin.conf + elif [[ -d "/etc/lighttpd/conf-available" ]]; then + conf=/etc/lighttpd/conf-available/15-pihole-admin.conf + install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/pihole-admin.conf $conf + if is_command lighty-enable-mod ; then + lighty-enable-mod pihole-admin > /dev/null || true + fi + else + # lighttpd config include dir not found + printf " %b Warning: lighttpd config include dir not found\\n" "${INFO}" + printf " Please manually install pihole-admin.conf\\n" + fi # Make the directories if they do not exist and set the owners mkdir -p /run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 0b516d0f26..541c0a7615 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -139,6 +139,19 @@ removeNoPurge() { ${SUDO} rm /etc/lighttpd/external.conf fi + # Fedora-based + if [[ -f /etc/lighttpd/conf.d/pihole-admin.conf ]]; then + ${SUDO} rm /etc/lighttpd/conf.d/pihole-admin.conf + fi + + # Debian-based + if [[ -f /etc/lighttpd/conf-available/pihole-admin.conf ]]; then + if is_command lighty-disable-mod ; then + ${SUDO} lighty-disable-mod pihole-admin > /dev/null || true + fi + ${SUDO} rm /etc/lighttpd/conf-available/15-pihole-admin.conf + fi + echo -e " ${TICK} Removed lighttpd configs" fi From 78f9e3842536d14f04acc093540c54b83fbcbd1e Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Sun, 18 Dec 2022 00:58:08 -0500 Subject: [PATCH 263/638] lighttpd: test for /etc/lighttpd/conf*/pihole-admin.conf Signed-off-by: Glenn Strauss --- test/test_any_automated_install.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 2ea619f704..0b039593d8 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -289,6 +289,24 @@ def test_installPihole_fresh_install_readableFiles(host): check_lighttpd = test_cmd.format("r", "/etc/lighttpd/lighttpd.conf", piholeuser) actual_rc = host.run(check_lighttpd).rc assert exit_status_success == actual_rc + # check readable /etc/lighttpd/conf*/pihole-admin.conf + check_lighttpd = test_cmd.format("r", "/etc/lighttpd/conf.d", piholeuser) + if host.run(check_lighttpd).rc == exit_status_success: + check_lighttpd = test_cmd.format( + "r", "/etc/lighttpd/conf.d/pihole-admin.conf", piholeuser + ) + actual_rc = host.run(check_lighttpd).rc + assert exit_status_success == actual_rc + else: + check_lighttpd = test_cmd.format( + "r", "/etc/lighttpd/conf-available", piholeuser + ) + if host.run(check_lighttpd).rc == exit_status_success: + check_lighttpd = test_cmd.format( + "r", "/etc/lighttpd/conf-available/15-pihole-admin.conf", piholeuser + ) + actual_rc = host.run(check_lighttpd).rc + assert exit_status_success == actual_rc # check readable and executable manpages if maninstalled is True: check_man = test_cmd.format("x", "/usr/local/share/man", piholeuser) From 0d5d3a1b2209bacbbdb09c069ce81cf2f3dafb28 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 14 Dec 2022 22:22:52 -0500 Subject: [PATCH 264/638] lighttpd: remove obsolete exclusion of letsencrypt.conf Signed-off-by: Glenn Strauss --- advanced/lighttpd.conf.debian | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 706b00a879..0bc1ae11a3 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -72,7 +72,4 @@ include "external*.conf" # default listening port for IPv6 falls back to the IPv4 port include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port - -# Prevent Lighttpd from enabling Let's Encrypt SSL for every blocked domain -#include_shell "/usr/share/lighttpd/include-conf-enabled.pl" -include_shell "find /etc/lighttpd/conf-enabled -name '*.conf' -a ! -name 'letsencrypt.conf' -printf 'include \"%p\"\n' 2>/dev/null" +include "/etc/lighttpd/conf-enabled/*.conf" From c6342ed84c6b433019fb3277df662e0c02c22381 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Mon, 19 Dec 2022 02:52:29 -0500 Subject: [PATCH 265/638] lighttpd: do not overwrite /etc/lighttpd/lighttpd.conf Signed-off-by: Glenn Strauss --- advanced/pihole-admin.conf | 10 +--- automated install/basic-install.sh | 74 +++++++++++++++++------------- automated install/uninstall.sh | 11 +++++ test/test_any_automated_install.py | 2 +- 4 files changed, 57 insertions(+), 40 deletions(-) diff --git a/advanced/pihole-admin.conf b/advanced/pihole-admin.conf index 7d3218317d..8e3508da0e 100644 --- a/advanced/pihole-admin.conf +++ b/advanced/pihole-admin.conf @@ -65,11 +65,5 @@ $HTTP["host"] == "pi.hole" { } } -# (safe to enable after pihole ceases to support Debian 10 (Buster)) -# (For lighttpd 1.4.56+ which ignores duplicated server.modules entries) -#server.modules += ( -# "mod_access", -# "mod_redirect", -# "mod_fastcgi", -# "mod_setenv", -#) +# (keep this on one line for basic-install.sh filtering during install) +server.modules += ( "mod_access", "mod_redirect", "mod_fastcgi", "mod_setenv" ) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 39d7ced41c..a65bbdc787 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1401,42 +1401,63 @@ installConfigs() { # If the user chose to install the dashboard, if [[ "${INSTALL_WEB_SERVER}" == true ]]; then - # and if the Web server conf directory does not exist, - if [[ ! -d "/etc/lighttpd" ]]; then - # make it and set the owners - install -d -m 755 -o "${USER}" -g root /etc/lighttpd - # Otherwise, if the config file already exists - elif [[ -f "${lighttpdConfig}" ]]; then - # back up the original - mv "${lighttpdConfig}"{,.orig} - fi - # and copy in the config file Pi-hole needs - install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" - # If there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config - if [[ -f "${PI_HOLE_404_DIR}/custom.php" ]]; then - sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"\/pihole\/custom\.php"/' "${lighttpdConfig}" + if grep -q -F "FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then + # Attempt to preserve backwards compatibility with older versions + install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" + # If there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config + if [[ -f "${PI_HOLE_404_DIR}/custom.php" ]]; then + sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"\/pihole\/custom\.php"/' "${lighttpdConfig}" + fi + # Make the directories if they do not exist and set the owners + mkdir -p /run/lighttpd + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd + mkdir -p /var/cache/lighttpd/compress + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress + mkdir -p /var/cache/lighttpd/uploads + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/uploads fi # Copy the config file to include for pihole admin interface if [[ -d "/etc/lighttpd/conf.d" ]]; then install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/pihole-admin.conf /etc/lighttpd/conf.d/pihole-admin.conf + if grep -q -F 'include "/etc/lighttpd/conf.d/pihole-admin.conf"' "${lighttpdConfig}"; then + : + else + echo 'include "/etc/lighttpd/conf.d/pihole-admin.conf"' >> "${lighttpdConfig}" + fi + # Avoid some warnings trace from lighttpd, which might break tests + conf=/etc/lighttpd/conf.d/pihole-admin.conf + if lighttpd -f "${lighttpdConfig}" -tt 2>&1 | grep -q -F "WARNING: unknown config-key: dir-listing\."; then + echo '# Avoid some warnings trace from lighttpd, which might break tests' >> $conf + echo 'server.modules += ( "mod_dirlisting" )' >> $conf + fi + if lighttpd -f "${lighttpdConfig}" -tt 2>&1 | grep -q -F "warning: please use server.use-ipv6"; then + echo '# Avoid some warnings trace from lighttpd, which might break tests' >> $conf + echo 'server.use-ipv6 := "disable"' >> $conf + fi elif [[ -d "/etc/lighttpd/conf-available" ]]; then conf=/etc/lighttpd/conf-available/15-pihole-admin.conf install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/pihole-admin.conf $conf + # disable server.modules += ( ... ) in $conf to avoid module dups + # (needed until Debian 10 no longer supported by pi-hole) + # (server.modules duplication is ignored in lighttpd 1.4.56+) + if awk '!/^server\.modules/{print}' $conf > $conf.$$ && mv $conf.$$ $conf; then + : + else + rm $conf.$$ + fi + chmod 644 $conf if is_command lighty-enable-mod ; then - lighty-enable-mod pihole-admin > /dev/null || true + lighty-enable-mod pihole-admin access redirect fastcgi setenv > /dev/null || true + else + # Otherwise, show info about installing them + printf " %b Warning: 'lighty-enable-mod' utility not found\\n" "${INFO}" + printf " Please ensure fastcgi is enabled if you experience issues\\n" fi else # lighttpd config include dir not found printf " %b Warning: lighttpd config include dir not found\\n" "${INFO}" printf " Please manually install pihole-admin.conf\\n" fi - # Make the directories if they do not exist and set the owners - mkdir -p /run/lighttpd - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd - mkdir -p /var/cache/lighttpd/compress - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress - mkdir -p /var/cache/lighttpd/uploads - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/uploads fi } @@ -1913,15 +1934,6 @@ installPihole() { # Give lighttpd access to the pihole group so the web interface can # manage the gravity.db database usermod -a -G pihole ${LIGHTTPD_USER} - # If the lighttpd command is executable, - if is_command lighty-enable-mod ; then - # enable fastcgi and fastcgi-php - lighty-enable-mod fastcgi fastcgi-php > /dev/null || true - else - # Otherwise, show info about installing them - printf " %b Warning: 'lighty-enable-mod' utility not found\\n" "${INFO}" - printf " Please ensure fastcgi is enabled if you experience issues\\n" - fi fi fi # Install base files and web interface diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 541c0a7615..c36027fced 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -131,6 +131,7 @@ removeNoPurge() { fi if package_check lighttpd > /dev/null; then + # Attempt to preserve backwards compatibility with older versions if [[ -f /etc/lighttpd/lighttpd.conf.orig ]]; then ${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf fi @@ -142,6 +143,16 @@ removeNoPurge() { # Fedora-based if [[ -f /etc/lighttpd/conf.d/pihole-admin.conf ]]; then ${SUDO} rm /etc/lighttpd/conf.d/pihole-admin.conf + conf=/etc/lighttpd/lighttpd.conf + tconf=/tmp/lighttpd.conf.$$ + if awk '!/^include "\/etc\/lighttpd\/conf\.d\/pihole-admin\.conf"$/{print}' \ + $conf > $tconf && mv $tconf $conf; then + : + else + rm $tconf + fi + ${SUDO} chown root:root $conf + ${SUDO} chmod 644 $conf fi # Debian-based diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 0b039593d8..98a9f8f75b 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -416,7 +416,7 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): usergroup="${{LIGHTTPD_USER}}:${{LIGHTTPD_GROUP}}", chmodarg="{{}}", config="/etc/lighttpd/lighttpd.conf", - run="/var/run/lighttpd", + run="/run/lighttpd", cache="/var/cache/lighttpd", uploads="/var/cache/lighttpd/uploads", compress="/var/cache/lighttpd/compress", From 539f9d4da07281cb25683dec9edafe7eb0d89e4c Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 14 Dec 2022 22:26:17 -0500 Subject: [PATCH 266/638] lighttpd: remove pihole block page error handler remove obsolete pihole block page error handler x-ref: Remove the advanced functionality of the 404 page (Blockpage) https://github.com/pi-hole/pi-hole/pull/3910 Signed-off-by: Glenn Strauss --- advanced/lighttpd.conf.debian | 1 - advanced/lighttpd.conf.fedora | 1 - 2 files changed, 2 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 0bc1ae11a3..06c284fe5f 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -26,7 +26,6 @@ server.modules = ( ) server.document-root = "/var/www/html" -server.error-handler-404 = "/pihole/index.php" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) server.errorlog = "/var/log/lighttpd/error-pihole.log" server.pid-file = "/run/lighttpd.pid" diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 05dfc7ec08..04f3ee0176 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -27,7 +27,6 @@ server.modules = ( ) server.document-root = "/var/www/html" -server.error-handler-404 = "/pihole/index.php" server.upload-dirs = ( "/var/cache/lighttpd/uploads" ) server.errorlog = "/var/log/lighttpd/error-pihole.log" server.pid-file = "/run/lighttpd.pid" From 34f45d011db3ca11ecc4b4de5b2a278d4eb0edba Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Thu, 15 Dec 2022 00:06:37 -0500 Subject: [PATCH 267/638] lighttpd: do not install obsolete 404 handler (/var/www/html/pihole/ dir and contents are still removed in uninstall) (/var/www/html/index.lighttpd.orig is still removed in uninstall) Signed-off-by: Glenn Strauss --- advanced/index.php | 81 ------------------------------ automated install/basic-install.sh | 29 ----------- test/test_any_automated_install.py | 22 -------- 3 files changed, 132 deletions(-) delete mode 100644 advanced/index.php diff --git a/advanced/index.php b/advanced/index.php deleted file mode 100644 index f3f2ce1cac..0000000000 --- a/advanced/index.php +++ /dev/null @@ -1,81 +0,0 @@ - "true") is configured in lighttpd, - // append $serverName to $authorizedHosts - array_push($authorizedHosts, $serverName); -} else if (!empty($_SERVER["VIRTUAL_HOST"])) { - // Append virtual hostname to $authorizedHosts - array_push($authorizedHosts, $_SERVER["VIRTUAL_HOST"]); -} - -// Determine block page type -if ($serverName === "pi.hole" - || (!empty($_SERVER["VIRTUAL_HOST"]) && $serverName === $_SERVER["VIRTUAL_HOST"])) { - // Redirect to Web Interface - header("Location: /admin"); - exit(); -} elseif (filter_var($serverName, FILTER_VALIDATE_IP) || in_array($serverName, $authorizedHosts)) { - // When directly browsing via IP or authorized hostname - // Render splash/landing page based off presence of $landPage file - // Unset variables so as to not be included in $landPage or $splashPage - unset($authorizedHosts); - // If $landPage file is present - if (is_file(getcwd()."/$landPage")) { - unset($serverName, $viewPort); // unset extra variables not to be included in $landpage - include $landPage; - exit(); - } - // If $landPage file was not present, Set Splash Page output - $splashPage = << - - - - - ● $serverName - - - - -
- Pi-hole logo -
-

Pi-hole: Your black hole for Internet advertisements

- Did you mean to go to the admin panel? -
- - -EOT; - exit($splashPage); -} - -header("HTTP/1.1 404 Not Found"); -exit(); -?> diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a65bbdc787..e29afad9cc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -82,7 +82,6 @@ PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update versi PI_HOLE_INSTALL_DIR="/opt/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole" PI_HOLE_BIN_DIR="/usr/local/bin" -PI_HOLE_404_DIR="${webroot}/pihole" FTL_CONFIG_FILE="${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" if [ -z "$useUpdateVars" ]; then useUpdateVars=false @@ -1404,10 +1403,6 @@ installConfigs() { if grep -q -F "FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then # Attempt to preserve backwards compatibility with older versions install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" - # If there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config - if [[ -f "${PI_HOLE_404_DIR}/custom.php" ]]; then - sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"\/pihole\/custom\.php"/' "${lighttpdConfig}" - fi # Make the directories if they do not exist and set the owners mkdir -p /run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd @@ -1708,30 +1703,6 @@ install_dependent_packages() { # Install the Web interface dashboard installPiholeWeb() { - printf "\\n %b Installing 404 page...\\n" "${INFO}" - - local str="Creating directory for 404 page, and copying files" - printf " %b %s..." "${INFO}" "${str}" - # Install the directory - install -d -m 0755 ${PI_HOLE_404_DIR} - # and the 404 handler - install -D -m 644 ${PI_HOLE_LOCAL_REPO}/advanced/index.php ${PI_HOLE_404_DIR}/ - - printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" - - local str="Backing up index.lighttpd.html" - printf " %b %s..." "${INFO}" "${str}" - # If the default index file exists, - if [[ -f "${webroot}/index.lighttpd.html" ]]; then - # back it up - mv ${webroot}/index.lighttpd.html ${webroot}/index.lighttpd.orig - printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" - else - # Otherwise, don't do anything - printf "%b %b %s\\n" "${OVER}" "${INFO}" "${str}" - printf " No default index.lighttpd.html file found... not backing up\\n" - fi - # Install Sudoers file local str="Installing sudoer file" printf "\\n %b %s..." "${INFO}" "${str}" diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 98a9f8f75b..4dcb1737fe 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -129,20 +129,8 @@ def test_installPiholeWeb_fresh_install_no_errors(host): installPiholeWeb """ ) - expected_stdout = info_box + " Installing 404 page..." - assert expected_stdout in installWeb.stdout - expected_stdout = tick_box + ( - " Creating directory for 404 page, " "and copying files" - ) - assert expected_stdout in installWeb.stdout - expected_stdout = info_box + " Backing up index.lighttpd.html" - assert expected_stdout in installWeb.stdout - expected_stdout = "No default index.lighttpd.html file found... " "not backing up" - assert expected_stdout in installWeb.stdout expected_stdout = tick_box + " Installing sudoer file" assert expected_stdout in installWeb.stdout - web_directory = host.run("ls -r /var/www/html/pihole").stdout - assert "index.php" in web_directory def get_directories_recursive(host, directory): @@ -556,16 +544,6 @@ def is_ip(address): return bool(m) if installWebInterface is True: - check_pihole = test_cmd.format("r", webroot + "/pihole", webuser) - actual_rc = host.run(check_pihole).rc - assert exit_status_success == actual_rc - check_pihole = test_cmd.format("x", webroot + "/pihole", webuser) - actual_rc = host.run(check_pihole).rc - assert exit_status_success == actual_rc - # check most important files in $webroot for read permission - check_index = test_cmd.format("r", webroot + "/pihole/index.php", webuser) - actual_rc = host.run(check_index).rc - assert exit_status_success == actual_rc if test_webpage is True: # check webpage for unreadable files noPHPfopen = re.compile( From c59e11a332358dbf8b4a6d67d844a85ca47c9bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 24 Nov 2022 20:53:15 +0100 Subject: [PATCH 268/638] Always set lighttpd config dir permissions 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e29afad9cc..a81ccf0edd 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1399,6 +1399,9 @@ installConfigs() { install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-poststop.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-poststop.sh" # If the user chose to install the dashboard, + # set permissions on /etc/lighttpd/lighttpd.conf so pihole user (other) can read the file + chmod o+x /etc/lighttpd + chmod o+r "${lighttpdConfig}" if [[ "${INSTALL_WEB_SERVER}" == true ]]; then if grep -q -F "FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then # Attempt to preserve backwards compatibility with older versions From 12674c0824e07f321e28dc301d0ff1a8d6ae6f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 22 Dec 2022 22:27:03 +0100 Subject: [PATCH 269/638] Shorten no merge conflict message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/merge-conflict.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/merge-conflict.yml b/.github/workflows/merge-conflict.yml index 5674fca1c2..d86e9cd189 100644 --- a/.github/workflows/merge-conflict.yml +++ b/.github/workflows/merge-conflict.yml @@ -18,4 +18,4 @@ jobs: dirtyLabel: "PR: Merge Conflict" repoToken: "${{ secrets.GITHUB_TOKEN }}" commentOnDirty: "This pull request has conflicts, please resolve those before we can evaluate the pull request." - commentOnClean: "Conflicts have been resolved. A maintainer will review the pull request shortly." + commentOnClean: "Conflicts have been resolved." From 20ad03fe158b1bbe7623cf60030551efb396c4f5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 24 Dec 2022 10:00:43 +0000 Subject: [PATCH 270/638] Bump actions/stale from 6.0.1 to 7.0.0 Bumps [actions/stale](https://github.com/actions/stale) from 6.0.1 to 7.0.0. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v6.0.1...v7.0.0) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index a17d5a94c2..58a2e64767 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v6.0.1 + - uses: actions/stale@v7.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 From 2bb7c05ed1309e2dd4ae283583201ca4000db7d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 24 Dec 2022 10:00:47 +0000 Subject: [PATCH 271/638] Bump actions/setup-python from 4.3.1 to 4.4.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.3.1 to 4.4.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.3.1...v4.4.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f4eaba553a..ab89867b2c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,7 +66,7 @@ jobs: uses: actions/checkout@v3.2.0 - name: Set up Python 3.10 - uses: actions/setup-python@v4.3.1 + uses: actions/setup-python@v4.4.0 with: python-version: "3.10" From 64d0621d2b1f61f31478373f67d0c2ea1a7f6d8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 26 Dec 2022 12:15:16 +0100 Subject: [PATCH 272/638] Update and set test suite python dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/requirements.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/requirements.txt b/test/requirements.txt index 9315800c6f..1972e2ba97 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,6 @@ -docker-compose -pytest -pytest-xdist -pytest-testinfra -tox <= 4.0.12 +docker-compose == 1.29.2 +pytest == 7.2.0 +pytest-xdist == 3.1.0 +pytest-testinfra == 7.0.0 +tox == 4.0.17 + From 14db88d6bb903cea8f2a1c22f92539e7e9c8327a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 26 Dec 2022 12:18:03 +0100 Subject: [PATCH 273/638] Add pip ecosystem to dependabot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f91a9b82ef..e140f79241 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,3 +10,13 @@ updates: target-branch: development reviewers: - "pi-hole/core-maintainers" +- package-ecosystem: pip + directory: "/test" + schedule: + interval: weekly + day: saturday + time: "10:00" + open-pull-requests-limit: 10 + target-branch: development + reviewers: + - "pi-hole/core-maintainers" From b9ebb0524679e6ad1d318023c9f63ee5de8410f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 28 Dec 2022 13:42:57 +0100 Subject: [PATCH 274/638] Set permission after we know the user wants to install the web server 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a81ccf0edd..fcfb240570 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1399,10 +1399,10 @@ installConfigs() { install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL-poststop.sh" "${PI_HOLE_INSTALL_DIR}/pihole-FTL-poststop.sh" # If the user chose to install the dashboard, + if [[ "${INSTALL_WEB_SERVER}" == true ]]; then # set permissions on /etc/lighttpd/lighttpd.conf so pihole user (other) can read the file chmod o+x /etc/lighttpd chmod o+r "${lighttpdConfig}" - if [[ "${INSTALL_WEB_SERVER}" == true ]]; then if grep -q -F "FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then # Attempt to preserve backwards compatibility with older versions install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" From 09977fdfec45511b4942a35ae8d6fad580728048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 28 Dec 2022 14:33:36 +0100 Subject: [PATCH 275/638] Add pihole tail [arg] to man page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- manpages/pihole.8 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/manpages/pihole.8 b/manpages/pihole.8 index 11c21b2844..1cf8ab3554 100644 --- a/manpages/pihole.8 +++ b/manpages/pihole.8 @@ -23,7 +23,7 @@ Pi-hole : A black-hole for internet advertisements .br pihole -r .br -pihole -t +\fBpihole\fR \fB-t\fR [arg] .br pihole -g\fR .br @@ -113,11 +113,15 @@ Available commands and options: Reconfigure or Repair Pi-hole subsystems .br -\fB-t, tail\fR +\fB-t, tail\fR [arg] .br View the live output of the Pi-hole log .br + [arg] Optional argument to filter the log for + (regular expressions are supported) +.br + \fB-a, admin\fR [options] .br From f73b965fcd33c67e8822b572a4aef073feeed473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 29 Dec 2022 21:59:23 +0100 Subject: [PATCH 276/638] Create versions file before sourcing it 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e29afad9cc..cf27e3ace2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2717,12 +2717,12 @@ main() { restart_service pihole-FTL - # Download and compile the aggregated block list - runGravity - # Update local and remote versions via updatechecker /opt/pihole/updatecheck.sh + # Download and compile the aggregated block list + runGravity + if [[ "${useUpdateVars}" == false ]]; then displayFinalMessage "${pw}" fi From 4413224a3142d75cd130b5950885a0b3ea5e61c0 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 30 Dec 2022 17:46:36 -0300 Subject: [PATCH 277/638] Add action to close stale PR Signed-off-by: RD WebDesign --- .github/workflows/stale_pr.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/stale_pr.yml diff --git a/.github/workflows/stale_pr.yml b/.github/workflows/stale_pr.yml new file mode 100644 index 0000000000..da12bb9a6d --- /dev/null +++ b/.github/workflows/stale_pr.yml @@ -0,0 +1,33 @@ +name: Close stale PR +# This action will add a `stale` label and close immediately every PR that meets the following conditions: +# - it is already marked with "merge conflict" label +# - the "merge conflict" label was added more than 30 days before. + +on: + schedule: + - cron: '0 10 * * *' + workflow_dispatch: + +jobs: + stale: + + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - uses: actions/stale@v7.0.0 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + # Do not mark a PR as stale + days-before-stale: -1 + days-before-pr-stale: 30 + days-before-pr-close: 0 + # only run the action on merge conflict PR + any-of-labels: 'PR: Merge Conflict' + exempt-pr-labels: 'internal, never-stale, ON HOLD, WIP' + exempt-all-pr-assignees: true + operations-per-run: 300 + stale-pr-message: '' + close-pr-message: 'Existing merge conflicts have not been addressed. This PR is considered abandoned.' From 9e47b61c8f6e0cf6c478a208b81542ee7ed0633d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 3 Jan 2023 21:20:22 +0100 Subject: [PATCH 278/638] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Templates/pihole-FTL.service | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index dc7649e7a6..460339ae71 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -38,15 +38,16 @@ start() { sh "${PI_HOLE_SCRIPT_DIR}/pihole-FTL-prestart.sh" if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE,CAP_IPC_LOCK,CAP_CHOWN+eip "/usr/bin/pihole-FTL"; then - su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole || ec=$? + su -s /bin/sh -c "/usr/bin/pihole-FTL" pihole else echo "Warning: Starting pihole-FTL as root because setting capabilities is not supported on this system" - /usr/bin/pihole-FTL || ec=$? + /usr/bin/pihole-FTL fi + rc=$? # Cleanup if startup failed - if [ -n "${ec}" ] && [ "${ec}" != 0 ]; then + if [ "${rc}" != 0 ]; then cleanup - exit $ec + exit $rc fi echo fi From d87cad76fb944c7439693f8d19f626de4bf1b2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 4 Jan 2023 12:31:49 +0100 Subject: [PATCH 279/638] Tweak get_directories_recursive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_automated_install.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 4dcb1737fe..c1288287e0 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -136,15 +136,9 @@ def test_installPiholeWeb_fresh_install_no_errors(host): def get_directories_recursive(host, directory): if directory is None: return directory - ls = host.run("ls -d {}".format(directory + "/*/")) - directories = list(filter(bool, ls.stdout.splitlines())) - dirs = directories - for dirval in directories: - dir_rec = get_directories_recursive(host, dirval) - if isinstance(dir_rec, str): - dirs.extend([dir_rec]) - else: - dirs.extend(dir_rec) + # returns all non-hidden subdirs of 'directory' + dirs_raw = host.run("find {} -type d -not -path '*/.*'".format(directory)) + dirs = list(filter(bool, dirs_raw.stdout.splitlines())) return dirs @@ -520,7 +514,7 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): check_admin = test_cmd.format("x", webroot + "/admin", webuser) actual_rc = host.run(check_admin).rc assert exit_status_success == actual_rc - directories = get_directories_recursive(host, webroot + "/admin/*/") + directories = get_directories_recursive(host, webroot + "/admin/") for directory in directories: check_pihole = test_cmd.format("r", directory, webuser) actual_rc = host.run(check_pihole).rc From 2c29b2578253b04901c08410c69608727ae1edb0 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 6 Jan 2023 19:00:55 -0300 Subject: [PATCH 280/638] More detailed comments Signed-off-by: RD WebDesign --- .github/workflows/stale_pr.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale_pr.yml b/.github/workflows/stale_pr.yml index da12bb9a6d..c45e3cb750 100644 --- a/.github/workflows/stale_pr.yml +++ b/.github/workflows/stale_pr.yml @@ -1,7 +1,7 @@ name: Close stale PR # This action will add a `stale` label and close immediately every PR that meets the following conditions: # - it is already marked with "merge conflict" label -# - the "merge conflict" label was added more than 30 days before. +# - there was no update/comment on the PR in the last 30 days. on: schedule: @@ -20,9 +20,11 @@ jobs: - uses: actions/stale@v7.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} - # Do not mark a PR as stale + # Do not automatically mark PR/issue as stale days-before-stale: -1 + # Override 'days-before-stale' for PR only days-before-pr-stale: 30 + # Close PRs immediately, after marking them 'stale' days-before-pr-close: 0 # only run the action on merge conflict PR any-of-labels: 'PR: Merge Conflict' From e05ef73011cb49b91d3fe6cd9618b8f3e6ead2c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Jan 2023 10:00:41 +0000 Subject: [PATCH 281/638] Bump actions/checkout from 3.2.0 to 3.3.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.2.0...v3.3.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 41fd5b1b38..5539cec9e9 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 889f9622b4..89b6323f48 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -11,7 +11,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ab89867b2c..40a92080e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 - name: Check scripts in repository are executable run: | @@ -63,7 +63,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.2.0 + uses: actions/checkout@v3.3.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.4.0 From d349a4640f95ab150de7666a684de2daf4c4984d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 12 Jan 2023 20:24:08 +0100 Subject: [PATCH 282/638] Remoce leftover from query.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/query.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index ae266ec047..d48e9363f5 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -77,7 +77,7 @@ fi # Strip valid options, leaving only the domain and invalid options # This allows users to place the options before or after the domain -options=$(sed -E 's/ ?-(adlists?|all|exact) ?//g' <<< "${options}") +options=$(sed -E 's/ ?-(all|exact) ?//g' <<< "${options}") # Handle remaining options # If $options contain non ASCII characters, convert to punycode From 4a53e56bd2adcdafeeb89b9783cc15bc0aee6fe4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 14 Jan 2023 10:00:35 +0000 Subject: [PATCH 283/638] Bump actions/setup-python from 4.4.0 to 4.5.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.4.0 to 4.5.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.4.0...v4.5.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 40a92080e1..cf84a28a99 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,7 +66,7 @@ jobs: uses: actions/checkout@v3.3.0 - name: Set up Python 3.10 - uses: actions/setup-python@v4.4.0 + uses: actions/setup-python@v4.5.0 with: python-version: "3.10" From c85e4227cf75ae99b0851b487c5baf95967bb67a Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 3 Jan 2023 17:07:34 -0300 Subject: [PATCH 284/638] Remove duplicated `fastcgi.server` config Signed-off-by: RD WebDesign --- advanced/pihole-admin.conf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/advanced/pihole-admin.conf b/advanced/pihole-admin.conf index 8e3508da0e..1cd3da91dd 100644 --- a/advanced/pihole-admin.conf +++ b/advanced/pihole-admin.conf @@ -15,6 +15,7 @@ $HTTP["url"] =~ "^/admin/" { server.document-root = "/var/www/html" server.stream-response-body = 1 + fastcgi.server = ( ".php" => ( "localhost" => ( @@ -22,6 +23,14 @@ $HTTP["url"] =~ "^/admin/" { "bin-path" => "/usr/bin/php-cgi", "min-procs" => 0, "max-procs" => 1, + "bin-environment" => ( + "PHP_FCGI_CHILDREN" => "4", + "PHP_FCGI_MAX_REQUESTS" => "10000", + ), + "bin-copy-environment" => ( + "PATH", "SHELL", "USER" + ), + "broken-scriptfilename" => "enable", ) ) ) From be8f25f8b8ad3ea82f79d090d1734321405820d4 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 10 Jan 2023 15:57:20 -0300 Subject: [PATCH 285/638] Adding errorlog and accesslog options Signed-off-by: RD WebDesign --- advanced/pihole-admin.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/pihole-admin.conf b/advanced/pihole-admin.conf index 1cd3da91dd..2809d33901 100644 --- a/advanced/pihole-admin.conf +++ b/advanced/pihole-admin.conf @@ -12,9 +12,13 @@ # ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # ############################################################################### +server.errorlog := "/var/log/lighttpd/error-pihole.log" + $HTTP["url"] =~ "^/admin/" { server.document-root = "/var/www/html" server.stream-response-body = 1 + accesslog.filename = "/var/log/lighttpd/access-pihole.log" + accesslog.format = "%{%s}t|%h|%V|%r|%s|%b" fastcgi.server = ( ".php" => ( From 318ee3b7d3490550337f60da47f0e9539285030b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 14 Jan 2023 17:54:02 +0000 Subject: [PATCH 286/638] Bump tox from 4.0.17 to 4.2.8 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.0.17 to 4.2.8. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.0.17...4.2.8) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 1972e2ba97..c681142bf7 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.2.0 pytest-xdist == 3.1.0 pytest-testinfra == 7.0.0 -tox == 4.0.17 +tox == 4.2.8 From eb1f2ac01c7dd19ad74973fc87106160289204f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 14 Jan 2023 18:08:40 +0000 Subject: [PATCH 287/638] Bump pytest from 7.2.0 to 7.2.1 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.2.0 to 7.2.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.2.0...7.2.1) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index c681142bf7..e891242c19 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ docker-compose == 1.29.2 -pytest == 7.2.0 +pytest == 7.2.1 pytest-xdist == 3.1.0 pytest-testinfra == 7.0.0 tox == 4.2.8 From c064a6d69a8de215299505e0a12c205524025147 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 15 Jan 2023 03:55:44 -0500 Subject: [PATCH 288/638] add type setting --- advanced/Scripts/webpage.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 61af4fec1a..bf72fd6641 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -502,7 +502,7 @@ ClearSpeedtestData() { cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb } -ChageSpeedTestSchedule() { +ChangeSpeedTestSchedule() { if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" @@ -536,7 +536,7 @@ SpeedtestMode() { } -function UpdateSpeedTestRange() { +UpdateSpeedTestRange() { if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 30 ]; then addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" @@ -544,6 +544,12 @@ function UpdateSpeedTestRange() { fi } +UpdateSpeedTestChartType() { + if [[ "${args[2]}" =~ ^(bar|line)$ ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "${args[2]}" + fi +} + SetCronTab() { # Remove OLD crontab -l >crontab.tmp || true @@ -912,12 +918,13 @@ main() { "audit" ) addAudit "$@";; "clearaudit" ) clearAudit;; "-l" | "privacylevel" ) SetPrivacyLevel;; - "-s" | "speedtest" ) ChageSpeedTestSchedule;; + "-s" | "speedtest" ) ChangeSpeedTestSchedule;; "-sd" ) UpdateSpeedTestRange;; "-sn" ) RunSpeedtestNow;; "-sm" ) SpeedtestMode;; "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; + "-st" ) UpdateSpeedTestChartType;; "addcustomdns" ) AddCustomDNSAddress;; "removecustomdns" ) RemoveCustomDNSAddress;; "addcustomcname" ) AddCustomCNAMERecord;; From e7280b1df5d0907caedeb38f4d69aca2aece7a3e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 15 Jan 2023 05:15:28 -0500 Subject: [PATCH 289/638] properly? handle type --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index bf72fd6641..f1f53b72a4 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -547,6 +547,8 @@ UpdateSpeedTestRange() { UpdateSpeedTestChartType() { if [[ "${args[2]}" =~ ^(bar|line)$ ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "${args[2]}" + else + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "line" fi } From 634e3b0e46a27e0d363614ec62bd98fe0be9c487 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 16 Jan 2023 11:03:21 +0000 Subject: [PATCH 290/638] mod_accesslog was ommited from the list of server modules, which causes a warning to be flashed up in the error log. Enabling this Signed-off-by: Adam Warner --- advanced/pihole-admin.conf | 2 +- automated install/basic-install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/pihole-admin.conf b/advanced/pihole-admin.conf index 2809d33901..60eca5644e 100644 --- a/advanced/pihole-admin.conf +++ b/advanced/pihole-admin.conf @@ -79,4 +79,4 @@ $HTTP["host"] == "pi.hole" { } # (keep this on one line for basic-install.sh filtering during install) -server.modules += ( "mod_access", "mod_redirect", "mod_fastcgi", "mod_setenv" ) +server.modules += ( "mod_access", "mod_accesslog", "mod_redirect", "mod_fastcgi", "mod_setenv" ) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index cf27e3ace2..3b37bf2845 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1442,7 +1442,7 @@ installConfigs() { fi chmod 644 $conf if is_command lighty-enable-mod ; then - lighty-enable-mod pihole-admin access redirect fastcgi setenv > /dev/null || true + lighty-enable-mod pihole-admin access accesslog redirect fastcgi setenv > /dev/null || true else # Otherwise, show info about installing them printf " %b Warning: 'lighty-enable-mod' utility not found\\n" "${INFO}" From bb4698429f7b3971cba869db0d48524131a39a6d Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 16 Jan 2023 13:54:38 +0000 Subject: [PATCH 291/638] Remove fed 35 from test suite Signed-off-by: Adam Warner --- .github/workflows/test.yml | 1 - test/_fedora_35.Dockerfile | 18 ------------------ 2 files changed, 19 deletions(-) delete mode 100644 test/_fedora_35.Dockerfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf84a28a99..ce948e093d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,7 +55,6 @@ jobs: ubuntu_22, centos_8, centos_9, - fedora_35, fedora_36, fedora_37, ] diff --git a/test/_fedora_35.Dockerfile b/test/_fedora_35.Dockerfile deleted file mode 100644 index 83c1765052..0000000000 --- a/test/_fedora_35.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM fedora:35 -RUN dnf install -y git initscripts - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ From afc8241c2c116b5b9b9a371db86c701bc8dd1d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 16 Jan 2023 21:59:21 +0100 Subject: [PATCH 292/638] Remove leftover Fedora 35 tox file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/tox.fedora_35.ini | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 test/tox.fedora_35.ini diff --git a/test/tox.fedora_35.ini b/test/tox.fedora_35.ini deleted file mode 100644 index c571a5647c..0000000000 --- a/test/tox.fedora_35.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py3 - -[testenv:py3] -allowlist_externals = docker -deps = -rrequirements.txt -commands = docker build -f _fedora_35.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From 7bb86e41189682d4c2fb502e672bd1dce99fb3c3 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 18 Jan 2023 22:12:29 +0000 Subject: [PATCH 293/638] Add a check for the version number of lighttpd. Only remove the server.modules += section of the new pihole-admin config if the version number is not greater than or equal to 1.4.56 Signed-off-by: Adam Warner --- advanced/lighttpd.conf.debian | 1 - automated install/basic-install.sh | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 06c284fe5f..61d2082188 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -17,7 +17,6 @@ server.modules = ( "mod_access", - "mod_accesslog", "mod_auth", "mod_expire", "mod_redirect", diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3b37bf2845..44b4b31355 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1432,14 +1432,23 @@ installConfigs() { elif [[ -d "/etc/lighttpd/conf-available" ]]; then conf=/etc/lighttpd/conf-available/15-pihole-admin.conf install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/pihole-admin.conf $conf - # disable server.modules += ( ... ) in $conf to avoid module dups - # (needed until Debian 10 no longer supported by pi-hole) - # (server.modules duplication is ignored in lighttpd 1.4.56+) - if awk '!/^server\.modules/{print}' $conf > $conf.$$ && mv $conf.$$ $conf; then + + # Get the version number of lighttpd + version=$(lighttpd -v | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+') + # Test if that version is greater than or euqal to 1.4.56 + if dpkg --compare-versions "$version" "ge" "1.4.56"; then + # If it is, then we don't need to disable the modules : else - rm $conf.$$ + # disable server.modules += ( ... ) in $conf to avoid module dups + # (server.modules duplication is ignored in lighttpd 1.4.56+) + if awk '!/^server\.modules/{print}' $conf > $conf.$$ && mv $conf.$$ $conf; then + : + else + rm $conf.$$ + fi fi + chmod 644 $conf if is_command lighty-enable-mod ; then lighty-enable-mod pihole-admin access accesslog redirect fastcgi setenv > /dev/null || true From 771b7cfcc7aafb3c9d902f2d22a039a0ba6e145c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 19 Jan 2023 21:41:32 +0100 Subject: [PATCH 294/638] Run updatechecker after gravity 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3b37bf2845..be906ea19d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2717,12 +2717,12 @@ main() { restart_service pihole-FTL - # Update local and remote versions via updatechecker - /opt/pihole/updatecheck.sh - # Download and compile the aggregated block list runGravity + # Update local and remote versions via updatechecker + /opt/pihole/updatecheck.sh + if [[ "${useUpdateVars}" == false ]]; then displayFinalMessage "${pw}" fi From 155bbc736446696f4744cba3b8399ce9027fb251 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 17:20:40 -0500 Subject: [PATCH 295/638] use systemd service --- advanced/Scripts/webpage.sh | 42 ++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f1f53b72a4..056010d6ce 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -506,7 +506,7 @@ ChangeSpeedTestSchedule() { if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" - SetCronTab ${args[2]} + SetService ${args[2]} fi fi } @@ -552,13 +552,14 @@ UpdateSpeedTestChartType() { fi } -SetCronTab() { +SetService() { # Remove OLD crontab -l >crontab.tmp || true + sed -i '/speedtest/d' crontab.tmp + crontab crontab.tmp && rm -f crontab.tmp if [[ "$1" == "0" ]]; then - sed -i '/speedtest/d' crontab.tmp - crontab crontab.tmp && rm -f crontab.tmp + systemctl disable --now pihole-speedtest.timer &> /dev/null else sed -i '/speedtest/d' crontab.tmp @@ -569,10 +570,35 @@ SetCronTab() { else speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" fi - - newtab="0 */"${1}" * * * sudo \""${speedtest_file}"\" > /dev/null 2>&1" - printf '%s\n' "$newtab" >>crontab.tmp - crontab crontab.tmp && rm -f crontab.tmp + + # create a systemd timer to run the service + # create a systemd service to run the speedtest + cat > /etc/systemd/system/pihole-speedtest.service << EOL +[Unit] +Description=Pi-hole Speedtest +After=network.target + +[Service] +Type=oneshot +ExecStart=$speedtest_file + +[Install] +WantedBy=multi-user.target +EOL + + cat > /etc/systemd/system/pihole-speedtest.timer << EOL +[Unit] +Description=Pi-hole Speedtest Timer + +[Timer] +OnCalendar=*-*-* *:$1:00 +Persistent=true + +[Install] +WantedBy=timers.target +EOL + + systemctl enable --now pihole-speedtest.timer &> /dev/null fi } From 15609b7554ddf60845d137b86b819168fd866c9a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 18:40:29 -0500 Subject: [PATCH 296/638] forgot about reload --- advanced/Scripts/webpage.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 056010d6ce..cae4dbf8eb 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -591,14 +591,16 @@ EOL Description=Pi-hole Speedtest Timer [Timer] -OnCalendar=*-*-* *:$1:00 +OnCalendar=*-*-* $1:00:00 Persistent=true [Install] WantedBy=timers.target EOL - systemctl enable --now pihole-speedtest.timer &> /dev/null + systemctl daemon-reload + systemctl reenable pihole-speedtest.timer &> /dev/null + systemctl restart pihole-speedtest.timer fi } From 21cfa7bf237662e41b76876e3917c907d0e879e0 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 19:52:38 -0500 Subject: [PATCH 297/638] are the files created? --- advanced/Scripts/webpage.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index cae4dbf8eb..69b1d8994f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -561,18 +561,12 @@ SetService() { if [[ "$1" == "0" ]]; then systemctl disable --now pihole-speedtest.timer &> /dev/null else - sed -i '/speedtest/d' crontab.tmp - mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) - + speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" if [[ "$mode" =~ "official" ]]; then speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" - else - speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" fi - # create a systemd timer to run the service - # create a systemd service to run the speedtest cat > /etc/systemd/system/pihole-speedtest.service << EOL [Unit] Description=Pi-hole Speedtest From aeb38e6824483b2487d96ec979aef5c232506b70 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:07:07 -0500 Subject: [PATCH 298/638] explicit shell moves redirection into su process --- advanced/Scripts/webpage.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 69b1d8994f..382808e185 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -56,6 +56,7 @@ Options: -sm Speedtest Mode -sc Clear speedtest data -ss Set custom server + -st Set default speedtest chart type (line, bar) -l, privacylevel Set privacy level (0 = lowest, 3 = highest) -t, teleporter Backup configuration as an archive -t, teleporter myname.tar.gz Backup configuration to archive with name myname.tar.gz as specified" @@ -567,7 +568,7 @@ SetService() { speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" fi - cat > /etc/systemd/system/pihole-speedtest.service << EOL + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOL [Unit] Description=Pi-hole Speedtest After=network.target @@ -578,9 +579,8 @@ ExecStart=$speedtest_file [Install] WantedBy=multi-user.target -EOL - - cat > /etc/systemd/system/pihole-speedtest.timer << EOL +EOL' + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOL [Unit] Description=Pi-hole Speedtest Timer @@ -590,7 +590,7 @@ Persistent=true [Install] WantedBy=timers.target -EOL +EOL' systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null From c80be75fcf253d0eab33fa6592b54ea7aacffd18 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:17:04 -0500 Subject: [PATCH 299/638] variable inside string --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 382808e185..2f7034a93f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -575,7 +575,7 @@ After=network.target [Service] Type=oneshot -ExecStart=$speedtest_file +ExecStart="$speedtest_file" [Install] WantedBy=multi-user.target @@ -585,7 +585,7 @@ EOL' Description=Pi-hole Speedtest Timer [Timer] -OnCalendar=*-*-* $1:00:00 +OnCalendar=*-*-* "$1":00:00 Persistent=true [Install] From 86ffe273fcd1709a759933240e11faf0abd021a6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:36:45 -0500 Subject: [PATCH 300/638] maybe escape --- 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 2f7034a93f..5489b63c76 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -568,7 +568,7 @@ SetService() { speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" fi - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOL + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << \EOF [Unit] Description=Pi-hole Speedtest After=network.target @@ -579,8 +579,8 @@ ExecStart="$speedtest_file" [Install] WantedBy=multi-user.target -EOL' - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOL +EOF' + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << \EOF [Unit] Description=Pi-hole Speedtest Timer @@ -590,7 +590,7 @@ Persistent=true [Install] WantedBy=timers.target -EOL' +EOF' systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null From b888b6ac0e5da9460a7fb24ca416247775f87af5 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:38:49 -0500 Subject: [PATCH 301/638] can i do this --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5489b63c76..6c2f376d31 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -575,7 +575,7 @@ After=network.target [Service] Type=oneshot -ExecStart="$speedtest_file" +ExecStart='"$speedtest_file"' [Install] WantedBy=multi-user.target @@ -585,7 +585,7 @@ EOF' Description=Pi-hole Speedtest Timer [Timer] -OnCalendar=*-*-* "$1":00:00 +OnCalendar=*-*-* '"$1"':00:00 Persistent=true [Install] From 68b3a5824412ef24d9091866cfe54a7f75a480e5 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:39:53 -0500 Subject: [PATCH 302/638] no escape? --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 6c2f376d31..1789272874 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -568,7 +568,7 @@ SetService() { speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" fi - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << \EOF + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest After=network.target @@ -580,7 +580,7 @@ ExecStart='"$speedtest_file"' [Install] WantedBy=multi-user.target EOF' - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << \EOF + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer From 01a4d8807b2e780302739f65f2f0466eee6c6bdc Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:40:57 -0500 Subject: [PATCH 303/638] no "? --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1789272874..0d0233591b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -575,7 +575,7 @@ After=network.target [Service] Type=oneshot -ExecStart='"$speedtest_file"' +ExecStart='$speedtest_file' [Install] WantedBy=multi-user.target @@ -585,7 +585,7 @@ EOF' Description=Pi-hole Speedtest Timer [Timer] -OnCalendar=*-*-* '"$1"':00:00 +OnCalendar=*-*-* '$1':00:00 Persistent=true [Install] From b2e6bf0c68290486752826bb4f19318ecb09ac16 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:45:14 -0500 Subject: [PATCH 304/638] there we go --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 0d0233591b..7299542e50 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -563,9 +563,9 @@ SetService() { systemctl disable --now pihole-speedtest.timer &> /dev/null else mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) - speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" + speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh' if [[ "$mode" =~ "official" ]]; then - speedtest_file="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" + speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh' fi sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF From d739d4a6e6655792a1084586f27b4987e34b7985 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:11:03 -0500 Subject: [PATCH 305/638] add support for update and uninstall functions --- advanced/Scripts/webpage.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7299542e50..224f420c52 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -51,6 +51,8 @@ Options: -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list + -up [un] Update Pi-hole and update or uninstall the Mod + -un [up] Uninstall Speedtest Mod and optionally update Pi-hole -sd Set speedtest display range -sn Run speedtest now -sm Speedtest Mode @@ -598,6 +600,13 @@ EOF' fi } +UpdateSpeedTest() { + curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/update.sh | bash ${args[2]} +} + +UninstallSpeedTest() { + curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/update.sh | bash ${args[2]} +} SetWebUITheme() { addOrEditKeyValPair "${setupVars}" "WEBTHEME" "${args[2]}" @@ -943,6 +952,8 @@ main() { "clearaudit" ) clearAudit;; "-l" | "privacylevel" ) SetPrivacyLevel;; "-s" | "speedtest" ) ChangeSpeedTestSchedule;; + "-up" ) UpdateSpeedTest;; + "-un" ) UninstallSpeedTest;; "-sd" ) UpdateSpeedTestRange;; "-sn" ) RunSpeedtestNow;; "-sm" ) SpeedtestMode;; From 79f4a7cef094ae7661ddfe2816f84b0585957523 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 20 Jan 2023 18:52:14 +0000 Subject: [PATCH 306/638] Maintain a list of valid hostnames (taken from the top of StevenBlack's host file), and discount them when calculating the number of "invalid" domains in a given list Soften the output message when reporting on unsuable domains Signed-off-by: Adam Warner --- gravity.sh | 67 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/gravity.sh b/gravity.sh index a5c944ce89..e8dfb34dbe 100755 --- a/gravity.sh +++ b/gravity.sh @@ -244,7 +244,7 @@ database_adlist_number() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${num_source_lines}" "${num_invalid}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${num_source_lines}" "${num_unusable}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -522,9 +522,9 @@ gravity_DownloadBlocklists() { # num_target_lines does increase for every correctly added domain in pareseList() num_target_lines=0 num_source_lines=0 -num_invalid=0 +num_unusable=0 parseList() { - local adlistID="${1}" src="${2}" target="${3}" incorrect_lines sample_incorrect_lines + local adlistID="${1}" src="${2}" target="${3}" unusable_lines sample_unusable_lines tmp_unusuable_lines_str false_positive # This sed does the following things: # 1. Remove all lines containing no domains # 2. Remove all domains containing invalid characters. Valid are: a-z, A-Z, 0-9, dot (.), minus (-), underscore (_) @@ -534,10 +534,41 @@ parseList() { sed -r "/([^\.]+\.)+[^\.]{2,}/!d;/[^a-zA-Z0-9.\_-]/d;s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${src}" >> "${target}" # Find lines containing no domains or with invalid characters (see above) - # Remove duplicates and limit to 5 domains - mapfile -t incorrect_lines <<< "$(sed -r "/([^\.]+\.)+[^\.]{2,}/d" < "${src}")" - mapfile -t -O "${#incorrect_lines[@]}" incorrect_lines <<< "$(sed -r "/[^a-zA-Z0-9.\_-]/!d" < "${src}")" - IFS=" " read -r -a sample_incorrect_lines <<< "$(tr ' ' '\n' <<< "${incorrect_lines[@]}" | sort -u | head -n 5| tr '\n' ' ')" + # Remove duplicates from the list + mapfile -t unusable_lines <<< "$(sed -r "/([^\.]+\.)+[^\.]{2,}/d" < "${src}")" + mapfile -t -O "${#unusable_lines[@]}" unusable_lines <<< "$(sed -r "/[^a-zA-Z0-9.\_-]/!d" < "${src}")" + IFS=" " read -r -a unusable_lines <<< "$(tr ' ' '\n' <<< "${unusable_lines[@]}" | sort -u | tr '\n' ' ')" + + # A list of items of common local hostnames not to report as unusable + # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files + # but flagging them as unusable causes more confusion than it's worth - so we suppress them from the output + false_positives=( + "localhost" + "localhost.localdomain" + "local" + "broadcasthost" + "localhost" + "ip6-localhost" + "ip6-loopback" + "lo0 localhost" + "ip6-localnet" + "ip6-mcastprefix" + "ip6-allnodes" + "ip6-allrouters" + "ip6-allhosts" + ) + + # Read the unusable lines into a string + tmp_unusuable_lines_str=" ${unusable_lines[*]} " + for false_positive in "${false_positives[@]}"; do + # Remove false positives from tmp_unusuable_lines_str + tmp_unusuable_lines_str="${tmp_unusuable_lines_str/ ${false_positive} / }" + done + # Read the string back into an array + IFS=" " read -r -a unusable_lines <<< "${tmp_unusuable_lines_str}" + + # Get a sample of the incorrect lines, limited to 5 (the list should already have been de-duplicated) + IFS=" " read -r -a sample_unusable_lines <<< "$(tr ' ' '\n' <<< "${unusable_lines[@]}" | head -n 5 | tr '\n' ' ')" local num_target_lines_new num_correct_lines # Get number of lines in source file @@ -548,22 +579,20 @@ parseList() { num_correct_lines="$(( num_target_lines_new-num_target_lines ))" # Update number of lines in target file num_target_lines="$num_target_lines_new" - num_invalid="$(( num_source_lines-num_correct_lines ))" - if [[ "${num_invalid}" -eq 0 ]]; then - echo " ${INFO} Analyzed ${num_source_lines} domains" - else - echo " ${INFO} Analyzed ${num_source_lines} domains, ${num_invalid} domains invalid!" - fi + num_unusable="${#unusable_lines[@]}" - # Display sample of invalid lines if we found some - if [ ${#sample_incorrect_lines[@]} -ne 0 ]; then - echo " Sample of invalid domains:" - for each in "${sample_incorrect_lines[@]}" + if [[ "${num_unusable}" -ne 0 ]]; then + echo " ${INFO} Imported ${num_correct_lines} domains, ignoring ${num_unusable} non-domain entries" + echo " Sample of non-domain entries:" + for each in "${sample_unusable_lines[@]}" do - echo " - ${each}" + echo " - ${each}" done + else + echo " ${INFO} Imported ${num_correct_lines} domains" fi } + compareLists() { local adlistID="${1}" target="${2}" @@ -717,7 +746,7 @@ gravity_DownloadBlocklistFromUrl() { echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}" # Manually reset these two numbers because we do not call parseList here num_source_lines=0 - num_invalid=0 + num_unusable=0 database_adlist_number "${adlistID}" database_adlist_status "${adlistID}" "4" fi From 7323c1f767d479a87693d74c3c1cdd6f57e1a154 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 20 Jan 2023 21:15:27 -0500 Subject: [PATCH 307/638] webpage.sh -> screen -> mod.sh --- advanced/Scripts/webpage.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 224f420c52..9378bdddee 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -51,8 +51,8 @@ Options: -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list - -up [un] Update Pi-hole and update or uninstall the Mod - -un [up] Uninstall Speedtest Mod and optionally update Pi-hole + -up [un] Update Pi-hole and the Mod (or uninstall the Mod) + -un Uninstall Speedtest Mod without updating Pi-hole (requires original Pi-hole backup) -sd Set speedtest display range -sn Run speedtest now -sm Speedtest Mode @@ -601,11 +601,19 @@ EOF' } UpdateSpeedTest() { - curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/update.sh | bash ${args[2]} + if ! command -v screen &> /dev/null + then + apt-get install screen -y + fi + screen -S pimod -dm bash -c "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- up ${args[2]}" } UninstallSpeedTest() { - curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/update.sh | bash ${args[2]} + if ! command -v screen &> /dev/null + then + apt-get install screen -y + fi + screen -S pimod -dm bash -c "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- un" } SetWebUITheme() { From b3e1daf313b63317a3e7c42d995a2d20ce94e5c6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 20 Jan 2023 21:17:35 -0500 Subject: [PATCH 308/638] org backup not needed --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9378bdddee..84bea93fa7 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -52,7 +52,7 @@ Options: -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list -up [un] Update Pi-hole and the Mod (or uninstall the Mod) - -un Uninstall Speedtest Mod without updating Pi-hole (requires original Pi-hole backup) + -un Uninstall Speedtest Mod without updating Pi-hole -sd Set speedtest display range -sn Run speedtest now -sm Speedtest Mode From 4c3dede0e328f23d8e72cd951e0937456d52b6f5 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 20 Jan 2023 23:01:16 -0500 Subject: [PATCH 309/638] do i need the timer? --- advanced/Scripts/webpage.sh | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 84bea93fa7..fb4e1d98b8 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -562,7 +562,7 @@ SetService() { crontab crontab.tmp && rm -f crontab.tmp if [[ "$1" == "0" ]]; then - systemctl disable --now pihole-speedtest.timer &> /dev/null + systemctl disable --now pihole-speedtest &> /dev/null else mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh' @@ -576,27 +576,19 @@ Description=Pi-hole Speedtest After=network.target [Service] -Type=oneshot +User=root +CPUQuota=20% +Restart=always +RestartSec=$(($1*3600)) ExecStart='$speedtest_file' [Install] WantedBy=multi-user.target -EOF' - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF -[Unit] -Description=Pi-hole Speedtest Timer - -[Timer] -OnCalendar=*-*-* '$1':00:00 -Persistent=true - -[Install] -WantedBy=timers.target EOF' systemctl daemon-reload - systemctl reenable pihole-speedtest.timer &> /dev/null - systemctl restart pihole-speedtest.timer + systemctl reenable pihole-speedtest + systemctl restart pihole-speedtest fi } From 367b31c8ab384d4b8667eb29f31fe7e37e9e8859 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 20 Jan 2023 23:04:05 -0500 Subject: [PATCH 310/638] forgot quotes --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index fb4e1d98b8..4b3a9903fa 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -579,7 +579,7 @@ After=network.target User=root CPUQuota=20% Restart=always -RestartSec=$(($1*3600)) +RestartSec='$(($1*3600))' ExecStart='$speedtest_file' [Install] From bb519efdd9eb065e70705ed572c72e143940859e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 20 Jan 2023 23:11:36 -0500 Subject: [PATCH 311/638] yeah timer's better --- advanced/Scripts/webpage.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 4b3a9903fa..3e32dba3dd 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -562,7 +562,7 @@ SetService() { crontab crontab.tmp && rm -f crontab.tmp if [[ "$1" == "0" ]]; then - systemctl disable --now pihole-speedtest &> /dev/null + systemctl disable --now pihole-speedtest.timer &> /dev/null else mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh' @@ -578,17 +578,27 @@ After=network.target [Service] User=root CPUQuota=20% -Restart=always -RestartSec='$(($1*3600))' +Type=oneshot ExecStart='$speedtest_file' [Install] WantedBy=multi-user.target +EOF' + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF +[Unit] +Description=Pi-hole Speedtest Timer + +[Timer] +OnCalendar=*-*-* '$1':00:00 +Persistent=true + +[Install] +WantedBy=timers.target EOF' systemctl daemon-reload - systemctl reenable pihole-speedtest - systemctl restart pihole-speedtest + systemctl reenable pihole-speedtest.timer &> /dev/null + systemctl restart pihole-speedtest.timer fi } From b8f6e1c8338612c9540547467138ef731690fe75 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 02:26:23 -0500 Subject: [PATCH 312/638] use my repo --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3e32dba3dd..5a76898e0d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,7 +607,7 @@ UpdateSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- up ${args[2]}" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/master/mod.sh | bash -s -- up ${args[2]}" } UninstallSpeedTest() { @@ -615,7 +615,7 @@ UninstallSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- un" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/master/mod.sh | bash -s -- un" } SetWebUITheme() { From af716ed1538e3f80de20e972f087f1e9e64970df Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 02:42:36 -0500 Subject: [PATCH 313/638] same thing --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5a76898e0d..3a84b15ee7 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,7 +607,7 @@ UpdateSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/master/mod.sh | bash -s -- up ${args[2]}" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" } UninstallSpeedTest() { @@ -615,7 +615,7 @@ UninstallSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/master/mod.sh | bash -s -- un" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" } SetWebUITheme() { From 73bbefbffef92efabdbea383c2256d2ca1b019df Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 02:46:03 -0500 Subject: [PATCH 314/638] is it the arg --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3a84b15ee7..957bfe3f59 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,7 +607,7 @@ UpdateSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up" } UninstallSpeedTest() { From a3e76c524223998e32a72cc51046082f24375714 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 02:48:20 -0500 Subject: [PATCH 315/638] let's put that back --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 957bfe3f59..3a84b15ee7 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,7 +607,7 @@ UpdateSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" } UninstallSpeedTest() { From 904467673de6ca15373e1082fa0557c3b5717bcc Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 03:41:43 -0500 Subject: [PATCH 316/638] tac tac? --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3a84b15ee7..f4648aa8a5 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,7 +607,7 @@ UpdateSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | sudo bash -s -- up ${args[2]}" } UninstallSpeedTest() { @@ -615,7 +615,7 @@ UninstallSpeedTest() { then apt-get install screen -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" + screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | sudo bash -s -- un" } SetWebUITheme() { From d6e25403eeb348271dce571642170ebcf5b54098 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 21 Jan 2023 10:01:41 +0000 Subject: [PATCH 317/638] Bump tox from 4.2.8 to 4.3.5 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.2.8 to 4.3.5. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.2.8...4.3.5) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index e891242c19..686f2a588d 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.2.1 pytest-xdist == 3.1.0 pytest-testinfra == 7.0.0 -tox == 4.2.8 +tox == 4.3.5 From db199e30e7212ee7bcfbb10632347aed5fe418eb Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 06:33:17 -0500 Subject: [PATCH 318/638] use tmux --- advanced/Scripts/webpage.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f4648aa8a5..1c8f854107 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -603,19 +603,17 @@ EOF' } UpdateSpeedTest() { - if ! command -v screen &> /dev/null - then - apt-get install screen -y + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | sudo bash -s -- up ${args[2]}" + tmux new-session -d -s pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" } UninstallSpeedTest() { - if ! command -v screen &> /dev/null - then - apt-get install screen -y + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | sudo bash -s -- un" + tmux new-session -d -s pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- un" } SetWebUITheme() { From 4aaebf165017a68117d3948e70d80abc340eea1f Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 06:51:54 -0500 Subject: [PATCH 319/638] stop tmux from exiting --- advanced/Scripts/webpage.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1c8f854107..f590192c57 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,14 +606,16 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- un" + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- un" Enter } SetWebUITheme() { From acb0762beefe59cad85e26ed8153479cab0e3dad Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 07:04:40 -0500 Subject: [PATCH 320/638] switch to tmux --- advanced/Scripts/webpage.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3e32dba3dd..52b1ea75c3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -603,19 +603,19 @@ EOF' } UpdateSpeedTest() { - if ! command -v screen &> /dev/null - then - apt-get install screen -y + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- up ${args[2]}" + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { - if ! command -v screen &> /dev/null - then - apt-get install screen -y + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y fi - screen -S pimod -dm bash -c "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- un" + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | tac | tac | bash -s -- un" Enter } SetWebUITheme() { From 673e8d684869a27af33f1d9a5a0ad4aa0255cdec Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 07:26:34 -0500 Subject: [PATCH 321/638] remove session if exists --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 52b1ea75c3..58f550d025 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,6 +606,7 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter } @@ -614,6 +615,7 @@ UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | tac | tac | bash -s -- un" Enter } From 00e36073b3d89ab5a6b48db36fc06d966330519c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 07:26:55 -0500 Subject: [PATCH 322/638] remove session if exists --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f590192c57..1857f086ab 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,6 +606,7 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter } @@ -614,6 +615,7 @@ UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- un" Enter } From b381bed6fd2d0536f3b481813d8cc343bda7a657 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 08:04:01 -0500 Subject: [PATCH 323/638] curl can manage buffer by itself like a big it --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1857f086ab..c1dd00becf 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -608,7 +608,7 @@ UpdateSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { @@ -617,7 +617,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- un" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter } SetWebUITheme() { From 24cdfa953b53bb7521a730703a4b39e7b3fe6ad7 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 08:05:05 -0500 Subject: [PATCH 324/638] change to how buffer is managed --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 58f550d025..6ffe543e5d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -608,7 +608,7 @@ UpdateSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { @@ -617,7 +617,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | tac | tac | bash -s -- un" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- un" Enter } SetWebUITheme() { From d30a5f1b950a5a1b8efcf93ccc4f80bf90e1e706 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 19 Jan 2023 12:24:57 +0000 Subject: [PATCH 325/638] Get the lighttpd version from `dpkg-query` instead Signed-off-by: Adam Warner --- 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 44b4b31355..20fd997de7 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1434,14 +1434,14 @@ installConfigs() { install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/pihole-admin.conf $conf # Get the version number of lighttpd - version=$(lighttpd -v | grep -o -E '[0-9]+\.[0-9]+\.[0-9]+') + version=$(dpkg-query -f='${Version}\n' --show lighttpd) # Test if that version is greater than or euqal to 1.4.56 if dpkg --compare-versions "$version" "ge" "1.4.56"; then # If it is, then we don't need to disable the modules + # (server.modules duplication is ignored in lighttpd 1.4.56+) : else # disable server.modules += ( ... ) in $conf to avoid module dups - # (server.modules duplication is ignored in lighttpd 1.4.56+) if awk '!/^server\.modules/{print}' $conf > $conf.$$ && mv $conf.$$ $conf; then : else From 9331cbff4b186f91542a5981b54355076cb08a3b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 21 Jan 2023 14:25:06 +0000 Subject: [PATCH 326/638] remove the access log configuration from lighttpd.conf.debian and .conf.fedora to prevent issues on upgrades (this is defined in pihole-admin.conf) Signed-off-by: Adam Warner --- advanced/lighttpd.conf.debian | 2 -- advanced/lighttpd.conf.fedora | 2 -- 2 files changed, 4 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 61d2082188..5a96c6cd94 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -33,8 +33,6 @@ server.groupname = "www-data" # For lighttpd version 1.4.46 or above, the port can be overwritten in `/etc/lighttpd/external.conf` using the := operator # e.g. server.port := 8000 server.port = 80 -accesslog.filename = "/var/log/lighttpd/access-pihole.log" -accesslog.format = "%{%s}t|%V|%r|%s|%b" # Allow streaming response # reference: https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_stream-response-bodyDetails diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 04f3ee0176..6276bfcbb8 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -35,8 +35,6 @@ server.groupname = "lighttpd" # For lighttpd version 1.4.46 or above, the port can be overwritten in `/etc/lighttpd/external.conf` using the := operator # e.g. server.port := 8000 server.port = 80 -accesslog.filename = "/var/log/lighttpd/access-pihole.log" -accesslog.format = "%{%s}t|%V|%r|%s|%b" # Allow streaming response # reference: https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_stream-response-bodyDetails From 91b1fefc9e42feee87c8c327a429b6a95e1c75b1 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:06:50 -0500 Subject: [PATCH 327/638] maybe it was better this way --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index c1dd00becf..1857f086ab 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -608,7 +608,7 @@ UpdateSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" Enter + tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { @@ -617,7 +617,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter + tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- un" Enter } SetWebUITheme() { From 190efa02c79cc4b3a43dd1cd4cfae398530aa34f Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:14:19 -0500 Subject: [PATCH 328/638] undo --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1857f086ab..e7a269aac3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -608,7 +608,7 @@ UpdateSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter + tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { @@ -617,7 +617,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- un" Enter + tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter } SetWebUITheme() { From 31a0a716d37ab24cc1dcad5e72ee6a54f58d0439 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:14:44 -0500 Subject: [PATCH 329/638] actually undo --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e7a269aac3..c1dd00becf 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -608,7 +608,7 @@ UpdateSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { @@ -617,7 +617,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter } SetWebUITheme() { From 8958fe0394595d4fec66b634a04d82582a293503 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:32:36 -0500 Subject: [PATCH 330/638] dont kill --- advanced/Scripts/webpage.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index c1dd00becf..912f3ab2d4 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,7 +606,6 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" Enter } @@ -615,7 +614,6 @@ UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter } From 5c04432fd0af070431ebc278be605094e72b23b4 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 11:50:49 -0500 Subject: [PATCH 331/638] is it the buffer --- advanced/Scripts/webpage.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 912f3ab2d4..25c0e7bda9 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,14 +606,16 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- up ${args[2]}" Enter + tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter } From 9b5bc4c839b7132103319bc048803563510c7be9 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 12:06:31 -0500 Subject: [PATCH 332/638] is it this --- advanced/Scripts/webpage.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 25c0e7bda9..49c5786c82 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,8 +607,7 @@ UpdateSpeedTest() { apt-get install tmux -y fi tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" Enter + tmux new-session -d -s pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" } UninstallSpeedTest() { @@ -616,8 +615,7 @@ UninstallSpeedTest() { apt-get install tmux -y fi tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" } SetWebUITheme() { From d2bdd35b672b5071e8d905dadd8113b65df04f1a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 12:28:34 -0500 Subject: [PATCH 333/638] forgot sudo --- advanced/Scripts/webpage.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 49c5786c82..d0f771984c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,7 +607,8 @@ UpdateSpeedTest() { apt-get install tmux -y fi tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod "curl -sSL https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | tac | tac | bash -s -- up ${args[2]}" + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { @@ -615,7 +616,8 @@ UninstallSpeedTest() { apt-get install tmux -y fi tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | bash -s -- un" + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter } SetWebUITheme() { From 6b4f77bdfe0b747b5c9ff8f80505322a30b0676f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 21 Jan 2023 17:42:32 +0000 Subject: [PATCH 334/638] change socket path back to /run/lighttpd/* - possibly causing issues https://github.com/pi-hole/pi-hole/issues/5131 Signed-off-by: Adam Warner --- advanced/pihole-admin.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/pihole-admin.conf b/advanced/pihole-admin.conf index 60eca5644e..ef15c8fe5c 100644 --- a/advanced/pihole-admin.conf +++ b/advanced/pihole-admin.conf @@ -23,7 +23,7 @@ $HTTP["url"] =~ "^/admin/" { fastcgi.server = ( ".php" => ( "localhost" => ( - "socket" => "/tmp/pihole-php-fastcgi.socket", + "socket" => "/run/lighttpd/pihole-php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi", "min-procs" => 0, "max-procs" => 1, From 4103b91453a0f8692bba33b2e87d75e639044bd9 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 12:59:11 -0500 Subject: [PATCH 335/638] add logging --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index d0f771984c..d26bcfc564 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -617,7 +617,9 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod + echo "Uninstalling Pi-hole Speedtest" > /tmp/pimod.log tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter + echo "Sent command" >> /tmp/pimod.log } SetWebUITheme() { From cdb463e0a2c43bf955e8cdfaf72fdcd9682f5366 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 14:51:10 -0500 Subject: [PATCH 336/638] undo log --- advanced/Scripts/webpage.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index d26bcfc564..d0f771984c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -617,9 +617,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - echo "Uninstalling Pi-hole Speedtest" > /tmp/pimod.log tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter - echo "Sent command" >> /tmp/pimod.log } SetWebUITheme() { From 62d9598826d32e0526da6c7fe61a5fe9373e9656 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 21 Jan 2023 15:53:37 -0500 Subject: [PATCH 337/638] at this point ill try anything --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index d0f771984c..8de0db13d9 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,7 +606,7 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null + tmux kill-session -t pimod tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter } @@ -615,7 +615,7 @@ UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null + tmux kill-session -t pimod tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter } From 9939cf1d774ced34b528c37ea6a90137419315b5 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 21 Jan 2023 23:47:19 +0000 Subject: [PATCH 338/638] Rename some of the variables to hopefully make the process a little clearer Signed-off-by: Adam Warner --- gravity.sh | 68 +++++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/gravity.sh b/gravity.sh index e8dfb34dbe..c279544244 100755 --- a/gravity.sh +++ b/gravity.sh @@ -244,7 +244,7 @@ database_adlist_number() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${num_source_lines}" "${num_unusable}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${num_domains}" "${num_non_domains}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -519,12 +519,12 @@ gravity_DownloadBlocklists() { gravity_Blackbody=true } -# num_target_lines does increase for every correctly added domain in pareseList() -num_target_lines=0 -num_source_lines=0 -num_unusable=0 +# num_total_imported_domains increases for each list processed +num_total_imported_domains=0 +num_domains=0 +num_non_domains=0 parseList() { - local adlistID="${1}" src="${2}" target="${3}" unusable_lines sample_unusable_lines tmp_unusuable_lines_str false_positive + local adlistID="${1}" src="${2}" target="${3}" non_domains sample_non_domains tmp_non_domains_str false_positive # This sed does the following things: # 1. Remove all lines containing no domains # 2. Remove all domains containing invalid characters. Valid are: a-z, A-Z, 0-9, dot (.), minus (-), underscore (_) @@ -535,9 +535,9 @@ parseList() { # Find lines containing no domains or with invalid characters (see above) # Remove duplicates from the list - mapfile -t unusable_lines <<< "$(sed -r "/([^\.]+\.)+[^\.]{2,}/d" < "${src}")" - mapfile -t -O "${#unusable_lines[@]}" unusable_lines <<< "$(sed -r "/[^a-zA-Z0-9.\_-]/!d" < "${src}")" - IFS=" " read -r -a unusable_lines <<< "$(tr ' ' '\n' <<< "${unusable_lines[@]}" | sort -u | tr '\n' ' ')" + mapfile -t non_domains <<< "$(sed -r "/([^\.]+\.)+[^\.]{2,}/d" < "${src}")" + mapfile -t -O "${#non_domains[@]}" non_domains <<< "$(sed -r "/[^a-zA-Z0-9.\_-]/!d" < "${src}")" + IFS=" " read -r -a non_domains <<< "$(tr ' ' '\n' <<< "${non_domains[@]}" | sort -u | tr '\n' ' ')" # A list of items of common local hostnames not to report as unusable # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files @@ -559,37 +559,37 @@ parseList() { ) # Read the unusable lines into a string - tmp_unusuable_lines_str=" ${unusable_lines[*]} " + tmp_non_domains_str=" ${non_domains[*]} " for false_positive in "${false_positives[@]}"; do - # Remove false positives from tmp_unusuable_lines_str - tmp_unusuable_lines_str="${tmp_unusuable_lines_str/ ${false_positive} / }" + # Remove false positives from tmp_non_domains_str + tmp_non_domains_str="${tmp_non_domains_str/ ${false_positive} / }" done # Read the string back into an array - IFS=" " read -r -a unusable_lines <<< "${tmp_unusuable_lines_str}" - - # Get a sample of the incorrect lines, limited to 5 (the list should already have been de-duplicated) - IFS=" " read -r -a sample_unusable_lines <<< "$(tr ' ' '\n' <<< "${unusable_lines[@]}" | head -n 5 | tr '\n' ' ')" - - local num_target_lines_new num_correct_lines - # Get number of lines in source file - num_source_lines="$(grep -c "^" "${src}")" - # Get the new number of lines in destination file - num_target_lines_new="$(grep -c "^" "${target}")" - # Number of new correctly added lines - num_correct_lines="$(( num_target_lines_new-num_target_lines ))" - # Update number of lines in target file - num_target_lines="$num_target_lines_new" - num_unusable="${#unusable_lines[@]}" - - if [[ "${num_unusable}" -ne 0 ]]; then - echo " ${INFO} Imported ${num_correct_lines} domains, ignoring ${num_unusable} non-domain entries" + IFS=" " read -r -a non_domains <<< "${tmp_non_domains_str}" + + # Get a sample of non-domain entries, limited to 5 (the list should already have been de-duplicated) + IFS=" " read -r -a sample_non_domains <<< "$(tr ' ' '\n' <<< "${non_domains[@]}" | head -n 5 | tr '\n' ' ')" + + local tmp_new_imported_total + # Get the new number of domains in destination file + tmp_new_imported_total="$(grep -c "^" "${target}")" + # Number of imported lines for this file is the difference between the new total and the old total. (Or, the number of domains we just added.) + num_domains="$(( tmp_new_imported_total-num_total_imported_domains ))" + # Replace the running total with the new total. + num_total_imported_domains="$tmp_new_imported_total" + # Get the number of non_domains (this is the number of entries left after stripping the source of comments/duplicates/false positives/domains) + num_non_domains="${#non_domains[@]}" + + # If there are unusable lines, we display some information about them. This is not error or major cause for concern. + if [[ "${num_non_domains}" -ne 0 ]]; then + echo " ${INFO} Imported ${num_domains} domains, ignoring ${num_non_domains} non-domain entries" echo " Sample of non-domain entries:" - for each in "${sample_unusable_lines[@]}" + for each in "${sample_non_domains[@]}" do echo " - ${each}" done else - echo " ${INFO} Imported ${num_correct_lines} domains" + echo " ${INFO} Imported ${num_domains} domains" fi } @@ -745,8 +745,8 @@ gravity_DownloadBlocklistFromUrl() { else echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}" # Manually reset these two numbers because we do not call parseList here - num_source_lines=0 - num_unusable=0 + num_domains=0 + num_non_domains=0 database_adlist_number "${adlistID}" database_adlist_status "${adlistID}" "4" fi From 670190619421d900c3de68435816f8c662593c4e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 02:14:04 -0500 Subject: [PATCH 339/638] put it back --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 8de0db13d9..d0f771984c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,7 +606,7 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter } @@ -615,7 +615,7 @@ UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod + tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter } From bbf58945092302b817b28bcc81befa3534e2d09a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 04:14:30 -0500 Subject: [PATCH 340/638] log preserves output --- advanced/Scripts/webpage.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index d0f771984c..60a2f555a6 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,18 +606,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter } SetWebUITheme() { From 7f26606d8d23b49d30951d77bc05cd7b1079520c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 04:20:23 -0500 Subject: [PATCH 341/638] words --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 60a2f555a6..1a639e26de 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,14 +606,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" } SetWebUITheme() { From 9c9c96ef31d952f12b577a37d9273a85f73119d7 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 06:13:52 -0500 Subject: [PATCH 342/638] save log in favor of a persistent session --- advanced/Scripts/webpage.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 6ffe543e5d..b122290e35 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -51,8 +51,8 @@ Options: -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list - -up [un] Update Pi-hole and the Mod (or uninstall the Mod) - -un Uninstall Speedtest Mod without updating Pi-hole + -up [un] [db] Update Pi-hole and (or uninstall) the Mod (and flush the database) + -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database) -sd Set speedtest display range -sn Run speedtest now -sm Speedtest Mode @@ -606,18 +606,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- up ${args[2]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | bash -s -- un" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" } SetWebUITheme() { From e82d5cbf80fe4f9ca20c24746dae795a74d1f0ca Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 06:14:53 -0500 Subject: [PATCH 343/638] words --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1a639e26de..b122290e35 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -51,8 +51,8 @@ Options: -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list - -up [un] Update Pi-hole and the Mod (or uninstall the Mod) - -un Uninstall Speedtest Mod without updating Pi-hole + -up [un] [db] Update Pi-hole and (or uninstall) the Mod (and flush the database) + -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database) -sd Set speedtest display range -sn Run speedtest now -sm Speedtest Mode From 45090eb308b288465e0a0527c46e82c953f6e8f3 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 09:20:17 -0500 Subject: [PATCH 344/638] account for db --- advanced/Scripts/webpage.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index b122290e35..019a1c3a62 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -50,9 +50,10 @@ Options: -k, kelvin Set Kelvin as preferred temperature unit -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior - -s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list - -up [un] [db] Update Pi-hole and (or uninstall) the Mod (and flush the database) + -s, speedtest Set speedtest interval, user 0 to disable Speedtests, use -sn to prevent logging to results list + -up [un] [db] Update Pi-hole (and | but uninstall) the Mod (and flush the database) -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database) + -db Flush the database -sd Set speedtest display range -sn Run speedtest now -sm Speedtest Mode @@ -962,6 +963,7 @@ main() { "-s" | "speedtest" ) ChangeSpeedTestSchedule;; "-up" ) UpdateSpeedTest;; "-un" ) UninstallSpeedTest;; + "-db" ) ClearSpeedtestData;; "-sd" ) UpdateSpeedTestRange;; "-sn" ) RunSpeedtestNow;; "-sm" ) SpeedtestMode;; From 562c44aaba241f05f20b3627a9aac84b6424d7f6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 12:56:17 -0500 Subject: [PATCH 345/638] persist tmux again --- advanced/Scripts/webpage.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 019a1c3a62..0ca4e146ed 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,14 +607,18 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" + tmux kill-session -t pimod &> /dev/null + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" + tmux kill-session -t pimod &> /dev/null + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" } SetWebUITheme() { From 215a78ab75c411c5d17d6171ec3bbc8b993abee3 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:03:00 -0500 Subject: [PATCH 346/638] word --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 0ca4e146ed..f240dc2a78 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -609,7 +609,7 @@ UpdateSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter } UninstallSpeedTest() { @@ -618,7 +618,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter } SetWebUITheme() { From 68a03cc877294c39f9be4ff99988c1f23361bcbf Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 22 Jan 2023 18:05:05 +0000 Subject: [PATCH 347/638] Ensure that /run/lighttpd exists and is owned by lighttpd user. It is likely that new installs will fail currently Signed-off-by: Adam Warner --- automated install/basic-install.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b1bd773ed6..6bb8e363ed 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1403,12 +1403,16 @@ installConfigs() { # set permissions on /etc/lighttpd/lighttpd.conf so pihole user (other) can read the file chmod o+x /etc/lighttpd chmod o+r "${lighttpdConfig}" + + # Ensure /run/lighttpd exists and is owned by lighttpd user + # Needed for the php socket + mkdir -p /run/lighttpd + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd + if grep -q -F "FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then # Attempt to preserve backwards compatibility with older versions install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" # Make the directories if they do not exist and set the owners - mkdir -p /run/lighttpd - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd mkdir -p /var/cache/lighttpd/compress chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress mkdir -p /var/cache/lighttpd/uploads From a6be22f58975038673bb09566c7fbd9ad6751e50 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:05:13 -0500 Subject: [PATCH 348/638] support the other options --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f240dc2a78..adddb860f0 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -609,7 +609,7 @@ UpdateSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" Enter } UninstallSpeedTest() { @@ -618,7 +618,7 @@ UninstallSpeedTest() { fi tmux kill-session -t pimod &> /dev/null tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" Enter + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" Enter } SetWebUITheme() { From 1daa0dd0c64f460a50524c72d01f022f2c7fc562 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:15:25 -0500 Subject: [PATCH 349/638] undo persist again --- advanced/Scripts/webpage.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index adddb860f0..019a1c3a62 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,18 +607,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" } SetWebUITheme() { From 9ec89f9e2e7e36b99468520b0a588c94aadb1095 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:18:19 -0500 Subject: [PATCH 350/638] redo --- advanced/Scripts/webpage.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index b122290e35..3b3d2dbe2d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -50,9 +50,10 @@ Options: -k, kelvin Set Kelvin as preferred temperature unit -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior - -s, speedtest Set speedtest intevel , user 0 to disable Speedtests use -sn to prevent logging to results list - -up [un] [db] Update Pi-hole and (or uninstall) the Mod (and flush the database) + -s, speedtest Set speedtest interval, user 0 to disable Speedtests, use -sn to prevent logging to results list + -up [un] [db] Update Pi-hole (and | but uninstall) the Mod (and flush the database) -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database) + -db Flush the database -sd Set speedtest display range -sn Run speedtest now -sm Speedtest Mode @@ -606,14 +607,18 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" + tmux kill-session -t pimod &> /dev/null + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" Enter } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" + tmux kill-session -t pimod &> /dev/null + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" Enter } SetWebUITheme() { @@ -962,6 +967,7 @@ main() { "-s" | "speedtest" ) ChangeSpeedTestSchedule;; "-up" ) UpdateSpeedTest;; "-un" ) UninstallSpeedTest;; + "-db" ) ClearSpeedtestData;; "-sd" ) UpdateSpeedTestRange;; "-sn" ) RunSpeedtestNow;; "-sm" ) SpeedtestMode;; From ff9d1ed4ac1f7a1ca77d4f8143c7e0aea1bd6e70 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:18:48 -0500 Subject: [PATCH 351/638] redo --- advanced/Scripts/webpage.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 019a1c3a62..3b3d2dbe2d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,14 +607,18 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" + tmux kill-session -t pimod &> /dev/null + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" Enter } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" + tmux kill-session -t pimod &> /dev/null + tmux new-session -d -s pimod + tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" Enter } SetWebUITheme() { From 27aa3c7685113a63643bd2ce609a180ba8cb0baf Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:28:25 -0500 Subject: [PATCH 352/638] undo --- advanced/Scripts/webpage.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3b3d2dbe2d..019a1c3a62 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,18 +607,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" } SetWebUITheme() { From 7bb014a3ebc883626450af127038c2ef24a5a2ab Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:28:48 -0500 Subject: [PATCH 353/638] what --- advanced/Scripts/webpage.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3b3d2dbe2d..019a1c3a62 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,18 +607,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux kill-session -t pimod &> /dev/null - tmux new-session -d -s pimod - tmux send-keys -t pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" Enter + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" } SetWebUITheme() { From 29883412dda2936b0540432af48a1e942c9b53ea Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:35:27 -0500 Subject: [PATCH 354/638] forgot that --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 019a1c3a62..1a34d1099f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,14 +607,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" } SetWebUITheme() { From ec38715c1890eca4c3484f5477690928902913de Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:36:02 -0500 Subject: [PATCH 355/638] forgot those --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 019a1c3a62..1a34d1099f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,14 +607,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" + tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" } SetWebUITheme() { From 6a6dbf1c52106a8c0e32cbc7128ee93e42cfcead Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 13:39:24 -0500 Subject: [PATCH 356/638] change repos --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 019a1c3a62..0aa211cf8f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,14 +607,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]}" + tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un" + tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash -s -- un ${args[2]}" } SetWebUITheme() { From 24c6fd610c6648464bfa8d489f0b5416fd568b0d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 15:14:16 -0500 Subject: [PATCH 357/638] test button --- advanced/Scripts/webpage.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1a34d1099f..fa81df5af1 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -60,6 +60,7 @@ Options: -sc Clear speedtest data -ss Set custom server -st Set default speedtest chart type (line, bar) + test Test the speedtest script -l, privacylevel Set privacy level (0 = lowest, 3 = highest) -t, teleporter Backup configuration as an archive -t, teleporter myname.tar.gz Backup configuration to archive with name myname.tar.gz as specified" @@ -603,6 +604,10 @@ EOF' fi } +SpeedTestTest() { + cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash & +} + UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y @@ -970,6 +975,7 @@ main() { "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; "-st" ) UpdateSpeedTestChartType;; + "test" ) SpeedTestTest;; "addcustomdns" ) AddCustomDNSAddress;; "removecustomdns" ) RemoveCustomDNSAddress;; "addcustomcname" ) AddCustomCNAMERecord;; From 251be73b705153e7f8ef69ae2061c1695db0ab66 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 15:48:06 -0500 Subject: [PATCH 358/638] make it nonblocking --- advanced/Scripts/webpage.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index fa81df5af1..379226bad0 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -605,7 +605,10 @@ EOF' } SpeedTestTest() { - cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash & + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y + fi + tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash" } UpdateSpeedTest() { From 9b81447f1e5d6b1cf0994c699ff565ed769e2ded Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 15:53:58 -0500 Subject: [PATCH 359/638] add test --- advanced/Scripts/webpage.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1a34d1099f..379226bad0 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -60,6 +60,7 @@ Options: -sc Clear speedtest data -ss Set custom server -st Set default speedtest chart type (line, bar) + test Test the speedtest script -l, privacylevel Set privacy level (0 = lowest, 3 = highest) -t, teleporter Backup configuration as an archive -t, teleporter myname.tar.gz Backup configuration to archive with name myname.tar.gz as specified" @@ -603,6 +604,13 @@ EOF' fi } +SpeedTestTest() { + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y + fi + tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash" +} + UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y @@ -970,6 +978,7 @@ main() { "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; "-st" ) UpdateSpeedTestChartType;; + "test" ) SpeedTestTest;; "addcustomdns" ) AddCustomDNSAddress;; "removecustomdns" ) RemoveCustomDNSAddress;; "addcustomcname" ) AddCustomCNAMERecord;; From e59f5db145e274fa86d9d3dbc3ea0afd6292fbc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 22 Jan 2023 22:37:19 +0100 Subject: [PATCH 360/638] Add pihole-admin.conf to debug log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c0264d1ad9..23767e00c1 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -77,6 +77,8 @@ PIHOLE_CRON_FILE="${CRON_D_DIRECTORY}/pihole" WEB_SERVER_CONFIG_FILE="${WEB_SERVER_CONFIG_DIRECTORY}/lighttpd.conf" WEB_SERVER_CUSTOM_CONFIG_FILE="${WEB_SERVER_CONFIG_DIRECTORY}/external.conf" +WEB_SERVER_PIHOLE_CONFIG_FILE_DEBIAN="${WEB_SERVER_CONFIG_DIRECTORY}/conf-available/15-pihole-admin.conf" +WEB_SERVER_PIHOLE_CONFIG_FILE_FEDORA="${WEB_SERVER_CONFIG_DIRECTORY}/conf.d/pihole-admin.conf" PIHOLE_INSTALL_LOG_FILE="${PIHOLE_DIRECTORY}/install.log" PIHOLE_RAW_BLOCKLIST_FILES="${PIHOLE_DIRECTORY}/list.*" @@ -140,6 +142,8 @@ PIHOLE_PROCESSES=( "lighttpd" "pihole-FTL" ) REQUIRED_FILES=("${PIHOLE_CRON_FILE}" "${WEB_SERVER_CONFIG_FILE}" "${WEB_SERVER_CUSTOM_CONFIG_FILE}" +"${WEB_SERVER_PIHOLE_CONFIG_FILE_DEBIAN}" +"${WEB_SERVER_PIHOLE_CONFIG_FILE_FEDORA}" "${PIHOLE_INSTALL_LOG_FILE}" "${PIHOLE_RAW_BLOCKLIST_FILES}" "${PIHOLE_LOCAL_HOSTS_FILE}" @@ -1069,10 +1073,13 @@ dir_check() { # check if exists first; if it does, if ls "${filename}" 1> /dev/null 2>&1; then # do nothing - : + true + return else # Otherwise, show an error log_write "${COL_RED}${directory} does not exist.${COL_NC}" + false + return fi done } @@ -1132,9 +1139,10 @@ show_content_of_files_in_dir() { # Set a local variable for better readability local directory="${1}" # Check if the directory exists - dir_check "${directory}" - # if it does, list the files in it - list_files_in_dir "${directory}" + if dir_check "${directory}"; then + # if it does, list the files in it + list_files_in_dir "${directory}" + fi } show_content_of_pihole_files() { @@ -1142,6 +1150,8 @@ show_content_of_pihole_files() { show_content_of_files_in_dir "${PIHOLE_DIRECTORY}" show_content_of_files_in_dir "${DNSMASQ_D_DIRECTORY}" show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}" + show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}/conf.d" + show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}/conf-available" show_content_of_files_in_dir "${CRON_D_DIRECTORY}" show_content_of_files_in_dir "${WEB_SERVER_LOG_DIRECTORY}" show_content_of_files_in_dir "${LOG_DIRECTORY}" From 912c670740f8342ff8f7ca613f93575aa34ddf58 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 23:29:52 -0500 Subject: [PATCH 361/638] fix timer --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f20ecf4c6b..cfccbfa78a 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -591,7 +591,7 @@ EOF' Description=Pi-hole Speedtest Timer [Timer] -OnCalendar=*-*-* '$1':00:00 +OnCalendar=00/'$1':00 Persistent=true [Install] From c23be9b93f0d913a67d0f728b548e54bf265edb6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 22 Jan 2023 23:30:15 -0500 Subject: [PATCH 362/638] fix timer --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 379226bad0..1722da74e3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -591,7 +591,7 @@ EOF' Description=Pi-hole Speedtest Timer [Timer] -OnCalendar=*-*-* '$1':00:00 +OnCalendar=00/'$1':00 Persistent=true [Install] From 2b79fef80cc3bd956366bfebe43683852a28de64 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 23 Jan 2023 01:11:44 -0500 Subject: [PATCH 363/638] simplify help --- advanced/Scripts/webpage.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index cfccbfa78a..ec791909f5 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -51,6 +51,7 @@ Options: -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest interval, user 0 to disable Speedtests, use -sn to prevent logging to results list + -in Reinstall Speedtest Mod -up [un] [db] Update Pi-hole (and | but uninstall) the Mod (and flush the database) -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database) -db Flush the database @@ -611,6 +612,13 @@ SpeedTestTest() { tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash" } +ReinstallSpeedTest() { + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y + fi + tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash" +} + UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y @@ -969,6 +977,7 @@ main() { "clearaudit" ) clearAudit;; "-l" | "privacylevel" ) SetPrivacyLevel;; "-s" | "speedtest" ) ChangeSpeedTestSchedule;; + "-in" ) ReinstallSpeedTest;; "-up" ) UpdateSpeedTest;; "-un" ) UninstallSpeedTest;; "-db" ) ClearSpeedtestData;; From fd4da5acfe81f0f360bc4bc5e03bd7ebf306af2f Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 23 Jan 2023 17:46:48 -0500 Subject: [PATCH 364/638] use sn --- advanced/Scripts/webpage.sh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 662620a074..e5dc4cd2de 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -61,7 +61,6 @@ Options: -sc Clear speedtest data -ss Set custom server -st Set default speedtest chart type (line, bar) - test Test the speedtest script -l, privacylevel Set privacy level (0 = lowest, 3 = highest) -t, teleporter Backup configuration as an archive -t, teleporter myname.tar.gz Backup configuration to archive with name myname.tar.gz as specified" @@ -528,10 +527,6 @@ SpeedtestServer() { fi } -RunSpeedtestNow() { - /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh -} - SpeedtestMode() { if [[ "${args[2]}" ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTEST_MODE" "${args[2]}" @@ -605,7 +600,7 @@ EOF' fi } -SpeedTestTest() { +RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi @@ -987,7 +982,6 @@ main() { "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; "-st" ) UpdateSpeedTestChartType;; - "test" ) SpeedTestTest;; "addcustomdns" ) AddCustomDNSAddress;; "removecustomdns" ) RemoveCustomDNSAddress;; "addcustomcname" ) AddCustomCNAMERecord;; From 1b2b27d6e8ae955e898a2e380d65d8f0e647f8f5 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 23 Jan 2023 18:10:34 -0500 Subject: [PATCH 365/638] change repo --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e5dc4cd2de..6aa447a16a 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -618,14 +618,14 @@ UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" + tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/ipitio/pihole-speedtest/raw/ipitio/mod.sh | sudo bash -s -- un ${args[2]}" + tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash -s -- un ${args[2]}" } SetWebUITheme() { From 5abbeb41b837eff8c1af76bb4c6da49a1a0eda55 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 24 Jan 2023 01:24:12 -0500 Subject: [PATCH 366/638] fix freq --- advanced/Scripts/webpage.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 6aa447a16a..62e30cd81f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -567,6 +567,8 @@ SetService() { if [[ "$mode" =~ "official" ]]; then speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh' fi + + freq=$([ "$1" < "24" ] && echo "00/$1:00" || [ "$1" == "24" ] && echo "daily" || echo "daily,$(($1/24)):$((($1%24)*60))") sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] @@ -587,7 +589,7 @@ EOF' Description=Pi-hole Speedtest Timer [Timer] -OnCalendar=00/'$1':00 +OnCalendar='$freq' Persistent=true [Install] From 9bde5de601197a477f3c195571585cf1cdcc3501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 24 Jan 2023 21:59:13 +0100 Subject: [PATCH 367/638] Use conf-enabled instead of conf-available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- 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 23767e00c1..614e00b170 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -77,7 +77,7 @@ PIHOLE_CRON_FILE="${CRON_D_DIRECTORY}/pihole" WEB_SERVER_CONFIG_FILE="${WEB_SERVER_CONFIG_DIRECTORY}/lighttpd.conf" WEB_SERVER_CUSTOM_CONFIG_FILE="${WEB_SERVER_CONFIG_DIRECTORY}/external.conf" -WEB_SERVER_PIHOLE_CONFIG_FILE_DEBIAN="${WEB_SERVER_CONFIG_DIRECTORY}/conf-available/15-pihole-admin.conf" +WEB_SERVER_PIHOLE_CONFIG_FILE_DEBIAN="${WEB_SERVER_CONFIG_DIRECTORY}/conf-enabled/15-pihole-admin.conf" WEB_SERVER_PIHOLE_CONFIG_FILE_FEDORA="${WEB_SERVER_CONFIG_DIRECTORY}/conf.d/pihole-admin.conf" PIHOLE_INSTALL_LOG_FILE="${PIHOLE_DIRECTORY}/install.log" @@ -1151,7 +1151,7 @@ show_content_of_pihole_files() { show_content_of_files_in_dir "${DNSMASQ_D_DIRECTORY}" show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}" show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}/conf.d" - show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}/conf-available" + show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}/conf-enabled" show_content_of_files_in_dir "${CRON_D_DIRECTORY}" show_content_of_files_in_dir "${WEB_SERVER_LOG_DIRECTORY}" show_content_of_files_in_dir "${LOG_DIRECTORY}" From be0efa233293f82e524a918dafdbeefa69477b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 24 Jan 2023 22:19:24 +0100 Subject: [PATCH 368/638] Add lighttpd selftest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 614e00b170..aa1975121c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -981,6 +981,20 @@ ftl_full_status(){ fi } +lighttpd_test_configuration(){ + # let lighttpd test it's own configuration + local lighttpd_conf_test + echo_current_diagnostic "Lighttpd configuration test" + lighttpd_conf_test=$(lighttpd -tt -f /etc/lighttpd/lighttpd.conf) + if [ -z "${lighttpd_conf_test}" ]; then + # empty output + log_write "${TICK} ${COL_GREEN}No error in lighttpd configuration${COL_NC}" + else + log_write "${CROSS} ${COL_RED}Error in lighttpd configuration${COL_NC}" + log_write " ${lighttpd_conf_test}" + fi +} + make_array_from_file() { local filename="${1}" # The second argument can put a limit on how many line should be read from the file @@ -1506,6 +1520,7 @@ check_name_resolution check_dhcp_servers process_status ftl_full_status +lighttpd_test_configuration parse_setup_vars check_x_headers analyze_ftl_db From 18ab94135ffc4aee8fe59c19a88a3fadaeb4f6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 24 Jan 2023 23:02:38 +0100 Subject: [PATCH 369/638] Show all files (not their content) of the lighttpd config dirs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index aa1975121c..ad25e86698 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -66,6 +66,8 @@ RUN_DIRECTORY="/run" LOG_DIRECTORY="/var/log/pihole" WEB_SERVER_LOG_DIRECTORY="/var/log/lighttpd" WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd" +WEB_SERVER_CONFIG_DIRECTORY_FEDORA="${WEB_SERVER_CONFIG_DIRECTORY}/conf.d" +WEB_SERVER_CONFIG_DIRECTORY_DEBIAN="${WEB_SERVER_CONFIG_DIRECTORY}/conf-enabled" HTML_DIRECTORY="/var/www/html" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" SHM_DIRECTORY="/dev/shm" @@ -77,8 +79,8 @@ PIHOLE_CRON_FILE="${CRON_D_DIRECTORY}/pihole" WEB_SERVER_CONFIG_FILE="${WEB_SERVER_CONFIG_DIRECTORY}/lighttpd.conf" WEB_SERVER_CUSTOM_CONFIG_FILE="${WEB_SERVER_CONFIG_DIRECTORY}/external.conf" -WEB_SERVER_PIHOLE_CONFIG_FILE_DEBIAN="${WEB_SERVER_CONFIG_DIRECTORY}/conf-enabled/15-pihole-admin.conf" -WEB_SERVER_PIHOLE_CONFIG_FILE_FEDORA="${WEB_SERVER_CONFIG_DIRECTORY}/conf.d/pihole-admin.conf" +WEB_SERVER_PIHOLE_CONFIG_FILE_DEBIAN="${WEB_SERVER_CONFIG_DIRECTORY_DEBIAN}/15-pihole-admin.conf" +WEB_SERVER_PIHOLE_CONFIG_FILE_FEDORA="${WEB_SERVER_CONFIG_DIRECTORY_FEDORA}/pihole-admin.conf" PIHOLE_INSTALL_LOG_FILE="${PIHOLE_DIRECTORY}/install.log" PIHOLE_RAW_BLOCKLIST_FILES="${PIHOLE_DIRECTORY}/list.*" @@ -1101,6 +1103,19 @@ dir_check() { list_files_in_dir() { # Set the first argument passed to this function as a named variable for better readability local dir_to_parse="${1}" + + # show files and sizes of some directories, don't print the file content (yet) + if [[ "${dir_to_parse}" == "${SHM_DIRECTORY}" ]]; then + # SHM file - we do not want to see the content, but we want to see the files and their sizes + log_write "$(ls -lh "${dir_to_parse}/")" + elif [[ "${dir_to_parse}" == "${WEB_SERVER_CONFIG_DIRECTORY_FEDORA}" ]]; then + # we want to see all files files in /etc/lighttpd/conf.d + log_write "$(ls -lh "${dir_to_parse}/" 2> /dev/null )" + elif [[ "${dir_to_parse}" == "${WEB_SERVER_CONFIG_DIRECTORY_DEBIAN}" ]]; then + # we want to see all files files in /etc/lighttpd/conf.d + log_write "$(ls -lh "${dir_to_parse}/"/ 2> /dev/null )" + fi + # Store the files found in an array mapfile -t files_found < <(ls "${dir_to_parse}") # For each file in the array, @@ -1116,11 +1131,8 @@ list_files_in_dir() { [[ "${dir_to_parse}/${each_file}" == "${PIHOLE_WEB_SERVER_ACCESS_LOG_FILE}" ]] || \ [[ "${dir_to_parse}/${each_file}" == "${PIHOLE_LOG_GZIPS}" ]]; then : - elif [[ "${dir_to_parse}" == "${SHM_DIRECTORY}" ]]; then - # SHM file - we do not want to see the content, but we want to see the files and their sizes - log_write "$(ls -lhd "${dir_to_parse}"/"${each_file}")" elif [[ "${dir_to_parse}" == "${DNSMASQ_D_DIRECTORY}" ]]; then - # in case of the dnsmasq directory inlcuede all files in the debug output + # in case of the dnsmasq directory include all files in the debug output log_write "\\n${COL_GREEN}$(ls -lhd "${dir_to_parse}"/"${each_file}")${COL_NC}" make_array_from_file "${dir_to_parse}/${each_file}" else @@ -1164,8 +1176,8 @@ show_content_of_pihole_files() { show_content_of_files_in_dir "${PIHOLE_DIRECTORY}" show_content_of_files_in_dir "${DNSMASQ_D_DIRECTORY}" show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}" - show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}/conf.d" - show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY}/conf-enabled" + show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY_FEDORA}" + show_content_of_files_in_dir "${WEB_SERVER_CONFIG_DIRECTORY_DEBIAN}" show_content_of_files_in_dir "${CRON_D_DIRECTORY}" show_content_of_files_in_dir "${WEB_SERVER_LOG_DIRECTORY}" show_content_of_files_in_dir "${LOG_DIRECTORY}" From b9e401aaa3e3770c615cb27c7b7d0b0b17f853a5 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 25 Jan 2023 14:35:57 -0300 Subject: [PATCH 370/638] Change `min_procs` value to `1` The original configuration used the default `min_procs=`. A recent change set this value to zero, but a lot of systems started to receive error messages about the socket file and in some systems lighttpd wasn't able to restart the PHP process, returning HTTP error 503. Setting this to 1 fixed those errors. Signed-off-by: RD WebDesign --- advanced/pihole-admin.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/pihole-admin.conf b/advanced/pihole-admin.conf index ef15c8fe5c..0bb6eac9d6 100644 --- a/advanced/pihole-admin.conf +++ b/advanced/pihole-admin.conf @@ -25,7 +25,7 @@ $HTTP["url"] =~ "^/admin/" { "localhost" => ( "socket" => "/run/lighttpd/pihole-php-fastcgi.socket", "bin-path" => "/usr/bin/php-cgi", - "min-procs" => 0, + "min-procs" => 1, "max-procs" => 1, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "4", From d313747baacedaa98ee3d5e45a8c96dc9ddfa220 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:47:16 -0500 Subject: [PATCH 371/638] fix if --- advanced/Scripts/webpage.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 62e30cd81f..636db46c6c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -516,8 +516,6 @@ ChangeSpeedTestSchedule() { fi } - - SpeedtestServer() { if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "${args[2]}" @@ -567,8 +565,6 @@ SetService() { if [[ "$mode" =~ "official" ]]; then speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh' fi - - freq=$([ "$1" < "24" ] && echo "00/$1:00" || [ "$1" == "24" ] && echo "daily" || echo "daily,$(($1/24)):$((($1%24)*60))") sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] @@ -584,6 +580,7 @@ ExecStart='$speedtest_file' [Install] WantedBy=multi-user.target EOF' + freq=$([ "$1" -lt "24" ] && echo "00/$1:00" || [ "$1" -eq "24" ] && echo "daily" || echo "daily,$(($1/24)):$((($1%24)*60))") sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer From f88050f03482981df144bd454b745b459e39a4ba Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 29 Jan 2023 05:20:12 -0500 Subject: [PATCH 372/638] move speedtest --- advanced/Scripts/webpage.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 636db46c6c..0f2873e291 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -503,7 +503,7 @@ SetWebUILayout() { } ClearSpeedtestData() { - mv $speedtestdb $speedtestdb"_old" + mv $speedtestdb $speedtestdb.old cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb } @@ -551,6 +551,8 @@ UpdateSpeedTestChartType() { fi } +speedtestscript="curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/speedtest.sh | sudo bash || { echo \"No Internet\" && sudo sqlite3 /etc/pihole/speedtest.db \"insert into speedtest values (NULL, '$(date +"%Y-%m-%d %H:%M:%S")', '$(date +"%Y-%m-%d %H:%M:%S")', 'No Internet', '-', '-', 0, 0, 0, 0, '#');\" ; }" + SetService() { # Remove OLD crontab -l >crontab.tmp || true @@ -560,12 +562,6 @@ SetService() { if [[ "$1" == "0" ]]; then systemctl disable --now pihole-speedtest.timer &> /dev/null else - mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) - speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh' - if [[ "$mode" =~ "official" ]]; then - speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh' - fi - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest @@ -575,7 +571,7 @@ After=network.target User=root CPUQuota=20% Type=oneshot -ExecStart='$speedtest_file' +ExecStart=eval '$speedtestscript' [Install] WantedBy=multi-user.target @@ -592,7 +588,6 @@ Persistent=true [Install] WantedBy=timers.target EOF' - systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null systemctl restart pihole-speedtest.timer @@ -603,7 +598,7 @@ RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash" + tmux new-session -d -s pimod "eval $speedtestscript" } ReinstallSpeedTest() { From db5bea8f60136c1f67818725ebcec39614ace829 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 29 Jan 2023 06:45:49 -0500 Subject: [PATCH 373/638] local script support --- advanced/Scripts/webpage.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 636db46c6c..35aeb9a481 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -503,7 +503,7 @@ SetWebUILayout() { } ClearSpeedtestData() { - mv $speedtestdb $speedtestdb"_old" + mv $speedtestdb $speedtestdb.old cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb } @@ -560,12 +560,7 @@ SetService() { if [[ "$1" == "0" ]]; then systemctl disable --now pihole-speedtest.timer &> /dev/null else - mode=$(sed -n -e '/SPEEDTEST_MODE/ s/.*\= *//p' $setupVars) - speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh' - if [[ "$mode" =~ "official" ]]; then - speedtest_file='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh' - fi - + speedtestfile="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest @@ -575,7 +570,7 @@ After=network.target User=root CPUQuota=20% Type=oneshot -ExecStart='$speedtest_file' +ExecStart='$speedtestfile' [Install] WantedBy=multi-user.target @@ -592,7 +587,6 @@ Persistent=true [Install] WantedBy=timers.target EOF' - systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null systemctl restart pihole-speedtest.timer @@ -603,7 +597,8 @@ RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash" + speedtestscript="curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/speedtest.sh | sudo bash || { echo \"No Internet\" && sudo sqlite3 /etc/pihole/speedtest.db \"insert into speedtest values (NULL, '$(date +"%Y-%m-%d %H:%M:%S")', '$(date +"%Y-%m-%d %H:%M:%S")', 'No Internet', '-', '-', 0, 0, 0, 0, '#');\" ; }" + tmux new-session -d -s pimod "eval $speedtestscript" } ReinstallSpeedTest() { @@ -624,7 +619,8 @@ UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash -s -- un ${args[2]}" + uninstallfile="/var/www/html/admin/scripts/pi-hole/speedtest/uninstall.sh" + tmux new-session -d -s pimod "cat $uninstallfile | sudo bash -s -- ${args[2]}" } SetWebUITheme() { From 03cc4dd732f8d4cd6a04299bbb196ebdab274a68 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 29 Jan 2023 06:48:14 -0500 Subject: [PATCH 374/638] match merge --- advanced/Scripts/webpage.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9546ba6305..35aeb9a481 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -551,8 +551,6 @@ UpdateSpeedTestChartType() { fi } -speedtestscript="curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/speedtest.sh | sudo bash || { echo \"No Internet\" && sudo sqlite3 /etc/pihole/speedtest.db \"insert into speedtest values (NULL, '$(date +"%Y-%m-%d %H:%M:%S")', '$(date +"%Y-%m-%d %H:%M:%S")', 'No Internet', '-', '-', 0, 0, 0, 0, '#');\" ; }" - SetService() { # Remove OLD crontab -l >crontab.tmp || true From 1f6e2922c48c768f3a06808bc983736826fa1587 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 29 Jan 2023 08:14:30 -0500 Subject: [PATCH 375/638] it really was single quotes? --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 35aeb9a481..a5a39c9baa 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -560,7 +560,7 @@ SetService() { if [[ "$1" == "0" ]]; then systemctl disable --now pihole-speedtest.timer &> /dev/null else - speedtestfile="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" + speedtestfile='/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh' sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest From 0a06ef8370b962458da841ad8399d728a17a9f4d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 29 Jan 2023 09:20:38 -0500 Subject: [PATCH 376/638] rm var --- advanced/Scripts/webpage.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 35aeb9a481..3ae683ee9f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -556,11 +556,10 @@ SetService() { crontab -l >crontab.tmp || true sed -i '/speedtest/d' crontab.tmp crontab crontab.tmp && rm -f crontab.tmp - + if [[ "$1" == "0" ]]; then systemctl disable --now pihole-speedtest.timer &> /dev/null else - speedtestfile="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh" sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest @@ -570,7 +569,7 @@ After=network.target User=root CPUQuota=20% Type=oneshot -ExecStart='$speedtestfile' +ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh [Install] WantedBy=multi-user.target From b533e87c95f6002ebabdaeb83d6d31b526c94728 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 29 Jan 2023 09:27:12 -0500 Subject: [PATCH 377/638] always use local speedtest --- advanced/Scripts/webpage.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3ae683ee9f..050bbcc9f5 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -596,8 +596,7 @@ RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - speedtestscript="curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/speedtest.sh | sudo bash || { echo \"No Internet\" && sudo sqlite3 /etc/pihole/speedtest.db \"insert into speedtest values (NULL, '$(date +"%Y-%m-%d %H:%M:%S")', '$(date +"%Y-%m-%d %H:%M:%S")', 'No Internet', '-', '-', 0, 0, 0, 0, '#');\" ; }" - tmux new-session -d -s pimod "eval $speedtestscript" + tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash" } ReinstallSpeedTest() { From 0a963e51b7c07944fba17b2c4b4df80b45089141 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 29 Jan 2023 09:33:12 -0500 Subject: [PATCH 378/638] rename to speedtest.sh --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 050bbcc9f5..a3b0e702e1 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -569,7 +569,7 @@ After=network.target User=root CPUQuota=20% Type=oneshot -ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh +ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh [Install] WantedBy=multi-user.target @@ -596,7 +596,7 @@ RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest-official.sh | sudo bash" + tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh | sudo bash" } ReinstallSpeedTest() { From e63746e2993b9f29f27259f4ee3b6d7dd66e4a6a Mon Sep 17 00:00:00 2001 From: itsmesid <693151+arevindh@users.noreply.github.com> Date: Mon, 30 Jan 2023 08:07:59 +0530 Subject: [PATCH 379/638] added reenable to ignore --- .codespellignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.codespellignore b/.codespellignore index 501a3d6732..7f391ce767 100644 --- a/.codespellignore +++ b/.codespellignore @@ -1,3 +1,4 @@ doubleclick wan nwe +reenable From 236ae445c86271ad926b67d7f28845f6f0163859 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:18:39 -0500 Subject: [PATCH 380/638] trailing whitespace --- advanced/Scripts/webpage.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index a3b0e702e1..2d456b1943 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -556,7 +556,6 @@ SetService() { crontab -l >crontab.tmp || true sed -i '/speedtest/d' crontab.tmp crontab crontab.tmp && rm -f crontab.tmp - if [[ "$1" == "0" ]]; then systemctl disable --now pihole-speedtest.timer &> /dev/null else From 3ad896595953b98647e6e01587fd06c5c9d88f5e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 1 Feb 2023 17:38:21 +0000 Subject: [PATCH 381/638] Tweak old pihole lighttpd config warning message to better reflect the consequences of making changes to the file Signed-off-by: Adam Warner --- advanced/lighttpd.conf.debian | 16 +++++++++------- advanced/lighttpd.conf.fedora | 16 +++++++++------- automated install/basic-install.sh | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 5a96c6cd94..f31f7bcd82 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -7,13 +7,15 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -############################################################################### -# FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE INSTALL/UPDATE PROCEDURE. # -# ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # -# # -# CHANGES SHOULD BE MADE IN A SEPARATE CONFIG FILE: # -# /etc/lighttpd/external.conf # -############################################################################### +################################################################################################### +# IF THIS HEADER EXISTS, THE FILE WILL BE OVERWRITTEN BY PI-HOLE'S UPDATE PROCEDURE. # +# ANY CHANGES MADE TO THIS FILE WILL BE LOST ON THE NEXT UPDATE UNLESS YOU REMOVE THIS HEADER # +# # +# ENSURE THAT YOU DO NOT REMOVE THE REQUIRED LINE: # +# # +# include "/etc/lighttpd/conf-enabled/*.conf" # +# # +################################################################################################### server.modules = ( "mod_access", diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 6276bfcbb8..e09d7760c4 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -7,13 +7,15 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -############################################################################### -# FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE INSTALL/UPDATE PROCEDURE. # -# ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # -# # -# CHANGES SHOULD BE MADE IN A SEPARATE CONFIG FILE: # -# /etc/lighttpd/external.conf # -############################################################################### +################################################################################################### +# IF THIS HEADER EXISTS, THE FILE WILL BE OVERWRITTEN BY PI-HOLE'S UPDATE PROCEDURE. # +# ANY CHANGES MADE TO THIS FILE WILL BE LOST ON THE NEXT UPDATE UNLESS YOU REMOVE THIS HEADER # +# # +# ENSURE THAT YOU DO NOT REMOVE THE REQUIRED LINE: # +# # +# include "/etc/lighttpd/conf.d/pihole-admin.conf" # +# # +################################################################################################### server.modules = ( "mod_access", diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 6bb8e363ed..05bc0e4eb8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1409,7 +1409,7 @@ installConfigs() { mkdir -p /run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd - if grep -q -F "FILE AUTOMATICALLY OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then + if grep -q -F "FILE WILL BE OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then # Attempt to preserve backwards compatibility with older versions install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" # Make the directories if they do not exist and set the owners From ca00ffa101d919b0fc493201a734646a620b0de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 2 Feb 2023 11:58:58 +0100 Subject: [PATCH 382/638] Only source versions file if the file exits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pihole b/pihole index a99a37e738..1d9ad82c3e 100755 --- a/pihole +++ b/pihole @@ -24,7 +24,12 @@ utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" source "${utilsfile}" versionsfile="/etc/pihole/versions" -source "${versionsfile}" +if [ -f "${versionsfile}" ]; then + # Only source versionsfile if the file exits + # fixes a warning during installation where versionsfile does not exist yet + # but gravity calls `pihole -status` and thereby sourcing the file + source "${versionsfile}" +fi webpageFunc() { source "${PI_HOLE_SCRIPT_DIR}/webpage.sh" From e5ea361b53d53a49e53de341c6b26f8f63a7f4ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 4 Feb 2023 10:01:16 +0000 Subject: [PATCH 383/638] Bump tox from 4.3.5 to 4.4.4 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.3.5 to 4.4.4. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.3.5...4.4.4) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 686f2a588d..08e7027a2f 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.2.1 pytest-xdist == 3.1.0 pytest-testinfra == 7.0.0 -tox == 4.3.5 +tox == 4.4.4 From c65ea9c47cdbdb849346dd9359d1eefdede07ea0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 10 Feb 2023 20:49:58 +0000 Subject: [PATCH 384/638] Adam does not always think things through completly. He will go and sit on the naughty step now. Co-authored-by: Adam Warner Co-authored-by: Dan Schaper Signed-off-by: Adam Warner --- 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 05bc0e4eb8..ccb5eac72a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1409,7 +1409,7 @@ installConfigs() { mkdir -p /run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /run/lighttpd - if grep -q -F "FILE WILL BE OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then + if grep -q -F "OVERWRITTEN BY PI-HOLE" "${lighttpdConfig}"; then # Attempt to preserve backwards compatibility with older versions install -D -m 644 -T ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} "${lighttpdConfig}" # Make the directories if they do not exist and set the owners From 5ecdfb53c23712a03f22a2d0bbbc78843cf4f68e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:57:20 +0000 Subject: [PATCH 385/638] Bump tox from 4.4.4 to 4.4.5 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.4.4 to 4.4.5. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.4.4...4.4.5) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 08e7027a2f..1670e765e7 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.2.1 pytest-xdist == 3.1.0 pytest-testinfra == 7.0.0 -tox == 4.4.4 +tox == 4.4.5 From d6275cdd7c7822545d022b0393d308f37b11fcb7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 13 Feb 2023 09:04:19 +0000 Subject: [PATCH 386/638] Bump pytest-xdist from 3.1.0 to 3.2.0 in /test Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 3.1.0 to 3.2.0. - [Release notes](https://github.com/pytest-dev/pytest-xdist/releases) - [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v3.1.0...v3.2.0) --- updated-dependencies: - dependency-name: pytest-xdist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 1670e765e7..229d01352b 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ docker-compose == 1.29.2 pytest == 7.2.1 -pytest-xdist == 3.1.0 +pytest-xdist == 3.2.0 pytest-testinfra == 7.0.0 tox == 4.4.5 From 46fe37b4dafdd860fe26decee88e1454d21feb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Feb 2023 21:11:54 +0100 Subject: [PATCH 387/638] Use new worksteal distribution algorithm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/tox.centos_8.ini | 2 +- test/tox.centos_9.ini | 2 +- test/tox.debian_10.ini | 2 +- test/tox.debian_11.ini | 2 +- test/tox.fedora_36.ini | 2 +- test/tox.fedora_37.ini | 2 +- test/tox.ubuntu_20.ini | 2 +- test/tox.ubuntu_22.ini | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini index dac10e97e4..5e94baa6b0 100644 --- a/test/tox.centos_8.ini +++ b/test/tox.centos_8.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.centos_9.ini b/test/tox.centos_9.ini index aa7009e109..d1de2c54d2 100644 --- a/test/tox.centos_9.ini +++ b/test/tox.centos_9.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _centos_9.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini index a012bda4ff..4913b173e8 100644 --- a/test/tox.debian_10.ini +++ b/test/tox.debian_10.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.debian_11.ini b/test/tox.debian_11.ini index 48dc9df1e7..fa8412a81c 100644 --- a/test/tox.debian_11.ini +++ b/test/tox.debian_11.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_11.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.fedora_36.ini b/test/tox.fedora_36.ini index 0cc6f29cef..47a4e08eac 100644 --- a/test/tox.fedora_36.ini +++ b/test/tox.fedora_36.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _fedora_36.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.fedora_37.ini b/test/tox.fedora_37.ini index d6f445335d..4a1d4f2537 100644 --- a/test/tox.fedora_37.ini +++ b/test/tox.fedora_37.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _fedora_37.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.ubuntu_20.ini b/test/tox.ubuntu_20.ini index 88ee0b541b..51715e91c5 100644 --- a/test/tox.ubuntu_20.ini +++ b/test/tox.ubuntu_20.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.ubuntu_22.ini b/test/tox.ubuntu_22.ini index cb5527aba3..70a0c820db 100644 --- a/test/tox.ubuntu_22.ini +++ b/test/tox.ubuntu_22.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py From 4b503a080b0ed21455c1e9215cb92360e1a0329e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Feb 2023 22:13:24 +0100 Subject: [PATCH 388/638] Revert "Use new worksteal distribution algorithm" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 46fe37b4dafdd860fe26decee88e1454d21feb1b. Signed-off-by: Christian König --- test/tox.centos_8.ini | 2 +- test/tox.centos_9.ini | 2 +- test/tox.debian_10.ini | 2 +- test/tox.debian_11.ini | 2 +- test/tox.fedora_36.ini | 2 +- test/tox.fedora_37.ini | 2 +- test/tox.ubuntu_20.ini | 2 +- test/tox.ubuntu_22.ini | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini index 5e94baa6b0..dac10e97e4 100644 --- a/test/tox.centos_8.ini +++ b/test/tox.centos_8.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.centos_9.ini b/test/tox.centos_9.ini index d1de2c54d2..aa7009e109 100644 --- a/test/tox.centos_9.ini +++ b/test/tox.centos_9.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _centos_9.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini index 4913b173e8..a012bda4ff 100644 --- a/test/tox.debian_10.ini +++ b/test/tox.debian_10.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.debian_11.ini b/test/tox.debian_11.ini index fa8412a81c..48dc9df1e7 100644 --- a/test/tox.debian_11.ini +++ b/test/tox.debian_11.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _debian_11.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.fedora_36.ini b/test/tox.fedora_36.ini index 47a4e08eac..0cc6f29cef 100644 --- a/test/tox.fedora_36.ini +++ b/test/tox.fedora_36.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _fedora_36.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.fedora_37.ini b/test/tox.fedora_37.ini index 4a1d4f2537..d6f445335d 100644 --- a/test/tox.fedora_37.ini +++ b/test/tox.fedora_37.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _fedora_37.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.ubuntu_20.ini b/test/tox.ubuntu_20.ini index 51715e91c5..88ee0b541b 100644 --- a/test/tox.ubuntu_20.ini +++ b/test/tox.ubuntu_20.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.ubuntu_22.ini b/test/tox.ubuntu_22.ini index 70a0c820db..cb5527aba3 100644 --- a/test/tox.ubuntu_22.ini +++ b/test/tox.ubuntu_22.ini @@ -5,4 +5,4 @@ envlist = py3 allowlist_externals = docker deps = -rrequirements.txt commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto --dist worksteal} ./test_any_automated_install.py ./test_any_utils.py + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From a4bdf2454bf6b8676fc199db7d81a699536c9b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 16 Feb 2023 10:34:19 +0100 Subject: [PATCH 389/638] Don't use intermediate strings to filter false positives in gravity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/gravity.sh b/gravity.sh index c279544244..28c28a9e2e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -524,7 +524,7 @@ num_total_imported_domains=0 num_domains=0 num_non_domains=0 parseList() { - local adlistID="${1}" src="${2}" target="${3}" non_domains sample_non_domains tmp_non_domains_str false_positive + local adlistID="${1}" src="${2}" target="${3}" non_domains sample_non_domains # This sed does the following things: # 1. Remove all lines containing no domains # 2. Remove all domains containing invalid characters. Valid are: a-z, A-Z, 0-9, dot (.), minus (-), underscore (_) @@ -542,30 +542,13 @@ parseList() { # A list of items of common local hostnames not to report as unusable # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files # but flagging them as unusable causes more confusion than it's worth - so we suppress them from the output - false_positives=( - "localhost" - "localhost.localdomain" - "local" - "broadcasthost" - "localhost" - "ip6-localhost" - "ip6-loopback" - "lo0 localhost" - "ip6-localnet" - "ip6-mcastprefix" - "ip6-allnodes" - "ip6-allrouters" - "ip6-allhosts" - ) - - # Read the unusable lines into a string - tmp_non_domains_str=" ${non_domains[*]} " - for false_positive in "${false_positives[@]}"; do - # Remove false positives from tmp_non_domains_str - tmp_non_domains_str="${tmp_non_domains_str/ ${false_positive} / }" - done - # Read the string back into an array - IFS=" " read -r -a non_domains <<< "${tmp_non_domains_str}" + false_positives="localhost|localhost.localdomain|local|broadcasthost|localhost|ip6-localhost|ip6-loopback|lo0 localhost|ip6-localnet|ip6-mcastprefix|ip6-allnodes|ip6-allrouters|ip6-allhosts" + + # if there are any non-domains, filter the array for false-positives + # Credit: https://stackoverflow.com/a/40264051 + if [[ "${#non_domains[@]}" -gt 0 ]]; then + mapfile -d $'\0' -t non_domains < <(printf '%s\0' "${non_domains[@]}" | grep -Ezv "^${false_positives}") + fi # Get a sample of non-domain entries, limited to 5 (the list should already have been de-duplicated) IFS=" " read -r -a sample_non_domains <<< "$(tr ' ' '\n' <<< "${non_domains[@]}" | head -n 5 | tr '\n' ' ')" From 90da155053dcebb205f33f438af8fdd4f9bcb3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 16 Feb 2023 21:02:49 +0100 Subject: [PATCH 390/638] Use buildx to create docker test images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/tox.centos_8.ini | 2 +- test/tox.centos_9.ini | 2 +- test/tox.debian_10.ini | 2 +- test/tox.debian_11.ini | 2 +- test/tox.fedora_36.ini | 2 +- test/tox.fedora_37.ini | 2 +- test/tox.ubuntu_20.ini | 2 +- test/tox.ubuntu_22.ini | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/tox.centos_8.ini b/test/tox.centos_8.ini index dac10e97e4..dca77c93bc 100644 --- a/test/tox.centos_8.ini +++ b/test/tox.centos_8.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _centos_8.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.centos_9.ini b/test/tox.centos_9.ini index aa7009e109..a69c336afd 100644 --- a/test/tox.centos_9.ini +++ b/test/tox.centos_9.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _centos_9.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _centos_9.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py diff --git a/test/tox.debian_10.ini b/test/tox.debian_10.ini index a012bda4ff..f107300f24 100644 --- a/test/tox.debian_10.ini +++ b/test/tox.debian_10.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _debian_10.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.debian_11.ini b/test/tox.debian_11.ini index 48dc9df1e7..c38a15fb90 100644 --- a/test/tox.debian_11.ini +++ b/test/tox.debian_11.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _debian_11.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _debian_11.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.fedora_36.ini b/test/tox.fedora_36.ini index 0cc6f29cef..515487edd1 100644 --- a/test/tox.fedora_36.ini +++ b/test/tox.fedora_36.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _fedora_36.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _fedora_36.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.fedora_37.ini b/test/tox.fedora_37.ini index d6f445335d..2a8ef39863 100644 --- a/test/tox.fedora_37.ini +++ b/test/tox.fedora_37.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _fedora_37.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _fedora_37.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py diff --git a/test/tox.ubuntu_20.ini b/test/tox.ubuntu_20.ini index 88ee0b541b..49a6153e2a 100644 --- a/test/tox.ubuntu_20.ini +++ b/test/tox.ubuntu_20.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _ubuntu_20.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py diff --git a/test/tox.ubuntu_22.ini b/test/tox.ubuntu_22.ini index cb5527aba3..8014d6d6ea 100644 --- a/test/tox.ubuntu_22.ini +++ b/test/tox.ubuntu_22.ini @@ -4,5 +4,5 @@ envlist = py3 [testenv:py3] allowlist_externals = docker deps = -rrequirements.txt -commands = docker build -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _ubuntu_22.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 4fd0f15d903472e2e56ee3604a16d48d982ab01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 16 Feb 2023 15:21:18 +0100 Subject: [PATCH 391/638] Ignore commented lines when reding PRIVACYLEVEL from config file Create dedicated getVal function in utils.sh as it might be useful somewhere else Account for tailing comments and $key not being on the first line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/utils.sh | 22 ++++++++++++++++++++-- automated install/basic-install.sh | 3 ++- test/test_any_utils.py | 16 ++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 3751647292..a1178265cc 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -44,7 +44,7 @@ addOrEditKeyValPair() { } ####################### -# Takes two arguments: file, and key. +# Takes two arguments: file and key. # Adds a key to target file # # Example usage: @@ -64,7 +64,7 @@ addKey(){ } ####################### -# Takes two arguments: file, and key. +# Takes two arguments: file and key. # Deletes a key or key/value pair from target file # # Example usage: @@ -76,6 +76,24 @@ removeKey() { sed -i "/^${key}/d" "${file}" } +####################### +# Takes two arguments: file and key. +# Returns the value of a given key from target file +# - ignores all commented lines +# - only returns the first value if multiple identical keys exist +# +# +# Example usage: +# getVal "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1" +####################### +getVal() { + local file="${1}" + local key="${2}" + local value + value=$(sed -e '/^[[:blank:]]*#/d' "${file}" | grep "${key}" | awk -F "=" 'NR==1{printf$2}') + printf "%s" "$value" +} + ####################### # returns FTL's current telnet API port based on the setting in /etc/pihole-FTL.conf diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 05bc0e4eb8..a9398d9036 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2612,7 +2612,8 @@ main() { # Get the privacy level if it exists (default is 0) if [[ -f "${FTL_CONFIG_FILE}" ]]; then - PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${FTL_CONFIG_FILE}") + # use getVal from utils.sh to get PRIVACYLEVEL + PRIVACY_LEVEL=$(getVal "${FTL_CONFIG_FILE}" "PRIVACYLEVEL") # If no setting was found, default to 0 PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 5b4075d9b9..6c920161a4 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -62,6 +62,22 @@ def test_key_removal_works(host): assert expected_stdout == output.stdout +def test_get_value_works(host): + """Confirms getVal returns the correct value for a given key""" + output = host.run( + """ + source /opt/pihole/utils.sh + echo "Somekey=xxx" >> /tmp/testfile + echo "#Testkey=1234" >> /tmp/testfile + echo "Testkey=5678" >> /tmp/testfile + echo "Testkey=abcd" >> /tmp/testfile + getVal "/tmp/testfile" "Testkey" + """ + ) + expected_stdout = "5678" + assert expected_stdout == output.stdout + + def test_getFTLAPIPort_default(host): """Confirms getFTLAPIPort returns the default API port""" output = host.run( From ca74152d1d5a5fc179314458a0a96a1843156f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 16 Feb 2023 23:11:00 +0100 Subject: [PATCH 392/638] Allow adding ABP style blocklists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adam Warner Signed-off-by: Christian König --- gravity.sh | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/gravity.sh b/gravity.sh index 28c28a9e2e..d3bb4a07df 100755 --- a/gravity.sh +++ b/gravity.sh @@ -519,25 +519,31 @@ gravity_DownloadBlocklists() { gravity_Blackbody=true } -# num_total_imported_domains increases for each list processed -num_total_imported_domains=0 -num_domains=0 -num_non_domains=0 parseList() { - local adlistID="${1}" src="${2}" target="${3}" non_domains sample_non_domains - # This sed does the following things: - # 1. Remove all lines containing no domains - # 2. Remove all domains containing invalid characters. Valid are: a-z, A-Z, 0-9, dot (.), minus (-), underscore (_) - # 3. Append ,adlistID to every line - # 4. Remove trailing period (see https://github.com/pi-hole/pi-hole/issues/4701) - # 5. Ensures there is a newline on the last line - sed -r "/([^\.]+\.)+[^\.]{2,}/!d;/[^a-zA-Z0-9.\_-]/d;s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${src}" >> "${target}" + local adlistID="${1}" src="${2}" target="${3}" temp_file non_domains sample_non_domains + + # Create a temporary file for the sed magic instead of using "${target}" directly + # this allows to split the sed commands to improve readability + temp_file="$(mktemp -p "/tmp" --suffix=".gravity")" + + # 1. Add all valid domains (adapted from https://stackoverflow.com/a/30007882) + # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already + sed -r "/^([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/!d" "${src}" > "${temp_file}" + # 2. Add all supported ABP style lines (||subdomain.domain.tlp^) + sed -r "/^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\^$/!d" "${src}" >> "${temp_file}" - # Find lines containing no domains or with invalid characters (see above) + # Find lines containing no domains or with invalid characters (not matching regex above) + # This is simply everything that is not in $temp_file compared to $src # Remove duplicates from the list - mapfile -t non_domains <<< "$(sed -r "/([^\.]+\.)+[^\.]{2,}/d" < "${src}")" - mapfile -t -O "${#non_domains[@]}" non_domains <<< "$(sed -r "/[^a-zA-Z0-9.\_-]/!d" < "${src}")" - IFS=" " read -r -a non_domains <<< "$(tr ' ' '\n' <<< "${non_domains[@]}" | sort -u | tr '\n' ' ')" + mapfile -t non_domains < <(grep -Fvf "${temp_file}" "${src}" | sort -u ) + + # 3. Remove trailing period (see https://github.com/pi-hole/pi-hole/issues/4701) + # 4. Append ,adlistID to every line + # 5. Ensures there is a newline on the last line + sed -i "s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${temp_file}" + + # concatenate the temporary file to the target file + cat "${temp_file}" >> "${target}" # A list of items of common local hostnames not to report as unusable # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files @@ -553,13 +559,8 @@ parseList() { # Get a sample of non-domain entries, limited to 5 (the list should already have been de-duplicated) IFS=" " read -r -a sample_non_domains <<< "$(tr ' ' '\n' <<< "${non_domains[@]}" | head -n 5 | tr '\n' ' ')" - local tmp_new_imported_total - # Get the new number of domains in destination file - tmp_new_imported_total="$(grep -c "^" "${target}")" - # Number of imported lines for this file is the difference between the new total and the old total. (Or, the number of domains we just added.) - num_domains="$(( tmp_new_imported_total-num_total_imported_domains ))" - # Replace the running total with the new total. - num_total_imported_domains="$tmp_new_imported_total" + # Get the number of domains added + num_domains="$(grep -c "^" "${temp_file}")" # Get the number of non_domains (this is the number of entries left after stripping the source of comments/duplicates/false positives/domains) num_non_domains="${#non_domains[@]}" From 1f3f8491065949f38faac75879764f7edf9ce94e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 19 Feb 2023 17:47:10 +0000 Subject: [PATCH 393/638] Remove lines starting with ! or [ to account for ABP style comments and header Also splits the piped "one-liner" in ParseFileIntoDomains into individually commented commands (makes for easier reading and debugging) Signed-off-by: Adam Warner --- gravity.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/gravity.sh b/gravity.sh index d3bb4a07df..fb7f42f147 100755 --- a/gravity.sh +++ b/gravity.sh @@ -745,18 +745,30 @@ gravity_ParseFileIntoDomains() { # Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous # This helps with that and makes it easier to read # It also helps with debugging so each stage of the script can be researched more in depth - # 1) Remove carriage returns - # 2) Convert all characters to lowercase - # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) + # 1) Convert all characters to lowercase + tr '[:upper:]' '[:lower:]' < "${src}" > "${destination}" + + # 2) Remove carriage returns + sed -i 's/\r$//' "${destination}" + + # 3a) Remove comments (text starting with "#", include possible spaces before the hash sign) + sed -i 's/\s*#.*//g' "${destination}" + + # 3b) Remove lines starting with ! (ABP Comments) + sed -i 's/\s*!.*//g' "${destination}" + + # 3c) Remove lines starting with [ (ABP Header) + sed -i 's/\s*\[.*//g' "${destination}" + # 4) Remove lines containing "/" - # 5) Remove leading tabs, spaces, etc. + sed -i -r '/(\/).*$/d' "${destination}" + + # 5) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) + sed -i -r 's/^.*\s+//g' "${destination}" + # 6) Remove empty lines - < "${src}" tr -d '\r' | \ - tr '[:upper:]' '[:lower:]' | \ - sed 's/\s*#.*//g' | \ - sed -r '/(\/).*$/d' | \ - sed -r 's/^.*\s+//g' | \ - sed '/^$/d'> "${destination}" + sed -i '/^$/d' "${destination}" + chmod 644 "${destination}" } From c5faf3d1744f100bbbfc800702c70ffc79eda02e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 19 Feb 2023 18:12:03 +0000 Subject: [PATCH 394/638] Use ',' as the separator char in query rather than the default '|' as we now expect some valid results to contain '|' Signed-off-by: Adam Warner --- advanced/Scripts/query.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index d48e9363f5..8717d3281e 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -116,7 +116,7 @@ scanDatabaseTable() { fi # Send prepared query to gravity database - result="$(pihole-FTL sqlite3 "${gravityDBfile}" "${querystr}")" 2> /dev/null + result="$(pihole-FTL sqlite3 -separator ',' "${gravityDBfile}" "${querystr}")" 2> /dev/null if [[ -z "${result}" ]]; then # Return early when there are no matches in this table return @@ -136,8 +136,8 @@ scanDatabaseTable() { # Loop over results and print them mapfile -t results <<< "${result}" for result in "${results[@]}"; do - domain="${result/|*}" - if [[ "${result#*|}" == "0" ]]; then + domain="${result/,*}" + if [[ "${result#*,}" == "0" ]]; then extra=" (disabled)" else extra="" @@ -212,10 +212,10 @@ if [[ -n "${exact}" ]]; then fi for result in "${results[@]}"; do - match="${result/|*/}" - extra="${result#*|}" - adlistAddress="${extra/|*/}" - extra="${extra#*|}" + match="${result/,*/}" + extra="${result#*,}" + adlistAddress="${extra/,*/}" + extra="${extra#*,}" if [[ "${extra}" == "0" ]]; then extra=" (disabled)" else From 523297968e501724ab9725cde04c1113e0f2a30b Mon Sep 17 00:00:00 2001 From: itsmesid <693151+arevindh@users.noreply.github.com> Date: Fri, 24 Feb 2023 12:49:26 +0530 Subject: [PATCH 395/638] removed CPUQuota=20% --- advanced/Scripts/webpage.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 2d456b1943..147b491db7 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -566,7 +566,6 @@ After=network.target [Service] User=root -CPUQuota=20% Type=oneshot ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh From eedd93d7823ace35e2915e83a6dcc86b13abfd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 22 Feb 2023 21:14:27 +0100 Subject: [PATCH 396/638] Remove temporary files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index fb7f42f147..57959b2523 100755 --- a/gravity.sh +++ b/gravity.sh @@ -524,7 +524,13 @@ parseList() { # Create a temporary file for the sed magic instead of using "${target}" directly # this allows to split the sed commands to improve readability + # we use a file handle here and remove the temporary file immediately so the content will be deleted in any case + # when the script stops temp_file="$(mktemp -p "/tmp" --suffix=".gravity")" + exec 3>"$temp_file" + rm "${temp_file}" + temp_file="/proc/$$/fd/3" + # 1. Add all valid domains (adapted from https://stackoverflow.com/a/30007882) # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already @@ -540,10 +546,8 @@ parseList() { # 3. Remove trailing period (see https://github.com/pi-hole/pi-hole/issues/4701) # 4. Append ,adlistID to every line # 5. Ensures there is a newline on the last line - sed -i "s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${temp_file}" - - # concatenate the temporary file to the target file - cat "${temp_file}" >> "${target}" + # and write everything to the target file + sed "s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${temp_file}" >> "${target}" # A list of items of common local hostnames not to report as unusable # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files @@ -575,6 +579,9 @@ parseList() { else echo " ${INFO} Imported ${num_domains} domains" fi + + # close file handle + exec 3<&- } compareLists() { From 821c7dc190cdabc28f024e4688bff3670f028731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 24 Feb 2023 22:18:41 +0100 Subject: [PATCH 397/638] Add info when list cotains ABP style domains MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/gravity.sh b/gravity.sh index 57959b2523..451a40fcde 100755 --- a/gravity.sh +++ b/gravity.sh @@ -520,23 +520,29 @@ gravity_DownloadBlocklists() { } parseList() { - local adlistID="${1}" src="${2}" target="${3}" temp_file non_domains sample_non_domains + local adlistID="${1}" src="${2}" target="${3}" temp_file temp_file_base non_domains sample_non_domains # Create a temporary file for the sed magic instead of using "${target}" directly # this allows to split the sed commands to improve readability # we use a file handle here and remove the temporary file immediately so the content will be deleted in any case # when the script stops - temp_file="$(mktemp -p "/tmp" --suffix=".gravity")" - exec 3>"$temp_file" - rm "${temp_file}" + temp_file_base="$(mktemp -p "/tmp" --suffix=".gravity")" + exec 3>"$temp_file_base" + rm "${temp_file_base}" temp_file="/proc/$$/fd/3" # 1. Add all valid domains (adapted from https://stackoverflow.com/a/30007882) # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already sed -r "/^([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/!d" "${src}" > "${temp_file}" - # 2. Add all supported ABP style lines (||subdomain.domain.tlp^) - sed -r "/^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\^$/!d" "${src}" >> "${temp_file}" + + # if there is at least one ABP style domains + if grep -E "^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" -m 1 -q "${src}"; then + echo " ${INFO} List contained AdBlock Plus style domains" + # 2. Add all supported ABP style lines (||subdomain.domain.tlp^) + sed -r "/^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\^$/!d" "${src}" >> "${temp_file}" + fi + # Find lines containing no domains or with invalid characters (not matching regex above) # This is simply everything that is not in $temp_file compared to $src From 48451df3e08054e8fb16dfa5219a9eed897d0667 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 24 Feb 2023 22:26:25 -0500 Subject: [PATCH 398/638] remove cpu quota --- advanced/Scripts/webpage.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 2d456b1943..147b491db7 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -566,7 +566,6 @@ After=network.target [Service] User=root -CPUQuota=20% Type=oneshot ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh From 31a9e189972c24c42ac959d12a09b1da689d4d1a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Feb 2023 10:57:18 +0000 Subject: [PATCH 399/638] Bump tox from 4.4.5 to 4.4.6 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.4.5 to 4.4.6. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.4.5...4.4.6) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 229d01352b..c7848e8d6b 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.2.1 pytest-xdist == 3.2.0 pytest-testinfra == 7.0.0 -tox == 4.4.5 +tox == 4.4.6 From 6cb0be82caca4ca7b642a292f3d5a16ab1b47bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 26 Feb 2023 10:34:17 +0100 Subject: [PATCH 400/638] Add flag abp_domains into info table to signal if abp domains have been found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 451a40fcde..39ac2ded66 100755 --- a/gravity.sh +++ b/gravity.sh @@ -137,6 +137,18 @@ update_gravity_timestamp() { return 0 } +# Update timestamp when the gravity table was last updated successfully +set_abp_info() { + pihole-FTL sqlite3 "${gravityDBfile}" "INSERT OR REPLACE INTO info (property,value) VALUES ('abp_domains',${abp_domains});" + status="$?" + + if [[ "${status}" -ne 0 ]]; then + echo -e "\\n ${CROSS} Unable to update ABP domain status in database ${gravityDBfile}\\n ${output}" + return 1 + fi + return 0 +} + # Import domains from file and store them in the specified database table database_table_from_file() { # Define locals @@ -519,6 +531,10 @@ gravity_DownloadBlocklists() { gravity_Blackbody=true } + +# global variable to indicate if we found ABP style domains during the gravity run +# is saved in gravtiy's info table to signal FTL if such domains are available +abp_domains=0 parseList() { local adlistID="${1}" src="${2}" target="${3}" temp_file temp_file_base non_domains sample_non_domains @@ -536,9 +552,10 @@ parseList() { # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already sed -r "/^([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/!d" "${src}" > "${temp_file}" - # if there is at least one ABP style domains + # if there is at least one ABP style domain if grep -E "^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" -m 1 -q "${src}"; then echo " ${INFO} List contained AdBlock Plus style domains" + abp_domains=1 # 2. Add all supported ABP style lines (||subdomain.domain.tlp^) sed -r "/^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\^$/!d" "${src}" >> "${temp_file}" fi @@ -1014,6 +1031,9 @@ fi # Update gravity timestamp update_gravity_timestamp +# Set abp_domain info field +set_abp_info + # Ensure proper permissions are set for the database chown pihole:pihole "${gravityDBfile}" chmod g+w "${piholeDir}" "${gravityDBfile}" From 16385af3ef473e4f148224bfc735e2582e666a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 26 Feb 2023 21:16:45 +0100 Subject: [PATCH 401/638] Use dedicated pattern variable to make RegEx reusable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gravity.sh b/gravity.sh index 39ac2ded66..8db728a401 100755 --- a/gravity.sh +++ b/gravity.sh @@ -536,7 +536,7 @@ gravity_DownloadBlocklists() { # is saved in gravtiy's info table to signal FTL if such domains are available abp_domains=0 parseList() { - local adlistID="${1}" src="${2}" target="${3}" temp_file temp_file_base non_domains sample_non_domains + local adlistID="${1}" src="${2}" target="${3}" temp_file temp_file_base non_domains sample_non_domains valid_domain_pattern abp_domain_pattern # Create a temporary file for the sed magic instead of using "${target}" directly # this allows to split the sed commands to improve readability @@ -547,17 +547,23 @@ parseList() { rm "${temp_file_base}" temp_file="/proc/$$/fd/3" - - # 1. Add all valid domains (adapted from https://stackoverflow.com/a/30007882) + # define valid domain patterns # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already - sed -r "/^([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$/!d" "${src}" > "${temp_file}" + # adapted from https://stackoverflow.com/a/30007882 + # supported ABP style: ||subdomain.domain.tlp^ + + valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" + abp_domain_pattern="\|\|${valid_domain_pattern}\^" + + + # 1. Add all valid domains + sed -r "/^${valid_domain_pattern}$/!d" "${src}" > "${temp_file}" - # if there is at least one ABP style domain - if grep -E "^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" -m 1 -q "${src}"; then + # 2. Add valid ABP style domains if there is at least one such domain + if grep -E "^${abp_domain_pattern}$" -m 1 -q "${src}"; then echo " ${INFO} List contained AdBlock Plus style domains" abp_domains=1 - # 2. Add all supported ABP style lines (||subdomain.domain.tlp^) - sed -r "/^\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\^$/!d" "${src}" >> "${temp_file}" + sed -r "/^${abp_domain_pattern}$/!d" "${src}" >> "${temp_file}" fi From 73de49323c13f1e87f68e272e9a71e12d03e3f65 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Tue, 21 Feb 2023 21:49:03 +0100 Subject: [PATCH 402/638] Remove systemd service and optionally override configs on uninstall This has been forgotten when adding the new native systemd service. Signed-off-by: MichaIng --- automated install/uninstall.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index c36027fced..7a1a290de1 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -193,6 +193,18 @@ removeNoPurge() { else service pihole-FTL stop fi + ${SUDO} rm -f /etc/systemd/system/pihole-FTL.service + if [[ -d '/etc/systemd/system/pihole-FTL.service.d' ]]; then + read -rp " ${QST} FTL service override directory /etc/systemd/system/pihole-FTL.service.d detected. Do you wish to remove this from your system? [y/N] " answer + case $answer in + [yY]*) + echo -ne " ${INFO} Removing /etc/systemd/system/pihole-FTL.service.d..." + ${SUDO} rm -R /etc/systemd/system/pihole-FTL.service.d + echo -e "${OVER} ${INFO} Removed /etc/systemd/system/pihole-FTL.service.d" + ;; + *) echo -e " ${INFO} Leaving /etc/systemd/system/pihole-FTL.service.d in place.";; + esac + fi ${SUDO} rm -f /etc/init.d/pihole-FTL ${SUDO} rm -f /usr/bin/pihole-FTL echo -e "${OVER} ${TICK} Removed pihole-FTL" From ddf972cede32c3b80fc25cfdab356c101d08f36e Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 8 Dec 2022 20:00:33 +0200 Subject: [PATCH 403/638] build: harden workflow permissions Signed-off-by: Alex --- .github/workflows/sync-back-to-dev.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index f689ae364c..8572ffde0f 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -5,8 +5,30 @@ on: branches: - master +# The section is needed to drop the default write-all permissions for all jobs +# that are granted on `push` event. By specifying any permission explicitly +# all others are set to none. By using the principle of least privilege the damage a compromised +# workflow can do (because of an injection or compromised third party tool or +# action) is restricted. Adding labels to issues, commenting +# on pull-requests, etc. may need additional permissions: +# +# Syntax for this section: +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions +# +# Reference for how to assign permissions on a job-by-job basis: +# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs +# +# Reference for available permissions that we can enable if needed: +# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token +permissions: {} + jobs: sync-branches: + # The job needs to be able to pull the code and create a pull request. + permissions: + contents: read # for actions/checkout + pull-requests: write # to create pull request + runs-on: ubuntu-latest name: Syncing branches steps: From 0b5da9f0dabccaf902aada60527c3a4b5855b925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 4 Mar 2023 10:36:07 +0100 Subject: [PATCH 404/638] Allow final dot (root zone) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 8db728a401..281d5d543a 100755 --- a/gravity.sh +++ b/gravity.sh @@ -552,7 +552,7 @@ parseList() { # adapted from https://stackoverflow.com/a/30007882 # supported ABP style: ||subdomain.domain.tlp^ - valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" + valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\.?" abp_domain_pattern="\|\|${valid_domain_pattern}\^" From 0b60601f863fff2453b5a1e9cb9f678d33e72b13 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 4 Mar 2023 10:57:42 +0000 Subject: [PATCH 405/638] Bump pytest from 7.2.1 to 7.2.2 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.2.1 to 7.2.2. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.2.1...7.2.2) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index c7848e8d6b..e64e8c6621 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ docker-compose == 1.29.2 -pytest == 7.2.1 +pytest == 7.2.2 pytest-xdist == 3.2.0 pytest-testinfra == 7.0.0 tox == 4.4.6 From d6f5552ccf4ee96c3ca137184b99307cf81b1496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 6 Mar 2023 21:16:51 +0100 Subject: [PATCH 406/638] Convert domain to lowercase in pihole -q MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/query.sh | 57 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index d48e9363f5..4061e17cab 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -30,33 +30,6 @@ gravityDBfile="${GRAVITYDB}" colfile="/opt/pihole/COL_TABLE" source "${colfile}" -# Scan an array of files for matching strings -scanList(){ - # Escape full stops - local domain="${1}" esc_domain="${1//./\\.}" lists="${2}" list_type="${3:-}" - - # Prevent grep from printing file path - cd "$piholeDir" || exit 1 - - # Prevent grep -i matching slowly: https://bit.ly/2xFXtUX - export LC_CTYPE=C - - # /dev/null forces filename to be printed when only one list has been generated - case "${list_type}" in - "exact" ) grep -i -E -l "(^|(?/dev/null;; - # Iterate through each regexp and check whether it matches the domainQuery - # If it does, print the matching regexp and continue looping - # Input 1 - regexps | Input 2 - domainQuery - "regex" ) - for list in ${lists}; do - if [[ "${domain}" =~ ${list} ]]; then - printf "%b\n" "${list}"; - fi - done;; - * ) grep -i "${esc_domain}" ${lists} /dev/null 2>/dev/null;; - esac -} - if [[ "${options}" == "-h" ]] || [[ "${options}" == "--help" ]]; then echo "Usage: pihole -q [option] Example: 'pihole -q -exact domain.com' @@ -88,11 +61,41 @@ case "${options}" in * ) domainQuery="${options}";; esac +# convert the domain to lowercase +domainQuery=$(echo "${domainQuery}" | tr '[:upper:]' '[:lower:]') + if [[ -n "${str:-}" ]]; then echo -e "${str}${COL_NC}\\nTry 'pihole -q --help' for more information." exit 1 fi +# Scan an array of files for matching strings +scanList(){ + # Escape full stops + local domain="${1}" esc_domain="${1//./\\.}" lists="${2}" list_type="${3:-}" + + # Prevent grep from printing file path + cd "$piholeDir" || exit 1 + + # Prevent grep -i matching slowly: https://bit.ly/2xFXtUX + export LC_CTYPE=C + + # /dev/null forces filename to be printed when only one list has been generated + case "${list_type}" in + "exact" ) grep -i -E -l "(^|(?/dev/null;; + # Iterate through each regexp and check whether it matches the domainQuery + # If it does, print the matching regexp and continue looping + # Input 1 - regexps | Input 2 - domainQuery + "regex" ) + for list in ${lists}; do + if [[ "${domain}" =~ ${list} ]]; then + printf "%b\n" "${list}"; + fi + done;; + * ) grep -i "${esc_domain}" ${lists} /dev/null 2>/dev/null;; + esac +} + scanDatabaseTable() { local domain table list_type querystr result extra domain="$(printf "%q" "${1}")" From 309ee789036708b77453e2c71f1a2a22180d85ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 7 Mar 2023 20:40:16 +0100 Subject: [PATCH 407/638] Use distinct variabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/query.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 4061e17cab..99c1cf0fc6 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -57,12 +57,12 @@ options=$(sed -E 's/ ?-(all|exact) ?//g' <<< "${options}") case "${options}" in "" ) str="No domain specified";; *" "* ) str="Unknown query option specified";; - *[![:ascii:]]* ) domainQuery=$(idn2 "${options}");; - * ) domainQuery="${options}";; + *[![:ascii:]]* ) rawDomainQuery=$(idn2 "${options}");; + * ) rawDomainQuery="${options}";; esac # convert the domain to lowercase -domainQuery=$(echo "${domainQuery}" | tr '[:upper:]' '[:lower:]') +domainQuery=$(echo "${rawDomainQuery}" | tr '[:upper:]' '[:lower:]') if [[ -n "${str:-}" ]]; then echo -e "${str}${COL_NC}\\nTry 'pihole -q --help' for more information." @@ -82,7 +82,7 @@ scanList(){ # /dev/null forces filename to be printed when only one list has been generated case "${list_type}" in - "exact" ) grep -i -E -l "(^|(?/dev/null;; + "exact" ) grep -i -E -l "(^|(?/dev/null;; # Iterate through each regexp and check whether it matches the domainQuery # If it does, print the matching regexp and continue looping # Input 1 - regexps | Input 2 - domainQuery @@ -92,7 +92,7 @@ scanList(){ printf "%b\n" "${list}"; fi done;; - * ) grep -i "${esc_domain}" ${lists} /dev/null 2>/dev/null;; + * ) grep -i "${esc_domain}" "${lists}" /dev/null 2>/dev/null;; esac } From 71e262c37f5582d54e5c7d9f05b4f61533ca81a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 14 Mar 2023 19:42:05 +0100 Subject: [PATCH 408/638] Revert "Allow final dot (root zone)" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 0b5da9f0dabccaf902aada60527c3a4b5855b925. Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 2 +- gravity.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ad25e86698..fa1cebbb7f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -230,7 +230,7 @@ initialize_debug() { # This is a function for visually displaying the current test that is being run. # Accepts one variable: the name of what is being diagnosed -# Colors do not show in the dasboard, but the icons do: [i], [✓], and [✗] +# Colors do not show in the dashboard, but the icons do: [i], [✓], and [✗] echo_current_diagnostic() { # Colors are used for visually distinguishing each test in the output # These colors do not show in the GUI, but the formatting will diff --git a/gravity.sh b/gravity.sh index 281d5d543a..8db728a401 100755 --- a/gravity.sh +++ b/gravity.sh @@ -552,7 +552,7 @@ parseList() { # adapted from https://stackoverflow.com/a/30007882 # supported ABP style: ||subdomain.domain.tlp^ - valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\.?" + valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" abp_domain_pattern="\|\|${valid_domain_pattern}\^" From c35ed6805159e3df319d0bb663cc145d5987a8af Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 27 Feb 2023 01:46:12 -0300 Subject: [PATCH 409/638] Allow `pihole -q` matching ABP subdomains Signed-off-by: RD WebDesign --- advanced/Scripts/query.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 463b090143..71309b5640 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -102,6 +102,16 @@ scanDatabaseTable() { table="${2}" list_type="${3:-}" + # Create search string for ABP entries + local abpentry="${domain}" searchstr + + searchstr="'||${abpentry}^'" + while [ "${abpentry}" != "${abpentry/./}" ] + do + abpentry=$(echo "${abpentry}" | cut -f 2- -d '.') + searchstr=$(echo "$searchstr, '||${abpentry}^'") + done + # As underscores are legitimate parts of domains, we escape them when using the LIKE operator. # Underscores are SQLite wildcards matching exactly one character. We obviously want to suppress this # behavior. The "ESCAPE '\'" clause specifies that an underscore preceded by an '\' should be matched @@ -109,12 +119,12 @@ scanDatabaseTable() { if [[ "${table}" == "gravity" ]]; then case "${exact}" in "exact" ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE domain = '${domain}'";; - * ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; + * ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE (domain IN (${searchstr}) OR domain LIKE '%${domain//_/\\_}%' ESCAPE '\\')";; esac else case "${exact}" in "exact" ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain = '${domain}'";; - * ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; + * ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND (domain IN (${searchstr}) OR domain LIKE '%${domain//_/\\_}%' ESCAPE '\\')";; esac fi From 20f8c6af3c3b10fa4be6bd23365ecd7b89c93cea Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 28 Feb 2023 15:55:02 -0300 Subject: [PATCH 410/638] Search for ABP entries only if they exist in gravity.db and use `abp_domains` property. Signed-off-by: RD WebDesign --- advanced/Scripts/query.sh | 40 +++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 71309b5640..c6a932b77d 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -102,29 +102,45 @@ scanDatabaseTable() { table="${2}" list_type="${3:-}" - # Create search string for ABP entries - local abpentry="${domain}" searchstr - - searchstr="'||${abpentry}^'" - while [ "${abpentry}" != "${abpentry/./}" ] - do - abpentry=$(echo "${abpentry}" | cut -f 2- -d '.') - searchstr=$(echo "$searchstr, '||${abpentry}^'") - done - # As underscores are legitimate parts of domains, we escape them when using the LIKE operator. # Underscores are SQLite wildcards matching exactly one character. We obviously want to suppress this # behavior. The "ESCAPE '\'" clause specifies that an underscore preceded by an '\' should be matched # as a literal underscore character. We pretreat the $domain variable accordingly to escape underscores. if [[ "${table}" == "gravity" ]]; then + local abpquerystr, abpfound, abpentry, searchstr + + # Are there ABP entries on gravity? + # Return 1 if abp_domain=1 or Zero if abp_domain=0 or not set + abpquerystr="SELECT EXISTS (SELECT 1 FROM info WHERE property='abp_domains' and value='1')" + abpfound="$(pihole-FTL sqlite3 "${gravityDBfile}" "${abpquerystr}")" 2> /dev/null + + # Create search string for ABP entries only if needed + if [ "${abpfound}" -eq 1 ]; then + abpentry="${domain}" + + searchstr="'||${abpentry}^'" + + # While a dot is found ... + while [ "${abpentry}" != "${abpentry/./}" ] + do + # ... remove text before the dot (including the dot) and append the result to $searchstr + abpentry=$(echo "${abpentry}" | cut -f 2- -d '.') + searchstr="$searchstr, '||${abpentry}^'" + done + + # The final search string will look like: + # "domain IN ('||sub2.sub1.domain.com^', '||sub1.domain.com^', '||domain.com^', '||com^') OR" + searchstr="domain IN (${searchstr}) OR " + fi + case "${exact}" in "exact" ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE domain = '${domain}'";; - * ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE (domain IN (${searchstr}) OR domain LIKE '%${domain//_/\\_}%' ESCAPE '\\')";; + * ) querystr="SELECT gravity.domain,adlist.address,adlist.enabled FROM gravity LEFT JOIN adlist ON adlist.id = gravity.adlist_id WHERE ${searchstr} domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; esac else case "${exact}" in "exact" ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain = '${domain}'";; - * ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND (domain IN (${searchstr}) OR domain LIKE '%${domain//_/\\_}%' ESCAPE '\\')";; + * ) querystr="SELECT domain,enabled FROM domainlist WHERE type = '${list_type}' AND domain LIKE '%${domain//_/\\_}%' ESCAPE '\\'";; esac fi From b9a6970bfd04b8fbe9f78bc849b5bddc776202eb Mon Sep 17 00:00:00 2001 From: William Blew Date: Thu, 16 Mar 2023 19:36:22 -0700 Subject: [PATCH 411/638] Fix addKey to handle substrings of existing keys Fix addKey to handle the case where a key is being added, and that key is the leading substring of an already existing key within that file. For example: add "server=192.168.1.1", when "server=192.168.1.178" already exists within the /etc/dnsmasq.d/01-pihole.conf file. Check pihole docker with PIHOLE_DNS="192.168.1.178;192.168.1.1". Its /etc/dnsmasq/01-pihole.conf will be missing its second server= entry. Add the test_key_addition_substr, to test addKey when its adding a substring key of an existing key in the file. Signed-off-by: William Blew --- advanced/Scripts/utils.sh | 2 +- test/test_any_utils.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 3751647292..9e7146069e 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -57,7 +57,7 @@ addKey(){ # touch file to prevent grep error if file does not exist yet touch "${file}" - if ! grep -q "^${key}" "${file}"; then + if ! grep -q "^${key}$" "${file}"; then # Key does not exist, add it. echo "${key}" >> "${file}" fi diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 5b4075d9b9..b3fabe6c48 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -40,6 +40,26 @@ def test_key_addition_works(host): assert expected_stdout == output.stdout +def test_key_addition_substr(host): + """Confirms addKey adds substring keys (no value) to a file""" + host.run( + """ + source /opt/pihole/utils.sh + addKey "./testoutput" "KEY_ONE" + addKey "./testoutput" "KEY_O" + addKey "./testoutput" "KEY_TWO" + addKey "./testoutput" "Y_TWO" + """ + ) + output = host.run( + """ + cat ./testoutput + """ + ) + expected_stdout = "KEY_ONE\nKEY_O\nKEY_TWO\nY_TWO\n" + assert expected_stdout == output.stdout + + def test_key_removal_works(host): """Confirms removeKey removes a key or key/value pair""" host.run( From 3c91b6558dcc947736e1df1631a9a7dfc7d32f9b Mon Sep 17 00:00:00 2001 From: William Blew Date: Fri, 17 Mar 2023 11:47:26 -0700 Subject: [PATCH 412/638] restore the addKey comment, reworded for anchors Per @dschaper, restore the addKey clarifying comment. It has been reworded to describe the use of anchors where before it referenced using grep's 'match only an entire line' argument. Signed-off-by: William Blew --- advanced/Scripts/utils.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 9e7146069e..f655e56ce0 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -57,6 +57,10 @@ addKey(){ # touch file to prevent grep error if file does not exist yet touch "${file}" + # Match key against entire line, using both anchors. We assume + # that the file's keys never have bounding whitespace. Anchors + # are necessary to ensure the key is considered absent when it + # is a substring of another key present in the file. if ! grep -q "^${key}$" "${file}"; then # Key does not exist, add it. echo "${key}" >> "${file}" From 3a592e56ba6b6e41d11f8fd3769a42892e4a3059 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 18 Mar 2023 10:56:52 +0000 Subject: [PATCH 413/638] Bump actions/checkout from 3.3.0 to 3.4.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.3.0 to 3.4.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.3.0...v3.4.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 5539cec9e9..01be8b2551 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 25c3a7f74e..0fe850d180 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce948e093d..27867ef3e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Check scripts in repository are executable run: | @@ -62,7 +62,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.5.0 From 8a2829de874aa1c90fba1ee38bfe44f5b480d3fe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 18 Mar 2023 10:58:49 +0000 Subject: [PATCH 414/638] Bump pytest-xdist from 3.2.0 to 3.2.1 in /test Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 3.2.0 to 3.2.1. - [Release notes](https://github.com/pytest-dev/pytest-xdist/releases) - [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v3.2.0...v3.2.1) --- updated-dependencies: - dependency-name: pytest-xdist dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index e64e8c6621..b2f0e8c458 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ docker-compose == 1.29.2 pytest == 7.2.2 -pytest-xdist == 3.2.0 +pytest-xdist == 3.2.1 pytest-testinfra == 7.0.0 tox == 4.4.6 From 686da5a9480fc1791c0623f7a035c84dceb23a06 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 18 Mar 2023 10:58:57 +0000 Subject: [PATCH 415/638] Bump tox from 4.4.6 to 4.4.7 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.4.6 to 4.4.7. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.4.6...4.4.7) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index e64e8c6621..ff2f49d0db 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.2.2 pytest-xdist == 3.2.0 pytest-testinfra == 7.0.0 -tox == 4.4.6 +tox == 4.4.7 From 493eb4b42a492dbc72a7f21db209864b3b5a89ca Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 19 Mar 2023 16:31:10 -0400 Subject: [PATCH 416/638] fix timer install --- 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 147b491db7..a24f200bb1 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -577,12 +577,12 @@ EOF' [Unit] Description=Pi-hole Speedtest Timer -[Timer] -OnCalendar='$freq' -Persistent=true - [Install] WantedBy=timers.target + +[Timer] +Persistent=true +OnCalendar='$freq' EOF' systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null From 6b919f3a2e36f724e8dd2a8f3b4e518d28de20a1 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 21 Mar 2023 12:27:20 -0300 Subject: [PATCH 417/638] Removing unnecessary commas Signed-off-by: RD WebDesign --- advanced/Scripts/query.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index c6a932b77d..604ac2edad 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -107,7 +107,7 @@ scanDatabaseTable() { # behavior. The "ESCAPE '\'" clause specifies that an underscore preceded by an '\' should be matched # as a literal underscore character. We pretreat the $domain variable accordingly to escape underscores. if [[ "${table}" == "gravity" ]]; then - local abpquerystr, abpfound, abpentry, searchstr + local abpquerystr abpfound abpentry searchstr # Are there ABP entries on gravity? # Return 1 if abp_domain=1 or Zero if abp_domain=0 or not set From 90333c375efec1fabf3e9c3d42a81084e64d1b5a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 21 Mar 2023 12:13:07 -0400 Subject: [PATCH 418/638] upstream typo --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ad25e86698..fa1cebbb7f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -230,7 +230,7 @@ initialize_debug() { # This is a function for visually displaying the current test that is being run. # Accepts one variable: the name of what is being diagnosed -# Colors do not show in the dasboard, but the icons do: [i], [✓], and [✗] +# Colors do not show in the dashboard, but the icons do: [i], [✓], and [✗] echo_current_diagnostic() { # Colors are used for visually distinguishing each test in the output # These colors do not show in the GUI, but the formatting will From 66ed7c9ea374cc7c322807b6a0fc5cb33ac45d80 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 21 Mar 2023 16:34:50 -0300 Subject: [PATCH 419/638] Declaring all local variables under the function declaration line Signed-off-by: RD WebDesign --- advanced/Scripts/query.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 604ac2edad..12295fbcfc 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -97,7 +97,7 @@ scanList(){ } scanDatabaseTable() { - local domain table list_type querystr result extra + local domain table list_type querystr result extra abpquerystr abpfound abpentry searchstr domain="$(printf "%q" "${1}")" table="${2}" list_type="${3:-}" @@ -107,7 +107,6 @@ scanDatabaseTable() { # behavior. The "ESCAPE '\'" clause specifies that an underscore preceded by an '\' should be matched # as a literal underscore character. We pretreat the $domain variable accordingly to escape underscores. if [[ "${table}" == "gravity" ]]; then - local abpquerystr abpfound abpentry searchstr # Are there ABP entries on gravity? # Return 1 if abp_domain=1 or Zero if abp_domain=0 or not set From 76b7453f902c50364a0ca688ef06eb106116f0f4 Mon Sep 17 00:00:00 2001 From: kot0dama <89980752+kot0dama@users.noreply.github.com> Date: Sun, 19 Mar 2023 05:32:46 +0100 Subject: [PATCH 420/638] Add configurable GRAVITY_TMPDIR variable into setupVars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Gomez <89980752+kot0dama@users.noreply.github.com> --- gravity.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 8db728a401..ca859e3802 100755 --- a/gravity.sh +++ b/gravity.sh @@ -52,6 +52,14 @@ else exit 1 fi +# Set up tmp dir variable in case it's not configured +: "${GRAVITY_TMPDIR:=/tmp}" + +if [ ! -d "${GRAVITY_TMPDIR}" ] || [ ! -w "${GRAVITY_TMPDIR}" ]; then + echo -e " ${COL_LIGHT_RED}Gravity temporary directory does not exist or is not a writeable directory, falling back to /tmp. ${COL_NC}" + GRAVITY_TMPDIR="/tmp" +fi + # Source pihole-FTL from install script pihole_FTL="${piholeDir}/pihole-FTL.conf" if [[ -f "${pihole_FTL}" ]]; then @@ -157,7 +165,7 @@ database_table_from_file() { src="${2}" backup_path="${piholeDir}/migration_backup" backup_file="${backup_path}/$(basename "${2}")" - tmpFile="$(mktemp -p "/tmp" --suffix=".gravity")" + tmpFile="$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".gravity")" local timestamp timestamp="$(date --utc +'%s')" @@ -430,7 +438,7 @@ gravity_DownloadBlocklists() { echo -e "${OVER} ${TICK} ${str}" fi - target="$(mktemp -p "/tmp" --suffix=".gravity")" + target="$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".gravity")" # Use compression to reduce the amount of data that is transferred # between the Pi-hole and the ad list provider. Use this feature @@ -643,7 +651,7 @@ gravity_DownloadBlocklistFromUrl() { local heisenbergCompensator="" patternBuffer str httpCode success="" ip # Create temp file to store content on disk instead of RAM - patternBuffer=$(mktemp -p "/tmp" --suffix=".phgpb") + patternBuffer=$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".phgpb") # Determine if $saveLocation has read permission if [[ -r "${saveLocation}" && $url != "file"* ]]; then @@ -860,7 +868,7 @@ gravity_Cleanup() { # Delete tmp content generated by Gravity rm ${piholeDir}/pihole.*.txt 2> /dev/null rm ${piholeDir}/*.tmp 2> /dev/null - rm /tmp/*.phgpb 2> /dev/null + rm "${GRAVITY_TMPDIR}"/*.phgpb 2> /dev/null # Ensure this function only runs when gravity_SetDownloadOptions() has completed if [[ "${gravity_Blackbody:-}" == true ]]; then From 58275ecd132d6f56529592baf02b207ee89f73dc Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 22 Mar 2023 21:52:39 +0000 Subject: [PATCH 421/638] Revert "Ignore commented lines when reading PRIVACYLEVEL from config file" --- advanced/Scripts/utils.sh | 22 ++-------------------- automated install/basic-install.sh | 3 +-- test/test_any_utils.py | 16 ---------------- 3 files changed, 3 insertions(+), 38 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 2d3c7fb18f..f655e56ce0 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -44,7 +44,7 @@ addOrEditKeyValPair() { } ####################### -# Takes two arguments: file and key. +# Takes two arguments: file, and key. # Adds a key to target file # # Example usage: @@ -68,7 +68,7 @@ addKey(){ } ####################### -# Takes two arguments: file and key. +# Takes two arguments: file, and key. # Deletes a key or key/value pair from target file # # Example usage: @@ -80,24 +80,6 @@ removeKey() { sed -i "/^${key}/d" "${file}" } -####################### -# Takes two arguments: file and key. -# Returns the value of a given key from target file -# - ignores all commented lines -# - only returns the first value if multiple identical keys exist -# -# -# Example usage: -# getVal "/etc/pihole/setupVars.conf" "PIHOLE_DNS_1" -####################### -getVal() { - local file="${1}" - local key="${2}" - local value - value=$(sed -e '/^[[:blank:]]*#/d' "${file}" | grep "${key}" | awk -F "=" 'NR==1{printf$2}') - printf "%s" "$value" -} - ####################### # returns FTL's current telnet API port based on the setting in /etc/pihole-FTL.conf diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a781f8c692..ccb5eac72a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2612,8 +2612,7 @@ main() { # Get the privacy level if it exists (default is 0) if [[ -f "${FTL_CONFIG_FILE}" ]]; then - # use getVal from utils.sh to get PRIVACYLEVEL - PRIVACY_LEVEL=$(getVal "${FTL_CONFIG_FILE}" "PRIVACYLEVEL") + PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${FTL_CONFIG_FILE}") # If no setting was found, default to 0 PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" diff --git a/test/test_any_utils.py b/test/test_any_utils.py index cb5ddeaade..b3fabe6c48 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -82,22 +82,6 @@ def test_key_removal_works(host): assert expected_stdout == output.stdout -def test_get_value_works(host): - """Confirms getVal returns the correct value for a given key""" - output = host.run( - """ - source /opt/pihole/utils.sh - echo "Somekey=xxx" >> /tmp/testfile - echo "#Testkey=1234" >> /tmp/testfile - echo "Testkey=5678" >> /tmp/testfile - echo "Testkey=abcd" >> /tmp/testfile - getVal "/tmp/testfile" "Testkey" - """ - ) - expected_stdout = "5678" - assert expected_stdout == output.stdout - - def test_getFTLAPIPort_default(host): """Confirms getFTLAPIPort returns the default API port""" output = host.run( From c96463bda20ca261286c7b4e7dc2a5dbc1103723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 22 Mar 2023 22:56:00 +0100 Subject: [PATCH 422/638] Fix getting 'privacylevel' 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ccb5eac72a..24fe9e547a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2612,7 +2612,8 @@ main() { # Get the privacy level if it exists (default is 0) if [[ -f "${FTL_CONFIG_FILE}" ]]; then - PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${FTL_CONFIG_FILE}") + # get the value from $FTL_CONFIG_FILE (and ignoring all commented lines) + PRIVACY_LEVEL=$(sed -e '/^[[:blank:]]*#/d' "${FTL_CONFIG_FILE}" | grep "PRIVACYLEVEL" | awk -F "=" 'NR==1{printf$2}') # If no setting was found, default to 0 PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" From fa116389c25ad45d284e8633aa7f9395599639af Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 23 Mar 2023 01:23:35 +0000 Subject: [PATCH 423/638] remove old comments Signed-off-by: ipitio <21136719+ipitio@users.noreply.github.com> --- advanced/Scripts/piholeDebug.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index fa1cebbb7f..6f747855d9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -230,10 +230,8 @@ initialize_debug() { # This is a function for visually displaying the current test that is being run. # Accepts one variable: the name of what is being diagnosed -# Colors do not show in the dashboard, but the icons do: [i], [✓], and [✗] echo_current_diagnostic() { # Colors are used for visually distinguishing each test in the output - # These colors do not show in the GUI, but the formatting will log_write "\\n${COL_PURPLE}*** [ DIAGNOSING ]:${COL_NC} ${1}" } From 95b12bad34a3fe719866f4f96cdbe9cea12ee039 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Mar 2023 10:56:35 +0000 Subject: [PATCH 424/638] Bump actions/stale from 7.0.0 to 8.0.0 Bumps [actions/stale](https://github.com/actions/stale) from 7.0.0 to 8.0.0. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v7.0.0...v8.0.0) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- .github/workflows/stale_pr.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 58a2e64767..071746a8a6 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,7 +13,7 @@ jobs: issues: write steps: - - uses: actions/stale@v7.0.0 + - uses: actions/stale@v8.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 diff --git a/.github/workflows/stale_pr.yml b/.github/workflows/stale_pr.yml index c45e3cb750..2db2a25d5e 100644 --- a/.github/workflows/stale_pr.yml +++ b/.github/workflows/stale_pr.yml @@ -17,7 +17,7 @@ jobs: pull-requests: write steps: - - uses: actions/stale@v7.0.0 + - uses: actions/stale@v8.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} # Do not automatically mark PR/issue as stale From 0656ceb149a25bb424f654da74ae0f34e6b4efd0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 24 Mar 2023 23:15:49 +0000 Subject: [PATCH 425/638] Speed things up a bit with some humble greps. Consolodate regexes and remove the need for so many mapfile/arrays Signed-off-by: Adam Warner Use temp files for parsing and remove when done. Always rm the non-domains temp file. exit 1 if gravity database creation fails. Signed-off-by: Dan Schaper Co-authored-by: Dan Schaper Co-authored-by: DL6ER Co-authored-by: Adam Warner --- gravity.sh | 94 ++++++++++++++++++++---------------------------------- 1 file changed, 35 insertions(+), 59 deletions(-) diff --git a/gravity.sh b/gravity.sh index ca859e3802..a415aa012a 100755 --- a/gravity.sh +++ b/gravity.sh @@ -546,15 +546,6 @@ abp_domains=0 parseList() { local adlistID="${1}" src="${2}" target="${3}" temp_file temp_file_base non_domains sample_non_domains valid_domain_pattern abp_domain_pattern - # Create a temporary file for the sed magic instead of using "${target}" directly - # this allows to split the sed commands to improve readability - # we use a file handle here and remove the temporary file immediately so the content will be deleted in any case - # when the script stops - temp_file_base="$(mktemp -p "/tmp" --suffix=".gravity")" - exec 3>"$temp_file_base" - rm "${temp_file_base}" - temp_file="/proc/$$/fd/3" - # define valid domain patterns # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already # adapted from https://stackoverflow.com/a/30007882 @@ -563,62 +554,39 @@ parseList() { valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" abp_domain_pattern="\|\|${valid_domain_pattern}\^" - - # 1. Add all valid domains - sed -r "/^${valid_domain_pattern}$/!d" "${src}" > "${temp_file}" - - # 2. Add valid ABP style domains if there is at least one such domain - if grep -E "^${abp_domain_pattern}$" -m 1 -q "${src}"; then - echo " ${INFO} List contained AdBlock Plus style domains" - abp_domains=1 - sed -r "/^${abp_domain_pattern}$/!d" "${src}" >> "${temp_file}" - fi - - - # Find lines containing no domains or with invalid characters (not matching regex above) - # This is simply everything that is not in $temp_file compared to $src - # Remove duplicates from the list - mapfile -t non_domains < <(grep -Fvf "${temp_file}" "${src}" | sort -u ) - - # 3. Remove trailing period (see https://github.com/pi-hole/pi-hole/issues/4701) - # 4. Append ,adlistID to every line - # 5. Ensures there is a newline on the last line - # and write everything to the target file - sed "s/\.$//;s/$/,${adlistID}/;/.$/a\\" "${temp_file}" >> "${target}" - # A list of items of common local hostnames not to report as unusable # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files # but flagging them as unusable causes more confusion than it's worth - so we suppress them from the output false_positives="localhost|localhost.localdomain|local|broadcasthost|localhost|ip6-localhost|ip6-loopback|lo0 localhost|ip6-localnet|ip6-mcastprefix|ip6-allnodes|ip6-allrouters|ip6-allhosts" - # if there are any non-domains, filter the array for false-positives - # Credit: https://stackoverflow.com/a/40264051 - if [[ "${#non_domains[@]}" -gt 0 ]]; then - mapfile -d $'\0' -t non_domains < <(printf '%s\0' "${non_domains[@]}" | grep -Ezv "^${false_positives}") + # Extract valid domains from source file and append ,${adlistID} to each line and save count to variable for display. + num_domains=$(grep -E "^(${valid_domain_pattern}|${abp_domain_pattern})$" "${src}" | tee >(sed "s/$/,${adlistID}/" >> "${target}") | wc -l) + + # Check if the source file contained AdBlock Plus style domains, if so we set the global variable and inform the user + if grep -E "^${abp_domain_pattern}$" -m 1 -q "${src}"; then + echo " ${INFO} List contained AdBlock Plus style domains" + abp_domains=1 fi - # Get a sample of non-domain entries, limited to 5 (the list should already have been de-duplicated) - IFS=" " read -r -a sample_non_domains <<< "$(tr ' ' '\n' <<< "${non_domains[@]}" | head -n 5 | tr '\n' ' ')" + # For completeness, we will get a count of non_domains (this is the number of entries left after stripping the source of comments/duplicates/false positives/domains) + invalid_domains="$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".ph-non-domains")" - # Get the number of domains added - num_domains="$(grep -c "^" "${temp_file}")" - # Get the number of non_domains (this is the number of entries left after stripping the source of comments/duplicates/false positives/domains) - num_non_domains="${#non_domains[@]}" + num_non_domains=$(grep -Ev "^(${valid_domain_pattern}|${abp_domain_pattern}|${false_positives})$" "${src}" | tee "${invalid_domains}" | wc -l) # If there are unusable lines, we display some information about them. This is not error or major cause for concern. if [[ "${num_non_domains}" -ne 0 ]]; then - echo " ${INFO} Imported ${num_domains} domains, ignoring ${num_non_domains} non-domain entries" + type="domains" + if [[ "${abp_domains}" -ne 0 ]]; then + type="patterns" + fi + echo " ${INFO} Imported ${num_domains} ${type}, ignoring ${num_non_domains} non-domain entries" echo " Sample of non-domain entries:" - for each in "${sample_non_domains[@]}" - do - echo " - ${each}" - done + invalid_lines=$(head -n 5 "${invalid_domains}") + echo "${invalid_lines}" | awk '{print " - " $0}' else echo " ${INFO} Imported ${num_domains} domains" fi - - # close file handle - exec 3<&- + rm "${invalid_domains}" } compareLists() { @@ -648,10 +616,10 @@ compareLists() { # Download specified URL and perform checks on HTTP status and file content gravity_DownloadBlocklistFromUrl() { local url="${1}" cmd_ext="${2}" agent="${3}" adlistID="${4}" saveLocation="${5}" target="${6}" compression="${7}" - local heisenbergCompensator="" patternBuffer str httpCode success="" ip + local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip # Create temp file to store content on disk instead of RAM - patternBuffer=$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".phgpb") + listCurlBuffer=$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".phgpb") # Determine if $saveLocation has read permission if [[ -r "${saveLocation}" && $url != "file"* ]]; then @@ -705,12 +673,12 @@ gravity_DownloadBlocklistFromUrl() { fi # shellcheck disable=SC2086 - httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${patternBuffer}" 2> /dev/null) + httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${listCurlBuffer}" 2> /dev/null) case $url in # Did we "download" a local file? "file"*) - if [[ -s "${patternBuffer}" ]]; then + if [[ -s "${listCurlBuffer}" ]]; then echo -e "${OVER} ${TICK} ${str} Retrieval successful"; success=true else echo -e "${OVER} ${CROSS} ${str} Not found / empty list" @@ -743,10 +711,12 @@ gravity_DownloadBlocklistFromUrl() { database_adlist_status "${adlistID}" "2" database_adlist_number "${adlistID}" done="true" - # Check if $patternbuffer is a non-zero length file - elif [[ -s "${patternBuffer}" ]]; then + # Check if $listCurlBuffer is a non-zero length file + elif [[ -s "${listCurlBuffer}" ]]; then # Determine if blocklist is non-standard and parse as appropriate - gravity_ParseFileIntoDomains "${patternBuffer}" "${saveLocation}" + gravity_ParseFileIntoDomains "${listCurlBuffer}" "${saveLocation}" + # Remove curl buffer file after its use + rm "${listCurlBuffer}" # Add domains to database table file parseList "${adlistID}" "${saveLocation}" "${target}" # Compare lists, are they identical? @@ -756,7 +726,7 @@ gravity_DownloadBlocklistFromUrl() { database_adlist_number "${adlistID}" done="true" else - # Fall back to previously cached list if $patternBuffer is empty + # Fall back to previously cached list if $listCurlBuffer is empty echo -e " ${INFO} Received empty file" fi fi @@ -868,7 +838,10 @@ gravity_Cleanup() { # Delete tmp content generated by Gravity rm ${piholeDir}/pihole.*.txt 2> /dev/null rm ${piholeDir}/*.tmp 2> /dev/null + # listCurlBuffer location rm "${GRAVITY_TMPDIR}"/*.phgpb 2> /dev/null + # invalid_domains location + rm "${GRAVITY_TMPDIR}"/*.ph-non-domains 2> /dev/null # Ensure this function only runs when gravity_SetDownloadOptions() has completed if [[ "${gravity_Blackbody:-}" == true ]]; then @@ -1031,7 +1004,10 @@ if ! gravity_CheckDNSResolutionAvailable; then exit 1 fi -gravity_DownloadBlocklists +if ! gravity_DownloadBlocklists; then + echo -e " ${CROSS} Unable to create gravity database. Please try again later. If the problem persists, please contact support." + exit 1 +fi # Create local.list gravity_generateLocalList From c71460e4b69fc97b5ec5e50f5401ae4a9d12314c Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 28 Mar 2023 16:41:11 -0300 Subject: [PATCH 426/638] Allow TLD blocking using ABP style This validates patterns without dots (only for abp style), allowing TLDs to be blocked Signed-off-by: RD WebDesign --- gravity.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index a415aa012a..19471ccee1 100755 --- a/gravity.sh +++ b/gravity.sh @@ -549,10 +549,12 @@ parseList() { # define valid domain patterns # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already # adapted from https://stackoverflow.com/a/30007882 - # supported ABP style: ||subdomain.domain.tlp^ valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" - abp_domain_pattern="\|\|${valid_domain_pattern}\^" + + # supported ABP style: ||subdomain.domain.tld^ + # allow TLD blocking using ABP style: ||tld^ + abp_domain_pattern="\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)*[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\^" # A list of items of common local hostnames not to report as unusable # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files From 32fb2e69ff26e057bc6754197b5d343889dc63e7 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 29 Mar 2023 00:02:42 -0300 Subject: [PATCH 427/638] Spliting the regex into TLD_pattern and subdomain_pattern Signed-off-by: RD WebDesign --- gravity.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 19471ccee1..431593785b 100755 --- a/gravity.sh +++ b/gravity.sh @@ -550,11 +550,14 @@ parseList() { # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already # adapted from https://stackoverflow.com/a/30007882 - valid_domain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" + TLD_pattern="[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" + subdomain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)" + + valid_domain_pattern="${subdomain_pattern}+${TLD_pattern}" # supported ABP style: ||subdomain.domain.tld^ - # allow TLD blocking using ABP style: ||tld^ - abp_domain_pattern="\|\|([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)*[a-z0-9][a-z0-9-]{0,61}[a-z0-9]\^" + # Subdomain is optional for ABP style, allowing TLD blocking: ||tld^ + abp_domain_pattern="\|\|${subdomain_pattern}*${TLD_pattern}\^" # A list of items of common local hostnames not to report as unusable # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files From 66bfa606a7d2b3abb5ddffb673e23db6d5028985 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Wed, 29 Mar 2023 14:17:41 -0300 Subject: [PATCH 428/638] Using a better text for the comment Signed-off-by: RD WebDesign --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 431593785b..34cad67d53 100755 --- a/gravity.sh +++ b/gravity.sh @@ -556,7 +556,7 @@ parseList() { valid_domain_pattern="${subdomain_pattern}+${TLD_pattern}" # supported ABP style: ||subdomain.domain.tld^ - # Subdomain is optional for ABP style, allowing TLD blocking: ||tld^ + # ${subdomain_pattern} is optional for ABP style, allowing TLD blocking: ||tld^ abp_domain_pattern="\|\|${subdomain_pattern}*${TLD_pattern}\^" # A list of items of common local hostnames not to report as unusable From 61ff5b2c761b3c8c511cd2628758dcab626094d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 09:44:31 +0200 Subject: [PATCH 429/638] Unifiy sed commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: RD WebDesign Signed-off-by: Christian König --- gravity.sh | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/gravity.sh b/gravity.sh index 34cad67d53..6ec53038fb 100755 --- a/gravity.sh +++ b/gravity.sh @@ -768,25 +768,21 @@ gravity_ParseFileIntoDomains() { tr '[:upper:]' '[:lower:]' < "${src}" > "${destination}" # 2) Remove carriage returns - sed -i 's/\r$//' "${destination}" - - # 3a) Remove comments (text starting with "#", include possible spaces before the hash sign) - sed -i 's/\s*#.*//g' "${destination}" - - # 3b) Remove lines starting with ! (ABP Comments) - sed -i 's/\s*!.*//g' "${destination}" - - # 3c) Remove lines starting with [ (ABP Header) - sed -i 's/\s*\[.*//g' "${destination}" - - # 4) Remove lines containing "/" - sed -i -r '/(\/).*$/d' "${destination}" - - # 5) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) - sed -i -r 's/^.*\s+//g' "${destination}" - - # 6) Remove empty lines - sed -i '/^$/d' "${destination}" + # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) + # 4) Remove lines starting with ! (ABP Comments) + # 5) Remove lines starting with [ (ABP Header) + # 6) Remove lines containing "/" + # 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) + # 8) Remove empty lines + + sed -i -r \ + -e 's/\r$//' \ + -e 's/\s*#.*//g' \ + -e 's/\s*!.*//g' \ + -e 's/\s*\[.*//g' \ + -e '/(\/).*$/d' \ + -e 's/^.*\s+//g' \ + -e '/^$/d' "${destination}" chmod 644 "${destination}" } From cc17fe18a9863d6149957728b5f3f3877cc15ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 10:14:59 +0200 Subject: [PATCH 430/638] Remove lines with ABP extended CSS selector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adam Warner Signed-off-by: Christian König --- gravity.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/gravity.sh b/gravity.sh index 6ec53038fb..6ba2711948 100755 --- a/gravity.sh +++ b/gravity.sh @@ -768,18 +768,20 @@ gravity_ParseFileIntoDomains() { tr '[:upper:]' '[:lower:]' < "${src}" > "${destination}" # 2) Remove carriage returns - # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) - # 4) Remove lines starting with ! (ABP Comments) - # 5) Remove lines starting with [ (ABP Header) - # 6) Remove lines containing "/" - # 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) - # 8) Remove empty lines + # 3) Remove lines starting with ! (ABP Comments) + # 4) Remove lines starting with [ (ABP Header) + # 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") + # 6) Remove comments (text starting with "#", include possible spaces before the hash sign) + # 7) Remove lines containing "/" + # 8) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) + # 9) Remove empty lines sed -i -r \ -e 's/\r$//' \ - -e 's/\s*#.*//g' \ -e 's/\s*!.*//g' \ -e 's/\s*\[.*//g' \ + -e '/\#[!|?|@]{0,1}\#/d' \ + -e 's/\s*#.*//g' \ -e '/(\/).*$/d' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}" From 2a0f72015364979fb1955e02bdb27ed13a62efe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 10:25:25 +0200 Subject: [PATCH 431/638] Don't delete lines containing `/` as they should count as invalid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 6ba2711948..f978cd0aaa 100755 --- a/gravity.sh +++ b/gravity.sh @@ -772,9 +772,8 @@ gravity_ParseFileIntoDomains() { # 4) Remove lines starting with [ (ABP Header) # 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") # 6) Remove comments (text starting with "#", include possible spaces before the hash sign) - # 7) Remove lines containing "/" - # 8) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) - # 9) Remove empty lines + # 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) + # 8) Remove empty lines sed -i -r \ -e 's/\r$//' \ @@ -782,7 +781,6 @@ gravity_ParseFileIntoDomains() { -e 's/\s*\[.*//g' \ -e '/\#[!|?|@]{0,1}\#/d' \ -e 's/\s*#.*//g' \ - -e '/(\/).*$/d' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}" From 9c4e74ffa7ec1425820c22f0eca463277bfbea7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 12:23:11 +0200 Subject: [PATCH 432/638] Remove special handling of pgl.yoyo.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/gravity.sh b/gravity.sh index 34cad67d53..54b521eb56 100755 --- a/gravity.sh +++ b/gravity.sh @@ -463,12 +463,6 @@ gravity_DownloadBlocklists() { # Default user-agent (for Cloudflare's Browser Integrity Check: https://support.cloudflare.com/hc/en-us/articles/200170086-What-does-the-Browser-Integrity-Check-do-) agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36" - # Provide special commands for blocklists which may need them - case "${domain}" in - "pgl.yoyo.org") cmd_ext="-d mimetype=plaintext -d hostformat=hosts";; - *) cmd_ext="";; - esac - echo -e " ${INFO} Target: ${url}" local regex check_url # Check for characters NOT allowed in URLs From aaf828117d6435fdb9885aa8940dee05275f7eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 12:36:50 +0200 Subject: [PATCH 433/638] Remove unecessary $cmd_ext MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gravity.sh b/gravity.sh index 54b521eb56..5cb6885060 100755 --- a/gravity.sh +++ b/gravity.sh @@ -421,7 +421,7 @@ gravity_DownloadBlocklists() { unset sources fi - local url domain agent cmd_ext str target compression + local url domain agent str target compression echo "" # Prepare new gravity database @@ -475,7 +475,7 @@ gravity_DownloadBlocklists() { if [[ "${check_url}" =~ ${regex} ]]; then echo -e " ${CROSS} Invalid Target" else - gravity_DownloadBlocklistFromUrl "${url}" "${cmd_ext}" "${agent}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" + gravity_DownloadBlocklistFromUrl "${url}" "${agent}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" fi echo "" done @@ -614,8 +614,8 @@ compareLists() { # Download specified URL and perform checks on HTTP status and file content gravity_DownloadBlocklistFromUrl() { - local url="${1}" cmd_ext="${2}" agent="${3}" adlistID="${4}" saveLocation="${5}" target="${6}" compression="${7}" - local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip + local url="${1}" agent="${2}" adlistID="${3}" saveLocation="${4}" target="${5}" compression="${6}" + local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip cmd_ext # Create temp file to store content on disk instead of RAM listCurlBuffer=$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".phgpb") @@ -668,7 +668,7 @@ gravity_DownloadBlocklistFromUrl() { bad_list=$(pihole -q -adlist "${domain}" | head -n1 | awk -F 'Match found in ' '{print $2}') echo -e "${OVER} ${CROSS} ${str} ${domain} is blocked by ${bad_list%:}. Using DNS on ${PIHOLE_DNS_1} to download ${url}"; echo -ne " ${INFO} ${str} Pending..." - cmd_ext="--resolve $domain:$port:$ip $cmd_ext" + cmd_ext="--resolve $domain:$port:$ip" fi # shellcheck disable=SC2086 From d10d59303e48703cb167164b246b1deead4db984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 7 Apr 2023 21:44:49 +0200 Subject: [PATCH 434/638] There is no ! but an $ rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index f978cd0aaa..7c40bc0dd9 100755 --- a/gravity.sh +++ b/gravity.sh @@ -779,7 +779,7 @@ gravity_ParseFileIntoDomains() { -e 's/\r$//' \ -e 's/\s*!.*//g' \ -e 's/\s*\[.*//g' \ - -e '/\#[!|?|@]{0,1}\#/d' \ + -e '/\#[$?@]{0,1}\#/d' \ -e 's/\s*#.*//g' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}" From dd3a7a4edb20edef094bc64e7348cfe769382140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 8 Apr 2023 08:01:46 +0200 Subject: [PATCH 435/638] Only delete lines containing separator when preceded by a letter to reduce false positiv (deleting valid comments) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7c40bc0dd9..925f47243d 100755 --- a/gravity.sh +++ b/gravity.sh @@ -770,7 +770,7 @@ gravity_ParseFileIntoDomains() { # 2) Remove carriage returns # 3) Remove lines starting with ! (ABP Comments) # 4) Remove lines starting with [ (ABP Header) - # 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") + # 5) Remove lines containing ABP extended CSS selectors ("##", "#!#", "#@#", "#?#") preceded by a letter # 6) Remove comments (text starting with "#", include possible spaces before the hash sign) # 7) Remove leading tabs, spaces, etc. (Also removes leading IP addresses) # 8) Remove empty lines @@ -779,7 +779,7 @@ gravity_ParseFileIntoDomains() { -e 's/\r$//' \ -e 's/\s*!.*//g' \ -e 's/\s*\[.*//g' \ - -e '/\#[$?@]{0,1}\#/d' \ + -e '/[a-z]\#[$?@]{0,1}\#/d' \ -e 's/\s*#.*//g' \ -e 's/^.*\s+//g' \ -e '/^$/d' "${destination}" From 87a612f88436492c936903504196c37ebbfc0851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 15 Apr 2023 10:28:39 +0200 Subject: [PATCH 436/638] Trigger stale workflow on issue comments to remove stale label immediately MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 58a2e64767..fa399be607 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -4,6 +4,7 @@ on: schedule: - cron: '0 8 * * *' workflow_dispatch: + issue_comment: jobs: stale: From c36d0257ec48d52237da08e22021a4ededa8177f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 15 Apr 2023 10:57:39 +0000 Subject: [PATCH 437/638] Bump tox from 4.4.7 to 4.4.12 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.4.7 to 4.4.12. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.4.7...4.4.12) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 8ba6156f28..be498400a5 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.2.2 pytest-xdist == 3.2.1 pytest-testinfra == 7.0.0 -tox == 4.4.7 +tox == 4.4.12 From d065afdbb19b1b1eeddbebe64738a4f8a5665048 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 15 Apr 2023 10:57:41 +0000 Subject: [PATCH 438/638] Bump actions/checkout from 3.4.0 to 3.5.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.4.0 to 3.5.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.4.0...v3.5.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 01be8b2551..f3bcf15a7f 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 0fe850d180..fa7564a348 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.2 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 27867ef3e9..cd8a4030ca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.2 - name: Check scripts in repository are executable run: | @@ -62,7 +62,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.2 - name: Set up Python 3.10 uses: actions/setup-python@v4.5.0 From 364fd38996656515a4fca1760e27eea8b946bf34 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 15 Apr 2023 12:34:19 +0000 Subject: [PATCH 439/638] Bump pytest from 7.2.2 to 7.3.1 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.2.2 to 7.3.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.2.2...7.3.1) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index be498400a5..8cd3ca7797 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ docker-compose == 1.29.2 -pytest == 7.2.2 +pytest == 7.3.1 pytest-xdist == 3.2.1 pytest-testinfra == 7.0.0 tox == 4.4.12 From 5985d506f1e17bcc205d4b795a6635dc2d75c043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 16 Apr 2023 14:39:13 +0200 Subject: [PATCH 440/638] Run seperate job to trigger removal on comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index fa399be607..786940b25c 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -7,8 +7,8 @@ on: issue_comment: jobs: - stale: - + stale_action: + if: github.event_name != 'issue_comment' runs-on: ubuntu-latest permissions: issues: write @@ -25,3 +25,18 @@ jobs: exempt-all-issue-assignees: true operations-per-run: 300 close-issue-reason: 'not_planned' + + remove_stale: # trigger "stale" removal immediately when stale issues are commented on + if: github.event_name == 'issue_comment' + permissions: + contents: read # for actions/checkout + issues: write # to edit issues label + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3.4.0 + - name: Remove 'stale' label + run: gh issue edit ${{ github.event.issue.number }} --remove-label 'stale' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + From 1a9dbec83caab696cd1f8e336b8b8ae4980dda21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 17 Apr 2023 20:52:51 +0200 Subject: [PATCH 441/638] Use env variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 786940b25c..3d8a076379 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -6,6 +6,9 @@ on: workflow_dispatch: issue_comment: +env: + stale_label: stale + jobs: stale_action: if: github.event_name != 'issue_comment' @@ -20,7 +23,7 @@ jobs: days-before-stale: 30 days-before-close: 5 stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.' - stale-issue-label: 'stale' + stale-issue-label: $stale_label exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed' exempt-all-issue-assignees: true operations-per-run: 300 @@ -36,7 +39,7 @@ jobs: - name: Checkout uses: actions/checkout@v3.4.0 - name: Remove 'stale' label - run: gh issue edit ${{ github.event.issue.number }} --remove-label 'stale' + run: gh issue edit ${{ github.event.issue.number }} --remove-label $stale_label env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From eed4b70512fdd77a949fc7262809fd4390295e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 19 Apr 2023 21:03:12 +0200 Subject: [PATCH 442/638] Add Fedora 38 to the test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 1 + test/_fedora_38.Dockerfile | 18 ++++++++++++++++++ test/tox.fedora_38.ini | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/_fedora_38.Dockerfile create mode 100644 test/tox.fedora_38.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cd8a4030ca..748f09b92e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,6 +57,7 @@ jobs: centos_9, fedora_36, fedora_37, + fedora_38, ] env: DISTRO: ${{matrix.distro}} diff --git a/test/_fedora_38.Dockerfile b/test/_fedora_38.Dockerfile new file mode 100644 index 0000000000..76f697717f --- /dev/null +++ b/test/_fedora_38.Dockerfile @@ -0,0 +1,18 @@ +FROM fedora:38 +RUN dnf install -y git initscripts + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.fedora_38.ini b/test/tox.fedora_38.ini new file mode 100644 index 0000000000..0aa7612e11 --- /dev/null +++ b/test/tox.fedora_38.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker buildx build --load --progress plain -f _fedora_38.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From 0df06dc2fb5bb406ee75177d9bffed900f2cc12b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 22 Apr 2023 10:56:37 +0000 Subject: [PATCH 443/638] Bump actions/setup-python from 4.5.0 to 4.6.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.5.0 to 4.6.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.5.0...v4.6.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 748f09b92e..2dceff1c22 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,7 +66,7 @@ jobs: uses: actions/checkout@v3.5.2 - name: Set up Python 3.10 - uses: actions/setup-python@v4.5.0 + uses: actions/setup-python@v4.6.0 with: python-version: "3.10" From 9bcb32356871b448b97a5fe6d6bd89fca72d3eca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 22 Apr 2023 13:37:35 +0000 Subject: [PATCH 444/638] Bump actions/checkout from 3.4.0 to 3.5.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.4.0 to 3.5.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.4.0...v3.5.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index cb49439ba5..fe28112c8d 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.2 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label $stale_label env: From 83afff953f15075fdd37a1cd7f842a5bf026112d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 29 Apr 2023 10:57:31 +0000 Subject: [PATCH 445/638] Bump tox from 4.4.12 to 4.5.1 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.4.12 to 4.5.1. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.4.12...4.5.1) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 8cd3ca7797..f13ae6bace 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.3.1 pytest-xdist == 3.2.1 pytest-testinfra == 7.0.0 -tox == 4.4.12 +tox == 4.5.1 From fd4e8766e45594b5e45ec121c272defe401a12d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 2 May 2023 22:44:35 +0200 Subject: [PATCH 446/638] Remove unused code from query.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/query.sh | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 12295fbcfc..1d3b0a29a0 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -69,31 +69,16 @@ if [[ -n "${str:-}" ]]; then exit 1 fi -# Scan an array of files for matching strings -scanList(){ - # Escape full stops - local domain="${1}" esc_domain="${1//./\\.}" lists="${2}" list_type="${3:-}" - - # Prevent grep from printing file path - cd "$piholeDir" || exit 1 - - # Prevent grep -i matching slowly: https://bit.ly/2xFXtUX - export LC_CTYPE=C - - # /dev/null forces filename to be printed when only one list has been generated - case "${list_type}" in - "exact" ) grep -i -E -l "(^|(?/dev/null;; - # Iterate through each regexp and check whether it matches the domainQuery - # If it does, print the matching regexp and continue looping - # Input 1 - regexps | Input 2 - domainQuery - "regex" ) - for list in ${lists}; do - if [[ "${domain}" =~ ${list} ]]; then - printf "%b\n" "${list}"; - fi - done;; - * ) grep -i "${esc_domain}" "${lists}" /dev/null 2>/dev/null;; - esac +# Scan a domain again a list of RegEX +scanRegExList(){ + local domain="${1}" list="${2}" + + for entry in ${list}; do + if [[ "${domain}" =~ ${entry} ]]; then + printf "%b\n" "${entry}"; + fi + done + } scanDatabaseTable() { @@ -188,7 +173,7 @@ scanRegexDatabaseTable() { # Split regexps over a new line str_regexList=$(printf '%s\n' "${regexList[@]}") # Check domain against regexps - mapfile -t regexMatches < <(scanList "${domain}" "${str_regexList}" "regex") + mapfile -t regexMatches < <(scanRegExList "${domain}" "${str_regexList}") # If there were regex matches if [[ "${#regexMatches[@]}" -ne 0 ]]; then # Split matching regexps over a new line From b74c6d5120d9630ff835bff70c531e5b16bf9e8d Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 5 Mar 2023 19:02:09 +0100 Subject: [PATCH 447/638] Add support for RISC-V 64-bit installs Signed-off-by: MichaIng --- automated install/basic-install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 24fe9e547a..1f3002e77a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -357,7 +357,7 @@ package_manager_detect() { # These variable names match the ones for apt-get. See above for an explanation of what they are for. PKG_INSTALL=("${PKG_MANAGER}" install -y) # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. - PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" + PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src|.riscv64)' | wc -l || true" OS_CHECK_DEPS=(grep bind-utils) INSTALLER_DEPS=(git dialog iproute newt procps-ng chkconfig ca-certificates) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq) @@ -2366,6 +2366,9 @@ get_binary_name() { # set the binary to be used l_binary="pihole-FTL-linux-x86_64" fi + elif [[ "${machine}" == "riscv64" ]]; then + printf "%b %b Detected riscv64 processor\\n" "${OVER}" "${TICK}" + l_binary="pihole-FTL-riscv64-linux-gnu" else # Something else - we try to use 32bit executable and warn the user if [[ ! "${machine}" == "i686" ]]; then From e6ae2e98cc3b6171c9777ed5bf935ba27c8f9d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 7 May 2023 13:21:23 +0200 Subject: [PATCH 448/638] Don't source the install script in webpage.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 54 ++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5ccdf733f6..6492a74db3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -22,12 +22,14 @@ readonly dnscustomcnamefile="/etc/dnsmasq.d/05-pihole-custom-cname.conf" readonly gravityDBfile="/etc/pihole/gravity.db" -# Source install script for ${setupVars}, ${PI_HOLE_BIN_DIR} and valid_ip() -readonly PI_HOLE_FILES_DIR="/etc/.pihole" -# shellcheck disable=SC2034 # used in basic-install to source the script without running it -SKIP_INSTALL="true" -source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" +readonly setupVars="/etc/pihole/setupVars.conf" +readonly PI_HOLE_BIN_DIR="/usr/local/bin" + +# Root of the web server +readonly webroot="/var/www/html" + +# Source utils script utilsfile="/opt/pihole/utils.sh" source "${utilsfile}" @@ -98,6 +100,47 @@ HashPassword() { echo "${return}" } +# Check an IP address to see if it is a valid one +valid_ip() { + # Local, named variables + local ip=${1} + local stat=1 + + # Regex matching one IPv4 component, i.e. an integer from 0 to 255. + # See https://tools.ietf.org/html/rfc1340 + local ipv4elem="(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)"; + # Regex matching an optional port (starting with '#') range of 1-65536 + local portelem="(#(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}|0))?"; + # Build a full IPv4 regex from the above subexpressions + local regex="^${ipv4elem}\\.${ipv4elem}\\.${ipv4elem}\\.${ipv4elem}${portelem}$" + + # Evaluate the regex, and return the result + [[ $ip =~ ${regex} ]] + + stat=$? + return "${stat}" +} + +valid_ip6() { + local ip=${1} + local stat=1 + + # Regex matching one IPv6 element, i.e. a hex value from 0000 to FFFF + local ipv6elem="[0-9a-fA-F]{1,4}" + # Regex matching an IPv6 CIDR, i.e. 1 to 128 + local v6cidr="(\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])){0,1}" + # Regex matching an optional port (starting with '#') range of 1-65536 + local portelem="(#(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}|0))?"; + # Build a full IPv6 regex from the above subexpressions + local regex="^(((${ipv6elem}))*((:${ipv6elem}))*::((${ipv6elem}))*((:${ipv6elem}))*|((${ipv6elem}))((:${ipv6elem})){7})${v6cidr}${portelem}$" + + # Evaluate the regex, and return the result + [[ ${ip} =~ ${regex} ]] + + stat=$? + return "${stat}" +} + SetWebPassword() { if [ "${SUDO_USER}" == "www-data" ]; then echo "Security measure: user www-data is not allowed to change webUI password!" @@ -613,7 +656,6 @@ Teleporter() { host="${host//./_}" filename="pi-hole-${host:-noname}-teleporter_${datetimestamp}.tar.gz" fi - # webroot is sourced from basic-install above php "${webroot}/admin/scripts/pi-hole/php/teleporter.php" > "${filename}" } From b8c3f6d999b3fec6375e09ecbf3430e258ad6294 Mon Sep 17 00:00:00 2001 From: MrDuck2742 Date: Fri, 5 May 2023 22:05:56 +0100 Subject: [PATCH 449/638] Adding Local DNS Records does not add to /etc/pihole/custom.list Fixes #5268 Signed-off-by: MrDuck2742 --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5ccdf733f6..5fa2475f17 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -622,7 +622,7 @@ checkDomain() local domain validDomain # Convert to lowercase domain="${1,,}" - validDomain=$(grep -P "^((-|_)*[a-z\\d]((-|_)*[a-z\\d])*(-|_)*)(\\.(-|_)*([a-z\\d]((-|_)*[a-z\\d])*))*$" <<< "${domain}") # Valid chars check + validDomain=$(grep -P "^((-|_)*[a-z0-9]((-|_)*[a-z0-9)*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$" <<< "${domain}") # Valid chars check validDomain=$(grep -P "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$" <<< "${validDomain}") # Length of each label echo "${validDomain}" } From a3e610dbf2e31afd4996641e2d0d77fcbcaee6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 10 May 2023 06:52:51 +0200 Subject: [PATCH 450/638] Don't use '--suffix' in mktemp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index dea9326740..3d62401898 100755 --- a/gravity.sh +++ b/gravity.sh @@ -165,7 +165,10 @@ database_table_from_file() { src="${2}" backup_path="${piholeDir}/migration_backup" backup_file="${backup_path}/$(basename "${2}")" - tmpFile="$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".gravity")" + # Create a temporary file. We don't use '--suffix' here because not all + # implementations of mktemp support it, e.g. on Alpine + tmpFile="$(mktemp -p "${GRAVITY_TMPDIR}")" + mv "${tmpFile}" "${tmpFile%.*}.gravity" local timestamp timestamp="$(date --utc +'%s')" @@ -438,7 +441,10 @@ gravity_DownloadBlocklists() { echo -e "${OVER} ${TICK} ${str}" fi - target="$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".gravity")" + # Create a temporary file. We don't use '--suffix' here because not all + # implementations of mktemp support it, e.g. on Alpine + target="$(mktemp -p "${GRAVITY_TMPDIR}")" + mv "${target}" "${target%.*}.gravity" # Use compression to reduce the amount of data that is transferred # between the Pi-hole and the ad list provider. Use this feature @@ -568,7 +574,9 @@ parseList() { fi # For completeness, we will get a count of non_domains (this is the number of entries left after stripping the source of comments/duplicates/false positives/domains) - invalid_domains="$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".ph-non-domains")" + # We don't use '--suffix' here because not all implementations of mktemp support it, e.g. on Alpine + invalid_domains=$(mktemp -p "${GRAVITY_TMPDIR}") + mv "${invalid_domains}" "${invalid_domains%.*}.ph-non-domains" num_non_domains=$(grep -Ev "^(${valid_domain_pattern}|${abp_domain_pattern}|${false_positives})$" "${src}" | tee "${invalid_domains}" | wc -l) @@ -618,7 +626,9 @@ gravity_DownloadBlocklistFromUrl() { local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip cmd_ext # Create temp file to store content on disk instead of RAM - listCurlBuffer=$(mktemp -p "${GRAVITY_TMPDIR}" --suffix=".phgpb") + # We don't use '--suffix' here because not all implementations of mktemp support it, e.g. on Alpine + listCurlBuffer="$(mktemp -p "${GRAVITY_TMPDIR}")" + mv "${listCurlBuffer}" "${listCurlBuffer%.*}.phgpb" # Determine if $saveLocation has read permission if [[ -r "${saveLocation}" && $url != "file"* ]]; then From eaded9fdb197f318d9fb72b110c0c38ce164a5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 11 May 2023 22:16:21 +0200 Subject: [PATCH 451/638] Remove forgotten variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 3d62401898..1757aa6ad4 100755 --- a/gravity.sh +++ b/gravity.sh @@ -544,7 +544,7 @@ gravity_DownloadBlocklists() { # is saved in gravtiy's info table to signal FTL if such domains are available abp_domains=0 parseList() { - local adlistID="${1}" src="${2}" target="${3}" temp_file temp_file_base non_domains sample_non_domains valid_domain_pattern abp_domain_pattern + local adlistID="${1}" src="${2}" target="${3}" valid_domain_pattern abp_domain_pattern # define valid domain patterns # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already From 8d91ca874be69840f07a89714be8e527de37c3a4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 13 May 2023 11:01:21 +0000 Subject: [PATCH 452/638] Bump pytest-xdist from 3.2.1 to 3.3.0 in /test Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 3.2.1 to 3.3.0. - [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v3.2.1...v3.3.0) --- updated-dependencies: - dependency-name: pytest-xdist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index f13ae6bace..0965d7e689 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ docker-compose == 1.29.2 pytest == 7.3.1 -pytest-xdist == 3.2.1 +pytest-xdist == 3.3.0 pytest-testinfra == 7.0.0 tox == 4.5.1 From 73733308ba0f1c4e2cc5fb0c4aac6a9027349e48 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 15 May 2023 19:25:56 +0200 Subject: [PATCH 453/638] Use parseList function offered by pihole-FTL --- gravity.sh | 184 +++++++++-------------------------------------------- 1 file changed, 29 insertions(+), 155 deletions(-) diff --git a/gravity.sh b/gravity.sh index 1757aa6ad4..fe2097dd25 100755 --- a/gravity.sh +++ b/gravity.sh @@ -129,7 +129,7 @@ gravity_swap_databases() { echo -e "${OVER} ${TICK} ${str}" if $oldAvail; then - echo -e " ${TICK} The old database remains available." + echo -e " ${TICK} The old database remains available" fi } @@ -145,18 +145,6 @@ update_gravity_timestamp() { return 0 } -# Update timestamp when the gravity table was last updated successfully -set_abp_info() { - pihole-FTL sqlite3 "${gravityDBfile}" "INSERT OR REPLACE INTO info (property,value) VALUES ('abp_domains',${abp_domains});" - status="$?" - - if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to update ABP domain status in database ${gravityDBfile}\\n ${output}" - return 1 - fi - return 0 -} - # Import domains from file and store them in the specified database table database_table_from_file() { # Define locals @@ -239,17 +227,6 @@ database_table_from_file() { echo -e " ${CROSS} Unable to remove ${tmpFile}" } -# Update timestamp of last update of this list. We store this in the "old" database as all values in the new database will later be overwritten -database_adlist_updated() { - output=$( { printf ".timeout 30000\\nUPDATE adlist SET date_updated = (cast(strftime('%%s', 'now') as int)) WHERE id = %i;\\n" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) - status="$?" - - if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to update timestamp of adlist with ID ${1} in database ${gravityDBfile}\\n ${output}" - gravity_Cleanup "error" - fi -} - # Check if a column with name ${2} exists in gravity table with name ${1} gravity_column_exists() { output=$( { printf ".timeout 30000\\nSELECT EXISTS(SELECT * FROM pragma_table_info('%s') WHERE name='%s');\\n" "${1}" "${2}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) @@ -267,7 +244,7 @@ database_adlist_number() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${num_domains}" "${num_non_domains}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${2}" "${3}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -441,10 +418,24 @@ gravity_DownloadBlocklists() { echo -e "${OVER} ${TICK} ${str}" fi - # Create a temporary file. We don't use '--suffix' here because not all - # implementations of mktemp support it, e.g. on Alpine - target="$(mktemp -p "${GRAVITY_TMPDIR}")" - mv "${target}" "${target%.*}.gravity" + str="Creating new gravity databases" + echo -ne " ${INFO} ${str}..." + + # Gravity copying SQL script + copyGravity="$(cat "${gravityDBcopy}")" + if [[ "${gravityDBfile}" != "${gravityDBfile_default}" ]]; then + # Replace default gravity script location by custom location + copyGravity="${copyGravity//"${gravityDBfile_default}"/"${gravityDBfile}"}" + fi + + output=$( { pihole-FTL sqlite3 "${gravityTEMPfile}" <<< "${copyGravity}"; } 2>&1 ) + status="$?" + + if [[ "${status}" -ne 0 ]]; then + echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}" + return 1 + fi + echo -e "${OVER} ${TICK} ${str}" # Use compression to reduce the amount of data that is transferred # between the Pi-hole and the ad list provider. Use this feature @@ -486,116 +477,9 @@ gravity_DownloadBlocklists() { echo "" done - str="Creating new gravity databases" - echo -ne " ${INFO} ${str}..." - - # Gravity copying SQL script - copyGravity="$(cat "${gravityDBcopy}")" - if [[ "${gravityDBfile}" != "${gravityDBfile_default}" ]]; then - # Replace default gravity script location by custom location - copyGravity="${copyGravity//"${gravityDBfile_default}"/"${gravityDBfile}"}" - fi - - output=$( { pihole-FTL sqlite3 "${gravityTEMPfile}" <<< "${copyGravity}"; } 2>&1 ) - status="$?" - - if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to copy data from ${gravityDBfile} to ${gravityTEMPfile}\\n ${output}" - return 1 - fi - echo -e "${OVER} ${TICK} ${str}" - - str="Storing downloaded domains in new gravity database" - echo -ne " ${INFO} ${str}..." - output=$( { printf ".timeout 30000\\n.mode csv\\n.import \"%s\" gravity\\n" "${target}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) - status="$?" - - if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to fill gravity table in database ${gravityTEMPfile}\\n ${output}" - gravity_Cleanup "error" - else - echo -e "${OVER} ${TICK} ${str}" - fi - - if [[ "${status}" -eq 0 && -n "${output}" ]]; then - echo -e " Encountered non-critical SQL warnings. Please check the suitability of the lists you're using!\\n\\n SQL warnings:" - local warning file line lineno - while IFS= read -r line; do - echo " - ${line}" - warning="$(grep -oh "^[^:]*:[0-9]*" <<< "${line}")" - file="${warning%:*}" - lineno="${warning#*:}" - if [[ -n "${file}" && -n "${lineno}" ]]; then - echo -n " Line contains: " - awk "NR==${lineno}" < "${file}" - fi - done <<< "${output}" - echo "" - fi - - rm "${target}" > /dev/null 2>&1 || \ - echo -e " ${CROSS} Unable to remove ${target}" - gravity_Blackbody=true } - -# global variable to indicate if we found ABP style domains during the gravity run -# is saved in gravtiy's info table to signal FTL if such domains are available -abp_domains=0 -parseList() { - local adlistID="${1}" src="${2}" target="${3}" valid_domain_pattern abp_domain_pattern - - # define valid domain patterns - # no need to include uppercase letters, as we convert to lowercase in gravity_ParseFileIntoDomains() already - # adapted from https://stackoverflow.com/a/30007882 - - TLD_pattern="[a-z0-9][a-z0-9-]{0,61}[a-z0-9]" - subdomain_pattern="([a-z0-9]([a-z0-9_-]{0,61}[a-z0-9]){0,1}\.)" - - valid_domain_pattern="${subdomain_pattern}+${TLD_pattern}" - - # supported ABP style: ||subdomain.domain.tld^ - # ${subdomain_pattern} is optional for ABP style, allowing TLD blocking: ||tld^ - abp_domain_pattern="\|\|${subdomain_pattern}*${TLD_pattern}\^" - - # A list of items of common local hostnames not to report as unusable - # Some lists (i.e StevenBlack's) contain these as they are supposed to be used as HOST files - # but flagging them as unusable causes more confusion than it's worth - so we suppress them from the output - false_positives="localhost|localhost.localdomain|local|broadcasthost|localhost|ip6-localhost|ip6-loopback|lo0 localhost|ip6-localnet|ip6-mcastprefix|ip6-allnodes|ip6-allrouters|ip6-allhosts" - - # Extract valid domains from source file and append ,${adlistID} to each line and save count to variable for display. - num_domains=$(grep -E "^(${valid_domain_pattern}|${abp_domain_pattern})$" "${src}" | tee >(sed "s/$/,${adlistID}/" >> "${target}") | wc -l) - - # Check if the source file contained AdBlock Plus style domains, if so we set the global variable and inform the user - if grep -E "^${abp_domain_pattern}$" -m 1 -q "${src}"; then - echo " ${INFO} List contained AdBlock Plus style domains" - abp_domains=1 - fi - - # For completeness, we will get a count of non_domains (this is the number of entries left after stripping the source of comments/duplicates/false positives/domains) - # We don't use '--suffix' here because not all implementations of mktemp support it, e.g. on Alpine - invalid_domains=$(mktemp -p "${GRAVITY_TMPDIR}") - mv "${invalid_domains}" "${invalid_domains%.*}.ph-non-domains" - - num_non_domains=$(grep -Ev "^(${valid_domain_pattern}|${abp_domain_pattern}|${false_positives})$" "${src}" | tee "${invalid_domains}" | wc -l) - - # If there are unusable lines, we display some information about them. This is not error or major cause for concern. - if [[ "${num_non_domains}" -ne 0 ]]; then - type="domains" - if [[ "${abp_domains}" -ne 0 ]]; then - type="patterns" - fi - echo " ${INFO} Imported ${num_domains} ${type}, ignoring ${num_non_domains} non-domain entries" - echo " Sample of non-domain entries:" - invalid_lines=$(head -n 5 "${invalid_domains}") - echo "${invalid_lines}" | awk '{print " - " $0}' - else - echo " ${INFO} Imported ${num_domains} domains" - fi - rm "${invalid_domains}" -} - compareLists() { local adlistID="${1}" target="${2}" @@ -606,7 +490,6 @@ compareLists() { sha1sum "${target}" > "${target}.sha1" echo " ${INFO} List has been updated" database_adlist_status "${adlistID}" "1" - database_adlist_updated "${adlistID}" else echo " ${INFO} List stayed unchanged" database_adlist_status "${adlistID}" "2" @@ -616,7 +499,6 @@ compareLists() { sha1sum "${target}" > "${target}.sha1" # We assume here it was changed upstream database_adlist_status "${adlistID}" "1" - database_adlist_updated "${adlistID}" fi } @@ -716,9 +598,8 @@ gravity_DownloadBlocklistFromUrl() { if [[ "${success}" == true ]]; then if [[ "${httpCode}" == "304" ]]; then # Add domains to database table file - parseList "${adlistID}" "${saveLocation}" "${target}" + pihole-FTL gravity parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}" database_adlist_status "${adlistID}" "2" - database_adlist_number "${adlistID}" done="true" # Check if $listCurlBuffer is a non-zero length file elif [[ -s "${listCurlBuffer}" ]]; then @@ -727,12 +608,9 @@ gravity_DownloadBlocklistFromUrl() { # Remove curl buffer file after its use rm "${listCurlBuffer}" # Add domains to database table file - parseList "${adlistID}" "${saveLocation}" "${target}" + pihole-FTL gravity parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}" # Compare lists, are they identical? compareLists "${adlistID}" "${saveLocation}" - # Update gravity database table (status and updated timestamp are set in - # compareLists) - database_adlist_number "${adlistID}" done="true" else # Fall back to previously cached list if $listCurlBuffer is empty @@ -746,15 +624,12 @@ gravity_DownloadBlocklistFromUrl() { if [[ -r "${saveLocation}" ]]; then echo -e " ${CROSS} List download failed: ${COL_LIGHT_GREEN}using previously cached list${COL_NC}" # Add domains to database table file - parseList "${adlistID}" "${saveLocation}" "${target}" - database_adlist_number "${adlistID}" + pihole-FTL gravity parseList "${saveLocation}" "${gravityTEMPfile}" "${adlistID}" database_adlist_status "${adlistID}" "3" else echo -e " ${CROSS} List download failed: ${COL_LIGHT_RED}no cached list available${COL_NC}" # Manually reset these two numbers because we do not call parseList here - num_domains=0 - num_non_domains=0 - database_adlist_number "${adlistID}" + database_adlist_number "${adlistID}" 0 0 database_adlist_status "${adlistID}" "4" fi fi @@ -797,9 +672,9 @@ gravity_Table_Count() { local str="${2}" local num num="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM ${table};")" - if [[ "${table}" == "vw_gravity" ]]; then + if [[ "${table}" == "gravity" ]]; then local unique - unique="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(DISTINCT domain) FROM ${table};")" + unique="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM (SELECT DISTINCT domain FROM ${table});")" echo -e " ${INFO} Number of ${str}: ${num} (${COL_BOLD}${unique} unique domains${COL_NC})" pihole-FTL sqlite3 "${gravityDBfile}" "INSERT OR REPLACE INTO info (property,value) VALUES ('gravity_count',${unique});" else @@ -809,7 +684,9 @@ gravity_Table_Count() { # Output count of blacklisted domains and regex filters gravity_ShowCount() { - gravity_Table_Count "vw_gravity" "gravity domains" "" + # Here we use the table "gravity" instead of the view "vw_gravity" for speed. + # It's safe to replace it here, because right after a gravity run both will show the exactly same number of domains. + gravity_Table_Count "gravity" "gravity domains" "" gravity_Table_Count "vw_blacklist" "exact blacklisted domains" gravity_Table_Count "vw_regex_blacklist" "regex blacklist filters" gravity_Table_Count "vw_whitelist" "exact whitelisted domains" @@ -1026,9 +903,6 @@ fi # Update gravity timestamp update_gravity_timestamp -# Set abp_domain info field -set_abp_info - # Ensure proper permissions are set for the database chown pihole:pihole "${gravityDBfile}" chmod g+w "${piholeDir}" "${gravityDBfile}" From f9b29cfb62bae81aa62e8cc76eee574d21bce9e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 20 May 2023 11:02:15 +0000 Subject: [PATCH 454/638] Bump pytest-xdist from 3.3.0 to 3.3.1 in /test Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 3.3.0 to 3.3.1. - [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v3.3.0...v3.3.1) --- updated-dependencies: - dependency-name: pytest-xdist dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 0965d7e689..f2423ba479 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ docker-compose == 1.29.2 pytest == 7.3.1 -pytest-xdist == 3.3.0 +pytest-xdist == 3.3.1 pytest-testinfra == 7.0.0 tox == 4.5.1 From 10fe85933b4f0341587236b8ffa7894207689711 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 20 May 2023 13:41:46 +0000 Subject: [PATCH 455/638] Bump pytest-testinfra from 7.0.0 to 8.0.0 in /test Bumps [pytest-testinfra](https://github.com/pytest-dev/pytest-testinfra) from 7.0.0 to 8.0.0. - [Release notes](https://github.com/pytest-dev/pytest-testinfra/releases) - [Changelog](https://github.com/pytest-dev/pytest-testinfra/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-testinfra/compare/7.0.0...8.0.0) --- updated-dependencies: - dependency-name: pytest-testinfra dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index f2423ba479..552002862b 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ docker-compose == 1.29.2 pytest == 7.3.1 pytest-xdist == 3.3.1 -pytest-testinfra == 7.0.0 +pytest-testinfra == 8.0.0 tox == 4.5.1 From c92826c1525c80cddca3d6fde7e2d8ce8a96bb46 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 24 May 2023 21:31:02 +0200 Subject: [PATCH 456/638] Do not copy info table during pihole -g Signed-off-by: DL6ER --- advanced/Templates/gravity_copy.sql | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Templates/gravity_copy.sql b/advanced/Templates/gravity_copy.sql index 3bea731d1b..ed11b61a78 100644 --- a/advanced/Templates/gravity_copy.sql +++ b/advanced/Templates/gravity_copy.sql @@ -19,8 +19,6 @@ INSERT OR REPLACE INTO adlist SELECT * FROM OLD.adlist; DELETE FROM OLD.adlist_by_group WHERE adlist_id NOT IN (SELECT id FROM OLD.adlist); INSERT OR REPLACE INTO adlist_by_group SELECT * FROM OLD.adlist_by_group; -INSERT OR REPLACE INTO info SELECT * FROM OLD.info; - INSERT OR REPLACE INTO client SELECT * FROM OLD.client; DELETE FROM OLD.client_by_group WHERE client_id NOT IN (SELECT id FROM OLD.client); INSERT OR REPLACE INTO client_by_group SELECT * FROM OLD.client_by_group; From 5bdb089b7f542d953f91e4ee9c0accf891e07c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 24 May 2023 22:54:47 +0200 Subject: [PATCH 457/638] Add Ubuntu 23 to test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 1 + test/_ubuntu_23.Dockerfile | 18 ++++++++++++++++++ test/tox.ubuntu_23.ini | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/_ubuntu_23.Dockerfile create mode 100644 test/tox.ubuntu_23.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2dceff1c22..7d9f403e4c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,6 +53,7 @@ jobs: debian_11, ubuntu_20, ubuntu_22, + ubuntu_23, centos_8, centos_9, fedora_36, diff --git a/test/_ubuntu_23.Dockerfile b/test/_ubuntu_23.Dockerfile new file mode 100644 index 0000000000..f9b3910b85 --- /dev/null +++ b/test/_ubuntu_23.Dockerfile @@ -0,0 +1,18 @@ +FROM buildpack-deps:lunar-scm + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR +ENV DEBIAN_FRONTEND=noninteractive + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.ubuntu_23.ini b/test/tox.ubuntu_23.ini new file mode 100644 index 0000000000..767ed9ef56 --- /dev/null +++ b/test/tox.ubuntu_23.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv:py3] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker buildx build --load --progress plain -f _ubuntu_23.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 783f9e556950fe06ab76a309a19d38e40c3f015c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 27 May 2023 10:56:41 +0000 Subject: [PATCH 458/638] Bump actions/setup-python from 4.6.0 to 4.6.1 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.6.0 to 4.6.1. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.6.0...v4.6.1) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2dceff1c22..a9f116f0bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,7 +66,7 @@ jobs: uses: actions/checkout@v3.5.2 - name: Set up Python 3.10 - uses: actions/setup-python@v4.6.0 + uses: actions/setup-python@v4.6.1 with: python-version: "3.10" From 3ae72114c76eb538bfabc4f374b92184d28d2fcc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 27 May 2023 10:59:32 +0000 Subject: [PATCH 459/638] Bump pytest-testinfra from 8.0.0 to 8.1.0 in /test Bumps [pytest-testinfra](https://github.com/pytest-dev/pytest-testinfra) from 8.0.0 to 8.1.0. - [Release notes](https://github.com/pytest-dev/pytest-testinfra/releases) - [Changelog](https://github.com/pytest-dev/pytest-testinfra/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-testinfra/compare/8.0.0...8.1.0) --- updated-dependencies: - dependency-name: pytest-testinfra dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 552002862b..f11d1253ec 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ docker-compose == 1.29.2 pytest == 7.3.1 pytest-xdist == 3.3.1 -pytest-testinfra == 8.0.0 +pytest-testinfra == 8.1.0 tox == 4.5.1 From 11679a5188c1e29fcaa13fa5c29204443349a794 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 28 May 2023 23:31:51 +0100 Subject: [PATCH 460/638] @MrDuck2742 dropped a `]` on the floor without me seeing. I picked it up and put it back again Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7680590f81..c92d0458dd 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -664,7 +664,7 @@ checkDomain() local domain validDomain # Convert to lowercase domain="${1,,}" - validDomain=$(grep -P "^((-|_)*[a-z0-9]((-|_)*[a-z0-9)*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$" <<< "${domain}") # Valid chars check + validDomain=$(grep -P "^((-|_)*[a-z0-9]((-|_)*[a-z0-9])*(-|_)*)(\\.(-|_)*([a-z0-9]((-|_)*[a-z0-9])*))*$" <<< "${domain}") # Valid chars check validDomain=$(grep -P "^[^\\.]{1,63}(\\.[^\\.]{1,63})*$" <<< "${validDomain}") # Length of each label echo "${validDomain}" } From 494734bf27f836d2e5f17df1567d79fc37ad9de0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 28 May 2023 23:40:47 +0100 Subject: [PATCH 461/638] Add in a test case Signed-off-by: Adam Warner --- test/test_any_automated_install.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index c1288287e0..36a4f0d2ea 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -1151,3 +1151,30 @@ def test_package_manager_has_web_deps(host): assert "No package" not in output.stdout assert output.rc == 0 + + +def test_webpage_sh_valid_domain(host): + """Confirms checkDomain function in webpage.sh works as expected""" + check1 = host.run( + """ + source /opt/pihole/webpage.sh + checkDomain "pi-hole.net" + """ + ) + check2 = host.run( + """ + source /opt/pihole/webpage.sh + checkDomain "ab.pi-hole.net" + """ + ) + + check3 = host.run( + """ + source /opt/pihole/webpage.sh + checkDomain "abc.pi-hole.net" + """ + ) + + assert "pi-hole.net" in check1.stdout + assert "ab.pi-hole.net" in check2.stdout + assert "abc.pi-hole.net" in check3.stdout From 6c302c9bc811a944cc721f640e3f5429db25869e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 30 May 2023 17:01:58 +0200 Subject: [PATCH 462/638] Adlist properties need to be stored in the new ("temp") database rather than the old. Signed-off-by: DL6ER --- gravity.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gravity.sh b/gravity.sh index fe2097dd25..2bd21d0101 100755 --- a/gravity.sh +++ b/gravity.sh @@ -229,7 +229,7 @@ database_table_from_file() { # Check if a column with name ${2} exists in gravity table with name ${1} gravity_column_exists() { - output=$( { printf ".timeout 30000\\nSELECT EXISTS(SELECT * FROM pragma_table_info('%s') WHERE name='%s');\\n" "${1}" "${2}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nSELECT EXISTS(SELECT * FROM pragma_table_info('%s') WHERE name='%s');\\n" "${1}" "${2}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) if [[ "${output}" == "1" ]]; then return 0 # Bash 0 is success fi @@ -244,11 +244,11 @@ database_adlist_number() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${2}" "${3}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${2}" "${3}" "${1}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to update number of domains in adlist with ID ${1} in database ${gravityDBfile}\\n ${output}" + echo -e "\\n ${CROSS} Unable to update number of domains in adlist with ID ${1} in database ${gravityTEMPfile}\\n ${output}" gravity_Cleanup "error" fi } @@ -260,11 +260,11 @@ database_adlist_status() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET status = %i WHERE id = %i;\\n" "${2}" "${1}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET status = %i WHERE id = %i;\\n" "${2}" "${1}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then - echo -e "\\n ${CROSS} Unable to update status of adlist with ID ${1} in database ${gravityDBfile}\\n ${output}" + echo -e "\\n ${CROSS} Unable to update status of adlist with ID ${1} in database ${gravityTEMPfile}\\n ${output}" gravity_Cleanup "error" fi } From b2c73f8325ae059a4dec86fca42c7dead6839b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 29 May 2023 22:02:38 +0200 Subject: [PATCH 463/638] Do not try to remove stale lables on PRs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index fe28112c8d..af3177d4a8 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -29,8 +29,11 @@ jobs: operations-per-run: 300 close-issue-reason: 'not_planned' - remove_stale: # trigger "stale" removal immediately when stale issues are commented on - if: github.event_name == 'issue_comment' + remove_stale: + # trigger "stale" removal immediately when stale issues are commented on + # we need to explicitly check that the trigger does not run on comment on a PR as + # 'issue_comment' triggers on issues AND PR comments + if: github.event_name == 'issue_comment' && ${{ !github.event.issue.pull_request }} permissions: contents: read # for actions/checkout issues: write # to edit issues label From 364537b32459d3c5871f8dde0d9cad5b7e12b008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 31 May 2023 22:14:05 +0200 Subject: [PATCH 464/638] Use env variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/stale.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index af3177d4a8..0d06ee2221 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -23,7 +23,7 @@ jobs: days-before-stale: 30 days-before-close: 5 stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Please comment or update this issue or it will be closed in 5 days.' - stale-issue-label: $stale_label + stale-issue-label: '${{ env.stale_label }}' exempt-issue-labels: 'Internal, Fixed in next release, Bug: Confirmed, Documentation Needed' exempt-all-issue-assignees: true operations-per-run: 300 @@ -42,7 +42,6 @@ jobs: - name: Checkout uses: actions/checkout@v3.5.2 - name: Remove 'stale' label - run: gh issue edit ${{ github.event.issue.number }} --remove-label $stale_label - env: + run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b0fa3795e9712d333b0d39db0caec1e2b75267c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 3 Jun 2023 10:58:23 +0000 Subject: [PATCH 465/638] Bump tox from 4.5.1 to 4.5.2 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.5.1 to 4.5.2. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.5.1...4.5.2) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index f11d1253ec..de54d22c76 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.3.1 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 -tox == 4.5.1 +tox == 4.5.2 From 7d3f354dd71c9cc0fc3abe7e0ad401ad8e864aae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 10 Jun 2023 10:57:12 +0000 Subject: [PATCH 466/638] Bump actions/checkout from 3.5.2 to 3.5.3 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.2 to 3.5.3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.5.2...v3.5.3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index f3bcf15a7f..7fd0e4e4d5 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index fe28112c8d..43d5ca96b5 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label $stale_label env: diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index fa7564a348..5435b7dbc6 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fca8bb190b..6cb88d9972 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Check scripts in repository are executable run: | @@ -64,7 +64,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Set up Python 3.10 uses: actions/setup-python@v4.6.1 From 8e481e27da2c3bf47edcb7f26b92c06300dd7f16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 10 Jun 2023 11:00:35 +0000 Subject: [PATCH 467/638] Bump tox from 4.5.2 to 4.6.0 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.5.2 to 4.6.0. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.5.2...4.6.0) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index de54d22c76..035ce805ce 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.3.1 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 -tox == 4.5.2 +tox == 4.6.0 From 117c15319da67de4e9bf35ba25d7cc0d8996291a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 10 Jun 2023 23:03:43 +0200 Subject: [PATCH 468/638] Add tests for Debian 12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 1 + test/_debian_12.Dockerfile | 17 +++++++++++++++++ test/tox.debian_12.ini | 8 ++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/_debian_12.Dockerfile create mode 100644 test/tox.debian_12.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6cb88d9972..c9184615ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,6 +51,7 @@ jobs: [ debian_10, debian_11, + debian_12, ubuntu_20, ubuntu_22, ubuntu_23, diff --git a/test/_debian_12.Dockerfile b/test/_debian_12.Dockerfile new file mode 100644 index 0000000000..a762fee03b --- /dev/null +++ b/test/_debian_12.Dockerfile @@ -0,0 +1,17 @@ +FROM buildpack-deps:bookworm-scm + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.debian_12.ini b/test/tox.debian_12.ini new file mode 100644 index 0000000000..ee70e8bd7d --- /dev/null +++ b/test/tox.debian_12.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv:py3] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker buildx build --load --progress plain -f _debian_12.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py From 3fd7b4ee243e84d371eb876cef52186a44c2bd6d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:59:42 +0000 Subject: [PATCH 469/638] Bump pytest from 7.3.1 to 7.3.2 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.3.1 to 7.3.2. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.3.1...7.3.2) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 035ce805ce..407c3e3ca2 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ docker-compose == 1.29.2 -pytest == 7.3.1 +pytest == 7.3.2 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 tox == 4.6.0 From 7a66083e6888d2109eaa9b042694cf1a1204adad Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 17 Jun 2023 11:35:38 +0000 Subject: [PATCH 470/638] Bump tox from 4.6.0 to 4.6.2 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.6.0 to 4.6.2. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.6.0...4.6.2) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 407c3e3ca2..44e6c94ad1 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.3.2 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 -tox == 4.6.0 +tox == 4.6.2 From 198ca65f7debc376fc8178483ed50c1047aa3129 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 24 Jun 2023 10:57:28 +0000 Subject: [PATCH 471/638] Bump tox from 4.6.2 to 4.6.3 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.6.2 to 4.6.3. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.6.2...4.6.3) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 44e6c94ad1..67dbcf6833 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.3.2 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 -tox == 4.6.2 +tox == 4.6.3 From 5490625d8d731347efc968d5187723c62ad3cee6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 24 Jun 2023 16:03:56 +0000 Subject: [PATCH 472/638] Bump pytest from 7.3.2 to 7.4.0 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.3.2 to 7.4.0. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.3.2...7.4.0) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 67dbcf6833..a08dff947f 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ docker-compose == 1.29.2 -pytest == 7.3.2 +pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 tox == 4.6.3 From a01d31e25da2cb20ceac18e5b1ecc0916f27b902 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 8 Jul 2023 10:15:54 +0000 Subject: [PATCH 473/638] Bump tox from 4.6.3 to 4.6.4 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.6.3 to 4.6.4. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.6.3...4.6.4) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index a08dff947f..a4f627fa7d 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ docker-compose == 1.29.2 pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 -tox == 4.6.3 +tox == 4.6.4 From 924de1d9ed9f18bcef484f1aa87961b267c562d7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 11 Jul 2023 23:51:28 +0100 Subject: [PATCH 474/638] Update dependabot.yml Signed-off-by: Adam Warner --- .github/dependabot.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index e140f79241..20163f5eb9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,3 +20,24 @@ updates: target-branch: development reviewers: - "pi-hole/core-maintainers" +# As above, but for development-v6 +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: weekly + day: saturday + time: "10:00" + open-pull-requests-limit: 10 + target-branch: development-v6 + reviewers: + - "pi-hole/core-maintainers" +- package-ecosystem: pip + directory: "/test" + schedule: + interval: weekly + day: saturday + time: "10:00" + open-pull-requests-limit: 10 + target-branch: development-v6 + reviewers: + - "pi-hole/core-maintainers" From 80091232a767efd28277e90e008c643266e06577 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 12 Jul 2023 21:31:19 +0100 Subject: [PATCH 475/638] Add missing `env:`, tweak conditional Signed-off-by: Adam Warner --- .github/workflows/stale.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 0d06ee2221..458a7fb60c 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -32,8 +32,8 @@ jobs: remove_stale: # trigger "stale" removal immediately when stale issues are commented on # we need to explicitly check that the trigger does not run on comment on a PR as - # 'issue_comment' triggers on issues AND PR comments - if: github.event_name == 'issue_comment' && ${{ !github.event.issue.pull_request }} + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment-on-issues-only-or-pull-requests-only + if: ${{ !github.event.issue.pull_request && github.event_name != 'schedule' }} permissions: contents: read # for actions/checkout issues: write # to edit issues label @@ -43,5 +43,6 @@ jobs: uses: actions/checkout@v3.5.2 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }} + env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 91dabc574d8d9c38379ec4db710f3799be55a8fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 15 Jul 2023 10:30:37 +0000 Subject: [PATCH 476/638] Bump actions/setup-python from 4.6.1 to 4.7.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.6.1 to 4.7.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.6.1...v4.7.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9184615ab..8546e02b1d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,7 +68,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Set up Python 3.10 - uses: actions/setup-python@v4.6.1 + uses: actions/setup-python@v4.7.0 with: python-version: "3.10" From 7e240251d55ea5830260fc9d3bc1106d1e33bdb2 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Jul 2023 08:03:05 +0100 Subject: [PATCH 477/638] Drop docker-compose from requirements.txt, it's not used. This was the only thing preventing us from using pyyaml 6.0.1 which fixes issues we were seeing with tests not running (https://github.com/yaml/pyyaml/pull/702) Signed-off-by: Adam Warner --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index a4f627fa7d..5a551fa784 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,4 +1,4 @@ -docker-compose == 1.29.2 +pyyaml == 6.0.1 pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 From 7747cd22324a28f00a4807787f2d5b6b801653b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 12 Aug 2023 10:52:02 +0000 Subject: [PATCH 478/638] Bump tox from 4.6.4 to 4.7.0 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.6.4 to 4.7.0. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.6.4...4.7.0) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 5a551fa784..c5d002e53e 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 -tox == 4.6.4 +tox == 4.7.0 From 272ca8c55d0aa2f245ac1a466fd2beabca43f026 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 19 Aug 2023 10:48:18 +0000 Subject: [PATCH 479/638] Bump tox from 4.7.0 to 4.9.0 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.7.0 to 4.9.0. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.7.0...4.9.0) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index c5d002e53e..0210aa4eaf 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 8.1.0 -tox == 4.7.0 +tox == 4.9.0 From 1c6919cf07a36c280f02dddd840e036a209747c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 26 Aug 2023 10:08:08 +0000 Subject: [PATCH 480/638] Bump pytest-testinfra from 8.1.0 to 9.0.0 in /test Bumps [pytest-testinfra](https://github.com/pytest-dev/pytest-testinfra) from 8.1.0 to 9.0.0. - [Release notes](https://github.com/pytest-dev/pytest-testinfra/releases) - [Changelog](https://github.com/pytest-dev/pytest-testinfra/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-testinfra/compare/8.1.0...9.0.0) --- updated-dependencies: - dependency-name: pytest-testinfra dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 0210aa4eaf..b1b36de1d4 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ pyyaml == 6.0.1 pytest == 7.4.0 pytest-xdist == 3.3.1 -pytest-testinfra == 8.1.0 +pytest-testinfra == 9.0.0 tox == 4.9.0 From 924f8b88448996c8b2f11be7c11aefbb6d928e79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 26 Aug 2023 10:20:12 +0000 Subject: [PATCH 481/638] Bump actions/checkout from 3.5.3 to 3.6.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.3 to 3.6.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.5.3...v3.6.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7fd0e4e4d5..1194ba0f15 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 43d5ca96b5..13b05df2f0 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label $stale_label env: diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 5435b7dbc6..60f38cf614 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8546e02b1d..01792fa46c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Check scripts in repository are executable run: | @@ -65,7 +65,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 From 9b68fa0b27c5b44a4f7baf211c051a6164c2c6df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 27 Aug 2023 12:28:54 +0000 Subject: [PATCH 482/638] Bump tox from 4.9.0 to 4.10.0 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.9.0 to 4.10.0. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.9.0...4.10.0) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index b1b36de1d4..90255f7fc4 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 9.0.0 -tox == 4.9.0 +tox == 4.10.0 From 9084b170cb162fdd9f615fe6b66d8e1dfa95a5b6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Sep 2023 10:35:16 +0000 Subject: [PATCH 483/638] Bump tox from 4.10.0 to 4.11.1 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.10.0 to 4.11.1. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.10.0...4.11.1) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 90255f7fc4..7f4d7e09c3 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 9.0.0 -tox == 4.10.0 +tox == 4.11.1 From cdc1c1ace10e4425dde0870ffb57a3c945910057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Mon, 21 Aug 2023 21:28:17 +0200 Subject: [PATCH 484/638] Remove user agent when downloading adlists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- gravity.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/gravity.sh b/gravity.sh index 2bd21d0101..db19909027 100755 --- a/gravity.sh +++ b/gravity.sh @@ -401,7 +401,7 @@ gravity_DownloadBlocklists() { unset sources fi - local url domain agent str target compression + local url domain str target compression echo "" # Prepare new gravity database @@ -457,9 +457,6 @@ gravity_DownloadBlocklists() { saveLocation="${piholeDir}/list.${id}.${domain}.${domainsExtension}" activeDomains[$i]="${saveLocation}" - # Default user-agent (for Cloudflare's Browser Integrity Check: https://support.cloudflare.com/hc/en-us/articles/200170086-What-does-the-Browser-Integrity-Check-do-) - agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36" - echo -e " ${INFO} Target: ${url}" local regex check_url # Check for characters NOT allowed in URLs @@ -472,7 +469,7 @@ gravity_DownloadBlocklists() { if [[ "${check_url}" =~ ${regex} ]]; then echo -e " ${CROSS} Invalid Target" else - gravity_DownloadBlocklistFromUrl "${url}" "${agent}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" + gravity_DownloadBlocklistFromUrl "${url}" "${sourceIDs[$i]}" "${saveLocation}" "${target}" "${compression}" fi echo "" done @@ -504,7 +501,7 @@ compareLists() { # Download specified URL and perform checks on HTTP status and file content gravity_DownloadBlocklistFromUrl() { - local url="${1}" agent="${2}" adlistID="${3}" saveLocation="${4}" target="${5}" compression="${6}" + local url="${1}" adlistID="${2}" saveLocation="${3}" target="${4}" compression="${5}" local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip cmd_ext # Create temp file to store content on disk instead of RAM @@ -564,7 +561,7 @@ gravity_DownloadBlocklistFromUrl() { fi # shellcheck disable=SC2086 - httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" -A "${agent}" "${url}" -o "${listCurlBuffer}" 2> /dev/null) + httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" "${url}" -o "${listCurlBuffer}" 2> /dev/null) case $url in # Did we "download" a local file? From 843f57399c289982cbcd1629030e685b13f01f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 7 Sep 2023 22:27:49 +0200 Subject: [PATCH 485/638] Ignore ABP style entries in debug log dig test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 6f747855d9..ecb4fc191b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -861,11 +861,15 @@ dig_at() { local record_type="A" fi - # Find a random blocked url that has not been whitelisted. + # Find a random blocked url that has not been whitelisted and is not ABP style. # This helps emulate queries to different domains that a user might query # It will also give extra assurance that Pi-hole is correctly resolving and blocking domains local random_url - random_url=$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity ORDER BY RANDOM() LIMIT 1") + random_url=$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity WHERE domain not like '||%^' ORDER BY RANDOM() LIMIT 1") + # Falback if no non-ABP style domains were found + if [ -z "${random_url}" ]; then + random_url="flurry.com" + fi # Next we need to check if Pi-hole can resolve a domain when the query is sent to it's IP address # This better emulates how clients will interact with Pi-hole as opposed to above where Pi-hole is From 1f241a3d451ea6bf36eb5feb07255b8bdf91d82f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Sep 2023 10:08:40 +0000 Subject: [PATCH 486/638] Bump actions/checkout from 3.6.0 to 4.0.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.6.0 to 4.0.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.6.0...v4.0.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1194ba0f15..570fabddca 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 13b05df2f0..8d09e5e0ea 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label $stale_label env: diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 60f38cf614..184319e0a3 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 01792fa46c..745a250c2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Check scripts in repository are executable run: | @@ -65,7 +65,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v3.6.0 + uses: actions/checkout@v4.0.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 From 047eac6d9c400556c107bd6fce0d28ff3f92ac4e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Sep 2023 10:58:28 +0000 Subject: [PATCH 487/638] Bump tox from 4.11.1 to 4.11.3 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.11.1 to 4.11.3. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.11.1...4.11.3) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 7f4d7e09c3..139be0fc00 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.0 pytest-xdist == 3.3.1 pytest-testinfra == 9.0.0 -tox == 4.11.1 +tox == 4.11.3 From 55f72ac92584342cf98870c9735554b0aa8df819 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Sep 2023 10:58:32 +0000 Subject: [PATCH 488/638] Bump pytest from 7.4.0 to 7.4.2 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.0 to 7.4.2. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.4.0...7.4.2) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 7f4d7e09c3..9279f97d37 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ pyyaml == 6.0.1 -pytest == 7.4.0 +pytest == 7.4.2 pytest-xdist == 3.3.1 pytest-testinfra == 9.0.0 tox == 4.11.1 From c3d1f366ec2b302b58488b45803a7707347e0c21 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 23 Sep 2023 10:39:24 +0000 Subject: [PATCH 489/638] Bump actions/checkout from 4.0.0 to 4.1.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.0.0 to 4.1.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4.0.0...v4.1.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 570fabddca..4685aa2cc2 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index b783ff25f9..14c55d102b 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -40,7 +40,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }} env: diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index 184319e0a3..a10256299e 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 745a250c2f..ae03db07de 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Check scripts in repository are executable run: | @@ -65,7 +65,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v4.0.0 + uses: actions/checkout@v4.1.0 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.0 From edf0060acf97e7072575599bcdbeab45541b568e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 6 Oct 2023 22:26:08 +0200 Subject: [PATCH 490/638] Fix spellcheck errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .codespellignore | 1 + advanced/Scripts/piholeDebug.sh | 4 ++-- automated install/basic-install.sh | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.codespellignore b/.codespellignore index 501a3d6732..6d05d295ae 100644 --- a/.codespellignore +++ b/.codespellignore @@ -1,3 +1,4 @@ doubleclick wan nwe +re-use diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ecb4fc191b..475926866d 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -866,7 +866,7 @@ dig_at() { # It will also give extra assurance that Pi-hole is correctly resolving and blocking domains local random_url random_url=$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity WHERE domain not like '||%^' ORDER BY RANDOM() LIMIT 1") - # Falback if no non-ABP style domains were found + # Fallback if no non-ABP style domains were found if [ -z "${random_url}" ]; then random_url="flurry.com" fi @@ -1503,7 +1503,7 @@ upload_to_tricorder() { # If no token was generated else # Show an error and some help instructions - # Skip this if being called from web interface and autmatic mode was not chosen (users opt-out to upload) + # Skip this if being called from web interface and automatic mode was not chosen (users opt-out to upload) if [[ "${WEBCALL}" ]] && [[ ! "${AUTOMATED}" ]]; then : else diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 1f3002e77a..e87edd7147 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2685,7 +2685,7 @@ main() { # Check for and disable systemd-resolved-DNSStubListener before reloading resolved # DNSStubListener needs to remain in place for installer to download needed files, # so this change needs to be made after installation is complete, - # but before starting or resarting the dnsmasq or ftl services + # but before starting or restarting the dnsmasq or ftl services disable_resolved_stublistener # If the Web server was installed, From afa688e3a0e565e797804051bd74888712484ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 7 Oct 2023 00:21:06 +0200 Subject: [PATCH 491/638] Yu vs uh (https://www.theguardian.com/guardian-observer-style-guide-r#:~:text=re/re%2D,re%2Dsign/resign) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .codespellignore | 1 - advanced/Scripts/piholeDebug.sh | 2 +- test/test_any_automated_install.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.codespellignore b/.codespellignore index 6d05d295ae..501a3d6732 100644 --- a/.codespellignore +++ b/.codespellignore @@ -1,4 +1,3 @@ doubleclick wan nwe -re-use diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 475926866d..1ca52f4563 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -449,7 +449,7 @@ os_check() { } diagnose_operating_system() { - # error message in a variable so we can easily modify it later (or re-use it) + # error message in a variable so we can easily modify it later (or reuse it) local error_msg="Distribution unknown -- most likely you are on an unsupported platform and may run into issues." # Display the current test that is running echo_current_diagnostic "Operating system" diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 36a4f0d2ea..840d1df70c 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -70,7 +70,7 @@ def test_setupVars_are_sourced_to_global_scope(host): def test_setupVars_saved_to_file(host): """ - confirm saved settings are written to a file for future updates to re-use + confirm saved settings are written to a file for future updates to reuse """ # dedent works better with this and padding matching script below set_setup_vars = "\n" From f52b2b98630dc0f606fed94d74abee6dc2b22582 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 10:23:00 +0000 Subject: [PATCH 492/638] Bump actions/setup-python from 4.7.0 to 4.7.1 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.7.0 to 4.7.1. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.7.0...v4.7.1) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ae03db07de..623590da66 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,7 +68,7 @@ jobs: uses: actions/checkout@v4.1.0 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.0 + uses: actions/setup-python@v4.7.1 with: python-version: "3.10" From 71357ecae7900b880ad336a6583491595491a350 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 8 Oct 2023 14:12:02 +0100 Subject: [PATCH 493/638] adminlte->web Signed-off-by: Adam Warner --- README.md | 2 +- advanced/Scripts/chronometer.sh | 2 +- advanced/Scripts/update.sh | 2 +- advanced/Scripts/updatecheck.sh | 4 ++-- advanced/Scripts/version.sh | 18 +++++++++--------- advanced/Scripts/webpage.sh | 2 +- automated install/basic-install.sh | 6 +++--- manpages/pihole.8 | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index adfd345017..eb50030b01 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ You can read our [Core Feature Breakdown](https://docs.pi-hole.net/core/pihole-c ### The Web Interface Dashboard -This [optional dashboard](https://github.com/pi-hole/AdminLTE) allows you to view stats, change settings, and configure your Pi-hole. It's the power of the Command Line Interface, with none of the learning curve! +This [optional dashboard](https://github.com/pi-hole/web) allows you to view stats, change settings, and configure your Pi-hole. It's the power of the Command Line Interface, with none of the learning curve! Some notable features include: diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index d69a56d33c..bb94a857d2 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -233,7 +233,7 @@ get_sys_stats() { if [[ -n "${ph_ver_raw[0]}" ]]; then ph_core_ver="${ph_ver_raw[0]}" if [[ ${#ph_ver_raw[@]} -eq 2 ]]; then - # AdminLTE not installed + # web not installed ph_lte_ver="(not installed)" ph_ftl_ver="${ph_ver_raw[1]}" else diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index c41c923230..1b9997a612 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -11,7 +11,7 @@ # Please see LICENSE file for your rights under this license. # Variables -readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git" +readonly ADMIN_INTERFACE_GIT_URL="https://github.com/pi-hole/web.git" readonly ADMIN_INTERFACE_DIR="/var/www/html/admin" readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_FILES_DIR="/etc/.pihole" diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 0cc652188e..8ce69a7575 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -97,10 +97,10 @@ if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then WEB_HASH="$(get_local_hash /var/www/html/admin)" addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" - GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" + GITHUB_WEB_VERSION="$(get_remote_version web)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" - GITHUB_WEB_HASH="$(get_remote_hash AdminLTE "${WEB_BRANCH}")" + GITHUB_WEB_HASH="$(get_remote_hash web "${WEB_BRANCH}")" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}" fi diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 946c69fe56..83fd0f39ac 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -28,7 +28,7 @@ fi getLocalVersion() { case ${1} in "Pi-hole" ) echo "${CORE_VERSION:=N/A}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION:=N/A}";; + "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION:=N/A}";; "FTL" ) echo "${FTL_VERSION:=N/A}";; esac } @@ -36,7 +36,7 @@ getLocalVersion() { getLocalHash() { case ${1} in "Pi-hole" ) echo "${CORE_HASH:=N/A}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH:=N/A}";; + "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH:=N/A}";; "FTL" ) echo "${FTL_HASH:=N/A}";; esac } @@ -44,7 +44,7 @@ getLocalHash() { getRemoteHash(){ case ${1} in "Pi-hole" ) echo "${GITHUB_CORE_HASH:=N/A}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH:=N/A}";; + "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH:=N/A}";; "FTL" ) echo "${GITHUB_FTL_HASH:=N/A}";; esac } @@ -52,7 +52,7 @@ getRemoteHash(){ getRemoteVersion(){ case ${1} in "Pi-hole" ) echo "${GITHUB_CORE_VERSION:=N/A}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION:=N/A}";; + "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION:=N/A}";; "FTL" ) echo "${GITHUB_FTL_VERSION:=N/A}";; esac } @@ -60,13 +60,13 @@ getRemoteVersion(){ getLocalBranch(){ case ${1} in "Pi-hole" ) echo "${CORE_BRANCH:=N/A}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH:=N/A}";; + "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH:=N/A}";; "FTL" ) echo "${FTL_BRANCH:=N/A}";; esac } versionOutput() { - if [ "$1" = "AdminLTE" ] && [ "${INSTALL_WEB_INTERFACE}" != true ]; then + if [ "$1" = "web" ] && [ "${INSTALL_WEB_INTERFACE}" != true ]; then echo " WebAdmin not installed" return 1 fi @@ -117,7 +117,7 @@ defaultOutput() { versionOutput "Pi-hole" "$@" if [ "${INSTALL_WEB_INTERFACE}" = true ]; then - versionOutput "AdminLTE" "$@" + versionOutput "web" "$@" fi versionOutput "FTL" "$@" @@ -130,7 +130,7 @@ Show Pi-hole, Admin Console & FTL versions Repositories: -p, --pihole Only retrieve info regarding Pi-hole repository - -a, --admin Only retrieve info regarding AdminLTE repository + -a, --admin Only retrieve info regarding web repository -f, --ftl Only retrieve info regarding FTL repository Options: @@ -143,7 +143,7 @@ Options: case "${1}" in "-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";; - "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";; + "-a" | "--admin" ) shift; versionOutput "web" "$@";; "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; "-h" | "--help" ) helpFunc;; * ) defaultOutput "$@";; diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index c92d0458dd..e05a6aff37 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -348,7 +348,7 @@ SetDNSServers() { IFS=',' read -r -a array <<< "${args[2]}" for index in "${!array[@]}" do - # Replace possible "\#" by "#". This fixes AdminLTE#1427 + # Replace possible "\#" by "#". This fixes web#1427 local ip ip="${array[index]//\\#/#}" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e87edd7147..4c69788fb3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -68,11 +68,11 @@ webroot="/var/www/html" # We clone (or update) two git repositories during the install. This helps to make sure that we always have the latest versions of the relevant files. -# AdminLTE is used to set up the Web admin interface. +# web is used to set up the Web admin interface. # Pi-hole contains various setup scripts and files which are critical to the installation. # Search for "PI_HOLE_LOCAL_REPO" in this file to see all such scripts. # Two notable scripts are gravity.sh (used to generate the HOSTS file) and advanced/Scripts/webpage.sh (used to install the Web admin interface) -webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" +webInterfaceGitUrl="https://github.com/pi-hole/web.git" webInterfaceDir="${webroot}/admin" piholeGitUrl="https://github.com/pi-hole/pi-hole.git" PI_HOLE_LOCAL_REPO="/etc/.pihole" @@ -334,7 +334,7 @@ package_manager_detect() { # 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") - # Prior to PHP8.0, JSON functionality is provided as dedicated module, required by Pi-hole AdminLTE: https://www.php.net/manual/json.installation.php + # Prior to PHP8.0, JSON functionality is provided as dedicated module, required by Pi-hole web: https://www.php.net/manual/json.installation.php if [[ -z "${phpInsMajor}" || "${phpInsMajor}" -lt 8 ]]; then PIHOLE_WEB_DEPS+=("${phpVer}-json") fi diff --git a/manpages/pihole.8 b/manpages/pihole.8 index 1cf8ab3554..fec1fa5ecf 100644 --- a/manpages/pihole.8 +++ b/manpages/pihole.8 @@ -212,7 +212,7 @@ Available commands and options: .br -p, --pihole Only retrieve info regarding Pi-hole repository .br - -a, --admin Only retrieve info regarding AdminLTE + -a, --admin Only retrieve info regarding web repository .br -f, --ftl Only retrieve info regarding FTL repository @@ -339,7 +339,7 @@ Displaying version information \fBpihole -v -a -c\fR .br - Display the current version of AdminLTE + Display the current version of web .br Temporarily disabling Pi-hole From 2a72012ca1448b8e2f7f0de3e79c6b9d7d72b7cc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 21 Oct 2023 10:55:06 +0000 Subject: [PATCH 494/638] Bump actions/checkout from 4.1.0 to 4.1.1 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 4685aa2cc2..6544db61f5 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 14c55d102b..0e149c79b3 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -40,7 +40,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }} env: diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index a10256299e..e52d4ae9af 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 623590da66..b070c982ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Check scripts in repository are executable run: | @@ -65,7 +65,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v4.1.0 + uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 uses: actions/setup-python@v4.7.1 From ec86124997d1b8969be2f528fc63b2626486eb73 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 28 Oct 2023 10:32:55 +0000 Subject: [PATCH 495/638] Bump pytest from 7.4.2 to 7.4.3 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.2 to 7.4.3. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.4.2...7.4.3) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 27417754b5..45c7c7c0e6 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ pyyaml == 6.0.1 -pytest == 7.4.2 +pytest == 7.4.3 pytest-xdist == 3.3.1 pytest-testinfra == 9.0.0 tox == 4.11.3 From 3c4f217876f9ad7f8889b94d0499a480518f8a22 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 18 Nov 2023 10:27:10 +0000 Subject: [PATCH 496/638] Bump pytest-xdist from 3.3.1 to 3.4.0 in /test Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 3.3.1 to 3.4.0. - [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v3.3.1...v3.4.0) --- updated-dependencies: - dependency-name: pytest-xdist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 45c7c7c0e6..564231920b 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ pyyaml == 6.0.1 pytest == 7.4.3 -pytest-xdist == 3.3.1 +pytest-xdist == 3.4.0 pytest-testinfra == 9.0.0 tox == 4.11.3 From 2e73eb36efbd129a105f5e18bfa0a6dd1b240032 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 18 Nov 2023 10:54:16 +0000 Subject: [PATCH 497/638] Bump pytest-testinfra from 9.0.0 to 10.0.0 in /test Bumps [pytest-testinfra](https://github.com/pytest-dev/pytest-testinfra) from 9.0.0 to 10.0.0. - [Release notes](https://github.com/pytest-dev/pytest-testinfra/releases) - [Changelog](https://github.com/pytest-dev/pytest-testinfra/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-testinfra/compare/9.0.0...10.0.0) --- updated-dependencies: - dependency-name: pytest-testinfra dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 564231920b..74c67fd94f 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ pyyaml == 6.0.1 pytest == 7.4.3 pytest-xdist == 3.4.0 -pytest-testinfra == 9.0.0 +pytest-testinfra == 10.0.0 tox == 4.11.3 From 9d57f6493751d319440727f927f099887decb886 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 25 Nov 2023 10:58:21 +0000 Subject: [PATCH 498/638] Bump pytest-xdist from 3.4.0 to 3.5.0 in /test Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/pytest-dev/pytest-xdist/releases) - [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v3.4.0...v3.5.0) --- updated-dependencies: - dependency-name: pytest-xdist dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 74c67fd94f..799e3fadfe 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ pyyaml == 6.0.1 pytest == 7.4.3 -pytest-xdist == 3.4.0 +pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 tox == 4.11.3 From bfc824f2ff05f56d24697230463a3ec0bf2a25cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Dec 2023 10:04:50 +0000 Subject: [PATCH 499/638] Bump tox from 4.11.3 to 4.11.4 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.11.3 to 4.11.4. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.11.3...4.11.4) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 799e3fadfe..bfc6d0278c 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.3 pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 -tox == 4.11.3 +tox == 4.11.4 From 16180e4b234510d3c52545f817164fd9873448a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Dec 2023 10:36:44 +0000 Subject: [PATCH 500/638] Bump actions/setup-python from 4.7.1 to 5.0.0 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.7.1 to 5.0.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4.7.1...v5.0.0) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b070c982ba..35ed0c3063 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,7 +68,7 @@ jobs: uses: actions/checkout@v4.1.1 - name: Set up Python 3.10 - uses: actions/setup-python@v4.7.1 + uses: actions/setup-python@v5.0.0 with: python-version: "3.10" From c34464d1e8f6e0ba5731171791d9a31d801dfa5c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Dec 2023 10:36:49 +0000 Subject: [PATCH 501/638] Bump actions/stale from 8.0.0 to 9.0.0 Bumps [actions/stale](https://github.com/actions/stale) from 8.0.0 to 9.0.0. - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/v8.0.0...v9.0.0) --- updated-dependencies: - dependency-name: actions/stale dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/stale.yml | 2 +- .github/workflows/stale_pr.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 0e149c79b3..095d7358bf 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -17,7 +17,7 @@ jobs: issues: write steps: - - uses: actions/stale@v8.0.0 + - uses: actions/stale@v9.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} days-before-stale: 30 diff --git a/.github/workflows/stale_pr.yml b/.github/workflows/stale_pr.yml index 2db2a25d5e..9665081899 100644 --- a/.github/workflows/stale_pr.yml +++ b/.github/workflows/stale_pr.yml @@ -17,7 +17,7 @@ jobs: pull-requests: write steps: - - uses: actions/stale@v8.0.0 + - uses: actions/stale@v9.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} # Do not automatically mark PR/issue as stale From 3f7413d538dae3524b0a5d627668aecd60bcd815 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 9 Dec 2023 23:07:35 +0100 Subject: [PATCH 502/638] Add "-ni" to all sqlite3 invocations Signed-off-by: DL6ER --- .../Scripts/database_migration/gravity-db.sh | 30 ++++++++-------- advanced/Scripts/list.sh | 20 +++++------ advanced/Scripts/piholeARPTable.sh | 4 +-- advanced/Scripts/piholeDebug.sh | 12 +++---- advanced/Scripts/piholeLogFlush.sh | 2 +- advanced/Scripts/query.sh | 6 ++-- advanced/Scripts/webpage.sh | 12 +++---- gravity.sh | 36 +++++++++---------- 8 files changed, 61 insertions(+), 61 deletions(-) diff --git a/advanced/Scripts/database_migration/gravity-db.sh b/advanced/Scripts/database_migration/gravity-db.sh index a7ba60a919..1459ecd9b7 100755 --- a/advanced/Scripts/database_migration/gravity-db.sh +++ b/advanced/Scripts/database_migration/gravity-db.sh @@ -19,13 +19,13 @@ upgrade_gravityDB(){ auditFile="${piholeDir}/auditlog.list" # Get database version - version="$(pihole-FTL sqlite3 "${database}" "SELECT \"value\" FROM \"info\" WHERE \"property\" = 'version';")" + version="$(pihole-FTL sqlite3 -ni "${database}" "SELECT \"value\" FROM \"info\" WHERE \"property\" = 'version';")" if [[ "$version" == "1" ]]; then # This migration script upgrades the gravity.db file by # adding the domain_audit table echo -e " ${INFO} Upgrading gravity database from version 1 to 2" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/1_to_2.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/1_to_2.sql" version=2 # Store audit domains in database table @@ -40,28 +40,28 @@ upgrade_gravityDB(){ # renaming the regex table to regex_blacklist, and # creating a new regex_whitelist table + corresponding linking table and views echo -e " ${INFO} Upgrading gravity database from version 2 to 3" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/2_to_3.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/2_to_3.sql" version=3 fi if [[ "$version" == "3" ]]; then # This migration script unifies the formally separated domain # lists into a single table with a UNIQUE domain constraint echo -e " ${INFO} Upgrading gravity database from version 3 to 4" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/3_to_4.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/3_to_4.sql" version=4 fi if [[ "$version" == "4" ]]; then # This migration script upgrades the gravity and list views # implementing necessary changes for per-client blocking echo -e " ${INFO} Upgrading gravity database from version 4 to 5" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/4_to_5.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/4_to_5.sql" version=5 fi if [[ "$version" == "5" ]]; then # This migration script upgrades the adlist view # to return an ID used in gravity.sh echo -e " ${INFO} Upgrading gravity database from version 5 to 6" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/5_to_6.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/5_to_6.sql" version=6 fi if [[ "$version" == "6" ]]; then @@ -69,7 +69,7 @@ upgrade_gravityDB(){ # which is automatically associated to all clients not # having their own group assignments echo -e " ${INFO} Upgrading gravity database from version 6 to 7" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/6_to_7.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/6_to_7.sql" version=7 fi if [[ "$version" == "7" ]]; then @@ -77,21 +77,21 @@ upgrade_gravityDB(){ # to ensure uniqueness on the group name # We also add date_added and date_modified columns echo -e " ${INFO} Upgrading gravity database from version 7 to 8" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/7_to_8.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/7_to_8.sql" version=8 fi if [[ "$version" == "8" ]]; then # This migration fixes some issues that were introduced # in the previous migration script. echo -e " ${INFO} Upgrading gravity database from version 8 to 9" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/8_to_9.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/8_to_9.sql" version=9 fi if [[ "$version" == "9" ]]; then # This migration drops unused tables and creates triggers to remove # obsolete groups assignments when the linked items are deleted echo -e " ${INFO} Upgrading gravity database from version 9 to 10" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/9_to_10.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/9_to_10.sql" version=10 fi if [[ "$version" == "10" ]]; then @@ -101,31 +101,31 @@ upgrade_gravityDB(){ # to keep the copying process generic (needs the same columns in both the # source and the destination databases). echo -e " ${INFO} Upgrading gravity database from version 10 to 11" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/10_to_11.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/10_to_11.sql" version=11 fi if [[ "$version" == "11" ]]; then # Rename group 0 from "Unassociated" to "Default" echo -e " ${INFO} Upgrading gravity database from version 11 to 12" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/11_to_12.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/11_to_12.sql" version=12 fi if [[ "$version" == "12" ]]; then # Add column date_updated to adlist table echo -e " ${INFO} Upgrading gravity database from version 12 to 13" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/12_to_13.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/12_to_13.sql" version=13 fi if [[ "$version" == "13" ]]; then # Add columns number and status to adlist table echo -e " ${INFO} Upgrading gravity database from version 13 to 14" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/13_to_14.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/13_to_14.sql" version=14 fi if [[ "$version" == "14" ]]; then # Changes the vw_adlist created in 5_to_6 echo -e " ${INFO} Upgrading gravity database from version 14 to 15" - pihole-FTL sqlite3 "${database}" < "${scriptPath}/14_to_15.sql" + pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/14_to_15.sql" version=15 fi } diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index b76a7ef7ac..76558e5827 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -150,18 +150,18 @@ AddDomain() { domain="$1" # Is the domain in the list we want to add it to? - num="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}';")" + num="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}';")" requestedListname="$(GetListnameFromTypeId "${typeId}")" if [[ "${num}" -ne 0 ]]; then - existingTypeId="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT type FROM domainlist WHERE domain = '${domain}';")" + existingTypeId="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT type FROM domainlist WHERE domain = '${domain}';")" if [[ "${existingTypeId}" == "${typeId}" ]]; then if [[ "${verbose}" == true ]]; then echo -e " ${INFO} ${1} already exists in ${requestedListname}, no need to add!" fi else existingListname="$(GetListnameFromTypeId "${existingTypeId}")" - pihole-FTL sqlite3 "${gravityDBfile}" "UPDATE domainlist SET type = ${typeId} WHERE domain='${domain}';" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "UPDATE domainlist SET type = ${typeId} WHERE domain='${domain}';" if [[ "${verbose}" == true ]]; then echo -e " ${INFO} ${1} already exists in ${existingListname}, it has been moved to ${requestedListname}!" fi @@ -177,10 +177,10 @@ AddDomain() { # Insert only the domain here. The enabled and date_added fields will be filled # with their default values (enabled = true, date_added = current timestamp) if [[ -z "${comment}" ]]; then - pihole-FTL sqlite3 "${gravityDBfile}" "INSERT INTO domainlist (domain,type) VALUES ('${domain}',${typeId});" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "INSERT INTO domainlist (domain,type) VALUES ('${domain}',${typeId});" else # also add comment when variable has been set through the "--comment" option - pihole-FTL sqlite3 "${gravityDBfile}" "INSERT INTO domainlist (domain,type,comment) VALUES ('${domain}',${typeId},'${comment}');" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "INSERT INTO domainlist (domain,type,comment) VALUES ('${domain}',${typeId},'${comment}');" fi } @@ -189,7 +189,7 @@ RemoveDomain() { domain="$1" # Is the domain in the list we want to remove it from? - num="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};")" + num="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT COUNT(*) FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};")" requestedListname="$(GetListnameFromTypeId "${typeId}")" @@ -206,14 +206,14 @@ RemoveDomain() { fi reload=true # Remove it from the current list - pihole-FTL sqlite3 "${gravityDBfile}" "DELETE FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "DELETE FROM domainlist WHERE domain = '${domain}' AND type = ${typeId};" } Displaylist() { local count num_pipes domain enabled status nicedate requestedListname requestedListname="$(GetListnameFromTypeId "${typeId}")" - data="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT domain,enabled,date_modified FROM domainlist WHERE type = ${typeId};" 2> /dev/null)" + data="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT domain,enabled,date_modified FROM domainlist WHERE type = ${typeId};" 2> /dev/null)" if [[ -z $data ]]; then echo -e "Not showing empty list" @@ -251,10 +251,10 @@ Displaylist() { } NukeList() { - count=$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(1) FROM domainlist WHERE type = ${typeId};") + count=$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT COUNT(1) FROM domainlist WHERE type = ${typeId};") listname="$(GetListnameFromTypeId "${typeId}")" if [ "$count" -gt 0 ];then - pihole-FTL sqlite3 "${gravityDBfile}" "DELETE FROM domainlist WHERE type = ${typeId};" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "DELETE FROM domainlist WHERE type = ${typeId};" echo " ${TICK} Removed ${count} domain(s) from the ${listname}" else echo " ${INFO} ${listname} already empty. Nothing to do!" diff --git a/advanced/Scripts/piholeARPTable.sh b/advanced/Scripts/piholeARPTable.sh index 5daa025d49..b92dd1242c 100755 --- a/advanced/Scripts/piholeARPTable.sh +++ b/advanced/Scripts/piholeARPTable.sh @@ -39,7 +39,7 @@ flushARP(){ # Truncate network_addresses table in pihole-FTL.db # This needs to be done before we can truncate the network table due to # foreign key constraints - if ! output=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM network_addresses" 2>&1); then + if ! output=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM network_addresses" 2>&1); then echo -e "${OVER} ${CROSS} Failed to truncate network_addresses table" echo " Database location: ${DBFILE}" echo " Output: ${output}" @@ -47,7 +47,7 @@ flushARP(){ fi # Truncate network table in pihole-FTL.db - if ! output=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM network" 2>&1); then + if ! output=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM network" 2>&1); then echo -e "${OVER} ${CROSS} Failed to truncate network table" echo " Database location: ${DBFILE}" echo " Output: ${output}" diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1ca52f4563..fb1efbebc3 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -865,7 +865,7 @@ dig_at() { # This helps emulate queries to different domains that a user might query # It will also give extra assurance that Pi-hole is correctly resolving and blocking domains local random_url - random_url=$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity WHERE domain not like '||%^' ORDER BY RANDOM() LIMIT 1") + random_url=$(pihole-FTL sqlite3 -ni "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity WHERE domain not like '||%^' ORDER BY RANDOM() LIMIT 1") # Fallback if no non-ABP style domains were found if [ -z "${random_url}" ]; then random_url="flurry.com" @@ -1226,7 +1226,7 @@ show_db_entries() { IFS=$'\r\n' local entries=() mapfile -t entries < <(\ - pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" \ + pihole-FTL sqlite3 -ni "${PIHOLE_GRAVITY_DB_FILE}" \ -cmd ".headers on" \ -cmd ".mode column" \ -cmd ".width ${widths}" \ @@ -1251,7 +1251,7 @@ show_FTL_db_entries() { IFS=$'\r\n' local entries=() mapfile -t entries < <(\ - pihole-FTL sqlite3 "${PIHOLE_FTL_DB_FILE}" \ + pihole-FTL sqlite3 -ni "${PIHOLE_FTL_DB_FILE}" \ -cmd ".headers on" \ -cmd ".mode column" \ -cmd ".width ${widths}" \ @@ -1317,7 +1317,7 @@ analyze_gravity_list() { fi show_db_entries "Info table" "SELECT property,value FROM info" "20 40" - gravity_updated_raw="$(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT value FROM info where property = 'updated'")" + gravity_updated_raw="$(pihole-FTL sqlite3 -ni "${PIHOLE_GRAVITY_DB_FILE}" "SELECT value FROM info where property = 'updated'")" gravity_updated="$(date -d @"${gravity_updated_raw}")" log_write " Last gravity run finished at: ${COL_CYAN}${gravity_updated}${COL_NC}" log_write "" @@ -1325,7 +1325,7 @@ analyze_gravity_list() { OLD_IFS="$IFS" IFS=$'\r\n' local gravity_sample=() - mapfile -t gravity_sample < <(pihole-FTL sqlite3 "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity LIMIT 10") + mapfile -t gravity_sample < <(pihole-FTL sqlite3 -ni "${PIHOLE_GRAVITY_DB_FILE}" "SELECT domain FROM vw_gravity LIMIT 10") log_write " ${COL_CYAN}----- First 10 Gravity Domains -----${COL_NC}" for line in "${gravity_sample[@]}"; do @@ -1357,7 +1357,7 @@ database_integrity_check(){ log_write "${INFO} Checking foreign key constraints of ${database} ... (this can take several minutes)" unset result - result="$(pihole-FTL sqlite3 "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1 & spinner)" + result="$(pihole-FTL sqlite3 -ni "${database}" -cmd ".headers on" -cmd ".mode column" "PRAGMA foreign_key_check" 2>&1 & spinner)" if [[ -z ${result} ]]; then log_write "${TICK} No foreign key errors in ${database}" else diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 3473fad591..b06aac8bb6 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -63,7 +63,7 @@ else fi fi # Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history) - deleted=$(pihole-FTL sqlite3 "${DBFILE}" "DELETE FROM query_storage WHERE timestamp >= strftime('%s','now')-86400; select changes() from query_storage limit 1") + deleted=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM query_storage WHERE timestamp >= strftime('%s','now')-86400; select changes() from query_storage limit 1") # Restart pihole-FTL to force reloading history sudo pihole restartdns diff --git a/advanced/Scripts/query.sh b/advanced/Scripts/query.sh index 1d3b0a29a0..ebcc6f79c9 100755 --- a/advanced/Scripts/query.sh +++ b/advanced/Scripts/query.sh @@ -96,7 +96,7 @@ scanDatabaseTable() { # Are there ABP entries on gravity? # Return 1 if abp_domain=1 or Zero if abp_domain=0 or not set abpquerystr="SELECT EXISTS (SELECT 1 FROM info WHERE property='abp_domains' and value='1')" - abpfound="$(pihole-FTL sqlite3 "${gravityDBfile}" "${abpquerystr}")" 2> /dev/null + abpfound="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "${abpquerystr}")" 2> /dev/null # Create search string for ABP entries only if needed if [ "${abpfound}" -eq 1 ]; then @@ -129,7 +129,7 @@ scanDatabaseTable() { fi # Send prepared query to gravity database - result="$(pihole-FTL sqlite3 -separator ',' "${gravityDBfile}" "${querystr}")" 2> /dev/null + result="$(pihole-FTL sqlite3 -ni -separator ',' "${gravityDBfile}" "${querystr}")" 2> /dev/null if [[ -z "${result}" ]]; then # Return early when there are no matches in this table return @@ -166,7 +166,7 @@ scanRegexDatabaseTable() { list_type="${3:-}" # Query all regex from the corresponding database tables - mapfile -t regexList < <(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT domain FROM domainlist WHERE type = ${list_type}" 2> /dev/null) + mapfile -t regexList < <(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT domain FROM domainlist WHERE type = ${list_type}" 2> /dev/null) # If we have regexps to process if [[ "${#regexList[@]}" -ne 0 ]]; then diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e05a6aff37..62ab4ea98c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -560,13 +560,13 @@ CustomizeAdLists() { if CheckUrl "${address}"; then if [[ "${args[2]}" == "enable" ]]; then - pihole-FTL sqlite3 "${gravityDBfile}" "UPDATE adlist SET enabled = 1 WHERE address = '${address}'" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "UPDATE adlist SET enabled = 1 WHERE address = '${address}'" elif [[ "${args[2]}" == "disable" ]]; then - pihole-FTL sqlite3 "${gravityDBfile}" "UPDATE adlist SET enabled = 0 WHERE address = '${address}'" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "UPDATE adlist SET enabled = 0 WHERE address = '${address}'" elif [[ "${args[2]}" == "add" ]]; then - pihole-FTL sqlite3 "${gravityDBfile}" "INSERT OR IGNORE INTO adlist (address, comment) VALUES ('${address}', '${comment}')" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "INSERT OR IGNORE INTO adlist (address, comment) VALUES ('${address}', '${comment}')" elif [[ "${args[2]}" == "del" ]]; then - pihole-FTL sqlite3 "${gravityDBfile}" "DELETE FROM adlist WHERE address = '${address}'" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "DELETE FROM adlist WHERE address = '${address}'" else echo "Not permitted" return 1 @@ -700,12 +700,12 @@ addAudit() done # Insert only the domain here. The date_added field will be # filled with its default value (date_added = current timestamp) - pihole-FTL sqlite3 "${gravityDBfile}" "INSERT INTO domain_audit (domain) VALUES ${domains};" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "INSERT INTO domain_audit (domain) VALUES ${domains};" } clearAudit() { - pihole-FTL sqlite3 "${gravityDBfile}" "DELETE FROM domain_audit;" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "DELETE FROM domain_audit;" } SetPrivacyLevel() { diff --git a/gravity.sh b/gravity.sh index db19909027..62631e3c26 100755 --- a/gravity.sh +++ b/gravity.sh @@ -84,7 +84,7 @@ fi # Generate new SQLite3 file from schema template generate_gravity_database() { - if ! pihole-FTL sqlite3 "${gravityDBfile}" < "${gravityDBschema}"; then + if ! pihole-FTL sqlite3 -ni "${gravityDBfile}" < "${gravityDBschema}"; then echo -e " ${CROSS} Unable to create ${gravityDBfile}" return 1 fi @@ -99,7 +99,7 @@ gravity_swap_databases() { echo -ne " ${INFO} ${str}..." # The index is intentionally not UNIQUE as poor quality adlists may contain domains more than once - output=$( { pihole-FTL sqlite3 "${gravityTEMPfile}" "CREATE INDEX idx_gravity ON gravity (domain, adlist_id);"; } 2>&1 ) + output=$( { pihole-FTL sqlite3 -ni "${gravityTEMPfile}" "CREATE INDEX idx_gravity ON gravity (domain, adlist_id);"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -135,7 +135,7 @@ gravity_swap_databases() { # Update timestamp when the gravity table was last updated successfully update_gravity_timestamp() { - output=$( { printf ".timeout 30000\\nINSERT OR REPLACE INTO info (property,value) values ('updated',cast(strftime('%%s', 'now') as int));" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nINSERT OR REPLACE INTO info (property,value) values ('updated',cast(strftime('%%s', 'now') as int));" | pihole-FTL sqlite3 -ni "${gravityDBfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -179,7 +179,7 @@ database_table_from_file() { # Get MAX(id) from domainlist when INSERTing into this table if [[ "${table}" == "domainlist" ]]; then - rowid="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT MAX(id) FROM domainlist;")" + rowid="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT MAX(id) FROM domainlist;")" if [[ -z "$rowid" ]]; then rowid=0 fi @@ -209,7 +209,7 @@ database_table_from_file() { # Store domains in database table specified by ${table} # Use printf as .mode and .import need to be on separate lines # see https://unix.stackexchange.com/a/445615/83260 - output=$( { printf ".timeout 30000\\n.mode csv\\n.import \"%s\" %s\\n" "${tmpFile}" "${table}" | pihole-FTL sqlite3 "${gravityDBfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\n.mode csv\\n.import \"%s\" %s\\n" "${tmpFile}" "${table}" | pihole-FTL sqlite3 -ni "${gravityDBfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -229,7 +229,7 @@ database_table_from_file() { # Check if a column with name ${2} exists in gravity table with name ${1} gravity_column_exists() { - output=$( { printf ".timeout 30000\\nSELECT EXISTS(SELECT * FROM pragma_table_info('%s') WHERE name='%s');\\n" "${1}" "${2}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nSELECT EXISTS(SELECT * FROM pragma_table_info('%s') WHERE name='%s');\\n" "${1}" "${2}" | pihole-FTL sqlite3 -ni "${gravityTEMPfile}"; } 2>&1 ) if [[ "${output}" == "1" ]]; then return 0 # Bash 0 is success fi @@ -244,7 +244,7 @@ database_adlist_number() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${2}" "${3}" "${1}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET number = %i, invalid_domains = %i WHERE id = %i;\\n" "${2}" "${3}" "${1}" | pihole-FTL sqlite3 -ni "${gravityTEMPfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -260,7 +260,7 @@ database_adlist_status() { return; fi - output=$( { printf ".timeout 30000\\nUPDATE adlist SET status = %i WHERE id = %i;\\n" "${2}" "${1}" | pihole-FTL sqlite3 "${gravityTEMPfile}"; } 2>&1 ) + output=$( { printf ".timeout 30000\\nUPDATE adlist SET status = %i WHERE id = %i;\\n" "${2}" "${1}" | pihole-FTL sqlite3 -ni "${gravityTEMPfile}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -378,8 +378,8 @@ gravity_DownloadBlocklists() { # Retrieve source URLs from gravity database # We source only enabled adlists, SQLite3 stores boolean values as 0 (false) or 1 (true) - mapfile -t sources <<< "$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2> /dev/null)" - mapfile -t sourceIDs <<< "$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT id FROM vw_adlist;" 2> /dev/null)" + mapfile -t sources <<< "$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT address FROM vw_adlist;" 2> /dev/null)" + mapfile -t sourceIDs <<< "$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT id FROM vw_adlist;" 2> /dev/null)" # Parse source domains from $sources mapfile -t sourceDomains <<< "$( @@ -408,7 +408,7 @@ gravity_DownloadBlocklists() { str="Preparing new gravity database" echo -ne " ${INFO} ${str}..." rm "${gravityTEMPfile}" > /dev/null 2>&1 - output=$( { pihole-FTL sqlite3 "${gravityTEMPfile}" < "${gravityDBschema}"; } 2>&1 ) + output=$( { pihole-FTL sqlite3 -ni "${gravityTEMPfile}" < "${gravityDBschema}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -428,7 +428,7 @@ gravity_DownloadBlocklists() { copyGravity="${copyGravity//"${gravityDBfile_default}"/"${gravityDBfile}"}" fi - output=$( { pihole-FTL sqlite3 "${gravityTEMPfile}" <<< "${copyGravity}"; } 2>&1 ) + output=$( { pihole-FTL sqlite3 -ni "${gravityTEMPfile}" <<< "${copyGravity}"; } 2>&1 ) status="$?" if [[ "${status}" -ne 0 ]]; then @@ -668,12 +668,12 @@ gravity_Table_Count() { local table="${1}" local str="${2}" local num - num="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM ${table};")" + num="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT COUNT(*) FROM ${table};")" if [[ "${table}" == "gravity" ]]; then local unique - unique="$(pihole-FTL sqlite3 "${gravityDBfile}" "SELECT COUNT(*) FROM (SELECT DISTINCT domain FROM ${table});")" + unique="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "SELECT COUNT(*) FROM (SELECT DISTINCT domain FROM ${table});")" echo -e " ${INFO} Number of ${str}: ${num} (${COL_BOLD}${unique} unique domains${COL_NC})" - pihole-FTL sqlite3 "${gravityDBfile}" "INSERT OR REPLACE INTO info (property,value) VALUES ('gravity_count',${unique});" + pihole-FTL sqlite3 -ni "${gravityDBfile}" "INSERT OR REPLACE INTO info (property,value) VALUES ('gravity_count',${unique});" else echo -e " ${INFO} Number of ${str}: ${num}" fi @@ -754,7 +754,7 @@ database_recovery() { local str="Checking integrity of existing gravity database (this can take a while)" local option="${1}" echo -ne " ${INFO} ${str}..." - result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA integrity_check" 2>&1)" + result="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "PRAGMA integrity_check" 2>&1)" if [[ ${result} = "ok" ]]; then echo -e "${OVER} ${TICK} ${str} - no errors found" @@ -762,7 +762,7 @@ database_recovery() { str="Checking foreign keys of existing gravity database (this can take a while)" echo -ne " ${INFO} ${str}..." unset result - result="$(pihole-FTL sqlite3 "${gravityDBfile}" "PRAGMA foreign_key_check" 2>&1)" + result="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" "PRAGMA foreign_key_check" 2>&1)" if [[ -z ${result} ]]; then echo -e "${OVER} ${TICK} ${str} - no errors found" if [[ "${option}" != "force" ]]; then @@ -781,7 +781,7 @@ database_recovery() { echo -ne " ${INFO} ${str}..." # We have to remove any possibly existing recovery database or this will fail rm -f "${gravityDBfile}.recovered" > /dev/null 2>&1 - if result="$(pihole-FTL sqlite3 "${gravityDBfile}" ".recover" | pihole-FTL sqlite3 "${gravityDBfile}.recovered" 2>&1)"; then + if result="$(pihole-FTL sqlite3 -ni "${gravityDBfile}" ".recover" | pihole-FTL sqlite3 -ni "${gravityDBfile}.recovered" 2>&1)"; then echo -e "${OVER} ${TICK} ${str} - success" mv "${gravityDBfile}" "${gravityDBfile}.old" mv "${gravityDBfile}.recovered" "${gravityDBfile}" From e8338d059009f009f8b93461e4fee51792acb600 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 10 Dec 2023 10:41:00 +0100 Subject: [PATCH 503/638] Install FTL's development branch to get the latest features during tests Signed-off-by: DL6ER --- test/test_any_automated_install.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 840d1df70c..c1b9166446 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -176,6 +176,12 @@ def test_installPihole_fresh_install_readableFiles(host): setup_var_file += "INSTALL_WEB_INTERFACE=true\n" setup_var_file += "EOF\n" host.run(setup_var_file) + # Install FTL's development branch to get the latest features + host.run( + """ + echo "development" > /etc/pihole/ftlbranch + """ + ) install = host.run( """ export TERM=xterm @@ -431,6 +437,12 @@ def test_installPihole_fresh_install_readableBlockpage(host, test_webpage): setup_var_file += "INSTALL_WEB_INTERFACE=true\n" setup_var_file += "EOF\n" host.run(setup_var_file) + # Install FTL's development branch to get the latest features + host.run( + """ + echo "development" > /etc/pihole/ftlbranch + """ + ) installWeb = host.run( """ export TERM=xterm From c6049d400214d45f6bd9229e6fd3291a3d53f3dc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Dec 2023 10:30:20 +0000 Subject: [PATCH 504/638] Bump github/codeql-action from 2 to 3 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2 to 3. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v2...v3) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 6544db61f5..fc82119413 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -29,12 +29,12 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: 'python' - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 From 05e7d0ee9263e17e0bc6706b3822310d7ed084a3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 6 Jan 2024 10:10:22 +0000 Subject: [PATCH 505/638] Bump pytest from 7.4.3 to 7.4.4 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.3 to 7.4.4. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.4.3...7.4.4) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index bfc6d0278c..0873d097cc 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ pyyaml == 6.0.1 -pytest == 7.4.3 +pytest == 7.4.4 pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 tox == 4.11.4 From 9eb47319f572674c91ce0a49b5240ddb66aee027 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 13 Jan 2024 10:32:36 +0000 Subject: [PATCH 506/638] Bump tox from 4.11.4 to 4.12.0 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.11.4 to 4.12.0. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.11.4...4.12.0) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 0873d097cc..59fd13cc62 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.4 pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 -tox == 4.11.4 +tox == 4.12.0 From ba2682c907e446138f142c64b2bef4a617e79692 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 20 Jan 2024 10:38:21 +0000 Subject: [PATCH 507/638] Bump tox from 4.12.0 to 4.12.1 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.12.0 to 4.12.1. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.12.0...4.12.1) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 59fd13cc62..dea4ace91f 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 7.4.4 pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 -tox == 4.12.0 +tox == 4.12.1 From a23147163478e79f7015f50271ccdd9fdcc8f7be Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 20 Jan 2024 09:45:46 -0500 Subject: [PATCH 508/638] force db backup --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index aefbcecbe2..826e596fe9 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -54,7 +54,7 @@ Options: -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest interval, user 0 to disable Speedtests, use -sn to prevent logging to results list -in Reinstall Speedtest Mod - -up [un] [db] Update Pi-hole (and | but uninstall) the Mod (and flush the database) + -up [un] [db] Update Pi-hole and (uninstall) the Mod (and flush the database) -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database) -db Flush the database -sd Set speedtest display range @@ -546,7 +546,7 @@ SetWebUILayout() { } ClearSpeedtestData() { - mv $speedtestdb $speedtestdb.old + mv -f $speedtestdb $speedtestdb.old cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb } From 541ada92296c009a8bb3a0689b6fdb7838a9ab47 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 20 Jan 2024 10:10:59 -0500 Subject: [PATCH 509/638] temporarily allow restore after flush --- advanced/Scripts/webpage.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 826e596fe9..efeefe217d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -545,9 +545,18 @@ SetWebUILayout() { addOrEditKeyValPair "${setupVars}" "WEBUIBOXEDLAYOUT" "${args[2]}" } +hashFile() { + md5sum "$1" | cut -d ' ' -f 1 +} + ClearSpeedtestData() { - mv -f $speedtestdb $speedtestdb.old - cp /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db $speedtestdb + init_db=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db + if [[ -f $speedtestdb.old ]] && [[ $(hashFile $init_db) == $(hashFile $speedtestdb) ]]; then + mv -f $speedtestdb.old $speedtestdb + else + mv -f $speedtestdb $speedtestdb.old + cp $init_db $speedtestdb + fi } ChangeSpeedTestSchedule() { From c4c0a5e5df292f21b4206105861029731fbc8911 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 22 Jan 2024 06:17:39 -0500 Subject: [PATCH 510/638] update readme --- README.md | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 88e392610c..9169b10609 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,13 @@ -## This project is part of +# Pihole Speedtest Mod -https://github.com/arevindh/pihole-speedtest +[![Join the chat at https://gitter.im/pihole-speedtest/community](https://badges.gitter.im/pihole-speedtest/community.svg)](https://gitter.im/pihole-speedtest/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/TW9TfyM) -## About the project +Test your connection speed directly in the Pi-hole web interface! -This project is just another fun project integrating speedtest to PiHole Web UI. +Please go to the [main repository](https://github.com/arevindh/pihole-speedtest) for more information, including installation instructions, pull requests, and issues. -It will be using speedtest.net on background for testing. More frequent the speed tests more data will used. - -What does this mod have in extra ? - -1. Speedtest results of 1/2/4/7/30 days as graph. -2. Custom speed test server selection. -3. Detailed speedtest results page. -4. Ability to schedule speedtest interval. - -## Wiki - -Wiki is available here https://github.com/arevindh/pihole-speedtest/wiki +[Uninstall Instructions](https://github.com/arevindh/pihole-speedtest/wiki/Uninstalling-Speedtest-Mod) ## Disclaimer -We are not affiliated or endorced by [Pi-hole](https://github.com/pi-hole/AdminLTE) - -## Use Official CLI Mode for best results. - -[Uninstall Instructions](https://github.com/arevindh/pihole-speedtest/wiki/Uninstalling-Speedtest-Mod) +We are not affiliated or endorsed by [Pi-hole](https://github.com/pi-hole/AdminLTE) From 5d02fb78fee88570edf56516e1da828820124724 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:44:09 -0500 Subject: [PATCH 511/638] Grammar --- README.md | 2 +- advanced/Scripts/webpage.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9169b10609..44628c058e 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ Please go to the [main repository](https://github.com/arevindh/pihole-speedtest) ## Disclaimer -We are not affiliated or endorsed by [Pi-hole](https://github.com/pi-hole/AdminLTE) +We are not affiliated with or endorsed by [Pi-hole](https://github.com/pi-hole/AdminLTE) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e582019060..4fbc22e6d4 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -53,9 +53,9 @@ Options: -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest interval, user 0 to disable Speedtests, use -sn to prevent logging to results list - -in Reinstall Speedtest Mod - -up [un] [db] Update Pi-hole and (uninstall) the Mod (and flush the database) - -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete the database) + -in (Re)install Latest Speedtest Mod and only Mod + -up [un] [db] (Re)install Latest Pi-hole and (uninstall) the Mod (and flush/restore the database) + -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete/restore the database) -db Flush the database -sd Set speedtest display range -sn Run speedtest now From 94533e74a1c33a20f0ebcea61ecf6f7f85ebf17e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 19:35:02 -0500 Subject: [PATCH 512/638] set service with or without arg --- advanced/Scripts/webpage.sh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 4fbc22e6d4..fcf53c636d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -560,11 +560,14 @@ ClearSpeedtestData() { } ChangeSpeedTestSchedule() { - if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" - SetService ${args[2]} + if [[ "${args[2]}" =~ ^[0-9]+$ ]] && [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" + SetService ${args[2]} + else + if [[ -z "${SPEEDTESTSCHEDULE}" ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0" fi + SetService ${SPEEDTESTSCHEDULE} fi } From 350fccee04ac0f5bb753d5cf079896840710d78d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 20:56:48 -0500 Subject: [PATCH 513/638] unset service --- advanced/Scripts/webpage.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index fcf53c636d..75dd9f689b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -645,6 +645,13 @@ EOF' fi } +UnsetService() { + systemctl disable --now pihole-speedtest.timer &> /dev/null + rm -f /etc/systemd/system/pihole-speedtest.service + rm -f /etc/systemd/system/pihole-speedtest.timer + systemctl daemon-reload +} + RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y @@ -1027,6 +1034,7 @@ main() { "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; "-st" ) UpdateSpeedTestChartType;; + "-su" ) UnsetService;; "addcustomdns" ) AddCustomDNSAddress;; "removecustomdns" ) RemoveCustomDNSAddress;; "addcustomcname" ) AddCustomCNAMERecord;; From 23c5ba09475fc5336cc3cfc2f53ecb895be0c4aa Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 21:21:00 -0500 Subject: [PATCH 514/638] change freq --- advanced/Scripts/webpage.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 75dd9f689b..bbda34ae5e 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -627,7 +627,15 @@ ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh [Install] WantedBy=multi-user.target EOF' - freq=$([ "$1" -lt "24" ] && echo "00/$1:00" || [ "$1" -eq "24" ] && echo "daily" || echo "daily,$(($1/24)):$((($1%24)*60))") + if (( $1 < 24 )); then + freq="00/$1:00" + elif (( $1 == 24 )); then + freq="daily" + else + hours=$(( $1 / 24 )) + minutes=$(( ($1 % 24) * 60 )) + freq="daily,$hours:$minutes" + fi sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer From dc9b3eb42f9486ab22b75d1a3e4d723d4d7e88e6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 21:22:42 -0500 Subject: [PATCH 515/638] get updated value --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index bbda34ae5e..5dd2de41f4 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -567,6 +567,8 @@ ChangeSpeedTestSchedule() { if [[ -z "${SPEEDTESTSCHEDULE}" ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0" fi + # get updated value + SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") SetService ${SPEEDTESTSCHEDULE} fi } From 97ac3ae6cfcbaa7cb1fe3612566b3bdaf0960065 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 21:44:17 -0500 Subject: [PATCH 516/638] get value --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 5dd2de41f4..feeb146780 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -564,10 +564,10 @@ ChangeSpeedTestSchedule() { addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" SetService ${args[2]} else + SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") if [[ -z "${SPEEDTESTSCHEDULE}" ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0" fi - # get updated value SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") SetService ${SPEEDTESTSCHEDULE} fi From 23a564fb205896d7977029ba946355afc1863b76 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 21:59:18 -0500 Subject: [PATCH 517/638] generate_systemd_calendar --- advanced/Scripts/webpage.sh | 40 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index feeb146780..fb303ecf7e 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -608,6 +608,33 @@ UpdateSpeedTestChartType() { fi } +generate_systemd_calendar() { + local hours=$1 + local freq_entries=() + + if (( hours < 24 )); then + freq_entries+=("*-*-* */$hours:00:00") + elif (( hours == 24 )); then + freq_entries+=("*-*-* 00:00:00") + elif (( hours > 0 )); then + local total_minutes=$((hours * 60)) + local current_minute=0 + while (( current_minute < 1440 )); do # 1440 minutes in a day + local hour=$((current_minute / 60)) + local minute=$((current_minute % 60)) + freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") + ((current_minute += total_minutes)) + done + else + echo "Error: Invalid number of hours" + exit 1 + fi + + # Join the entries with a newline character + local IFS=$'\n' + echo "${freq_entries[*]}" +} + SetService() { # Remove OLD crontab -l >crontab.tmp || true @@ -629,15 +656,7 @@ ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh [Install] WantedBy=multi-user.target EOF' - if (( $1 < 24 )); then - freq="00/$1:00" - elif (( $1 == 24 )); then - freq="daily" - else - hours=$(( $1 / 24 )) - minutes=$(( ($1 % 24) * 60 )) - freq="daily,$hours:$minutes" - fi + freq=$(generate_systemd_calendar "$1") sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer @@ -647,7 +666,8 @@ WantedBy=timers.target [Timer] Persistent=true -OnCalendar='$freq' +$(for time in $freq; do echo "OnCalendar=$time"; done) + EOF' systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null From 4c2e834c7b3adad4f3757e8284d17283c19c8f02 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:12:34 -0500 Subject: [PATCH 518/638] append after --- advanced/Scripts/webpage.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index fb303ecf7e..99995f3ea3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -666,9 +666,10 @@ WantedBy=timers.target [Timer] Persistent=true -$(for time in $freq; do echo "OnCalendar=$time"; done) - EOF' + for time in $freq; do + sudo bash -c "echo 'OnCalendar=$time' >> /etc/systemd/system/pihole-speedtest.timer" + done systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null systemctl restart pihole-speedtest.timer From 39af2ab1244119be35f44133e329eecd69dda31d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:19:33 -0500 Subject: [PATCH 519/638] fix generate --- advanced/Scripts/webpage.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 99995f3ea3..4b90fde07a 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -613,7 +613,11 @@ generate_systemd_calendar() { local freq_entries=() if (( hours < 24 )); then - freq_entries+=("*-*-* */$hours:00:00") + local current_hour=0 + while (( current_hour < 24 )); do + freq_entries+=("*-*-* $(printf "%02d:00:00" $current_hour)") + ((current_hour += hours)) + done elif (( hours == 24 )); then freq_entries+=("*-*-* 00:00:00") elif (( hours > 0 )); then From c730dcbff0f0427323332cbacf240b7756fa93f1 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:24:15 -0500 Subject: [PATCH 520/638] fix? --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 4b90fde07a..89cd0c1921 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -615,7 +615,7 @@ generate_systemd_calendar() { if (( hours < 24 )); then local current_hour=0 while (( current_hour < 24 )); do - freq_entries+=("*-*-* $(printf "%02d:00:00" $current_hour)") + freq_entries+=("$(printf "*-*-* %02d:00:00" $current_hour)") ((current_hour += hours)) done elif (( hours == 24 )); then @@ -626,7 +626,7 @@ generate_systemd_calendar() { while (( current_minute < 1440 )); do # 1440 minutes in a day local hour=$((current_minute / 60)) local minute=$((current_minute % 60)) - freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") + freq_entries+=("$(printf "*-*-* %02d:%02d:00" $hour $minute)") ((current_minute += total_minutes)) done else From 13ccb8f6278f9618c6893c9db16b8a6958388166 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:29:04 -0500 Subject: [PATCH 521/638] fix --- advanced/Scripts/webpage.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 89cd0c1921..f2b6c1f51c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -671,9 +671,9 @@ WantedBy=timers.target [Timer] Persistent=true EOF' - for time in $freq; do - sudo bash -c "echo 'OnCalendar=$time' >> /etc/systemd/system/pihole-speedtest.timer" - done + while IFS= read -r line; do + sudo bash -c "echo 'OnCalendar=$line' >> /etc/systemd/system/pihole-speedtest.timer" + done <<< "$freq" systemctl daemon-reload systemctl reenable pihole-speedtest.timer &> /dev/null systemctl restart pihole-speedtest.timer From c93d82ed92ca8316fd897b568b977f95983d9295 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:33:09 -0500 Subject: [PATCH 522/638] simplify for mod 0 --- advanced/Scripts/webpage.sh | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f2b6c1f51c..8adb601512 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -610,33 +610,27 @@ UpdateSpeedTestChartType() { generate_systemd_calendar() { local hours=$1 - local freq_entries=() - - if (( hours < 24 )); then - local current_hour=0 - while (( current_hour < 24 )); do - freq_entries+=("$(printf "*-*-* %02d:00:00" $current_hour)") - ((current_hour += hours)) - done + if (( hours < 24 && 24 % hours == 0 )); then + echo "*-*-* */$hours:00:00" elif (( hours == 24 )); then - freq_entries+=("*-*-* 00:00:00") + echo "*-*-* 00:00:00" elif (( hours > 0 )); then local total_minutes=$((hours * 60)) local current_minute=0 + local freq_entries=() while (( current_minute < 1440 )); do # 1440 minutes in a day local hour=$((current_minute / 60)) local minute=$((current_minute % 60)) - freq_entries+=("$(printf "*-*-* %02d:%02d:00" $hour $minute)") + freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") ((current_minute += total_minutes)) done + # Join the entries with a newline character + local IFS=$'\n' + echo "${freq_entries[*]}" else echo "Error: Invalid number of hours" exit 1 fi - - # Join the entries with a newline character - local IFS=$'\n' - echo "${freq_entries[*]}" } SetService() { From 938d9718bcbb39f62b746b40393c6733a10ed293 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:38:17 -0500 Subject: [PATCH 523/638] fix mod 0 --- advanced/Scripts/webpage.sh | 60 ++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 8adb601512..3ebad596e6 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -610,27 +610,51 @@ UpdateSpeedTestChartType() { generate_systemd_calendar() { local hours=$1 - if (( hours < 24 && 24 % hours == 0 )); then - echo "*-*-* */$hours:00:00" - elif (( hours == 24 )); then - echo "*-*-* 00:00:00" - elif (( hours > 0 )); then - local total_minutes=$((hours * 60)) - local current_minute=0 - local freq_entries=() - while (( current_minute < 1440 )); do # 1440 minutes in a day - local hour=$((current_minute / 60)) - local minute=$((current_minute % 60)) - freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") - ((current_minute += total_minutes)) - done - # Join the entries with a newline character - local IFS=$'\n' - echo "${freq_entries[*]}" - else + local freq_entries=() + + if (( hours <= 0 )); then echo "Error: Invalid number of hours" exit 1 + elif (( hours == 24 )); then + freq_entries+=("*-*-* 00:00:00") + elif (( hours < 24 )); then + # For schedules that divide evenly into 24 hours + if (( 24 % hours == 0 )); then + for (( hour=0; hour<24; hour+=hours )); do + freq_entries+=("*-*-* $(printf "%02d:00:00" $hour)") + done + else + # For schedules that don't divide evenly, list specific times + local total_minutes=$((hours * 60)) + local current_minute=0 + while (( current_minute < 1440 )); do # 1440 minutes in a day + local hour=$((current_minute / 60)) + local minute=$((current_minute % 60)) + freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") + ((current_minute += total_minutes)) + done + fi + else + local days=$(( hours / 24 )) + local remaining_hours=$(( hours % 24 )) + if (( remaining_hours == 0 )); then + # If it's multiple of 24 hours + freq_entries+=("*-*-1/$days 00:00:00") + else + # If it's not a multiple of 24 + local day=1 + while (( day <= days )); do + freq_entries+=("*-*-$(printf "%02d" $day) 00:00:00") + ((day++)) + done + # Add the remaining hours as an additional day's time + freq_entries+=("*-*-$(printf "%02d" $day) $(printf "%02d:00:00" $remaining_hours)") + fi fi + + # Join the entries with a newline character + local IFS=$'\n' + echo "${freq_entries[*]}" } SetService() { From 1dbc8646579a68ead7dc0a6a53d512f50f53cc97 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:43:15 -0500 Subject: [PATCH 524/638] fix 1 --- advanced/Scripts/webpage.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3ebad596e6..e7f8cbcd7e 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -616,15 +616,14 @@ generate_systemd_calendar() { echo "Error: Invalid number of hours" exit 1 elif (( hours == 24 )); then + # For exactly 24 hours, it's daily at midnight freq_entries+=("*-*-* 00:00:00") elif (( hours < 24 )); then - # For schedules that divide evenly into 24 hours - if (( 24 % hours == 0 )); then - for (( hour=0; hour<24; hour+=hours )); do - freq_entries+=("*-*-* $(printf "%02d:00:00" $hour)") - done + # For hourly schedules, generate an entry for each hour + if (( hours == 1 )); then + freq_entries+=("*:00:00") else - # For schedules that don't divide evenly, list specific times + # For other schedules less than 24 hours but not hourly, list specific times local total_minutes=$((hours * 60)) local current_minute=0 while (( current_minute < 1440 )); do # 1440 minutes in a day @@ -635,13 +634,14 @@ generate_systemd_calendar() { done fi else + # For schedules more than 24 hours, calculate days and times local days=$(( hours / 24 )) local remaining_hours=$(( hours % 24 )) if (( remaining_hours == 0 )); then # If it's multiple of 24 hours freq_entries+=("*-*-1/$days 00:00:00") else - # If it's not a multiple of 24 + # If it's more than 24 hours but not a multiple of 24 local day=1 while (( day <= days )); do freq_entries+=("*-*-$(printf "%02d" $day) 00:00:00") From 1d70d47bcd3606cc12b5dfc5d4f17b815603e7bb Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 24 Jan 2024 23:01:29 -0500 Subject: [PATCH 525/638] actual fix --- advanced/Scripts/webpage.sh | 38 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e7f8cbcd7e..6cad9e2414 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -613,17 +613,15 @@ generate_systemd_calendar() { local freq_entries=() if (( hours <= 0 )); then - echo "Error: Invalid number of hours" - exit 1 - elif (( hours == 24 )); then - # For exactly 24 hours, it's daily at midnight - freq_entries+=("*-*-* 00:00:00") - elif (( hours < 24 )); then - # For hourly schedules, generate an entry for each hour - if (( hours == 1 )); then - freq_entries+=("*:00:00") + echo "Error: Invalid number of hours" >&2 + return 1 + elif (( hours == 1 )); then + freq_entries+=("*-*-* *:00:00") + elif (( hours <= 24 )); then + if (( 24 % hours == 0 )); then + freq_entries+=("*-*-* 00/$hours:00:00") else - # For other schedules less than 24 hours but not hourly, list specific times + # For schedules less than 24 hours that don't divide evenly, list specific times local total_minutes=$((hours * 60)) local current_minute=0 while (( current_minute < 1440 )); do # 1440 minutes in a day @@ -634,21 +632,15 @@ generate_systemd_calendar() { done fi else - # For schedules more than 24 hours, calculate days and times - local days=$(( hours / 24 )) - local remaining_hours=$(( hours % 24 )) + # For schedules more than 24 hours + local full_days=$((hours / 24)) + local remaining_hours=$((hours % 24)) if (( remaining_hours == 0 )); then - # If it's multiple of 24 hours - freq_entries+=("*-*-1/$days 00:00:00") + freq_entries+=("*-*-1/$full_days 00:00:00") else - # If it's more than 24 hours but not a multiple of 24 - local day=1 - while (( day <= days )); do - freq_entries+=("*-*-$(printf "%02d" $day) 00:00:00") - ((day++)) - done - # Add the remaining hours as an additional day's time - freq_entries+=("*-*-$(printf "%02d" $day) $(printf "%02d:00:00" $remaining_hours)") + # If there are remaining hours, schedule every full_days days and an additional day + freq_entries+=("*-*-1/$full_days 00:00:00") + freq_entries+=("*-*-$(printf "%02d" $((full_days + 1))) $(printf "%02d:00:00" $remaining_hours)") fi fi From 2f1b00b0d6e02aa8b5ba7672d89547c3323fbc51 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 25 Jan 2024 00:42:45 -0500 Subject: [PATCH 526/638] just call unset --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 6cad9e2414..ffe950af3c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -655,7 +655,7 @@ SetService() { sed -i '/speedtest/d' crontab.tmp crontab crontab.tmp && rm -f crontab.tmp if [[ "$1" == "0" ]]; then - systemctl disable --now pihole-speedtest.timer &> /dev/null + UnsetService else sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] From eea61553b872aeda424b16e2e7ac141f8c75f281 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 26 Jan 2024 00:08:48 -0500 Subject: [PATCH 527/638] create db --- advanced/Scripts/webpage.sh | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index ffe950af3c..ed8cf96307 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -545,18 +545,37 @@ SetWebUILayout() { addOrEditKeyValPair "${setupVars}" "WEBUIBOXEDLAYOUT" "${args[2]}" } -hashFile() { - md5sum "$1" | cut -d ' ' -f 1 +isEmpty() { + db=$1 + if [ -f $db ]; then + if ! sqlite3 "$db" "select * from $db_table limit 1;" >/dev/null 2>&1 || [ -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ]; then + return 0 + fi + fi + return 1 } ClearSpeedtestData() { - init_db=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.db - if [[ -f $speedtestdb.old ]] && [[ $(hashFile $init_db) == $(hashFile $speedtestdb) ]]; then + if [[ -f $speedtestdb.old ]] && isEmpty $speedtestdb; then mv -f $speedtestdb.old $speedtestdb - else + elif [[ -f $speedtestdb ]]; then mv -f $speedtestdb $speedtestdb.old - cp $init_db $speedtestdb fi + db_table="speedtest" + create_table="create table if not exists $db_table ( + id integer primary key autoincrement, + start_time integer, + stop_time text, + from_server text, + from_ip text, + server text, + server_dist real, + server_ping real, + download real, + upload real, + share_url text + );" + sqlite3 $speedtestdb "$create_table" } ChangeSpeedTestSchedule() { From ca00533c9f0df3d96832b6e049ad2179f1a147e8 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 26 Jan 2024 02:07:11 -0500 Subject: [PATCH 528/638] handle fractional hours --- advanced/Scripts/webpage.sh | 59 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index ed8cf96307..1e5e8f7b33 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -628,39 +628,42 @@ UpdateSpeedTestChartType() { } generate_systemd_calendar() { - local hours=$1 + local total_seconds=$(bc <<< "scale=2; $1 * 3600") # Convert hours to seconds local freq_entries=() - if (( hours <= 0 )); then - echo "Error: Invalid number of hours" >&2 + # Check if total_seconds is a valid number + if ! [[ $total_seconds =~ ^[0-9]+(\.[0-9]+)?$ ]]; then + echo "Error: Invalid interval" >&2 return 1 - elif (( hours == 1 )); then + fi + + # Check for non-positive intervals + if (( $(bc <<< "$total_seconds <= 0") )); then + echo "Error: Interval must be greater than 0" >&2 + return 1 + fi + + # Convert total_seconds to an integer for comparison and modulo operations + local total_seconds_int=${total_seconds%.*} + + if (( total_seconds_int == 3600 )); then + # Every 1 hour freq_entries+=("*-*-* *:00:00") - elif (( hours <= 24 )); then - if (( 24 % hours == 0 )); then - freq_entries+=("*-*-* 00/$hours:00:00") - else - # For schedules less than 24 hours that don't divide evenly, list specific times - local total_minutes=$((hours * 60)) - local current_minute=0 - while (( current_minute < 1440 )); do # 1440 minutes in a day - local hour=$((current_minute / 60)) - local minute=$((current_minute % 60)) - freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") - ((current_minute += total_minutes)) - done - fi + elif (( 86400 % total_seconds_int == 0 )); then + # For schedules that divide evenly into 24 hours (in seconds) + local hour_interval=$((total_seconds_int / 3600)) + freq_entries+=("*-*-* 00/$hour_interval:00:00") else - # For schedules more than 24 hours - local full_days=$((hours / 24)) - local remaining_hours=$((hours % 24)) - if (( remaining_hours == 0 )); then - freq_entries+=("*-*-1/$full_days 00:00:00") - else - # If there are remaining hours, schedule every full_days days and an additional day - freq_entries+=("*-*-1/$full_days 00:00:00") - freq_entries+=("*-*-$(printf "%02d" $((full_days + 1))) $(printf "%02d:00:00" $remaining_hours)") - fi + # For other schedules, list specific times including seconds + local current_second=0 + while (( current_second < 86400 )); do # 86400 seconds in a day + local hour=$((current_second / 3600)) + local minute=$(((current_second % 3600) / 60)) + local second=$((current_second % 60)) + freq_entries+=("*-*-* $(printf "%02d:%02d:%02d" $hour $minute $second)") + current_second=$(bc <<< "$current_second + $total_seconds") + current_second=${current_second%.*} # Convert to integer for comparison + done fi # Join the entries with a newline character From 94ad962bc175776590fbfc75d413ac9a5610332a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 26 Jan 2024 06:59:33 -0500 Subject: [PATCH 529/638] fix generate again --- advanced/Scripts/webpage.sh | 80 +++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1e5e8f7b33..33f7334ff5 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -579,16 +579,18 @@ ClearSpeedtestData() { } ChangeSpeedTestSchedule() { - if [[ "${args[2]}" =~ ^[0-9]+$ ]] && [ "${args[2]}" -ge 0 -a "${args[2]}" -le 24 ]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" - SetService ${args[2]} + if [[ "${args[2]-}" =~ ^([0-9]+(\.[0-9]+)?|\.[0-9]+)$ ]]; then + if (( $(echo "${args[2]} >= 0" | bc -l) )); then + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" + SetService "${args[2]}" + fi else SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") if [[ -z "${SPEEDTESTSCHEDULE}" ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0" fi SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") - SetService ${SPEEDTESTSCHEDULE} + SetService "${SPEEDTESTSCHEDULE}" fi } @@ -628,45 +630,47 @@ UpdateSpeedTestChartType() { } generate_systemd_calendar() { - local total_seconds=$(bc <<< "scale=2; $1 * 3600") # Convert hours to seconds + local interval_hours="$1" + local total_seconds=$(echo "$interval_hours * 3600" | bc) local freq_entries=() - # Check if total_seconds is a valid number - if ! [[ $total_seconds =~ ^[0-9]+(\.[0-9]+)?$ ]]; then - echo "Error: Invalid interval" >&2 - return 1 + if (( $(echo "$total_seconds < 60" | bc -l) )); then # less than a minute + total_seconds=60 fi - - # Check for non-positive intervals - if (( $(bc <<< "$total_seconds <= 0") )); then - echo "Error: Interval must be greater than 0" >&2 - return 1 - fi - - # Convert total_seconds to an integer for comparison and modulo operations - local total_seconds_int=${total_seconds%.*} - - if (( total_seconds_int == 3600 )); then - # Every 1 hour + if (( $(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l) )); then # less than an hour + local minute_interval=$(echo "$total_seconds / 60" | bc) + freq_entries+=("*-*-* *:00/$minute_interval:00") + elif (( $(echo "$total_seconds == 3600" | bc -l) )); then # exactly an hour freq_entries+=("*-*-* *:00:00") - elif (( 86400 % total_seconds_int == 0 )); then - # For schedules that divide evenly into 24 hours (in seconds) - local hour_interval=$((total_seconds_int / 3600)) - freq_entries+=("*-*-* 00/$hour_interval:00:00") - else - # For other schedules, list specific times including seconds - local current_second=0 - while (( current_second < 86400 )); do # 86400 seconds in a day - local hour=$((current_second / 3600)) - local minute=$(((current_second % 3600) / 60)) - local second=$((current_second % 60)) - freq_entries+=("*-*-* $(printf "%02d:%02d:%02d" $hour $minute $second)") - current_second=$(bc <<< "$current_second + $total_seconds") - current_second=${current_second%.*} # Convert to integer for comparison - done + elif (( $(echo "$total_seconds < 86400" | bc -l) )); then # less than a day + if (( $(echo "3600 % $total_seconds == 0" | bc -l) )); then # divides evenly into an hour + local hour_interval=$(echo "$total_seconds / 3600" | bc) + freq_entries+=("*-*-* 00/$hour_interval:00:00") + else # does not divide evenly into an hour + local current_second=0 + while (( $(echo "$current_second < 86400" | bc -l) )); do + local hour=$(echo "$current_second / 3600" | bc) + local minute=$(echo "($current_second % 3600) / 60" | bc) + hour=${hour%.*} + minute=${minute%.*} + freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") + current_second=$(echo "$current_second + $total_seconds" | bc) + done + fi + else # more than a day + local full_days=$(echo "$interval_hours / 24" | bc) + local remaining_hours=$(echo "$interval_hours - ($full_days * 24)" | bc) + if (( $(echo "$full_days > 0" | bc -l) )); then + freq_entries+=("*-*-1/$(printf "%02.0f" $full_days)") + fi + if (( $(echo "$remaining_hours > 0" | bc -l) )); then + local remaining_minutes=$(echo "($remaining_hours - ($remaining_hours / 1)) * 60" | bc) + local remaining_hours_int=${remaining_hours%.*} + local remaining_minutes_int=${remaining_minutes%.*} + freq_entries+=("*-*-* $(printf "%02d:%02d:00" $remaining_hours_int $remaining_minutes_int)") + fi fi - # Join the entries with a newline character local IFS=$'\n' echo "${freq_entries[*]}" } @@ -679,6 +683,7 @@ SetService() { if [[ "$1" == "0" ]]; then UnsetService else + freq=$(generate_systemd_calendar "$1") sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest @@ -692,7 +697,6 @@ ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh [Install] WantedBy=multi-user.target EOF' - freq=$(generate_systemd_calendar "$1") sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer From 42461aa4a4214e27d0a2103c712977364edc044e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 26 Jan 2024 08:27:22 -0500 Subject: [PATCH 530/638] update help --- advanced/Scripts/webpage.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 33f7334ff5..faf171a696 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -52,17 +52,18 @@ Options: -k, kelvin Set Kelvin as preferred temperature unit -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior - -s, speedtest Set speedtest interval, user 0 to disable Speedtests, use -sn to prevent logging to results list + -s, speedtest Set speedtest interval, add 0 to disable -in (Re)install Latest Speedtest Mod and only Mod -up [un] [db] (Re)install Latest Pi-hole and (uninstall) the Mod (and flush/restore the database) -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete/restore the database) - -db Flush the database + -db Flush or restore the Speedtest Mod database -sd Set speedtest display range -sn Run speedtest now - -sm Speedtest Mode + -sm Speedtest Mode (deprecated) -sc Clear speedtest data -ss Set custom server -st Set default speedtest chart type (line, bar) + -su Stop future scheduled speedtests -l, privacylevel Set privacy level (0 = lowest, 3 = highest) -t, teleporter Backup configuration as an archive -t, teleporter myname.tar.gz Backup configuration to archive with name myname.tar.gz as specified" @@ -665,9 +666,9 @@ generate_systemd_calendar() { fi if (( $(echo "$remaining_hours > 0" | bc -l) )); then local remaining_minutes=$(echo "($remaining_hours - ($remaining_hours / 1)) * 60" | bc) - local remaining_hours_int=${remaining_hours%.*} - local remaining_minutes_int=${remaining_minutes%.*} - freq_entries+=("*-*-* $(printf "%02d:%02d:00" $remaining_hours_int $remaining_minutes_int)") + remaining_hours=${remaining_hours%.*} + remaining_minutes=${remaining_minutes%.*} + freq_entries+=("*-*-* $(printf "%02d:%02d:00" $remaining_hours $remaining_minutes)") fi fi From 509d668e65c2be629200e257cc643342b91a560d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 26 Jan 2024 08:39:33 -0500 Subject: [PATCH 531/638] strip trailing dot --- advanced/Scripts/webpage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index faf171a696..cfaeb82b50 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -580,6 +580,7 @@ ClearSpeedtestData() { } ChangeSpeedTestSchedule() { + args[2]=${args[2]%\.} if [[ "${args[2]-}" =~ ^([0-9]+(\.[0-9]+)?|\.[0-9]+)$ ]]; then if (( $(echo "${args[2]} >= 0" | bc -l) )); then addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" From e298f561db58cb67ce194d3d7e903ba1c680912c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 26 Jan 2024 08:46:53 -0500 Subject: [PATCH 532/638] round up --- advanced/Scripts/webpage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index cfaeb82b50..4c92a673c8 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -638,6 +638,7 @@ generate_systemd_calendar() { if (( $(echo "$total_seconds < 60" | bc -l) )); then # less than a minute total_seconds=60 + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0.017" fi if (( $(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l) )); then # less than an hour local minute_interval=$(echo "$total_seconds / 60" | bc) From d257c0753c724190e0334a32052f7ce58ef4b70d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:53:07 -0500 Subject: [PATCH 533/638] allow any number of days --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 4c92a673c8..f17460c9d8 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -617,7 +617,7 @@ SpeedtestMode() { UpdateSpeedTestRange() { if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - if [ "${args[2]}" -ge 0 -a "${args[2]}" -le 30 ]; then + if [[ "${args[2]}" -ge 0 ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" fi fi From 494467a61f9f60999057997abf2849f2a3a16873 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 30 Jan 2024 01:25:41 -0500 Subject: [PATCH 534/638] allow all days --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f17460c9d8..24a28924e5 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -616,8 +616,8 @@ SpeedtestMode() { } UpdateSpeedTestRange() { - if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - if [[ "${args[2]}" -ge 0 ]]; then + if [[ "${args[2]}" =~ ^-?[0-9]+$ ]]; then + if [[ "${args[2]}" -ge -1 ]]; then addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" fi fi From d0299ab4999c10cfe59258bd3ded088f62962738 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 30 Jan 2024 07:39:09 -0500 Subject: [PATCH 535/638] don't remove files --- advanced/Scripts/webpage.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 24a28924e5..3578b1cbf8 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -721,9 +721,6 @@ EOF' UnsetService() { systemctl disable --now pihole-speedtest.timer &> /dev/null - rm -f /etc/systemd/system/pihole-speedtest.service - rm -f /etc/systemd/system/pihole-speedtest.timer - systemctl daemon-reload } RunSpeedtestNow() { From 080172dd4833eae899e2925c1d6bd1eab45bbc2f Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 30 Jan 2024 12:57:39 -0500 Subject: [PATCH 536/638] bump --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 3578b1cbf8..11f6e53fbc 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -666,7 +666,7 @@ generate_systemd_calendar() { if (( $(echo "$full_days > 0" | bc -l) )); then freq_entries+=("*-*-1/$(printf "%02.0f" $full_days)") fi - if (( $(echo "$remaining_hours > 0" | bc -l) )); then + if (( $(echo "$remaining_hours > 0" | bc -l) )); then # partial day local remaining_minutes=$(echo "($remaining_hours - ($remaining_hours / 1)) * 60" | bc) remaining_hours=${remaining_hours%.*} remaining_minutes=${remaining_minutes%.*} From 2c13f31a6d3b9a0542a3e9cc0090ed9bde03f59e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 31 Jan 2024 04:57:01 -0500 Subject: [PATCH 537/638] use copied script --- advanced/Scripts/webpage.sh | 149 ++++++++++++++---------------------- 1 file changed, 58 insertions(+), 91 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 11f6e53fbc..240a0578bd 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -546,91 +546,6 @@ SetWebUILayout() { addOrEditKeyValPair "${setupVars}" "WEBUIBOXEDLAYOUT" "${args[2]}" } -isEmpty() { - db=$1 - if [ -f $db ]; then - if ! sqlite3 "$db" "select * from $db_table limit 1;" >/dev/null 2>&1 || [ -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ]; then - return 0 - fi - fi - return 1 -} - -ClearSpeedtestData() { - if [[ -f $speedtestdb.old ]] && isEmpty $speedtestdb; then - mv -f $speedtestdb.old $speedtestdb - elif [[ -f $speedtestdb ]]; then - mv -f $speedtestdb $speedtestdb.old - fi - db_table="speedtest" - create_table="create table if not exists $db_table ( - id integer primary key autoincrement, - start_time integer, - stop_time text, - from_server text, - from_ip text, - server text, - server_dist real, - server_ping real, - download real, - upload real, - share_url text - );" - sqlite3 $speedtestdb "$create_table" -} - -ChangeSpeedTestSchedule() { - args[2]=${args[2]%\.} - if [[ "${args[2]-}" =~ ^([0-9]+(\.[0-9]+)?|\.[0-9]+)$ ]]; then - if (( $(echo "${args[2]} >= 0" | bc -l) )); then - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" - SetService "${args[2]}" - fi - else - SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") - if [[ -z "${SPEEDTESTSCHEDULE}" ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0" - fi - SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") - SetService "${SPEEDTESTSCHEDULE}" - fi -} - -SpeedtestServer() { - if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "${args[2]}" - else - # Autoselect for invalid data - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "" - fi -} - -SpeedtestMode() { - if [[ "${args[2]}" ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_MODE" "${args[2]}" - else - # Autoselect for invalid data - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_MODE" "" - fi - -} - -UpdateSpeedTestRange() { - if [[ "${args[2]}" =~ ^-?[0-9]+$ ]]; then - if [[ "${args[2]}" -ge -1 ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" - fi - fi -} - -UpdateSpeedTestChartType() { - if [[ "${args[2]}" =~ ^(bar|line)$ ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "${args[2]}" - else - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "line" - fi -} - generate_systemd_calendar() { local interval_hours="$1" local total_seconds=$(echo "$interval_hours * 3600" | bc) @@ -723,33 +638,86 @@ UnsetService() { systemctl disable --now pihole-speedtest.timer &> /dev/null } +ChangeSpeedTestSchedule() { + args[2]=${args[2]%\.} + if [[ "${args[2]-}" =~ ^([0-9]+(\.[0-9]+)?|\.[0-9]+)$ ]]; then + if (( $(echo "${args[2]} >= 0" | bc -l) )); then + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" + SetService "${args[2]}" + fi + else + SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") + if [[ -z "${SPEEDTESTSCHEDULE}" ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0" + fi + SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") + SetService "${SPEEDTESTSCHEDULE}" + fi +} + +UpdateSpeedTestRange() { + if [[ "${args[2]}" =~ ^-?[0-9]+$ ]]; then + if [[ "${args[2]}" -ge -1 ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" + fi + fi +} + +UpdateSpeedTestChartType() { + if [[ "${args[2]}" =~ ^(bar|line)$ ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "${args[2]}" + else + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "line" + fi +} + +SpeedtestServer() { + if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "${args[2]}" + else + # Autoselect for invalid data + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "" + fi +} + RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "cat /var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh | sudo bash" + testscript="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" + tmux new-session -d -s pimod "cat $testscript | sudo bash" } ReinstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash" + modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" + tmux new-session -d -s pimod "cat $modscript | sudo bash" } UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - tmux new-session -d -s pimod "curl -sSLN https://github.com/arevindh/pihole-speedtest/raw/master/mod.sh | sudo bash -s -- up ${args[2]} ${args[3]}" + modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" + tmux new-session -d -s pimod "cat $modscript | sudo bash -s -- up ${args[2]} ${args[3]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - uninstallfile="/var/www/html/admin/scripts/pi-hole/speedtest/uninstall.sh" - tmux new-session -d -s pimod "cat $uninstallfile | sudo bash -s -- ${args[2]}" + modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" + tmux new-session -d -s pimod "cat $modscript | sudo bash -s -- un ${args[2]}" +} + +ClearSpeedtestData() { + if ! command -v tmux &> /dev/null; then + apt-get install tmux -y + fi + modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" + tmux new-session -d -s pimod "cat $modscript | sudo bash -s -- db" } SetWebUITheme() { @@ -1101,7 +1069,6 @@ main() { "-db" ) ClearSpeedtestData;; "-sd" ) UpdateSpeedTestRange;; "-sn" ) RunSpeedtestNow;; - "-sm" ) SpeedtestMode;; "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; "-st" ) UpdateSpeedTestChartType;; From 81f465ab6b1e9cb0ea23c67ea277d3c402c87b4c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 31 Jan 2024 05:49:24 -0500 Subject: [PATCH 538/638] move scripts --- advanced/Scripts/speedtestmod/mod.sh | 311 +++++++++++++++++++++ advanced/Scripts/speedtestmod/speedtest.sh | 81 ++++++ advanced/Scripts/webpage.sh | 24 +- 3 files changed, 402 insertions(+), 14 deletions(-) create mode 100644 advanced/Scripts/speedtestmod/mod.sh create mode 100755 advanced/Scripts/speedtestmod/speedtest.sh diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh new file mode 100644 index 0000000000..63159cd4f1 --- /dev/null +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -0,0 +1,311 @@ +#!/bin/bash +LOG_FILE="/var/log/pimod.log" + +admin_dir=/var/www/html +curr_wp=/opt/pihole/webpage.sh +last_wp=$curr_wp.old +org_wp=$curr_wp.org + +curr_db=/etc/pihole/speedtest.db +last_db=$curr_db.old +db_table="speedtest" +create_table="create table if not exists $db_table ( +id integer primary key autoincrement, +start_time integer, +stop_time text, +from_server text, +from_ip text, +server text, +server_dist real, +server_ping real, +download real, +upload real, +share_url text +);" + +help() { + echo "(Re)install Latest Speedtest Mod." + echo "Usage: sudo $0 [up] [un] [db]" + echo "up - update Pi-hole (along with the Mod)" + echo "un - remove the mod (including all backups)" + echo "db - flush database (restore for a short while after)" + echo "If no option is specified, the Mod will be (re)installed." +} + +setTags() { + local path=${1-} + local name=${2-} + if [ ! -z "$path" ]; then + cd "$path" + git fetch origin -q + git fetch --tags -f -q + latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) + fi + if [ ! -z "$name" ]; then + localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 6) + [ "$localTag" == "HEAD" ] && localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 7) + fi +} + +download() { + local path=$1 + local name=$2 + local url=$3 + local src=${4-} + local branch=${5-master} + local dest=$path/$name + if [ ! -d $dest ]; then # replicate + cd "$path" + rm -rf "$name" + git clone --depth=1 -b "$branch" "$url" "$name" + setTags "$name" "$src" + if [ ! -z "$src" ]; then + if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then + latestTag=$localTag + git fetch --unshallow + fi + fi + else # replace + setTags $dest + if [ ! -z "$src" ]; then + if [ "$url" != "old" ]; then + git config --global --add safe.directory "$dest" + git remote -v | grep -q "old" || git remote rename origin old + git remote -v | grep -q "origin" && git remote remove origin + git remote add origin $url + else + git remote remove origin + git remote rename old origin + fi + git fetch origin -q + fi + git reset --hard origin/$branch + fi + + git -c advice.detachedHead=false checkout $latestTag + cd .. +} + +isEmpty() { + db=$1 + if [ -f $db ]; then + if ! sqlite3 "$db" "select * from $db_table limit 1;" >/dev/null 2>&1 || [ -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ]; then + return 0 + fi + fi + return 1 +} + +manageHistory() { + if [ "${1-}" == "db" ]; then + if [ -f $curr_db ] && ! isEmpty $curr_db; then + if [ -z "${2-}" ]; then + echo "Flushing Database..." + mv -f $curr_db $last_db + fi + elif [ -f $last_db ]; then + echo "Restoring Database..." + mv -f $last_db $curr_db + fi + echo "Configuring Database..." + sqlite3 "$curr_db" "$create_table" + fi +} + +notInstalled() { + apt-cache policy "$1" | grep 'Installed: (none)' >/dev/null +} + +install() { + echo "Installing Mod..." + + if [ ! -f /usr/local/bin/pihole ]; then + echo "Installing Pi-hole..." + curl -sSL https://install.pi-hole.net | sudo bash + fi + + if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then + echo "Adding speedtest source..." + if [ -e /etc/os-release ]; then + . /etc/os-release + local base="ubuntu debian" + local os=${ID} + local dist=${VERSION_CODENAME} + if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then + os=${ID_LIKE%% *} + [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + dist=${UBUNTU_CODENAME} + [ -z "$dist" ] && dist=${VERSION_CODENAME} + fi + wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 + chmod +x /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh + rm -f /tmp/script.deb.sh + else + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash + fi + fi + + local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) + local packages="bc sqlite3 php${PHP_VERSION}-sqlite3 jq" + + local missing_packages="" + for package in $packages; do + if notInstalled "$package"; then + missing_packages="$missing_packages $package" + fi + done + if notInstalled speedtest && notInstalled speedtest-cli; then + missing_packages="$missing_packages speedtest" + fi + missing_packages=$(echo "$missing_packages" | xargs) + if [ ! -z "${missing_packages}" ]; then + apt-get install -y $missing_packages + fi + if [ -f /usr/local/bin/speedtest ]; then + rm -f /usr/local/bin/speedtest + ln -s /usr/bin/speedtest /usr/local/bin/speedtest + fi + + download /opt mod_pihole https://github.com/arevindh/pi-hole + download /var/www/html admin https://github.com/arevindh/AdminLTE web + if [ -f $curr_wp ]; then + if ! cat $curr_wp | grep -q SpeedTest; then + cp -a $curr_wp $org_wp + fi + if [ ! -f $last_wp ]; then + cp -a $curr_wp $last_wp + fi + fi + cp -a /opt/mod_pihole/advanced/Scripts/webpage.sh $curr_wp + cp -a /opt/mod_pihole/advanced/Scripts/speedtestmod /opt/pihole/speedtestmod + chmod +x $curr_wp + manageHistory db . + pihole -a -s + pihole updatechecker local +} + +uninstall() { + if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then + echo "Restoring Pi-hole..." + + if [ ! -f $org_wp ]; then + if [ ! -d /opt/org_pihole ]; then + download /opt org_pihole https://github.com/pi-hole/pi-hole Pi-hole + fi + cd /opt + cp -a org_pihole/advanced/Scripts/webpage.sh $org_wp + rm -rf org_pihole + fi + + pihole -a -su + download /var/www/html admin https://github.com/pi-hole/AdminLTE web + if [ ! -f $last_wp ]; then + cp -a $curr_wp $last_wp + fi + cp -a $org_wp $curr_wp + chmod +x $curr_wp + fi + + manageHistory ${1-} +} + +purge() { + rm -rf "$admin_dir"*_admin + rm -rf /opt/mod_pihole + if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then + rm -f /etc/systemd/system/pihole-speedtest.service + rm -f /etc/systemd/system/pihole-speedtest.timer + systemctl daemon-reload + fi + + rm -f "$curr_wp".* + rm -f "$curr_db".* + rm -f "$curr_db"_* + if isEmpty $curr_db; then + rm -f $curr_db + fi +} + +update() { + echo "Updating Pi-hole..." + PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up + if [ "${1-}" == "un" ]; then + purge + exit 0 + fi +} + +abort() { + echo "Process Aborting..." + + if [ -f $last_wp ]; then + cp -a $last_wp $curr_wp + chmod +x $curr_wp + rm -f $last_wp + fi + if [ -f $last_db ] && [ ! -f $curr_db ]; then + mv $last_db $curr_db + fi + if [ ! -f $curr_wp ] || ! cat $curr_wp | grep -q SpeedTest; then + purge + fi + if [ -d $admin_dir/admin/.git/refs/remotes/old ]; then + download $admin_dir admin old web + fi + + if (($aborted == 0)); then + pihole restartdns + printf "Please try again or try manually.\n\n$(date)\n" + fi + aborted=1 + exit 1 +} + +commit() { + cd $admin_dir/admin + git remote -v | grep -q "old" && git remote remove old + rm -f $last_wp + pihole restartdns + printf "Done!\n\n$(date)\n" + exit 0 +} + +main() { + printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" + local op=${1-} + if [ "$op" == "-h" ] || [ "$op" == "--help" ]; then + help + exit 0 + fi + if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? + fi + aborted=0 + set -Eeuo pipefail + trap '[ "$?" -eq "0" ] && commit || abort' EXIT + trap 'abort' INT TERM + + local db=$([ "$op" == "up" ] && echo "${3-}" || [ "$op" == "un" ] && echo "${2-}" || echo "$op") + case $op in + db) + manageHistory $db + ;; + un) + uninstall $db + purge + ;; + up) + uninstall $db + update ${2-} + install + ;; + *) + install + ;; + esac + exit 0 +} + +main "$@" 2>&1 | sudo tee -- "$LOG_FILE" diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh new file mode 100755 index 0000000000..fddea98b64 --- /dev/null +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -0,0 +1,81 @@ +#!/bin/bash +FILE=/tmp/speedtest.log +readonly setupVars="/etc/pihole/setupVars.conf" +serverid=$(grep 'SPEEDTEST_SERVER' ${setupVars} | cut -d '=' -f2) +start=$(date +"%Y-%m-%d %H:%M:%S %Z") + +speedtest() { + if grep -q official <<< "$(/usr/bin/speedtest --version)"; then + if [[ -z "${serverid}" ]]; then + /usr/bin/speedtest --accept-gdpr --accept-license -f json-pretty + else + /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json-pretty + fi + else + if [[ -z "${serverid}" ]]; then + /usr/bin/speedtest --json --share --secure + else + /usr/bin/speedtest -s $serverid --json --share --secure + fi + fi +} + +internet() { + stop=$(date +"%Y-%m-%d %H:%M:%S %Z") + res="$(<$FILE)" + server_name=$(jq -r '.server.name' <<< "$res") + server_dist=0 + + if grep -q official <<< "$(/usr/bin/speedtest --version)"; then + download=$(jq -r '.download.bandwidth' <<< "$res" | awk '{$1=$1*8/1000/1000; print $1;}' | sed 's/,/./g') + upload=$(jq -r '.upload.bandwidth' <<< "$res" | awk '{$1=$1*8/1000/1000; print $1;}' | sed 's/,/./g') + isp=$(jq -r '.isp' <<< "$res") + server_ip=$(jq -r '.server.ip' <<< "$res") + from_ip=$(jq -r '.interface.externalIp' <<< "$res") + server_ping=$(jq -r '.ping.latency' <<< "$res") + share_url=$(jq -r '.result.url' <<< "$res") + else + download=$(jq -r '.download' <<< "$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') + upload=$(jq -r '.upload' <<< "$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') + isp=$(jq -r '.client.isp' <<< "$res") + server_ip=$(jq -r '.server.host' <<< "$res") + from_ip=$(jq -r '.client.ip' <<< "$res") + server_ping=$(jq -r '.ping' <<< "$res") + share_url=$(jq -r '.share' <<< "$res") + fi + + sep="\t" + quote="" + opts= + sep="$quote$sep$quote" + printf "$quote$start$sep$stop$sep$isp$sep$from_ip$sep$server_name$sep$server_dist$sep$server_ping$sep$download$sep$upload$sep$share_url$quote\n" + sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', '${isp}', '${from_ip}', '${server_name}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" + exit 0 +} + +nointernet(){ + stop=$(date +"%Y-%m-%d %H:%M:%S %Z") + echo "No Internet" + sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', 'No Internet', '-', '-', 0, 0, 0, 0, '#');" + exit 1 +} + +tryagain(){ + if apt-cache policy speedtest-cli | grep -q 'Installed: (none)'; then + apt-get install -y speedtest-cli speedtest- + else + apt-get install -y speedtest speedtest-cli- + fi + speedtest > "$FILE" && internet || nointernet +} + +main() { + if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? + fi + echo "Test has been initiated, please wait." + speedtest > "$FILE" && internet || tryagain +} + +main diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 240a0578bd..35eff76b39 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -19,11 +19,12 @@ readonly FTLconf="/etc/pihole/pihole-FTL.conf" readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf" readonly dnscustomfile="/etc/pihole/custom.list" readonly dnscustomcnamefile="/etc/dnsmasq.d/05-pihole-custom-cname.conf" -readonly speedtestfile="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" -readonly speedtestdb="/etc/pihole/speedtest.db" - readonly gravityDBfile="/etc/pihole/gravity.db" +# speedtest mod +readonly speedtestmod="/opt/pihole/speedtestmod/mod.sh" +readonly speedtestfile="/opt/pihole/speedtestmod/speedtest.sh" +readonly speedtestdb="/etc/pihole/speedtest.db" readonly setupVars="/etc/pihole/setupVars.conf" readonly PI_HOLE_BIN_DIR="/usr/local/bin" @@ -610,7 +611,7 @@ After=network.target [Service] User=root Type=oneshot -ExecStart=/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh +ExecStart=/opt/pihole/speedtestmod/speedtest.sh [Install] WantedBy=multi-user.target @@ -684,40 +685,35 @@ RunSpeedtestNow() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - testscript="/var/www/html/admin/scripts/pi-hole/speedtest/speedtest.sh" - tmux new-session -d -s pimod "cat $testscript | sudo bash" + tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" } ReinstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" - tmux new-session -d -s pimod "cat $modscript | sudo bash" + tmux new-session -d -s pimod "cat $speedtestmod | sudo bash" } UpdateSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" - tmux new-session -d -s pimod "cat $modscript | sudo bash -s -- up ${args[2]} ${args[3]}" + tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- up ${args[2]} ${args[3]}" } UninstallSpeedTest() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" - tmux new-session -d -s pimod "cat $modscript | sudo bash -s -- un ${args[2]}" + tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- un ${args[2]}" } ClearSpeedtestData() { if ! command -v tmux &> /dev/null; then apt-get install tmux -y fi - modscript="/var/www/html/admin/scripts/pi-hole/speedtest/mod.sh" - tmux new-session -d -s pimod "cat $modscript | sudo bash -s -- db" + tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- db" } SetWebUITheme() { From 1271656494b3ce8ab2cfeb434da2ec44a44ca71b Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 31 Jan 2024 06:11:31 -0500 Subject: [PATCH 539/638] make executable --- advanced/Scripts/speedtestmod/mod.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 advanced/Scripts/speedtestmod/mod.sh diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh old mode 100644 new mode 100755 From ee559c7a2a555283ca39dd49b9a5420c9df183ef Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 31 Jan 2024 11:27:27 -0500 Subject: [PATCH 540/638] delete mod_pihole on upgrade --- advanced/Scripts/speedtestmod/mod.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 63159cd4f1..b59b9cbf3b 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -205,6 +205,7 @@ uninstall() { fi cp -a $org_wp $curr_wp chmod +x $curr_wp + rm -rf /opt/mod_pihole fi manageHistory ${1-} @@ -212,7 +213,6 @@ uninstall() { purge() { rm -rf "$admin_dir"*_admin - rm -rf /opt/mod_pihole if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then rm -f /etc/systemd/system/pihole-speedtest.service rm -f /etc/systemd/system/pihole-speedtest.timer From eacbe3369857cd1a8ae30a3e36fadd27246007cb Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:25:25 -0500 Subject: [PATCH 541/638] we're already at the latest tag --- advanced/Scripts/speedtestmod/mod.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index b59b9cbf3b..76fdb47ef8 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -82,7 +82,9 @@ download() { git reset --hard origin/$branch fi - git -c advice.detachedHead=false checkout $latestTag + if [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag)" ]; then + git -c advice.detachedHead=false checkout $latestTag + fi cd .. } From c2e5fa0a638f0730743b042564c5b94f68f04868 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:11:42 -0500 Subject: [PATCH 542/638] fix up --- advanced/Scripts/speedtestmod/mod.sh | 29 +++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 76fdb47ef8..5bdaa78e68 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -35,9 +35,15 @@ help() { setTags() { local path=${1-} local name=${2-} + local branch="${3-master}" + local url=${4-} if [ ! -z "$path" ]; then cd "$path" - git fetch origin -q + if [ ! -z "$url" ]; then + git remote -v | grep -q "origin" && git remote remove origin + git remote add origin $url + fi + git fetch origin $branch:refs/remotes/origin/$branch -q git fetch --tags -f -q latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) fi @@ -52,13 +58,13 @@ download() { local name=$2 local url=$3 local src=${4-} - local branch=${5-master} + local branch="${5-master}" local dest=$path/$name if [ ! -d $dest ]; then # replicate cd "$path" rm -rf "$name" git clone --depth=1 -b "$branch" "$url" "$name" - setTags "$name" "$src" + setTags "$name" "$src" $branch if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then latestTag=$localTag @@ -66,20 +72,24 @@ download() { fi fi else # replace - setTags $dest + cd "$dest" + git config --global --add safe.directory "$dest" + git remote -v | grep -q "old" || git remote rename origin old + setTags $dest "" $branch $url if [ ! -z "$src" ]; then if [ "$url" != "old" ]; then - git config --global --add safe.directory "$dest" - git remote -v | grep -q "old" || git remote rename origin old git remote -v | grep -q "origin" && git remote remove origin git remote add origin $url - else + elif [ -d .git/refs/remotes/old ]; then git remote remove origin git remote rename old origin fi git fetch origin -q fi git reset --hard origin/$branch + git checkout -B $branch -q + git branch -u origin/$branch -q + git clean -ffdx fi if [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag)" ]; then @@ -170,7 +180,7 @@ install() { fi download /opt mod_pihole https://github.com/arevindh/pi-hole - download /var/www/html admin https://github.com/arevindh/AdminLTE web + download $admin_dir admin https://github.com/arevindh/AdminLTE web if [ -f $curr_wp ]; then if ! cat $curr_wp | grep -q SpeedTest; then cp -a $curr_wp $org_wp @@ -201,13 +211,14 @@ uninstall() { fi pihole -a -su - download /var/www/html admin https://github.com/pi-hole/AdminLTE web + download $admin_dir admin https://github.com/pi-hole/AdminLTE web if [ ! -f $last_wp ]; then cp -a $curr_wp $last_wp fi cp -a $org_wp $curr_wp chmod +x $curr_wp rm -rf /opt/mod_pihole + rm -rf /opt/pihole/speedtestmod fi manageHistory ${1-} From 3770257f32261e7027c72563bc2e2406010c428f Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 1 Feb 2024 02:17:50 -0500 Subject: [PATCH 543/638] remove old fix --- advanced/Scripts/speedtestmod/mod.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 5bdaa78e68..4dcf7a3e0c 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -36,13 +36,8 @@ setTags() { local path=${1-} local name=${2-} local branch="${3-master}" - local url=${4-} if [ ! -z "$path" ]; then cd "$path" - if [ ! -z "$url" ]; then - git remote -v | grep -q "origin" && git remote remove origin - git remote add origin $url - fi git fetch origin $branch:refs/remotes/origin/$branch -q git fetch --tags -f -q latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) @@ -72,12 +67,11 @@ download() { fi fi else # replace - cd "$dest" - git config --global --add safe.directory "$dest" - git remote -v | grep -q "old" || git remote rename origin old - setTags $dest "" $branch $url + setTags $dest "" $branch if [ ! -z "$src" ]; then if [ "$url" != "old" ]; then + git config --global --add safe.directory "$dest" + git remote -v | grep -q "old" || git remote rename origin old git remote -v | grep -q "origin" && git remote remove origin git remote add origin $url elif [ -d .git/refs/remotes/old ]; then @@ -218,7 +212,6 @@ uninstall() { cp -a $org_wp $curr_wp chmod +x $curr_wp rm -rf /opt/mod_pihole - rm -rf /opt/pihole/speedtestmod fi manageHistory ${1-} @@ -226,6 +219,7 @@ uninstall() { purge() { rm -rf "$admin_dir"*_admin + rm -rf /opt/pihole/speedtestmod if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then rm -f /etc/systemd/system/pihole-speedtest.service rm -f /etc/systemd/system/pihole-speedtest.timer From cb4622895e9a72412004d8949af898e6ff40e3c5 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 1 Feb 2024 03:01:50 -0500 Subject: [PATCH 544/638] run updatechecker --- advanced/Scripts/speedtestmod/mod.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 4dcf7a3e0c..c5fcf61353 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -58,7 +58,7 @@ download() { if [ ! -d $dest ]; then # replicate cd "$path" rm -rf "$name" - git clone --depth=1 -b "$branch" "$url" "$name" + git clone --depth=1 -b "$branch" "$url" "$name" -q setTags "$name" "$src" $branch if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then @@ -81,8 +81,8 @@ download() { git fetch origin -q fi git reset --hard origin/$branch - git checkout -B $branch -q - git branch -u origin/$branch -q + git checkout -B $branch + git branch -u origin/$branch git clean -ffdx fi @@ -232,6 +232,8 @@ purge() { if isEmpty $curr_db; then rm -f $curr_db fi + + pi-hole updatechecker } update() { From d51e59035491e21bbe0c773d0903d24e7d08f176 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 1 Feb 2024 03:07:11 -0500 Subject: [PATCH 545/638] better dep handling --- advanced/Scripts/speedtestmod/mod.sh | 2 +- advanced/Scripts/webpage.sh | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index c5fcf61353..4e3b581d10 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -153,7 +153,7 @@ install() { fi local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local packages="bc sqlite3 php${PHP_VERSION}-sqlite3 jq" + local packages="bc sqlite3 php${PHP_VERSION}-sqlite3 jq tmux" local missing_packages="" for package in $packages; do diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 35eff76b39..6ec567ea17 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -682,37 +682,22 @@ SpeedtestServer() { } RunSpeedtestNow() { - if ! command -v tmux &> /dev/null; then - apt-get install tmux -y - fi tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" } ReinstallSpeedTest() { - if ! command -v tmux &> /dev/null; then - apt-get install tmux -y - fi tmux new-session -d -s pimod "cat $speedtestmod | sudo bash" } UpdateSpeedTest() { - if ! command -v tmux &> /dev/null; then - apt-get install tmux -y - fi tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- up ${args[2]} ${args[3]}" } UninstallSpeedTest() { - if ! command -v tmux &> /dev/null; then - apt-get install tmux -y - fi tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- un ${args[2]}" } ClearSpeedtestData() { - if ! command -v tmux &> /dev/null; then - apt-get install tmux -y - fi tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- db" } From aaa9e7a5000ee03520c5394ea79b9a758eaa7852 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:54:56 -0500 Subject: [PATCH 546/638] always update v --- advanced/Scripts/speedtestmod/mod.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 4e3b581d10..9b137f6a6f 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -212,6 +212,7 @@ uninstall() { cp -a $org_wp $curr_wp chmod +x $curr_wp rm -rf /opt/mod_pihole + pihole updatechecker fi manageHistory ${1-} From f8bfd59f11332b664c954ebfb2ed1586fbd3d070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 7 Nov 2023 22:24:34 +0100 Subject: [PATCH 547/638] Drop Fedora 36 and add Fedora 39 to the test suite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 2 +- test/{_fedora_36.Dockerfile => _fedora_39.Dockerfile} | 2 +- test/{tox.fedora_36.ini => tox.fedora_39.ini} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename test/{_fedora_36.Dockerfile => _fedora_39.Dockerfile} (97%) rename test/{tox.fedora_36.ini => tox.fedora_39.ini} (81%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35ed0c3063..6737725599 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,9 +57,9 @@ jobs: ubuntu_23, centos_8, centos_9, - fedora_36, fedora_37, fedora_38, + fedora_39, ] env: DISTRO: ${{matrix.distro}} diff --git a/test/_fedora_36.Dockerfile b/test/_fedora_39.Dockerfile similarity index 97% rename from test/_fedora_36.Dockerfile rename to test/_fedora_39.Dockerfile index 847767e790..1727a3aa22 100644 --- a/test/_fedora_36.Dockerfile +++ b/test/_fedora_39.Dockerfile @@ -1,4 +1,4 @@ -FROM fedora:36 +FROM fedora:39 RUN dnf install -y git initscripts ENV GITDIR /etc/.pihole diff --git a/test/tox.fedora_36.ini b/test/tox.fedora_39.ini similarity index 81% rename from test/tox.fedora_36.ini rename to test/tox.fedora_39.ini index 515487edd1..7a53837175 100644 --- a/test/tox.fedora_36.ini +++ b/test/tox.fedora_39.ini @@ -1,8 +1,8 @@ [tox] envlist = py3 -[testenv:py3] +[testenv] allowlist_externals = docker deps = -rrequirements.txt -commands = docker buildx build --load --progress plain -f _fedora_36.Dockerfile -t pytest_pihole:test_container ../ +commands = docker buildx build --load --progress plain -f _fedora_39.Dockerfile -t pytest_pihole:test_container ../ pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From 7b6f0d1596f879b65552c5deddc0dc620b290d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 28 Jan 2024 16:56:57 +0100 Subject: [PATCH 548/638] Also remove Fedora 37 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- .github/workflows/test.yml | 3 +-- test/_fedora_37.Dockerfile | 18 ------------------ test/tox.fedora_37.ini | 8 -------- 3 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 test/_fedora_37.Dockerfile delete mode 100644 test/tox.fedora_37.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6737725599..fabf380eb1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,8 +57,7 @@ jobs: ubuntu_23, centos_8, centos_9, - fedora_37, - fedora_38, + fedora_38, fedora_39, ] env: diff --git a/test/_fedora_37.Dockerfile b/test/_fedora_37.Dockerfile deleted file mode 100644 index b4f939ba39..0000000000 --- a/test/_fedora_37.Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM fedora:37 -RUN dnf install -y git initscripts - -ENV GITDIR /etc/.pihole -ENV SCRIPTDIR /opt/pihole - -RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole -ADD . $GITDIR -RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ -ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR - -RUN true && \ - chmod +x $SCRIPTDIR/* - -ENV SKIP_INSTALL true -ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net - -#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.fedora_37.ini b/test/tox.fedora_37.ini deleted file mode 100644 index 2a8ef39863..0000000000 --- a/test/tox.fedora_37.ini +++ /dev/null @@ -1,8 +0,0 @@ -[tox] -envlist = py3 - -[testenv] -allowlist_externals = docker -deps = -rrequirements.txt -commands = docker buildx build --load --progress plain -f _fedora_37.Dockerfile -t pytest_pihole:test_container ../ - pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_fedora_support.py From f0878c0890926e8f7443c7349581b1b10c8d3e3d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 4 Feb 2024 21:39:17 +0000 Subject: [PATCH 549/638] Bump pytest from 7.4.4 to 8.0.0 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.4 to 8.0.0. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/7.4.4...8.0.0) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index dea4ace91f..2b8dfb1b49 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ pyyaml == 6.0.1 -pytest == 7.4.4 +pytest == 8.0.0 pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 tox == 4.12.1 From b428066cf59085a596cadcab62a7a4799103dd09 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:40:07 -0500 Subject: [PATCH 550/638] support sans systemd --- advanced/Scripts/speedtestmod/mod.sh | 62 ++++------- advanced/Scripts/speedtestmod/speedtest.sh | 18 +++- advanced/Scripts/webpage.sh | 117 ++++++++++++++++----- 3 files changed, 132 insertions(+), 65 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 9b137f6a6f..b293e477fe 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -9,19 +9,6 @@ org_wp=$curr_wp.org curr_db=/etc/pihole/speedtest.db last_db=$curr_db.old db_table="speedtest" -create_table="create table if not exists $db_table ( -id integer primary key autoincrement, -start_time integer, -stop_time text, -from_server text, -from_ip text, -server text, -server_dist real, -server_ping real, -download real, -upload real, -share_url text -);" help() { echo "(Re)install Latest Speedtest Mod." @@ -58,7 +45,7 @@ download() { if [ ! -d $dest ]; then # replicate cd "$path" rm -rf "$name" - git clone --depth=1 -b "$branch" "$url" "$name" -q + git clone --depth=1 -b "$branch" "$url" "$name" setTags "$name" "$src" $branch if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then @@ -81,7 +68,7 @@ download() { git fetch origin -q fi git reset --hard origin/$branch - git checkout -B $branch + git checkout -B $branch -q git branch -u origin/$branch git clean -ffdx fi @@ -105,16 +92,18 @@ isEmpty() { manageHistory() { if [ "${1-}" == "db" ]; then if [ -f $curr_db ] && ! isEmpty $curr_db; then - if [ -z "${2-}" ]; then - echo "Flushing Database..." - mv -f $curr_db $last_db + echo "Flushing Database..." + mv -f $curr_db $last_db + if [ -f /etc/pihole/last_speedtest ]; then + mv -f /etc/pihole/last_speedtest /etc/pihole/last_speedtest.old fi elif [ -f $last_db ]; then echo "Restoring Database..." mv -f $last_db $curr_db + if [ -f /etc/pihole/last_speedtest.old ]; then + mv -f /etc/pihole/last_speedtest.old /etc/pihole/last_speedtest + fi fi - echo "Configuring Database..." - sqlite3 "$curr_db" "$create_table" fi } @@ -130,6 +119,10 @@ install() { curl -sSL https://install.pi-hole.net | sudo bash fi + local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) + apt-get update + apt-get install -y bc sqlite3 php$PHP_VERSION-sqlite3 jq tmux curl wget + if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then echo "Adding speedtest source..." if [ -e /etc/os-release ]; then @@ -151,22 +144,8 @@ install() { curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash fi fi - - local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local packages="bc sqlite3 php${PHP_VERSION}-sqlite3 jq tmux" - - local missing_packages="" - for package in $packages; do - if notInstalled "$package"; then - missing_packages="$missing_packages $package" - fi - done if notInstalled speedtest && notInstalled speedtest-cli; then - missing_packages="$missing_packages speedtest" - fi - missing_packages=$(echo "$missing_packages" | xargs) - if [ ! -z "${missing_packages}" ]; then - apt-get install -y $missing_packages + apt-get install -y speedtest fi if [ -f /usr/local/bin/speedtest ]; then rm -f /usr/local/bin/speedtest @@ -186,7 +165,6 @@ install() { cp -a /opt/mod_pihole/advanced/Scripts/webpage.sh $curr_wp cp -a /opt/mod_pihole/advanced/Scripts/speedtestmod /opt/pihole/speedtestmod chmod +x $curr_wp - manageHistory db . pihole -a -s pihole updatechecker local } @@ -230,16 +208,21 @@ purge() { rm -f "$curr_wp".* rm -f "$curr_db".* rm -f "$curr_db"_* + rm -f /etc/pihole/last_speedtest.* if isEmpty $curr_db; then rm -f $curr_db fi - pi-hole updatechecker + pihole updatechecker } update() { - echo "Updating Pi-hole..." - PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up + if [[ -d /run/systemd/system ]]; then + echo "Updating Pi-hole..." + PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up + else + echo "Systemd not found. Skipping Pi-hole update..." + fi if [ "${1-}" == "un" ]; then purge exit 0 @@ -313,6 +296,7 @@ main() { ;; *) install + manageHistory $db ;; esac exit 0 diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index fddea98b64..4d0d648f9d 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -1,8 +1,22 @@ #!/bin/bash FILE=/tmp/speedtest.log -readonly setupVars="/etc/pihole/setupVars.conf" -serverid=$(grep 'SPEEDTEST_SERVER' ${setupVars} | cut -d '=' -f2) start=$(date +"%Y-%m-%d %H:%M:%S %Z") +serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) + +create_table="create table if not exists speedtest ( +id integer primary key autoincrement, +start_time text, +stop_time text, +from_server text, +from_ip text, +server text, +server_dist real, +server_ping real, +download real, +upload real, +share_url text +);" +sqlite3 /etc/pihole/speedtest.db "$create_table" speedtest() { if grep -q official <<< "$(/usr/bin/speedtest --version)"; then diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 6ec567ea17..a55e8856fe 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -594,16 +594,85 @@ generate_systemd_calendar() { echo "${freq_entries[*]}" } +generate_cron_schedule() { + local interval_hours="$1" + local total_seconds=$(echo "$interval_hours * 3600" | bc) + local schedule_script="/opt/pihole/speedtestmod/schedule_check.sh" + + if (( $(echo "$total_seconds < 60" | bc -l) )) && (( $(echo "$total_seconds > 0" | bc -l) )); then + total_seconds=60 + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0.017" + fi + + if [[ ! "$total_seconds" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then + total_seconds="nan" + fi + + sudo bash -c "cat > $(printf %q "$schedule_script")" << EOF +#!/bin/bash +# Schedule script to handle complex cron schedules +last_run_file="/etc/pihole/last_speedtest" +interval_seconds=$total_seconds + +schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") + +# if schedule is set and is greater than 0, and interval is "nan", set the speedtest interval to the schedule +if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (( \$(echo "\$schedule > 0" | bc -l) )) && [[ "\$interval_seconds" == "nan" ]]; then + /usr/local/bin/pihole -a -s "\$schedule" + exit 0 +fi + +if (( \$(echo "\$interval_seconds <= 0" | bc -l) )); then + exit 0 +fi + +if [[ -f "\$last_run_file" ]]; then + last_run=\$(cat "\$last_run_file") + current_time=\$(date +%s) + if (( \$(echo "\$current_time - \$last_run < \$interval_seconds" | bc -l) )); then + exit 0 + fi +fi + +echo \$(date +%s) > "\$last_run_file" +if [[ \$(tmux list-sessions 2>/dev/null | grep -c pimod) -eq 0 ]]; then + /usr/bin/tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" +fi +EOF + sudo chmod +x "$schedule_script" + + crontab -l 2>/dev/null | grep -v "$schedule_script" | crontab - + if [[ "$total_seconds" == "nan" ]] || (( $(echo "$total_seconds > 0" | bc -l) )); then + crontab -l &> /dev/null || crontab -l 2>/dev/null | { cat; echo ""; } | crontab - + (crontab -l; echo "* * * * * /bin/bash $schedule_script") | crontab - + fi +} + +get_scheduler() { + if [[ -d /run/systemd/system ]]; then + echo "systemd" + else + echo "cron" + fi +} + +UnsetService() { + if [[ "$(get_scheduler)" == "cron" ]]; then + generate_cron_schedule "-1" + else + systemctl disable --now pihole-speedtest.timer &> /dev/null + fi +} + SetService() { - # Remove OLD - crontab -l >crontab.tmp || true - sed -i '/speedtest/d' crontab.tmp - crontab crontab.tmp && rm -f crontab.tmp if [[ "$1" == "0" ]]; then UnsetService else - freq=$(generate_systemd_calendar "$1") - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF + if [[ "$(get_scheduler)" == "cron" ]]; then + generate_cron_schedule "$1" + else + local freq=$(generate_systemd_calendar "$1") + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest After=network.target @@ -616,7 +685,7 @@ ExecStart=/opt/pihole/speedtestmod/speedtest.sh [Install] WantedBy=multi-user.target EOF' - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer @@ -626,33 +695,31 @@ WantedBy=timers.target [Timer] Persistent=true EOF' - while IFS= read -r line; do - sudo bash -c "echo 'OnCalendar=$line' >> /etc/systemd/system/pihole-speedtest.timer" - done <<< "$freq" - systemctl daemon-reload - systemctl reenable pihole-speedtest.timer &> /dev/null - systemctl restart pihole-speedtest.timer - fi -} + while IFS= read -r line; do + sudo bash -c "echo 'OnCalendar=$line' >> /etc/systemd/system/pihole-speedtest.timer" + done <<< "$freq" -UnsetService() { - systemctl disable --now pihole-speedtest.timer &> /dev/null + systemctl daemon-reload + systemctl reenable pihole-speedtest.timer &> /dev/null + systemctl restart pihole-speedtest.timer + fi + fi } ChangeSpeedTestSchedule() { args[2]=${args[2]%\.} - if [[ "${args[2]-}" =~ ^([0-9]+(\.[0-9]+)?|\.[0-9]+)$ ]]; then + if [[ "${args[2]-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then if (( $(echo "${args[2]} >= 0" | bc -l) )); then addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" SetService "${args[2]}" fi else - SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") - if [[ -z "${SPEEDTESTSCHEDULE}" ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0" + local interval=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") + if [[ ! "${interval-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then + UnsetService + else + SetService "$interval" fi - SPEEDTESTSCHEDULE=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") - SetService "${SPEEDTESTSCHEDULE}" fi } @@ -682,7 +749,9 @@ SpeedtestServer() { } RunSpeedtestNow() { - tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" + if [[ $(tmux list-sessions 2>/dev/null | grep -c pimod) -eq 0 ]]; then + tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" + fi } ReinstallSpeedTest() { From d751a90c052220d3dc10e7360d331feb0ce6a7ff Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 7 Feb 2024 04:59:37 -0500 Subject: [PATCH 551/638] update readme --- README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 44628c058e..481c59d426 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,17 @@ -# Pihole Speedtest Mod +
-[![Join the chat at https://gitter.im/pihole-speedtest/community](https://badges.gitter.im/pihole-speedtest/community.svg)](https://gitter.im/pihole-speedtest/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/TW9TfyM) +# Pi-hole Speedtest + +[![Join the chat at https://gitter.im/pihole-speedtest/community](https://badges.gitter.im/pihole-speedtest/community.svg)](https://gitter.im/pihole-speedtest/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/TW9TfyM) Test your connection speed directly in the Pi-hole web interface! -Please go to the [main repository](https://github.com/arevindh/pihole-speedtest) for more information, including installation instructions, pull requests, and issues. +
+ +--- -[Uninstall Instructions](https://github.com/arevindh/pihole-speedtest/wiki/Uninstalling-Speedtest-Mod) +Please go to the [main repository](https://github.com/arevindh/pihole-speedtest) for more information, including (un)installation instructions, pull requests, and issues. ## Disclaimer -We are not affiliated with or endorsed by [Pi-hole](https://github.com/pi-hole/AdminLTE) +We are not affiliated with or endorsed by [Pi-hole](https://github.com/pi-hole/pi-hole) From 19848963c768839f03fbda2c701a17061e99f92a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 00:53:16 -0500 Subject: [PATCH 552/638] run script immediately --- advanced/Scripts/webpage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index a55e8856fe..22d82e42dc 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -645,6 +645,7 @@ EOF if [[ "$total_seconds" == "nan" ]] || (( $(echo "$total_seconds > 0" | bc -l) )); then crontab -l &> /dev/null || crontab -l 2>/dev/null | { cat; echo ""; } | crontab - (crontab -l; echo "* * * * * /bin/bash $schedule_script") | crontab - + sudo bash -c "$schedule_script" fi } From a7902e7172998ce88fd79d613c854c6d10cbff29 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 03:38:02 -0500 Subject: [PATCH 553/638] better if --- advanced/Scripts/webpage.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 22d82e42dc..7c7920e687 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -617,8 +617,10 @@ interval_seconds=$total_seconds schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") # if schedule is set and is greater than 0, and interval is "nan", set the speedtest interval to the schedule -if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (( \$(echo "\$schedule > 0" | bc -l) )) && [[ "\$interval_seconds" == "nan" ]]; then - /usr/local/bin/pihole -a -s "\$schedule" +if [[ "\$interval_seconds" == "nan" ]]; then + if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (( \$(echo "\$schedule > 0" | bc -l) )); then + /usr/local/bin/pihole -a -s "\$schedule" + fi exit 0 fi From dce50a90110a29008585a384d248d2c0632747ca Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 03:55:50 -0500 Subject: [PATCH 554/638] fix negative --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7c7920e687..130b710e89 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -604,7 +604,7 @@ generate_cron_schedule() { addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0.017" fi - if [[ ! "$total_seconds" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then + if [[ ! "$total_seconds" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then total_seconds="nan" fi From 8551bdddcd101063cb2c1b5fd6e2d7099f8a6bfa Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:57:56 -0500 Subject: [PATCH 555/638] use utc again, fedora support --- advanced/Scripts/speedtestmod/mod.sh | 77 +++++++++++++++------- advanced/Scripts/speedtestmod/speedtest.sh | 32 +++++++-- 2 files changed, 80 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index b293e477fe..6cab24b2d7 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -108,7 +108,15 @@ manageHistory() { } notInstalled() { - apt-cache policy "$1" | grep 'Installed: (none)' >/dev/null + if [ -x "$(command -v yum)" ] || [ -x "$(command -v dnf)" ]; then + rpm -q "$1" &>/dev/null || return 0 + elif [ -x "$(command -v apt-get)" ]; then + dpkg -s "$1" &>/dev/null || return 0 + else + echo "Unsupported package manager!" + exit 1 + fi + return 1 } install() { @@ -120,32 +128,55 @@ install() { fi local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - apt-get update - apt-get install -y bc sqlite3 php$PHP_VERSION-sqlite3 jq tmux curl wget - - if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then - echo "Adding speedtest source..." - if [ -e /etc/os-release ]; then - . /etc/os-release - local base="ubuntu debian" - local os=${ID} - local dist=${VERSION_CODENAME} - if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then - os=${ID_LIKE%% *} - [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) - dist=${UBUNTU_CODENAME} - [ -z "$dist" ] && dist=${VERSION_CODENAME} + local PKG_MANAGER=$(command -v apt-get || command -v yum || command -v dnf) + local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") + + if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + apt-get update + fi + + local missingPkgs=() + for pkg in "${PKGS[@]}"; do + if notInstalled "$pkg"; then + missingPkgs+=("$pkg") + fi + done + + if [ ${#missingPkgs[@]} -gt 0 ]; then + sudo $PKG_MANAGER install -y "${missingPkgs[@]}" + fi + + if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then + if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then + echo "Adding speedtest source for RPM..." + sudo bash -c 'curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash' + fi + elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then + echo "Adding speedtest source for DEB..." + if [ -e /etc/os-release ]; then + . /etc/os-release + local base="ubuntu debian" + local os=${ID} + local dist=${VERSION_CODENAME} + if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then + os=${ID_LIKE%% *} + [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + dist=${UBUNTU_CODENAME} + [ -z "$dist" ] && dist=${VERSION_CODENAME} + fi + wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 + chmod +x /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh + rm -f /tmp/script.deb.sh + else + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash fi - wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 - chmod +x /tmp/script.deb.sh - os=$os dist=$dist /tmp/script.deb.sh - rm -f /tmp/script.deb.sh - else - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash fi fi + if notInstalled speedtest && notInstalled speedtest-cli; then - apt-get install -y speedtest + sudo $PKG_MANAGER install -y speedtest fi if [ -f /usr/local/bin/speedtest ]; then rm -f /usr/local/bin/speedtest diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 4d0d648f9d..5c9bc84587 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -1,6 +1,6 @@ #!/bin/bash FILE=/tmp/speedtest.log -start=$(date +"%Y-%m-%d %H:%M:%S %Z") +start=$(date -u -I'minutes') serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) create_table="create table if not exists speedtest ( @@ -35,7 +35,7 @@ speedtest() { } internet() { - stop=$(date +"%Y-%m-%d %H:%M:%S %Z") + stop=$(date -u -I'minutes') res="$(<$FILE)" server_name=$(jq -r '.server.name' <<< "$res") server_dist=0 @@ -68,17 +68,37 @@ internet() { } nointernet(){ - stop=$(date +"%Y-%m-%d %H:%M:%S %Z") + stop=$(date -u -I'minutes') echo "No Internet" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', 'No Internet', '-', '-', 0, 0, 0, 0, '#');" exit 1 } +notInstalled() { + if [ -x "$(command -v yum)" ] || [ -x "$(command -v dnf)" ]; then + rpm -q "$1" &>/dev/null || return 0 + elif [ -x "$(command -v apt-get)" ]; then + dpkg -s "$1" &>/dev/null || return 0 + else + echo "Unsupported package manager!" + exit 1 + fi + return 1 +} + tryagain(){ - if apt-cache policy speedtest-cli | grep -q 'Installed: (none)'; then - apt-get install -y speedtest-cli speedtest- + if notInstalled speedtest-cli; then + if [ -x "$(command -v apt-get)" ]; then + apt-get install -y speedtest-cli speedtest- + else + yum install -y --allowerasing speedtest-cli + fi else - apt-get install -y speedtest speedtest-cli- + if [ -x "$(command -v apt-get)" ]; then + apt-get install -y speedtest speedtest-cli- + else + yum install -y --allowerasing speedtest + fi fi speedtest > "$FILE" && internet || nointernet } From 8787a60ab013d8f3b260c696178ca934d0647448 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 16:51:27 -0500 Subject: [PATCH 556/638] seconds --- advanced/Scripts/speedtestmod/speedtest.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 5c9bc84587..06187ddb7c 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -1,6 +1,6 @@ #!/bin/bash FILE=/tmp/speedtest.log -start=$(date -u -I'minutes') +start=$(date -u -I'seconds') serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) create_table="create table if not exists speedtest ( @@ -35,7 +35,7 @@ speedtest() { } internet() { - stop=$(date -u -I'minutes') + stop=$(date -u -I'seconds') res="$(<$FILE)" server_name=$(jq -r '.server.name' <<< "$res") server_dist=0 @@ -68,7 +68,7 @@ internet() { } nointernet(){ - stop=$(date -u -I'minutes') + stop=$(date -u -I'seconds') echo "No Internet" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', 'No Internet', '-', '-', 0, 0, 0, 0, '#');" exit 1 From 4337e09af87232ee8165948289b6a80b09df8b65 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 17:31:04 -0500 Subject: [PATCH 557/638] rfc --- advanced/Scripts/speedtestmod/speedtest.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 06187ddb7c..48138141b9 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -1,6 +1,6 @@ #!/bin/bash FILE=/tmp/speedtest.log -start=$(date -u -I'seconds') +start=$(date -u --rfc-3339='seconds') serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) create_table="create table if not exists speedtest ( @@ -35,7 +35,7 @@ speedtest() { } internet() { - stop=$(date -u -I'seconds') + stop=$(date -u --rfc-3339='seconds') res="$(<$FILE)" server_name=$(jq -r '.server.name' <<< "$res") server_dist=0 @@ -68,7 +68,7 @@ internet() { } nointernet(){ - stop=$(date -u -I'seconds') + stop=$(date -u --rfc-3339='seconds') echo "No Internet" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', 'No Internet', '-', '-', 0, 0, 0, 0, '#');" exit 1 From 7584a8e0c17857dfb8d0b23ff4baaf076258ed38 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:18:17 -0500 Subject: [PATCH 558/638] redirect main --- advanced/Scripts/speedtestmod/speedtest.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 48138141b9..c22223e9cf 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -100,7 +100,7 @@ tryagain(){ yum install -y --allowerasing speedtest fi fi - speedtest > "$FILE" && internet || nointernet + speedtest && internet || nointernet } main() { @@ -109,7 +109,7 @@ main() { exit $? fi echo "Test has been initiated, please wait." - speedtest > "$FILE" && internet || tryagain + speedtest && internet || tryagain } -main +main > "$FILE" From c52ea4738851b242d645c3d82651900256512206 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:23:15 -0500 Subject: [PATCH 559/638] echo date after test --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 130b710e89..ab24920573 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -636,10 +636,10 @@ if [[ -f "\$last_run_file" ]]; then fi fi -echo \$(date +%s) > "\$last_run_file" if [[ \$(tmux list-sessions 2>/dev/null | grep -c pimod) -eq 0 ]]; then /usr/bin/tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" fi +echo \$(date +%s) > "\$last_run_file" EOF sudo chmod +x "$schedule_script" From 691ed75159d3ff3598f0dd727e5c26e652ee318c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:28:33 -0500 Subject: [PATCH 560/638] echo in if --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index ab24920573..f611026223 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -638,8 +638,8 @@ fi if [[ \$(tmux list-sessions 2>/dev/null | grep -c pimod) -eq 0 ]]; then /usr/bin/tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" + echo \$(date +%s) > "\$last_run_file" fi -echo \$(date +%s) > "\$last_run_file" EOF sudo chmod +x "$schedule_script" From cecb52f0ea6dc024d7594ec30cb324aab7119821 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 18:32:07 -0500 Subject: [PATCH 561/638] echo before --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f611026223..db80644037 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -637,8 +637,8 @@ if [[ -f "\$last_run_file" ]]; then fi if [[ \$(tmux list-sessions 2>/dev/null | grep -c pimod) -eq 0 ]]; then - /usr/bin/tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" echo \$(date +%s) > "\$last_run_file" + /usr/bin/tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" fi EOF sudo chmod +x "$schedule_script" From 97793fc35bf0fa4b7eb3e073fa1e2fb68640ff43 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 19:30:42 -0500 Subject: [PATCH 562/638] round seconds --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index db80644037..719e776c31 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,6 +606,8 @@ generate_cron_schedule() { if [[ ! "$total_seconds" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then total_seconds="nan" + else + total_seconds=$(echo "scale=0; ($total_seconds + 30) / 60 * 60" | bc) fi sudo bash -c "cat > $(printf %q "$schedule_script")" << EOF From a4d5178357a5c9c6bc55776c7136d31be9b66609 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 20:56:14 -0500 Subject: [PATCH 563/638] use remainder --- advanced/Scripts/webpage.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 719e776c31..2689b7f449 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -607,7 +607,12 @@ generate_cron_schedule() { if [[ ! "$total_seconds" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then total_seconds="nan" else - total_seconds=$(echo "scale=0; ($total_seconds + 30) / 60 * 60" | bc) + remainder=$(echo "$total_seconds % 60" | bc) + if [ $(echo "$remainder < 30" | bc) -eq 1 ]; then + total_seconds=$(echo "$total_seconds - $remainder" | bc) + else + total_seconds=$(echo "$total_seconds + (60 - $remainder)" | bc) + fi fi sudo bash -c "cat > $(printf %q "$schedule_script")" << EOF From dc8a668c9fb2fa9c458b4adcfab2ea59c9dbb1b6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:18:56 -0500 Subject: [PATCH 564/638] swap log --- advanced/Scripts/speedtestmod/speedtest.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index c22223e9cf..26d3d3f9cf 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -113,3 +113,7 @@ main() { } main > "$FILE" + +cp $FILE /var/log/pihole/speedtest.log +rm $FILE +``` From 3de5728970c0c770cfcbc32e7d060de44cf323d3 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 22:03:59 -0500 Subject: [PATCH 565/638] extra if --- advanced/Scripts/webpage.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 2689b7f449..f08cd3b537 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -595,8 +595,7 @@ generate_systemd_calendar() { } generate_cron_schedule() { - local interval_hours="$1" - local total_seconds=$(echo "$interval_hours * 3600" | bc) + local total_seconds=$(echo "$1 * 3600" | bc) local schedule_script="/opt/pihole/speedtestmod/schedule_check.sh" if (( $(echo "$total_seconds < 60" | bc -l) )) && (( $(echo "$total_seconds > 0" | bc -l) )); then @@ -606,7 +605,7 @@ generate_cron_schedule() { if [[ ! "$total_seconds" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then total_seconds="nan" - else + elif (( $(echo "$total_seconds > 0" | bc -l) )); then remainder=$(echo "$total_seconds % 60" | bc) if [ $(echo "$remainder < 30" | bc) -eq 1 ]; then total_seconds=$(echo "$total_seconds - $remainder" | bc) From 3721265cbb91362c2a262c36daf4b9d175887e7d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 22:06:11 -0500 Subject: [PATCH 566/638] typo --- advanced/Scripts/speedtestmod/speedtest.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 26d3d3f9cf..08951b62ee 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -116,4 +116,3 @@ main > "$FILE" cp $FILE /var/log/pihole/speedtest.log rm $FILE -``` From 47f6f4032fd6df61a45ba325b02464ce584e52ad Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 8 Feb 2024 22:10:46 -0500 Subject: [PATCH 567/638] bc -l --- 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 f08cd3b537..9edff8d439 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -606,11 +606,11 @@ generate_cron_schedule() { if [[ ! "$total_seconds" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then total_seconds="nan" elif (( $(echo "$total_seconds > 0" | bc -l) )); then - remainder=$(echo "$total_seconds % 60" | bc) - if [ $(echo "$remainder < 30" | bc) -eq 1 ]; then - total_seconds=$(echo "$total_seconds - $remainder" | bc) + remainder=$(echo "$total_seconds % 60" | bc -l) + if (( $(echo "$remainder < 30" | bc -l) )); then + total_seconds=$(echo "$total_seconds - $remainder" | bc -l) else - total_seconds=$(echo "$total_seconds + (60 - $remainder)" | bc) + total_seconds=$(echo "$total_seconds + (60 - $remainder)" | bc -l) fi fi From ba661e43582ebd9a3541af2d2f73fc317cd50b0a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 9 Feb 2024 04:23:57 -0500 Subject: [PATCH 568/638] fix speedtest in docker --- advanced/Scripts/speedtestmod/mod.sh | 17 +++++-------- advanced/Scripts/speedtestmod/speedtest.sh | 29 +++++++++++----------- advanced/Scripts/webpage.sh | 8 +++--- 3 files changed, 25 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 6cab24b2d7..4a6aeeaa3c 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,11 +1,8 @@ #!/bin/bash -LOG_FILE="/var/log/pimod.log" - admin_dir=/var/www/html curr_wp=/opt/pihole/webpage.sh last_wp=$curr_wp.old org_wp=$curr_wp.org - curr_db=/etc/pihole/speedtest.db last_db=$curr_db.old db_table="speedtest" @@ -278,12 +275,8 @@ abort() { download $admin_dir admin old web fi - if (($aborted == 0)); then - pihole restartdns - printf "Please try again or try manually.\n\n$(date)\n" - fi - aborted=1 - exit 1 + pihole restartdns + printf "Please try again or try manually.\n\n$(date)\n" } commit() { @@ -292,7 +285,6 @@ commit() { rm -f $last_wp pihole restartdns printf "Done!\n\n$(date)\n" - exit 0 } main() { @@ -333,4 +325,7 @@ main() { exit 0 } -main "$@" 2>&1 | sudo tee -- "$LOG_FILE" +rm -f /tmp/pimod.log +main "$@" 2>&1 | tee -a /tmp/pimod.log +mv -f /tmp/pimod.log /var/log/pihole/mod.log +exit 0 diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 08951b62ee..96f01e39f7 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -36,9 +36,8 @@ speedtest() { internet() { stop=$(date -u --rfc-3339='seconds') - res="$(<$FILE)" + res="$(/dev/null || return 0 else echo "Unsupported package manager!" + mv -f "$FILE" /var/log/pihole/speedtest.log exit 1 fi return 1 @@ -100,7 +103,7 @@ tryagain(){ yum install -y --allowerasing speedtest fi fi - speedtest && internet || nointernet + speedtest > /tmp/speedtest_results && internet || nointernet } main() { @@ -108,11 +111,9 @@ main() { sudo "$0" "$@" exit $? fi - echo "Test has been initiated, please wait." - speedtest && internet || tryagain + echo "Test has been initiated, please wait..." + speedtest > /tmp/speedtest_results && internet || tryagain } -main > "$FILE" - -cp $FILE /var/log/pihole/speedtest.log -rm $FILE +rm -f "$FILE" +main | tee -a "$FILE" diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9edff8d439..fe94c6fb8e 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -562,14 +562,14 @@ generate_systemd_calendar() { elif (( $(echo "$total_seconds == 3600" | bc -l) )); then # exactly an hour freq_entries+=("*-*-* *:00:00") elif (( $(echo "$total_seconds < 86400" | bc -l) )); then # less than a day - if (( $(echo "3600 % $total_seconds == 0" | bc -l) )); then # divides evenly into an hour + if (( $(awk "BEGIN {print ($total_seconds / 3600) % 1}") == 0 )); then # divides evenly into an hour local hour_interval=$(echo "$total_seconds / 3600" | bc) freq_entries+=("*-*-* 00/$hour_interval:00:00") else # does not divide evenly into an hour local current_second=0 while (( $(echo "$current_second < 86400" | bc -l) )); do local hour=$(echo "$current_second / 3600" | bc) - local minute=$(echo "($current_second % 3600) / 60" | bc) + local minute=$(awk "BEGIN {print ($current_second % 3600) / 60}") hour=${hour%.*} minute=${minute%.*} freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") @@ -600,18 +600,18 @@ generate_cron_schedule() { if (( $(echo "$total_seconds < 60" | bc -l) )) && (( $(echo "$total_seconds > 0" | bc -l) )); then total_seconds=60 - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0.017" fi if [[ ! "$total_seconds" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then total_seconds="nan" elif (( $(echo "$total_seconds > 0" | bc -l) )); then - remainder=$(echo "$total_seconds % 60" | bc -l) + remainder=$(awk "BEGIN {print $total_seconds % 60}") if (( $(echo "$remainder < 30" | bc -l) )); then total_seconds=$(echo "$total_seconds - $remainder" | bc -l) else total_seconds=$(echo "$total_seconds + (60 - $remainder)" | bc -l) fi + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "$(echo "scale=3; $total_seconds / 3600" | bc)" fi sudo bash -c "cat > $(printf %q "$schedule_script")" << EOF From 617d39c24846f68c99cf513801ced863403b678a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 9 Feb 2024 04:59:39 -0500 Subject: [PATCH 569/638] curl dist --- advanced/Scripts/speedtestmod/speedtest.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 96f01e39f7..71ec8625a6 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -48,8 +48,11 @@ internet() { server_ping=$(jq -r '.ping.latency' <<< "$res") share_url=$(jq -r '.result.url' <<< "$res") server_id=$(jq -r '.server.id' <<< "$res") - #servers="$(curl 'https://www.speedtest.net/api/js/servers' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Sec-GPC: 1')" - server_dist=0 + servers="$(curl 'https://www.speedtest.net/api/js/servers' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Sec-GPC: 1')" + server_dist=$(jq --arg id "$server_id" '.[] | select(.id == $id) | .distance' <<< "$servers") + if [ -z "$server_dist" ]; then + server_dist=0 + fi else download=$(jq -r '.download' <<< "$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') upload=$(jq -r '.upload' <<< "$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') From 63b3effb70d4968e4689de4907a105be799fe0eb Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 11 Feb 2024 03:24:10 -0500 Subject: [PATCH 570/638] fix cp --- advanced/Scripts/speedtestmod/mod.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 4a6aeeaa3c..d323062777 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -184,14 +184,14 @@ install() { download $admin_dir admin https://github.com/arevindh/AdminLTE web if [ -f $curr_wp ]; then if ! cat $curr_wp | grep -q SpeedTest; then - cp -a $curr_wp $org_wp + cp -af $curr_wp $org_wp fi if [ ! -f $last_wp ]; then - cp -a $curr_wp $last_wp + cp -af $curr_wp $last_wp fi fi - cp -a /opt/mod_pihole/advanced/Scripts/webpage.sh $curr_wp - cp -a /opt/mod_pihole/advanced/Scripts/speedtestmod /opt/pihole/speedtestmod + cp -af /opt/mod_pihole/advanced/Scripts/webpage.sh $curr_wp + cp -af /opt/mod_pihole/advanced/Scripts/speedtestmod/. /opt/pihole/speedtestmod/ chmod +x $curr_wp pihole -a -s pihole updatechecker local @@ -206,16 +206,16 @@ uninstall() { download /opt org_pihole https://github.com/pi-hole/pi-hole Pi-hole fi cd /opt - cp -a org_pihole/advanced/Scripts/webpage.sh $org_wp + cp -af org_pihole/advanced/Scripts/webpage.sh $org_wp rm -rf org_pihole fi pihole -a -su download $admin_dir admin https://github.com/pi-hole/AdminLTE web if [ ! -f $last_wp ]; then - cp -a $curr_wp $last_wp + cp -af $curr_wp $last_wp fi - cp -a $org_wp $curr_wp + cp -af $org_wp $curr_wp chmod +x $curr_wp rm -rf /opt/mod_pihole pihole updatechecker @@ -261,7 +261,7 @@ abort() { echo "Process Aborting..." if [ -f $last_wp ]; then - cp -a $last_wp $curr_wp + cp -af $last_wp $curr_wp chmod +x $curr_wp rm -f $last_wp fi @@ -276,6 +276,7 @@ abort() { fi pihole restartdns + aborted=1 printf "Please try again or try manually.\n\n$(date)\n" } @@ -322,10 +323,9 @@ main() { manageHistory $db ;; esac - exit 0 } rm -f /tmp/pimod.log main "$@" 2>&1 | tee -a /tmp/pimod.log mv -f /tmp/pimod.log /var/log/pihole/mod.log -exit 0 +exit $aborted From 423f7e01bed064ed3ddcac41758e9b3b4e5a14ab Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 11 Feb 2024 03:36:24 -0500 Subject: [PATCH 571/638] copy log --- advanced/Scripts/speedtestmod/mod.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index d323062777..1d9ccf3898 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -94,12 +94,18 @@ manageHistory() { if [ -f /etc/pihole/last_speedtest ]; then mv -f /etc/pihole/last_speedtest /etc/pihole/last_speedtest.old fi + if [ -f /var/log/pihole/speedtest.log ]; then + mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old + fi elif [ -f $last_db ]; then echo "Restoring Database..." mv -f $last_db $curr_db if [ -f /etc/pihole/last_speedtest.old ]; then mv -f /etc/pihole/last_speedtest.old /etc/pihole/last_speedtest fi + if [ -f /var/log/pihole/speedtest.log.old ]; then + mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log + fi fi fi } From e164b051e4add26f472b99ae6c1df5977b14bc0e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 11 Feb 2024 22:45:59 -0500 Subject: [PATCH 572/638] oops --- advanced/Scripts/speedtestmod/mod.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 1d9ccf3898..d5127c487d 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -329,6 +329,7 @@ main() { manageHistory $db ;; esac + exit 0 } rm -f /tmp/pimod.log From 0cb6ed0224057837e8a7ce6bcbfae94e6c1d0062 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 13 Feb 2024 01:23:16 -0500 Subject: [PATCH 573/638] same dist, jq output --- advanced/Scripts/speedtestmod/speedtest.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 71ec8625a6..0e5bd695df 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -38,6 +38,11 @@ internet() { stop=$(date -u --rfc-3339='seconds') res="$( Date: Tue, 13 Feb 2024 03:52:12 -0500 Subject: [PATCH 574/638] refactor ChangeSpeedTestSchedule --- advanced/Scripts/speedtestmod/mod.sh | 2 +- advanced/Scripts/speedtestmod/speedtest.sh | 11 ++- advanced/Scripts/webpage.sh | 87 ++++++++-------------- 3 files changed, 39 insertions(+), 61 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index d5127c487d..0f4749b1aa 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -216,7 +216,7 @@ uninstall() { rm -rf org_pihole fi - pihole -a -su + pihole -a -s 0 download $admin_dir admin https://github.com/pi-hole/AdminLTE web if [ ! -f $last_wp ]; then cp -af $curr_wp $last_wp diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 0e5bd695df..eaab7b7c74 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -38,11 +38,9 @@ internet() { stop=$(date -u --rfc-3339='seconds') res="$( 0" | bc -l) )); then - total_seconds=60 - fi + if [[ "$1" != "nan" ]] && [[ "$1" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (( $(echo "$1 > 0" | bc -l) )); then + total_seconds=$(echo "$1 * 3600" | bc) + if (( $(echo "$total_seconds < 60" | bc -l) )); then + total_seconds=60 + fi - if [[ ! "$total_seconds" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then - total_seconds="nan" - elif (( $(echo "$total_seconds > 0" | bc -l) )); then - remainder=$(awk "BEGIN {print $total_seconds % 60}") + local remainder=$(awk "BEGIN {print $total_seconds % 60}") if (( $(echo "$remainder < 30" | bc -l) )); then total_seconds=$(echo "$total_seconds - $remainder" | bc -l) else @@ -624,7 +622,7 @@ schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") # if schedule is set and is greater than 0, and interval is "nan", set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then - if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (( \$(echo "\$schedule > 0" | bc -l) )); then + if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then /usr/local/bin/pihole -a -s "\$schedule" fi exit 0 @@ -657,31 +655,27 @@ EOF fi } -get_scheduler() { - if [[ -d /run/systemd/system ]]; then - echo "systemd" +ChangeSpeedTestSchedule() { + local interval="${args[2]%\.}" + if [[ "${interval-}" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then + if (( $(echo "$interval < 0" | bc -l) )); then + interval="0" + fi + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "$interval" else - echo "cron" + interval=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") + if [[ ! "${interval-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then + interval="nan" + fi fi -} -UnsetService() { - if [[ "$(get_scheduler)" == "cron" ]]; then - generate_cron_schedule "-1" - else + if [[ ! -d /run/systemd/system ]]; then + generate_cron_schedule "$interval" + elif [[ "$interval" == "0" ]] || [[ "$interval" == "nan" ]]; then systemctl disable --now pihole-speedtest.timer &> /dev/null - fi -} - -SetService() { - if [[ "$1" == "0" ]]; then - UnsetService else - if [[ "$(get_scheduler)" == "cron" ]]; then - generate_cron_schedule "$1" - else - local freq=$(generate_systemd_calendar "$1") - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF + local freq=$(generate_systemd_calendar "$interval") + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest After=network.target @@ -694,7 +688,7 @@ ExecStart=/opt/pihole/speedtestmod/speedtest.sh [Install] WantedBy=multi-user.target EOF' - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer @@ -704,31 +698,13 @@ WantedBy=timers.target [Timer] Persistent=true EOF' - while IFS= read -r line; do - sudo bash -c "echo 'OnCalendar=$line' >> /etc/systemd/system/pihole-speedtest.timer" - done <<< "$freq" - - systemctl daemon-reload - systemctl reenable pihole-speedtest.timer &> /dev/null - systemctl restart pihole-speedtest.timer - fi - fi -} + while IFS= read -r line; do + sudo bash -c "echo 'OnCalendar=$line' >> /etc/systemd/system/pihole-speedtest.timer" + done <<< "$freq" -ChangeSpeedTestSchedule() { - args[2]=${args[2]%\.} - if [[ "${args[2]-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then - if (( $(echo "${args[2]} >= 0" | bc -l) )); then - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "${args[2]}" - SetService "${args[2]}" - fi - else - local interval=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") - if [[ ! "${interval-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then - UnsetService - else - SetService "$interval" - fi + systemctl daemon-reload + systemctl reenable pihole-speedtest.timer &> /dev/null + systemctl restart pihole-speedtest.timer fi } @@ -1131,7 +1107,6 @@ main() { "-sc" ) ClearSpeedtestData;; "-ss" ) SpeedtestServer;; "-st" ) UpdateSpeedTestChartType;; - "-su" ) UnsetService;; "addcustomdns" ) AddCustomDNSAddress;; "removecustomdns" ) RemoveCustomDNSAddress;; "addcustomcname" ) AddCustomCNAMERecord;; From b72a8fb225d619377ee66f5627903ee14e2f38df Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 13 Feb 2024 04:19:58 -0500 Subject: [PATCH 575/638] fix server name --- advanced/Scripts/speedtestmod/speedtest.sh | 5 ++--- advanced/Scripts/webpage.sh | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index eaab7b7c74..d89d7f0fc4 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -37,16 +37,15 @@ speedtest() { internet() { stop=$(date -u --rfc-3339='seconds') res="$( Date: Tue, 13 Feb 2024 07:07:06 -0500 Subject: [PATCH 576/638] create db after --- advanced/Scripts/speedtestmod/speedtest.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index d89d7f0fc4..a5d726840c 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -1,8 +1,7 @@ #!/bin/bash -FILE=/tmp/speedtest.log start=$(date -u --rfc-3339='seconds') +out=/tmp/speedtest.log serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) - create_table="create table if not exists speedtest ( id integer primary key autoincrement, start_time text, @@ -16,7 +15,6 @@ download real, upload real, share_url text );" -sqlite3 /etc/pihole/speedtest.db "$create_table" speedtest() { if grep -q official <<< "$(/usr/bin/speedtest --version)"; then @@ -66,8 +64,9 @@ internet() { fi jq . /tmp/speedtest_results + sqlite3 /etc/pihole/speedtest.db "$create_table" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', '${isp}', '${from_ip}', '${server_name}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" - mv -f "$FILE" /var/log/pihole/speedtest.log + mv -f "$out" /var/log/pihole/speedtest.log exit 0 } @@ -75,8 +74,9 @@ nointernet(){ stop=$(date -u --rfc-3339='seconds') rm -f /tmp/speedtest_results echo "No Internet" + sqlite3 /etc/pihole/speedtest.db "$create_table" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start}', '${stop}', 'No Internet', '-', '-', 0, 0, 0, 0, '#');" - mv -f "$FILE" /var/log/pihole/speedtest.log + mv -f "$out" /var/log/pihole/speedtest.log exit 1 } @@ -87,7 +87,7 @@ notInstalled() { dpkg -s "$1" &>/dev/null || return 0 else echo "Unsupported package manager!" - mv -f "$FILE" /var/log/pihole/speedtest.log + mv -f "$out" /var/log/pihole/speedtest.log exit 1 fi return 1 @@ -119,5 +119,5 @@ main() { speedtest > /tmp/speedtest_results && internet || tryagain } -rm -f "$FILE" -main | tee -a "$FILE" +rm -f "$out" +main | tee -a "$out" From 9e2ffd08377883979673c78bc1a83287c7f51df3 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:27:13 -0500 Subject: [PATCH 577/638] copy speedtest log to volume --- advanced/Scripts/speedtestmod/mod.sh | 2 + advanced/Scripts/speedtestmod/speedtest.sh | 72 +++++++++++++--------- advanced/Scripts/webpage.sh | 1 - 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 0f4749b1aa..e5076b82bc 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -96,6 +96,7 @@ manageHistory() { fi if [ -f /var/log/pihole/speedtest.log ]; then mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old + rm -f /etc/pihole/speedtest.log fi elif [ -f $last_db ]; then echo "Restoring Database..." @@ -105,6 +106,7 @@ manageHistory() { fi if [ -f /var/log/pihole/speedtest.log.old ]; then mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log + cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log fi fi fi diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index a5d726840c..27e37a3d02 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -32,52 +32,64 @@ speedtest() { fi } +savetest() { + local start_time=$1 + local stop_time=$2 + local isp=${3-"No Internet"} + local from_ip=${4-"-"} + local server=${5-"-"} + local server_dist=${6-0} + local server_ping=${7-0} + local download=${8-0} + local upload=${9-0} + local share_url=${10-"#"} + sqlite3 /etc/pihole/speedtest.db "$create_table" + sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" + mv -f "$out" /var/log/pihole/speedtest.log + cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log + rm -f /tmp/speedtest_results + [ "$isp" == "No Internet" ] && exit 1 || exit 0 +} + internet() { - stop=$(date -u --rfc-3339='seconds') - res="$( /tmp/speedtest_results + savetest "$start" "$stop" } notInstalled() { diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 6042c04a29..8a9539808b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -651,7 +651,6 @@ EOF if [[ "$total_seconds" == "nan" ]] || (( $(echo "$total_seconds > 0" | bc -l) )); then crontab -l &> /dev/null || crontab -l 2>/dev/null | { cat; echo ""; } | crontab - (crontab -l; echo "* * * * * /bin/bash $schedule_script") | crontab - - sudo bash -c "$schedule_script" fi } From 1c5c498362888d3954630c73b8fa71448bea5295 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:56:34 -0500 Subject: [PATCH 578/638] fix schedule reset --- advanced/Scripts/speedtestmod/mod.sh | 4 ++-- advanced/Scripts/webpage.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index e5076b82bc..3cf9c178f7 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -201,8 +201,8 @@ install() { cp -af /opt/mod_pihole/advanced/Scripts/webpage.sh $curr_wp cp -af /opt/mod_pihole/advanced/Scripts/speedtestmod/. /opt/pihole/speedtestmod/ chmod +x $curr_wp - pihole -a -s pihole updatechecker local + pihole -a -s } uninstall() { @@ -218,7 +218,7 @@ uninstall() { rm -rf org_pihole fi - pihole -a -s 0 + pihole -a -s -1 download $admin_dir admin https://github.com/pi-hole/AdminLTE web if [ ! -f $last_wp ]; then cp -af $curr_wp $last_wp diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 8a9539808b..14b8341ecb 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -659,8 +659,9 @@ ChangeSpeedTestSchedule() { if [[ "${interval-}" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then if (( $(echo "$interval < 0" | bc -l) )); then interval="0" + else + addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "$interval" fi - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "$interval" else interval=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") if [[ ! "${interval-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then From 5b75cb1950544b4af0e1e4330fb39f22f4215aca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 17 Feb 2024 10:29:46 +0000 Subject: [PATCH 579/638] Bump tox from 4.12.1 to 4.13.0 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.12.1 to 4.13.0. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.12.1...4.13.0) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index 2b8dfb1b49..a6826838da 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 8.0.0 pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 -tox == 4.12.1 +tox == 4.13.0 From 3d0037451318c8a7eddb8b76c9a5c26c46214f46 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 17 Feb 2024 06:16:25 -0500 Subject: [PATCH 580/638] run settags again --- advanced/Scripts/speedtestmod/mod.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 3cf9c178f7..73f1eae413 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -28,7 +28,9 @@ setTags() { fi if [ ! -z "$name" ]; then localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 6) - [ "$localTag" == "HEAD" ] && localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 7) + if [ "$localTag" == "HEAD" ]; then + localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 7) + fi fi } @@ -39,11 +41,11 @@ download() { local src=${4-} local branch="${5-master}" local dest=$path/$name - if [ ! -d $dest ]; then # replicate + if [ ! -d "$dest" ]; then # replicate cd "$path" rm -rf "$name" git clone --depth=1 -b "$branch" "$url" "$name" - setTags "$name" "$src" $branch + setTags "$name" "$src" "$branch" if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then latestTag=$localTag @@ -51,27 +53,28 @@ download() { fi fi else # replace - setTags $dest "" $branch + setTags "$dest" "" "$branch" if [ ! -z "$src" ]; then if [ "$url" != "old" ]; then git config --global --add safe.directory "$dest" git remote -v | grep -q "old" || git remote rename origin old git remote -v | grep -q "origin" && git remote remove origin - git remote add origin $url + git remote add origin "$url" elif [ -d .git/refs/remotes/old ]; then git remote remove origin git remote rename old origin + git clean -ffdx fi git fetch origin -q + setTags "$dest" "$src" "$branch" fi - git reset --hard origin/$branch - git checkout -B $branch -q - git branch -u origin/$branch - git clean -ffdx + git reset --hard origin/"$branch" + git checkout -B "$branch" -q + git branch -u origin/"$branch" fi if [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag)" ]; then - git -c advice.detachedHead=false checkout $latestTag + git -c advice.detachedHead=false checkout "$latestTag" fi cd .. } @@ -154,7 +157,7 @@ install() { if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then echo "Adding speedtest source for RPM..." - sudo bash -c 'curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash' + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash fi elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then From 0fe566e256cc50390f944f2cf53ccb09a7e7ef92 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 17 Feb 2024 07:35:33 -0500 Subject: [PATCH 581/638] call settags less, check null, recursive test run --- advanced/Scripts/speedtestmod/mod.sh | 30 +++--- advanced/Scripts/speedtestmod/speedtest.sh | 113 ++++++++++----------- 2 files changed, 71 insertions(+), 72 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 73f1eae413..46b9f3e6e0 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -17,9 +17,9 @@ help() { } setTags() { - local path=${1-} - local name=${2-} - local branch="${3-master}" + local path=${1:-} + local name=${2:-} + local branch="${3:-master}" if [ ! -z "$path" ]; then cd "$path" git fetch origin $branch:refs/remotes/origin/$branch -q @@ -38,14 +38,15 @@ download() { local path=$1 local name=$2 local url=$3 - local src=${4-} - local branch="${5-master}" + local src=${4:-} + local branch="${5:-master}" local dest=$path/$name + if [ ! -d "$dest" ]; then # replicate cd "$path" rm -rf "$name" git clone --depth=1 -b "$branch" "$url" "$name" - setTags "$name" "$src" "$branch" + setTags "$name" "${src:-}" "$branch" if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then latestTag=$localTag @@ -53,7 +54,7 @@ download() { fi fi else # replace - setTags "$dest" "" "$branch" + cd "$dest" if [ ! -z "$src" ]; then if [ "$url" != "old" ]; then git config --global --add safe.directory "$dest" @@ -65,9 +66,8 @@ download() { git remote rename old origin git clean -ffdx fi - git fetch origin -q - setTags "$dest" "$src" "$branch" fi + setTags "$dest" "${src:-}" "$branch" git reset --hard origin/"$branch" git checkout -B "$branch" -q git branch -u origin/"$branch" @@ -90,7 +90,7 @@ isEmpty() { } manageHistory() { - if [ "${1-}" == "db" ]; then + if [ "${1:-}" == "db" ]; then if [ -f $curr_db ] && ! isEmpty $curr_db; then echo "Flushing Database..." mv -f $curr_db $last_db @@ -232,7 +232,7 @@ uninstall() { pihole updatechecker fi - manageHistory ${1-} + manageHistory ${1:-} } purge() { @@ -262,7 +262,7 @@ update() { else echo "Systemd not found. Skipping Pi-hole update..." fi - if [ "${1-}" == "un" ]; then + if [ "${1:-}" == "un" ]; then purge exit 0 fi @@ -301,7 +301,7 @@ commit() { main() { printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" - local op=${1-} + local op=${1:-} if [ "$op" == "-h" ] || [ "$op" == "--help" ]; then help exit 0 @@ -315,7 +315,7 @@ main() { trap '[ "$?" -eq "0" ] && commit || abort' EXIT trap 'abort' INT TERM - local db=$([ "$op" == "up" ] && echo "${3-}" || [ "$op" == "un" ] && echo "${2-}" || echo "$op") + local db=$([ "$op" == "up" ] && echo "${3:-}" || [ "$op" == "un" ] && echo "${2:-}" || echo "$op") case $op in db) manageHistory $db @@ -326,7 +326,7 @@ main() { ;; up) uninstall $db - update ${2-} + update ${2:-} install ;; *) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 27e37a3d02..2ead1bd445 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -17,7 +17,7 @@ share_url text );" speedtest() { - if grep -q official <<< "$(/usr/bin/speedtest --version)"; then + if grep -q official <<<"$(/usr/bin/speedtest --version)"; then if [[ -z "${serverid}" ]]; then /usr/bin/speedtest --accept-gdpr --accept-license -f json-pretty else @@ -35,14 +35,14 @@ speedtest() { savetest() { local start_time=$1 local stop_time=$2 - local isp=${3-"No Internet"} - local from_ip=${4-"-"} - local server=${5-"-"} - local server_dist=${6-0} - local server_ping=${7-0} - local download=${8-0} - local upload=${9-0} - local share_url=${10-"#"} + local isp=${3:-"No Internet"} + local from_ip=${4:-"-"} + local server=${5:-"-"} + local server_dist=${6:-0} + local server_ping=${7:-0} + local download=${8:-0} + local upload=${9:-0} + local share_url=${10:-"#"} sqlite3 /etc/pihole/speedtest.db "$create_table" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" mv -f "$out" /var/log/pihole/speedtest.log @@ -51,45 +51,14 @@ savetest() { [ "$isp" == "No Internet" ] && exit 1 || exit 0 } -internet() { - local stop=$(date -u --rfc-3339='seconds') - local res="$( /tmp/speedtest_results - savetest "$start" "$stop" } notInstalled() { @@ -105,21 +74,51 @@ notInstalled() { return 1 } -tryagain(){ - if notInstalled speedtest-cli; then - if [ -x "$(command -v apt-get)" ]; then - apt-get install -y speedtest-cli speedtest- +run() { + local res=$(speedtest >/tmp/speedtest_results) + local stop=$(date -u --rfc-3339='seconds') + if $res; then + local server_id=$(jq -r '.server.id' <<<"$res") + local servers="$(curl 'https://www.speedtest.net/api/js/servers' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Sec-GPC: 1')" + local server_dist=$(jq --arg id "$server_id" '.[] | select(.id == $id) | .distance' <<<"$servers") + + if grep -q official <<<"$(/usr/bin/speedtest --version)"; then + local server_name=$(jq -r '.server.name' <<<"$res") + local download=$(jq -r '.download.bandwidth' <<<"$res" | awk '{$1=$1*8/1000/1000; print $1;}' | sed 's/,/./g') + local upload=$(jq -r '.upload.bandwidth' <<<"$res" | awk '{$1=$1*8/1000/1000; print $1;}' | sed 's/,/./g') + local isp=$(jq -r '.isp' <<<"$res") + local from_ip=$(jq -r '.interface.externalIp' <<<"$res") + local server_ping=$(jq -r '.ping.latency' <<<"$res") + local share_url=$(jq -r '.result.url' <<<"$res") + if [ -z "$server_dist" ]; then + server_dist="-1" + fi else - yum install -y --allowerasing speedtest-cli + local server_name=$(jq -r '.server.sponsor' <<<"$res") + local download=$(jq -r '.download' <<<"$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') + local upload=$(jq -r '.upload' <<<"$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') + local isp=$(jq -r '.client.isp' <<<"$res") + local from_ip=$(jq -r '.client.ip' <<<"$res") + local server_ping=$(jq -r '.ping' <<<"$res") + local share_url=$(jq -r '.share' <<<"$res") + if [ -z "$server_dist" ]; then + server_dist=$(jq -r '.server.d' <<<"$res") + fi fi + + jq . /tmp/speedtest_results + savetest "$start" "$stop" "$isp" "$from_ip" "$server_name" "$server_dist" "$server_ping" "$download" "$upload" "$share_url" + elif [ "${1:-}" == "3" ]; then + echo "Test Failed!" >/tmp/speedtest_results + savetest "$start" "$stop" else - if [ -x "$(command -v apt-get)" ]; then - apt-get install -y speedtest speedtest-cli- + if notInstalled speedtest-cli; then + swaptest speedtest-cli speedtest else - yum install -y --allowerasing speedtest + swaptest speedtest speedtest-cli fi + run $((${1:-0} + 1)) fi - speedtest > /tmp/speedtest_results && internet || nointernet } main() { @@ -127,9 +126,9 @@ main() { sudo "$0" "$@" exit $? fi - echo "Test has been initiated, please wait..." - speedtest > /tmp/speedtest_results && internet || tryagain + run } +echo "Running test..." rm -f "$out" main | tee -a "$out" From 9386bd4ec71b1a5a19219dbf41fe73eb58540f5c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 17 Feb 2024 09:41:27 -0500 Subject: [PATCH 582/638] edit test log --- advanced/Scripts/speedtestmod/speedtest.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 2ead1bd445..31589ebd03 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -45,9 +45,9 @@ savetest() { local share_url=${10:-"#"} sqlite3 /etc/pihole/speedtest.db "$create_table" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" - mv -f "$out" /var/log/pihole/speedtest.log + mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log - rm -f /tmp/speedtest_results + rm -f "$out" [ "$isp" == "No Internet" ] && exit 1 || exit 0 } @@ -75,9 +75,10 @@ notInstalled() { } run() { - local res=$(speedtest >/tmp/speedtest_results) + speedtest >/tmp/speedtest_results local stop=$(date -u --rfc-3339='seconds') - if $res; then + if jq -e . /tmp/speedtest_results &>/dev/null; then + local res=$( Date: Sat, 17 Feb 2024 09:54:02 -0500 Subject: [PATCH 583/638] fix pretty log --- advanced/Scripts/speedtestmod/speedtest.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 31589ebd03..08932d547e 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -107,7 +107,7 @@ run() { fi fi - jq . /tmp/speedtest_results + jq . /tmp/speedtest_results >/tmp/speedtest_results savetest "$start" "$stop" "$isp" "$from_ip" "$server_name" "$server_dist" "$server_ping" "$download" "$upload" "$share_url" elif [ "${1:-}" == "3" ]; then echo "Test Failed!" >/tmp/speedtest_results @@ -131,6 +131,5 @@ main() { run } - rm -f "$out" main | tee -a "$out" From 881cb5f7275e2613fc04ba42631dcc0d88b03c15 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 17 Feb 2024 10:10:38 -0500 Subject: [PATCH 584/638] pipe log --- advanced/Scripts/speedtestmod/speedtest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 08932d547e..3bd627fffb 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -107,7 +107,7 @@ run() { fi fi - jq . /tmp/speedtest_results >/tmp/speedtest_results + jq . /tmp/speedtest_results | tee /tmp/speedtest_results savetest "$start" "$stop" "$isp" "$from_ip" "$server_name" "$server_dist" "$server_ping" "$download" "$upload" "$share_url" elif [ "${1:-}" == "3" ]; then echo "Test Failed!" >/tmp/speedtest_results From 028c8ace5547b32264c518ee811ac329b6df5096 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 19 Feb 2024 05:23:38 -0500 Subject: [PATCH 585/638] pipe log --- advanced/Scripts/speedtestmod/mod.sh | 3 ++- advanced/Scripts/speedtestmod/speedtest.sh | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 46b9f3e6e0..8d2f5ca764 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -69,7 +69,7 @@ download() { fi setTags "$dest" "${src:-}" "$branch" git reset --hard origin/"$branch" - git checkout -B "$branch" -q + git checkout -B "$branch" git branch -u origin/"$branch" fi @@ -338,6 +338,7 @@ main() { } rm -f /tmp/pimod.log +touch /tmp/pimod.log main "$@" 2>&1 | tee -a /tmp/pimod.log mv -f /tmp/pimod.log /var/log/pihole/mod.log exit $aborted diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 3bd627fffb..90f2d0553a 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -19,9 +19,9 @@ share_url text speedtest() { if grep -q official <<<"$(/usr/bin/speedtest --version)"; then if [[ -z "${serverid}" ]]; then - /usr/bin/speedtest --accept-gdpr --accept-license -f json-pretty + /usr/bin/speedtest --accept-gdpr --accept-license -f json else - /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json-pretty + /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json fi else if [[ -z "${serverid}" ]]; then @@ -75,9 +75,9 @@ notInstalled() { } run() { - speedtest >/tmp/speedtest_results + speedtest | jq . >/tmp/speedtest_results || echo "Attempt ${2:-1} Failed!" >/tmp/speedtest_results local stop=$(date -u --rfc-3339='seconds') - if jq -e . /tmp/speedtest_results &>/dev/null; then + if jq -e '.server.id' /tmp/speedtest_results &>/dev/null; then local res=$(/tmp/speedtest_results savetest "$start" "$stop" else @@ -118,7 +117,7 @@ run() { else swaptest speedtest speedtest-cli fi - run $((${1:-0} + 1)) + run $1 $((${2:-1} + 1)) fi } @@ -128,8 +127,7 @@ main() { exit $? fi echo "Running test..." - run + run $1 # Number of attempts } -rm -f "$out" -main | tee -a "$out" +main ${1:-3} >"$out" From 6453fde0b9ee8949116d4d52327c2c1a0175eb8d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 19 Feb 2024 06:35:11 -0500 Subject: [PATCH 586/638] ensure speedtest source --- advanced/Scripts/speedtestmod/mod.sh | 67 ++++++++++------------ advanced/Scripts/speedtestmod/speedtest.sh | 40 +++++++++++-- 2 files changed, 67 insertions(+), 40 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 8d2f5ca764..ead8a7fffc 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -136,7 +136,7 @@ install() { fi local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local PKG_MANAGER=$(command -v apt-get || command -v yum || command -v dnf) + local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then @@ -151,48 +151,43 @@ install() { done if [ ${#missingPkgs[@]} -gt 0 ]; then - sudo $PKG_MANAGER install -y "${missingPkgs[@]}" + $PKG_MANAGER install -y "${missingPkgs[@]}" fi - if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then - if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then - echo "Adding speedtest source for RPM..." - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash - fi - elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then - echo "Adding speedtest source for DEB..." - if [ -e /etc/os-release ]; then - . /etc/os-release - local base="ubuntu debian" - local os=${ID} - local dist=${VERSION_CODENAME} - if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then - os=${ID_LIKE%% *} - [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) - dist=${UBUNTU_CODENAME} - [ -z "$dist" ] && dist=${VERSION_CODENAME} + if notInstalled speedtest && notInstalled speedtest-cli; then + if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then + if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then + echo "Adding speedtest source for RPM..." + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash + fi + elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then + echo "Adding speedtest source for DEB..." + if [ -e /etc/os-release ]; then + . /etc/os-release + local base="ubuntu debian" + local os=${ID} + local dist=${VERSION_CODENAME} + if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then + os=${ID_LIKE%% *} + [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + dist=${UBUNTU_CODENAME} + [ -z "$dist" ] && dist=${VERSION_CODENAME} + fi + wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 + chmod +x /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh + rm -f /tmp/script.deb.sh + else + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash fi - wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 - chmod +x /tmp/script.deb.sh - os=$os dist=$dist /tmp/script.deb.sh - rm -f /tmp/script.deb.sh - else - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash fi fi + $PKG_MANAGER install -y speedtest fi - if notInstalled speedtest && notInstalled speedtest-cli; then - sudo $PKG_MANAGER install -y speedtest - fi - if [ -f /usr/local/bin/speedtest ]; then - rm -f /usr/local/bin/speedtest - ln -s /usr/bin/speedtest /usr/local/bin/speedtest - fi - - download /opt mod_pihole https://github.com/arevindh/pi-hole - download $admin_dir admin https://github.com/arevindh/AdminLTE web + download /opt mod_pihole https://github.com/ipitio/pi-hole "" ipitio + download $admin_dir admin https://github.com/ipitio/AdminLTE web if [ -f $curr_wp ]; then if ! cat $curr_wp | grep -q SpeedTest; then cp -af $curr_wp $org_wp diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 90f2d0553a..51c7de2296 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -71,6 +71,7 @@ notInstalled() { mv -f "$out" /var/log/pihole/speedtest.log exit 1 fi + return 1 } @@ -112,11 +113,41 @@ run() { echo "Test Failed!" >/tmp/speedtest_results savetest "$start" "$stop" else - if notInstalled speedtest-cli; then - swaptest speedtest-cli speedtest - else + if notInstalled speedtest; then + local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) + if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then + if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then + echo "Adding speedtest source for RPM..." + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash + fi + elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then + echo "Adding speedtest source for DEB..." + if [ -e /etc/os-release ]; then + . /etc/os-release + local base="ubuntu debian" + local os=${ID} + local dist=${VERSION_CODENAME} + if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then + os=${ID_LIKE%% *} + [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + dist=${UBUNTU_CODENAME} + [ -z "$dist" ] && dist=${VERSION_CODENAME} + fi + wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 + chmod +x /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh + rm -f /tmp/script.deb.sh + else + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash + fi + fi + fi swaptest speedtest speedtest-cli + else + swaptest speedtest-cli speedtest fi + run $1 $((${2:-1} + 1)) fi } @@ -126,7 +157,8 @@ main() { sudo "$0" "$@" exit $? fi - echo "Running test..." + + echo "Running Test..." run $1 # Number of attempts } From 44ffcea463a1cbe459c4961727d5f00b59464bf8 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 22 Feb 2024 00:29:47 -0500 Subject: [PATCH 587/638] oops --- advanced/Scripts/speedtestmod/mod.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index ead8a7fffc..210ce253b9 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -186,8 +186,8 @@ install() { $PKG_MANAGER install -y speedtest fi - download /opt mod_pihole https://github.com/ipitio/pi-hole "" ipitio - download $admin_dir admin https://github.com/ipitio/AdminLTE web + download /opt mod_pihole https://github.com/arevindh/pi-hole + download $admin_dir admin https://github.com/arevindh/AdminLTE web if [ -f $curr_wp ]; then if ! cat $curr_wp | grep -q SpeedTest; then cp -af $curr_wp $org_wp From 45d46568fd4e3792fb407a7929781242d7320e53 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 22 Feb 2024 00:54:45 -0500 Subject: [PATCH 588/638] apt update if notinstalled --- advanced/Scripts/speedtestmod/mod.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 210ce253b9..2a20127dcb 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -139,10 +139,6 @@ install() { local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") - if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - apt-get update - fi - local missingPkgs=() for pkg in "${PKGS[@]}"; do if notInstalled "$pkg"; then @@ -151,6 +147,9 @@ install() { done if [ ${#missingPkgs[@]} -gt 0 ]; then + if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + apt-get update + fi $PKG_MANAGER install -y "${missingPkgs[@]}" fi From 72c4eaab3e59c4281b9749078bc1c64bab50090d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 22 Feb 2024 04:16:57 -0500 Subject: [PATCH 589/638] add only branch --- advanced/Scripts/speedtestmod/mod.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 2a20127dcb..8c5379fa9e 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -20,6 +20,7 @@ setTags() { local path=${1:-} local name=${2:-} local branch="${3:-master}" + if [ ! -z "$path" ]; then cd "$path" git fetch origin $branch:refs/remotes/origin/$branch -q @@ -60,7 +61,7 @@ download() { git config --global --add safe.directory "$dest" git remote -v | grep -q "old" || git remote rename origin old git remote -v | grep -q "origin" && git remote remove origin - git remote add origin "$url" + git remote add -t "$branch" origin "$url" elif [ -d .git/refs/remotes/old ]; then git remote remove origin git remote rename old origin From 90e55333a156273679540313b9dd172e678fb796 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 22 Feb 2024 04:29:53 -0500 Subject: [PATCH 590/638] reorder if --- advanced/Scripts/speedtestmod/mod.sh | 7 ++++--- advanced/Scripts/speedtestmod/speedtest.sh | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 8c5379fa9e..49d758abbc 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -117,14 +117,15 @@ manageHistory() { } notInstalled() { - if [ -x "$(command -v yum)" ] || [ -x "$(command -v dnf)" ]; then - rpm -q "$1" &>/dev/null || return 0 - elif [ -x "$(command -v apt-get)" ]; then + if [ -x "$(command -v apt-get)" ]; then dpkg -s "$1" &>/dev/null || return 0 + elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]; then + rpm -q "$1" &>/dev/null || return 0 else echo "Unsupported package manager!" exit 1 fi + return 1 } diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 51c7de2296..3c8ceee445 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -62,10 +62,10 @@ swaptest() { } notInstalled() { - if [ -x "$(command -v yum)" ] || [ -x "$(command -v dnf)" ]; then - rpm -q "$1" &>/dev/null || return 0 - elif [ -x "$(command -v apt-get)" ]; then + if [ -x "$(command -v apt-get)" ]; then dpkg -s "$1" &>/dev/null || return 0 + elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]; then + rpm -q "$1" &>/dev/null || return 0 else echo "Unsupported package manager!" mv -f "$out" /var/log/pihole/speedtest.log From 06bd889761a892512e0662be24843fe09c13f27f Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:00:41 -0500 Subject: [PATCH 591/638] add librespeed, defer install (#76) * add librespeed, defer install * verbiage --- advanced/Scripts/speedtestmod/mod.sh | 76 +++---- advanced/Scripts/speedtestmod/speedtest.sh | 221 +++++++++++++++++++-- 2 files changed, 233 insertions(+), 64 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 49d758abbc..2dc4299785 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,9 +1,11 @@ #!/bin/bash admin_dir=/var/www/html -curr_wp=/opt/pihole/webpage.sh +opt_dir=/opt/pihole +etc_dir=/etc/pihole +curr_wp=$opt_dir/webpage.sh last_wp=$curr_wp.old org_wp=$curr_wp.org -curr_db=/etc/pihole/speedtest.db +curr_db=$etc_dir/speedtest.db last_db=$curr_db.old db_table="speedtest" @@ -13,7 +15,7 @@ help() { echo "up - update Pi-hole (along with the Mod)" echo "un - remove the mod (including all backups)" echo "db - flush database (restore for a short while after)" - echo "If no option is specified, the Mod will be (re)installed." + echo "If no option is specified, the latest version of the Mod will be (re)installed." } setTags() { @@ -71,7 +73,11 @@ download() { setTags "$dest" "${src:-}" "$branch" git reset --hard origin/"$branch" git checkout -B "$branch" - git branch -u origin/"$branch" + if git rev-parse --verify "$branch" >/dev/null 2>&1; then + git branch -u "origin/$branch" "$branch" + else + git checkout --track "origin/$branch" + fi fi if [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag)" ]; then @@ -95,22 +101,22 @@ manageHistory() { if [ -f $curr_db ] && ! isEmpty $curr_db; then echo "Flushing Database..." mv -f $curr_db $last_db - if [ -f /etc/pihole/last_speedtest ]; then - mv -f /etc/pihole/last_speedtest /etc/pihole/last_speedtest.old + if [ -f $etc_dir/last_speedtest ]; then + mv -f $etc_dir/last_speedtest $etc_dir/last_speedtest.old fi if [ -f /var/log/pihole/speedtest.log ]; then mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old - rm -f /etc/pihole/speedtest.log + rm -f $etc_dir/speedtest.log fi elif [ -f $last_db ]; then echo "Restoring Database..." mv -f $last_db $curr_db - if [ -f /etc/pihole/last_speedtest.old ]; then - mv -f /etc/pihole/last_speedtest.old /etc/pihole/last_speedtest + if [ -f $etc_dir/last_speedtest.old ]; then + mv -f $etc_dir/last_speedtest.old $etc_dir/last_speedtest fi if [ -f /var/log/pihole/speedtest.log.old ]; then mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log - cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log + cp -af /var/log/pihole/speedtest.log $etc_dir/speedtest.log fi fi fi @@ -155,39 +161,7 @@ install() { $PKG_MANAGER install -y "${missingPkgs[@]}" fi - if notInstalled speedtest && notInstalled speedtest-cli; then - if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then - if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then - echo "Adding speedtest source for RPM..." - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash - fi - elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then - echo "Adding speedtest source for DEB..." - if [ -e /etc/os-release ]; then - . /etc/os-release - local base="ubuntu debian" - local os=${ID} - local dist=${VERSION_CODENAME} - if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then - os=${ID_LIKE%% *} - [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) - dist=${UBUNTU_CODENAME} - [ -z "$dist" ] && dist=${VERSION_CODENAME} - fi - wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 - chmod +x /tmp/script.deb.sh - os=$os dist=$dist /tmp/script.deb.sh - rm -f /tmp/script.deb.sh - else - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash - fi - fi - fi - $PKG_MANAGER install -y speedtest - fi - - download /opt mod_pihole https://github.com/arevindh/pi-hole + download $etc_dir mod https://github.com/arevindh/pi-hole download $admin_dir admin https://github.com/arevindh/AdminLTE web if [ -f $curr_wp ]; then if ! cat $curr_wp | grep -q SpeedTest; then @@ -197,8 +171,8 @@ install() { cp -af $curr_wp $last_wp fi fi - cp -af /opt/mod_pihole/advanced/Scripts/webpage.sh $curr_wp - cp -af /opt/mod_pihole/advanced/Scripts/speedtestmod/. /opt/pihole/speedtestmod/ + cp -af $etc_dir/mod/advanced/Scripts/webpage.sh $curr_wp + cp -af $etc_dir/mod/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ chmod +x $curr_wp pihole updatechecker local pihole -a -s @@ -225,6 +199,7 @@ uninstall() { cp -af $org_wp $curr_wp chmod +x $curr_wp rm -rf /opt/mod_pihole + rm -rf $etc_dir/mod pihole updatechecker fi @@ -232,8 +207,8 @@ uninstall() { } purge() { - rm -rf "$admin_dir"*_admin - rm -rf /opt/pihole/speedtestmod + rm -rf "$admin_dir"/*_admin + rm -rf $opt_dir/speedtestmod if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then rm -f /etc/systemd/system/pihole-speedtest.service rm -f /etc/systemd/system/pihole-speedtest.timer @@ -243,7 +218,7 @@ purge() { rm -f "$curr_wp".* rm -f "$curr_db".* rm -f "$curr_db"_* - rm -f /etc/pihole/last_speedtest.* + rm -f $etc_dir/last_speedtest.* if isEmpty $curr_db; then rm -f $curr_db fi @@ -284,7 +259,7 @@ abort() { pihole restartdns aborted=1 - printf "Please try again or try manually.\n\n$(date)\n" + printf "Please try again before reporting an issue.\n\n$(date)\n" } commit() { @@ -306,10 +281,10 @@ main() { sudo "$0" "$@" exit $? fi - aborted=0 set -Eeuo pipefail trap '[ "$?" -eq "0" ] && commit || abort' EXIT trap 'abort' INT TERM + shopt -s dotglob local db=$([ "$op" == "up" ] && echo "${3:-}" || [ "$op" == "un" ] && echo "${2:-}" || echo "$op") case $op in @@ -333,6 +308,7 @@ main() { exit 0 } +aborted=0 rm -f /tmp/pimod.log touch /tmp/pimod.log main "$@" 2>&1 | tee -a /tmp/pimod.log diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 3c8ceee445..a53ed7bdbf 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -21,13 +21,13 @@ speedtest() { if [[ -z "${serverid}" ]]; then /usr/bin/speedtest --accept-gdpr --accept-license -f json else - /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json + /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json fi else if [[ -z "${serverid}" ]]; then /usr/bin/speedtest --json --share --secure else - /usr/bin/speedtest -s $serverid --json --share --secure + /usr/bin/speedtest --server $serverid --json --share --secure || /usr/bin/speedtest --json --share --secure fi fi } @@ -45,19 +45,49 @@ savetest() { local share_url=${10:-"#"} sqlite3 /etc/pihole/speedtest.db "$create_table" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" + + local rm_empty=' + def nonempty: . and length > 0 and (type != "object" or . != {}) and (type != "array" or any(.[]; . != "")); + if type == "array" then map(walk(if type == "object" then with_entries(select(.value | nonempty)) else . end)) else walk(if type == "object" then with_entries(select(.value | nonempty)) else . end) end +' + local temp_file=$(mktemp) + local json_file="/tmp/speedtest_results" + jq "$rm_empty" "$json_file" > "$temp_file" && mv -f "$temp_file" "$json_file" + rm -f "$temp_file" mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log rm -f "$out" [ "$isp" == "No Internet" ] && exit 1 || exit 0 } -swaptest() { +isAvailable() { if [ -x "$(command -v apt-get)" ]; then - apt-get install -y $1 $2- - elif [ -x "$(command -v dnf)" ]; then - dnf install -y --allowerasing $1 + # Check if there is a candidate and it is not "(none)" + if apt-cache policy "$1" | grep -q "Candidate:" && ! apt-cache policy "$1" | grep -q "Candidate: (none)"; then + return 0 + fi + elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]; then + local PKG_MANAGER=$(command -v dnf || command -v yum) + if $PKG_MANAGER list available "$1" &>/dev/null; then + return 0 + fi else - yum install -y --allowerasing $1 + echo "Unsupported package manager!" + exit 1 + fi + + return 1 +} + +swaptest() { + if isAvailable $1; then + if [ -x "$(command -v apt-get)" ]; then + apt-get install -y $1 $2- + elif [ -x "$(command -v dnf)" ]; then + dnf install -y --allowerasing $1 + else + yum install -y --allowerasing $1 + fi fi } @@ -75,10 +105,103 @@ notInstalled() { return 1 } +setTags() { + local path=${1:-} + local name=${2:-} + local branch="${3:-master}" + + if [ ! -z "$path" ]; then + cd "$path" + git fetch origin $branch:refs/remotes/origin/$branch -q + git fetch --tags -f -q + latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) + fi + if [ ! -z "$name" ]; then + localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 6) + if [ "$localTag" == "HEAD" ]; then + localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 7) + fi + fi +} + +download() { + local path=$1 + local name=$2 + local url=$3 + local src=${4:-} + local branch="${5:-master}" + local dest=$path/$name + + if [ ! -d "$dest" ]; then # replicate + cd "$path" + rm -rf "$name" + git clone --depth=1 -b "$branch" "$url" "$name" + setTags "$name" "${src:-}" "$branch" + if [ ! -z "$src" ]; then + if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then + latestTag=$localTag + git fetch --unshallow + fi + fi + else # replace + cd "$dest" + if [ ! -z "$src" ]; then + if [ "$url" != "old" ]; then + git config --global --add safe.directory "$dest" + git remote -v | grep -q "old" || git remote rename origin old + git remote -v | grep -q "origin" && git remote remove origin + git remote add -t "$branch" origin "$url" + elif [ -d .git/refs/remotes/old ]; then + git remote remove origin + git remote rename old origin + git clean -ffdx + fi + fi + setTags "$dest" "${src:-}" "$branch" + git reset --hard origin/"$branch" + git checkout -B "$branch" + if git rev-parse --verify "$branch" >/dev/null 2>&1; then + git branch -u "origin/$branch" "$branch" + else + git checkout --track "origin/$branch" + fi + fi + + if [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag)" ]; then + git -c advice.detachedHead=false checkout "$latestTag" + fi + cd .. +} + +librespeed() { + if notInstalled golang; then + if grep -q "Raspbian" /etc/os-release; then + if [ ! -f /etc/apt/sources.list.d/testing.list ] && ! grep -q "testing" /etc/apt/sources.list; then + echo "Adding testing repo to sources.list.d" + echo "deb http://archive.raspbian.org/raspbian/ testing main" >/etc/apt/sources.list.d/testing.list + echo "Package: *\nPin: release a=testing\nPin-Priority: 50" >/etc/apt/preferences.d/limit-testing + $PKG_MANAGER update + fi + + $PKG_MANAGER install -y -t testing golang + else + $PKG_MANAGER install -y golang + fi + fi + download /etc/pihole librespeed https://github.com/librespeed/speedtest-cli + cd librespeed + if [ -d out ]; then + rm -rf out + fi + ./build.sh + mv -f out/* /usr/bin/speedtest + chmod +x /usr/bin/speedtest +} + run() { speedtest | jq . >/tmp/speedtest_results || echo "Attempt ${2:-1} Failed!" >/tmp/speedtest_results local stop=$(date -u --rfc-3339='seconds') - if jq -e '.server.id' /tmp/speedtest_results &>/dev/null; then + if jq -e '.server' /tmp/speedtest_results &>/dev/null; then local res=$(/dev/null; then # librespeed + local res=$(/tmp/speedtest_results savetest "$start" "$stop" else - if notInstalled speedtest; then - local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) + if notInstalled speedtest && notInstalled speedtest-cli; then + if [ -f /usr/bin/speedtest ]; then + rm -f /usr/bin/speedtest + fi + if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then echo "Adding speedtest source for RPM..." curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash fi + + if yum list speedtest | grep -q "Available Packages"; then + $PKG_MANAGER install -y speedtest + fi elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then echo "Adding speedtest source for DEB..." @@ -141,14 +282,23 @@ run() { else curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash fi + + sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list + apt-get update + fi + + if isAvailable speedtest; then + $PKG_MANAGER install -y speedtest fi fi - swaptest speedtest speedtest-cli - else + elif ! notInstalled speedtest; then swaptest speedtest-cli speedtest + else + $PKG_MANAGER remove -y speedtest-cli + librespeed fi - run $1 $((${2:-1} + 1)) + run $1 $((${2:-0} + 1)) fi } @@ -158,6 +308,49 @@ main() { exit $? fi + PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) + if [ ! -f /usr/bin/speedtest ]; then + if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then + if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then + echo "Adding speedtest source for RPM..." + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash + fi + elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then + echo "Adding speedtest source for DEB..." + if [ -e /etc/os-release ]; then + . /etc/os-release + local base="ubuntu debian" + local os=${ID} + local dist=${VERSION_CODENAME} + if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then + os=${ID_LIKE%% *} + [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + dist=${UBUNTU_CODENAME} + [ -z "$dist" ] && dist=${VERSION_CODENAME} + fi + wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 + chmod +x /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh + rm -f /tmp/script.deb.sh + else + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash + fi + + sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list + apt-get update + fi + fi + + if isAvailable speedtest; then + $PKG_MANAGER install -y speedtest + elif isAvailable speedtest-cli; then + $PKG_MANAGER install -y speedtest-cli + else + librespeed + fi + fi + echo "Running Test..." run $1 # Number of attempts } From a666084057073d2b93c75b4175c4217759fce991 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 28 Feb 2024 04:17:31 -0500 Subject: [PATCH 592/638] fix perm (#77) * allow speedtest log to be read --- advanced/Scripts/speedtestmod/speedtest.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index a53ed7bdbf..70163669bd 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -54,6 +54,7 @@ savetest() { local json_file="/tmp/speedtest_results" jq "$rm_empty" "$json_file" > "$temp_file" && mv -f "$temp_file" "$json_file" rm -f "$temp_file" + chmod 644 /tmp/speedtest_results mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log rm -f "$out" From 37e2a00786725f30731e59c48805f2eab9f6a908 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 28 Feb 2024 04:44:50 -0500 Subject: [PATCH 593/638] uninstall first (#78) * allow switching between any remotes --- advanced/Scripts/speedtestmod/mod.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 2dc4299785..b22e214c26 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -301,6 +301,7 @@ main() { install ;; *) + uninstall install manageHistory $db ;; From 598d8f06398afecace0b89095fba56879a1cfd0d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 29 Feb 2024 01:07:46 -0500 Subject: [PATCH 594/638] check version (#79) * check version --- advanced/Scripts/piholeDebug.sh | 3 +++ advanced/Scripts/speedtestmod/mod.sh | 3 +++ advanced/Scripts/updatecheck.sh | 22 ++++++++++++++++++++-- advanced/Scripts/version.sh | 6 ++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index fb1efbebc3..4ee733ea4e 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -72,6 +72,7 @@ HTML_DIRECTORY="/var/www/html" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" SHM_DIRECTORY="/dev/shm" ETC="/etc" +SPEEDTEST_GIT_DIRECTORY="/etc/pihole/speedtest" # Files required by Pi-hole # https://discourse.pi-hole.net/t/what-files-does-pi-hole-use/1684 @@ -345,6 +346,8 @@ check_component_versions() { compare_local_version_to_git_version "${CORE_GIT_DIRECTORY}" "Core" # Check the Web version, branch, and commit compare_local_version_to_git_version "${WEB_GIT_DIRECTORY}" "Web" + # Check the Speedtest version, branch, and commit + compare_local_version_to_git_version "${SPEEDTEST_GIT_DIRECTORY}" "Speedtest" # Check the FTL version check_ftl_version } diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index b22e214c26..30e46246bf 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -161,6 +161,7 @@ install() { $PKG_MANAGER install -y "${missingPkgs[@]}" fi + download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest download $etc_dir mod https://github.com/arevindh/pi-hole download $admin_dir admin https://github.com/arevindh/AdminLTE web if [ -f $curr_wp ]; then @@ -209,6 +210,8 @@ uninstall() { purge() { rm -rf "$admin_dir"/*_admin rm -rf $opt_dir/speedtestmod + rm -rf $etc_dir/speedtest + rm -rf $etc_dir/mod if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then rm -f /etc/systemd/system/pihole-speedtest.service rm -f /etc/systemd/system/pihole-speedtest.timer diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 8ce69a7575..2e2d0d1290 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -26,12 +26,12 @@ function get_local_hash() { } function get_remote_version() { - curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 + curl -s "https://api.github.com/repos/arevindh/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || { curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1; } } function get_remote_hash(){ - git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || return 1 + git ls-remote "https://github.com/arevindh/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || { git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || return 1; } } # Source the setupvars config file @@ -131,3 +131,21 @@ if [[ "${DOCKER_TAG}" ]]; then GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi + + +# get Speedtest versions + +SPEEDTEST_VERSION="$(get_local_version /etc/pihole/speedtest)" +addOrEditKeyValPair "${VERSION_FILE}" "SPEEDTEST_VERSION" "${SPEEDTEST_VERSION}" + +SPEEDTEST_BRANCH="$(get_local_branch /etc/pihole/speedtest)" +addOrEditKeyValPair "${VERSION_FILE}" "SPEEDTEST_BRANCH" "${SPEEDTEST_BRANCH}" + +SPEEDTEST_HASH="$(get_local_hash /etc/pihole/speedtest)" +addOrEditKeyValPair "${VERSION_FILE}" "SPEEDTEST_HASH" "${SPEEDTEST_HASH}" + +GITHUB_SPEEDTEST_VERSION="$(get_remote_version pihole-speedtest)" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_SPEEDTEST_VERSION" "${GITHUB_SPEEDTEST_VERSION}" + +GITHUB_SPEEDTEST_HASH="$(get_remote_hash pihole-speedtest "${SPEEDTEST_BRANCH}")" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_SPEEDTEST_HASH" "${GITHUB_SPEEDTEST_HASH}" diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 83fd0f39ac..6c5001cfe2 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -30,6 +30,7 @@ getLocalVersion() { "Pi-hole" ) echo "${CORE_VERSION:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION:=N/A}";; "FTL" ) echo "${FTL_VERSION:=N/A}";; + "speedtest" ) echo "${SPEEDTEST_VERSION:=N/A}";; esac } @@ -38,6 +39,7 @@ getLocalHash() { "Pi-hole" ) echo "${CORE_HASH:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH:=N/A}";; "FTL" ) echo "${FTL_HASH:=N/A}";; + "speedtest" ) echo "${SPEEDTEST_HASH:=N/A}";; esac } @@ -46,6 +48,7 @@ getRemoteHash(){ "Pi-hole" ) echo "${GITHUB_CORE_HASH:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH:=N/A}";; "FTL" ) echo "${GITHUB_FTL_HASH:=N/A}";; + "speedtest" ) echo "${GITHUB_SPEEDTEST_HASH:=N/A}";; esac } @@ -54,6 +57,7 @@ getRemoteVersion(){ "Pi-hole" ) echo "${GITHUB_CORE_VERSION:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION:=N/A}";; "FTL" ) echo "${GITHUB_FTL_VERSION:=N/A}";; + "speedtest" ) echo "${GITHUB_SPEEDTEST_VERSION:=N/A}";; esac } @@ -132,6 +136,7 @@ Repositories: -p, --pihole Only retrieve info regarding Pi-hole repository -a, --admin Only retrieve info regarding web repository -f, --ftl Only retrieve info regarding FTL repository + -s, --speedtest Only retrieve info regarding Speedtest repository Options: -c, --current Return the current version @@ -145,6 +150,7 @@ case "${1}" in "-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";; "-a" | "--admin" ) shift; versionOutput "web" "$@";; "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; + "-s" | "--speedtest" ) shift; versionOutput "speedtest" "$@";; "-h" | "--help" ) helpFunc;; * ) defaultOutput "$@";; esac From df893c72b350eb2f07ca14d8e1e0d99347ca2da0 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 29 Feb 2024 01:37:12 -0500 Subject: [PATCH 595/638] add safe (#80) * patch version check --- advanced/Scripts/speedtestmod/mod.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 30e46246bf..fe8f836bdd 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -49,6 +49,7 @@ download() { cd "$path" rm -rf "$name" git clone --depth=1 -b "$branch" "$url" "$name" + git config --global --add safe.directory "$path"/"$name" setTags "$name" "${src:-}" "$branch" if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then @@ -57,10 +58,10 @@ download() { fi fi else # replace + git config --global --add safe.directory "$dest" cd "$dest" if [ ! -z "$src" ]; then if [ "$url" != "old" ]; then - git config --global --add safe.directory "$dest" git remote -v | grep -q "old" || git remote rename origin old git remote -v | grep -q "origin" && git remote remove origin git remote add -t "$branch" origin "$url" From a072f204303e4020311359df987b0c91ce0ee316 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 1 Mar 2024 02:20:26 -0500 Subject: [PATCH 596/638] fix getting version (#81) --- advanced/Scripts/speedtestmod/mod.sh | 80 +++++++++------------- advanced/Scripts/speedtestmod/speedtest.sh | 7 +- advanced/Scripts/updatecheck.sh | 2 +- advanced/Scripts/version.sh | 12 ++-- advanced/Scripts/webpage.sh | 73 ++++++++++++++++++++ 5 files changed, 119 insertions(+), 55 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index fe8f836bdd..de29f5c38f 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,10 +1,9 @@ #!/bin/bash admin_dir=/var/www/html +core_dir=/etc/.pihole opt_dir=/opt/pihole etc_dir=/etc/pihole curr_wp=$opt_dir/webpage.sh -last_wp=$curr_wp.old -org_wp=$curr_wp.org curr_db=$etc_dir/speedtest.db last_db=$curr_db.old db_table="speedtest" @@ -49,7 +48,7 @@ download() { cd "$path" rm -rf "$name" git clone --depth=1 -b "$branch" "$url" "$name" - git config --global --add safe.directory "$path"/"$name" + git config --global --add safe.directory "$dest" setTags "$name" "${src:-}" "$branch" if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then @@ -136,7 +135,7 @@ notInstalled() { return 1 } -install() { +installMod() { echo "Installing Mod..." if [ ! -f /usr/local/bin/pihole ]; then @@ -162,47 +161,32 @@ install() { $PKG_MANAGER install -y "${missingPkgs[@]}" fi + download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole + SKIP_INSTALL=true + source "$core_dir/automated install/basic-install.sh" + installScripts + cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest - download $etc_dir mod https://github.com/arevindh/pi-hole download $admin_dir admin https://github.com/arevindh/AdminLTE web - if [ -f $curr_wp ]; then - if ! cat $curr_wp | grep -q SpeedTest; then - cp -af $curr_wp $org_wp - fi - if [ ! -f $last_wp ]; then - cp -af $curr_wp $last_wp - fi - fi - cp -af $etc_dir/mod/advanced/Scripts/webpage.sh $curr_wp - cp -af $etc_dir/mod/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ - chmod +x $curr_wp - pihole updatechecker local pihole -a -s + pihole updatechecker } uninstall() { if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then echo "Restoring Pi-hole..." - if [ ! -f $org_wp ]; then - if [ ! -d /opt/org_pihole ]; then - download /opt org_pihole https://github.com/pi-hole/pi-hole Pi-hole - fi - cd /opt - cp -af org_pihole/advanced/Scripts/webpage.sh $org_wp - rm -rf org_pihole - fi - pihole -a -s -1 - download $admin_dir admin https://github.com/pi-hole/AdminLTE web - if [ ! -f $last_wp ]; then - cp -af $curr_wp $last_wp + if [ ! -d $core_dir/.git ]; then + mv -f $core_dir $core_dir.old fi - cp -af $org_wp $curr_wp - chmod +x $curr_wp - rm -rf /opt/mod_pihole - rm -rf $etc_dir/mod - pihole updatechecker + download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole + download $admin_dir admin https://github.com/pi-hole/AdminLTE web + + SKIP_INSTALL=true + source "$core_dir/automated install/basic-install.sh" + installScripts fi manageHistory ${1:-} @@ -246,19 +230,19 @@ update() { abort() { echo "Process Aborting..." - if [ -f $last_wp ]; then - cp -af $last_wp $curr_wp - chmod +x $curr_wp - rm -f $last_wp + if [ -d $admin_dir/admin/.git/refs/remotes/old ]; then + download $admin_dir admin old web fi - if [ -f $last_db ] && [ ! -f $curr_db ]; then - mv $last_db $curr_db + if [ -d $core_dir/.git/refs/remotes/old ]; then + download /etc .pihole old Pi-hole + source "$core_dir/automated install/basic-install.sh" + installScripts fi if [ ! -f $curr_wp ] || ! cat $curr_wp | grep -q SpeedTest; then purge fi - if [ -d $admin_dir/admin/.git/refs/remotes/old ]; then - download $admin_dir admin old web + if [ -f $last_db ] && [ ! -f $curr_db ]; then + mv $last_db $curr_db fi pihole restartdns @@ -267,9 +251,10 @@ abort() { } commit() { + cd $core_dir + git remote -v | grep -q "old" && git remote remove old cd $admin_dir/admin git remote -v | grep -q "old" && git remote remove old - rm -f $last_wp pihole restartdns printf "Done!\n\n$(date)\n" } @@ -285,7 +270,7 @@ main() { sudo "$0" "$@" exit $? fi - set -Eeuo pipefail + set -Eeo pipefail trap '[ "$?" -eq "0" ] && commit || abort' EXIT trap 'abort' INT TERM shopt -s dotglob @@ -302,12 +287,11 @@ main() { up) uninstall $db update ${2:-} - install + installMod ;; *) - uninstall - install - manageHistory $db + uninstall $db + installMod ;; esac exit 0 diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 70163669bd..1008e508cf 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -137,6 +137,7 @@ download() { cd "$path" rm -rf "$name" git clone --depth=1 -b "$branch" "$url" "$name" + git config --global --add safe.directory "$dest" setTags "$name" "${src:-}" "$branch" if [ ! -z "$src" ]; then if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then @@ -145,10 +146,10 @@ download() { fi fi else # replace + git config --global --add safe.directory "$dest" cd "$dest" if [ ! -z "$src" ]; then if [ "$url" != "old" ]; then - git config --global --add safe.directory "$dest" git remote -v | grep -q "old" || git remote rename origin old git remote -v | grep -q "origin" && git remote remove origin git remote add -t "$branch" origin "$url" @@ -309,6 +310,10 @@ main() { exit $? fi + if [ ! -d /etc/pihole/speedtest ]; then + download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest + fi + PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) if [ ! -f /usr/bin/speedtest ]; then if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 2e2d0d1290..93b1d95b0c 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -17,7 +17,7 @@ function get_local_branch() { function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - git describe --tags --always 2> /dev/null || return 1 + git tag --sort=-version:refname | head -n 1 || return 1 } function get_local_hash() { diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 6c5001cfe2..cc76ba3155 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -30,7 +30,7 @@ getLocalVersion() { "Pi-hole" ) echo "${CORE_VERSION:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION:=N/A}";; "FTL" ) echo "${FTL_VERSION:=N/A}";; - "speedtest" ) echo "${SPEEDTEST_VERSION:=N/A}";; + "Speedtest" ) echo "${SPEEDTEST_VERSION:=N/A}";; esac } @@ -39,7 +39,7 @@ getLocalHash() { "Pi-hole" ) echo "${CORE_HASH:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH:=N/A}";; "FTL" ) echo "${FTL_HASH:=N/A}";; - "speedtest" ) echo "${SPEEDTEST_HASH:=N/A}";; + "Speedtest" ) echo "${SPEEDTEST_HASH:=N/A}";; esac } @@ -48,7 +48,7 @@ getRemoteHash(){ "Pi-hole" ) echo "${GITHUB_CORE_HASH:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH:=N/A}";; "FTL" ) echo "${GITHUB_FTL_HASH:=N/A}";; - "speedtest" ) echo "${GITHUB_SPEEDTEST_HASH:=N/A}";; + "Speedtest" ) echo "${GITHUB_SPEEDTEST_HASH:=N/A}";; esac } @@ -57,7 +57,7 @@ getRemoteVersion(){ "Pi-hole" ) echo "${GITHUB_CORE_VERSION:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION:=N/A}";; "FTL" ) echo "${GITHUB_FTL_VERSION:=N/A}";; - "speedtest" ) echo "${GITHUB_SPEEDTEST_VERSION:=N/A}";; + "Speedtest" ) echo "${GITHUB_SPEEDTEST_VERSION:=N/A}";; esac } @@ -66,6 +66,7 @@ getLocalBranch(){ "Pi-hole" ) echo "${CORE_BRANCH:=N/A}";; "web" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH:=N/A}";; "FTL" ) echo "${FTL_BRANCH:=N/A}";; + "Speedtest" ) echo "${SPEEDTEST_BRANCH:=N/A}";; esac } @@ -125,6 +126,7 @@ defaultOutput() { fi versionOutput "FTL" "$@" + versionOutput "Speedtest" "$@" } helpFunc() { @@ -150,7 +152,7 @@ case "${1}" in "-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";; "-a" | "--admin" ) shift; versionOutput "web" "$@";; "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; - "-s" | "--speedtest" ) shift; versionOutput "speedtest" "$@";; + "-s" | "--speedtest" ) shift; versionOutput "Speedtest" "$@";; "-h" | "--help" ) helpFunc;; * ) defaultOutput "$@";; esac diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 14b8341ecb..90f1f6cbec 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -620,6 +620,79 @@ interval_seconds=$total_seconds schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") +setTags() { + local path=\${1:-} + local name=\${2:-} + local branch="\${3:-master}" + + if [ ! -z "\$path" ]; then + cd "\$path" + git fetch origin \$branch:refs/remotes/origin/\$branch -q + git fetch --tags -f -q + latestTag=\$(git describe --tags \$(git rev-list --tags --max-count=1)) + fi + if [ ! -z "\$name" ]; then + localTag=\$(pihole -v | grep "\$name" | cut -d ' ' -f 6) + if [ "\$localTag" == "HEAD" ]; then + localTag=\$(pihole -v | grep "\$name" | cut -d ' ' -f 7) + fi + fi +} + +download() { + local path=\$1 + local name=\$2 + local url=\$3 + local src=\${4:-} + local branch="\${5:-master}" + local dest=\$path/\$name + + if [ ! -d "\$dest" ]; then # replicate + cd "\$path" + rm -rf "\$name" + git clone --depth=1 -b "\$branch" "\$url" "\$name" + git config --global --add safe.directory "\$dest" + setTags "\$name" "\${src:-}" "\$branch" + if [ ! -z "\$src" ]; then + if [[ "\$localTag" == *.* ]] && [[ "\$localTag" < "\$latestTag" ]]; then + latestTag=\$localTag + git fetch --unshallow + fi + fi + else # replace + git config --global --add safe.directory "\$dest" + cd "\$dest" + if [ ! -z "\$src" ]; then + if [ "\$url" != "old" ]; then + git remote -v | grep -q "old" || git remote rename origin old + git remote -v | grep -q "origin" && git remote remove origin + git remote add -t "\$branch" origin "\$url" + elif [ -d .git/refs/remotes/old ]; then + git remote remove origin + git remote rename old origin + git clean -ffdx + fi + fi + setTags "\$dest" "\${src:-}" "\$branch" + git reset --hard origin/"\$branch" + git checkout -B "\$branch" + if git rev-parse --verify "\$branch" >/dev/null 2>&1; then + git branch -u "origin/\$branch" "\$branch" + else + git checkout --track "origin/\$branch" + fi + fi + + if [ "$(git rev-parse HEAD)" != "$(git rev-parse \$latestTag)" ]; then + git -c advice.detachedHead=false checkout "\$latestTag" + fi + cd .. +} + +if [ ! -d /etc/pihole/speedtest ]; then + download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest +fi + # if schedule is set and interval is "nan", set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then From 1493a90e443d7fe7028bccac98597216912e94cc Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Fri, 1 Mar 2024 03:06:52 -0500 Subject: [PATCH 597/638] no vdev (#82) --- advanced/Scripts/updatecheck.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 93b1d95b0c..3b9c649ad9 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -17,7 +17,11 @@ function get_local_branch() { function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - git tag --sort=-version:refname | head -n 1 || return 1 + local local_v=$(git tag --sort=-version:refname | head -n 1) + if [[ "${local_v}" == "vDev" ]]; then + local_v=$(git tag --sort=-version:refname | head -n 2 | tail -n 1) + fi + echo "${local_v}" || return 1 } function get_local_hash() { From cb3e448b385672f4abb8dbfb78dd0fbb063ac59e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:18:47 +0000 Subject: [PATCH 598/638] Bump pytest from 8.0.0 to 8.0.2 in /test Bumps [pytest](https://github.com/pytest-dev/pytest) from 8.0.0 to 8.0.2. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/8.0.0...8.0.2) --- updated-dependencies: - dependency-name: pytest dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index a6826838da..bf9827ad00 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,5 +1,5 @@ pyyaml == 6.0.1 -pytest == 8.0.0 +pytest == 8.0.2 pytest-xdist == 3.5.0 pytest-testinfra == 10.0.0 tox == 4.13.0 From 0fdd959c7f751d40d9e3fd5947612478f7a5c643 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:52:21 +0000 Subject: [PATCH 599/638] Bump pytest-testinfra from 10.0.0 to 10.1.0 in /test Bumps [pytest-testinfra](https://github.com/pytest-dev/pytest-testinfra) from 10.0.0 to 10.1.0. - [Release notes](https://github.com/pytest-dev/pytest-testinfra/releases) - [Changelog](https://github.com/pytest-dev/pytest-testinfra/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest-testinfra/compare/10.0.0...10.1.0) --- updated-dependencies: - dependency-name: pytest-testinfra dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index bf9827ad00..ffb05813f3 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,6 @@ pyyaml == 6.0.1 pytest == 8.0.2 pytest-xdist == 3.5.0 -pytest-testinfra == 10.0.0 +pytest-testinfra == 10.1.0 tox == 4.13.0 From 0a1256693b91ea0188b2d4b72c987c015143143c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:37:39 -0500 Subject: [PATCH 600/638] fix uninstall (#83) --- advanced/Scripts/speedtestmod/mod.sh | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index de29f5c38f..dbbb327a26 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -7,6 +7,7 @@ curr_wp=$opt_dir/webpage.sh curr_db=$etc_dir/speedtest.db last_db=$curr_db.old db_table="speedtest" +SKIP_INSTALL=true help() { echo "(Re)install Latest Speedtest Mod." @@ -56,6 +57,9 @@ download() { git fetch --unshallow fi fi + elif [ ! -d "$dest/.git" ]; then + mv -f "$dest" "$dest.old" + download "$@" else # replace git config --global --add safe.directory "$dest" cd "$dest" @@ -80,8 +84,15 @@ download() { fi fi - if [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag)" ]; then - git -c advice.detachedHead=false checkout "$latestTag" + # Checkout the last tag before/at HEAD or latest tag if the branch is master + if [ "$branch" == "master" ]; then + if ! last_tag_before_head=$(git describe --tags --abbrev=0 HEAD 2>/dev/null); then + last_tag_before_head=$latestTag + fi + + if [ "$(git rev-parse HEAD)" != "$(git rev-parse $last_tag_before_head 2>/dev/null)" ]; then + git -c advice.detachedHead=false checkout "$last_tag_before_head" + fi fi cd .. } @@ -162,13 +173,12 @@ installMod() { fi download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole - SKIP_INSTALL=true + download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest + download $admin_dir admin https://github.com/arevindh/AdminLTE web + source "$core_dir/automated install/basic-install.sh" installScripts cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ - - download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest - download $admin_dir admin https://github.com/arevindh/AdminLTE web pihole -a -s pihole updatechecker } @@ -178,13 +188,8 @@ uninstall() { echo "Restoring Pi-hole..." pihole -a -s -1 - if [ ! -d $core_dir/.git ]; then - mv -f $core_dir $core_dir.old - fi download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole download $admin_dir admin https://github.com/pi-hole/AdminLTE web - - SKIP_INSTALL=true source "$core_dir/automated install/basic-install.sh" installScripts fi From 9dd138b03348f24a001d60f27e29c8c62af28871 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 4 Mar 2024 19:38:13 +0100 Subject: [PATCH 601/638] Only use local files (file://) when they have explicit permissions a+r Signed-off-by: DL6ER --- gravity.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 62631e3c26..86c7fc2381 100755 --- a/gravity.sh +++ b/gravity.sh @@ -503,6 +503,7 @@ compareLists() { gravity_DownloadBlocklistFromUrl() { local url="${1}" adlistID="${2}" saveLocation="${3}" target="${4}" compression="${5}" local heisenbergCompensator="" listCurlBuffer str httpCode success="" ip cmd_ext + local file_path permissions ip_addr port blocked=false download=true # Create temp file to store content on disk instead of RAM # We don't use '--suffix' here because not all implementations of mktemp support it, e.g. on Alpine @@ -519,7 +520,6 @@ gravity_DownloadBlocklistFromUrl() { str="Status:" echo -ne " ${INFO} ${str} Pending..." - blocked=false case $BLOCKINGMODE in "IP-NODATA-AAAA"|"IP") # Get IP address of this domain @@ -560,8 +560,36 @@ gravity_DownloadBlocklistFromUrl() { cmd_ext="--resolve $domain:$port:$ip" fi - # shellcheck disable=SC2086 - httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" "${url}" -o "${listCurlBuffer}" 2> /dev/null) + # If we are going to "download" a local file, we first check if the target + # file has a+r permission. We explicitly check for all+read because we want + # to make sure that the file is readable by everyone and not just the user + # running the script. + if [[ $url == "file://"* ]]; then + # Get the file path + file_path=$(echo "$url" | cut -d'/' -f3-) + # Check if the file exists + if [[ ! -e $file_path ]]; then + # Output that the file does not exist + echo -e "${OVER} ${CROSS} ${file_path} does not exist" + download=false + else + # Check if the file has a+r permissions + permissions=$(stat -c "%a" "$file_path") + if [[ $permissions == "??4" || $permissions == "??5" || $permissions == "??6" || $permissions == "??7" ]]; then + # Output that we are using the local file + echo -e "${OVER} ${INFO} Using local file ${file_path}" + else + # Output that the file does not have the correct permissions + echo -e "${OVER} ${CROSS} Cannot read file (file needs to have a+r permission)" + download=false + fi + fi + fi + + if [[ "${download}" == true ]]; then + # shellcheck disable=SC2086 + httpCode=$(curl --connect-timeout ${curl_connect_timeout} -s -L ${compression} ${cmd_ext} ${heisenbergCompensator} -w "%{http_code}" "${url}" -o "${listCurlBuffer}" 2> /dev/null) + fi case $url in # Did we "download" a local file? @@ -569,7 +597,7 @@ gravity_DownloadBlocklistFromUrl() { if [[ -s "${listCurlBuffer}" ]]; then echo -e "${OVER} ${TICK} ${str} Retrieval successful"; success=true else - echo -e "${OVER} ${CROSS} ${str} Not found / empty list" + echo -e "${OVER} ${CROSS} ${str} Retrieval failed / empty list" fi;; # Did we "download" a remote file? *) From 1ec3542eb23ecbc6e408302675be0c0b5879e16c Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:44:32 -0500 Subject: [PATCH 602/638] fix uninstall when there's a new pi-hole release (#84) --- advanced/Scripts/speedtestmod/mod.sh | 96 ++++++++++++++-------- advanced/Scripts/speedtestmod/speedtest.sh | 74 +---------------- advanced/Scripts/updatecheck.sh | 8 +- advanced/Scripts/webpage.sh | 70 +--------------- 4 files changed, 76 insertions(+), 172 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index dbbb327a26..9ba7d90f7e 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -7,21 +7,21 @@ curr_wp=$opt_dir/webpage.sh curr_db=$etc_dir/speedtest.db last_db=$curr_db.old db_table="speedtest" -SKIP_INSTALL=true help() { echo "(Re)install Latest Speedtest Mod." echo "Usage: sudo $0 [up] [un] [db]" - echo "up - update Pi-hole (along with the Mod)" - echo "un - remove the mod (including all backups)" - echo "db - flush database (restore for a short while after)" + echo "up - update the mod (and Pi-hole if not in Docker)" + echo "un - remove the mod (and any database backups)" + echo "db - flush the database (if it's not empty, otherwise restore it)" echo "If no option is specified, the latest version of the Mod will be (re)installed." } setTags() { local path=${1:-} local name=${2:-} - local branch="${3:-master}" + local url=${3:-} + local branch="${4:-master}" if [ ! -z "$path" ]; then cd "$path" @@ -29,11 +29,21 @@ setTags() { git fetch --tags -f -q latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) fi - if [ ! -z "$name" ]; then - localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 6) + + if [[ "$url" != *"arevindh"* ]] && [ ! -z "$name" ]; then + local localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 6) + if [ "$localTag" == "HEAD" ]; then localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 7) fi + + if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then + latestTag=$localTag + + if [ -f "$(git rev-parse --git-dir)"/shallow ]; then + git fetch --unshallow + fi + fi fi } @@ -50,19 +60,14 @@ download() { rm -rf "$name" git clone --depth=1 -b "$branch" "$url" "$name" git config --global --add safe.directory "$dest" - setTags "$name" "${src:-}" "$branch" - if [ ! -z "$src" ]; then - if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then - latestTag=$localTag - git fetch --unshallow - fi - fi + setTags "$name" "$src" "$url" "$branch" elif [ ! -d "$dest/.git" ]; then mv -f "$dest" "$dest.old" download "$@" else # replace git config --global --add safe.directory "$dest" cd "$dest" + if [ ! -z "$src" ]; then if [ "$url" != "old" ]; then git remote -v | grep -q "old" || git remote rename origin old @@ -74,9 +79,11 @@ download() { git clean -ffdx fi fi - setTags "$dest" "${src:-}" "$branch" + + setTags "$dest" "$src" "$url" "$branch" git reset --hard origin/"$branch" git checkout -B "$branch" + if git rev-parse --verify "$branch" >/dev/null 2>&1; then git branch -u "origin/$branch" "$branch" else @@ -84,14 +91,18 @@ download() { fi fi - # Checkout the last tag before/at HEAD or latest tag if the branch is master - if [ "$branch" == "master" ]; then - if ! last_tag_before_head=$(git describe --tags --abbrev=0 HEAD 2>/dev/null); then - last_tag_before_head=$latestTag + if [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]]; then + # Get last tag before/at $latestTag installed + last_tag_before_current=$(git tag -l | grep '^v' | grep -v 'vDev' | sort -V | awk -v latestTag="$latestTag" '$1 <= latestTag' | tail -n1) + + # If no such tag is found, fall back to $latestTag + if [ -z "$last_tag_before_current" ]; then + last_tag_before_current=$latestTag fi - if [ "$(git rev-parse HEAD)" != "$(git rev-parse $last_tag_before_head 2>/dev/null)" ]; then - git -c advice.detachedHead=false checkout "$last_tag_before_head" + # Check if HEAD is already at this tag, if not, check out the tag + if [ "$(git rev-parse HEAD)" != "$(git rev-parse $last_tag_before_current 2>/dev/null)" ]; then + git -c advice.detachedHead=false checkout "$last_tag_before_current" fi fi cd .. @@ -112,9 +123,11 @@ manageHistory() { if [ -f $curr_db ] && ! isEmpty $curr_db; then echo "Flushing Database..." mv -f $curr_db $last_db + if [ -f $etc_dir/last_speedtest ]; then mv -f $etc_dir/last_speedtest $etc_dir/last_speedtest.old fi + if [ -f /var/log/pihole/speedtest.log ]; then mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old rm -f $etc_dir/speedtest.log @@ -122,9 +135,11 @@ manageHistory() { elif [ -f $last_db ]; then echo "Restoring Database..." mv -f $last_db $curr_db + if [ -f $etc_dir/last_speedtest.old ]; then mv -f $etc_dir/last_speedtest.old $etc_dir/last_speedtest fi + if [ -f /var/log/pihole/speedtest.log.old ]; then mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log cp -af /var/log/pihole/speedtest.log $etc_dir/speedtest.log @@ -146,6 +161,14 @@ notInstalled() { return 1 } +swapScripts() { + SKIP_INSTALL=true + set +u + source "$core_dir/automated install/basic-install.sh" + installScripts + set -u +} + installMod() { echo "Installing Mod..." @@ -169,6 +192,7 @@ installMod() { if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then apt-get update fi + $PKG_MANAGER install -y "${missingPkgs[@]}" fi @@ -176,8 +200,7 @@ installMod() { download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest download $admin_dir admin https://github.com/arevindh/AdminLTE web - source "$core_dir/automated install/basic-install.sh" - installScripts + swapScripts cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s pihole updatechecker @@ -190,8 +213,7 @@ uninstall() { pihole -a -s -1 download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole download $admin_dir admin https://github.com/pi-hole/AdminLTE web - source "$core_dir/automated install/basic-install.sh" - installScripts + swapScripts fi manageHistory ${1:-} @@ -226,6 +248,7 @@ update() { else echo "Systemd not found. Skipping Pi-hole update..." fi + if [ "${1:-}" == "un" ]; then purge exit 0 @@ -238,14 +261,17 @@ abort() { if [ -d $admin_dir/admin/.git/refs/remotes/old ]; then download $admin_dir admin old web fi + if [ -d $core_dir/.git/refs/remotes/old ]; then download /etc .pihole old Pi-hole source "$core_dir/automated install/basic-install.sh" installScripts fi + if [ ! -f $curr_wp ] || ! cat $curr_wp | grep -q SpeedTest; then purge fi + if [ -f $last_db ] && [ ! -f $curr_db ]; then mv $last_db $curr_db fi @@ -267,15 +293,18 @@ commit() { main() { printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" local op=${1:-} + if [ "$op" == "-h" ] || [ "$op" == "--help" ]; then help exit 0 fi + if [ $EUID != 0 ]; then sudo "$0" "$@" exit $? fi - set -Eeo pipefail + + set -Eeuo pipefail trap '[ "$?" -eq "0" ] && commit || abort' EXIT trap 'abort' INT TERM shopt -s dotglob @@ -302,9 +331,12 @@ main() { exit 0 } -aborted=0 -rm -f /tmp/pimod.log -touch /tmp/pimod.log -main "$@" 2>&1 | tee -a /tmp/pimod.log -mv -f /tmp/pimod.log /var/log/pihole/mod.log -exit $aborted +# allow to source this script without running it +if [[ "${SKIP_MOD:-}" != true ]]; then + aborted=0 + rm -f /tmp/pimod.log + touch /tmp/pimod.log + main "$@" 2>&1 | tee -a /tmp/pimod.log + mv -f /tmp/pimod.log /var/log/pihole/mod.log + exit $aborted +fi diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 1008e508cf..fb2ad8d868 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -16,6 +16,9 @@ upload real, share_url text );" +SKIP_MOD=true +source /opt/pihole/speedtestmod/mod.sh + speedtest() { if grep -q official <<<"$(/usr/bin/speedtest --version)"; then if [[ -z "${serverid}" ]]; then @@ -52,7 +55,7 @@ savetest() { ' local temp_file=$(mktemp) local json_file="/tmp/speedtest_results" - jq "$rm_empty" "$json_file" > "$temp_file" && mv -f "$temp_file" "$json_file" + jq "$rm_empty" "$json_file" >"$temp_file" && mv -f "$temp_file" "$json_file" rm -f "$temp_file" chmod 644 /tmp/speedtest_results mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log @@ -106,75 +109,6 @@ notInstalled() { return 1 } -setTags() { - local path=${1:-} - local name=${2:-} - local branch="${3:-master}" - - if [ ! -z "$path" ]; then - cd "$path" - git fetch origin $branch:refs/remotes/origin/$branch -q - git fetch --tags -f -q - latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) - fi - if [ ! -z "$name" ]; then - localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 6) - if [ "$localTag" == "HEAD" ]; then - localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 7) - fi - fi -} - -download() { - local path=$1 - local name=$2 - local url=$3 - local src=${4:-} - local branch="${5:-master}" - local dest=$path/$name - - if [ ! -d "$dest" ]; then # replicate - cd "$path" - rm -rf "$name" - git clone --depth=1 -b "$branch" "$url" "$name" - git config --global --add safe.directory "$dest" - setTags "$name" "${src:-}" "$branch" - if [ ! -z "$src" ]; then - if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then - latestTag=$localTag - git fetch --unshallow - fi - fi - else # replace - git config --global --add safe.directory "$dest" - cd "$dest" - if [ ! -z "$src" ]; then - if [ "$url" != "old" ]; then - git remote -v | grep -q "old" || git remote rename origin old - git remote -v | grep -q "origin" && git remote remove origin - git remote add -t "$branch" origin "$url" - elif [ -d .git/refs/remotes/old ]; then - git remote remove origin - git remote rename old origin - git clean -ffdx - fi - fi - setTags "$dest" "${src:-}" "$branch" - git reset --hard origin/"$branch" - git checkout -B "$branch" - if git rev-parse --verify "$branch" >/dev/null 2>&1; then - git branch -u "origin/$branch" "$branch" - else - git checkout --track "origin/$branch" - fi - fi - - if [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag)" ]; then - git -c advice.detachedHead=false checkout "$latestTag" - fi - cd .. -} - librespeed() { if notInstalled golang; then if grep -q "Raspbian" /etc/os-release; then diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 3b9c649ad9..53128ed03c 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -17,7 +17,7 @@ function get_local_branch() { function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - local local_v=$(git tag --sort=-version:refname | head -n 1) + local_v=$(git tag --sort=-version:refname | head -n 1) if [[ "${local_v}" == "vDev" ]]; then local_v=$(git tag --sort=-version:refname | head -n 2 | tail -n 1) fi @@ -30,7 +30,11 @@ function get_local_hash() { } function get_remote_version() { - curl -s "https://api.github.com/repos/arevindh/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || { curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1; } + if [[ "${1}" == "docker-pi-hole" ]]; then + curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 + else + curl -s "https://api.github.com/repos/arevindh/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || { curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1; } + fi } diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 90f1f6cbec..8d697b94a6 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -620,74 +620,8 @@ interval_seconds=$total_seconds schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") -setTags() { - local path=\${1:-} - local name=\${2:-} - local branch="\${3:-master}" - - if [ ! -z "\$path" ]; then - cd "\$path" - git fetch origin \$branch:refs/remotes/origin/\$branch -q - git fetch --tags -f -q - latestTag=\$(git describe --tags \$(git rev-list --tags --max-count=1)) - fi - if [ ! -z "\$name" ]; then - localTag=\$(pihole -v | grep "\$name" | cut -d ' ' -f 6) - if [ "\$localTag" == "HEAD" ]; then - localTag=\$(pihole -v | grep "\$name" | cut -d ' ' -f 7) - fi - fi -} - -download() { - local path=\$1 - local name=\$2 - local url=\$3 - local src=\${4:-} - local branch="\${5:-master}" - local dest=\$path/\$name - - if [ ! -d "\$dest" ]; then # replicate - cd "\$path" - rm -rf "\$name" - git clone --depth=1 -b "\$branch" "\$url" "\$name" - git config --global --add safe.directory "\$dest" - setTags "\$name" "\${src:-}" "\$branch" - if [ ! -z "\$src" ]; then - if [[ "\$localTag" == *.* ]] && [[ "\$localTag" < "\$latestTag" ]]; then - latestTag=\$localTag - git fetch --unshallow - fi - fi - else # replace - git config --global --add safe.directory "\$dest" - cd "\$dest" - if [ ! -z "\$src" ]; then - if [ "\$url" != "old" ]; then - git remote -v | grep -q "old" || git remote rename origin old - git remote -v | grep -q "origin" && git remote remove origin - git remote add -t "\$branch" origin "\$url" - elif [ -d .git/refs/remotes/old ]; then - git remote remove origin - git remote rename old origin - git clean -ffdx - fi - fi - setTags "\$dest" "\${src:-}" "\$branch" - git reset --hard origin/"\$branch" - git checkout -B "\$branch" - if git rev-parse --verify "\$branch" >/dev/null 2>&1; then - git branch -u "origin/\$branch" "\$branch" - else - git checkout --track "origin/\$branch" - fi - fi - - if [ "$(git rev-parse HEAD)" != "$(git rev-parse \$latestTag)" ]; then - git -c advice.detachedHead=false checkout "\$latestTag" - fi - cd .. -} +SKIP_MOD=true +source /opt/pihole/speedtestmod/mod.sh if [ ! -d /etc/pihole/speedtest ]; then download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest From c9ee61806264b9acffe974d60dc3f980453f4bd1 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 02:16:21 -0500 Subject: [PATCH 603/638] delete local tags before fetching them (#85) * delete local tags before fetching them --- advanced/Scripts/speedtestmod/mod.sh | 3 ++- advanced/Scripts/webpage.sh | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 9ba7d90f7e..3c5bdefb1f 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -16,7 +16,7 @@ help() { echo "db - flush the database (if it's not empty, otherwise restore it)" echo "If no option is specified, the latest version of the Mod will be (re)installed." } - +pi setTags() { local path=${1:-} local name=${2:-} @@ -26,6 +26,7 @@ setTags() { if [ ! -z "$path" ]; then cd "$path" git fetch origin $branch:refs/remotes/origin/$branch -q + git tag -l | xargs git tag -d git fetch --tags -f -q latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) fi diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 8d697b94a6..d8e78a14fa 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -623,12 +623,9 @@ schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh -if [ ! -d /etc/pihole/speedtest ]; then - download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest -fi - -# if schedule is set and interval is "nan", set the speedtest interval to the schedule +# if schedule is set and interval is "nan", get latest release and set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then + download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then /usr/local/bin/pihole -a -s "\$schedule" fi From ba954a71e226499e719a028dac1a2eb46ac4ae68 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 02:39:33 -0500 Subject: [PATCH 604/638] typo (#86) --- advanced/Scripts/speedtestmod/mod.sh | 4 ++-- advanced/Scripts/webpage.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 3c5bdefb1f..ce181a1936 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -16,7 +16,7 @@ help() { echo "db - flush the database (if it's not empty, otherwise restore it)" echo "If no option is specified, the latest version of the Mod will be (re)installed." } -pi + setTags() { local path=${1:-} local name=${2:-} @@ -26,7 +26,7 @@ setTags() { if [ ! -z "$path" ]; then cd "$path" git fetch origin $branch:refs/remotes/origin/$branch -q - git tag -l | xargs git tag -d + git tag -l | xargs git tag -d >/dev/null 2>&1 git fetch --tags -f -q latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) fi diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index d8e78a14fa..f9ec218d51 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -625,10 +625,11 @@ source /opt/pihole/speedtestmod/mod.sh # if schedule is set and interval is "nan", get latest release and set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then - download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then /usr/local/bin/pihole -a -s "\$schedule" fi + download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest + pihole updatechecker exit 0 fi From 289c8026089b9ff94441261e2bda953d13502fc4 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 03:19:07 -0500 Subject: [PATCH 605/638] fix install (#87) * fix install --- advanced/Scripts/speedtestmod/mod.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index ce181a1936..1e2db56a20 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -93,12 +93,18 @@ download() { fi if [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]]; then - # Get last tag before/at $latestTag installed - last_tag_before_current=$(git tag -l | grep '^v' | grep -v 'vDev' | sort -V | awk -v latestTag="$latestTag" '$1 <= latestTag' | tail -n1) + if [[ "$url" == *"arevindh"* ]]; then + if ! last_tag_before_current=$(git describe --tags --abbrev=0 HEAD 2>/dev/null); then + last_tag_before_current=$latestTag + fi + else + # Get last tag before/at $latestTag installed + last_tag_before_current=$(git tag -l | grep '^v' | grep -v 'vDev' | sort -V | awk -v latestTag="$latestTag" '$1 <= latestTag' | tail -n1) - # If no such tag is found, fall back to $latestTag - if [ -z "$last_tag_before_current" ]; then - last_tag_before_current=$latestTag + # If no such tag is found, fall back to $latestTag + if [ -z "$last_tag_before_current" ]; then + last_tag_before_current=$latestTag + fi fi # Check if HEAD is already at this tag, if not, check out the tag From a7c04b5d6722c7ff0a8fcfe1e3fc895a0b354e21 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 03:26:10 -0500 Subject: [PATCH 606/638] another check (#88) * another check --- advanced/Scripts/speedtestmod/mod.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 1e2db56a20..379dc0e458 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -26,7 +26,9 @@ setTags() { if [ ! -z "$path" ]; then cd "$path" git fetch origin $branch:refs/remotes/origin/$branch -q - git tag -l | xargs git tag -d >/dev/null 2>&1 + if [[ "$url" != *"arevindh"* ]]; then + git tag -l | xargs git tag -d >/dev/null 2>&1 + fi git fetch --tags -f -q latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) fi From 0b20bc5dd924576b6ecdbd5617041603d94191c6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 03:56:27 -0500 Subject: [PATCH 607/638] get latest tag using ls-remote (#89) --- advanced/Scripts/speedtestmod/mod.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 379dc0e458..849e777ef4 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -30,7 +30,7 @@ setTags() { git tag -l | xargs git tag -d >/dev/null 2>&1 fi git fetch --tags -f -q - latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) + latestTag=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep -v '\^{}' | sort -V | tail -n1) fi if [[ "$url" != *"arevindh"* ]] && [ ! -z "$name" ]; then From 4ce673b9272fd17f734a20041090e8e1898db0db Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 05:47:22 -0500 Subject: [PATCH 608/638] refactor download (#90) * refactor download --- advanced/Scripts/speedtestmod/mod.sh | 117 +++++++++------------------ advanced/Scripts/webpage.sh | 11 ++- 2 files changed, 45 insertions(+), 83 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 849e777ef4..b59544d255 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -17,39 +17,6 @@ help() { echo "If no option is specified, the latest version of the Mod will be (re)installed." } -setTags() { - local path=${1:-} - local name=${2:-} - local url=${3:-} - local branch="${4:-master}" - - if [ ! -z "$path" ]; then - cd "$path" - git fetch origin $branch:refs/remotes/origin/$branch -q - if [[ "$url" != *"arevindh"* ]]; then - git tag -l | xargs git tag -d >/dev/null 2>&1 - fi - git fetch --tags -f -q - latestTag=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep -v '\^{}' | sort -V | tail -n1) - fi - - if [[ "$url" != *"arevindh"* ]] && [ ! -z "$name" ]; then - local localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 6) - - if [ "$localTag" == "HEAD" ]; then - localTag=$(pihole -v | grep "$name" | cut -d ' ' -f 7) - fi - - if [[ "$localTag" == *.* ]] && [[ "$localTag" < "$latestTag" ]]; then - latestTag=$localTag - - if [ -f "$(git rev-parse --git-dir)"/shallow ]; then - git fetch --unshallow - fi - fi - fi -} - download() { local path=$1 local name=$2 @@ -58,62 +25,52 @@ download() { local branch="${5:-master}" local dest=$path/$name - if [ ! -d "$dest" ]; then # replicate - cd "$path" - rm -rf "$name" - git clone --depth=1 -b "$branch" "$url" "$name" - git config --global --add safe.directory "$dest" - setTags "$name" "$src" "$url" "$branch" + if [ ! -d "$dest" ]; then + git clone --depth=1 -b "$branch" "$url" "$dest" elif [ ! -d "$dest/.git" ]; then mv -f "$dest" "$dest.old" download "$@" - else # replace - git config --global --add safe.directory "$dest" - cd "$dest" - - if [ ! -z "$src" ]; then - if [ "$url" != "old" ]; then - git remote -v | grep -q "old" || git remote rename origin old - git remote -v | grep -q "origin" && git remote remove origin - git remote add -t "$branch" origin "$url" - elif [ -d .git/refs/remotes/old ]; then - git remote remove origin - git remote rename old origin - git clean -ffdx - fi - fi - - setTags "$dest" "$src" "$url" "$branch" - git reset --hard origin/"$branch" - git checkout -B "$branch" - - if git rev-parse --verify "$branch" >/dev/null 2>&1; then - git branch -u "origin/$branch" "$branch" - else - git checkout --track "origin/$branch" - fi + return fi - if [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]]; then - if [[ "$url" == *"arevindh"* ]]; then - if ! last_tag_before_current=$(git describe --tags --abbrev=0 HEAD 2>/dev/null); then - last_tag_before_current=$latestTag - fi - else - # Get last tag before/at $latestTag installed - last_tag_before_current=$(git tag -l | grep '^v' | grep -v 'vDev' | sort -V | awk -v latestTag="$latestTag" '$1 <= latestTag' | tail -n1) + cd "$dest" + git config --global --add safe.directory "$dest" + + if [ "$url" != "old" ]; then + git remote -v | grep -q "old" || git remote rename origin old + git remote -v | grep -q "origin" && git remote remove origin + git remote add -t "$branch" origin "$url" + elif [ -d .git/refs/remotes/old ]; then + git remote remove origin + git remote rename old origin + git clean -ffdx + fi - # If no such tag is found, fall back to $latestTag - if [ -z "$last_tag_before_current" ]; then - last_tag_before_current=$latestTag - fi + git fetch origin $branch:refs/remotes/origin/$branch -q + git reset --hard origin/"$branch" + git checkout -B "$branch" + git rev-parse --verify "$branch" >/dev/null 2>&1 && git branch -u "origin/$branch" "$branch" || git checkout --track "origin/$branch" + git tag -l | xargs git tag -d >/dev/null 2>&1 + git fetch --tags -f -q + [ "$url" == "old" ] || latestTag=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep -v '\^{}' | sort -V | tail -n1) + [[ "${latestTag:-}" == *.* ]] || latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) + + if [[ "$url" != *"arevindh"* ]] && [ ! -z "$src" ] && [[ "$url" != *"ipitio"* ]] && ! git remote -v | grep -q "old.*ipitio"; then + local localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 6) + [ "$localVersion" != "HEAD" ] || localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 7) + + # if the local version is less than the latest tag then use the tag before it + if [[ "$localVersion" == *.* ]] && [[ "$localVersion" < "$latestTag" ]]; then + [ "$url" == "old" ] || latestTag=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep -v '\^{}' | sort -V | awk -v lv="$localVersion" '$1 < lv {print $1}' | tail -n1) + [[ "$latestTag" == *.* ]] || latestTag=$(git tag -l | grep -v '\^{}' | sort -V | awk -v lv="$localVersion" '$1 < lv {print $1}' | tail -n1) + [ ! -f "$(git rev-parse --git-dir)"/shallow ] || git fetch --unshallow fi + fi - # Check if HEAD is already at this tag, if not, check out the tag - if [ "$(git rev-parse HEAD)" != "$(git rev-parse $last_tag_before_current 2>/dev/null)" ]; then - git -c advice.detachedHead=false checkout "$last_tag_before_current" - fi + if [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]] && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ]; then + git -c advice.detachedHead=false checkout "$latestTag" fi + cd .. } diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f9ec218d51..20dcec8039 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -623,13 +623,18 @@ schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh -# if schedule is set and interval is "nan", get latest release and set the speedtest interval to the schedule +# if "pihole -v" includes "N/A", update the mod +if [[ "\$(/usr/local/bin/pihole -v)" == *"N/A"* ]]; then + download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest + pihole updatechecker +fi + +# if schedule is set and interval is "nan", set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then /usr/local/bin/pihole -a -s "\$schedule" fi - download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest - pihole updatechecker + exit 0 fi From 4596f828a532c54ec725327d4050eb95e95838ba Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 5 Mar 2024 05:57:41 -0500 Subject: [PATCH 609/638] docker hack fix (#91) * docker hack fix --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 20dcec8039..870d0e4abd 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -623,8 +623,8 @@ schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh -# if "pihole -v" includes "N/A", update the mod -if [[ "\$(/usr/local/bin/pihole -v)" == *"N/A"* ]]; then +# if "pihole -v" includes "N/A" or doesn't include "speedtest", download the mod +if [[ "\$(/usr/local/bin/pihole -v)" == *"N/A"* ]] || [[ "\$(/usr/local/bin/pihole -v)" != *"speedtest"* ]]; then download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest pihole updatechecker fi From 8042d9e3fd0464964f5f3a783bd1af1db17cc277 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 9 Mar 2024 10:21:53 +0000 Subject: [PATCH 610/638] Bump tox from 4.13.0 to 4.14.1 in /test Bumps [tox](https://github.com/tox-dev/tox) from 4.13.0 to 4.14.1. - [Release notes](https://github.com/tox-dev/tox/releases) - [Changelog](https://github.com/tox-dev/tox/blob/main/docs/changelog.rst) - [Commits](https://github.com/tox-dev/tox/compare/4.13.0...4.14.1) --- updated-dependencies: - dependency-name: tox dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/requirements.txt b/test/requirements.txt index ffb05813f3..d4415e2b32 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,5 +2,5 @@ pyyaml == 6.0.1 pytest == 8.0.2 pytest-xdist == 3.5.0 pytest-testinfra == 10.1.0 -tox == 4.13.0 +tox == 4.14.1 From f71391b59e413917e7af710d1e2b6d64f3765902 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 9 Mar 2024 13:07:10 -0500 Subject: [PATCH 611/638] simplify code (#92) Features: * several fixes and enhancements Fixes: * fix abort * fix setting version after install in docker Enhancements: * make download more efficient * reduce log verbosity --- advanced/Scripts/speedtestmod/mod.sh | 445 ++++++++++----------- advanced/Scripts/speedtestmod/speedtest.sh | 180 +++------ advanced/Scripts/webpage.sh | 8 +- 3 files changed, 266 insertions(+), 367 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index b59544d255..41e6e85cd9 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,38 +1,28 @@ #!/bin/bash -admin_dir=/var/www/html -core_dir=/etc/.pihole -opt_dir=/opt/pihole -etc_dir=/etc/pihole -curr_wp=$opt_dir/webpage.sh -curr_db=$etc_dir/speedtest.db -last_db=$curr_db.old -db_table="speedtest" - -help() { - echo "(Re)install Latest Speedtest Mod." - echo "Usage: sudo $0 [up] [un] [db]" - echo "up - update the mod (and Pi-hole if not in Docker)" - echo "un - remove the mod (and any database backups)" - echo "db - flush the database (if it's not empty, otherwise restore it)" - echo "If no option is specified, the latest version of the Mod will be (re)installed." + +getLocalVersion() { + local src=${1:-} + + if [ -z "$src" ]; then + echo "" + else + local localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 6) + [ "$localVersion" != "HEAD" ] || localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 7) + echo "$localVersion" + fi } download() { local path=$1 local name=$2 local url=$3 - local src=${4:-} + local localVersion=${4:-} local branch="${5:-master}" local dest=$path/$name + local tags=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V) - if [ ! -d "$dest" ]; then - git clone --depth=1 -b "$branch" "$url" "$dest" - elif [ ! -d "$dest/.git" ]; then - mv -f "$dest" "$dest.old" - download "$@" - return - fi - + [ -d "$dest" ] && [ ! -d "$dest/.git" ] && mv -f "$dest" "$dest.old" || : + [ -d "$dest" ] || git clone --depth=1 -b "$branch" "$url" "$dest" -q cd "$dest" git config --global --add safe.directory "$dest" @@ -46,74 +36,15 @@ download() { git clean -ffdx fi - git fetch origin $branch:refs/remotes/origin/$branch -q - git reset --hard origin/"$branch" - git checkout -B "$branch" - git rev-parse --verify "$branch" >/dev/null 2>&1 && git branch -u "origin/$branch" "$branch" || git checkout --track "origin/$branch" - git tag -l | xargs git tag -d >/dev/null 2>&1 - git fetch --tags -f -q - [ "$url" == "old" ] || latestTag=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep -v '\^{}' | sort -V | tail -n1) - [[ "${latestTag:-}" == *.* ]] || latestTag=$(git describe --tags $(git rev-list --tags --max-count=1)) - - if [[ "$url" != *"arevindh"* ]] && [ ! -z "$src" ] && [[ "$url" != *"ipitio"* ]] && ! git remote -v | grep -q "old.*ipitio"; then - local localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 6) - [ "$localVersion" != "HEAD" ] || localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 7) - - # if the local version is less than the latest tag then use the tag before it - if [[ "$localVersion" == *.* ]] && [[ "$localVersion" < "$latestTag" ]]; then - [ "$url" == "old" ] || latestTag=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep -v '\^{}' | sort -V | awk -v lv="$localVersion" '$1 < lv {print $1}' | tail -n1) - [[ "$latestTag" == *.* ]] || latestTag=$(git tag -l | grep -v '\^{}' | sort -V | awk -v lv="$localVersion" '$1 < lv {print $1}' | tail -n1) - [ ! -f "$(git rev-parse --git-dir)"/shallow ] || git fetch --unshallow - fi - fi - - if [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]] && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ]; then - git -c advice.detachedHead=false checkout "$latestTag" - fi - + git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q + git reset --hard origin/"$branch" -q + git checkout -B "$branch" -q + [[ "$localVersion" == *.* ]] && local latestTag=$localVersion || local latestTag=$(getLocalVersion "$localVersion") + [ "$url" != "old" ] && [[ "$url" != *"arevindh"* ]] && ! git remote -v | grep -q "old.*ipitio" && [[ "$localVersion" < "$latestTag" ]] && latestTag=$(awk -v lv="$localVersion" '$1 <= lv' <<< "$tags" | tail -n1) || latestTag=$(tail -n1 <<< "$tags") + [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]] && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ] && git fetch origin tag $latestTag --depth=1 -q && git -c advice.detachedHead=false checkout "$latestTag" -q cd .. } -isEmpty() { - db=$1 - if [ -f $db ]; then - if ! sqlite3 "$db" "select * from $db_table limit 1;" >/dev/null 2>&1 || [ -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ]; then - return 0 - fi - fi - return 1 -} - -manageHistory() { - if [ "${1:-}" == "db" ]; then - if [ -f $curr_db ] && ! isEmpty $curr_db; then - echo "Flushing Database..." - mv -f $curr_db $last_db - - if [ -f $etc_dir/last_speedtest ]; then - mv -f $etc_dir/last_speedtest $etc_dir/last_speedtest.old - fi - - if [ -f /var/log/pihole/speedtest.log ]; then - mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old - rm -f $etc_dir/speedtest.log - fi - elif [ -f $last_db ]; then - echo "Restoring Database..." - mv -f $last_db $curr_db - - if [ -f $etc_dir/last_speedtest.old ]; then - mv -f $etc_dir/last_speedtest.old $etc_dir/last_speedtest - fi - - if [ -f /var/log/pihole/speedtest.log.old ]; then - mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log - cp -af /var/log/pihole/speedtest.log $etc_dir/speedtest.log - fi - fi - fi -} - notInstalled() { if [ -x "$(command -v apt-get)" ]; then dpkg -s "$1" &>/dev/null || return 0 @@ -127,179 +58,215 @@ notInstalled() { return 1 } -swapScripts() { - SKIP_INSTALL=true - set +u - source "$core_dir/automated install/basic-install.sh" - installScripts - set -u -} - -installMod() { - echo "Installing Mod..." - - if [ ! -f /usr/local/bin/pihole ]; then - echo "Installing Pi-hole..." - curl -sSL https://install.pi-hole.net | sudo bash - fi +# allow to source the above helper functions without running the whole script +if [[ "${SKIP_MOD:-}" != true ]]; then + aborted=0 + html_dir=/var/www/html + core_dir=/etc/.pihole + opt_dir=/opt/pihole + etc_dir=/etc/pihole + curr_wp=$opt_dir/webpage.sh + curr_db=$etc_dir/speedtest.db + last_db=$curr_db.old + db_table="speedtest" + st_ver=$db_table + + help() { + echo "(Re)install Latest Speedtest Mod." + echo "Usage: sudo $0 [up] [un] [db]" + echo "up - update the mod (and Pi-hole if not in Docker)" + echo "un - remove the mod (and any database backups)" + echo "db - flush the database (if it's not empty, otherwise restore it)" + echo "If no option is specified, the latest version of the Mod will be (re)installed." + } + + isEmpty() { + db=$1 + [ -f $db ] && sqlite3 "$db" "select * from $db_table limit 1;" >/dev/null 2>&1 && [ ! -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ] && return 1 || return 0 + } + + manageHistory() { + if [ "${1:-}" == "db" ]; then + if [ -f $curr_db ] && ! isEmpty $curr_db; then + echo "Flushing Database..." + mv -f $curr_db $last_db + [ ! -f $etc_dir/last_speedtest ] || mv -f $etc_dir/last_speedtest $etc_dir/last_speedtest.old + + if [ -f /var/log/pihole/speedtest.log ]; then + mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old + rm -f $etc_dir/speedtest.log + fi + elif [ -f $last_db ]; then + echo "Restoring Database..." + mv -f $last_db $curr_db + [ ! -f $etc_dir/last_speedtest.old ] || mv -f $etc_dir/last_speedtest.old $etc_dir/last_speedtest + + if [ -f /var/log/pihole/speedtest.log.old ]; then + mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log + cp -af /var/log/pihole/speedtest.log $etc_dir/speedtest.log + fi + fi + fi + } - local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) - local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") + swapScripts() { + SKIP_INSTALL=true + set +u + source "$core_dir/automated install/basic-install.sh" + installScripts + set -u + } - local missingPkgs=() - for pkg in "${PKGS[@]}"; do - if notInstalled "$pkg"; then - missingPkgs+=("$pkg") - fi - done + installMod() { + echo "Installing Mod..." - if [ ${#missingPkgs[@]} -gt 0 ]; then - if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - apt-get update + if [ ! -f /usr/local/bin/pihole ]; then + echo "Installing Pi-hole..." + curl -sSL https://install.pi-hole.net | sudo bash fi - $PKG_MANAGER install -y "${missingPkgs[@]}" - fi - - download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole - download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest - download $admin_dir admin https://github.com/arevindh/AdminLTE web + local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) + local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) + local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") + local missingPkgs=() - swapScripts - cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ - pihole -a -s - pihole updatechecker -} + for pkg in "${PKGS[@]}"; do + notInstalled "$pkg" && missingPkgs+=("$pkg") || : + done -uninstall() { - if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then - echo "Restoring Pi-hole..." + if [ ${#missingPkgs[@]} -gt 0 ]; then + [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update + $PKG_MANAGER install -y "${missingPkgs[@]}" + fi - pihole -a -s -1 - download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole - download $admin_dir admin https://github.com/pi-hole/AdminLTE web + download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole swapScripts - fi - - manageHistory ${1:-} -} - -purge() { - rm -rf "$admin_dir"/*_admin - rm -rf $opt_dir/speedtestmod - rm -rf $etc_dir/speedtest - rm -rf $etc_dir/mod - if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then - rm -f /etc/systemd/system/pihole-speedtest.service - rm -f /etc/systemd/system/pihole-speedtest.timer - systemctl daemon-reload - fi + cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + pihole -a -s + download $html_dir admin https://github.com/arevindh/AdminLTE web + download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest + pihole updatechecker + } + + uninstall() { + if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then + echo "Restoring Pi-hole..." + pihole -a -s -1 + download $html_dir admin https://github.com/pi-hole/AdminLTE web + download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole + st_ver=$(getLocalVersion "speedtest") + rm -rf $etc_dir/speedtest + swapScripts + fi - rm -f "$curr_wp".* - rm -f "$curr_db".* - rm -f "$curr_db"_* - rm -f $etc_dir/last_speedtest.* - if isEmpty $curr_db; then - rm -f $curr_db - fi + manageHistory ${1:-} + } - pihole updatechecker -} + purge() { + if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then + rm -f /etc/systemd/system/pihole-speedtest.service + rm -f /etc/systemd/system/pihole-speedtest.timer + systemctl daemon-reload + fi -update() { - if [[ -d /run/systemd/system ]]; then - echo "Updating Pi-hole..." - PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up - else - echo "Systemd not found. Skipping Pi-hole update..." - fi + rm -rf "$html_dir"/*_admin + rm -rf $opt_dir/speedtestmod + rm -rf $etc_dir/mod + rm -f "$curr_wp".* + rm -f "$curr_db".* + rm -f "$curr_db"_* + rm -f $etc_dir/last_speedtest.* + isEmpty $curr_db && rm -f $curr_db || : + pihole updatechecker + } + + update() { + if [[ -d /run/systemd/system ]]; then + echo "Updating Pi-hole..." + PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up + else + echo "Systemd not found. Skipping Pi-hole update..." + fi - if [ "${1:-}" == "un" ]; then - purge - exit 0 - fi -} + if [ "${1:-}" == "un" ]; then + purge + exit 0 + fi -abort() { - echo "Process Aborting..." + installMod + } - if [ -d $admin_dir/admin/.git/refs/remotes/old ]; then - download $admin_dir admin old web - fi + abort() { + echo "Process Aborting..." - if [ -d $core_dir/.git/refs/remotes/old ]; then - download /etc .pihole old Pi-hole - source "$core_dir/automated install/basic-install.sh" - installScripts - fi + if [ -d $core_dir/.git/refs/remotes/old ]; then + download /etc .pihole old Pi-hole + swapScripts - if [ ! -f $curr_wp ] || ! cat $curr_wp | grep -q SpeedTest; then - purge - fi + if [ -d $core_dir/advanced/Scripts/speedtestmod ]; then + cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + pihole -a -s + fi + fi - if [ -f $last_db ] && [ ! -f $curr_db ]; then - mv $last_db $curr_db - fi + [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin old web + [ -d $etc_dir/speedtest ] && [ -d $etc_dir/speedtest/.git/refs/remotes/old ] && download $etc_dir speedtest old $st_ver || : + [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest && purge || : + [ -f $last_db ] && [ ! -f $curr_db ] && mv $last_db $curr_db || : + aborted=1 + printf "Please try again before reporting an issue.\n\n$(date)\n" + } + + commit() { + for dir in $core_dir $html_dir/admin $etc_dir/speedtest; do + if [ -d $dir/.git/refs/remotes/old ]; then + cd $dir + git remote -v | grep -q "old" && git remote remove old || : + fi + done + printf "Done!\n\n$(date)\n" + } - pihole restartdns - aborted=1 - printf "Please try again before reporting an issue.\n\n$(date)\n" -} + main() { + printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" + local op=${1:-} -commit() { - cd $core_dir - git remote -v | grep -q "old" && git remote remove old - cd $admin_dir/admin - git remote -v | grep -q "old" && git remote remove old - pihole restartdns - printf "Done!\n\n$(date)\n" -} + if [ "$op" == "-h" ] || [ "$op" == "--help" ]; then + help + exit 0 + fi -main() { - printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" - local op=${1:-} + if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? + fi - if [ "$op" == "-h" ] || [ "$op" == "--help" ]; then - help + set -Eeuo pipefail + trap '[ "$?" -eq "0" ] && commit || abort' EXIT + trap 'abort' INT TERM + shopt -s dotglob + + local db=$([ "$op" == "up" ] && echo "${3:-}" || [ "$op" == "un" ] && echo "${2:-}" || echo "$op") + case $op in + db) + manageHistory $db + ;; + un) + uninstall $db + purge + ;; + up) + uninstall $db + update ${2:-} + ;; + *) + uninstall $db + installMod + ;; + esac exit 0 - fi + } - if [ $EUID != 0 ]; then - sudo "$0" "$@" - exit $? - fi - - set -Eeuo pipefail - trap '[ "$?" -eq "0" ] && commit || abort' EXIT - trap 'abort' INT TERM - shopt -s dotglob - - local db=$([ "$op" == "up" ] && echo "${3:-}" || [ "$op" == "un" ] && echo "${2:-}" || echo "$op") - case $op in - db) - manageHistory $db - ;; - un) - uninstall $db - purge - ;; - up) - uninstall $db - update ${2:-} - installMod - ;; - *) - uninstall $db - installMod - ;; - esac - exit 0 -} - -# allow to source this script without running it -if [[ "${SKIP_MOD:-}" != true ]]; then - aborted=0 rm -f /tmp/pimod.log touch /tmp/pimod.log main "$@" 2>&1 | tee -a /tmp/pimod.log diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index fb2ad8d868..b52e2eaa71 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -15,23 +15,14 @@ download real, upload real, share_url text );" - SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh speedtest() { if grep -q official <<<"$(/usr/bin/speedtest --version)"; then - if [[ -z "${serverid}" ]]; then - /usr/bin/speedtest --accept-gdpr --accept-license -f json - else - /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json - fi + [[ ! -z "${serverid}" ]] && /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json else - if [[ -z "${serverid}" ]]; then - /usr/bin/speedtest --json --share --secure - else - /usr/bin/speedtest --server $serverid --json --share --secure || /usr/bin/speedtest --json --share --secure - fi + [[ ! -z "${serverid}" ]] && /usr/bin/speedtest --server $serverid --json --share --secure || /usr/bin/speedtest --json --share --secure fi } @@ -46,9 +37,6 @@ savetest() { local download=${8:-0} local upload=${9:-0} local share_url=${10:-"#"} - sqlite3 /etc/pihole/speedtest.db "$create_table" - sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" - local rm_empty=' def nonempty: . and length > 0 and (type != "object" or . != {}) and (type != "array" or any(.[]; . != "")); if type == "array" then map(walk(if type == "object" then with_entries(select(.value | nonempty)) else . end)) else walk(if type == "object" then with_entries(select(.value | nonempty)) else . end) end @@ -61,37 +49,27 @@ savetest() { mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log rm -f "$out" + sqlite3 /etc/pihole/speedtest.db "$create_table" + sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" [ "$isp" == "No Internet" ] && exit 1 || exit 0 } isAvailable() { if [ -x "$(command -v apt-get)" ]; then # Check if there is a candidate and it is not "(none)" - if apt-cache policy "$1" | grep -q "Candidate:" && ! apt-cache policy "$1" | grep -q "Candidate: (none)"; then - return 0 - fi + apt-cache policy "$1" | grep -q "Candidate:" && ! apt-cache policy "$1" | grep -q "Candidate: (none)" && return 0 || return 1 elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]; then local PKG_MANAGER=$(command -v dnf || command -v yum) - if $PKG_MANAGER list available "$1" &>/dev/null; then - return 0 - fi + $PKG_MANAGER list available "$1" &>/dev/null && return 0 || return 1 else echo "Unsupported package manager!" exit 1 fi - - return 1 } swaptest() { if isAvailable $1; then - if [ -x "$(command -v apt-get)" ]; then - apt-get install -y $1 $2- - elif [ -x "$(command -v dnf)" ]; then - dnf install -y --allowerasing $1 - else - yum install -y --allowerasing $1 - fi + [ -x "$(command -v apt-get)" ] && apt-get install -y $1 $2- || { [ -x "$(command -v dnf)" ] && dnf install -y --allowerasing $1 || yum install -y --allowerasing $1; } fi } @@ -126,14 +104,51 @@ librespeed() { fi download /etc/pihole librespeed https://github.com/librespeed/speedtest-cli cd librespeed - if [ -d out ]; then - rm -rf out - fi + [ ! -d out ] || rm -rf out ./build.sh mv -f out/* /usr/bin/speedtest chmod +x /usr/bin/speedtest } +addSource() { + if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then + if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then + echo "Adding speedtest source for RPM..." + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash + fi + + yum list speedtest | grep -q "Available Packages" && $PKG_MANAGER install -y speedtest || : + elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then + echo "Adding speedtest source for DEB..." + if [ -e /etc/os-release ]; then + . /etc/os-release + local base="ubuntu debian" + local os=${ID} + local dist=${VERSION_CODENAME} + if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then + os=${ID_LIKE%% *} + [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + dist=${UBUNTU_CODENAME} + [ -z "$dist" ] && dist=${VERSION_CODENAME} + fi + wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 + chmod +x /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh + rm -f /tmp/script.deb.sh + else + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash + fi + + sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list + apt-get update + fi + else + echo "Unsupported package manager!" + exit 1 + fi +} + run() { speedtest | jq . >/tmp/speedtest_results || echo "Attempt ${2:-1} Failed!" >/tmp/speedtest_results local stop=$(date -u --rfc-3339='seconds') @@ -151,9 +166,7 @@ run() { local from_ip=$(jq -r '.interface.externalIp' <<<"$res") local server_ping=$(jq -r '.ping.latency' <<<"$res") local share_url=$(jq -r '.result.url' <<<"$res") - if [ -z "$server_dist" ]; then - server_dist="-1" - fi + [ ! -z "$server_dist" ] || server_dist="-1" else # speedtest-cli local server_name=$(jq -r '.server.sponsor' <<<"$res") local download=$(jq -r '.download' <<<"$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') @@ -162,9 +175,7 @@ run() { local from_ip=$(jq -r '.client.ip' <<<"$res") local server_ping=$(jq -r '.ping' <<<"$res") local share_url=$(jq -r '.share' <<<"$res") - if [ -z "$server_dist" ]; then - server_dist=$(jq -r '.server.d' <<<"$res") - fi + [ ! -z "$server_dist" ] || server_dist=$(jq -r '.server.d' <<<"$res") fi savetest "$start" "$stop" "$isp" "$from_ip" "$server_name" "$server_dist" "$server_ping" "$download" "$upload" "$share_url" @@ -184,49 +195,9 @@ run() { savetest "$start" "$stop" else if notInstalled speedtest && notInstalled speedtest-cli; then - if [ -f /usr/bin/speedtest ]; then - rm -f /usr/bin/speedtest - fi - - if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then - if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then - echo "Adding speedtest source for RPM..." - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash - fi - - if yum list speedtest | grep -q "Available Packages"; then - $PKG_MANAGER install -y speedtest - fi - elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then - echo "Adding speedtest source for DEB..." - if [ -e /etc/os-release ]; then - . /etc/os-release - local base="ubuntu debian" - local os=${ID} - local dist=${VERSION_CODENAME} - if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then - os=${ID_LIKE%% *} - [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) - dist=${UBUNTU_CODENAME} - [ -z "$dist" ] && dist=${VERSION_CODENAME} - fi - wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 - chmod +x /tmp/script.deb.sh - os=$os dist=$dist /tmp/script.deb.sh - rm -f /tmp/script.deb.sh - else - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash - fi - - sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list - apt-get update - fi - - if isAvailable speedtest; then - $PKG_MANAGER install -y speedtest - fi - fi + [ ! -f /usr/bin/speedtest ] || rm -f /usr/bin/speedtest + addSource + isAvailable speedtest && $PKG_MANAGER install -y speedtest || : elif ! notInstalled speedtest; then swaptest speedtest-cli speedtest else @@ -244,51 +215,12 @@ main() { exit $? fi - if [ ! -d /etc/pihole/speedtest ]; then - download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest - fi - + [ -d /etc/pihole/speedtest ] || download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) - if [ ! -f /usr/bin/speedtest ]; then - if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then - if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then - echo "Adding speedtest source for RPM..." - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash - fi - elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then - echo "Adding speedtest source for DEB..." - if [ -e /etc/os-release ]; then - . /etc/os-release - local base="ubuntu debian" - local os=${ID} - local dist=${VERSION_CODENAME} - if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then - os=${ID_LIKE%% *} - [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) - dist=${UBUNTU_CODENAME} - [ -z "$dist" ] && dist=${VERSION_CODENAME} - fi - wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 - chmod +x /tmp/script.deb.sh - os=$os dist=$dist /tmp/script.deb.sh - rm -f /tmp/script.deb.sh - else - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash - fi - sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list - apt-get update - fi - fi - - if isAvailable speedtest; then - $PKG_MANAGER install -y speedtest - elif isAvailable speedtest-cli; then - $PKG_MANAGER install -y speedtest-cli - else - librespeed - fi + if [ ! -f /usr/bin/speedtest ]; then + addSource + isAvailable speedtest && $PKG_MANAGER install -y speedtest || { isAvailable speedtest-cli && $PKG_MANAGER install -y speedtest-cli || librespeed; } fi echo "Running Test..." diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 870d0e4abd..4b8e8a311b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -623,10 +623,10 @@ schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh -# if "pihole -v" includes "N/A" or doesn't include "speedtest", download the mod -if [[ "\$(/usr/local/bin/pihole -v)" == *"N/A"* ]] || [[ "\$(/usr/local/bin/pihole -v)" != *"speedtest"* ]]; then - download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest - pihole updatechecker +# if "pihole -v" includes "N/A" or doesn't include "speedtest", get v +if [[ "\$(/usr/local/bin/pihole -v)" == *"N/A"* ]] || [[ "\$(/usr/local/bin/pihole -v)" != *"Speedtest"* ]]; then + [ -d /etc/pihole/speedtest ] || download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest + /usr/local/bin/pihole updatechecker fi # if schedule is set and interval is "nan", set the speedtest interval to the schedule From bed7fe63d10265718c0f4df2a00f04435828335a Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 9 Mar 2024 13:25:37 -0500 Subject: [PATCH 612/638] quiet install (#93) * reduce output --- advanced/Scripts/speedtestmod/mod.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 41e6e85cd9..926dec3ad2 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -135,8 +135,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then done if [ ${#missingPkgs[@]} -gt 0 ]; then - [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update - $PKG_MANAGER install -y "${missingPkgs[@]}" + [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update > /dev/null + $PKG_MANAGER install -y "${missingPkgs[@]}" > /dev/null fi download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole From dde7dca3f6e97cf7af0d4e19b844530205b424bd Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 13 Mar 2024 21:43:19 -0400 Subject: [PATCH 613/638] improve script (#94) * improve arg handling & dl func, try offline uninstall, consolidate code, fix docker hack fix, ensure unaliased cp --- advanced/Scripts/speedtestmod/mod.sh | 296 ++++++++++----------- advanced/Scripts/speedtestmod/speedtest.sh | 2 +- advanced/Scripts/webpage.sh | 7 +- 3 files changed, 149 insertions(+), 156 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 926dec3ad2..09235fa72e 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,16 +1,5 @@ #!/bin/bash - -getLocalVersion() { - local src=${1:-} - - if [ -z "$src" ]; then - echo "" - else - local localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 6) - [ "$localVersion" != "HEAD" ] || localVersion=$(pihole -v | grep "$src" | cut -d ' ' -f 7) - echo "$localVersion" - fi -} +aborted=0 download() { local path=$1 @@ -19,29 +8,39 @@ download() { local localVersion=${4:-} local branch="${5:-master}" local dest=$path/$name - local tags=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V) [ -d "$dest" ] && [ ! -d "$dest/.git" ] && mv -f "$dest" "$dest.old" || : [ -d "$dest" ] || git clone --depth=1 -b "$branch" "$url" "$dest" -q cd "$dest" git config --global --add safe.directory "$dest" - if [ "$url" != "old" ]; then + if [ "$aborted" == "0" ]; then git remote -v | grep -q "old" || git remote rename origin old git remote -v | grep -q "origin" && git remote remove origin git remote add -t "$branch" origin "$url" elif [ -d .git/refs/remotes/old ]; then git remote remove origin git remote rename old origin - git clean -ffdx + url=$(git remote get-url origin) + fi + + local tags=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V) + local latestTag=$(tail -n1 <<<"$tags") + local localTag=$latestTag + + if [[ "$localVersion" == *.* ]]; then + latestTag=$localVersion + localTag=$latestTag + elif [ ! -z "$localVersion" ]; then + localTag=$(pihole -v | grep "$localVersion" | cut -d ' ' -f 6) + [ "$localTag" != "HEAD" ] || localTag=$(pihole -v | grep "$localVersion" | cut -d ' ' -f 7) fi git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q - [[ "$localVersion" == *.* ]] && local latestTag=$localVersion || local latestTag=$(getLocalVersion "$localVersion") - [ "$url" != "old" ] && [[ "$url" != *"arevindh"* ]] && ! git remote -v | grep -q "old.*ipitio" && [[ "$localVersion" < "$latestTag" ]] && latestTag=$(awk -v lv="$localVersion" '$1 <= lv' <<< "$tags" | tail -n1) || latestTag=$(tail -n1 <<< "$tags") - [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]] && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ] && git fetch origin tag $latestTag --depth=1 -q && git -c advice.detachedHead=false checkout "$latestTag" -q + [ "$aborted" == "0" ] && { [[ "$url" != *"arevindh"* ]] && [[ "$url" != *"ipitio"* ]] && ! git remote -v | grep -q "old.*ipitio" && [[ "$localTag" < "$latestTag" ]] && latestTag=$(awk -v lv="$localTag" '$1 <= lv' <<<"$tags" | tail -n1) || :; } || latestTag=$localTag + [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]] && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ] && git fetch origin tag $latestTag --depth=1 -q && git -c advice.detachedHead=false checkout "$latestTag" -q || : cd .. } @@ -60,7 +59,6 @@ notInstalled() { # allow to source the above helper functions without running the whole script if [[ "${SKIP_MOD:-}" != true ]]; then - aborted=0 html_dir=/var/www/html core_dir=/etc/.pihole opt_dir=/opt/pihole @@ -82,31 +80,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then isEmpty() { db=$1 - [ -f $db ] && sqlite3 "$db" "select * from $db_table limit 1;" >/dev/null 2>&1 && [ ! -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ] && return 1 || return 0 - } - - manageHistory() { - if [ "${1:-}" == "db" ]; then - if [ -f $curr_db ] && ! isEmpty $curr_db; then - echo "Flushing Database..." - mv -f $curr_db $last_db - [ ! -f $etc_dir/last_speedtest ] || mv -f $etc_dir/last_speedtest $etc_dir/last_speedtest.old - - if [ -f /var/log/pihole/speedtest.log ]; then - mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old - rm -f $etc_dir/speedtest.log - fi - elif [ -f $last_db ]; then - echo "Restoring Database..." - mv -f $last_db $curr_db - [ ! -f $etc_dir/last_speedtest.old ] || mv -f $etc_dir/last_speedtest.old $etc_dir/last_speedtest - - if [ -f /var/log/pihole/speedtest.log.old ]; then - mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log - cp -af /var/log/pihole/speedtest.log $etc_dir/speedtest.log - fi - fi - fi + [ -f $db ] && sqlite3 "$db" "select * from $db_table limit 1;" &>/dev/null && [ ! -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ] && return 1 || return 0 } swapScripts() { @@ -117,112 +91,32 @@ if [[ "${SKIP_MOD:-}" != true ]]; then set -u } - installMod() { - echo "Installing Mod..." - - if [ ! -f /usr/local/bin/pihole ]; then - echo "Installing Pi-hole..." - curl -sSL https://install.pi-hole.net | sudo bash - fi - - local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) - local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") - local missingPkgs=() - - for pkg in "${PKGS[@]}"; do - notInstalled "$pkg" && missingPkgs+=("$pkg") || : - done - - if [ ${#missingPkgs[@]} -gt 0 ]; then - [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update > /dev/null - $PKG_MANAGER install -y "${missingPkgs[@]}" > /dev/null - fi - - download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole - swapScripts - cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ - pihole -a -s - download $html_dir admin https://github.com/arevindh/AdminLTE web - download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest - pihole updatechecker - } - - uninstall() { - if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then - echo "Restoring Pi-hole..." - pihole -a -s -1 - download $html_dir admin https://github.com/pi-hole/AdminLTE web - download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole - st_ver=$(getLocalVersion "speedtest") - rm -rf $etc_dir/speedtest - swapScripts - fi - - manageHistory ${1:-} - } - - purge() { - if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then - rm -f /etc/systemd/system/pihole-speedtest.service - rm -f /etc/systemd/system/pihole-speedtest.timer - systemctl daemon-reload - fi - - rm -rf "$html_dir"/*_admin - rm -rf $opt_dir/speedtestmod - rm -rf $etc_dir/mod - rm -f "$curr_wp".* - rm -f "$curr_db".* - rm -f "$curr_db"_* - rm -f $etc_dir/last_speedtest.* - isEmpty $curr_db && rm -f $curr_db || : - pihole updatechecker - } - - update() { - if [[ -d /run/systemd/system ]]; then - echo "Updating Pi-hole..." - PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up - else - echo "Systemd not found. Skipping Pi-hole update..." - fi - - if [ "${1:-}" == "un" ]; then - purge - exit 0 - fi - - installMod - } - abort() { echo "Process Aborting..." + aborted=1 if [ -d $core_dir/.git/refs/remotes/old ]; then - download /etc .pihole old Pi-hole + download /etc .pihole "" Pi-hole swapScripts if [ -d $core_dir/advanced/Scripts/speedtestmod ]; then - cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s fi fi - [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin old web - [ -d $etc_dir/speedtest ] && [ -d $etc_dir/speedtest/.git/refs/remotes/old ] && download $etc_dir speedtest old $st_ver || : - [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest && purge || : + [ -d $etc_dir/speedtest ] && [ -d $etc_dir/speedtest/.git/refs/remotes/old ] && download $etc_dir speedtest "" $st_ver || : + [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin "" web + [ -f $curr_wp ] && ! cat $curr_wp | grep -q SpeedTest && purge || : [ -f $last_db ] && [ ! -f $curr_db ] && mv $last_db $curr_db || : - aborted=1 printf "Please try again before reporting an issue.\n\n$(date)\n" } commit() { for dir in $core_dir $html_dir/admin $etc_dir/speedtest; do - if [ -d $dir/.git/refs/remotes/old ]; then - cd $dir - git remote -v | grep -q "old" && git remote remove old || : - fi + [ ! -d $dir ] && continue || cd $dir + ! git remote -v | grep -q "old" || git remote remove old + git clean -ffdx done printf "Done!\n\n$(date)\n" } @@ -246,24 +140,124 @@ if [[ "${SKIP_MOD:-}" != true ]]; then trap 'abort' INT TERM shopt -s dotglob - local db=$([ "$op" == "up" ] && echo "${3:-}" || [ "$op" == "un" ] && echo "${2:-}" || echo "$op") - case $op in - db) - manageHistory $db - ;; - un) - uninstall $db - purge - ;; - up) - uninstall $db - update ${2:-} - ;; - *) - uninstall $db - installMod - ;; - esac + local up=false + local un=false + local db=false + + for arg in "$@"; do + case $arg in + up) up=true ;; + un) un=true ;; + db) db=true ;; + esac + done + + if $db; then + if [ -f $curr_db ] && ! isEmpty $curr_db; then + echo "Flushing Database..." + mv -f $curr_db $last_db + [ ! -f $etc_dir/last_speedtest ] || mv -f $etc_dir/last_speedtest $etc_dir/last_speedtest.old + + if [ -f /var/log/pihole/speedtest.log ]; then + mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old + rm -f $etc_dir/speedtest.log + fi + elif [ -f $last_db ]; then + echo "Restoring Database..." + mv -f $last_db $curr_db + [ ! -f $etc_dir/last_speedtest.old ] || mv -f $etc_dir/last_speedtest.old $etc_dir/last_speedtest + + if [ -f /var/log/pihole/speedtest.log.old ]; then + mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log + \cp -af /var/log/pihole/speedtest.log $etc_dir/speedtest.log + fi + fi + fi + + if $up || $un || [ "$#" -eq 0 ]; then + local working_dir=$(pwd) + cd ~ + + if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then + echo "Restoring Pi-hole..." + pihole -a -s -1 + + if $un && [ -d $html_dir/admin.bak ]; then + [ -e $html_dir/admin ] && rm -rf $html_dir/admin + mv -f $html_dir/admin.bak $html_dir/admin + else + download $html_dir admin https://github.com/pi-hole/AdminLTE web + fi + + if $un && [ -d $core_dir.bak ]; then + [ -e $core_dir ] && rm -rf $core_dir + mv -f $core_dir.bak $core_dir + else + download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole + fi + + [ ! -d $etc_dir/speedtest ] || rm -rf $etc_dir/speedtest + st_ver=$(pihole -v -s | cut -d ' ' -f 6) + [ "$st_ver" != "HEAD" ] || st_ver=$(pihole -v -s | cut -d ' ' -f 7) + swapScripts + fi + + if $up; then + if [ -d /run/systemd/system ]; then + echo "Updating Pi-hole..." + PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up + else + echo "Systemd not found. Skipping Pi-hole update..." + fi + fi + + if $un; then + if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then + rm -f /etc/systemd/system/pihole-speedtest.service + rm -f /etc/systemd/system/pihole-speedtest.timer + systemctl daemon-reload + fi + + rm -rf $opt_dir/speedtestmod + rm -f "$curr_db".* + rm -f $etc_dir/last_speedtest.* + ! isEmpty $curr_db || rm -f $curr_db + else + if [ ! -f /usr/local/bin/pihole ]; then + echo "Installing Pi-hole..." + curl -sSL https://install.pi-hole.net | sudo bash + fi + + echo "Installing Mod..." + local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) + local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) + local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") + local missingPkgs=() + + for pkg in "${PKGS[@]}"; do + ! notInstalled "$pkg" || missingPkgs+=("$pkg") + done + + if [ ${#missingPkgs[@]} -gt 0 ]; then + [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update >/dev/null + $PKG_MANAGER install -y "${missingPkgs[@]}" &>/dev/null + fi + + [ ! -d $core_dir ] || \cp -af $core_dir $core_dir.bak + [ ! -d $html_dir/admin ] || \cp -af $html_dir/admin $html_dir/admin.bak + download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest + touch $etc_dir/speedtest/updated + download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole + swapScripts + \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + pihole -a -s + download $html_dir admin https://github.com/arevindh/AdminLTE web + fi + + pihole updatechecker + [ -d $working_dir ] && cd $working_dir + fi + exit 0 } diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index b52e2eaa71..0d04d9b485 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -47,7 +47,7 @@ savetest() { rm -f "$temp_file" chmod 644 /tmp/speedtest_results mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log - cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log + \cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log rm -f "$out" sqlite3 /etc/pihole/speedtest.db "$create_table" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 4b8e8a311b..8889beef25 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -612,6 +612,7 @@ generate_cron_schedule() { addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "$(echo "scale=3; $total_seconds / 3600" | bc)" fi + [ -d /opt/pihole/speedtestmod ] || return sudo bash -c "cat > $(printf %q "$schedule_script")" << EOF #!/bin/bash # Schedule script to handle complex cron schedules @@ -623,10 +624,8 @@ schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh -# if "pihole -v" includes "N/A" or doesn't include "speedtest", get v -if [[ "\$(/usr/local/bin/pihole -v)" == *"N/A"* ]] || [[ "\$(/usr/local/bin/pihole -v)" != *"Speedtest"* ]]; then - [ -d /etc/pihole/speedtest ] || download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest - /usr/local/bin/pihole updatechecker +if [ ! -f /etc/pihole/speedtest/updated ]; then + /usr/bin/tmux new-session -d "download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest ; touch /etc/pihole/speedtest/updated ; /usr/local/bin/pihole updatechecker" fi # if schedule is set and interval is "nan", set the speedtest interval to the schedule From cf42fb801dfb3df5c526eb936cfa0b5e2be094e7 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:24:11 -0400 Subject: [PATCH 614/638] slightly speed up install by using tar in lieu of cp, fix version check after uninstall (#95) --- advanced/Scripts/speedtestmod/mod.sh | 71 +++++++++++++++------------- advanced/Scripts/webpage.sh | 5 +- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 09235fa72e..f9bb79f304 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -72,8 +72,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then help() { echo "(Re)install Latest Speedtest Mod." echo "Usage: sudo $0 [up] [un] [db]" - echo "up - update the mod (and Pi-hole if not in Docker)" - echo "un - remove the mod (and any database backups)" + echo "up - (re)install the latest version of the mod and, if not in Docker, run Pi-hole's update script" + echo "un - uninstall the mod (and remove any database backups)" echo "db - flush the database (if it's not empty, otherwise restore it)" echo "If no option is specified, the latest version of the Mod will be (re)installed." } @@ -91,6 +91,28 @@ if [[ "${SKIP_MOD:-}" != true ]]; then set -u } + restore() { + [ -d $1.bak ] || return 1 + [ ! -e $1 ] || rm -rf $1 + mv -f $1.bak $1 + cd $1 + git tag -l | xargs git tag -d >/dev/null 2>&1 + git fetch --tags -f -q + } + + purge() { + if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then + rm -f /etc/systemd/system/pihole-speedtest.service + rm -f /etc/systemd/system/pihole-speedtest.timer + systemctl daemon-reload + fi + + rm -rf $opt_dir/speedtestmod + rm -f "$curr_db".* + rm -f $etc_dir/last_speedtest.* + ! isEmpty $curr_db || rm -f $curr_db + } + abort() { echo "Process Aborting..." aborted=1 @@ -113,7 +135,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then } commit() { - for dir in $core_dir $html_dir/admin $etc_dir/speedtest; do + for dir in $core_dir $html_dir/admin; do [ ! -d $dir ] && continue || cd $dir ! git remote -v | grep -q "old" || git remote remove old git clean -ffdx @@ -181,21 +203,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then echo "Restoring Pi-hole..." pihole -a -s -1 - - if $un && [ -d $html_dir/admin.bak ]; then - [ -e $html_dir/admin ] && rm -rf $html_dir/admin - mv -f $html_dir/admin.bak $html_dir/admin - else - download $html_dir admin https://github.com/pi-hole/AdminLTE web - fi - - if $un && [ -d $core_dir.bak ]; then - [ -e $core_dir ] && rm -rf $core_dir - mv -f $core_dir.bak $core_dir - else - download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole - fi - + [[ $un == true ]] && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE web + [[ $un == true ]] && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole [ ! -d $etc_dir/speedtest ] || rm -rf $etc_dir/speedtest st_ver=$(pihole -v -s | cut -d ' ' -f 6) [ "$st_ver" != "HEAD" ] || st_ver=$(pihole -v -s | cut -d ' ' -f 7) @@ -212,16 +221,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi if $un; then - if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then - rm -f /etc/systemd/system/pihole-speedtest.service - rm -f /etc/systemd/system/pihole-speedtest.timer - systemctl daemon-reload - fi - - rm -rf $opt_dir/speedtestmod - rm -f "$curr_db".* - rm -f $etc_dir/last_speedtest.* - ! isEmpty $curr_db || rm -f $curr_db + purge else if [ ! -f /usr/local/bin/pihole ]; then echo "Installing Pi-hole..." @@ -231,7 +231,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then echo "Installing Mod..." local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) - local PKGS=(bc sqlite3 jq tmux wget "php$PHP_VERSION-sqlite3") + local PKGS=(bc sqlite3 jq tar tmux wget "php$PHP_VERSION-sqlite3") local missingPkgs=() for pkg in "${PKGS[@]}"; do @@ -243,15 +243,20 @@ if [[ "${SKIP_MOD:-}" != true ]]; then $PKG_MANAGER install -y "${missingPkgs[@]}" &>/dev/null fi - [ ! -d $core_dir ] || \cp -af $core_dir $core_dir.bak - [ ! -d $html_dir/admin ] || \cp -af $html_dir/admin $html_dir/admin.bak - download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest - touch $etc_dir/speedtest/updated + for repo in $core_dir $html_dir/admin; do + if [ -d $repo ]; then + [ -d $repo.bak ] || mkdir -p $repo.bak + tar -C $repo -c . | tar -C $repo.bak -xp --overwrite + fi + done + download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole swapScripts \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s download $html_dir admin https://github.com/arevindh/AdminLTE web + download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest + touch $etc_dir/speedtest/updated # checkfile for Docker fi pihole updatechecker diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 8889beef25..349411ddcb 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -618,15 +618,12 @@ generate_cron_schedule() { # Schedule script to handle complex cron schedules last_run_file="/etc/pihole/last_speedtest" interval_seconds=$total_seconds - schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh -if [ ! -f /etc/pihole/speedtest/updated ]; then - /usr/bin/tmux new-session -d "download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest ; touch /etc/pihole/speedtest/updated ; /usr/local/bin/pihole updatechecker" -fi +[ -f /etc/pihole/speedtest/updated ] || /usr/bin/tmux new-session -d "download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest && touch /etc/pihole/speedtest/updated && /usr/local/bin/pihole updatechecker" # if schedule is set and interval is "nan", set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then From 9be7fe7fefbe3d1f800db96e7f91a0f78e809ccc Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 16 Mar 2024 00:35:53 -0400 Subject: [PATCH 615/638] refix docker hack fix (#96) --- advanced/Scripts/webpage.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 349411ddcb..c438f3e29c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -623,7 +623,11 @@ schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") SKIP_MOD=true source /opt/pihole/speedtestmod/mod.sh -[ -f /etc/pihole/speedtest/updated ] || /usr/bin/tmux new-session -d "download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest && touch /etc/pihole/speedtest/updated && /usr/local/bin/pihole updatechecker" +if [ ! -f /etc/pihole/speedtest/updated ]; then + download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest + touch /etc/pihole/speedtest/updated + /usr/local/bin/pihole updatechecker +fi # if schedule is set and interval is "nan", set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then From eb23fbf8796e63deda951b52af55d3969cc4bf44 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 16 Mar 2024 10:08:27 +0000 Subject: [PATCH 616/638] Bump actions/checkout from 4.1.1 to 4.1.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4.1.1...v4.1.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/stale.yml | 2 +- .github/workflows/sync-back-to-dev.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index fc82119413..9cfd8a61d6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -25,7 +25,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 095d7358bf..c6a581ffde 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -40,7 +40,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 - name: Remove 'stale' label run: gh issue edit ${{ github.event.issue.number }} --remove-label ${{ env.stale_label }} env: diff --git a/.github/workflows/sync-back-to-dev.yml b/.github/workflows/sync-back-to-dev.yml index e52d4ae9af..9b35a974d1 100644 --- a/.github/workflows/sync-back-to-dev.yml +++ b/.github/workflows/sync-back-to-dev.yml @@ -33,7 +33,7 @@ jobs: name: Syncing branches steps: - name: Checkout - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 - name: Opening pull request run: gh pr create -B development -H master --title 'Sync master back into development' --body 'Created by Github action' --label 'internal' env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fabf380eb1..d2282d2d62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 - name: Check scripts in repository are executable run: | @@ -64,7 +64,7 @@ jobs: DISTRO: ${{matrix.distro}} steps: - name: Checkout repository - uses: actions/checkout@v4.1.1 + uses: actions/checkout@v4.1.2 - name: Set up Python 3.10 uses: actions/setup-python@v5.0.0 From eb7daf4d2c5ca9f77b70f11c80a2b8b03ca65af5 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 27 Mar 2024 19:12:59 +0000 Subject: [PATCH 617/638] Fix file permission check in gravity.sh. Remove quotes that were added after complaints from shellcheck, this stopped the comparisson from working Signed-off-by: Adam Warner --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 86c7fc2381..ccb082e2ad 100755 --- a/gravity.sh +++ b/gravity.sh @@ -575,7 +575,7 @@ gravity_DownloadBlocklistFromUrl() { else # Check if the file has a+r permissions permissions=$(stat -c "%a" "$file_path") - if [[ $permissions == "??4" || $permissions == "??5" || $permissions == "??6" || $permissions == "??7" ]]; then + if [[ $permissions == *4 || $permissions == *5 || $permissions == *6 || $permissions == *7 ]]; then # Output that we are using the local file echo -e "${OVER} ${INFO} Using local file ${file_path}" else From d80fcf2e62e4610dea0249c3fe3b521f4da820fb Mon Sep 17 00:00:00 2001 From: Orazio <22700499+orazioedoardo@users.noreply.github.com> Date: Wed, 27 Mar 2024 22:10:12 +0100 Subject: [PATCH 618/638] More checks when downloading from file:// scheme Signed-off-by: Orazio <22700499+orazioedoardo@users.noreply.github.com> --- gravity.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index ccb082e2ad..636cde0dda 100755 --- a/gravity.sh +++ b/gravity.sh @@ -567,14 +567,14 @@ gravity_DownloadBlocklistFromUrl() { if [[ $url == "file://"* ]]; then # Get the file path file_path=$(echo "$url" | cut -d'/' -f3-) - # Check if the file exists - if [[ ! -e $file_path ]]; then + # Check if the file exists and is a regular file (i.e. not a socket, fifo, tty, block). Might still be a symlink. + if [[ ! -f $file_path ]]; then # Output that the file does not exist echo -e "${OVER} ${CROSS} ${file_path} does not exist" download=false else - # Check if the file has a+r permissions - permissions=$(stat -c "%a" "$file_path") + # Check if the file or a file referenced by the symlink has a+r permissions + permissions=$(stat -L -c "%a" "$file_path") if [[ $permissions == *4 || $permissions == *5 || $permissions == *6 || $permissions == *7 ]]; then # Output that we are using the local file echo -e "${OVER} ${INFO} Using local file ${file_path}" From 011a675f79c506009c910e373b9efdf28404a3ca Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 14 Apr 2024 01:57:14 +0000 Subject: [PATCH 619/638] Add options to script (#98) # Features * new options: backup,online,install,reinstall,testing,version,verbose,help # Enhancements * Use new dir to avoid docker hack # Fixes * download() supports tags and commits Please see the wiki for information about the options. --- advanced/Scripts/piholeDebug.sh | 2 +- advanced/Scripts/speedtestmod/mod.sh | 307 +++++++++++++++------ advanced/Scripts/speedtestmod/speedtest.sh | 1 - advanced/Scripts/updatecheck.sh | 6 +- advanced/Scripts/webpage.sh | 15 +- 5 files changed, 232 insertions(+), 99 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 4ee733ea4e..143ff9d76a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -72,7 +72,7 @@ HTML_DIRECTORY="/var/www/html" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" SHM_DIRECTORY="/dev/shm" ETC="/etc" -SPEEDTEST_GIT_DIRECTORY="/etc/pihole/speedtest" +SPEEDTEST_GIT_DIRECTORY="/etc/pihole-speedtest" # Files required by Pi-hole # https://discourse.pi-hole.net/t/what-files-does-pi-hole-use/1684 diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index f9bb79f304..b47d484571 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,5 +1,21 @@ #!/bin/bash aborted=0 +stable=true + +getTag() { + local tag="" + + if [ -d $1 ]; then + cd $1 + tag=$(git rev-parse HEAD 2>/dev/null) + cd - &>/dev/null + elif [ -x "$(command -v pihole)" ]; then + tag=$(pihole -v | grep "$1" | cut -d ' ' -f 6) + [ "$tag" != "HEAD" ] || tag=$(pihole -v | grep "$1" | cut -d ' ' -f 7) + fi + + echo $tag +} download() { local path=$1 @@ -15,11 +31,14 @@ download() { git config --global --add safe.directory "$dest" if [ "$aborted" == "0" ]; then - git remote -v | grep -q "old" || git remote rename origin old + if ! git remote -v | grep -q "old" && git remote -v | grep -q "origin"; then + git remote rename origin old + fi + git remote -v | grep -q "origin" && git remote remove origin git remote add -t "$branch" origin "$url" elif [ -d .git/refs/remotes/old ]; then - git remote remove origin + git remote -v | grep -q "origin" && git remote remove origin git remote rename old origin url=$(git remote get-url origin) fi @@ -28,19 +47,28 @@ download() { local latestTag=$(tail -n1 <<<"$tags") local localTag=$latestTag - if [[ "$localVersion" == *.* ]]; then - latestTag=$localVersion - localTag=$latestTag - elif [ ! -z "$localVersion" ]; then - localTag=$(pihole -v | grep "$localVersion" | cut -d ' ' -f 6) - [ "$localTag" != "HEAD" ] || localTag=$(pihole -v | grep "$localVersion" | cut -d ' ' -f 7) + if [ ! -z "$localVersion" ]; then + if [ "$localVersion" != "Pi-hole" ] && [ "$localVersion" != "web" ] && [ "$localVersion" != "speedtest" ]; then + latestTag=$localVersion + localTag=$latestTag + else + localTag=$(getTag "$localVersion") + fi fi git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q [ "$aborted" == "0" ] && { [[ "$url" != *"arevindh"* ]] && [[ "$url" != *"ipitio"* ]] && ! git remote -v | grep -q "old.*ipitio" && [[ "$localTag" < "$latestTag" ]] && latestTag=$(awk -v lv="$localTag" '$1 <= lv' <<<"$tags" | tail -n1) || :; } || latestTag=$localTag - [ "$branch" == "master" ] && [[ "$url" != *"ipitio"* ]] && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ] && git fetch origin tag $latestTag --depth=1 -q && git -c advice.detachedHead=false checkout "$latestTag" -q || : + local unstable=false + [[ "$url" != *"ipitio"* ]] || unstable=true + [[ "$url" == *"arevindh"* ]] && ! $stable && unstable=true || : + + if [ "$branch" == "master" ] && ! $unstable && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ]; then + [[ "$latestTag" == *.* ]] && git fetch origin tag $latestTag --depth=1 -q || git fetch origin $latestTag --depth=1 -q + git -c advice.detachedHead=false checkout "$latestTag" -q + fi + cd .. } @@ -57,37 +85,68 @@ notInstalled() { return 1 } +setCnf() { + grep -q "^$1=" $3 && sed -i "s|^$1=.*|$1=$2|" $3 || echo "$1=$2" >>$3 +} + # allow to source the above helper functions without running the whole script if [[ "${SKIP_MOD:-}" != true ]]; then html_dir=/var/www/html core_dir=/etc/.pihole opt_dir=/opt/pihole etc_dir=/etc/pihole + mod_dir=/etc/pihole-speedtest curr_wp=$opt_dir/webpage.sh curr_db=$etc_dir/speedtest.db last_db=$curr_db.old db_table="speedtest" - st_ver=$db_table + st_ver="" + core_ver="Pi-hole" + admin_ver="web" + org_core_ver=$core_ver + org_admin_ver=$admin_ver + mod_core_ver=$core_ver + mod_admin_ver=$admin_ver + cleanup=true + + set +u + SKIP_INSTALL=true + source "$core_dir/automated install/basic-install.sh" + set -u help() { - echo "(Re)install Latest Speedtest Mod." - echo "Usage: sudo $0 [up] [un] [db]" - echo "up - (re)install the latest version of the mod and, if not in Docker, run Pi-hole's update script" - echo "un - uninstall the mod (and remove any database backups)" - echo "db - flush the database (if it's not empty, otherwise restore it)" - echo "If no option is specified, the latest version of the Mod will be (re)installed." + echo "The Mod Script" + echo "Usage: sudo bash /path/to/mod.sh [options]" + echo " or: curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash [-s -- options]" + echo "(Re)install the latest release of the Speedtest Mod, and/or the following options:" + echo "" + echo "Options:" + echo " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" + echo " -b, --backup preserve stock Pi-hole files for faster offline restore" + echo " -o, --online force online restore of stock Pi-hole files even if a backup exists" + echo " -i, --install skip restore of stock Pi-hole (for when not updating Pi-hole nor switching repos)" + echo " -r, --reinstall keep current version of the mod, if installed" + echo " -t, --testing install the latest commit" + echo " -n, --uninstall, un remove the mod and its files, but keep the database" + echo " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" + echo " -v, --version display the version of the mod" + echo " -x, --verbose show the commands being run" + echo " -h, --help display this help message" + echo "" + echo "Examples:" + echo " sudo bash /opt/pihole/speedtestmod/mod.sh -ubo" + echo " sudo bash /opt/pihole/speedtestmod/mod.sh -i -r -d" + echo " sudo bash /opt/pihole/speedtestmod/mod.sh --uninstall" + echo " curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -u" } isEmpty() { - db=$1 - [ -f $db ] && sqlite3 "$db" "select * from $db_table limit 1;" &>/dev/null && [ ! -z "$(sqlite3 "$db" "select * from $db_table limit 1;")" ] && return 1 || return 0 + [ -f $1 ] && sqlite3 "$1" "select * from $db_table limit 1;" &>/dev/null && [ ! -z "$(sqlite3 "$1" "select * from $db_table limit 1;")" ] && return 1 || return 0 } swapScripts() { - SKIP_INSTALL=true set +u - source "$core_dir/automated install/basic-install.sh" - installScripts + installScripts >/dev/null 2>&1 set -u } @@ -108,73 +167,120 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi rm -rf $opt_dir/speedtestmod + rm -rf $core_dir.bak + rm -rf $html_dir/admin.bak + rm -rf $core_dir.mod + rm -rf $html_dir/admin.mod rm -f "$curr_db".* rm -f $etc_dir/last_speedtest.* ! isEmpty $curr_db || rm -f $curr_db } abort() { - echo "Process Aborting..." - aborted=1 - - if [ -d $core_dir/.git/refs/remotes/old ]; then - download /etc .pihole "" Pi-hole - swapScripts + if $cleanup; then + echo "Process Aborting..." + aborted=1 + [ ! -z "$st_ver" ] || st_ver="speedtest" + [ ! -z "$core_ver" ] || core_ver="Pi-hole" + [ ! -z "$admin_ver" ] || admin_ver="web" + + if [ -d $core_dir/.git/refs/remotes/old ]; then + download /etc .pihole "" $core_ver + swapScripts - if [ -d $core_dir/advanced/Scripts/speedtestmod ]; then - \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ - pihole -a -s + if [ -d $core_dir/advanced/Scripts/speedtestmod ]; then + \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + pihole -a -s + fi fi - fi - [ -d $etc_dir/speedtest ] && [ -d $etc_dir/speedtest/.git/refs/remotes/old ] && download $etc_dir speedtest "" $st_ver || : - [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin "" web - [ -f $curr_wp ] && ! cat $curr_wp | grep -q SpeedTest && purge || : - [ -f $last_db ] && [ ! -f $curr_db ] && mv $last_db $curr_db || : - printf "Please try again before reporting an issue.\n\n$(date)\n" + [ -d $mod_dir ] && [ -d $mod_dir/.git/refs/remotes/old ] && download $etc_dir speedtest "" $st_ver || : + [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin "" $admin_ver + [ -f $last_db ] && [ ! -f $curr_db ] && mv $last_db $curr_db || : + [ -f $curr_wp ] && ! cat $curr_wp | grep -q SpeedTest && purge || : + printf "Please try again before reporting an issue.\n\n$(date)\n" + fi } commit() { - for dir in $core_dir $html_dir/admin; do - [ ! -d $dir ] && continue || cd $dir - ! git remote -v | grep -q "old" || git remote remove old - git clean -ffdx - done - printf "Done!\n\n$(date)\n" + if $cleanup; then + for dir in $core_dir $html_dir/admin; do + [ ! -d $dir ] && continue || cd $dir + ! git remote -v | grep -q "old" || git remote remove old + git clean -ffdx + done + printf "Done!\n\n$(date)\n" + fi } main() { - printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" - local op=${1:-} - - if [ "$op" == "-h" ] || [ "$op" == "--help" ]; then - help - exit 0 - fi - - if [ $EUID != 0 ]; then - sudo "$0" "$@" - exit $? - fi - set -Eeuo pipefail - trap '[ "$?" -eq "0" ] && commit || abort' EXIT trap 'abort' INT TERM shopt -s dotglob - local up=false - local un=false - local db=false + local update=false + local backup=false + local online=false + local install=false + local reinstall=false + local uninstall=false + local database=false + local verbose=false + local dashes=0 + local SHORT=-uboirtndvxh + local LONG=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,help + declare -a EXTRA_ARGS + declare -a POSITIONAL + PARSED=$(getopt --options ${SHORT} --longoptions ${LONG} --name "$0" -- "$@") + eval set -- "${PARSED}" + + while [[ $# -gt 0 ]]; do + case "$1" in + -u | --update) update=true ;; + -b | --backup) backup=true ;; + -o | --online) online=true ;; + -i | --install) install=true ;; + -r | --reinstall) reinstall=true ;; + -t | --testing) stable=false ;; + -n | --uninstall) uninstall=true ;; + -d | --database) database=true ;; + -v | --version) + getTag $mod_dir + cleanup=false + exit 0 + ;; + -x | --verbose) verbose=true ;; + -h | --help) + help + cleanup=false + exit 0 + ;; + --) dashes=1 ;; + *) [[ $dashes -eq 0 ]] && POSITIONAL+=("$1") || EXTRA_ARGS+=("$1") ;; + esac + shift + done + + set -- "${POSITIONAL[@]}" for arg in "$@"; do case $arg in - up) up=true ;; - un) un=true ;; - db) db=true ;; + up) update=true ;; + un) uninstall=true ;; + db) database=true ;; + *) + help + cleanup=false + exit 0 + ;; esac done - if $db; then + trap '[ "$?" -eq "0" ] && commit || abort' EXIT + printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" + ! $verbose || set -x + + if $database; then if [ -f $curr_db ] && ! isEmpty $curr_db; then echo "Flushing Database..." mv -f $curr_db $last_db @@ -196,22 +302,33 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi fi - if $up || $un || [ "$#" -eq 0 ]; then + if ! $database || [ "$#" -gt 1 ]; then local working_dir=$(pwd) cd ~ - if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then - echo "Restoring Pi-hole..." + if $reinstall; then + echo "Reinstalling Mod..." + mod_core_ver=$(getTag $core_dir) + mod_admin_ver=$(getTag $html_dir/admin) + st_ver=$(getTag $mod_dir) + fi + + if ! $install && [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then + echo "Restoring Pi-hole$($online && echo " online..." || echo "...")" pihole -a -s -1 - [[ $un == true ]] && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE web - [[ $un == true ]] && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole Pi-hole - [ ! -d $etc_dir/speedtest ] || rm -rf $etc_dir/speedtest - st_ver=$(pihole -v -s | cut -d ' ' -f 6) - [ "$st_ver" != "HEAD" ] || st_ver=$(pihole -v -s | cut -d ' ' -f 7) + + if [ -f $mod_dir/cnf ]; then + org_core_ver=$(awk -F= -v r="$core_dir" '$1 == r {print $2}' $mod_dir/cnf) + org_admin_ver=$(awk -F= -v r="$html_dir/admin" '$1 == r {print $2}' $mod_dir/cnf) + fi + + ! $online && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE $org_admin_ver + ! $online && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole $org_core_ver + [ ! -d $mod_dir ] || rm -rf $mod_dir swapScripts fi - if $up; then + if ! $install && $update; then if [ -d /run/systemd/system ]; then echo "Updating Pi-hole..." PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up @@ -220,7 +337,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi fi - if $un; then + if ! $install && $uninstall; then + echo "Purging Mod..." purge else if [ ! -f /usr/local/bin/pihole ]; then @@ -228,7 +346,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then curl -sSL https://install.pi-hole.net | sudo bash fi - echo "Installing Mod..." + echo "Downloading Mod..." local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) local PKGS=(bc sqlite3 jq tar tmux wget "php$PHP_VERSION-sqlite3") @@ -243,20 +361,42 @@ if [[ "${SKIP_MOD:-}" != true ]]; then $PKG_MANAGER install -y "${missingPkgs[@]}" &>/dev/null fi + download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest $st_ver + + if $backup; then + download /etc .pihole.mod https://github.com/arevindh/pi-hole $mod_core_ver + download $html_dir admin.mod https://github.com/arevindh/AdminLTE $mod_admin_ver + echo "Backing up Pi-hole..." + fi + + local stockTag=$(getTag $mod_dir) + [ -f $mod_dir/cnf ] || touch $mod_dir/cnf + setCnf $mod_dir $stockTag $mod_dir/cnf + for repo in $core_dir $html_dir/admin; do if [ -d $repo ]; then - [ -d $repo.bak ] || mkdir -p $repo.bak - tar -C $repo -c . | tar -C $repo.bak -xp --overwrite + stockTag=$(getTag $repo) + setCnf $repo $stockTag $mod_dir/cnf + [ "$repo" == "$core_dir" ] && core_ver=$stockTag || admin_ver=$stockTag + + if $backup; then + if [ ! -d $repo.bak ] || [ "$(getTag $repo.bak)" != "$stockTag" ]; then + rm -rf $repo.bak + mv -f $repo $repo.bak + fi + + rm -rf $repo + mv -f $repo.mod $repo + fi fi done - download /etc .pihole https://github.com/arevindh/pi-hole Pi-hole + $backup || download /etc .pihole https://github.com/ipitio/pi-hole $mod_core_ver ipitio + echo "Installing Mod..." swapScripts \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s - download $html_dir admin https://github.com/arevindh/AdminLTE web - download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest - touch $etc_dir/speedtest/updated # checkfile for Docker + $backup || download $html_dir admin https://github.com/ipitio/AdminLTE $mod_admin_ver fi pihole updatechecker @@ -266,9 +406,14 @@ if [[ "${SKIP_MOD:-}" != true ]]; then exit 0 } + if [ $EUID != 0 ]; then + sudo "$0" "$@" + exit $? + fi + rm -f /tmp/pimod.log touch /tmp/pimod.log main "$@" 2>&1 | tee -a /tmp/pimod.log - mv -f /tmp/pimod.log /var/log/pihole/mod.log + $cleanup && mv -f /tmp/pimod.log /var/log/pihole/mod.log || rm -f /tmp/pimod.log exit $aborted fi diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 0d04d9b485..8d0c9be25e 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -215,7 +215,6 @@ main() { exit $? fi - [ -d /etc/pihole/speedtest ] || download $etc_dir speedtest https://github.com/arevindh/pihole-speedtest PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) if [ ! -f /usr/bin/speedtest ]; then diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 53128ed03c..26593f1d8d 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -143,13 +143,13 @@ fi # get Speedtest versions -SPEEDTEST_VERSION="$(get_local_version /etc/pihole/speedtest)" +SPEEDTEST_VERSION="$(get_local_version /etc/pihole-speedtest)" addOrEditKeyValPair "${VERSION_FILE}" "SPEEDTEST_VERSION" "${SPEEDTEST_VERSION}" -SPEEDTEST_BRANCH="$(get_local_branch /etc/pihole/speedtest)" +SPEEDTEST_BRANCH="$(get_local_branch /etc/pihole-speedtest)" addOrEditKeyValPair "${VERSION_FILE}" "SPEEDTEST_BRANCH" "${SPEEDTEST_BRANCH}" -SPEEDTEST_HASH="$(get_local_hash /etc/pihole/speedtest)" +SPEEDTEST_HASH="$(get_local_hash /etc/pihole-speedtest)" addOrEditKeyValPair "${VERSION_FILE}" "SPEEDTEST_HASH" "${SPEEDTEST_HASH}" GITHUB_SPEEDTEST_VERSION="$(get_remote_version pihole-speedtest)" diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index c438f3e29c..97db21c8dc 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -620,15 +620,6 @@ last_run_file="/etc/pihole/last_speedtest" interval_seconds=$total_seconds schedule=\$(grep "SPEEDTESTSCHEDULE" "$setupVars" | cut -f2 -d"=") -SKIP_MOD=true -source /opt/pihole/speedtestmod/mod.sh - -if [ ! -f /etc/pihole/speedtest/updated ]; then - download /etc/pihole speedtest https://github.com/arevindh/pihole-speedtest - touch /etc/pihole/speedtest/updated - /usr/local/bin/pihole updatechecker -fi - # if schedule is set and interval is "nan", set the speedtest interval to the schedule if [[ "\$interval_seconds" == "nan" ]]; then if [[ "\${schedule-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then @@ -650,10 +641,8 @@ if [[ -f "\$last_run_file" ]]; then fi fi -if [[ \$(tmux list-sessions 2>/dev/null | grep -c pimod) -eq 0 ]]; then - echo \$(date +%s) > "\$last_run_file" - /usr/bin/tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" -fi +echo \$(date +%s) > "\$last_run_file" +cat $speedtestfile | sudo bash EOF sudo chmod +x "$schedule_script" From dc4d706e8572ec7b1e44426007d9f22a9ae40373 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sun, 14 Apr 2024 07:22:37 +0000 Subject: [PATCH 620/638] fix -r and url (#99) --- advanced/Scripts/speedtestmod/mod.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index b47d484571..683d6cdf4f 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -23,6 +23,7 @@ download() { local url=$3 local localVersion=${4:-} local branch="${5:-master}" + local reinstall=${6:-false} local dest=$path/$name [ -d "$dest" ] && [ ! -d "$dest/.git" ] && mv -f "$dest" "$dest.old" || : @@ -31,10 +32,7 @@ download() { git config --global --add safe.directory "$dest" if [ "$aborted" == "0" ]; then - if ! git remote -v | grep -q "old" && git remote -v | grep -q "origin"; then - git remote rename origin old - fi - + ! git remote -v | grep -q "old" && git remote -v | grep -q "origin" && git remote rename origin old || : git remote -v | grep -q "origin" && git remote remove origin git remote add -t "$branch" origin "$url" elif [ -d .git/refs/remotes/old ]; then @@ -61,10 +59,11 @@ download() { git checkout -B "$branch" -q [ "$aborted" == "0" ] && { [[ "$url" != *"arevindh"* ]] && [[ "$url" != *"ipitio"* ]] && ! git remote -v | grep -q "old.*ipitio" && [[ "$localTag" < "$latestTag" ]] && latestTag=$(awk -v lv="$localTag" '$1 <= lv' <<<"$tags" | tail -n1) || :; } || latestTag=$localTag local unstable=false - [[ "$url" != *"ipitio"* ]] || unstable=true + [[ "$url" == *"ipitio"* ]] && $stable && unstable=true || : # invert -t for me [[ "$url" == *"arevindh"* ]] && ! $stable && unstable=true || : + ! $reinstall || unstable=false - if [ "$branch" == "master" ] && ! $unstable && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ]; then + if ! $unstable && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ]; then [[ "$latestTag" == *.* ]] && git fetch origin tag $latestTag --depth=1 -q || git fetch origin $latestTag --depth=1 -q git -c advice.detachedHead=false checkout "$latestTag" -q fi @@ -100,7 +99,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then curr_db=$etc_dir/speedtest.db last_db=$curr_db.old db_table="speedtest" - st_ver="" + st_ver="speedtest" core_ver="Pi-hole" admin_ver="web" org_core_ver=$core_ver @@ -361,11 +360,11 @@ if [[ "${SKIP_MOD:-}" != true ]]; then $PKG_MANAGER install -y "${missingPkgs[@]}" &>/dev/null fi - download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest $st_ver + download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest $st_ver "" $reinstall if $backup; then - download /etc .pihole.mod https://github.com/arevindh/pi-hole $mod_core_ver - download $html_dir admin.mod https://github.com/arevindh/AdminLTE $mod_admin_ver + download /etc .pihole.mod https://github.com/arevindh/pi-hole $mod_core_ver "" $reinstall + download $html_dir admin.mod https://github.com/arevindh/AdminLTE $mod_admin_ver "" $reinstall echo "Backing up Pi-hole..." fi @@ -391,12 +390,12 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi done - $backup || download /etc .pihole https://github.com/ipitio/pi-hole $mod_core_ver ipitio + $backup || download /etc .pihole https://github.com/arevindh/pi-hole $mod_core_ver "" $reinstall echo "Installing Mod..." swapScripts \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s - $backup || download $html_dir admin https://github.com/ipitio/AdminLTE $mod_admin_ver + $backup || download $html_dir admin https://github.com/arevindh/AdminLTE $mod_admin_ver "" $reinstall fi pihole updatechecker From 8a16a6cb6f97e74521ff59e222b6695ab93a4a91 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 15 Apr 2024 20:28:09 +0000 Subject: [PATCH 621/638] fix dl (#100) actually fix reinstall --- advanced/Scripts/speedtestmod/mod.sh | 185 ++++++++++++++------------- advanced/Scripts/updatecheck.sh | 14 +- 2 files changed, 108 insertions(+), 91 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 683d6cdf4f..590892a30d 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,71 +1,79 @@ #!/bin/bash -aborted=0 -stable=true getTag() { - local tag="" + local foundCommit="" if [ -d $1 ]; then cd $1 - tag=$(git rev-parse HEAD 2>/dev/null) + foundCommit=$(git rev-parse HEAD 2>/dev/null) cd - &>/dev/null elif [ -x "$(command -v pihole)" ]; then - tag=$(pihole -v | grep "$1" | cut -d ' ' -f 6) - [ "$tag" != "HEAD" ] || tag=$(pihole -v | grep "$1" | cut -d ' ' -f 7) + foundCommit=$(pihole -v | grep "$1" | cut -d ' ' -f 6) + [ "$foundCommit" != "HEAD" ] && [ "$foundCommit" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundCommit=$(pihole -v | grep "$1" | cut -d ' ' -f 7) fi - echo $tag + echo $foundCommit } download() { local path=$1 local name=$2 local url=$3 - local localVersion=${4:-} + local desiredVersion="${4:-}" local branch="${5:-master}" - local reinstall=${6:-false} + local snapToTag="${6:-true}" local dest=$path/$name + local aborting=false [ -d "$dest" ] && [ ! -d "$dest/.git" ] && mv -f "$dest" "$dest.old" || : [ -d "$dest" ] || git clone --depth=1 -b "$branch" "$url" "$dest" -q cd "$dest" git config --global --add safe.directory "$dest" - if [ "$aborted" == "0" ]; then + if [ ! -z "$desiredVersion" ]; then + local repos=("Pi-hole" "web" "speedtest") + + for repo in "${repos[@]}"; do + if [[ "$desiredVersion" == *"$repo"* ]]; then + aborting=true + break + fi + done + fi + + if ! $aborting; then ! git remote -v | grep -q "old" && git remote -v | grep -q "origin" && git remote rename origin old || : - git remote -v | grep -q "origin" && git remote remove origin + ! git remote -v | grep -q "origin" || git remote remove origin git remote add -t "$branch" origin "$url" - elif [ -d .git/refs/remotes/old ]; then - git remote -v | grep -q "origin" && git remote remove origin + elif git remote -v | grep -q "old"; then + ! git remote -v | grep -q "origin" || git remote remove origin git remote rename old origin - url=$(git remote get-url origin) fi - local tags=$(git ls-remote --tags "$url" | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V) - local latestTag=$(tail -n1 <<<"$tags") - local localTag=$latestTag + git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q + git reset --hard origin/"$branch" -q + git checkout -B "$branch" -q + git tag | xargs git tag -d >/dev/null 2>&1 + git fetch --tags -q + local currentCommit=$(getTag "$dest") - if [ ! -z "$localVersion" ]; then - if [ "$localVersion" != "Pi-hole" ] && [ "$localVersion" != "web" ] && [ "$localVersion" != "speedtest" ]; then - latestTag=$localVersion - localTag=$latestTag - else - localTag=$(getTag "$localVersion") + if [ -z "$desiredVersion" ]; then # if empty, get the latest version + url=$(git remote get-url origin) + [[ "$url" == *"ipitio"* ]] && snapToTag=$(echo "$snapToTag" | grep -q "true" && echo "false" || echo "true") + + if [ "$snapToTag" == "true" ]; then + local latestTag=$(git show-ref --tags | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) + [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentCommit fi + elif $aborting; then + desiredVersion=$(getTag "$desiredVersion") fi - git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q - git reset --hard origin/"$branch" -q - git checkout -B "$branch" -q - [ "$aborted" == "0" ] && { [[ "$url" != *"arevindh"* ]] && [[ "$url" != *"ipitio"* ]] && ! git remote -v | grep -q "old.*ipitio" && [[ "$localTag" < "$latestTag" ]] && latestTag=$(awk -v lv="$localTag" '$1 <= lv' <<<"$tags" | tail -n1) || :; } || latestTag=$localTag - local unstable=false - [[ "$url" == *"ipitio"* ]] && $stable && unstable=true || : # invert -t for me - [[ "$url" == *"arevindh"* ]] && ! $stable && unstable=true || : - ! $reinstall || unstable=false - - if ! $unstable && [ "$(git rev-parse HEAD)" != "$(git rev-parse $latestTag 2>/dev/null)" ]; then - [[ "$latestTag" == *.* ]] && git fetch origin tag $latestTag --depth=1 -q || git fetch origin $latestTag --depth=1 -q - git -c advice.detachedHead=false checkout "$latestTag" -q + [[ "$desiredVersion" != *.* ]] || desiredVersion=$(git show-ref --tags | grep $desiredVersion$ | awk '{print $1;}') + + if [ "$currentCommit" != "$desiredVersion" ]; then + git fetch origin --depth=1 $desiredVersion -q + git -c advice.detachedHead=false checkout $desiredVersion -q fi cd .. @@ -99,14 +107,11 @@ if [[ "${SKIP_MOD:-}" != true ]]; then curr_db=$etc_dir/speedtest.db last_db=$curr_db.old db_table="speedtest" - st_ver="speedtest" - core_ver="Pi-hole" - admin_ver="web" - org_core_ver=$core_ver - org_admin_ver=$admin_ver - mod_core_ver=$core_ver - mod_admin_ver=$admin_ver + st_ver="" + mod_core_ver="" + mod_admin_ver="" cleanup=true + aborted=0 set +u SKIP_INSTALL=true @@ -116,21 +121,22 @@ if [[ "${SKIP_MOD:-}" != true ]]; then help() { echo "The Mod Script" echo "Usage: sudo bash /path/to/mod.sh [options]" - echo " or: curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash [-s -- options]" + echo " or: curl -sSLN //link/to/mod.sh | sudo bash [-s -- options]" echo "(Re)install the latest release of the Speedtest Mod, and/or the following options:" echo "" echo "Options:" - echo " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" - echo " -b, --backup preserve stock Pi-hole files for faster offline restore" - echo " -o, --online force online restore of stock Pi-hole files even if a backup exists" - echo " -i, --install skip restore of stock Pi-hole (for when not updating Pi-hole nor switching repos)" - echo " -r, --reinstall keep current version of the mod, if installed" - echo " -t, --testing install the latest commit" - echo " -n, --uninstall, un remove the mod and its files, but keep the database" - echo " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" - echo " -v, --version display the version of the mod" - echo " -x, --verbose show the commands being run" - echo " -h, --help display this help message" + echo " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" + echo " -b, --backup preserve stock Pi-hole files for faster offline restore" + echo " -o, --online force online restore of stock Pi-hole files even if a backup exists" + echo " -i, --install skip restore of stock Pi-hole (for when not updating Pi-hole nor switching repos)" + echo " -r, --reinstall keep current version of the mod, if installed" + echo " -t, --testing install the latest commit" + echo " -n, --uninstall, un remove the mod and its files, but keep the database" + echo " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" + echo " -v, --version display the version of the mod" + echo " -x, --verbose show the commands being run" + echo " -c, --careless skip checking for missing dependencies" + echo " -h, --help display this help message" echo "" echo "Examples:" echo " sudo bash /opt/pihole/speedtestmod/mod.sh -ubo" @@ -179,12 +185,9 @@ if [[ "${SKIP_MOD:-}" != true ]]; then if $cleanup; then echo "Process Aborting..." aborted=1 - [ ! -z "$st_ver" ] || st_ver="speedtest" - [ ! -z "$core_ver" ] || core_ver="Pi-hole" - [ ! -z "$admin_ver" ] || admin_ver="web" if [ -d $core_dir/.git/refs/remotes/old ]; then - download /etc .pihole "" $core_ver + download /etc .pihole "" Pi-hole swapScripts if [ -d $core_dir/advanced/Scripts/speedtestmod ]; then @@ -193,8 +196,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi fi - [ -d $mod_dir ] && [ -d $mod_dir/.git/refs/remotes/old ] && download $etc_dir speedtest "" $st_ver || : - [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin "" $admin_ver + [ -d $mod_dir ] && [ -d $mod_dir/.git/refs/remotes/old ] && download /etc pihole-speedtest "" speedtest || : + [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin "" web [ -f $last_db ] && [ ! -f $curr_db ] && mv $last_db $curr_db || : [ -f $curr_wp ] && ! cat $curr_wp | grep -q SpeedTest && purge || : printf "Please try again before reporting an issue.\n\n$(date)\n" @@ -222,12 +225,14 @@ if [[ "${SKIP_MOD:-}" != true ]]; then local online=false local install=false local reinstall=false + local stable=true local uninstall=false local database=false local verbose=false + local chk_dep=true local dashes=0 - local SHORT=-uboirtndvxh - local LONG=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,help + local SHORT=-uboirtndvxch + local LONG=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,careless,help declare -a EXTRA_ARGS declare -a POSITIONAL PARSED=$(getopt --options ${SHORT} --longoptions ${LONG} --name "$0" -- "$@") @@ -249,6 +254,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then exit 0 ;; -x | --verbose) verbose=true ;; + -c | --careless) chk_dep=false ;; -h | --help) help cleanup=false @@ -316,13 +322,15 @@ if [[ "${SKIP_MOD:-}" != true ]]; then echo "Restoring Pi-hole$($online && echo " online..." || echo "...")" pihole -a -s -1 + local core_ver="" + local admin_ver="" if [ -f $mod_dir/cnf ]; then - org_core_ver=$(awk -F= -v r="$core_dir" '$1 == r {print $2}' $mod_dir/cnf) - org_admin_ver=$(awk -F= -v r="$html_dir/admin" '$1 == r {print $2}' $mod_dir/cnf) + core_ver=$(awk -F= -v r="$core_dir" '$1 == r {print $2}' $mod_dir/cnf) + admin_ver=$(awk -F= -v r="$html_dir/admin" '$1 == r {print $2}' $mod_dir/cnf) fi - ! $online && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE $org_admin_ver - ! $online && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole $org_core_ver + ! $online && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE "$admin_ver" + ! $online && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" [ ! -d $mod_dir ] || rm -rf $mod_dir swapScripts fi @@ -340,31 +348,35 @@ if [[ "${SKIP_MOD:-}" != true ]]; then echo "Purging Mod..." purge else - if [ ! -f /usr/local/bin/pihole ]; then - echo "Installing Pi-hole..." - curl -sSL https://install.pi-hole.net | sudo bash - fi + if $chk_dep; then + if [ ! -f /usr/local/bin/pihole ]; then + echo "Installing Pi-hole..." + curl -sSL https://install.pi-hole.net | sudo bash + fi - echo "Downloading Mod..." - local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) - local PKGS=(bc sqlite3 jq tar tmux wget "php$PHP_VERSION-sqlite3") - local missingPkgs=() + echo "Checking Dependencies..." + local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) + local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) + local PKGS=(bc sqlite3 jq tar tmux wget "php$PHP_VERSION-sqlite3") + local missingPkgs=() - for pkg in "${PKGS[@]}"; do - ! notInstalled "$pkg" || missingPkgs+=("$pkg") - done + for pkg in "${PKGS[@]}"; do + ! notInstalled "$pkg" || missingPkgs+=("$pkg") + done - if [ ${#missingPkgs[@]} -gt 0 ]; then - [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update >/dev/null - $PKG_MANAGER install -y "${missingPkgs[@]}" &>/dev/null + if [ ${#missingPkgs[@]} -gt 0 ]; then + [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update >/dev/null + echo "Installing Missing..." + $PKG_MANAGER install -y "${missingPkgs[@]}" + fi fi - download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest $st_ver "" $reinstall + echo "Swapping Repos..." + download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable if $backup; then - download /etc .pihole.mod https://github.com/arevindh/pi-hole $mod_core_ver "" $reinstall - download $html_dir admin.mod https://github.com/arevindh/AdminLTE $mod_admin_ver "" $reinstall + download /etc .pihole.mod https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable + download $html_dir admin.mod https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable echo "Backing up Pi-hole..." fi @@ -376,7 +388,6 @@ if [[ "${SKIP_MOD:-}" != true ]]; then if [ -d $repo ]; then stockTag=$(getTag $repo) setCnf $repo $stockTag $mod_dir/cnf - [ "$repo" == "$core_dir" ] && core_ver=$stockTag || admin_ver=$stockTag if $backup; then if [ ! -d $repo.bak ] || [ "$(getTag $repo.bak)" != "$stockTag" ]; then @@ -390,12 +401,12 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi done - $backup || download /etc .pihole https://github.com/arevindh/pi-hole $mod_core_ver "" $reinstall + $backup || download /etc .pihole https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable echo "Installing Mod..." swapScripts \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s - $backup || download $html_dir admin https://github.com/arevindh/AdminLTE $mod_admin_ver "" $reinstall + $backup || download $html_dir admin https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable fi pihole updatechecker diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 26593f1d8d..77607bfd4f 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -17,11 +17,17 @@ function get_local_branch() { function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - local_v=$(git tag --sort=-version:refname | head -n 1) - if [[ "${local_v}" == "vDev" ]]; then - local_v=$(git tag --sort=-version:refname | head -n 2 | tail -n 1) + + local local_commit=$(git rev-parse HEAD) + local local_vs=$(git show-ref --tags -d | grep "$local_commit" | awk '{print $2}' | grep -o 'v.*$' | sort -V) + + if [ -z "$local_vs" ]; then + echo "$local_commit" + else + local local_v=$(echo "$local_vs" | tail -n1) + [[ "$local_v" != "vDev" ]] || local_v=$(echo "$local_vs" | tail -n2 | head -n1) + echo "$local_v" fi - echo "${local_v}" || return 1 } function get_local_hash() { From a78cc09b71d789f2e98bf1780a9e0bac1778f6f6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 15 Apr 2024 21:11:43 +0000 Subject: [PATCH 622/638] use url again (#101) --- advanced/Scripts/speedtestmod/mod.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 590892a30d..fb55d498c5 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -50,6 +50,8 @@ download() { git remote rename old origin fi + url=$(git remote get-url origin) + [[ "$url" == *"ipitio"* ]] && snapToTag=$(echo "$snapToTag" | grep -q "true" && echo "false" || echo "true") git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q @@ -58,18 +60,15 @@ download() { local currentCommit=$(getTag "$dest") if [ -z "$desiredVersion" ]; then # if empty, get the latest version - url=$(git remote get-url origin) - [[ "$url" == *"ipitio"* ]] && snapToTag=$(echo "$snapToTag" | grep -q "true" && echo "false" || echo "true") - if [ "$snapToTag" == "true" ]; then - local latestTag=$(git show-ref --tags | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) + local latestTag=$(git ls-remote -t "$url" | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentCommit fi elif $aborting; then desiredVersion=$(getTag "$desiredVersion") fi - [[ "$desiredVersion" != *.* ]] || desiredVersion=$(git show-ref --tags | grep $desiredVersion$ | awk '{print $1;}') + [[ "$desiredVersion" != *.* ]] || desiredVersion=$(git ls-remote -t "$url" | grep $desiredVersion$ | awk '{print $1;}') if [ "$currentCommit" != "$desiredVersion" ]; then git fetch origin --depth=1 $desiredVersion -q From 0da107f95ecda4da2b01f642ef4882f072ad2985 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Mon, 15 Apr 2024 21:21:11 +0000 Subject: [PATCH 623/638] don't need to fetch tags (#102) --- advanced/Scripts/speedtestmod/mod.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index fb55d498c5..ac77610a59 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -55,8 +55,6 @@ download() { git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q - git tag | xargs git tag -d >/dev/null 2>&1 - git fetch --tags -q local currentCommit=$(getTag "$dest") if [ -z "$desiredVersion" ]; then # if empty, get the latest version From 434c8271b37399569dbdd88ff574d83aba285903 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:45:03 +0000 Subject: [PATCH 624/638] use cnf (#103) * improve reinstall * use cnf --- advanced/Scripts/speedtestmod/mod.sh | 85 +++++++++++++++------------- advanced/Scripts/updatecheck.sh | 15 ++--- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index ac77610a59..4d7227924b 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,18 +1,19 @@ #!/bin/bash -getTag() { - local foundCommit="" +getVersion() { + local foundVersion="" if [ -d $1 ]; then cd $1 - foundCommit=$(git rev-parse HEAD 2>/dev/null) + foundVersion=$(git tag --points-at) + [ -z "$foundVersion" ] && foundVersion=$(git rev-parse HEAD 2>/dev/null) || foundVersion=$(echo "$foundVersion" | sort -V | tail -n1) cd - &>/dev/null elif [ -x "$(command -v pihole)" ]; then - foundCommit=$(pihole -v | grep "$1" | cut -d ' ' -f 6) - [ "$foundCommit" != "HEAD" ] && [ "$foundCommit" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundCommit=$(pihole -v | grep "$1" | cut -d ' ' -f 7) + foundVersion=$(pihole -v | grep "$1" | cut -d ' ' -f 6) + [ "$foundVersion" != "HEAD" ] && [ "$foundVersion" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundVersion=$(pihole -v | grep "$1" | cut -d ' ' -f 7) fi - echo $foundCommit + echo $foundVersion } download() { @@ -55,20 +56,21 @@ download() { git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q - local currentCommit=$(getTag "$dest") + local currentVersion=$(getVersion "$dest") + [[ "$currentVersion" != *.* ]] || currentVersion=$(git ls-remote -t "$url" | grep $currentVersion$ | awk '{print $1;}') if [ -z "$desiredVersion" ]; then # if empty, get the latest version if [ "$snapToTag" == "true" ]; then local latestTag=$(git ls-remote -t "$url" | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) - [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentCommit + [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentVersion fi elif $aborting; then - desiredVersion=$(getTag "$desiredVersion") + desiredVersion=$(getVersion "$desiredVersion") fi [[ "$desiredVersion" != *.* ]] || desiredVersion=$(git ls-remote -t "$url" | grep $desiredVersion$ | awk '{print $1;}') - if [ "$currentCommit" != "$desiredVersion" ]; then + if [ "$currentVersion" != "$desiredVersion" ]; then git fetch origin --depth=1 $desiredVersion -q git -c advice.detachedHead=false checkout $desiredVersion -q fi @@ -90,7 +92,12 @@ notInstalled() { } setCnf() { - grep -q "^$1=" $3 && sed -i "s|^$1=.*|$1=$2|" $3 || echo "$1=$2" >>$3 + grep -q "^$1=" $3 || echo "$1=$2" >>$3 + [ "${4:-false}" == "true" ] || sed -i "s|^$1=.*|$1=$2|" $3 +} + +getCnf() { + awk -F= -v r="$2" '$1 == r {print $2}' $1 } # allow to source the above helper functions without running the whole script @@ -246,7 +253,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then -n | --uninstall) uninstall=true ;; -d | --database) database=true ;; -v | --version) - getTag $mod_dir + getVersion $mod_dir cleanup=false exit 0 ;; @@ -308,28 +315,30 @@ if [[ "${SKIP_MOD:-}" != true ]]; then local working_dir=$(pwd) cd ~ - if $reinstall; then - echo "Reinstalling Mod..." - mod_core_ver=$(getTag $core_dir) - mod_admin_ver=$(getTag $html_dir/admin) - st_ver=$(getTag $mod_dir) - fi + if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then + if $reinstall; then + echo "Reinstalling Mod..." + mod_core_ver=$(getCnf $mod_dir/cnf mod-$core_dir) + mod_admin_ver=$(getCnf $mod_dir/cnf mod-$html_dir/admin) + st_ver=$(getCnf $mod_dir/cnf mod-$mod_dir) + fi - if ! $install && [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then - echo "Restoring Pi-hole$($online && echo " online..." || echo "...")" - pihole -a -s -1 + if ! $install; then + echo "Restoring Pi-hole$($online && echo " online..." || echo "...")" + pihole -a -s -1 - local core_ver="" - local admin_ver="" - if [ -f $mod_dir/cnf ]; then - core_ver=$(awk -F= -v r="$core_dir" '$1 == r {print $2}' $mod_dir/cnf) - admin_ver=$(awk -F= -v r="$html_dir/admin" '$1 == r {print $2}' $mod_dir/cnf) - fi + local core_ver="" + local admin_ver="" + if [ -f $mod_dir/cnf ]; then + core_ver=$(getCnf $mod_dir/cnf org-$core_dir) + admin_ver=$(getCnf $mod_dir/cnf org-$html_dir/admin) + fi - ! $online && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE "$admin_ver" - ! $online && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" - [ ! -d $mod_dir ] || rm -rf $mod_dir - swapScripts + ! $online && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE "$admin_ver" + ! $online && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" + [ ! -d $mod_dir ] || rm -rf $mod_dir + swapScripts + fi fi if ! $install && $update; then @@ -370,6 +379,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then echo "Swapping Repos..." download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable + [ -f $mod_dir/cnf ] || touch $mod_dir/cnf + setCnf mod-$mod_dir "$(getVersion $mod_dir)" $mod_dir/cnf $reinstall if $backup; then download /etc .pihole.mod https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable @@ -377,17 +388,13 @@ if [[ "${SKIP_MOD:-}" != true ]]; then echo "Backing up Pi-hole..." fi - local stockTag=$(getTag $mod_dir) - [ -f $mod_dir/cnf ] || touch $mod_dir/cnf - setCnf $mod_dir $stockTag $mod_dir/cnf - for repo in $core_dir $html_dir/admin; do if [ -d $repo ]; then - stockTag=$(getTag $repo) - setCnf $repo $stockTag $mod_dir/cnf + local stockTag=$(getVersion $repo) + setCnf org-$repo $stockTag $mod_dir/cnf if $backup; then - if [ ! -d $repo.bak ] || [ "$(getTag $repo.bak)" != "$stockTag" ]; then + if [ ! -d $repo.bak ] || [ "$(getVersion $repo.bak)" != "$stockTag" ]; then rm -rf $repo.bak mv -f $repo $repo.bak fi @@ -404,6 +411,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s $backup || download $html_dir admin https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable + setCnf mod-$core_dir "$(getVersion $core_dir)" $mod_dir/cnf $reinstall + setCnf mod-$html_dir/admin "$(getVersion $html_dir/admin)" $mod_dir/cnf $reinstall fi pihole updatechecker diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 77607bfd4f..961a4033ae 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -8,6 +8,9 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. +SKIP_MOD=true +source /opt/pihole/speedtestmod/mod.sh + function get_local_branch() { # Return active branch cd "${1}" 2> /dev/null || return 1 @@ -17,17 +20,7 @@ function get_local_branch() { function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - - local local_commit=$(git rev-parse HEAD) - local local_vs=$(git show-ref --tags -d | grep "$local_commit" | awk '{print $2}' | grep -o 'v.*$' | sort -V) - - if [ -z "$local_vs" ]; then - echo "$local_commit" - else - local local_v=$(echo "$local_vs" | tail -n1) - [[ "$local_v" != "vDev" ]] || local_v=$(echo "$local_vs" | tail -n2 | head -n1) - echo "$local_v" - fi + getCnf /etc/pihole-speedtest/cnf mod-$1 } function get_local_hash() { From 54fcf48f9c7349d7ff4929913dac02dffc801c00 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:51:52 +0000 Subject: [PATCH 625/638] better getCnf (#104) --- advanced/Scripts/speedtestmod/mod.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 4d7227924b..27d67b9638 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -97,7 +97,9 @@ setCnf() { } getCnf() { - awk -F= -v r="$2" '$1 == r {print $2}' $1 + local value=$(grep "^$2=" $1 | cut -d '=' -f 2) + [ -z "$value" ] && value=$(getVersion $2) + echo $value } # allow to source the above helper functions without running the whole script From 3a18e60684066d5e757c4e8603529f3ba71b816d Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 16 Apr 2024 00:59:50 +0000 Subject: [PATCH 626/638] strip prefix (#105) --- advanced/Scripts/speedtestmod/mod.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 27d67b9638..e5673653c1 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -98,7 +98,7 @@ setCnf() { getCnf() { local value=$(grep "^$2=" $1 | cut -d '=' -f 2) - [ -z "$value" ] && value=$(getVersion $2) + [ -z "$value" ] && value=$(getVersion $(echo $2 | sed 's/^mod-//;s/^org-//')) echo $value } From 85dab1c916904a8f7b4cf8599815335a8a348075 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 16 Apr 2024 10:06:52 +0000 Subject: [PATCH 627/638] fix reinstall, uninstall, and updatecheck (#106) * flip condition * better condition * fix reinstall and uninstall --- advanced/Scripts/speedtestmod/mod.sh | 69 ++++++++++++++++++---------- advanced/Scripts/updatecheck.sh | 14 +++--- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index e5673653c1..d8e047e734 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -5,12 +5,18 @@ getVersion() { if [ -d $1 ]; then cd $1 - foundVersion=$(git tag --points-at) - [ -z "$foundVersion" ] && foundVersion=$(git rev-parse HEAD 2>/dev/null) || foundVersion=$(echo "$foundVersion" | sort -V | tail -n1) + local tags=$(git ls-remote -t origin) + foundVersion=$(git rev-parse HEAD 2>/dev/null) + + if [ -z "${2:-}" ]; then + ! grep -q "$foundVersion" <<<"$tags" || foundVersion=$(grep "$foundVersion" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + fi + cd - &>/dev/null elif [ -x "$(command -v pihole)" ]; then - foundVersion=$(pihole -v | grep "$1" | cut -d ' ' -f 6) - [ "$foundVersion" != "HEAD" ] && [ "$foundVersion" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundVersion=$(pihole -v | grep "$1" | cut -d ' ' -f 7) + local versions=$(pihole -v | grep "$1") + foundVersion=$(cut -d ' ' -f 6 <<<"$versions") + [ "$foundVersion" != "HEAD" ] && [ "$foundVersion" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundVersion=$(cut -d ' ' -f 7 <<<"$versions") fi echo $foundVersion @@ -31,7 +37,7 @@ download() { cd "$dest" git config --global --add safe.directory "$dest" - if [ ! -z "$desiredVersion" ]; then + if [ ! -z "$desiredVersion" ] && [[ "$desiredVersion" != *.* ]]; then local repos=("Pi-hole" "web" "speedtest") for repo in "${repos[@]}"; do @@ -49,32 +55,35 @@ download() { elif git remote -v | grep -q "old"; then ! git remote -v | grep -q "origin" || git remote remove origin git remote rename old origin + url=$(git remote get-url origin) fi - url=$(git remote get-url origin) - [[ "$url" == *"ipitio"* ]] && snapToTag=$(echo "$snapToTag" | grep -q "true" && echo "false" || echo "true") + [[ "$url" == *"ipitio"* ]] && snapToTag=$(grep -q "true" <<<"$snapToTag" && echo "false" || echo "true") git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q local currentVersion=$(getVersion "$dest") - [[ "$currentVersion" != *.* ]] || currentVersion=$(git ls-remote -t "$url" | grep $currentVersion$ | awk '{print $1;}') + local tags=$(git ls-remote -t origin) + + if [[ "$currentVersion" == *.* ]]; then + grep -q "$currentVersion$" <<<"$tags" && currentVersion=$(grep "$currentVersion$" <<<"$tags" | awk '{print $1;}') || $currentVersion $(git rev-parse origin/$branch) + fi if [ -z "$desiredVersion" ]; then # if empty, get the latest version if [ "$snapToTag" == "true" ]; then - local latestTag=$(git ls-remote -t "$url" | awk -F/ '{print $3}' | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) + local latestTag=$(awk -F/ '{print $3}' <<<"$tags" | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentVersion fi elif $aborting; then desiredVersion=$(getVersion "$desiredVersion") fi - [[ "$desiredVersion" != *.* ]] || desiredVersion=$(git ls-remote -t "$url" | grep $desiredVersion$ | awk '{print $1;}') - - if [ "$currentVersion" != "$desiredVersion" ]; then - git fetch origin --depth=1 $desiredVersion -q - git -c advice.detachedHead=false checkout $desiredVersion -q + if [[ "$desiredVersion" == *.* ]]; then + grep -q "$desiredVersion$" <<<"$tags" && desiredVersion=$(grep "$desiredVersion$" <<<"$tags" | awk '{print $1;}') || desiredVersion=$currentVersion fi + git fetch origin --depth=1 $desiredVersion -q + git -c advice.detachedHead=false checkout $desiredVersion -q cd .. } @@ -97,8 +106,17 @@ setCnf() { } getCnf() { + local keydir=$(echo $2 | sed 's/^mod-//;s/^org-//') local value=$(grep "^$2=" $1 | cut -d '=' -f 2) - [ -z "$value" ] && value=$(getVersion $(echo $2 | sed 's/^mod-//;s/^org-//')) + [ ! -z "$value" ] || value=$(getVersion $keydir "${3:-}") + + if [ ! -z "${3:-}" ] && [[ "$value" == *.* ]]; then + cd $keydir + local tags=$(git ls-remote -t origin) + grep -q "$value$" <<<"$tags" && ver=$(grep "$value$" <<<"$tags" | awk '{print $1;}') || value=$(git rev-parse HEAD) + cd - &>/dev/null + fi + echo $value } @@ -134,16 +152,18 @@ if [[ "${SKIP_MOD:-}" != true ]]; then echo " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" echo " -b, --backup preserve stock Pi-hole files for faster offline restore" echo " -o, --online force online restore of stock Pi-hole files even if a backup exists" - echo " -i, --install skip restore of stock Pi-hole (for when not updating Pi-hole nor switching repos)" - echo " -r, --reinstall keep current version of the mod, if installed" + echo " -i, --install skip restore of stock Pi-hole*" + echo " -r, --reinstall keep current version of the mod, if installed*" echo " -t, --testing install the latest commit" echo " -n, --uninstall, un remove the mod and its files, but keep the database" echo " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" echo " -v, --version display the version of the mod" echo " -x, --verbose show the commands being run" - echo " -c, --careless skip checking for missing dependencies" + echo " -c, --careless skip check for missing dependencies" echo " -h, --help display this help message" echo "" + echo " *for when not updating Pi-hole nor switching repos" + echo "" echo "Examples:" echo " sudo bash /opt/pihole/speedtestmod/mod.sh -ubo" echo " sudo bash /opt/pihole/speedtestmod/mod.sh -i -r -d" @@ -319,10 +339,11 @@ if [[ "${SKIP_MOD:-}" != true ]]; then if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then if $reinstall; then - echo "Reinstalling Mod..." - mod_core_ver=$(getCnf $mod_dir/cnf mod-$core_dir) - mod_admin_ver=$(getCnf $mod_dir/cnf mod-$html_dir/admin) - st_ver=$(getCnf $mod_dir/cnf mod-$mod_dir) + # if hashes of current and stored versions are the same, use stored version, else use the current version + # since versions could be tags or commit hashes, and commits can have multiple tags + [ "$(getVersion $core_dir hash)" == "$(getCnf $mod_dir/cnf mod-$core_dir hash)" ] && mod_core_ver=$(getCnf $mod_dir/cnf mod-$core_dir) || mod_core_ver=$(getVersion $core_dir) + [ "$(getVersion $html_dir/admin hash)" == "$(getCnf $mod_dir/cnf mod-$html_dir/admin hash)" ] && mod_admin_ver=$(getCnf $mod_dir/cnf mod-$html_dir/admin) || mod_admin_ver=$(getVersion $html_dir/admin) + [ "$(getVersion $mod_dir hash)" == "$(getCnf $mod_dir/cnf mod-$mod_dir hash)" ] && st_ver=$(getCnf $mod_dir/cnf mod-$mod_dir) || st_ver=$(getVersion $mod_dir) fi if ! $install; then @@ -379,7 +400,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi fi - echo "Swapping Repos..." + echo "Patching Repos..." download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable [ -f $mod_dir/cnf ] || touch $mod_dir/cnf setCnf mod-$mod_dir "$(getVersion $mod_dir)" $mod_dir/cnf $reinstall @@ -408,7 +429,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then done $backup || download /etc .pihole https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable - echo "Installing Mod..." + $reinstall && echo "Reinstalling Mod..." || echo "Installing Mod..." swapScripts \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 961a4033ae..13760d8504 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -8,9 +8,6 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -SKIP_MOD=true -source /opt/pihole/speedtestmod/mod.sh - function get_local_branch() { # Return active branch cd "${1}" 2> /dev/null || return 1 @@ -20,7 +17,10 @@ function get_local_branch() { function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - getCnf /etc/pihole-speedtest/cnf mod-$1 + local tags=$(git ls-remote -t origin) + local foundVersion=$(git rev-parse HEAD 2>/dev/null) + ! grep -q "$foundVersion" <<<"$tags" || foundVersion=$(grep "$foundVersion" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + echo "${foundVersion}" } function get_local_hash() { @@ -29,7 +29,7 @@ function get_local_hash() { } function get_remote_version() { - if [[ "${1}" == "docker-pi-hole" ]]; then + if [ "${1}" == "docker-pi-hole" ] || [ "${1}" == "FTL" ]; then curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 else curl -s "https://api.github.com/repos/arevindh/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || { curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1; } @@ -104,10 +104,10 @@ if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then WEB_HASH="$(get_local_hash /var/www/html/admin)" addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" - GITHUB_WEB_VERSION="$(get_remote_version web)" + GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" - GITHUB_WEB_HASH="$(get_remote_hash web "${WEB_BRANCH}")" + GITHUB_WEB_HASH="$(get_remote_hash AdminLTE "${WEB_BRANCH}")" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}" fi From 30228af19e1638977ba001cebb4fd9fd8c333366 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 16 Apr 2024 10:27:38 +0000 Subject: [PATCH 628/638] improve grep (#107) --- advanced/Scripts/updatecheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 13760d8504..5716f4b5ba 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -19,7 +19,7 @@ function get_local_version() { cd "${1}" 2> /dev/null || return 1 local tags=$(git ls-remote -t origin) local foundVersion=$(git rev-parse HEAD 2>/dev/null) - ! grep -q "$foundVersion" <<<"$tags" || foundVersion=$(grep "$foundVersion" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + ! grep -q "^$foundVersion" <<<"$tags" || foundVersion=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) echo "${foundVersion}" } From 84d3dc3366369ba0f4c3530171a9e0aa7ed04a05 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:13:01 +0000 Subject: [PATCH 629/638] improve updatecheck (#108) * improve grep * fix get_local_branch --- advanced/Scripts/updatecheck.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 5716f4b5ba..3eec092b96 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -11,7 +11,8 @@ function get_local_branch() { # Return active branch cd "${1}" 2> /dev/null || return 1 - git rev-parse --abbrev-ref HEAD || return 1 + local foundBranch=$(git show-ref --heads | grep "$(git rev-parse HEAD)" | awk '{print $2;}' | cut -d '/' -f 3) + echo "${foundBranch:-HEAD}" } function get_local_version() { @@ -36,7 +37,6 @@ function get_remote_version() { fi } - function get_remote_hash(){ git ls-remote "https://github.com/arevindh/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || { git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || return 1; } } From 8aff36cbf04875425d42e549f156c6d47eb4e635 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:51:29 +0000 Subject: [PATCH 630/638] put head check back (#109) --- advanced/Scripts/speedtestmod/mod.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index d8e047e734..b2ff446893 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -82,8 +82,11 @@ download() { grep -q "$desiredVersion$" <<<"$tags" && desiredVersion=$(grep "$desiredVersion$" <<<"$tags" | awk '{print $1;}') || desiredVersion=$currentVersion fi - git fetch origin --depth=1 $desiredVersion -q - git -c advice.detachedHead=false checkout $desiredVersion -q + if [ "$(git rev-parse HEAD)" != "$desiredVersion" ]; then + git fetch origin --depth=1 $desiredVersion -q + git reset --hard $desiredVersion -q + fi + cd .. } From bc6dfc555c206606f92521c52cfe9607313758c6 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:33:52 +0000 Subject: [PATCH 631/638] hashes deserve porcelain (#110) Improve logic around hashes. --- advanced/Scripts/speedtestmod/mod.sh | 117 +++++++++++++++------------ advanced/Scripts/updatecheck.sh | 19 +++-- 2 files changed, 78 insertions(+), 58 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index b2ff446893..d469c70144 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -5,18 +5,23 @@ getVersion() { if [ -d $1 ]; then cd $1 - local tags=$(git ls-remote -t origin) - foundVersion=$(git rev-parse HEAD 2>/dev/null) + foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') if [ -z "${2:-}" ]; then - ! grep -q "$foundVersion" <<<"$tags" || foundVersion=$(grep "$foundVersion" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + local tags=$(git ls-remote -t origin) + local foundTag=$foundVersion + ! grep -q "$foundVersion" <<<"$tags" || foundTag=$(grep "$foundVersion" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + [ -z "$foundTag" ] || foundVersion=$foundTag fi cd - &>/dev/null elif [ -x "$(command -v pihole)" ]; then local versions=$(pihole -v | grep "$1") foundVersion=$(cut -d ' ' -f 6 <<<"$versions") - [ "$foundVersion" != "HEAD" ] && [ "$foundVersion" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundVersion=$(cut -d ' ' -f 7 <<<"$versions") + + if [[ "$foundVersion" != *.* ]]; then + [ "$foundVersion" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundVersion=$(cut -d ' ' -f 7 <<<"$versions") + fi fi echo $foundVersion @@ -62,27 +67,23 @@ download() { git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q - local currentVersion=$(getVersion "$dest") + local currentHash=$(getVersion "$dest" hash) local tags=$(git ls-remote -t origin) - if [[ "$currentVersion" == *.* ]]; then - grep -q "$currentVersion$" <<<"$tags" && currentVersion=$(grep "$currentVersion$" <<<"$tags" | awk '{print $1;}') || $currentVersion $(git rev-parse origin/$branch) - fi - if [ -z "$desiredVersion" ]; then # if empty, get the latest version if [ "$snapToTag" == "true" ]; then local latestTag=$(awk -F/ '{print $3}' <<<"$tags" | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) - [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentVersion + [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentHash fi elif $aborting; then - desiredVersion=$(getVersion "$desiredVersion") + desiredVersion=$(getVersion "$desiredVersion" hash) fi if [[ "$desiredVersion" == *.* ]]; then - grep -q "$desiredVersion$" <<<"$tags" && desiredVersion=$(grep "$desiredVersion$" <<<"$tags" | awk '{print $1;}') || desiredVersion=$currentVersion + grep -q "$desiredVersion$" <<<"$tags" && desiredVersion=$(grep "$desiredVersion$" <<<"$tags" | awk '{print $1;}') || desiredVersion=$currentHash fi - if [ "$(git rev-parse HEAD)" != "$desiredVersion" ]; then + if [ "$currentHash" != "$desiredVersion" ]; then git fetch origin --depth=1 $desiredVersion -q git reset --hard $desiredVersion -q fi @@ -146,32 +147,36 @@ if [[ "${SKIP_MOD:-}" != true ]]; then set -u help() { - echo "The Mod Script" - echo "Usage: sudo bash /path/to/mod.sh [options]" - echo " or: curl -sSLN //link/to/mod.sh | sudo bash [-s -- options]" - echo "(Re)install the latest release of the Speedtest Mod, and/or the following options:" - echo "" - echo "Options:" - echo " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" - echo " -b, --backup preserve stock Pi-hole files for faster offline restore" - echo " -o, --online force online restore of stock Pi-hole files even if a backup exists" - echo " -i, --install skip restore of stock Pi-hole*" - echo " -r, --reinstall keep current version of the mod, if installed*" - echo " -t, --testing install the latest commit" - echo " -n, --uninstall, un remove the mod and its files, but keep the database" - echo " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" - echo " -v, --version display the version of the mod" - echo " -x, --verbose show the commands being run" - echo " -c, --careless skip check for missing dependencies" - echo " -h, --help display this help message" - echo "" - echo " *for when not updating Pi-hole nor switching repos" - echo "" - echo "Examples:" - echo " sudo bash /opt/pihole/speedtestmod/mod.sh -ubo" - echo " sudo bash /opt/pihole/speedtestmod/mod.sh -i -r -d" - echo " sudo bash /opt/pihole/speedtestmod/mod.sh --uninstall" - echo " curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -u" + local helpText=( + "The Mod Script" + "Usage: sudo bash /path/to/mod.sh [options]" + " or: curl -sSLN //link/to/mod.sh | sudo bash [-s -- options]" + "(Re)install the latest release of the Speedtest Mod, and/or the following options:" + "" + "Options:" + " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" + " -b, --backup preserve stock Pi-hole files for faster offline restore" + " -o, --online force online restore of stock Pi-hole files even if a backup exists" + " -i, --install skip restore of stock Pi-hole*" + " -r, --reinstall keep current version of the mod, if installed*" + " -t, --testing install the latest commit" + " -n, --uninstall, un remove the mod and its files, but keep the database" + " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" + " -v, --version display the version of the mod" + " -x, --verbose show the commands being run" + " -c, --continuous skip check for missing dependencies" + " -h, --help display this help message" + "" + " *for when not updating Pi-hole nor switching repos" + "" + "Examples:" + " sudo bash /opt/pihole/speedtestmod/mod.sh -ubo" + " sudo bash /opt/pihole/speedtestmod/mod.sh -i -r -d" + " sudo bash /opt/pihole/speedtestmod/mod.sh --uninstall" + " curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -u" + ) + + printf "%s\n" "${helpText[@]}" } isEmpty() { @@ -261,7 +266,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then local chk_dep=true local dashes=0 local SHORT=-uboirtndvxch - local LONG=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,careless,help + local LONG=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,continuous,help declare -a EXTRA_ARGS declare -a POSITIONAL PARSED=$(getopt --options ${SHORT} --longoptions ${LONG} --name "$0" -- "$@") @@ -283,7 +288,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then exit 0 ;; -x | --verbose) verbose=true ;; - -c | --careless) chk_dep=false ;; + -c | --continuous) chk_dep=false ;; -h | --help) help cleanup=false @@ -342,11 +347,18 @@ if [[ "${SKIP_MOD:-}" != true ]]; then if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then if $reinstall; then - # if hashes of current and stored versions are the same, use stored version, else use the current version - # since versions could be tags or commit hashes, and commits can have multiple tags - [ "$(getVersion $core_dir hash)" == "$(getCnf $mod_dir/cnf mod-$core_dir hash)" ] && mod_core_ver=$(getCnf $mod_dir/cnf mod-$core_dir) || mod_core_ver=$(getVersion $core_dir) - [ "$(getVersion $html_dir/admin hash)" == "$(getCnf $mod_dir/cnf mod-$html_dir/admin hash)" ] && mod_admin_ver=$(getCnf $mod_dir/cnf mod-$html_dir/admin) || mod_admin_ver=$(getVersion $html_dir/admin) - [ "$(getVersion $mod_dir hash)" == "$(getCnf $mod_dir/cnf mod-$mod_dir hash)" ] && st_ver=$(getCnf $mod_dir/cnf mod-$mod_dir) || st_ver=$(getVersion $mod_dir) + for repo in $core_dir $html_dir/admin $mod_dir; do + if [ -d $repo ]; then + local hashTag=$(getVersion $repo) # if hashes are the same, we may be on an older tag + [ "$(getVersion $repo hash)" != "$(getCnf $mod_dir/cnf mod-$repo hash)" ] || hashTag=$(getCnf $mod_dir/cnf mod-$repo) + + case "$repo" in + "$core_dir") mod_core_ver=$hashTag ;; + "$html_dir/admin") mod_admin_ver=$hashTag ;; + "$mod_dir") st_ver=$hashTag ;; + esac + fi + done fi if ! $install; then @@ -403,17 +415,17 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi fi - echo "Patching Repos..." - download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable - [ -f $mod_dir/cnf ] || touch $mod_dir/cnf - setCnf mod-$mod_dir "$(getVersion $mod_dir)" $mod_dir/cnf $reinstall - if $backup; then + echo "Backing up Pi-hole..." download /etc .pihole.mod https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable download $html_dir admin.mod https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable - echo "Backing up Pi-hole..." fi + $reinstall && echo "Reinstalling Mod..." || echo "Installing Mod..." + download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable + [ -f $mod_dir/cnf ] || touch $mod_dir/cnf + setCnf mod-$mod_dir "$(getVersion $mod_dir)" $mod_dir/cnf $reinstall + for repo in $core_dir $html_dir/admin; do if [ -d $repo ]; then local stockTag=$(getVersion $repo) @@ -432,7 +444,6 @@ if [[ "${SKIP_MOD:-}" != true ]]; then done $backup || download /etc .pihole https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable - $reinstall && echo "Reinstalling Mod..." || echo "Installing Mod..." swapScripts \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ pihole -a -s diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 3eec092b96..a368f06737 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -11,7 +11,7 @@ function get_local_branch() { # Return active branch cd "${1}" 2> /dev/null || return 1 - local foundBranch=$(git show-ref --heads | grep "$(git rev-parse HEAD)" | awk '{print $2;}' | cut -d '/' -f 3) + local foundBranch=$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}') echo "${foundBranch:-HEAD}" } @@ -19,14 +19,16 @@ function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 local tags=$(git ls-remote -t origin) - local foundVersion=$(git rev-parse HEAD 2>/dev/null) - ! grep -q "^$foundVersion" <<<"$tags" || foundVersion=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + local foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' | cut -c1-8) + local foundTag=$foundVersion + ! grep -q "^$foundVersion" <<<"$tags" && foundTag=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) || : + [ -z "${foundTag}" ] || foundVersion="${foundTag}" echo "${foundVersion}" } function get_local_hash() { cd "${1}" 2> /dev/null || return 1 - git rev-parse --short=8 HEAD || return 1 + git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' | cut -c1-8 || return 1 } function get_remote_version() { @@ -38,7 +40,14 @@ function get_remote_version() { } function get_remote_hash(){ - git ls-remote "https://github.com/arevindh/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || { git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,8);}' || return 1; } + local foundHash="" + + for repo in "arevindh" "pi-hole" "ipitio"; do + foundHash=$(git ls-remote "https://github.com/${repo}/${1}" --tags "${2}" | awk '{print $1;}' | cut -c1-8 2> /dev/null) + [ -n "${foundHash}" ] && break + done + + [ ! -z "${foundHash}" ] && echo "${foundHash}" || return 1 } # Source the setupvars config file From 0d396f6301d7cb625ddf71538b9398d3f2ae9c8b Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:44:34 +0000 Subject: [PATCH 632/638] flip cond (#111) --- advanced/Scripts/updatecheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index a368f06737..04fd7deab1 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -21,7 +21,7 @@ function get_local_version() { local tags=$(git ls-remote -t origin) local foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' | cut -c1-8) local foundTag=$foundVersion - ! grep -q "^$foundVersion" <<<"$tags" && foundTag=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) || : + grep -q "^$foundVersion" <<<"$tags" && foundTag=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) || : [ -z "${foundTag}" ] || foundVersion="${foundTag}" echo "${foundVersion}" } From 27695c5b7d040a8bc2f969fdb119caa3b18f042e Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 27 Apr 2024 04:26:58 +0000 Subject: [PATCH 633/638] improved scripts, multiplexed test (#112) * shellcheck, multiplex the test, pushd/popd, no seconds in log, update package cache only if needed --- advanced/Scripts/speedtestmod/mod.sh | 511 ++++++++++++++------- advanced/Scripts/speedtestmod/speedtest.sh | 312 +++++++++---- advanced/Scripts/updatecheck.sh | 22 +- advanced/Scripts/webpage.sh | 143 +++--- 4 files changed, 668 insertions(+), 320 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index d469c70144..403814cd27 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -1,52 +1,84 @@ #!/bin/bash - +# +# The Mod Script, Speedtest Mod for Pi-hole Installation Manager +# Please run this with the --help option for usage information +# +# shellcheck disable=SC2015 +# + +####################################### +# Get the version of a repository, either from a local clone or from the installed package +# Globals: +# None +# Arguments: +# $1: The path to, or name of, the repository +# $2: Non-empty string to get the hash, empty string to get the tag if it exists +# Returns: +# The version of the repository +####################################### getVersion() { - local foundVersion="" - - if [ -d $1 ]; then - cd $1 - foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') - - if [ -z "${2:-}" ]; then - local tags=$(git ls-remote -t origin) - local foundTag=$foundVersion - ! grep -q "$foundVersion" <<<"$tags" || foundTag=$(grep "$foundVersion" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) - [ -z "$foundTag" ] || foundVersion=$foundTag + local found_version="" + + if [[ -d "$1" ]]; then + pushd "$1" &>/dev/null || exit 1 + found_version=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') + + if [[ -z "${2:-}" ]]; then + local tags + local found_tag=$found_version + tags=$(git ls-remote -t origin || git show-ref --tags) + ! grep -q "$found_version" <<<"$tags" || found_tag=$(grep "$found_version" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + [[ -z "$found_tag" ]] || found_version=$found_tag fi - cd - &>/dev/null - elif [ -x "$(command -v pihole)" ]; then - local versions=$(pihole -v | grep "$1") - foundVersion=$(cut -d ' ' -f 6 <<<"$versions") + popd &>/dev/null + elif [[ -x "$(command -v pihole)" ]]; then + local versions + versions=$(pihole -v | grep "$1") + found_version=$(cut -d ' ' -f 6 <<<"$versions") - if [[ "$foundVersion" != *.* ]]; then - [ "$foundVersion" != "$(git rev-parse --abbrev-ref HEAD)" ] || foundVersion=$(cut -d ' ' -f 7 <<<"$versions") + if [[ "$found_version" != *.* ]]; then + [[ "$found_version" != "$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}')" ]] || found_version=$(cut -d ' ' -f 7 <<<"$versions") fi fi - echo $foundVersion + echo "$found_version" } +####################################### +# Fetch a repository, optionally a specific version +# Globals: +# None +# Arguments: +# $1: The path to download the repository to +# $2: The name of the repository +# $3: The URL of the repository +# $4: The desired version, hash or tag, to download (optional, none by default) +# $5: The branch to download (optional, master by default) +# $6: Whether to snap to the tag (optional, true by default) +# Outputs: +# The repository at the desired version +####################################### download() { local path=$1 local name=$2 local url=$3 - local desiredVersion="${4:-}" + local desired_version="${4:-}" local branch="${5:-master}" - local snapToTag="${6:-true}" + local snap_to_tag="${6:-true}" local dest=$path/$name local aborting=false - [ -d "$dest" ] && [ ! -d "$dest/.git" ] && mv -f "$dest" "$dest.old" || : - [ -d "$dest" ] || git clone --depth=1 -b "$branch" "$url" "$dest" -q - cd "$dest" + [[ ! -d "$dest" || -d "$dest/.git" ]] || mv -f "$dest" "$dest.old" + [[ -d "$dest" ]] || git clone --depth=1 -b "$branch" "$url" "$dest" -q + pushd "$dest" &>/dev/null || exit 1 git config --global --add safe.directory "$dest" - if [ ! -z "$desiredVersion" ] && [[ "$desiredVersion" != *.* ]]; then + if [[ -n "$desired_version" && "$desired_version" != *.* ]]; then local repos=("Pi-hole" "web" "speedtest") for repo in "${repos[@]}"; do - if [[ "$desiredVersion" == *"$repo"* ]]; then + if [[ "$desired_version" == *"$repo"* ]]; then aborting=true break fi @@ -63,38 +95,48 @@ download() { url=$(git remote get-url origin) fi - [[ "$url" == *"ipitio"* ]] && snapToTag=$(grep -q "true" <<<"$snapToTag" && echo "false" || echo "true") - git fetch origin --depth=1 $branch:refs/remotes/origin/$branch -q + [[ "$url" != *"ipitio"* ]] || snap_to_tag=$(grep -q "true" <<<"$snap_to_tag" && echo "false" || echo "true") + git fetch origin --depth=1 "$branch":refs/remotes/origin/"$branch" -q git reset --hard origin/"$branch" -q git checkout -B "$branch" -q - local currentHash=$(getVersion "$dest" hash) - local tags=$(git ls-remote -t origin) - - if [ -z "$desiredVersion" ]; then # if empty, get the latest version - if [ "$snapToTag" == "true" ]; then - local latestTag=$(awk -F/ '{print $3}' <<<"$tags" | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) - [ ! -z "$latestTag" ] && desiredVersion=$latestTag || desiredVersion=$currentHash - fi + local current_hash + local tags + current_hash=$(getVersion "$dest" hash) + tags=$(git ls-remote -t origin || git show-ref --tags) + + if [[ -z "$desired_version" ]]; then # if empty, get the latest version + local latest_tag="" + [[ "$snap_to_tag" != "true" ]] || latest_tag=$(awk -F/ '{print $3}' <<<"$tags" | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) + [[ -n "$latest_tag" ]] && desired_version=$latest_tag || desired_version=$current_hash elif $aborting; then - desiredVersion=$(getVersion "$desiredVersion" hash) + desired_version=$(getVersion "$desired_version" hash) fi - if [[ "$desiredVersion" == *.* ]]; then - grep -q "$desiredVersion$" <<<"$tags" && desiredVersion=$(grep "$desiredVersion$" <<<"$tags" | awk '{print $1;}') || desiredVersion=$currentHash + if [[ "$desired_version" == *.* ]]; then + grep -q "$desired_version$" <<<"$tags" && desired_version=$(grep "$desired_version$" <<<"$tags" | awk '{print $1;}') || desired_version=$current_hash fi - if [ "$currentHash" != "$desiredVersion" ]; then - git fetch origin --depth=1 $desiredVersion -q - git reset --hard $desiredVersion -q + if [[ "$current_hash" != "$desired_version" ]]; then + git fetch origin --depth=1 "$desired_version" -q + git reset --hard "$desired_version" -q fi - cd .. + popd &>/dev/null } +####################################### +# Check if a package is installed, only used below when --continuous is not +# Globals: +# None +# Arguments: +# $1: The package to check +# Returns: +# 0 if the package is not installed, 1 if it is +####################################### notInstalled() { - if [ -x "$(command -v apt-get)" ]; then + if [[ -x "$(command -v apt-get)" ]]; then dpkg -s "$1" &>/dev/null || return 0 - elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]; then + elif [[ -x "$(command -v dnf)" ]] || [[ -x "$(command -v yum)" ]]; then rpm -q "$1" &>/dev/null || return 0 else echo "Unsupported package manager!" @@ -104,68 +146,96 @@ notInstalled() { return 1 } +####################################### +# Set a key-value pair in a configuration file, used below for --reinstall +# Globals: +# None +# Arguments: +# $1: The key to set +# $2: The value to set +# $3: The configuration file to set the key-value pair in +# $4: Whether to replace the value if it already exists +# Outputs: +# The configuration file with the key-value pair set +####################################### setCnf() { - grep -q "^$1=" $3 || echo "$1=$2" >>$3 - [ "${4:-false}" == "true" ] || sed -i "s|^$1=.*|$1=$2|" $3 + grep -q "^$1=" "$3" || echo "$1=$2" >>"$3" + [[ "${4:-false}" == "true" ]] || sed -i "s|^$1=.*|$1=$2|" "$3" } +####################################### +# Get a key-value pair from a configuration file, used below for --reinstall +# Globals: +# None +# Arguments: +# $1: The configuration file to get the key-value pair from +# $2: The key to get the value of +# $3: Non-empty string to get the hash, empty string to get the tag if it exists +# Returns: +# The value of the key-value pair +####################################### getCnf() { - local keydir=$(echo $2 | sed 's/^mod-//;s/^org-//') - local value=$(grep "^$2=" $1 | cut -d '=' -f 2) - [ ! -z "$value" ] || value=$(getVersion $keydir "${3:-}") - - if [ ! -z "${3:-}" ] && [[ "$value" == *.* ]]; then - cd $keydir - local tags=$(git ls-remote -t origin) - grep -q "$value$" <<<"$tags" && ver=$(grep "$value$" <<<"$tags" | awk '{print $1;}') || value=$(git rev-parse HEAD) - cd - &>/dev/null - fi - - echo $value + local keydir + local value + keydir=$(echo "$2" | sed 's/^mod-//;s/^org-//') + value=$(grep "^$2=" "$1" | cut -d '=' -f 2) + [[ -n "$value" ]] || value=$(getVersion "$keydir" "${3:-}") + echo "$value" } # allow to source the above helper functions without running the whole script if [[ "${SKIP_MOD:-}" != true ]]; then - html_dir=/var/www/html - core_dir=/etc/.pihole - opt_dir=/opt/pihole - etc_dir=/etc/pihole - mod_dir=/etc/pihole-speedtest - curr_wp=$opt_dir/webpage.sh - curr_db=$etc_dir/speedtest.db - last_db=$curr_db.old - db_table="speedtest" + declare -r HTML_DIR="/var/www/html" + declare -r CORE_DIR="/etc/.pihole" + declare -r OPT_DIR="/opt/pihole" + declare -r ETC_DIR="/etc/pihole" + declare -r MOD_DIR="/etc/pihole-speedtest" + declare -r CURR_WP="$OPT_DIR/webpage.sh" + declare -r CURR_DB="$ETC_DIR/speedtest.db" + declare -r LAST_DB="$CURR_DB.old" + declare -r DB_TABLE="speedtest" + declare -i aborted=0 st_ver="" mod_core_ver="" mod_admin_ver="" cleanup=true - aborted=0 set +u + # shellcheck disable=SC2034 SKIP_INSTALL=true - source "$core_dir/automated install/basic-install.sh" + # shellcheck disable=SC1091 + source "$CORE_DIR/automated install/basic-install.sh" set -u + ####################################### + # Display the help message + # Globals: + # None + # Arguments: + # None + # Outputs: + # The help message + ####################################### help() { - local helpText=( + local -r help_text=( "The Mod Script" "Usage: sudo bash /path/to/mod.sh [options]" " or: curl -sSLN //link/to/mod.sh | sudo bash [-s -- options]" "(Re)install the latest release of the Speedtest Mod, and/or the following options:" "" "Options:" - " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" " -b, --backup preserve stock Pi-hole files for faster offline restore" " -o, --online force online restore of stock Pi-hole files even if a backup exists" " -i, --install skip restore of stock Pi-hole*" + " -c, --continuous skip check for missing dependencies" " -r, --reinstall keep current version of the mod, if installed*" " -t, --testing install the latest commit" + " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" " -n, --uninstall, un remove the mod and its files, but keep the database" " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" - " -v, --version display the version of the mod" " -x, --verbose show the commands being run" - " -c, --continuous skip check for missing dependencies" - " -h, --help display this help message" + " -v, --version display the version of the mod and exit" + " -h, --help display this help message and exit" "" " *for when not updating Pi-hole nor switching repos" "" @@ -176,82 +246,171 @@ if [[ "${SKIP_MOD:-}" != true ]]; then " curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -u" ) - printf "%s\n" "${helpText[@]}" + printf "%s\n" "${help_text[@]}" } + ####################################### + # Check if a database is empty + # Globals: + # DB_TABLE + # Arguments: + # $1: The database to check + # Returns: + # 0 if the database is empty, 1 if it is not + ####################################### isEmpty() { - [ -f $1 ] && sqlite3 "$1" "select * from $db_table limit 1;" &>/dev/null && [ ! -z "$(sqlite3 "$1" "select * from $db_table limit 1;")" ] && return 1 || return 0 + [[ -f "$1" ]] && sqlite3 "$1" "select * from $DB_TABLE limit 1;" &>/dev/null && [[ -n "$(sqlite3 "$1" "select * from $DB_TABLE limit 1;")" ]] && return 1 || return 0 } + ####################################### + # Copy scripts from the CORE to the OPT repository + # Globals: + # OPT_DIR + # Arguments: + # None + # Outputs: + # The scripts copied to the OPT repository + ####################################### swapScripts() { set +u installScripts >/dev/null 2>&1 set -u } + ####################################### + # Restore a backup, used after --backup unless --online or --install are used + # Globals: + # None + # Arguments: + # $1: The backup to restore + # Returns: + # 1 if the backup does not exist or is stale, 0 if it does and isn't + # Outputs: + # The backup restored + ####################################### restore() { - [ -d $1.bak ] || return 1 - [ ! -e $1 ] || rm -rf $1 - mv -f $1.bak $1 - cd $1 - git tag -l | xargs git tag -d >/dev/null 2>&1 - git fetch --tags -f -q + [[ -d "$1".bak && "$(getVersion "$1".bak hash)" == "$(getCnf $MOD_DIR/cnf org-"$1" hash)" ]] || return 1 + [[ ! -e "$1" ]] || rm -rf "$1" + mv -f "$1".bak "$1" } + ####################################### + # Purge the mod, used for --uninstall + # Globals: + # CORE_DIR + # HTML_DIR + # OPT_DIR + # CURR_DB + # ETC_DIR + # Arguments: + # None + # Outputs: + # The mod purged + ####################################### purge() { - if [ -f /etc/systemd/system/pihole-speedtest.timer ]; then + if [[ -f /etc/systemd/system/pihole-speedtest.timer ]]; then rm -f /etc/systemd/system/pihole-speedtest.service rm -f /etc/systemd/system/pihole-speedtest.timer systemctl daemon-reload fi - rm -rf $opt_dir/speedtestmod - rm -rf $core_dir.bak - rm -rf $html_dir/admin.bak - rm -rf $core_dir.mod - rm -rf $html_dir/admin.mod - rm -f "$curr_db".* - rm -f $etc_dir/last_speedtest.* - ! isEmpty $curr_db || rm -f $curr_db + rm -rf $OPT_DIR/speedtestmod + rm -rf $CORE_DIR.bak + rm -rf $HTML_DIR/admin.bak + rm -rf $CORE_DIR.mod + rm -rf $HTML_DIR/admin.mod + rm -f "$CURR_DB".* + rm -f $ETC_DIR/last_speedtest.* + ! isEmpty $CURR_DB || rm -f $CURR_DB } + ####################################### + # Abort the process + # Globals: + # CORE_DIR + # HTML_DIR + # MOD_DIR + # OPT_DIR + # CURR_WP + # CURR_DB + # LAST_DB + # ETC_DIR + # cleanup + # aborted + # Arguments: + # None + # Outputs: + # The changes reverted + # shellcheck disable=SC2317 ########### abort() { if $cleanup; then echo "Process Aborting..." aborted=1 - if [ -d $core_dir/.git/refs/remotes/old ]; then + if [[ -d "$CORE_DIR"/.git/refs/remotes/old ]]; then download /etc .pihole "" Pi-hole swapScripts - if [ -d $core_dir/advanced/Scripts/speedtestmod ]; then - \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + if [[ -d "$CORE_DIR"/advanced/Scripts/speedtestmod ]]; then + \cp -af "$CORE_DIR"/advanced/Scripts/speedtestmod/. "$OPT_DIR"/speedtestmod/ pihole -a -s fi fi - [ -d $mod_dir ] && [ -d $mod_dir/.git/refs/remotes/old ] && download /etc pihole-speedtest "" speedtest || : - [ ! -d $html_dir/admin/.git/refs/remotes/old ] || download $html_dir admin "" web - [ -f $last_db ] && [ ! -f $curr_db ] && mv $last_db $curr_db || : - [ -f $curr_wp ] && ! cat $curr_wp | grep -q SpeedTest && purge || : - printf "Please try again before reporting an issue.\n\n$(date)\n" + [[ ! -d "$MOD_DIR" || ! -d "$MOD_DIR"/.git/refs/remotes/old ]] || download /etc pihole-speedtest "" speedtest + [[ ! -d "$HTML_DIR"/admin/.git/refs/remotes/old ]] || download "$HTML_DIR" admin "" web + [[ ! -f "$LAST_DB" || -f "$CURR_DB" ]] || mv "$LAST_DB" "$CURR_DB" + [[ -f "$CURR_WP" ]] && ! grep -q SpeedTest "$CURR_WP" && purge || : + printf "Please try again before reporting an issue.\n\n%s\n" "$(date)" fi } + ####################################### + # Commit the changes + # Globals: + # CORE_DIR + # HTML_DIR + # cleanup + # Arguments: + # None + # Outputs: + # The repositories cleaned up + # shellcheck disable=SC2317 ########### commit() { if $cleanup; then - for dir in $core_dir $html_dir/admin; do - [ ! -d $dir ] && continue || cd $dir + for dir in $CORE_DIR $HTML_DIR/admin; do + [[ ! -d "$dir" ]] && continue || pushd "$dir" &>/dev/null || exit 1 ! git remote -v | grep -q "old" || git remote remove old git clean -ffdx + popd &>/dev/null done - printf "Done!\n\n$(date)\n" + printf "Done!\n\n%s\n" "$(date)" fi } + ####################################### + # Manage the installation + # Globals: + # CORE_DIR + # HTML_DIR + # MOD_DIR + # OPT_DIR + # CURR_WP + # CURR_DB + # LAST_DB + # ETC_DIR + # st_ver + # mod_core_ver + # mod_admin_ver + # cleanup + # Arguments: + # $@: The options for managing the installation + # Outputs: + # The installation managed + ####################################### main() { set -Eeuo pipefail - trap 'abort' INT TERM + trap 'abort' INT TERM ERR shopt -s dotglob local update=false @@ -264,13 +423,13 @@ if [[ "${SKIP_MOD:-}" != true ]]; then local database=false local verbose=false local chk_dep=true - local dashes=0 - local SHORT=-uboirtndvxch - local LONG=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,continuous,help - declare -a EXTRA_ARGS - declare -a POSITIONAL - PARSED=$(getopt --options ${SHORT} --longoptions ${LONG} --name "$0" -- "$@") - eval set -- "${PARSED}" + local -i dashes=0 + local -r short_opts=-uboirtndvxch + local -r long_opts=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,continuous,help + local -r parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@") + declare -a POSITIONAL EXTRA_ARGS + eval set -- "${parsed_opts}" + local -ri num_args=$# while [[ $# -gt 0 ]]; do case "$1" in @@ -283,7 +442,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then -n | --uninstall) uninstall=true ;; -d | --database) database=true ;; -v | --version) - getVersion $mod_dir + getVersion $MOD_DIR cleanup=false exit 0 ;; @@ -315,47 +474,49 @@ if [[ "${SKIP_MOD:-}" != true ]]; then esac done + readonly update backup online install reinstall stable uninstall database verbose chk_dep cleanup trap '[ "$?" -eq "0" ] && commit || abort' EXIT - printf "Thanks for using Speedtest Mod!\nScript by @ipitio\n\n$(date)\n\n" + printf "%s\n\nRunning The Mod Script by @ipitio...\n" "$(date)" ! $verbose || set -x if $database; then - if [ -f $curr_db ] && ! isEmpty $curr_db; then + if [[ -f $CURR_DB ]] && ! isEmpty $CURR_DB; then echo "Flushing Database..." - mv -f $curr_db $last_db - [ ! -f $etc_dir/last_speedtest ] || mv -f $etc_dir/last_speedtest $etc_dir/last_speedtest.old + mv -f $CURR_DB $LAST_DB + [[ ! -f $ETC_DIR/last_speedtest ]] || mv -f $ETC_DIR/last_speedtest $ETC_DIR/last_speedtest.old - if [ -f /var/log/pihole/speedtest.log ]; then + if [[ -f /var/log/pihole/speedtest.log ]]; then mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old - rm -f $etc_dir/speedtest.log + rm -f $ETC_DIR/speedtest.log fi - elif [ -f $last_db ]; then + elif [[ -f $LAST_DB ]]; then echo "Restoring Database..." - mv -f $last_db $curr_db - [ ! -f $etc_dir/last_speedtest.old ] || mv -f $etc_dir/last_speedtest.old $etc_dir/last_speedtest + mv -f $LAST_DB $CURR_DB + [[ ! -f $ETC_DIR/last_speedtest.old ]] || mv -f $ETC_DIR/last_speedtest.old $ETC_DIR/last_speedtest - if [ -f /var/log/pihole/speedtest.log.old ]; then + if [[ -f /var/log/pihole/speedtest.log.old ]]; then mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log - \cp -af /var/log/pihole/speedtest.log $etc_dir/speedtest.log + \cp -af /var/log/pihole/speedtest.log $ETC_DIR/speedtest.log fi fi fi - if ! $database || [ "$#" -gt 1 ]; then - local working_dir=$(pwd) - cd ~ + if ! $database || [[ "$num_args" -gt 1 ]]; then + pushd ~ >/dev/null || exit 1 + pihole -v - if [ -f $curr_wp ] && cat $curr_wp | grep -q SpeedTest; then + if [[ -f $CURR_WP ]] && grep -q SpeedTest "$CURR_WP"; then if $reinstall; then - for repo in $core_dir $html_dir/admin $mod_dir; do - if [ -d $repo ]; then - local hashTag=$(getVersion $repo) # if hashes are the same, we may be on an older tag - [ "$(getVersion $repo hash)" != "$(getCnf $mod_dir/cnf mod-$repo hash)" ] || hashTag=$(getCnf $mod_dir/cnf mod-$repo) + for repo in $CORE_DIR $HTML_DIR/admin $MOD_DIR; do + if [[ -d "$repo" ]]; then + local hash_tag + hash_tag=$(getVersion "$repo") # if hashes are the same, we may be on an older tag + [[ "$(getVersion "$repo" hash)" != "$(getCnf $MOD_DIR/cnf mod-"$repo" hash)" ]] || hash_tag=$(getCnf $MOD_DIR/cnf mod-"$repo") case "$repo" in - "$core_dir") mod_core_ver=$hashTag ;; - "$html_dir/admin") mod_admin_ver=$hashTag ;; - "$mod_dir") st_ver=$hashTag ;; + "$CORE_DIR") mod_core_ver=$hash_tag ;; + "$HTML_DIR/admin") mod_admin_ver=$hash_tag ;; + "$MOD_DIR") st_ver=$hash_tag ;; esac fi done @@ -367,20 +528,23 @@ if [[ "${SKIP_MOD:-}" != true ]]; then local core_ver="" local admin_ver="" - if [ -f $mod_dir/cnf ]; then - core_ver=$(getCnf $mod_dir/cnf org-$core_dir) - admin_ver=$(getCnf $mod_dir/cnf org-$html_dir/admin) + + if [[ -f $MOD_DIR/cnf ]]; then + core_ver=$(getCnf $MOD_DIR/cnf org-$CORE_DIR) + admin_ver=$(getCnf $MOD_DIR/cnf org-$HTML_DIR/admin) fi - ! $online && restore $html_dir/admin || download $html_dir admin https://github.com/pi-hole/AdminLTE "$admin_ver" - ! $online && restore $core_dir || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" - [ ! -d $mod_dir ] || rm -rf $mod_dir + readonly core_ver admin_ver + + ! $online && restore $HTML_DIR/admin || download $HTML_DIR admin https://github.com/pi-hole/AdminLTE "$admin_ver" + ! $online && restore $CORE_DIR || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" + [[ ! -d $MOD_DIR ]] || rm -rf $MOD_DIR swapScripts fi fi if ! $install && $update; then - if [ -d /run/systemd/system ]; then + if [[ -d /run/systemd/system ]]; then echo "Updating Pi-hole..." PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up else @@ -393,73 +557,80 @@ if [[ "${SKIP_MOD:-}" != true ]]; then purge else if $chk_dep; then - if [ ! -f /usr/local/bin/pihole ]; then + if [[ ! -f /usr/local/bin/pihole ]]; then echo "Installing Pi-hole..." curl -sSL https://install.pi-hole.net | sudo bash fi echo "Checking Dependencies..." - local PHP_VERSION=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) - local PKGS=(bc sqlite3 jq tar tmux wget "php$PHP_VERSION-sqlite3") - local missingPkgs=() + local -r php_version=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) + local -r pkg_manager=$(command -v apt-get || command -v dnf || command -v yum) + local -r pkgs=(bc nano sqlite3 jq tar tmux wget "php$php_version-sqlite3") + local missingpkgs=() - for pkg in "${PKGS[@]}"; do - ! notInstalled "$pkg" || missingPkgs+=("$pkg") + for pkg in "${pkgs[@]}"; do + ! notInstalled "$pkg" || missingpkgs+=("$pkg") done - if [ ${#missingPkgs[@]} -gt 0 ]; then - [[ "$PKG_MANAGER" != *"apt-get"* ]] || apt-get update >/dev/null - echo "Installing Missing..." - $PKG_MANAGER install -y "${missingPkgs[@]}" + readonly missingpkgs + if [[ ${#missingpkgs[@]} -gt 0 ]]; then + if [[ "$pkg_manager" == *"apt-get"* ]] && apt-cache show "${missingpkgs[@]}" | grep -q "Unable to locate package"; then + echo "Updating Package Cache..." + apt-get update -y &>/dev/null + fi + + echo "Installing Missing Dependencies..." + $pkg_manager install -y "${missingpkgs[@]}" &>/dev/null # hide an unimportant warning in docker fi fi if $backup; then echo "Backing up Pi-hole..." download /etc .pihole.mod https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable - download $html_dir admin.mod https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable + download $HTML_DIR admin.mod https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable fi $reinstall && echo "Reinstalling Mod..." || echo "Installing Mod..." download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable - [ -f $mod_dir/cnf ] || touch $mod_dir/cnf - setCnf mod-$mod_dir "$(getVersion $mod_dir)" $mod_dir/cnf $reinstall + [[ -f $MOD_DIR/cnf ]] || touch $MOD_DIR/cnf + setCnf mod-$MOD_DIR "$(getVersion $MOD_DIR)" $MOD_DIR/cnf $reinstall + local stock_tag - for repo in $core_dir $html_dir/admin; do - if [ -d $repo ]; then - local stockTag=$(getVersion $repo) - setCnf org-$repo $stockTag $mod_dir/cnf + for repo in $CORE_DIR $HTML_DIR/admin; do + if [[ -d "$repo" ]]; then + stock_tag=$(getVersion "$repo") + setCnf org-"$repo" "$stock_tag" $MOD_DIR/cnf if $backup; then - if [ ! -d $repo.bak ] || [ "$(getVersion $repo.bak)" != "$stockTag" ]; then - rm -rf $repo.bak - mv -f $repo $repo.bak + if [[ ! -d "$repo".bak || "$(getVersion "$repo".bak)" != "$stock_tag" ]]; then + rm -rf "$repo".bak + mv -f "$repo" "$repo".bak fi - rm -rf $repo - mv -f $repo.mod $repo + rm -rf "$repo" + mv -f "$repo".mod "$repo" fi fi done $backup || download /etc .pihole https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable swapScripts - \cp -af $core_dir/advanced/Scripts/speedtestmod/. $opt_dir/speedtestmod/ + \cp -af $CORE_DIR/advanced/Scripts/speedtestmod/. $OPT_DIR/speedtestmod/ pihole -a -s - $backup || download $html_dir admin https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable - setCnf mod-$core_dir "$(getVersion $core_dir)" $mod_dir/cnf $reinstall - setCnf mod-$html_dir/admin "$(getVersion $html_dir/admin)" $mod_dir/cnf $reinstall + $backup || download $HTML_DIR admin https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable + setCnf mod-$CORE_DIR "$(getVersion $CORE_DIR)" $MOD_DIR/cnf $reinstall + setCnf mod-$HTML_DIR/admin "$(getVersion $HTML_DIR/admin)" $MOD_DIR/cnf $reinstall fi pihole updatechecker - [ -d $working_dir ] && cd $working_dir + pihole -v + popd >/dev/null fi exit 0 } - if [ $EUID != 0 ]; then + if [[ $EUID != 0 ]]; then sudo "$0" "$@" exit $? fi diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 8d0c9be25e..77eb06db13 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -1,8 +1,13 @@ #!/bin/bash -start=$(date -u --rfc-3339='seconds') -out=/tmp/speedtest.log -serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) -create_table="create table if not exists speedtest ( +# +# The Test Script, Speedtest Mod for Pi-hole Run Supervisor +# Please run this with the --help option for usage information +# +# shellcheck disable=SC2015 +# + +declare -r OUT_FILE=/tmp/speedtest.log +declare -r CREATE_TABLE="create table if not exists speedtest ( id integer primary key autoincrement, start_time text, stop_time text, @@ -15,51 +20,97 @@ download real, upload real, share_url text );" +declare START +declare PKG_MANAGER +declare SERVER_ID +START=$(date -u --rfc-3339='seconds') +PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) +SERVER_ID=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) +readonly START PKG_MANAGER SERVER_ID + +# shellcheck disable=SC2034 SKIP_MOD=true +# shellcheck disable=SC1091 source /opt/pihole/speedtestmod/mod.sh +####################################### +# Run the speedtest +# Globals: +# SERVER_ID +# Arguments: +# None +# Returns: +# None +####################################### speedtest() { if grep -q official <<<"$(/usr/bin/speedtest --version)"; then - [[ ! -z "${serverid}" ]] && /usr/bin/speedtest -s $serverid --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json + [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest -s "$SERVER_ID" --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json else - [[ ! -z "${serverid}" ]] && /usr/bin/speedtest --server $serverid --json --share --secure || /usr/bin/speedtest --json --share --secure + [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest --server "$SERVER_ID" --json --share --secure || /usr/bin/speedtest --json --share --secure fi } +####################################### +# Save the results of the speedtest to the database +# Globals: +# OUT_FILE +# CREATE_TABLE +# Arguments: +# $1: Start time +# $2: Stop time +# $3: ISP +# $4: From IP +# $5: Server +# $6: Server Distance +# $7: Server Ping +# $8: Download +# $9: Upload +# $10: Share URL +# Returns: +# None +####################################### savetest() { - local start_time=$1 - local stop_time=$2 - local isp=${3:-"No Internet"} - local from_ip=${4:-"-"} - local server=${5:-"-"} - local server_dist=${6:-0} - local server_ping=${7:-0} - local download=${8:-0} - local upload=${9:-0} - local share_url=${10:-"#"} - local rm_empty=' + local -r start_time=$1 + local -r stop_time=$2 + local -r isp=${3:-"No Internet"} + local -r from_ip=${4:-"-"} + local -r server=${5:-"-"} + local -r server_dist=${6:-0} + local -r server_ping=${7:-0} + local -r download=${8:-0} + local -r upload=${9:-0} + local -r share_url=${10:-"#"} + local -r rm_empty=' def nonempty: . and length > 0 and (type != "object" or . != {}) and (type != "array" or any(.[]; . != "")); if type == "array" then map(walk(if type == "object" then with_entries(select(.value | nonempty)) else . end)) else walk(if type == "object" then with_entries(select(.value | nonempty)) else . end) end ' - local temp_file=$(mktemp) - local json_file="/tmp/speedtest_results" + local -r temp_file=$(mktemp) + local -r json_file="/tmp/speedtest_results" jq "$rm_empty" "$json_file" >"$temp_file" && mv -f "$temp_file" "$json_file" rm -f "$temp_file" chmod 644 /tmp/speedtest_results mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log \cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log - rm -f "$out" - sqlite3 /etc/pihole/speedtest.db "$create_table" + rm -f "$OUT_FILE" + sqlite3 /etc/pihole/speedtest.db "$CREATE_TABLE" sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" - [ "$isp" == "No Internet" ] && exit 1 || exit 0 + [[ "$isp" == "No Internet" ]] && exit 1 || exit 0 } +####################################### +# Check if the package is available +# Globals: +# PKG_MANAGER +# Arguments: +# $1: Package name +# Returns: +# 0 if available, 1 if not +####################################### isAvailable() { - if [ -x "$(command -v apt-get)" ]; then + if [[ "$PKG_MANAGER" == "/usr/bin/apt-get" ]]; then # Check if there is a candidate and it is not "(none)" apt-cache policy "$1" | grep -q "Candidate:" && ! apt-cache policy "$1" | grep -q "Candidate: (none)" && return 0 || return 1 - elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]; then - local PKG_MANAGER=$(command -v dnf || command -v yum) + elif [[ "$PKG_MANAGER" == "/usr/bin/dnf" || "$PKG_MANAGER" == "/usr/bin/yum" ]]; then $PKG_MANAGER list available "$1" &>/dev/null && return 0 || return 1 else echo "Unsupported package manager!" @@ -67,33 +118,62 @@ isAvailable() { fi } +####################################### +# Change between two conflicting packages +# Globals: +# PKG_MANAGER +# Arguments: +# $1: Package to install +# $2: Package to remove +# Returns: +# None +####################################### swaptest() { - if isAvailable $1; then - [ -x "$(command -v apt-get)" ] && apt-get install -y $1 $2- || { [ -x "$(command -v dnf)" ] && dnf install -y --allowerasing $1 || yum install -y --allowerasing $1; } + if isAvailable "$1"; then + [[ "$PKG_MANAGER" == "/usr/bin/apt-get" ]] && apt-get install -y "$1" "$2"- || { [[ "$PKG_MANAGER" == "/usr/bin/dnf" ]] && dnf install -y --allowerasing "$1" || yum install -y --allowerasing "$1"; } fi } +####################################### +# Check if a package is installed +# Globals: +# PKG_MANAGER +# OUT_FILE +# Arguments: +# $1: The package to check +# Returns: +# 0 if the package is not installed, 1 if it is +####################################### notInstalled() { - if [ -x "$(command -v apt-get)" ]; then + if [[ "$PKG_MANAGER" == "/usr/bin/apt-get" ]]; then dpkg -s "$1" &>/dev/null || return 0 - elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]; then + elif [[ "$PKG_MANAGER" == "/usr/bin/dnf" || "$PKG_MANAGER" == "/usr/bin/yum" ]]; then rpm -q "$1" &>/dev/null || return 0 else echo "Unsupported package manager!" - mv -f "$out" /var/log/pihole/speedtest.log + mv -f "$OUT_FILE" /var/log/pihole/speedtest.log exit 1 fi return 1 } +####################################### +# Download and install librespeed +# Globals: +# PKG_MANAGER +# Arguments: +# None +# Returns: +# None +####################################### librespeed() { if notInstalled golang; then if grep -q "Raspbian" /etc/os-release; then - if [ ! -f /etc/apt/sources.list.d/testing.list ] && ! grep -q "testing" /etc/apt/sources.list; then + if [[ ! -f /etc/apt/sources.list.d/testing.list ]] && ! grep -q "testing" /etc/apt/sources.list; then echo "Adding testing repo to sources.list.d" echo "deb http://archive.raspbian.org/raspbian/ testing main" >/etc/apt/sources.list.d/testing.list - echo "Package: *\nPin: release a=testing\nPin-Priority: 50" >/etc/apt/preferences.d/limit-testing + printf "Package: *\nPin: release a=testing\nPin-Priority: 50" >/etc/apt/preferences.d/limit-testing $PKG_MANAGER update fi @@ -103,34 +183,45 @@ librespeed() { fi fi download /etc/pihole librespeed https://github.com/librespeed/speedtest-cli - cd librespeed - [ ! -d out ] || rm -rf out + cd librespeed || exit + [[ ! -d out ]] || rm -rf out ./build.sh mv -f out/* /usr/bin/speedtest chmod +x /usr/bin/speedtest } +####################################### +# Add the Ookla speedtest CLI source +# Globals: +# PKG_MANAGER +# Arguments: +# None +# Returns: +# None +####################################### addSource() { if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then - if [ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]; then + if [[ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]]; then echo "Adding speedtest source for RPM..." curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash fi yum list speedtest | grep -q "Available Packages" && $PKG_MANAGER install -y speedtest || : elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - if [ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]; then + if [[ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]]; then echo "Adding speedtest source for DEB..." - if [ -e /etc/os-release ]; then - . /etc/os-release - local base="ubuntu debian" + if [[ -e /etc/os-release ]]; then + # shellcheck disable=SC1091 + source /etc/os-release + local -r base="ubuntu debian" local os=${ID} local dist=${VERSION_CODENAME} - if [ ! -z "${ID_LIKE-}" ] && [[ "${base//\"/}" =~ "${ID_LIKE//\"/}" ]] && [ "${os}" != "ubuntu" ]; then + # shellcheck disable=SC2076 + if [[ -n "${ID_LIKE:-}" && "${base//\"/}" =~ "${ID_LIKE//\"/}" && "${os}" != "ubuntu" ]]; then os=${ID_LIKE%% *} - [ -z "${UBUNTU_CODENAME-}" ] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + [[ -z "${UBUNTU_CODENAME:-}" ]] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) dist=${UBUNTU_CODENAME} - [ -z "$dist" ] && dist=${VERSION_CODENAME} + [[ -z "$dist" ]] && dist=${VERSION_CODENAME} fi wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 chmod +x /tmp/script.deb.sh @@ -149,53 +240,65 @@ addSource() { fi } +####################################### +# Run the speedtest and save the results +# Globals: +# PKG_MANAGER +# START +# Arguments: +# $1: Number of attempts (optional, 3 by default) +# $2: Current attempt (optional, 0 by default) +# Returns: +# None +####################################### run() { speedtest | jq . >/tmp/speedtest_results || echo "Attempt ${2:-1} Failed!" >/tmp/speedtest_results - local stop=$(date -u --rfc-3339='seconds') + local -r stop=$(date -u --rfc-3339='seconds') if jq -e '.server' /tmp/speedtest_results &>/dev/null; then - local res=$(/dev/null; then # librespeed - local res=$(/tmp/speedtest_results - savetest "$start" "$stop" + savetest "$START" "$stop" else if notInstalled speedtest && notInstalled speedtest-cli; then - [ ! -f /usr/bin/speedtest ] || rm -f /usr/bin/speedtest + [[ ! -f /usr/bin/speedtest ]] || rm -f /usr/bin/speedtest addSource isAvailable speedtest && $PKG_MANAGER install -y speedtest || : elif ! notInstalled speedtest; then @@ -209,21 +312,64 @@ run() { fi } +####################################### +# Display the help message +# Globals: +# None +# Arguments: +# None +# Returns: +# None +####################################### +help() { + echo "Usage: $0 [attempts]" + echo " attempts: Number of attempts to run the speedtest, cycling through the packages (default: 3)" + exit 1 +} + +####################################### +# Main function +# Globals: +# PKG_MANAGER +# Arguments: +# None +# Returns: +# None +####################################### main() { - if [ $EUID != 0 ]; then + local -r short_opts=-h + local -r long_opts=help + local -r parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@") + local POSITIONAL=() + local attempts="3" + eval set -- "${parsed_opts}" + + while [[ $# -gt 0 ]]; do + case "$1" in + -h | --help) help ;; + *) POSITIONAL+=("$1") ;; + esac + shift + done + + set -- "${POSITIONAL[@]}" + + if [[ "$1" != "--" ]]; then + [[ "$1" =~ ^[0-9]+$ ]] && attempts="$1" || help + fi + + if [[ $EUID != 0 ]]; then sudo "$0" "$@" exit $? fi - PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) - - if [ ! -f /usr/bin/speedtest ]; then + if [[ ! -f /usr/bin/speedtest ]]; then addSource isAvailable speedtest && $PKG_MANAGER install -y speedtest || { isAvailable speedtest-cli && $PKG_MANAGER install -y speedtest-cli || librespeed; } fi echo "Running Test..." - run $1 # Number of attempts + run $attempts } -main ${1:-3} >"$out" +main "$@" >"$OUT_FILE" diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 04fd7deab1..d886e4acb5 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -11,28 +11,32 @@ function get_local_branch() { # Return active branch cd "${1}" 2> /dev/null || return 1 - local foundBranch=$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}') + local foundBranch + foundBranch=$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}') echo "${foundBranch:-HEAD}" } function get_local_version() { # Return active version cd "${1}" 2> /dev/null || return 1 - local tags=$(git ls-remote -t origin) - local foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' | cut -c1-8) + local tags + local foundVersion + tags=$(git ls-remote -t origin) + foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') local foundTag=$foundVersion + # shellcheck disable=SC2015 grep -q "^$foundVersion" <<<"$tags" && foundTag=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) || : - [ -z "${foundTag}" ] || foundVersion="${foundTag}" + [[ -z "${foundTag}" ]] || foundVersion="${foundTag}" echo "${foundVersion}" } function get_local_hash() { cd "${1}" 2> /dev/null || return 1 - git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' | cut -c1-8 || return 1 + git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' || return 1 } function get_remote_version() { - if [ "${1}" == "docker-pi-hole" ] || [ "${1}" == "FTL" ]; then + if [[ "${1}" == "docker-pi-hole" || "${1}" == "FTL" ]]; then curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 else curl -s "https://api.github.com/repos/arevindh/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || { curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1; } @@ -43,11 +47,11 @@ function get_remote_hash(){ local foundHash="" for repo in "arevindh" "pi-hole" "ipitio"; do - foundHash=$(git ls-remote "https://github.com/${repo}/${1}" --tags "${2}" | awk '{print $1;}' | cut -c1-8 2> /dev/null) - [ -n "${foundHash}" ] && break + foundHash=$(git ls-remote "https://github.com/${repo}/${1}" --tags "${2}" | awk '{print $1;}' 2> /dev/null) + [[ -n "${foundHash}" ]] && break done - [ ! -z "${foundHash}" ] && echo "${foundHash}" || return 1 + [[ -n "${foundHash}" ]] && echo "${foundHash}" || return 1 } # Source the setupvars config file diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 97db21c8dc..da508ba0b8 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -24,7 +24,6 @@ readonly gravityDBfile="/etc/pihole/gravity.db" # speedtest mod readonly speedtestmod="/opt/pihole/speedtestmod/mod.sh" readonly speedtestfile="/opt/pihole/speedtestmod/speedtest.sh" -readonly speedtestdb="/etc/pihole/speedtest.db" readonly setupVars="/etc/pihole/setupVars.conf" readonly PI_HOLE_BIN_DIR="/usr/local/bin" @@ -548,44 +547,52 @@ SetWebUILayout() { generate_systemd_calendar() { local interval_hours="$1" - local total_seconds=$(echo "$interval_hours * 3600" | bc) + local total_seconds + total_seconds=$(echo "$interval_hours * 3600" | bc) local freq_entries=() - if (( $(echo "$total_seconds < 60" | bc -l) )); then # less than a minute + if (($(echo "$total_seconds < 60" | bc -l))); then # less than a minute total_seconds=60 addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0.017" fi - if (( $(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l) )); then # less than an hour - local minute_interval=$(echo "$total_seconds / 60" | bc) + if (($(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l))); then # less than an hour + local minute_interval + minute_interval=$(echo "$total_seconds / 60" | bc) freq_entries+=("*-*-* *:00/$minute_interval:00") - elif (( $(echo "$total_seconds == 3600" | bc -l) )); then # exactly an hour + elif (($(echo "$total_seconds == 3600" | bc -l))); then # exactly an hour freq_entries+=("*-*-* *:00:00") - elif (( $(echo "$total_seconds < 86400" | bc -l) )); then # less than a day - if (( $(awk "BEGIN {print ($total_seconds / 3600) % 1}") == 0 )); then # divides evenly into an hour - local hour_interval=$(echo "$total_seconds / 3600" | bc) + elif (($(echo "$total_seconds < 86400" | bc -l))); then # less than a day + if (($(awk "BEGIN {print ($total_seconds / 3600) % 1}") == 0)); then # divides evenly into an hour + local hour_interval + hour_interval=$(echo "$total_seconds / 3600" | bc) freq_entries+=("*-*-* 00/$hour_interval:00:00") else # does not divide evenly into an hour local current_second=0 - while (( $(echo "$current_second < 86400" | bc -l) )); do - local hour=$(echo "$current_second / 3600" | bc) - local minute=$(awk "BEGIN {print ($current_second % 3600) / 60}") + while (($(echo "$current_second < 86400" | bc -l))); do + local hour + hour=$(echo "$current_second / 3600" | bc) + local minute + minute=$(awk "BEGIN {print ($current_second % 3600) / 60}") hour=${hour%.*} minute=${minute%.*} - freq_entries+=("*-*-* $(printf "%02d:%02d:00" $hour $minute)") + freq_entries+=("*-*-* $(printf "%02d:%02d:00" "$hour" "$minute")") current_second=$(echo "$current_second + $total_seconds" | bc) done fi else # more than a day - local full_days=$(echo "$interval_hours / 24" | bc) - local remaining_hours=$(echo "$interval_hours - ($full_days * 24)" | bc) - if (( $(echo "$full_days > 0" | bc -l) )); then - freq_entries+=("*-*-1/$(printf "%02.0f" $full_days)") + local full_days + full_days=$(echo "$interval_hours / 24" | bc) + local remaining_hours + remaining_hours=$(echo "$interval_hours - ($full_days * 24)" | bc) + if (($(echo "$full_days > 0" | bc -l))); then + freq_entries+=("*-*-1/$(printf "%02.0f" "$full_days")") fi - if (( $(echo "$remaining_hours > 0" | bc -l) )); then # partial day - local remaining_minutes=$(echo "($remaining_hours - ($remaining_hours / 1)) * 60" | bc) + if (($(echo "$remaining_hours > 0" | bc -l))); then # partial day + local remaining_minutes + remaining_minutes=$(echo "($remaining_hours - ($remaining_hours / 1)) * 60" | bc) remaining_hours=${remaining_hours%.*} remaining_minutes=${remaining_minutes%.*} - freq_entries+=("*-*-* $(printf "%02d:%02d:00" $remaining_hours $remaining_minutes)") + freq_entries+=("*-*-* $(printf "%02d:%02d:00" "$remaining_hours" "$remaining_minutes")") fi fi @@ -597,14 +604,15 @@ generate_cron_schedule() { local total_seconds="nan" local schedule_script="/opt/pihole/speedtestmod/schedule_check.sh" - if [[ "$1" != "nan" ]] && [[ "$1" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (( $(echo "$1 > 0" | bc -l) )); then + if [[ "$1" != "nan" ]] && [[ "$1" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (($(echo "$1 > 0" | bc -l))); then total_seconds=$(echo "$1 * 3600" | bc) - if (( $(echo "$total_seconds < 60" | bc -l) )); then + if (($(echo "$total_seconds < 60" | bc -l))); then total_seconds=60 fi - local remainder=$(awk "BEGIN {print $total_seconds % 60}") - if (( $(echo "$remainder < 30" | bc -l) )); then + local remainder + remainder=$(awk "BEGIN {print $total_seconds % 60}") + if (($(echo "$remainder < 30" | bc -l))); then total_seconds=$(echo "$total_seconds - $remainder" | bc -l) else total_seconds=$(echo "$total_seconds + (60 - $remainder)" | bc -l) @@ -613,50 +621,58 @@ generate_cron_schedule() { fi [ -d /opt/pihole/speedtestmod ] || return - sudo bash -c "cat > $(printf %q "$schedule_script")" << EOF + sudo bash -c "cat > $(printf %q "$schedule_script")" < 0" | bc -l) )) || exit 0 -if [[ -f "\$last_run_file" ]]; then - last_run=\$(cat "\$last_run_file") +if [[ -f "\$LAST_RUN_FILE" ]]; then + declare last_run + last_run=\$(<"\$LAST_RUN_FILE") current_time=\$(date +%s) - if (( \$(echo "\$current_time - \$last_run < \$interval_seconds" | bc -l) )); then - exit 0 - fi + (( \$(echo "\$current_time - \$last_run >= \$INTERVAL_SECONDS" | bc -l) )) || exit 0 fi -echo \$(date +%s) > "\$last_run_file" -cat $speedtestfile | sudo bash +[[ \$(/usr/bin/tmux list-sessions 2>/dev/null | grep -c pimodtest) -eq 0 ]] || exit 0 +echo "\$current_time" > "\$LAST_RUN_FILE" +/usr/bin/tmux new-session -d -s pimodtest "sudo bash $speedtestfile" EOF sudo chmod +x "$schedule_script" crontab -l 2>/dev/null | grep -v "$schedule_script" | crontab - - if [[ "$total_seconds" == "nan" ]] || (( $(echo "$total_seconds > 0" | bc -l) )); then - crontab -l &> /dev/null || crontab -l 2>/dev/null | { cat; echo ""; } | crontab - - (crontab -l; echo "* * * * * /bin/bash $schedule_script") | crontab - + if [[ "$total_seconds" == "nan" ]] || (($(echo "$total_seconds > 0" | bc -l))); then + crontab -l &>/dev/null || crontab -l 2>/dev/null | { + cat + echo "" + } | crontab - + ( + crontab -l + echo "* * * * * /bin/bash $schedule_script" + ) | crontab - fi } ChangeSpeedTestSchedule() { local interval="${args[2]%\.}" if [[ "${interval-}" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then - if (( $(echo "$interval < 0" | bc -l) )); then + if (($(echo "$interval < 0" | bc -l))); then interval="0" else addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "$interval" @@ -671,9 +687,10 @@ ChangeSpeedTestSchedule() { if [[ ! -d /run/systemd/system ]]; then generate_cron_schedule "$interval" elif [[ "$interval" == "0" ]] || [[ "$interval" == "nan" ]]; then - systemctl disable --now pihole-speedtest.timer &> /dev/null + systemctl disable --now pihole-speedtest.timer &>/dev/null else - local freq=$(generate_systemd_calendar "$interval") + local freq + freq=$(generate_systemd_calendar "$interval") sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF [Unit] Description=Pi-hole Speedtest @@ -699,10 +716,10 @@ Persistent=true EOF' while IFS= read -r line; do sudo bash -c "echo 'OnCalendar=$line' >> /etc/systemd/system/pihole-speedtest.timer" - done <<< "$freq" + done <<<"$freq" systemctl daemon-reload - systemctl reenable pihole-speedtest.timer &> /dev/null + systemctl reenable pihole-speedtest.timer &>/dev/null systemctl restart pihole-speedtest.timer fi } @@ -733,25 +750,35 @@ SpeedtestServer() { } RunSpeedtestNow() { - if [[ $(tmux list-sessions 2>/dev/null | grep -c pimod) -eq 0 ]]; then - tmux new-session -d -s pimod "cat $speedtestfile | sudo bash" - fi + # if there is a running session, wait for it to finish + # if the session is still running after 5 minutes, kill it + while [[ $(tmux list-sessions 2>/dev/null | grep -c pimodtest) -gt 0 ]]; do + sleep 1 + ((counter++)) + + if [[ $counter -gt 300 ]]; then + tmux kill-session -t pimodtest + break + fi + done + + tmux new-session -d -s pimodtest "sudo bash $speedtestfile" } ReinstallSpeedTest() { - tmux new-session -d -s pimod "cat $speedtestmod | sudo bash" + tmux new-session -d -s pimod "sudo bash $speedtestmod" } UpdateSpeedTest() { - tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- up ${args[2]} ${args[3]}" + tmux new-session -d -s pimod "sudo bash $speedtestmod up ${args[2]} ${args[3]}" } UninstallSpeedTest() { - tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- un ${args[2]}" + tmux new-session -d -s pimod "sudo bash $speedtestmod un ${args[2]}" } ClearSpeedtestData() { - tmux new-session -d -s pimod "cat $speedtestmod | sudo bash -s -- db" + tmux new-session -d -s pimod "sudo bash $speedtestmod db" } SetWebUITheme() { From 1879f77f0d23383671cb89c7b85e0fdfc3bc9d13 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 27 Apr 2024 07:28:49 +0000 Subject: [PATCH 634/638] fix failing tests and package cache check (#113) * fix package check * git status was the issue --- advanced/Scripts/speedtestmod/mod.sh | 24 ++++++++++++++---------- advanced/Scripts/updatecheck.sh | 10 +++++++--- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 403814cd27..7aa64e20f9 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -22,6 +22,7 @@ getVersion() { if [[ -d "$1" ]]; then pushd "$1" &>/dev/null || exit 1 found_version=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') + [[ $found_version != *"("* ]] || found_version=$(git rev-parse HEAD 2>/dev/null) if [[ -z "${2:-}" ]]; then local tags @@ -38,7 +39,10 @@ getVersion() { found_version=$(cut -d ' ' -f 6 <<<"$versions") if [[ "$found_version" != *.* ]]; then - [[ "$found_version" != "$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}')" ]] || found_version=$(cut -d ' ' -f 7 <<<"$versions") + local found_branch + found_branch="$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}')" + [[ $found_branch != *"("* ]] || found_branch=$(git show-ref --heads | grep "$(git rev-parse HEAD)" | awk '{print $2;}' | cut -d '/' -f 3) + [[ "$found_version" != "$found_branch" ]] || found_version=$(cut -d ' ' -f 7 <<<"$versions") fi fi @@ -476,7 +480,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then readonly update backup online install reinstall stable uninstall database verbose chk_dep cleanup trap '[ "$?" -eq "0" ] && commit || abort' EXIT - printf "%s\n\nRunning The Mod Script by @ipitio...\n" "$(date)" + printf "%s\n\nRunning the Mod Script by @ipitio...\n" "$(date)" ! $verbose || set -x if $database; then @@ -503,7 +507,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then if ! $database || [[ "$num_args" -gt 1 ]]; then pushd ~ >/dev/null || exit 1 - pihole -v + pihole -v || : if [[ -f $CURR_WP ]] && grep -q SpeedTest "$CURR_WP"; then if $reinstall; then @@ -574,13 +578,13 @@ if [[ "${SKIP_MOD:-}" != true ]]; then readonly missingpkgs if [[ ${#missingpkgs[@]} -gt 0 ]]; then - if [[ "$pkg_manager" == *"apt-get"* ]] && apt-cache show "${missingpkgs[@]}" | grep -q "Unable to locate package"; then - echo "Updating Package Cache..." - apt-get update -y &>/dev/null - fi - echo "Installing Missing Dependencies..." - $pkg_manager install -y "${missingpkgs[@]}" &>/dev/null # hide an unimportant warning in docker + if ! $pkg_manager install -y "${missingpkgs[@]}" &>/dev/null; then + [[ "$pkg_manager" == *"apt-get"* ]] || exit 1 + echo "And Updating Package Cache..." + $pkg_manager update -y &>/dev/null + $pkg_manager install -y "${missingpkgs[@]}" &>/dev/null + fi fi fi @@ -623,7 +627,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then fi pihole updatechecker - pihole -v + pihole -v || : popd >/dev/null fi diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index d886e4acb5..e72ea061f9 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -13,6 +13,7 @@ function get_local_branch() { cd "${1}" 2> /dev/null || return 1 local foundBranch foundBranch=$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}') + [[ $foundBranch != *"("* ]] || foundBranch=$(git show-ref --heads | grep "$(git rev-parse HEAD)" | awk '{print $2;}' | cut -d '/' -f 3) echo "${foundBranch:-HEAD}" } @@ -21,8 +22,9 @@ function get_local_version() { cd "${1}" 2> /dev/null || return 1 local tags local foundVersion - tags=$(git ls-remote -t origin) + tags=$(git ls-remote -t origin || git show-ref --tags) foundVersion=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') + [[ $foundVersion != *"("* ]] || foundVersion=$(git rev-parse HEAD 2>/dev/null) local foundTag=$foundVersion # shellcheck disable=SC2015 grep -q "^$foundVersion" <<<"$tags" && foundTag=$(grep "^$foundVersion.*/v[0-9].*$" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) || : @@ -32,7 +34,9 @@ function get_local_version() { function get_local_hash() { cd "${1}" 2> /dev/null || return 1 - git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}' || return 1 + foundHash=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') + [[ $foundHash != *"("* ]] || foundHash=$(git rev-parse HEAD 2>/dev/null) + echo "${foundHash}" } function get_remote_version() { @@ -48,7 +52,7 @@ function get_remote_hash(){ for repo in "arevindh" "pi-hole" "ipitio"; do foundHash=$(git ls-remote "https://github.com/${repo}/${1}" --tags "${2}" | awk '{print $1;}' 2> /dev/null) - [[ -n "${foundHash}" ]] && break + [[ -z "${foundHash}" ]] || break done [[ -n "${foundHash}" ]] && echo "${foundHash}" || return 1 From ad77aa8a48527e36562578dded662645b2125962 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 27 Apr 2024 11:35:04 +0000 Subject: [PATCH 635/638] fetch tags for web (#114) --- advanced/Scripts/speedtestmod/mod.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index 7aa64e20f9..a26927524a 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -347,7 +347,7 @@ if [[ "${SKIP_MOD:-}" != true ]]; then # The changes reverted # shellcheck disable=SC2317 ########### abort() { - if $cleanup; then + if $cleanup && [[ $aborted -eq 0 ]]; then echo "Process Aborting..." aborted=1 @@ -544,6 +544,15 @@ if [[ "${SKIP_MOD:-}" != true ]]; then ! $online && restore $CORE_DIR || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" [[ ! -d $MOD_DIR ]] || rm -rf $MOD_DIR swapScripts + + if $update; then + for repo in $HTML_DIR/admin; do + pushd "$repo" &>/dev/null || exit 1 + git tag -l | xargs git tag -d >/dev/null 2>&1 + git fetch --tags -f -q + popd &>/dev/null + done + fi fi fi From 90c96774a6697ea40869459857ebc7e541948b79 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Sat, 27 Apr 2024 11:45:17 +0000 Subject: [PATCH 636/638] fetch tags on uninstall (#115) --- advanced/Scripts/speedtestmod/mod.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index a26927524a..b978cc127f 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -545,8 +545,8 @@ if [[ "${SKIP_MOD:-}" != true ]]; then [[ ! -d $MOD_DIR ]] || rm -rf $MOD_DIR swapScripts - if $update; then - for repo in $HTML_DIR/admin; do + if $update || $uninstall; then + for repo in $CORE_DIR $HTML_DIR/admin; do pushd "$repo" &>/dev/null || exit 1 git tag -l | xargs git tag -d >/dev/null 2>&1 git fetch --tags -f -q From 332b998a4a49aef55316a42491906952f27d9356 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Tue, 30 Apr 2024 12:36:39 +0000 Subject: [PATCH 637/638] create lib, fix speedtest, enhance mod script (#116) * create lib * fix speedtest runner * fix uninstall by fixing get_remote_hash * remove -c and -i options and add -s option * find last compatible versions when not updating pihole --- advanced/Scripts/speedtestmod/lib.sh | 507 ++++++++++ advanced/Scripts/speedtestmod/mod.sh | 1041 +++++++++----------- advanced/Scripts/speedtestmod/speedtest.sh | 423 +++----- advanced/Scripts/updatecheck.sh | 1 + advanced/Scripts/webpage.sh | 188 +--- 5 files changed, 1119 insertions(+), 1041 deletions(-) create mode 100755 advanced/Scripts/speedtestmod/lib.sh diff --git a/advanced/Scripts/speedtestmod/lib.sh b/advanced/Scripts/speedtestmod/lib.sh new file mode 100755 index 0000000000..a5d1d04086 --- /dev/null +++ b/advanced/Scripts/speedtestmod/lib.sh @@ -0,0 +1,507 @@ +#!/bin/bash +# +# The Library Script, Speedtest Mod for Pi-hole Helper Functions +# +# shellcheck disable=SC2015 +# + +declare PKG_MANAGER +PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) +readonly PKG_MANAGER + +####################################### +# Get the version of a repository, either from a local clone or from the installed package +# Globals: +# None +# Arguments: +# $1: The path to, or name of, the repository +# $2: Non-empty string to get the hash, empty string to get the tag if it exists +# Returns: +# The version of the repository +####################################### +getVersion() { + local found_version="" + + if [[ -d "$1" && -d "$1/.git" ]]; then + pushd "$1" &>/dev/null || exit 1 + found_version=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') + [[ $found_version != *"("* ]] || found_version=$(git rev-parse HEAD 2>/dev/null) + + if [[ -z "${2:-}" ]]; then + local tags + local found_tag=$found_version + tags=$(git ls-remote -t origin || git show-ref --tags) + ! grep -q "$found_version" <<<"$tags" || found_tag=$(grep "$found_version" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) + [[ -z "$found_tag" ]] || found_version=$found_tag + fi + + popd &>/dev/null || exit 1 + elif [[ -x "$(command -v pihole)" ]]; then + local versions + versions=$(pihole -v | grep "$1") + found_version=$(cut -d ' ' -f 6 <<<"$versions") + [[ "$found_version" == *.* || ${#found_version} -ge 40 ]] || found_version=$(cut -d ' ' -f 7 <<<"$versions") + fi + + echo "$found_version" +} + +####################################### +# Fetch a repository, optionally a specific version +# Globals: +# None +# Arguments: +# $1: The path to download the repository to +# $2: The name of the repository +# $3: The URL of the repository +# $4: The desired version, hash or tag, to download (optional, none by default) +# $5: The branch to download (optional, master by default) +# $6: Whether to snap to the tag (optional, true by default) +# Outputs: +# The repository at the desired version +####################################### +download() { + local path=$1 + local name=$2 + local url=$3 + local desired_version="${4:-}" + local branch="${5:-master}" + local snap_to_tag="${6:-true}" + local dest=$path/$name + local aborting=false + + [[ ! -d "$dest" || -d "$dest/.git" ]] || mv -f "$dest" "$dest.old" + [[ -d "$dest" ]] || git clone --depth=1 -b "$branch" "$url" "$dest" -q + pushd "$dest" &>/dev/null || exit 1 + git config --global --add safe.directory "$dest" + + if [[ -n "$desired_version" && "$desired_version" != *.* ]]; then + local repos=("Pi-hole" "web" "speedtest") + + for repo in "${repos[@]}"; do + if [[ "$desired_version" == *"$repo"* ]]; then + aborting=true + break + fi + done + fi + + if ! $aborting; then + ! git remote -v | grep -q "old" && git remote -v | grep -q "origin" && git remote rename origin old || : + ! git remote -v | grep -q "origin" || git remote remove origin + git remote add -t "$branch" origin "$url" + elif git remote -v | grep -q "old"; then + ! git remote -v | grep -q "origin" || git remote remove origin + git remote rename old origin + url=$(git remote get-url origin) + fi + + [[ "$url" != *"ipitio"* ]] || snap_to_tag=$(grep -q "true" <<<"$snap_to_tag" && echo "false" || echo "true") + git fetch origin --depth=1 "$branch":refs/remotes/origin/"$branch" -q + git reset --hard origin/"$branch" -q + git checkout -B "$branch" -q + local current_hash + local tags + current_hash=$(getVersion "$dest" hash) + tags=$(git ls-remote -t origin || git show-ref --tags) + + if [[ -z "$desired_version" ]]; then # if empty, get the latest version + local latest_tag="" + [[ "$snap_to_tag" != "true" ]] || latest_tag=$(awk -F/ '{print $3}' <<<"$tags" | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) + [[ -n "$latest_tag" ]] && desired_version=$latest_tag || desired_version=$current_hash + elif $aborting; then + desired_version=$(getVersion "$desired_version" hash) + fi + + if [[ "$desired_version" == *.* ]]; then + grep -q "$desired_version$" <<<"$tags" && desired_version=$(grep "$desired_version$" <<<"$tags" | awk '{print $1;}') || desired_version=$current_hash + fi + + if [[ "$current_hash" != "$desired_version" ]]; then + git fetch origin --depth=1 "$desired_version" -q + git reset --hard "$desired_version" -q + fi + + popd &>/dev/null || exit 1 +} + +####################################### +# Check if the package is available +# Globals: +# PKG_MANAGER +# Arguments: +# $1: Package name +# Returns: +# 0 if available, 1 if not +####################################### +isAvailable() { + if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + # Check if there is a candidate and it is not "(none)" + apt-cache policy "$1" | grep -q "Candidate:" && ! apt-cache policy "$1" | grep -q "Candidate: (none)" && return 0 || return 1 + elif [[ "$PKG_MANAGER" == *"dnf"* || "$PKG_MANAGER" == *"yum"* ]]; then + $PKG_MANAGER list available "$1" &>/dev/null && return 0 || return 1 + else + echo "Unsupported package manager!" + exit 1 + fi +} + +####################################### +# Check if a package is installed, only used below when --continuous is not +# Globals: +# None +# Arguments: +# $1: The package to check +# Returns: +# 0 if the package is not installed, 1 if it is +####################################### +notInstalled() { + if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + dpkg -s "$1" &>/dev/null || return 0 + elif [[ "$PKG_MANAGER" == *"dnf"* || "$PKG_MANAGER" == *"yum"* ]]; then + rpm -q "$1" &>/dev/null || return 0 + else + echo "Unsupported package manager!" + exit 1 + fi + + return 1 +} + +####################################### +# Set a key-value pair in a configuration file, used below for --reinstall +# Globals: +# None +# Arguments: +# $1: The key to set +# $2: The value to set +# $3: The configuration file to set the key-value pair in +# $4: Whether to replace the value if it already exists +# Outputs: +# The configuration file with the key-value pair set +####################################### +setCnf() { + grep -q "^$1=" "$3" || echo "$1=$2" >>"$3" + [[ "${4:-false}" == "true" ]] || sed -i "s|^$1=.*|$1=$2|" "$3" +} + +####################################### +# Get a key-value pair from a configuration file, used below for --reinstall +# Globals: +# None +# Arguments: +# $1: The configuration file to get the key-value pair from +# $2: The key to get the value of +# $3: Non-empty string to get the hash, empty string to get the tag if it exists +# Returns: +# The value of the key-value pair +####################################### +getCnf() { + local keydir + local value + keydir=$(echo "$2" | sed 's/^mod-//;s/^org-//') + value=$(grep "^$2=" "$1" | cut -d '=' -f 2) + [[ -n "$value" ]] || value=$(getVersion "$keydir" "${3:-}") + echo "$value" +} + +####################################### +# Download and install librespeed +# Globals: +# PKG_MANAGERsetupVars +# Arguments: +# None +# Returns: +# 0 if the installation was successful, 1 if it was not +####################################### +libreSpeed() { + echo "Installing LibreSpeed..." + $PKG_MANAGER remove -y speedtest-cli speedtest >/dev/null 2>&1 + + if notInstalled golang; then + if grep -q "Raspbian" /etc/os-release; then + if [[ ! -f /etc/apt/sources.list.d/testing.list ]] && ! grep -q "testing" /etc/apt/sources.list; then + echo "Adding testing repo to sources.list.d" + echo "deb http://archive.raspbian.org/raspbian/ testing main" >/etc/apt/sources.list.d/testing.list + printf "Package: *\nPin: release a=testing\nPin-Priority: 50" >/etc/apt/preferences.d/limit-testing + $PKG_MANAGER update -y + fi + + $PKG_MANAGER install -y -t testing golang + else + $PKG_MANAGER install -y golang + fi + fi + + download /etc/pihole librespeed https://github.com/librespeed/speedtest-cli + pushd /etc/pihole/librespeed &>/dev/null || return 1 + [[ ! -d out ]] || rm -rf out + ./build.sh + rm -f /usr/bin/speedtest + mv -f out/* /usr/bin/speedtest + popd &>/dev/null || return 1 + chmod +x /usr/bin/speedtest + + if [[ -x /usr/bin/speedtest ]]; then + echo "Installed LibreSpeed." + return 0 + fi + + echo "Installation of $candidate Failed!" + return 1 +} + +####################################### +# Install a package, removing a conflicting package if necessary +# Globals: +# PKG_MANAGER +# Arguments: +# None +# Outputs: +# The installed package +####################################### +swivelSpeed() { + local candidate="${1:-speedtest-cli}" + local target="${2:-speedtest}" + [[ ! -f /usr/bin/speedtest ]] || rm -f /usr/bin/speedtest + echo "Installing $candidate..." + + case "$PKG_MANAGER" in + /usr/bin/apt-get) + ! isAvailable "$candidate" && echo "And Updating Package Cache..." && $PKG_MANAGER update -y &>/dev/null || : + "$PKG_MANAGER" install -y "$candidate" "$target"- &>/dev/null + ;; + /usr/bin/dnf) "$PKG_MANAGER" install -y --allowerasing "$candidate" &>/dev/null ;; + /usr/bin/yum) "$PKG_MANAGER" install -y --allowerasing "$candidate" &>/dev/null ;; + esac + + if ! notInstalled "$candidate"; then + printf "Installed " + /usr/bin/speedtest --version || return 1 + return 0 + fi + + echo "Installation of $candidate Failed!" + return 1 +} + +####################################### +# Add the Ookla speedtest CLI source and install the package +# Globals: +# PKG_MANAGER +# Arguments: +# None +# Outputs: +# The source for the speedtest CLI and the package +####################################### +ooklaSpeed() { + if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* && ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]]; then + echo "Adding speedtest source for RPM..." + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash + elif [[ "$PKG_MANAGER" == *"apt-get"* && ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]]; then + echo "Adding speedtest source for DEB..." + if [[ -e /etc/os-release ]]; then + # shellcheck disable=SC1091 + source /etc/os-release + local -r base="ubuntu debian" + local os=${ID} + local dist=${VERSION_CODENAME} + # shellcheck disable=SC2076 + if [[ -n "${ID_LIKE:-}" && "${base//\"/}" =~ "${ID_LIKE//\"/}" && "${os}" != "ubuntu" ]]; then + os=${ID_LIKE%% *} + [[ -z "${UBUNTU_CODENAME:-}" ]] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) + dist=${UBUNTU_CODENAME} + [[ -z "$dist" ]] && dist=${VERSION_CODENAME} + fi + wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 + chmod +x /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh + rm -f /tmp/script.deb.sh + else + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash + fi + + sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list + apt-get update -y &>/dev/null + fi + + swivelSpeed speedtest speedtest-cli +} + +####################################### +# Use an interval to generate a systemd calendar +# Globals: +# None +# Arguments: +# $1: The interval in hours, down to the minute +# Outputs: +# The systemd unit and timer files +####################################### +generate_systemd_service() { + local interval_hours="$1" + local freq_entries=() + local total_seconds + total_seconds=$(echo "$interval_hours * 3600" | bc) + + if (($(echo "$total_seconds < 60" | bc -l))); then # less than a minute + total_seconds=60 + addOrEditKeyValPair "/etc/pihole/setupVars.conf" "SPEEDTESTSCHEDULE" "0.017" + fi + + if (($(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l))); then # less than an hour + local minute_interval + minute_interval=$(echo "$total_seconds / 60" | bc) + freq_entries+=("*-*-* *:00/$minute_interval:00") + elif (($(echo "$total_seconds == 3600" | bc -l))); then # exactly an hour + freq_entries+=("*-*-* *:00:00") + elif (($(echo "$total_seconds < 86400" | bc -l))); then # less than a day + if (($(awk "BEGIN {print ($total_seconds / 3600) % 1}") == 0)); then # divides evenly into an hour + local hour_interval + hour_interval=$(echo "$total_seconds / 3600" | bc) + freq_entries+=("*-*-* 00/$hour_interval:00:00") + else # does not divide evenly into an hour + local current_second=0 + + while (($(echo "$current_second < 86400" | bc -l))); do + local hour + hour=$(echo "$current_second / 3600" | bc) + local minute + minute=$(awk "BEGIN {print ($current_second % 3600) / 60}") + hour=${hour%.*} + minute=${minute%.*} + freq_entries+=("*-*-* $(printf "%02d:%02d:00" "$hour" "$minute")") + current_second=$(echo "$current_second + $total_seconds" | bc) + done + fi + else # more than a day + local full_days + local remaining_hours + full_days=$(echo "$interval_hours / 24" | bc) + remaining_hours=$(echo "$interval_hours - ($full_days * 24)" | bc) + + if (($(echo "$full_days > 0" | bc -l))); then + freq_entries+=("*-*-1/$(printf "%02.0f" "$full_days")") + fi + + if (($(echo "$remaining_hours > 0" | bc -l))); then # partial day + local remaining_minutes + remaining_minutes=$(echo "($remaining_hours - ($remaining_hours / 1)) * 60" | bc) + remaining_hours=${remaining_hours%.*} + remaining_minutes=${remaining_minutes%.*} + freq_entries+=("*-*-* $(printf "%02d:%02d:00" "$remaining_hours" "$remaining_minutes")") + fi + fi + + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF +[Unit] +Description=Pi-hole Speedtest +After=network.target + +[Service] +User=root +Type=forking +ExecStart=/usr/local/bin/pihole -a -sn + +[Install] +WantedBy=multi-user.target +EOF' + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF +[Unit] +Description=Pi-hole Speedtest Timer + +[Install] +WantedBy=timers.target + +[Timer] +Persistent=true +EOF' + + for freq in "${freq_entries[@]}"; do + sudo bash -c "echo 'OnCalendar=$freq' >> /etc/systemd/system/pihole-speedtest.timer" + done + + systemctl daemon-reload + systemctl reenable pihole-speedtest.timer &>/dev/null + systemctl restart pihole-speedtest.timer +} + +####################################### +# Save the interval to a file that is run by cron every minute +# Globals: +# None +# Arguments: +# $1: The interval in hours +# Outputs: +# The interval in a file and the cron job +####################################### +generate_cron_job() { + local total_seconds="nan" + local schedule_script="/opt/pihole/speedtestmod/schedule_check.sh" + + if [[ "$1" != "nan" ]] && [[ "$1" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (($(echo "$1 > 0" | bc -l))); then + total_seconds=$(echo "$1 * 3600" | bc) + if (($(echo "$total_seconds < 60" | bc -l))); then + total_seconds=60 + fi + + local remainder + remainder=$(awk "BEGIN {print $total_seconds % 60}") + + if (($(echo "$remainder < 30" | bc -l))); then + total_seconds=$(echo "$total_seconds - $remainder" | bc -l) + else + total_seconds=$(echo "$total_seconds + (60 - $remainder)" | bc -l) + fi + + addOrEditKeyValPair "/etc/pihole/setupVars.conf" "SPEEDTESTSCHEDULE" "$(echo "scale=3; $total_seconds / 3600" | bc)" + fi + + [ -d /opt/pihole/speedtestmod ] || return + sudo bash -c "cat > $(printf %q "$schedule_script")" < 0" | bc -l) )) || exit 0 + +if [[ -f "\$LAST_RUN_FILE" ]]; then + declare last_run + last_run=\$(<"\$LAST_RUN_FILE") + current_time=\$(date +%s) + (( \$(echo "\$current_time - \$last_run >= \$INTERVAL_SECONDS" | bc -l) )) || exit 0 +fi + +[[ \$(/usr/bin/tmux list-sessions 2>/dev/null | grep -c pimodtest) -eq 0 ]] || exit 0 +echo "\$current_time" > "\$LAST_RUN_FILE" +/usr/bin/tmux new-session -d -s pimodtest "sudo bash /opt/pihole/speedtestmod/speedtest.sh" +EOF + sudo chmod +x "$schedule_script" + + crontab -l 2>/dev/null | grep -v "$schedule_script" | crontab - + + if [[ "$total_seconds" == "nan" ]] || (($(echo "$total_seconds > 0" | bc -l))); then + crontab -l &>/dev/null || crontab -l 2>/dev/null | { + cat + echo "" + } | crontab - + ( + crontab -l + echo "* * * * * /bin/bash $schedule_script" + ) | crontab - + fi +} diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index b978cc127f..d8b9302f58 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -6,651 +6,530 @@ # shellcheck disable=SC2015 # +declare -r HTML_DIR="/var/www/html" +declare -r CORE_DIR="/etc/.pihole" +declare -r OPT_DIR="/opt/pihole" +declare -r ETC_DIR="/etc/pihole" +declare -r MOD_DIR="/etc/pihole-speedtest" +declare -r CURR_WP="$OPT_DIR/webpage.sh" +declare -r CURR_DB="$ETC_DIR/speedtest.db" +declare -r LAST_DB="$CURR_DB.old" +declare -r DB_TABLE="speedtest" +declare -i aborted=0 +st_ver="" +mod_core_ver="" +mod_admin_ver="" +cleanup=true +# shellcheck disable=SC2034 +SKIP_INSTALL=true +# shellcheck disable=SC1091 +source "$CORE_DIR/automated install/basic-install.sh" +# shellcheck disable=SC1090,SC1091 +[[ -f "$OPT_DIR/speedtestmod/lib.sh" ]] && source "$OPT_DIR/speedtestmod/lib.sh" || source <(curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/lib.sh) + ####################################### -# Get the version of a repository, either from a local clone or from the installed package +# Display the help message # Globals: # None # Arguments: -# $1: The path to, or name of, the repository -# $2: Non-empty string to get the hash, empty string to get the tag if it exists -# Returns: -# The version of the repository +# None +# Outputs: +# The help message ####################################### -getVersion() { - local found_version="" - - if [[ -d "$1" ]]; then - pushd "$1" &>/dev/null || exit 1 - found_version=$(git status --porcelain=2 -b | grep branch.oid | awk '{print $3;}') - [[ $found_version != *"("* ]] || found_version=$(git rev-parse HEAD 2>/dev/null) - - if [[ -z "${2:-}" ]]; then - local tags - local found_tag=$found_version - tags=$(git ls-remote -t origin || git show-ref --tags) - ! grep -q "$found_version" <<<"$tags" || found_tag=$(grep "$found_version" <<<"$tags" | awk '{print $2;}' | cut -d '/' -f 3 | sort -V | tail -n1) - [[ -z "$found_tag" ]] || found_version=$found_tag - fi - - popd &>/dev/null - elif [[ -x "$(command -v pihole)" ]]; then - local versions - versions=$(pihole -v | grep "$1") - found_version=$(cut -d ' ' -f 6 <<<"$versions") - - if [[ "$found_version" != *.* ]]; then - local found_branch - found_branch="$(git status --porcelain=2 -b | grep branch.head | awk '{print $3;}')" - [[ $found_branch != *"("* ]] || found_branch=$(git show-ref --heads | grep "$(git rev-parse HEAD)" | awk '{print $2;}' | cut -d '/' -f 3) - [[ "$found_version" != "$found_branch" ]] || found_version=$(cut -d ' ' -f 7 <<<"$versions") - fi - fi +help() { + local -r help_text=( + "The Mod Script" + "Usage: sudo bash /path/to/mod.sh [options]" + " or: curl -sSLN //link/to/mod.sh | sudo bash [-s -- options]" + "(Re)install the latest release of the Speedtest Mod and/or the following options:" + "" + "Installation:" + " -u, --update, up also update Pi-hole" + " -r, --reinstall keep current version of the mod, if installed" + " -t, --testing install the beta version of the mod" + "" + "Restoration:" + " -n, --uninstall, un purge the mod, keeping the speedtest package, logs, and database" + " -b, --backup backup Pi-hole for faster offline restore" + " -o, --online force online restore of Pi-hole" + "" + "Standalone:" + " -d, --database, db flush/restore the database if it's not/empty" + " -s, --speedtest[=] install Ookla's or the specified CLI even if another is already installed" + " -x, --verbose show the commands being run" + " -v, --version display the version of the mod and exit" + " -h, --help display this help message and exit" + "" + "Examples:" + " sudo bash /opt/pihole/speedtestmod/mod.sh -d -slibre" + " sudo bash /opt/pihole/speedtestmod/mod.sh --uninstall" + " curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod | sudo bash" + " curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -bo" + ) + + printf "%s\n" "${help_text[@]}" + cleanup=false + exit 0 +} - echo "$found_version" +####################################### +# Check if a database is empty +# Globals: +# DB_TABLE +# Arguments: +# $1: The database to check +# Returns: +# 0 if the database is empty, 1 if it is not +####################################### +isEmpty() { + [[ -f "$1" ]] && sqlite3 "$1" "select * from $DB_TABLE limit 1;" &>/dev/null && [[ -n "$(sqlite3 "$1" "select * from $DB_TABLE limit 1;")" ]] && return 1 || return 0 } ####################################### -# Fetch a repository, optionally a specific version +# Copy scripts from the CORE to the OPT repository # Globals: -# None +# OPT_DIR # Arguments: -# $1: The path to download the repository to -# $2: The name of the repository -# $3: The URL of the repository -# $4: The desired version, hash or tag, to download (optional, none by default) -# $5: The branch to download (optional, master by default) -# $6: Whether to snap to the tag (optional, true by default) +# None # Outputs: -# The repository at the desired version +# The scripts copied to the OPT repository ####################################### -download() { - local path=$1 - local name=$2 - local url=$3 - local desired_version="${4:-}" - local branch="${5:-master}" - local snap_to_tag="${6:-true}" - local dest=$path/$name - local aborting=false - - [[ ! -d "$dest" || -d "$dest/.git" ]] || mv -f "$dest" "$dest.old" - [[ -d "$dest" ]] || git clone --depth=1 -b "$branch" "$url" "$dest" -q - pushd "$dest" &>/dev/null || exit 1 - git config --global --add safe.directory "$dest" - - if [[ -n "$desired_version" && "$desired_version" != *.* ]]; then - local repos=("Pi-hole" "web" "speedtest") - - for repo in "${repos[@]}"; do - if [[ "$desired_version" == *"$repo"* ]]; then - aborting=true - break - fi - done - fi - - if ! $aborting; then - ! git remote -v | grep -q "old" && git remote -v | grep -q "origin" && git remote rename origin old || : - ! git remote -v | grep -q "origin" || git remote remove origin - git remote add -t "$branch" origin "$url" - elif git remote -v | grep -q "old"; then - ! git remote -v | grep -q "origin" || git remote remove origin - git remote rename old origin - url=$(git remote get-url origin) - fi - - [[ "$url" != *"ipitio"* ]] || snap_to_tag=$(grep -q "true" <<<"$snap_to_tag" && echo "false" || echo "true") - git fetch origin --depth=1 "$branch":refs/remotes/origin/"$branch" -q - git reset --hard origin/"$branch" -q - git checkout -B "$branch" -q - local current_hash - local tags - current_hash=$(getVersion "$dest" hash) - tags=$(git ls-remote -t origin || git show-ref --tags) - - if [[ -z "$desired_version" ]]; then # if empty, get the latest version - local latest_tag="" - [[ "$snap_to_tag" != "true" ]] || latest_tag=$(awk -F/ '{print $3}' <<<"$tags" | grep '^v[0-9]' | grep -v '\^{}' | sort -V | tail -n1) - [[ -n "$latest_tag" ]] && desired_version=$latest_tag || desired_version=$current_hash - elif $aborting; then - desired_version=$(getVersion "$desired_version" hash) - fi - - if [[ "$desired_version" == *.* ]]; then - grep -q "$desired_version$" <<<"$tags" && desired_version=$(grep "$desired_version$" <<<"$tags" | awk '{print $1;}') || desired_version=$current_hash - fi - - if [[ "$current_hash" != "$desired_version" ]]; then - git fetch origin --depth=1 "$desired_version" -q - git reset --hard "$desired_version" -q - fi - - popd &>/dev/null +swapScripts() { + set +u + installScripts >/dev/null 2>&1 + set -u } ####################################### -# Check if a package is installed, only used below when --continuous is not +# Restore a backup, used after --backup unless --online or --install are used # Globals: # None # Arguments: -# $1: The package to check +# $1: The backup to restore # Returns: -# 0 if the package is not installed, 1 if it is +# 1 if the backup does not exist or is stale, 0 if it does and isn't +# Outputs: +# The backup restored ####################################### -notInstalled() { - if [[ -x "$(command -v apt-get)" ]]; then - dpkg -s "$1" &>/dev/null || return 0 - elif [[ -x "$(command -v dnf)" ]] || [[ -x "$(command -v yum)" ]]; then - rpm -q "$1" &>/dev/null || return 0 - else - echo "Unsupported package manager!" - exit 1 - fi - - return 1 +restore() { + [[ -d "$1".bak && "$(getVersion "$1".bak hash)" == "$(getCnf $MOD_DIR/cnf org-"$1" hash)" ]] || return 1 + [[ ! -e "$1" ]] || rm -rf "$1" + mv -f "$1".bak "$1" } ####################################### -# Set a key-value pair in a configuration file, used below for --reinstall +# Purge the mod, used for --uninstall # Globals: -# None +# CORE_DIR +# HTML_DIR +# OPT_DIR +# CURR_DB +# ETC_DIR # Arguments: -# $1: The key to set -# $2: The value to set -# $3: The configuration file to set the key-value pair in -# $4: Whether to replace the value if it already exists +# None # Outputs: -# The configuration file with the key-value pair set +# The mod purged ####################################### -setCnf() { - grep -q "^$1=" "$3" || echo "$1=$2" >>"$3" - [[ "${4:-false}" == "true" ]] || sed -i "s|^$1=.*|$1=$2|" "$3" +purge() { + if [[ -f /etc/systemd/system/pihole-speedtest.timer ]]; then + rm -f /etc/systemd/system/pihole-speedtest.service + rm -f /etc/systemd/system/pihole-speedtest.timer + systemctl daemon-reload + fi + + rm -rf $OPT_DIR/speedtestmod + rm -rf $CORE_DIR.bak + rm -rf $HTML_DIR/admin.bak + rm -rf $CORE_DIR.mod + rm -rf $HTML_DIR/admin.mod + rm -f "$CURR_DB".* + rm -f $ETC_DIR/last_speedtest.* + ! isEmpty $CURR_DB || rm -f $CURR_DB } ####################################### -# Get a key-value pair from a configuration file, used below for --reinstall +# Abort the process # Globals: -# None +# CORE_DIR +# HTML_DIR +# MOD_DIR +# OPT_DIR +# CURR_WP +# CURR_DB +# LAST_DB +# ETC_DIR +# cleanup +# aborted # Arguments: -# $1: The configuration file to get the key-value pair from -# $2: The key to get the value of -# $3: Non-empty string to get the hash, empty string to get the tag if it exists -# Returns: -# The value of the key-value pair -####################################### -getCnf() { - local keydir - local value - keydir=$(echo "$2" | sed 's/^mod-//;s/^org-//') - value=$(grep "^$2=" "$1" | cut -d '=' -f 2) - [[ -n "$value" ]] || value=$(getVersion "$keydir" "${3:-}") - echo "$value" +# None +# Outputs: +# The changes reverted +# shellcheck disable=SC2317 ########### +abort() { + if $cleanup && [[ $aborted -eq 0 ]]; then + echo "Process Aborting..." + aborted=1 + + if [[ -d "$CORE_DIR"/.git/refs/remotes/old ]]; then + download /etc .pihole "" Pi-hole + swapScripts + + if [[ -d "$CORE_DIR"/advanced/Scripts/speedtestmod ]]; then + \cp -af "$CORE_DIR"/advanced/Scripts/speedtestmod/. "$OPT_DIR"/speedtestmod/ + pihole -a -s + fi + fi + + [[ ! -d "$MOD_DIR" || ! -d "$MOD_DIR"/.git/refs/remotes/old ]] || download /etc pihole-speedtest "" speedtest + [[ ! -d "$HTML_DIR"/admin/.git/refs/remotes/old ]] || download "$HTML_DIR" admin "" web + [[ ! -f "$LAST_DB" || -f "$CURR_DB" ]] || mv "$LAST_DB" "$CURR_DB" + [[ -f "$CURR_WP" ]] && ! grep -q SpeedTest "$CURR_WP" && purge || : + printf "Please try again before reporting an issue.\n\n%s\n" "$(date)" + fi } -# allow to source the above helper functions without running the whole script -if [[ "${SKIP_MOD:-}" != true ]]; then - declare -r HTML_DIR="/var/www/html" - declare -r CORE_DIR="/etc/.pihole" - declare -r OPT_DIR="/opt/pihole" - declare -r ETC_DIR="/etc/pihole" - declare -r MOD_DIR="/etc/pihole-speedtest" - declare -r CURR_WP="$OPT_DIR/webpage.sh" - declare -r CURR_DB="$ETC_DIR/speedtest.db" - declare -r LAST_DB="$CURR_DB.old" - declare -r DB_TABLE="speedtest" - declare -i aborted=0 - st_ver="" - mod_core_ver="" - mod_admin_ver="" - cleanup=true +####################################### +# Commit the changes +# Globals: +# CORE_DIR +# HTML_DIR +# cleanup +# Arguments: +# None +# Outputs: +# The repositories cleaned up +# shellcheck disable=SC2317 ########### +commit() { + if $cleanup; then + for dir in $CORE_DIR $HTML_DIR/admin; do + [[ ! -d "$dir" ]] && continue || pushd "$dir" &>/dev/null || exit 1 + ! git remote -v | grep -q "old" || git remote remove old + git clean -ffdx + popd &>/dev/null + done - set +u - # shellcheck disable=SC2034 - SKIP_INSTALL=true - # shellcheck disable=SC1091 - source "$CORE_DIR/automated install/basic-install.sh" - set -u + printf "Done!\n\n%s\n" "$(date)" + fi +} - ####################################### - # Display the help message - # Globals: - # None - # Arguments: - # None - # Outputs: - # The help message - ####################################### - help() { - local -r help_text=( - "The Mod Script" - "Usage: sudo bash /path/to/mod.sh [options]" - " or: curl -sSLN //link/to/mod.sh | sudo bash [-s -- options]" - "(Re)install the latest release of the Speedtest Mod, and/or the following options:" - "" - "Options:" - " -b, --backup preserve stock Pi-hole files for faster offline restore" - " -o, --online force online restore of stock Pi-hole files even if a backup exists" - " -i, --install skip restore of stock Pi-hole*" - " -c, --continuous skip check for missing dependencies" - " -r, --reinstall keep current version of the mod, if installed*" - " -t, --testing install the latest commit" - " -u, --update, up also update Pi-hole, unless Systemd is not being used (ie. not in Docker)" - " -n, --uninstall, un remove the mod and its files, but keep the database" - " -d, --database, db flush/restore the database if it's not/empty (and exit if this is the only arg given)" - " -x, --verbose show the commands being run" - " -v, --version display the version of the mod and exit" - " -h, --help display this help message and exit" - "" - " *for when not updating Pi-hole nor switching repos" - "" - "Examples:" - " sudo bash /opt/pihole/speedtestmod/mod.sh -ubo" - " sudo bash /opt/pihole/speedtestmod/mod.sh -i -r -d" - " sudo bash /opt/pihole/speedtestmod/mod.sh --uninstall" - " curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -u" - ) - - printf "%s\n" "${help_text[@]}" - } - - ####################################### - # Check if a database is empty - # Globals: - # DB_TABLE - # Arguments: - # $1: The database to check - # Returns: - # 0 if the database is empty, 1 if it is not - ####################################### - isEmpty() { - [[ -f "$1" ]] && sqlite3 "$1" "select * from $DB_TABLE limit 1;" &>/dev/null && [[ -n "$(sqlite3 "$1" "select * from $DB_TABLE limit 1;")" ]] && return 1 || return 0 - } - - ####################################### - # Copy scripts from the CORE to the OPT repository - # Globals: - # OPT_DIR - # Arguments: - # None - # Outputs: - # The scripts copied to the OPT repository - ####################################### - swapScripts() { - set +u - installScripts >/dev/null 2>&1 - set -u - } - - ####################################### - # Restore a backup, used after --backup unless --online or --install are used - # Globals: - # None - # Arguments: - # $1: The backup to restore - # Returns: - # 1 if the backup does not exist or is stale, 0 if it does and isn't - # Outputs: - # The backup restored - ####################################### - restore() { - [[ -d "$1".bak && "$(getVersion "$1".bak hash)" == "$(getCnf $MOD_DIR/cnf org-"$1" hash)" ]] || return 1 - [[ ! -e "$1" ]] || rm -rf "$1" - mv -f "$1".bak "$1" - } - - ####################################### - # Purge the mod, used for --uninstall - # Globals: - # CORE_DIR - # HTML_DIR - # OPT_DIR - # CURR_DB - # ETC_DIR - # Arguments: - # None - # Outputs: - # The mod purged - ####################################### - purge() { - if [[ -f /etc/systemd/system/pihole-speedtest.timer ]]; then - rm -f /etc/systemd/system/pihole-speedtest.service - rm -f /etc/systemd/system/pihole-speedtest.timer - systemctl daemon-reload +####################################### +# Manage the installation +# Globals: +# CORE_DIR +# HTML_DIR +# MOD_DIR +# OPT_DIR +# CURR_WP +# CURR_DB +# LAST_DB +# ETC_DIR +# st_ver +# mod_core_ver +# mod_admin_ver +# cleanup +# Arguments: +# $@: The options for managing the installation +# Outputs: +# The installation managed +####################################### +main() { + local -r short_opts=-ubortnds::vxh + local -r long_opts=update,backup,online,reinstall,testing,uninstall,database,speedtest::,version,verbose,help + local parsed_opts + parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@") || help + eval set -- "${parsed_opts}" + + declare -a POSITIONAL EXTRA_ARGS + local -i dashes=0 + local update=false + local backup=false + local online=false + local reinstall=false + local stable=true + local uninstall=false + local database=false + local verbose=false + local select_test=false + local selected_test="" + local do_main=false + + while [[ $# -gt 0 ]]; do + case "$1" in + -u | --update) + update=true + do_main=true + ;; + -b | --backup) + backup=true + do_main=true + ;; + -o | --online) + online=true + do_main=true + ;; + -r | --reinstall) + reinstall=true + do_main=true + ;; + -t | --testing) + stable=false + do_main=true + ;; + -n | --uninstall) + uninstall=true + do_main=true + ;; + -d | --database) database=true ;; + -s | --speedtest) + select_test=true + [[ -n "$2" && ! "$2" =~ sivel|libre ]] && help || selected_test=$2 + shift + ;; + -v | --version) + getVersion $MOD_DIR + cleanup=false + exit 0 + ;; + -x | --verbose) verbose=true ;; + -h | --help) help ;; + --) dashes=1 ;; + *) [[ $dashes -eq 0 ]] && POSITIONAL+=("$1") || EXTRA_ARGS+=("$1") ;; + esac + shift + done + + set -- "${POSITIONAL[@]}" + + # backward compatibility + for arg in "$@"; do + case $arg in + up) update=true ;; + un) uninstall=true ;; + db) database=true ;; + *) help ;; + esac + done + + readonly update backup online reinstall stable uninstall database verbose cleanup select_test selected_test + trap '[ "$?" -eq "0" ] && commit || abort' EXIT + trap 'abort' INT TERM ERR + set -Eeuo pipefail + shopt -s dotglob + printf "%s\n\nRunning the Mod Script by @ipitio...\n" "$(date)" + ! $do_main && ! $database && ! $select_test && do_main=true || : + ! $verbose || set -x + + if $database; then + if [[ -f $CURR_DB ]] && ! isEmpty $CURR_DB; then + echo "Flushing Database..." + mv -f $CURR_DB $LAST_DB + [[ ! -f $ETC_DIR/last_speedtest ]] || mv -f $ETC_DIR/last_speedtest $ETC_DIR/last_speedtest.old + + if [[ -f /var/log/pihole/speedtest.log ]]; then + mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old + rm -f $ETC_DIR/speedtest.log + fi + elif [[ -f $LAST_DB ]]; then + echo "Restoring Database..." + mv -f $LAST_DB $CURR_DB + [[ ! -f $ETC_DIR/last_speedtest.old ]] || mv -f $ETC_DIR/last_speedtest.old $ETC_DIR/last_speedtest + + if [[ -f /var/log/pihole/speedtest.log.old ]]; then + mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log + \cp -af /var/log/pihole/speedtest.log $ETC_DIR/speedtest.log + fi fi + fi - rm -rf $OPT_DIR/speedtestmod - rm -rf $CORE_DIR.bak - rm -rf $HTML_DIR/admin.bak - rm -rf $CORE_DIR.mod - rm -rf $HTML_DIR/admin.mod - rm -f "$CURR_DB".* - rm -f $ETC_DIR/last_speedtest.* - ! isEmpty $CURR_DB || rm -f $CURR_DB - } - - ####################################### - # Abort the process - # Globals: - # CORE_DIR - # HTML_DIR - # MOD_DIR - # OPT_DIR - # CURR_WP - # CURR_DB - # LAST_DB - # ETC_DIR - # cleanup - # aborted - # Arguments: - # None - # Outputs: - # The changes reverted - # shellcheck disable=SC2317 ########### - abort() { - if $cleanup && [[ $aborted -eq 0 ]]; then - echo "Process Aborting..." - aborted=1 - - if [[ -d "$CORE_DIR"/.git/refs/remotes/old ]]; then - download /etc .pihole "" Pi-hole - swapScripts - - if [[ -d "$CORE_DIR"/advanced/Scripts/speedtestmod ]]; then - \cp -af "$CORE_DIR"/advanced/Scripts/speedtestmod/. "$OPT_DIR"/speedtestmod/ - pihole -a -s - fi + if $select_test; then + set +Eeo pipefail # don't exit on error, not critical + case $selected_test in + sivel) swivelSpeed ;; + libre) libreSpeed ;; + *) ooklaSpeed ;; + esac + set -Eeo pipefail + fi + + if $do_main; then + if [[ ! -f /usr/local/bin/pihole ]]; then + # https://discourse.pi-hole.net/t/pi-hole-as-part-of-a-post-installation-script/3523/15 + if [[ ! -f /etc/pihole/setupVars.conf ]]; then + cat </etc/pihole/setupVars.conf +WEBPASSWORD={{ pihole_admin_password | hash('sha256') | hash('sha256') }} +PIHOLE_INTERFACE=eth0 +IPV4_ADDRESS=192.168.x.y/24 +IPV6_ADDRESS=fd00::2 +QUERY_LOGGING=true +INSTALL_WEB_INTERFACE=true +LIGHTTPD_ENABLED=false +INSTALL_WEB_SERVER=false +DNSMASQ_LISTENING=single +PIHOLE_DNS_1=8.8.8.8 +PIHOLE_DNS_2=4.4.4.4 +PIHOLE_DNS_3=2001:4860:4860:0:0:0:0:8888 +PIHOLE_DNS_4=2001:4860:4860:0:0:0:0:8844 +DNS_FQDN_REQUIRED=true +DNS_BOGUS_PRIV=true +DNSSEC=false +TEMPERATUREUNIT=C +WEBUIBOXEDLAYOUT=traditional +API_EXCLUDE_DOMAINS= +API_EXCLUDE_CLIENTS= +API_QUERY_LOG_SHOW=all +API_PRIVACY_MODE=false +BLOCKING_ENABLED=true +REV_SERVER=true +REV_SERVER_CIDR=192.168.x.0/24 +REV_SERVER_TARGET=192.168.x.z +REV_SERVER_DOMAIN=your.domain +CACHE_SIZE=10000 +EOF fi - [[ ! -d "$MOD_DIR" || ! -d "$MOD_DIR"/.git/refs/remotes/old ]] || download /etc pihole-speedtest "" speedtest - [[ ! -d "$HTML_DIR"/admin/.git/refs/remotes/old ]] || download "$HTML_DIR" admin "" web - [[ ! -f "$LAST_DB" || -f "$CURR_DB" ]] || mv "$LAST_DB" "$CURR_DB" - [[ -f "$CURR_WP" ]] && ! grep -q SpeedTest "$CURR_WP" && purge || : - printf "Please try again before reporting an issue.\n\n%s\n" "$(date)" + echo "Installing Pi-hole..." + curl -sSL https://install.pi-hole.net | sudo bash /dev/stdin --unattended fi - } - - ####################################### - # Commit the changes - # Globals: - # CORE_DIR - # HTML_DIR - # cleanup - # Arguments: - # None - # Outputs: - # The repositories cleaned up - # shellcheck disable=SC2317 ########### - commit() { - if $cleanup; then - for dir in $CORE_DIR $HTML_DIR/admin; do - [[ ! -d "$dir" ]] && continue || pushd "$dir" &>/dev/null || exit 1 - ! git remote -v | grep -q "old" || git remote remove old - git clean -ffdx - popd &>/dev/null - done - printf "Done!\n\n%s\n" "$(date)" - fi - } - - ####################################### - # Manage the installation - # Globals: - # CORE_DIR - # HTML_DIR - # MOD_DIR - # OPT_DIR - # CURR_WP - # CURR_DB - # LAST_DB - # ETC_DIR - # st_ver - # mod_core_ver - # mod_admin_ver - # cleanup - # Arguments: - # $@: The options for managing the installation - # Outputs: - # The installation managed - ####################################### - main() { - set -Eeuo pipefail - trap 'abort' INT TERM ERR - shopt -s dotglob - - local update=false - local backup=false - local online=false - local install=false - local reinstall=false - local stable=true - local uninstall=false - local database=false - local verbose=false - local chk_dep=true - local -i dashes=0 - local -r short_opts=-uboirtndvxch - local -r long_opts=update,backup,online,install,reinstall,testing,uninstall,database,version,verbose,continuous,help - local -r parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@") - declare -a POSITIONAL EXTRA_ARGS - eval set -- "${parsed_opts}" - local -ri num_args=$# - - while [[ $# -gt 0 ]]; do - case "$1" in - -u | --update) update=true ;; - -b | --backup) backup=true ;; - -o | --online) online=true ;; - -i | --install) install=true ;; - -r | --reinstall) reinstall=true ;; - -t | --testing) stable=false ;; - -n | --uninstall) uninstall=true ;; - -d | --database) database=true ;; - -v | --version) - getVersion $MOD_DIR - cleanup=false - exit 0 - ;; - -x | --verbose) verbose=true ;; - -c | --continuous) chk_dep=false ;; - -h | --help) - help - cleanup=false - exit 0 - ;; - --) dashes=1 ;; - *) [[ $dashes -eq 0 ]] && POSITIONAL+=("$1") || EXTRA_ARGS+=("$1") ;; - esac - shift - done - set -- "${POSITIONAL[@]}" - - for arg in "$@"; do - case $arg in - up) update=true ;; - un) uninstall=true ;; - db) database=true ;; - *) - help - cleanup=false - exit 0 - ;; - esac - done - - readonly update backup online install reinstall stable uninstall database verbose chk_dep cleanup - trap '[ "$?" -eq "0" ] && commit || abort' EXIT - printf "%s\n\nRunning the Mod Script by @ipitio...\n" "$(date)" - ! $verbose || set -x + pushd ~ >/dev/null || exit 1 + pihole updatechecker + pihole -v || : - if $database; then - if [[ -f $CURR_DB ]] && ! isEmpty $CURR_DB; then - echo "Flushing Database..." - mv -f $CURR_DB $LAST_DB - [[ ! -f $ETC_DIR/last_speedtest ]] || mv -f $ETC_DIR/last_speedtest $ETC_DIR/last_speedtest.old - - if [[ -f /var/log/pihole/speedtest.log ]]; then - mv -f /var/log/pihole/speedtest.log /var/log/pihole/speedtest.log.old - rm -f $ETC_DIR/speedtest.log - fi - elif [[ -f $LAST_DB ]]; then - echo "Restoring Database..." - mv -f $LAST_DB $CURR_DB - [[ ! -f $ETC_DIR/last_speedtest.old ]] || mv -f $ETC_DIR/last_speedtest.old $ETC_DIR/last_speedtest - - if [[ -f /var/log/pihole/speedtest.log.old ]]; then - mv -f /var/log/pihole/speedtest.log.old /var/log/pihole/speedtest.log - \cp -af /var/log/pihole/speedtest.log $ETC_DIR/speedtest.log - fi + if [[ -f $CURR_WP ]] && grep -q SpeedTest "$CURR_WP"; then + if $reinstall; then + for repo in $CORE_DIR $HTML_DIR/admin $MOD_DIR; do + if [[ -d "$repo" ]]; then + local hash_tag + hash_tag=$(getVersion "$repo") # if hashes are the same, we may be on an older tag + [[ "$(getVersion "$repo" hash)" != "$(getCnf $MOD_DIR/cnf mod-"$repo" hash)" ]] || hash_tag=$(getCnf $MOD_DIR/cnf mod-"$repo") + + case "$repo" in + "$CORE_DIR") mod_core_ver=$hash_tag ;; + "$HTML_DIR/admin") mod_admin_ver=$hash_tag ;; + "$MOD_DIR") st_ver=$hash_tag ;; + esac + fi + done fi - fi - if ! $database || [[ "$num_args" -gt 1 ]]; then - pushd ~ >/dev/null || exit 1 - pihole -v || : - - if [[ -f $CURR_WP ]] && grep -q SpeedTest "$CURR_WP"; then - if $reinstall; then - for repo in $CORE_DIR $HTML_DIR/admin $MOD_DIR; do - if [[ -d "$repo" ]]; then - local hash_tag - hash_tag=$(getVersion "$repo") # if hashes are the same, we may be on an older tag - [[ "$(getVersion "$repo" hash)" != "$(getCnf $MOD_DIR/cnf mod-"$repo" hash)" ]] || hash_tag=$(getCnf $MOD_DIR/cnf mod-"$repo") - - case "$repo" in - "$CORE_DIR") mod_core_ver=$hash_tag ;; - "$HTML_DIR/admin") mod_admin_ver=$hash_tag ;; - "$MOD_DIR") st_ver=$hash_tag ;; - esac - fi - done - fi + local core_ver="" + local admin_ver="" + echo "Restoring Pi-hole$($online && echo " Online..." || echo "...")" + pihole -a -s -1 - if ! $install; then - echo "Restoring Pi-hole$($online && echo " online..." || echo "...")" - pihole -a -s -1 - - local core_ver="" - local admin_ver="" + if [[ -f $MOD_DIR/cnf ]]; then + core_ver=$(getCnf $MOD_DIR/cnf org-$CORE_DIR) + admin_ver=$(getCnf $MOD_DIR/cnf org-$HTML_DIR/admin) + fi - if [[ -f $MOD_DIR/cnf ]]; then - core_ver=$(getCnf $MOD_DIR/cnf org-$CORE_DIR) - admin_ver=$(getCnf $MOD_DIR/cnf org-$HTML_DIR/admin) - fi + readonly core_ver admin_ver + ! $online && restore $HTML_DIR/admin || download $HTML_DIR admin https://github.com/pi-hole/AdminLTE "$admin_ver" + ! $online && restore $CORE_DIR || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" + [[ ! -d $MOD_DIR ]] || rm -rf $MOD_DIR + swapScripts - readonly core_ver admin_ver + for repo in $CORE_DIR $HTML_DIR/admin; do + pushd "$repo" &>/dev/null || exit 1 + git tag -l | xargs git tag -d >/dev/null 2>&1 + git fetch --tags -f -q + popd &>/dev/null + done + fi - ! $online && restore $HTML_DIR/admin || download $HTML_DIR admin https://github.com/pi-hole/AdminLTE "$admin_ver" - ! $online && restore $CORE_DIR || download /etc .pihole https://github.com/pi-hole/pi-hole "$core_ver" - [[ ! -d $MOD_DIR ]] || rm -rf $MOD_DIR - swapScripts + if $uninstall; then + echo "Purging Mod..." + purge + else + echo "Checking Dependencies..." + local -r php_version=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) + local -r pkgs=(bc nano sqlite3 jq tar tmux wget "php$php_version-sqlite3") + local missingpkgs=() + + for pkg in "${pkgs[@]}"; do + ! notInstalled "$pkg" || missingpkgs+=("$pkg") + done - if $update || $uninstall; then - for repo in $CORE_DIR $HTML_DIR/admin; do - pushd "$repo" &>/dev/null || exit 1 - git tag -l | xargs git tag -d >/dev/null 2>&1 - git fetch --tags -f -q - popd &>/dev/null - done - fi + readonly missingpkgs + if [[ ${#missingpkgs[@]} -gt 0 ]]; then + echo "Installing Missing Dependencies..." + if ! $PKG_MANAGER install -y "${missingpkgs[@]}" &>/dev/null; then + [[ "$PKG_MANAGER" == *"apt-get"* ]] || exit 1 + echo "And Updating Package Cache..." + $PKG_MANAGER update -y &>/dev/null + $PKG_MANAGER install -y "${missingpkgs[@]}" &>/dev/null fi fi - if ! $install && $update; then - if [[ -d /run/systemd/system ]]; then - echo "Updating Pi-hole..." - PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up - else - echo "Systemd not found. Skipping Pi-hole update..." + if ! $update; then + if ! $reinstall; then + local -r installed_core_ver=$(getVersion "Pi-hole") + local -r installed_admin_ver=$(getVersion "web") + if [[ "$installed_core_ver" == *.* && "$installed_admin_ver" == *.* ]]; then + echo "Finding Latest Compatible Versions..." + mod_core_ver=$(git ls-remote "https://github.com/arevindh/pi-hole" | grep -q "$installed_core_ver" && git ls-remote "https://github.com/arevindh/pi-hole" | grep "$installed_core_ver" | awk '{print $2;}' | cut -d '/' -f 3 | sort -Vr | head -n1 || echo "") + mod_admin_ver=$(git ls-remote "https://github.com/arevindh/AdminLTE" | grep -q "$installed_admin_ver" && git ls-remote "https://github.com/arevindh/AdminLTE" | grep "$installed_admin_ver" | awk '{print $2;}' | cut -d '/' -f 3 | sort -Vr | head -n1 || echo "") + fi fi + elif [[ -d /run/systemd/system ]]; then + echo "Updating Pi-hole..." + PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -up + else + echo "Systemd not found. Skipping Pi-hole Update..." fi - if ! $install && $uninstall; then - echo "Purging Mod..." - purge - else - if $chk_dep; then - if [[ ! -f /usr/local/bin/pihole ]]; then - echo "Installing Pi-hole..." - curl -sSL https://install.pi-hole.net | sudo bash - fi + if $backup; then + echo "Creating Backup..." + download /etc .pihole.mod https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable + download $HTML_DIR admin.mod https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable + fi - echo "Checking Dependencies..." - local -r php_version=$(php -v | head -n 1 | awk '{print $2}' | cut -d "." -f 1,2) - local -r pkg_manager=$(command -v apt-get || command -v dnf || command -v yum) - local -r pkgs=(bc nano sqlite3 jq tar tmux wget "php$php_version-sqlite3") - local missingpkgs=() - - for pkg in "${pkgs[@]}"; do - ! notInstalled "$pkg" || missingpkgs+=("$pkg") - done - - readonly missingpkgs - if [[ ${#missingpkgs[@]} -gt 0 ]]; then - echo "Installing Missing Dependencies..." - if ! $pkg_manager install -y "${missingpkgs[@]}" &>/dev/null; then - [[ "$pkg_manager" == *"apt-get"* ]] || exit 1 - echo "And Updating Package Cache..." - $pkg_manager update -y &>/dev/null - $pkg_manager install -y "${missingpkgs[@]}" &>/dev/null + $reinstall && echo "Reinstalling Mod..." || echo "Installing Mod..." + download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable + [[ -f $MOD_DIR/cnf ]] || touch $MOD_DIR/cnf + setCnf mod-$MOD_DIR "$(getVersion $MOD_DIR)" $MOD_DIR/cnf $reinstall + local stock_tag + + for repo in $CORE_DIR $HTML_DIR/admin; do + if [[ -d "$repo" ]]; then + stock_tag=$(getVersion "$repo") + setCnf org-"$repo" "$stock_tag" $MOD_DIR/cnf + + if $backup; then + if [[ ! -d "$repo".bak || "$(getVersion "$repo".bak)" != "$stock_tag" ]]; then + rm -rf "$repo".bak + mv -f "$repo" "$repo".bak fi - fi - fi - - if $backup; then - echo "Backing up Pi-hole..." - download /etc .pihole.mod https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable - download $HTML_DIR admin.mod https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable - fi - - $reinstall && echo "Reinstalling Mod..." || echo "Installing Mod..." - download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable - [[ -f $MOD_DIR/cnf ]] || touch $MOD_DIR/cnf - setCnf mod-$MOD_DIR "$(getVersion $MOD_DIR)" $MOD_DIR/cnf $reinstall - local stock_tag - for repo in $CORE_DIR $HTML_DIR/admin; do - if [[ -d "$repo" ]]; then - stock_tag=$(getVersion "$repo") - setCnf org-"$repo" "$stock_tag" $MOD_DIR/cnf - - if $backup; then - if [[ ! -d "$repo".bak || "$(getVersion "$repo".bak)" != "$stock_tag" ]]; then - rm -rf "$repo".bak - mv -f "$repo" "$repo".bak - fi - - rm -rf "$repo" - mv -f "$repo".mod "$repo" - fi + rm -rf "$repo" + mv -f "$repo".mod "$repo" fi - done - - $backup || download /etc .pihole https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable - swapScripts - \cp -af $CORE_DIR/advanced/Scripts/speedtestmod/. $OPT_DIR/speedtestmod/ - pihole -a -s - $backup || download $HTML_DIR admin https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable - setCnf mod-$CORE_DIR "$(getVersion $CORE_DIR)" $MOD_DIR/cnf $reinstall - setCnf mod-$HTML_DIR/admin "$(getVersion $HTML_DIR/admin)" $MOD_DIR/cnf $reinstall - fi + fi + done - pihole updatechecker - pihole -v || : - popd >/dev/null + $backup || download /etc .pihole https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable + swapScripts + \cp -af $CORE_DIR/advanced/Scripts/speedtestmod/. $OPT_DIR/speedtestmod/ + pihole -a -s + $backup || download $HTML_DIR admin https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable + setCnf mod-$CORE_DIR "$(getVersion $CORE_DIR)" $MOD_DIR/cnf $reinstall + setCnf mod-$HTML_DIR/admin "$(getVersion $HTML_DIR/admin)" $MOD_DIR/cnf $reinstall fi - exit 0 - } - - if [[ $EUID != 0 ]]; then - sudo "$0" "$@" - exit $? + pihole updatechecker + pihole -v || : + popd >/dev/null fi - rm -f /tmp/pimod.log - touch /tmp/pimod.log - main "$@" 2>&1 | tee -a /tmp/pimod.log - $cleanup && mv -f /tmp/pimod.log /var/log/pihole/mod.log || rm -f /tmp/pimod.log - exit $aborted + exit 0 +} + +if [[ $EUID != 0 ]]; then + sudo "$0" "$@" + exit $? fi + +rm -f /tmp/pimod.log +touch /tmp/pimod.log +main "$@" 2>&1 | tee -a /tmp/pimod.log +$cleanup && mv -f /tmp/pimod.log /var/log/pihole/mod.log || rm -f /tmp/pimod.log +exit $aborted diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index 77eb06db13..f766e77bc8 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -6,6 +6,9 @@ # shellcheck disable=SC2015 # +# shellcheck disable=SC1091 +source /opt/pihole/speedtestmod/lib.sh + declare -r OUT_FILE=/tmp/speedtest.log declare -r CREATE_TABLE="create table if not exists speedtest ( id integer primary key autoincrement, @@ -21,222 +24,51 @@ upload real, share_url text );" declare START -declare PKG_MANAGER declare SERVER_ID START=$(date -u --rfc-3339='seconds') -PKG_MANAGER=$(command -v apt-get || command -v dnf || command -v yum) SERVER_ID=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) -readonly START PKG_MANAGER SERVER_ID - -# shellcheck disable=SC2034 -SKIP_MOD=true -# shellcheck disable=SC1091 -source /opt/pihole/speedtestmod/mod.sh - -####################################### -# Run the speedtest -# Globals: -# SERVER_ID -# Arguments: -# None -# Returns: -# None -####################################### -speedtest() { - if grep -q official <<<"$(/usr/bin/speedtest --version)"; then - [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest -s "$SERVER_ID" --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json - else - [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest --server "$SERVER_ID" --json --share --secure || /usr/bin/speedtest --json --share --secure - fi -} - -####################################### -# Save the results of the speedtest to the database -# Globals: -# OUT_FILE -# CREATE_TABLE -# Arguments: -# $1: Start time -# $2: Stop time -# $3: ISP -# $4: From IP -# $5: Server -# $6: Server Distance -# $7: Server Ping -# $8: Download -# $9: Upload -# $10: Share URL -# Returns: -# None -####################################### -savetest() { - local -r start_time=$1 - local -r stop_time=$2 - local -r isp=${3:-"No Internet"} - local -r from_ip=${4:-"-"} - local -r server=${5:-"-"} - local -r server_dist=${6:-0} - local -r server_ping=${7:-0} - local -r download=${8:-0} - local -r upload=${9:-0} - local -r share_url=${10:-"#"} - local -r rm_empty=' - def nonempty: . and length > 0 and (type != "object" or . != {}) and (type != "array" or any(.[]; . != "")); - if type == "array" then map(walk(if type == "object" then with_entries(select(.value | nonempty)) else . end)) else walk(if type == "object" then with_entries(select(.value | nonempty)) else . end) end -' - local -r temp_file=$(mktemp) - local -r json_file="/tmp/speedtest_results" - jq "$rm_empty" "$json_file" >"$temp_file" && mv -f "$temp_file" "$json_file" - rm -f "$temp_file" - chmod 644 /tmp/speedtest_results - mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log - \cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log - rm -f "$OUT_FILE" - sqlite3 /etc/pihole/speedtest.db "$CREATE_TABLE" - sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${start_time}', '${stop_time}', '${isp}', '${from_ip}', '${server}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" - [[ "$isp" == "No Internet" ]] && exit 1 || exit 0 -} +readonly START SERVER_ID +declare -i run_status=0 ####################################### -# Check if the package is available -# Globals: -# PKG_MANAGER -# Arguments: -# $1: Package name -# Returns: -# 0 if available, 1 if not -####################################### -isAvailable() { - if [[ "$PKG_MANAGER" == "/usr/bin/apt-get" ]]; then - # Check if there is a candidate and it is not "(none)" - apt-cache policy "$1" | grep -q "Candidate:" && ! apt-cache policy "$1" | grep -q "Candidate: (none)" && return 0 || return 1 - elif [[ "$PKG_MANAGER" == "/usr/bin/dnf" || "$PKG_MANAGER" == "/usr/bin/yum" ]]; then - $PKG_MANAGER list available "$1" &>/dev/null && return 0 || return 1 - else - echo "Unsupported package manager!" - exit 1 - fi -} - -####################################### -# Change between two conflicting packages +# Display the help message # Globals: -# PKG_MANAGER -# Arguments: -# $1: Package to install -# $2: Package to remove -# Returns: # None -####################################### -swaptest() { - if isAvailable "$1"; then - [[ "$PKG_MANAGER" == "/usr/bin/apt-get" ]] && apt-get install -y "$1" "$2"- || { [[ "$PKG_MANAGER" == "/usr/bin/dnf" ]] && dnf install -y --allowerasing "$1" || yum install -y --allowerasing "$1"; } - fi -} - -####################################### -# Check if a package is installed -# Globals: -# PKG_MANAGER -# OUT_FILE -# Arguments: -# $1: The package to check -# Returns: -# 0 if the package is not installed, 1 if it is -####################################### -notInstalled() { - if [[ "$PKG_MANAGER" == "/usr/bin/apt-get" ]]; then - dpkg -s "$1" &>/dev/null || return 0 - elif [[ "$PKG_MANAGER" == "/usr/bin/dnf" || "$PKG_MANAGER" == "/usr/bin/yum" ]]; then - rpm -q "$1" &>/dev/null || return 0 - else - echo "Unsupported package manager!" - mv -f "$OUT_FILE" /var/log/pihole/speedtest.log - exit 1 - fi - - return 1 -} - -####################################### -# Download and install librespeed -# Globals: -# PKG_MANAGER # Arguments: # None -# Returns: -# None +# Outputs: +# The help message ####################################### -librespeed() { - if notInstalled golang; then - if grep -q "Raspbian" /etc/os-release; then - if [[ ! -f /etc/apt/sources.list.d/testing.list ]] && ! grep -q "testing" /etc/apt/sources.list; then - echo "Adding testing repo to sources.list.d" - echo "deb http://archive.raspbian.org/raspbian/ testing main" >/etc/apt/sources.list.d/testing.list - printf "Package: *\nPin: release a=testing\nPin-Priority: 50" >/etc/apt/preferences.d/limit-testing - $PKG_MANAGER update - fi - - $PKG_MANAGER install -y -t testing golang - else - $PKG_MANAGER install -y golang - fi - fi - download /etc/pihole librespeed https://github.com/librespeed/speedtest-cli - cd librespeed || exit - [[ ! -d out ]] || rm -rf out - ./build.sh - mv -f out/* /usr/bin/speedtest - chmod +x /usr/bin/speedtest +help() { + local -r help_text=( + "Usage: $0 [options]" + "" + "Run the speedtest" + "" + "Options:" + " -a, --attempts= Number of attempts (default: 3)" + " -x, --verbose Show the commands being run" + " -h, --help Display this help message" + ) + + printf "%s\n" "${help_text[@]}" + exit 1 } ####################################### -# Add the Ookla speedtest CLI source +# Run the speedtest # Globals: -# PKG_MANAGER +# SERVER_ID # Arguments: # None -# Returns: -# None +# Outputs: +# The speedtest results ####################################### -addSource() { - if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* ]]; then - if [[ ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]]; then - echo "Adding speedtest source for RPM..." - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash - fi - - yum list speedtest | grep -q "Available Packages" && $PKG_MANAGER install -y speedtest || : - elif [[ "$PKG_MANAGER" == *"apt-get"* ]]; then - if [[ ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]]; then - echo "Adding speedtest source for DEB..." - if [[ -e /etc/os-release ]]; then - # shellcheck disable=SC1091 - source /etc/os-release - local -r base="ubuntu debian" - local os=${ID} - local dist=${VERSION_CODENAME} - # shellcheck disable=SC2076 - if [[ -n "${ID_LIKE:-}" && "${base//\"/}" =~ "${ID_LIKE//\"/}" && "${os}" != "ubuntu" ]]; then - os=${ID_LIKE%% *} - [[ -z "${UBUNTU_CODENAME:-}" ]] && UBUNTU_CODENAME=$(/usr/bin/lsb_release -cs) - dist=${UBUNTU_CODENAME} - [[ -z "$dist" ]] && dist=${VERSION_CODENAME} - fi - wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 - chmod +x /tmp/script.deb.sh - os=$os dist=$dist /tmp/script.deb.sh - rm -f /tmp/script.deb.sh - else - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash - fi - - sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list - apt-get update - fi +speedtest() { + if /usr/bin/speedtest --version | grep -q "official"; then + [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest -s "$SERVER_ID" --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json else - echo "Unsupported package manager!" - exit 1 + [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest --server "$SERVER_ID" --json --share --secure || /usr/bin/speedtest --json --share --secure fi } @@ -249,103 +81,124 @@ addSource() { # $1: Number of attempts (optional, 3 by default) # $2: Current attempt (optional, 0 by default) # Returns: -# None +# 1 if the speedtest failed, 0 if successful ####################################### run() { - speedtest | jq . >/tmp/speedtest_results || echo "Attempt ${2:-1} Failed!" >/tmp/speedtest_results - local -r stop=$(date -u --rfc-3339='seconds') - if jq -e '.server' /tmp/speedtest_results &>/dev/null; then - local -r res=$(/dev/null; then # librespeed - local -r res=$(/tmp/speedtest_results - savetest "$START" "$stop" - else + local isp="No Internet" + local from_ip="-" + local server_name="-" + local server_dist=0 + local server_ping=0 + local download=0 + local upload=0 + local share_url="#" + local res + local stop + + if [[ "${2:-0}" -gt 0 || ! -f /usr/bin/speedtest ]]; then if notInstalled speedtest && notInstalled speedtest-cli; then [[ ! -f /usr/bin/speedtest ]] || rm -f /usr/bin/speedtest - addSource - isAvailable speedtest && $PKG_MANAGER install -y speedtest || : - elif ! notInstalled speedtest; then - swaptest speedtest-cli speedtest + ! ooklaSpeed && ! swivelSpeed && libreSpeed || : + elif ! notInstalled speedtest && isAvailable speedtest-cli; then + ! swivelSpeed && ! libreSpeed && ooklaSpeed || : else - $PKG_MANAGER remove -y speedtest-cli - librespeed + ! libreSpeed && ! ooklaSpeed && swivelSpeed || : fi + fi - run $1 $((${2:-0} + 1)) + if [[ "${1}" -gt "${2:-0}" ]]; then + [[ -n "${2:-}" ]] || echo "Running Test..." + speedtest | jq . >/tmp/speedtest_results || echo "Attempt ${2:-0} Failed!" + stop=$(date -u --rfc-3339='seconds') + + if [[ -s /tmp/speedtest_results ]]; then + res=$(/dev/null; then + local server_id + local servers + server_id=$(jq -r '.server.id' <<<"$res") + servers="$(curl 'https://www.speedtest.net/api/js/servers' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'DNT: 1' -H 'Sec-GPC: 1')" + server_dist=$(jq --arg id "$server_id" '.[] | select(.id == $id) | .distance' <<<"$servers") + + if /usr/bin/speedtest --version | grep -q "official"; then # ookla + server_name=$(jq -r '.server.name' <<<"$res") + download=$(jq -r '.download.bandwidth' <<<"$res" | awk '{$1=$1*8/1000/1000; print $1;}' | sed 's/,/./g') + upload=$(jq -r '.upload.bandwidth' <<<"$res" | awk '{$1=$1*8/1000/1000; print $1;}' | sed 's/,/./g') + isp=$(jq -r '.isp' <<<"$res") + from_ip=$(jq -r '.interface.externalIp' <<<"$res") + server_ping=$(jq -r '.ping.latency' <<<"$res") + share_url=$(jq -r '.result.url' <<<"$res") + [[ -n "$server_dist" ]] || server_dist="-1" + else # speedtest-cli + server_name=$(jq -r '.server.sponsor' <<<"$res") + download=$(jq -r '.download' <<<"$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') + upload=$(jq -r '.upload' <<<"$res" | awk '{$1=$1/1000/1000; print $1;}' | sed 's/,/./g') + isp=$(jq -r '.client.isp' <<<"$res") + from_ip=$(jq -r '.client.ip' <<<"$res") + server_ping=$(jq -r '.ping' <<<"$res") + share_url=$(jq -r '.share' <<<"$res") + [[ -n "$server_dist" ]] || server_dist=$(jq -r '.server.d' <<<"$res") + fi + else # if jq -e '.[].server' /tmp/speedtest_results &>/dev/null; then # librespeed + server_name=$(jq -r '.[].server.name' <<<"$res") + download=$(jq -r '.[].download' <<<"$res") + upload=$(jq -r '.[].upload' <<<"$res") + isp="Unknown" + from_ip=$(curl -sSL https://ipv4.icanhazip.com) + server_ping=$(jq -r '.[].ping' <<<"$res") + share_url=$(jq -r '.[].share' <<<"$res") + server_dist="-1" + fi + else + run $1 $((${2:-0} + 1)) + fi + else + echo "Limit Reached!" fi -} -####################################### -# Display the help message -# Globals: -# None -# Arguments: -# None -# Returns: -# None -####################################### -help() { - echo "Usage: $0 [attempts]" - echo " attempts: Number of attempts to run the speedtest, cycling through the packages (default: 3)" - exit 1 + local -r rm_empty=" + def walk(f): . as \$in | if type == \"object\" then reduce keys_unsorted[] as \$key ({}; . + { (\$key): (\$in[\$key] | walk(f)) }) | f else if type == \"array\" then map( walk(f) ) | f else f end; + def nonempty: . and length > 0 and (type != \"object\" or . != {}) and (type != \"array\" or any(.[]; . != \"\")); + if type == \"array\" then map(walk(if type == \"object\" then with_entries(select(.value | nonempty)) else . end)) else walk(if type == \"object\" then with_entries(select(.value | nonempty)) else . end) end +" + local -r temp_file=$(mktemp) + local -r json_file="/tmp/speedtest_results" + jq "$rm_empty" "$json_file" >"$temp_file" && mv -f "$temp_file" "$json_file" + rm -f "$temp_file" + chmod 644 /tmp/speedtest_results + mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log + \cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log + sqlite3 /etc/pihole/speedtest.db "$CREATE_TABLE" + sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${START}', '${stop}', '${isp}', '${from_ip}', '${server_name}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" + [[ "$isp" == "No Internet" ]] && return 1 || return 0 } ####################################### -# Main function +# Start the runner # Globals: # PKG_MANAGER # Arguments: # None -# Returns: -# None +# Outputs: +# The speedtest status ####################################### main() { - local -r short_opts=-h - local -r long_opts=help + local -r short_opts=-a:xh + local -r long_opts=attempts:,verbose,help local -r parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@") local POSITIONAL=() local attempts="3" + local verbose=false eval set -- "${parsed_opts}" while [[ $# -gt 0 ]]; do case "$1" in + -a | --attempts) + attempts="$2" + shift + ;; + -x | --verbose) verbose=true ;; -h | --help) help ;; *) POSITIONAL+=("$1") ;; esac @@ -353,23 +206,19 @@ main() { done set -- "${POSITIONAL[@]}" - - if [[ "$1" != "--" ]]; then - [[ "$1" =~ ^[0-9]+$ ]] && attempts="$1" || help - fi - - if [[ $EUID != 0 ]]; then - sudo "$0" "$@" - exit $? - fi - - if [[ ! -f /usr/bin/speedtest ]]; then - addSource - isAvailable speedtest && $PKG_MANAGER install -y speedtest || { isAvailable speedtest-cli && $PKG_MANAGER install -y speedtest-cli || librespeed; } - fi - - echo "Running Test..." + [[ "$attempts" =~ ^[0-9]+$ ]] || attempts="3" + ! $verbose || set -x run $attempts + run_status=$? } -main "$@" >"$OUT_FILE" +if [[ $EUID != 0 ]]; then + sudo "$0" "$@" + exit $? +fi + +rm -f "$OUT_FILE" +touch "$OUT_FILE" +main "$@" 2>&1 | tee -a "$OUT_FILE" +mv -f "$OUT_FILE" /var/log/pihole/speedtest-run.log || rm -f "$OUT_FILE" +exit $run_status diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index e72ea061f9..e71d73339b 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -51,6 +51,7 @@ function get_remote_hash(){ local foundHash="" for repo in "arevindh" "pi-hole" "ipitio"; do + [[ "${repo}" != "pi-hole" || "${1}" != "pihole-speedtest" ]] || continue foundHash=$(git ls-remote "https://github.com/${repo}/${1}" --tags "${2}" | awk '{print $1;}' 2> /dev/null) [[ -z "${foundHash}" ]] || break done diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index da508ba0b8..313932f584 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -545,132 +545,9 @@ SetWebUILayout() { addOrEditKeyValPair "${setupVars}" "WEBUIBOXEDLAYOUT" "${args[2]}" } -generate_systemd_calendar() { - local interval_hours="$1" - local total_seconds - total_seconds=$(echo "$interval_hours * 3600" | bc) - local freq_entries=() - - if (($(echo "$total_seconds < 60" | bc -l))); then # less than a minute - total_seconds=60 - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "0.017" - fi - if (($(echo "$total_seconds >= 60 && $total_seconds < 3600" | bc -l))); then # less than an hour - local minute_interval - minute_interval=$(echo "$total_seconds / 60" | bc) - freq_entries+=("*-*-* *:00/$minute_interval:00") - elif (($(echo "$total_seconds == 3600" | bc -l))); then # exactly an hour - freq_entries+=("*-*-* *:00:00") - elif (($(echo "$total_seconds < 86400" | bc -l))); then # less than a day - if (($(awk "BEGIN {print ($total_seconds / 3600) % 1}") == 0)); then # divides evenly into an hour - local hour_interval - hour_interval=$(echo "$total_seconds / 3600" | bc) - freq_entries+=("*-*-* 00/$hour_interval:00:00") - else # does not divide evenly into an hour - local current_second=0 - while (($(echo "$current_second < 86400" | bc -l))); do - local hour - hour=$(echo "$current_second / 3600" | bc) - local minute - minute=$(awk "BEGIN {print ($current_second % 3600) / 60}") - hour=${hour%.*} - minute=${minute%.*} - freq_entries+=("*-*-* $(printf "%02d:%02d:00" "$hour" "$minute")") - current_second=$(echo "$current_second + $total_seconds" | bc) - done - fi - else # more than a day - local full_days - full_days=$(echo "$interval_hours / 24" | bc) - local remaining_hours - remaining_hours=$(echo "$interval_hours - ($full_days * 24)" | bc) - if (($(echo "$full_days > 0" | bc -l))); then - freq_entries+=("*-*-1/$(printf "%02.0f" "$full_days")") - fi - if (($(echo "$remaining_hours > 0" | bc -l))); then # partial day - local remaining_minutes - remaining_minutes=$(echo "($remaining_hours - ($remaining_hours / 1)) * 60" | bc) - remaining_hours=${remaining_hours%.*} - remaining_minutes=${remaining_minutes%.*} - freq_entries+=("*-*-* $(printf "%02d:%02d:00" "$remaining_hours" "$remaining_minutes")") - fi - fi - - local IFS=$'\n' - echo "${freq_entries[*]}" -} - -generate_cron_schedule() { - local total_seconds="nan" - local schedule_script="/opt/pihole/speedtestmod/schedule_check.sh" - - if [[ "$1" != "nan" ]] && [[ "$1" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]] && (($(echo "$1 > 0" | bc -l))); then - total_seconds=$(echo "$1 * 3600" | bc) - if (($(echo "$total_seconds < 60" | bc -l))); then - total_seconds=60 - fi - - local remainder - remainder=$(awk "BEGIN {print $total_seconds % 60}") - if (($(echo "$remainder < 30" | bc -l))); then - total_seconds=$(echo "$total_seconds - $remainder" | bc -l) - else - total_seconds=$(echo "$total_seconds + (60 - $remainder)" | bc -l) - fi - addOrEditKeyValPair "${setupVars}" "SPEEDTESTSCHEDULE" "$(echo "scale=3; $total_seconds / 3600" | bc)" - fi - - [ -d /opt/pihole/speedtestmod ] || return - sudo bash -c "cat > $(printf %q "$schedule_script")" < 0" | bc -l) )) || exit 0 - -if [[ -f "\$LAST_RUN_FILE" ]]; then - declare last_run - last_run=\$(<"\$LAST_RUN_FILE") - current_time=\$(date +%s) - (( \$(echo "\$current_time - \$last_run >= \$INTERVAL_SECONDS" | bc -l) )) || exit 0 -fi - -[[ \$(/usr/bin/tmux list-sessions 2>/dev/null | grep -c pimodtest) -eq 0 ]] || exit 0 -echo "\$current_time" > "\$LAST_RUN_FILE" -/usr/bin/tmux new-session -d -s pimodtest "sudo bash $speedtestfile" -EOF - sudo chmod +x "$schedule_script" - - crontab -l 2>/dev/null | grep -v "$schedule_script" | crontab - - if [[ "$total_seconds" == "nan" ]] || (($(echo "$total_seconds > 0" | bc -l))); then - crontab -l &>/dev/null || crontab -l 2>/dev/null | { - cat - echo "" - } | crontab - - ( - crontab -l - echo "* * * * * /bin/bash $schedule_script" - ) | crontab - - fi -} - ChangeSpeedTestSchedule() { local interval="${args[2]%\.}" + if [[ "${interval-}" =~ ^-?([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then if (($(echo "$interval < 0" | bc -l))); then interval="0" @@ -679,74 +556,39 @@ ChangeSpeedTestSchedule() { fi else interval=$(grep "SPEEDTESTSCHEDULE" "${setupVars}" | cut -f2 -d"=") + if [[ ! "${interval-}" =~ ^([0-9]+(\.[0-9]*)?|\.[0-9]+)$ ]]; then interval="nan" fi fi if [[ ! -d /run/systemd/system ]]; then - generate_cron_schedule "$interval" + # shellcheck disable=SC1091 + source "/opt/pihole/speedtestmod/lib.sh" + generate_cron_job "$interval" elif [[ "$interval" == "0" ]] || [[ "$interval" == "nan" ]]; then systemctl disable --now pihole-speedtest.timer &>/dev/null else - local freq - freq=$(generate_systemd_calendar "$interval") - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.service << EOF -[Unit] -Description=Pi-hole Speedtest -After=network.target - -[Service] -User=root -Type=oneshot -ExecStart=/opt/pihole/speedtestmod/speedtest.sh - -[Install] -WantedBy=multi-user.target -EOF' - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF -[Unit] -Description=Pi-hole Speedtest Timer - -[Install] -WantedBy=timers.target - -[Timer] -Persistent=true -EOF' - while IFS= read -r line; do - sudo bash -c "echo 'OnCalendar=$line' >> /etc/systemd/system/pihole-speedtest.timer" - done <<<"$freq" - - systemctl daemon-reload - systemctl reenable pihole-speedtest.timer &>/dev/null - systemctl restart pihole-speedtest.timer + # shellcheck disable=SC1091 + source "/opt/pihole/speedtestmod/lib.sh" + generate_systemd_service "$interval" fi } UpdateSpeedTestRange() { - if [[ "${args[2]}" =~ ^-?[0-9]+$ ]]; then - if [[ "${args[2]}" -ge -1 ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" - fi - fi + [[ ! "${args[2]}" =~ ^-?[0-9]+$ || "${args[2]}" -lt -1 ]] || addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_DAYS" "${args[2]}" } UpdateSpeedTestChartType() { - if [[ "${args[2]}" =~ ^(bar|line)$ ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "${args[2]}" - else - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "line" - fi + local chart_type="line" + [[ ! "${args[2]}" =~ ^(bar|line)$ ]] || chart_type="${args[2]}" + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_CHART_TYPE" "$chart_type" } SpeedtestServer() { - if [[ "${args[2]}" =~ ^[0-9]+$ ]]; then - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "${args[2]}" - else - # Autoselect for invalid data - addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "" - fi + local test_server="" + [[ ! "${args[2]}" =~ ^[0-9]+$ ]] || test_server="${args[2]}" + addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "$test_server" } RunSpeedtestNow() { From 9ed2515898a55b896f30697d649369d4d48eb6a0 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Thu, 2 May 2024 07:51:53 +0000 Subject: [PATCH 638/638] v2.9 (#117) * v2.9 --- advanced/Scripts/speedtestmod/lib.sh | 30 +++-- advanced/Scripts/speedtestmod/mod.sh | 137 ++++++++++++--------- advanced/Scripts/speedtestmod/speedtest.sh | 74 +++++++---- advanced/Scripts/webpage.sh | 53 ++++---- 4 files changed, 175 insertions(+), 119 deletions(-) diff --git a/advanced/Scripts/speedtestmod/lib.sh b/advanced/Scripts/speedtestmod/lib.sh index a5d1d04086..b0c7d42f67 100755 --- a/advanced/Scripts/speedtestmod/lib.sh +++ b/advanced/Scripts/speedtestmod/lib.sh @@ -135,7 +135,7 @@ download() { # 0 if available, 1 if not ####################################### isAvailable() { - if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + if [[ "$PKG_MANAGER" == *"apt"* ]]; then # Check if there is a candidate and it is not "(none)" apt-cache policy "$1" | grep -q "Candidate:" && ! apt-cache policy "$1" | grep -q "Candidate: (none)" && return 0 || return 1 elif [[ "$PKG_MANAGER" == *"dnf"* || "$PKG_MANAGER" == *"yum"* ]]; then @@ -156,7 +156,7 @@ isAvailable() { # 0 if the package is not installed, 1 if it is ####################################### notInstalled() { - if [[ "$PKG_MANAGER" == *"apt-get"* ]]; then + if [[ "$PKG_MANAGER" == *"apt"* ]]; then dpkg -s "$1" &>/dev/null || return 0 elif [[ "$PKG_MANAGER" == *"dnf"* || "$PKG_MANAGER" == *"yum"* ]]; then rpm -q "$1" &>/dev/null || return 0 @@ -215,7 +215,7 @@ getCnf() { # 0 if the installation was successful, 1 if it was not ####################################### libreSpeed() { - echo "Installing LibreSpeed..." + echo "Installing librespeed-cli..." $PKG_MANAGER remove -y speedtest-cli speedtest >/dev/null 2>&1 if notInstalled golang; then @@ -224,12 +224,14 @@ libreSpeed() { echo "Adding testing repo to sources.list.d" echo "deb http://archive.raspbian.org/raspbian/ testing main" >/etc/apt/sources.list.d/testing.list printf "Package: *\nPin: release a=testing\nPin-Priority: 50" >/etc/apt/preferences.d/limit-testing - $PKG_MANAGER update -y + $PKG_MANAGER update -y &>/dev/null fi - $PKG_MANAGER install -y -t testing golang + isAvailable golang || $PKG_MANAGER update -y &>/dev/null + $PKG_MANAGER install -y -t testing golang >/dev/null 2>&1 else - $PKG_MANAGER install -y golang + [[ $PKG_MANAGER == *"apt"* ]] && ! isAvailable golang && $PKG_MANAGER update -y &>/dev/null || : + $PKG_MANAGER install -y golang >/dev/null 2>&1 fi fi @@ -243,7 +245,7 @@ libreSpeed() { chmod +x /usr/bin/speedtest if [[ -x /usr/bin/speedtest ]]; then - echo "Installed LibreSpeed." + echo "Installed librespeed-cli" return 0 fi @@ -275,9 +277,11 @@ swivelSpeed() { /usr/bin/yum) "$PKG_MANAGER" install -y --allowerasing "$candidate" &>/dev/null ;; esac - if ! notInstalled "$candidate"; then + if ! notInstalled "$candidate" && [[ -x /usr/bin/speedtest ]]; then printf "Installed " - /usr/bin/speedtest --version || return 1 + local version= + version=$(/usr/bin/speedtest --version) || return 1 + echo "${version%%$'\n'*}" return 0 fi @@ -298,7 +302,7 @@ ooklaSpeed() { if [[ "$PKG_MANAGER" == *"yum"* || "$PKG_MANAGER" == *"dnf"* && ! -f /etc/yum.repos.d/ookla_speedtest-cli.repo ]]; then echo "Adding speedtest source for RPM..." curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.rpm.sh | sudo bash - elif [[ "$PKG_MANAGER" == *"apt-get"* && ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]]; then + elif [[ "$PKG_MANAGER" == *"apt"* && ! -f /etc/apt/sources.list.d/ookla_speedtest-cli.list ]]; then echo "Adding speedtest source for DEB..." if [[ -e /etc/os-release ]]; then # shellcheck disable=SC1091 @@ -315,10 +319,10 @@ ooklaSpeed() { fi wget -O /tmp/script.deb.sh https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh >/dev/null 2>&1 chmod +x /tmp/script.deb.sh - os=$os dist=$dist /tmp/script.deb.sh + os=$os dist=$dist /tmp/script.deb.sh >/dev/null 2>&1 rm -f /tmp/script.deb.sh else - curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash + curl -sSLN https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash >/dev/null 2>&1 fi sed -i 's/g]/g allow-insecure=yes trusted=yes]/' /etc/apt/sources.list.d/ookla_speedtest-cli.list @@ -405,7 +409,7 @@ ExecStart=/usr/local/bin/pihole -a -sn [Install] WantedBy=multi-user.target EOF' - sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF + sudo bash -c 'cat > /etc/systemd/system/pihole-speedtest.timer << EOF [Unit] Description=Pi-hole Speedtest Timer diff --git a/advanced/Scripts/speedtestmod/mod.sh b/advanced/Scripts/speedtestmod/mod.sh index d8b9302f58..e2e5e57d0a 100755 --- a/advanced/Scripts/speedtestmod/mod.sh +++ b/advanced/Scripts/speedtestmod/mod.sh @@ -6,6 +6,10 @@ # shellcheck disable=SC2015 # +declare -r MOD_REPO="arevindh" +declare -r MOD_BRANCH="master" +declare -r CORE_BRANCH="master" +declare -r ADMIN_BRANCH="master" declare -r HTML_DIR="/var/www/html" declare -r CORE_DIR="/etc/.pihole" declare -r OPT_DIR="/opt/pihole" @@ -15,17 +19,18 @@ declare -r CURR_WP="$OPT_DIR/webpage.sh" declare -r CURR_DB="$ETC_DIR/speedtest.db" declare -r LAST_DB="$CURR_DB.old" declare -r DB_TABLE="speedtest" -declare -i aborted=0 -st_ver="" -mod_core_ver="" -mod_admin_ver="" -cleanup=true +declare cleanup +declare aborted +cleanup=$(mktemp) +aborted=$(mktemp) +echo "false" >"$cleanup" +echo "false" >"$aborted" # shellcheck disable=SC2034 SKIP_INSTALL=true # shellcheck disable=SC1091 source "$CORE_DIR/automated install/basic-install.sh" # shellcheck disable=SC1090,SC1091 -[[ -f "$OPT_DIR/speedtestmod/lib.sh" ]] && source "$OPT_DIR/speedtestmod/lib.sh" || source <(curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/lib.sh) +[[ -f "$OPT_DIR/speedtestmod/lib.sh" ]] && source "$OPT_DIR/speedtestmod/lib.sh" || source <(curl -sSLN https://github.com/"$MOD_REPO"/pi-hole/raw/"$CORE_BRANCH"/advanced/Scripts/speedtestmod/lib.sh) ####################################### # Display the help message @@ -41,35 +46,34 @@ help() { "The Mod Script" "Usage: sudo bash /path/to/mod.sh [options]" " or: curl -sSLN //link/to/mod.sh | sudo bash [-s -- options]" - "(Re)install the latest release of the Speedtest Mod and/or the following options:" + " or: pihole -a -sm [options]" + "(Re)install Speedtest Mod and/or the following options:" "" "Installation:" " -u, --update, up also update Pi-hole" - " -r, --reinstall keep current version of the mod, if installed" - " -t, --testing install the beta version of the mod" + " -r, --reinstall repair currently installed version of the Mod" + " -t, --testing try unstable changes" "" "Restoration:" - " -n, --uninstall, un purge the mod, keeping the speedtest package, logs, and database" + " -n, --uninstall, un purge the Mod, keeping the speedtest package, logs, and database" " -b, --backup backup Pi-hole for faster offline restore" " -o, --online force online restore of Pi-hole" "" "Standalone:" " -d, --database, db flush/restore the database if it's not/empty" - " -s, --speedtest[=] install Ookla's or the specified CLI even if another is already installed" + " -s, --speedtest[=] install Ookla's or the specified CLI immediately" " -x, --verbose show the commands being run" - " -v, --version display the version of the mod and exit" + " -v, --version display the installed version of the Mod and exit" " -h, --help display this help message and exit" "" "Examples:" - " sudo bash /opt/pihole/speedtestmod/mod.sh -d -slibre" - " sudo bash /opt/pihole/speedtestmod/mod.sh --uninstall" - " curl -sSL https://github.com/arevindh/pihole-speedtest/raw/master/mod | sudo bash" - " curl -sSLN https://github.com/arevindh/pi-hole/raw/master/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -bo" + " pihole -a -sm -d -slibre" + " sudo bash /opt/pihole/speedtestmod/mod.sh --update" + " curl -sSL https://github.com/$MOD_REPO/pihole-speedtest/raw/$CORE_BRANCH/mod | sudo bash" + " curl -sSLN https://github.com/$MOD_REPO/pi-hole/raw/$CORE_BRANCH/advanced/Scripts/speedtestmod/mod.sh | sudo bash -s -- -bo" ) printf "%s\n" "${help_text[@]}" - cleanup=false - exit 0 } ####################################### @@ -166,9 +170,9 @@ purge() { # The changes reverted # shellcheck disable=SC2317 ########### abort() { - if $cleanup && [[ $aborted -eq 0 ]]; then + if grep -q true "$cleanup" && grep -q false "$aborted"; then echo "Process Aborting..." - aborted=1 + echo "true" >"$aborted" if [[ -d "$CORE_DIR"/.git/refs/remotes/old ]]; then download /etc .pihole "" Pi-hole @@ -200,7 +204,7 @@ abort() { # The repositories cleaned up # shellcheck disable=SC2317 ########### commit() { - if $cleanup; then + if grep -q true "$cleanup"; then for dir in $CORE_DIR $HTML_DIR/admin; do [[ ! -d "$dir" ]] && continue || pushd "$dir" &>/dev/null || exit 1 ! git remote -v | grep -q "old" || git remote remove old @@ -223,9 +227,6 @@ commit() { # CURR_DB # LAST_DB # ETC_DIR -# st_ver -# mod_core_ver -# mod_admin_ver # cleanup # Arguments: # $@: The options for managing the installation @@ -233,10 +234,17 @@ commit() { # The installation managed ####################################### main() { + set -u + local -r short_opts=-ubortnds::vxh local -r long_opts=update,backup,online,reinstall,testing,uninstall,database,speedtest::,version,verbose,help local parsed_opts - parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@") || help + + if ! parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@"); then + help + return 1 + fi + eval set -- "${parsed_opts}" declare -a POSITIONAL EXTRA_ARGS @@ -252,6 +260,9 @@ main() { local select_test=false local selected_test="" local do_main=false + local st_ver="" + local mod_core_ver="" + local mod_admin_ver="" while [[ $# -gt 0 ]]; do case "$1" in @@ -282,16 +293,24 @@ main() { -d | --database) database=true ;; -s | --speedtest) select_test=true - [[ -n "$2" && ! "$2" =~ sivel|libre ]] && help || selected_test=$2 + + if [[ -n "$2" && ! "$2" =~ sivel|libre ]]; then + help + return 1 + fi + + selected_test=$2 shift ;; -v | --version) getVersion $MOD_DIR - cleanup=false - exit 0 + return 0 ;; -x | --verbose) verbose=true ;; - -h | --help) help ;; + -h | --help) + help + return 0 + ;; --) dashes=1 ;; *) [[ $dashes -eq 0 ]] && POSITIONAL+=("$1") || EXTRA_ARGS+=("$1") ;; esac @@ -306,18 +325,31 @@ main() { up) update=true ;; un) uninstall=true ;; db) database=true ;; - *) help ;; + *) + help + return 1 + ;; esac done - readonly update backup online reinstall stable uninstall database verbose cleanup select_test selected_test + echo "true" >"$cleanup" + ! $do_main && ! $database && ! $select_test && do_main=true || : + readonly update backup online reinstall stable uninstall database verbose select_test selected_test do_main + printf "%s\n\nRunning the Mod Script by @ipitio...\n" "$(date)" + ! $verbose || set -x + + if $select_test; then + case $selected_test in + sivel) swivelSpeed ;; + libre) libreSpeed ;; + *) ooklaSpeed ;; + esac + fi + + set -Eeo pipefail trap '[ "$?" -eq "0" ] && commit || abort' EXIT trap 'abort' INT TERM ERR - set -Eeuo pipefail shopt -s dotglob - printf "%s\n\nRunning the Mod Script by @ipitio...\n" "$(date)" - ! $do_main && ! $database && ! $select_test && do_main=true || : - ! $verbose || set -x if $database; then if [[ -f $CURR_DB ]] && ! isEmpty $CURR_DB; then @@ -341,16 +373,6 @@ main() { fi fi - if $select_test; then - set +Eeo pipefail # don't exit on error, not critical - case $selected_test in - sivel) swivelSpeed ;; - libre) libreSpeed ;; - *) ooklaSpeed ;; - esac - set -Eeo pipefail - fi - if $do_main; then if [[ ! -f /usr/local/bin/pihole ]]; then # https://discourse.pi-hole.net/t/pi-hole-as-part-of-a-post-installation-script/3523/15 @@ -453,7 +475,7 @@ EOF if [[ ${#missingpkgs[@]} -gt 0 ]]; then echo "Installing Missing Dependencies..." if ! $PKG_MANAGER install -y "${missingpkgs[@]}" &>/dev/null; then - [[ "$PKG_MANAGER" == *"apt-get"* ]] || exit 1 + [[ "$PKG_MANAGER" == *"apt"* ]] || exit 1 echo "And Updating Package Cache..." $PKG_MANAGER update -y &>/dev/null $PKG_MANAGER install -y "${missingpkgs[@]}" &>/dev/null @@ -466,8 +488,10 @@ EOF local -r installed_admin_ver=$(getVersion "web") if [[ "$installed_core_ver" == *.* && "$installed_admin_ver" == *.* ]]; then echo "Finding Latest Compatible Versions..." - mod_core_ver=$(git ls-remote "https://github.com/arevindh/pi-hole" | grep -q "$installed_core_ver" && git ls-remote "https://github.com/arevindh/pi-hole" | grep "$installed_core_ver" | awk '{print $2;}' | cut -d '/' -f 3 | sort -Vr | head -n1 || echo "") - mod_admin_ver=$(git ls-remote "https://github.com/arevindh/AdminLTE" | grep -q "$installed_admin_ver" && git ls-remote "https://github.com/arevindh/AdminLTE" | grep "$installed_admin_ver" | awk '{print $2;}' | cut -d '/' -f 3 | sort -Vr | head -n1 || echo "") + local -r remote_core_ver=$(git ls-remote "https://github.com/$MOD_REPO/pi-hole") + local -r remote_admin_ver=$(git ls-remote "https://github.com/$MOD_REPO/AdminLTE") + mod_core_ver=$(grep -q "$installed_core_ver" <<<"$remote_core_ver" && grep "$installed_core_ver" <<<"$remote_core_ver" | awk '{print $2;}' | cut -d '/' -f 3 | sort -Vr | head -n1 || echo "") + mod_admin_ver=$(grep -q "$installed_admin_ver" <<<"$remote_admin_ver" && grep "$installed_admin_ver" <<<"$remote_admin_ver" | awk '{print $2;}' | cut -d '/' -f 3 | sort -Vr | head -n1 || echo "") fi fi elif [[ -d /run/systemd/system ]]; then @@ -479,12 +503,12 @@ EOF if $backup; then echo "Creating Backup..." - download /etc .pihole.mod https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable - download $HTML_DIR admin.mod https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable + download /etc .pihole.mod https://github.com/"$MOD_REPO"/pi-hole "$mod_core_ver" "$CORE_BRANCH" $stable + download $HTML_DIR admin.mod https://github.com/"$MOD_REPO"/AdminLTE "$mod_admin_ver" "$ADMIN_BRANCH" $stable fi $reinstall && echo "Reinstalling Mod..." || echo "Installing Mod..." - download /etc pihole-speedtest https://github.com/arevindh/pihole-speedtest "$st_ver" master $stable + download /etc pihole-speedtest https://github.com/"$MOD_REPO"/pihole-speedtest "$st_ver" "$MOD_BRANCH" $stable [[ -f $MOD_DIR/cnf ]] || touch $MOD_DIR/cnf setCnf mod-$MOD_DIR "$(getVersion $MOD_DIR)" $MOD_DIR/cnf $reinstall local stock_tag @@ -506,11 +530,11 @@ EOF fi done - $backup || download /etc .pihole https://github.com/arevindh/pi-hole "$mod_core_ver" master $stable + $backup || download /etc .pihole https://github.com/"$MOD_REPO"/pi-hole "$mod_core_ver" "$CORE_BRANCH" $stable swapScripts \cp -af $CORE_DIR/advanced/Scripts/speedtestmod/. $OPT_DIR/speedtestmod/ pihole -a -s - $backup || download $HTML_DIR admin https://github.com/arevindh/AdminLTE "$mod_admin_ver" master $stable + $backup || download $HTML_DIR admin https://github.com/"$MOD_REPO"/AdminLTE "$mod_admin_ver" "$ADMIN_BRANCH" $stable setCnf mod-$CORE_DIR "$(getVersion $CORE_DIR)" $MOD_DIR/cnf $reinstall setCnf mod-$HTML_DIR/admin "$(getVersion $HTML_DIR/admin)" $MOD_DIR/cnf $reinstall fi @@ -531,5 +555,8 @@ fi rm -f /tmp/pimod.log touch /tmp/pimod.log main "$@" 2>&1 | tee -a /tmp/pimod.log -$cleanup && mv -f /tmp/pimod.log /var/log/pihole/mod.log || rm -f /tmp/pimod.log -exit $aborted +grep -q false "$cleanup" || mv -f /tmp/pimod.log /var/log/pihole/mod.log && rm -f /tmp/pimod.log +return_status=$(<"$aborted") +rm -f "$cleanup" +rm -f "$aborted" +[[ "$return_status" == "true" ]] && exit 1 || exit 0 diff --git a/advanced/Scripts/speedtestmod/speedtest.sh b/advanced/Scripts/speedtestmod/speedtest.sh index f766e77bc8..0e3ff08ed7 100755 --- a/advanced/Scripts/speedtestmod/speedtest.sh +++ b/advanced/Scripts/speedtestmod/speedtest.sh @@ -6,9 +6,9 @@ # shellcheck disable=SC2015 # -# shellcheck disable=SC1091 -source /opt/pihole/speedtestmod/lib.sh - +declare -r MOD_REPO="arevindh" +declare -r CORE_BRANCH="master" +declare -r OPT_DIR="/opt/pihole" declare -r OUT_FILE=/tmp/speedtest.log declare -r CREATE_TABLE="create table if not exists speedtest ( id integer primary key autoincrement, @@ -24,11 +24,14 @@ upload real, share_url text );" declare START -declare SERVER_ID START=$(date -u --rfc-3339='seconds') -SERVER_ID=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) -readonly START SERVER_ID -declare -i run_status=0 +readonly START +serverid=$(grep 'SPEEDTEST_SERVER' "/etc/pihole/setupVars.conf" | cut -d '=' -f2) +run_status=$(mktemp) +database="/etc/pihole/speedtest.db" +echo "0" >"$run_status" +# shellcheck disable=SC1090,SC1091 +[[ -f "$OPT_DIR/speedtestmod/lib.sh" ]] && source "$OPT_DIR/speedtestmod/lib.sh" || source <(curl -sSLN https://github.com/"$MOD_REPO"/pi-hole/raw/"$CORE_BRANCH"/advanced/Scripts/speedtestmod/lib.sh) ####################################### # Display the help message @@ -41,14 +44,25 @@ declare -i run_status=0 ####################################### help() { local -r help_text=( - "Usage: $0 [options]" - "" + "The Test Script" + "Usage: sudo bash /path/to/speedtest.sh [options]" + " or: curl -sSLN //link/to/speedtest.sh | sudo bash [-s -- options]" + " or: pihole -a -sn [options]" "Run the speedtest" "" "Options:" + " -s, --server= Speedtest server id" + " -l, --list List all speedtest servers" + " -o, --output= Sqlite3 database (default: /etc/pihole/speedtest.db)" " -a, --attempts= Number of attempts (default: 3)" " -x, --verbose Show the commands being run" " -h, --help Display this help message" + "" + "Examples:" + " pihole -a -sn -a 1" + " sudo bash /opt/pihole/speedtestmod/speedtest.sh" + " curl -sSL https://github.com/$MOD_REPO/pihole-speedtest/raw/$CORE_BRANCH/test | sudo bash" + " curl -sSLN https://github.com/$MOD_REPO/pi-hole/raw/$CORE_BRANCH/advanced/Scripts/speedtestmod/speedtest.sh | sudo bash -s -- --verbose" ) printf "%s\n" "${help_text[@]}" @@ -58,7 +72,7 @@ help() { ####################################### # Run the speedtest # Globals: -# SERVER_ID +# serverid # Arguments: # None # Outputs: @@ -66,9 +80,9 @@ help() { ####################################### speedtest() { if /usr/bin/speedtest --version | grep -q "official"; then - [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest -s "$SERVER_ID" --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json + [[ -n "${serverid}" ]] && /usr/bin/speedtest -s "$serverid" --accept-gdpr --accept-license -f json || /usr/bin/speedtest --accept-gdpr --accept-license -f json else - [[ -n "${SERVER_ID}" ]] && /usr/bin/speedtest --server "$SERVER_ID" --json --share --secure || /usr/bin/speedtest --json --share --secure + [[ -n "${serverid}" ]] && /usr/bin/speedtest --server "$serverid" --json --share --secure || /usr/bin/speedtest --json --share --secure fi } @@ -154,7 +168,7 @@ run() { run $1 $((${2:-0} + 1)) fi else - echo "Limit Reached!" + echo "Timeout!" fi local -r rm_empty=" @@ -167,10 +181,14 @@ run() { jq "$rm_empty" "$json_file" >"$temp_file" && mv -f "$temp_file" "$json_file" rm -f "$temp_file" chmod 644 /tmp/speedtest_results - mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log - \cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log - sqlite3 /etc/pihole/speedtest.db "$CREATE_TABLE" - sqlite3 /etc/pihole/speedtest.db "insert into speedtest values (NULL, '${START}', '${stop}', '${isp}', '${from_ip}', '${server_name}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" + + if [[ -f /usr/local/bin/pihole ]]; then + mv -f /tmp/speedtest_results /var/log/pihole/speedtest.log + \cp -af /var/log/pihole/speedtest.log /etc/pihole/speedtest.log + fi + + sqlite3 "$database" "$CREATE_TABLE" + sqlite3 "$database" "insert into speedtest values (NULL, '${START}', '${stop}', '${isp}', '${from_ip}', '${server_name}', ${server_dist}, ${server_ping}, ${download}, ${upload}, '${share_url}');" [[ "$isp" == "No Internet" ]] && return 1 || return 0 } @@ -184,8 +202,8 @@ run() { # The speedtest status ####################################### main() { - local -r short_opts=-a:xh - local -r long_opts=attempts:,verbose,help + local -r short_opts=-s:lo:a:xh + local -r long_opts=server:,list,output:,attempts:,verbose,help local -r parsed_opts=$(getopt --options ${short_opts} --longoptions ${long_opts} --name "$0" -- "$@") local POSITIONAL=() local attempts="3" @@ -194,6 +212,18 @@ main() { while [[ $# -gt 0 ]]; do case "$1" in + -s | --server) + serverid="$2" + shift + ;; + -l | --list) + /usr/bin/speedtest --version | grep -q official && sudo /usr/bin/speedtest -L || /usr/bin/speedtest --secure --list 2>&1 + exit 0 + ;; + -o | --output) + database="$2" + shift + ;; -a | --attempts) attempts="$2" shift @@ -209,7 +239,7 @@ main() { [[ "$attempts" =~ ^[0-9]+$ ]] || attempts="3" ! $verbose || set -x run $attempts - run_status=$? + echo "$?" >"$run_status" } if [[ $EUID != 0 ]]; then @@ -221,4 +251,6 @@ rm -f "$OUT_FILE" touch "$OUT_FILE" main "$@" 2>&1 | tee -a "$OUT_FILE" mv -f "$OUT_FILE" /var/log/pihole/speedtest-run.log || rm -f "$OUT_FILE" -exit $run_status +exit_code=$(<"$run_status") +rm -f "$run_status" +[[ "$exit_code" -eq 1 ]] && exit 1 || exit 0 diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 313932f584..aa4c9c6373 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -53,14 +53,9 @@ Options: -h, --help Show this help dialog -i, interface Specify dnsmasq's interface listening behavior -s, speedtest Set speedtest interval, add 0 to disable - -in (Re)install Latest Speedtest Mod and only Mod - -up [un] [db] (Re)install Latest Pi-hole and (uninstall) the Mod (and flush/restore the database) - -un [db] Uninstall Speedtest Mod without updating Pi-hole (and delete/restore the database) - -db Flush or restore the Speedtest Mod database -sd Set speedtest display range - -sn Run speedtest now - -sm Speedtest Mode (deprecated) - -sc Clear speedtest data + -sm [options] Run the Mod Script in the background (tmux a -t pimod) + -sn [options] Run the Test Script in the background (tmux a -t pimodtest) -ss Set custom server -st Set default speedtest chart type (line, bar) -l, privacylevel Set privacy level (0 = lowest, 3 = highest) @@ -591,36 +586,38 @@ SpeedtestServer() { addOrEditKeyValPair "${setupVars}" "SPEEDTEST_SERVER" "$test_server" } -RunSpeedtestNow() { +RunSpeedtestMod() { # if there is a running session, wait for it to finish - # if the session is still running after 5 minutes, kill it - while [[ $(tmux list-sessions 2>/dev/null | grep -c pimodtest) -gt 0 ]]; do + while [[ $(tmux list-sessions 2>/dev/null | grep -c pimod) -gt 0 ]]; do sleep 1 ((counter++)) if [[ $counter -gt 300 ]]; then - tmux kill-session -t pimodtest + tmux kill-session -t pimod break fi done - tmux new-session -d -s pimodtest "sudo bash $speedtestfile" + # discard indexes 0 and 1 from args + args=("${args[@]:2}") + tmux new-session -d -s pimod "sudo bash $speedtestmod ${args[*]}" } -ReinstallSpeedTest() { - tmux new-session -d -s pimod "sudo bash $speedtestmod" -} - -UpdateSpeedTest() { - tmux new-session -d -s pimod "sudo bash $speedtestmod up ${args[2]} ${args[3]}" -} +RunSpeedtestNow() { + # if the session is still running after 5 minutes, kill it + while [[ $(tmux list-sessions 2>/dev/null | grep -c pimodtest) -gt 0 ]]; do + sleep 1 + ((counter++)) -UninstallSpeedTest() { - tmux new-session -d -s pimod "sudo bash $speedtestmod un ${args[2]}" -} + if [[ $counter -gt 300 ]]; then + tmux kill-session -t pimodtest + break + fi + done -ClearSpeedtestData() { - tmux new-session -d -s pimod "sudo bash $speedtestmod db" + # discard indexes 0 and 1 from args + args=("${args[@]:2}") + tmux new-session -d -s pimodtest "sudo bash $speedtestfile ${args[*]}" } SetWebUITheme() { @@ -966,13 +963,9 @@ main() { "clearaudit" ) clearAudit;; "-l" | "privacylevel" ) SetPrivacyLevel;; "-s" | "speedtest" ) ChangeSpeedTestSchedule;; - "-in" ) ReinstallSpeedTest;; - "-up" ) UpdateSpeedTest;; - "-un" ) UninstallSpeedTest;; - "-db" ) ClearSpeedtestData;; "-sd" ) UpdateSpeedTestRange;; - "-sn" ) RunSpeedtestNow;; - "-sc" ) ClearSpeedtestData;; + "-sm" ) RunSpeedtestMod ;; + "-sn" ) RunSpeedtestNow ;; "-ss" ) SpeedtestServer;; "-st" ) UpdateSpeedTestChartType;; "addcustomdns" ) AddCustomDNSAddress;;