From 9934f505a5c717d39167f705a818b25e8cdfda5a Mon Sep 17 00:00:00 2001 From: Molikuner Date: Thu, 13 Jul 2017 23:18:40 +0200 Subject: [PATCH 1/8] Fix URL extension parsing when there is a querystring Pi-hole sometimes parsed a wrong extension --- advanced/index.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index 1dd5acc7..2facd144 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -21,8 +21,9 @@ if ($serverName === 'pi.hole') } // Retrieve server URI extension (EG: jpg, exe, php) +// strtok($uri, '\?') splits the querystring from the path (if there is a querystring) ini_set('pcre.recursion_limit',100); -$uriExt = pathinfo($uri, PATHINFO_EXTENSION); +$uriExt = pathinfo(strtok($uri,'\?'), PATHINFO_EXTENSION); // Define which URL extensions get rendered as "Website Blocked" $webExt = array('asp', 'htm', 'html', 'php', 'rss', 'xml'); From 57878957944999c8917be95e8845a50e94f49bec Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 28 Jul 2017 16:10:13 +0100 Subject: [PATCH 2/8] stop an extra `h` being added to leasetime of DHCP server. We already storethe `h` in `setupVars.conf` 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 9d101482..a72a0709 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -264,7 +264,7 @@ ProcessDHCPSettings() { leasetime="24h" change_setting "DHCP_LEASETIME" "${leasetime}" else - leasetime="${DHCP_LEASETIME}h" + leasetime="${DHCP_LEASETIME}" fi # Write settings to file From 4fb66e632fbb35e72af2f08e37b3e6c6f6c5534b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 28 Jul 2017 16:30:03 +0100 Subject: [PATCH 3/8] The other h --- 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 a72a0709..b0d88284 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -261,10 +261,10 @@ ProcessDHCPSettings() { if [[ "${DHCP_LEASETIME}" == "0" ]]; then leasetime="infinite" elif [[ "${DHCP_LEASETIME}" == "" ]]; then - leasetime="24h" + leasetime="24" change_setting "DHCP_LEASETIME" "${leasetime}" else - leasetime="${DHCP_LEASETIME}" + leasetime="${DHCP_LEASETIME}h" fi # Write settings to file From 0a9965292cd0918477b186c1f2981979c67e1933 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 28 Jul 2017 19:40:13 +0100 Subject: [PATCH 4/8] Additional check to fix any existing cases of "24h" in setupVars.conf automatically. Signed-off-by: Adam Warner --- advanced/Scripts/webpage.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index b0d88284..560bebd0 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -263,6 +263,11 @@ ProcessDHCPSettings() { elif [[ "${DHCP_LEASETIME}" == "" ]]; then leasetime="24" change_setting "DHCP_LEASETIME" "${leasetime}" + 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" + change_setting "DHCP_LEASETIME" "${leasetime}" else leasetime="${DHCP_LEASETIME}h" fi From defc17ba464829a14bb901eda10ba8abedaaec11 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Jul 2017 20:24:27 -0700 Subject: [PATCH 5/8] Remove DO from README.md Preparation for futher infrastructure changes. Will remove the DO slug from README and adjust some wording. --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 6f8813fa..832c9fcf 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,9 @@ Block ads for **all** your devices _without_ the need to install client-side sof - Internet-connected home automation - Anything that communicates with the Internet -

- -

- ## Your Support Still Matters -Digital Ocean helps with our infrastructure, but our developers are all volunteers so *your donations help keep us innovating*. Sending a donation using our links below helps us offset a portion of our monthly costs. +All our developers are all volunteers so *your donations help keep us innovating*. Sending a donation using our links below helps us offset a portion of our monthly costs. - ![Paypal](https://assets.pi-hole.net/static/paypal.png) [Donate via PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY) - ![Bitcoin](https://assets.pi-hole.net/static/Bitcoin.png) Bitcoin Address: 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL From 2f36acae4969c14a9c4f8a66e0ead3de14984d5d Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Wed, 23 Aug 2017 11:51:16 +1000 Subject: [PATCH 6/8] Remove errornous space --- 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 4047502b..4fc94837 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1216,7 +1216,7 @@ install_dependent_packages() { if command -v debconf-apt-progress &> /dev/null; then # For each package, for i in "${argArray1[@]}"; do - echo -ne " ${INFO} Checking for $i..." + echo -ne " ${INFO} Checking for $i..." # if dpkg-query -W -f='${Status}' "${i}" 2>/dev/null | grep "ok installed" &> /dev/null; then # @@ -1243,7 +1243,7 @@ install_dependent_packages() { # Install Fedora/CentOS packages for i in "${argArray1[@]}"; do - echo -ne " ${INFO} Checking for $i..." + echo -ne " ${INFO} Checking for $i..." # if ${PKG_MANAGER} -q list installed "${i}" &> /dev/null; then echo -e "${OVER} ${TICK} Checking for $i" From 3125d24dedfa58143339516580e3dd8f304a691d Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 31 Aug 2017 17:39:41 +1000 Subject: [PATCH 7/8] Replace superseded netstat command * Make colfile readonly, and use path of PI_HOLE_SCRIPT_DIR * Rename piholeStatus function to statusFunc for function name consistency * Replace superseded netstat command with nc * Perform addn-hosts check using a single grep subshell --- pihole | 71 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/pihole b/pihole index 61ed6cd6..80d9e379 100755 --- a/pihole +++ b/pihole @@ -1,4 +1,5 @@ #!/bin/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. @@ -8,11 +9,11 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -colfile="/opt/pihole/COL_TABLE" -source ${colfile} - readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" +readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE" + +source ${colfile} # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then @@ -481,41 +482,41 @@ Options: echo -e "${OVER} ${TICK} ${str}" } -piholeStatus() { - if [[ "$(netstat -plnt | grep -c ':53 ')" -gt "0" ]]; then - if [[ "${1}" != "web" ]]; then - echo -e " ${TICK} DNS service is running" - fi +statusFunc() { + local addnConfigs + + # Determine if service is running on port 53 + if nc -z 127.0.0.1 53; then + [[ "${1}" != "web" ]] && echo -e " ${TICK} DNS service is running" else - if [[ "${1}" == "web" ]]; then - echo "-1"; - else - echo -e " ${CROSS} DNS service is NOT running" - fi - return + case "${1}" in + "web") echo "-1";; + *) echo -e " ${CROSS} DNS service is NOT running";; + esac + return 0 fi - if [[ "$(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then - # List is commented out - if [[ "${1}" == "web" ]]; then - echo 0; - else - echo -e " ${CROSS} Pi-hole blocking is Disabled"; - fi - elif [[ "$(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then - # List set - if [[ "${1}" == "web" ]]; then - echo 1; - else - echo -e " ${TICK} Pi-hole blocking is Enabled"; - fi + # Determine if any of Pi-hole's addn-hosts configs are commented out + addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf) + + if [[ "${addnConfigs}" =~ "#" ]]; then + # A config is commented out + case "${1}" in + "web") echo 0;; + *) echo -e " ${CROSS} Pi-hole blocking is Disabled";; + esac + elif [[ -n "${addnConfigs}" ]]; then + # Configs are set + case "${1}" in + "web") echo 1;; + *) echo -e " ${TICK} Pi-hole blocking is Enabled";; + esac else - # Addn-host not found - if [[ "${1}" == "web" ]]; then - echo 99 - else - echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state" - fi + # No configs were found + case "${1}" in + "web") echo 99;; + *) echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state";; + esac # Add addn-host= to dnsmasq echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf restartDNS @@ -651,7 +652,7 @@ case "${1}" in "uninstall" ) uninstallFunc;; "enable" ) piholeEnable 1;; "disable" ) piholeEnable 0 "$2";; - "status" ) piholeStatus "$2";; + "status" ) statusFunc "$2";; "restartdns" ) restartDNS;; "-a" | "admin" ) webpageFunc "$@";; "-t" | "tail" ) tailFunc;; From 15a5f425bfa2991b58c3698ff44e5890125dc707 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 31 Aug 2017 20:32:02 +1000 Subject: [PATCH 8/8] Replace nc with psuedo-device * Also fix minor conditional style issue --- pihole | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pihole b/pihole index 80d9e379..ded79f71 100755 --- a/pihole +++ b/pihole @@ -485,9 +485,11 @@ Options: statusFunc() { local addnConfigs - # Determine if service is running on port 53 - if nc -z 127.0.0.1 53; then - [[ "${1}" != "web" ]] && echo -e " ${TICK} DNS service is running" + # Determine if service is running on port 53 (Cr: https://superuser.com/a/806331) + if (echo > /dev/tcp/localhost/53) >/dev/null 2>&1; then + if [[ "${1}" != "web" ]]; then + echo -e " ${TICK} DNS service is running" + fi else case "${1}" in "web") echo "-1";; @@ -496,7 +498,7 @@ statusFunc() { return 0 fi - # Determine if any of Pi-hole's addn-hosts configs are commented out + # Determine if Pi-hole's addn-hosts configs are commented out addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf) if [[ "${addnConfigs}" =~ "#" ]]; then @@ -562,7 +564,7 @@ tricorderFunc() { exit 1 fi - if ! timeout 2 nc -z tricorder.pi-hole.net 9998 &> /dev/null; then + if ! (echo > /dev/tcp/tricorder.pi-hole.net/9998) >/dev/null 2>&1; then echo -e " ${CROSS} Unable to connect to Pi-hole's Tricorder server" exit 1 fi