From 16f1d7fad9420b8fb6aa83cbcd9c82400f122444 Mon Sep 17 00:00:00 2001 From: tuplink Date: Wed, 19 Oct 2016 21:50:34 -0400 Subject: [PATCH 01/17] Blacklist unwhitelisted --- advanced/Scripts/whitelist.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 2b572d00..b294e7b6 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -99,6 +99,8 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} + #Blacklist unwhitelisted + ${blacklistScript} $1 fi } From 74bfcea6a8653299f261efe89228654b1b1b1f16 Mon Sep 17 00:00:00 2001 From: tuplink Date: Wed, 19 Oct 2016 22:00:03 -0400 Subject: [PATCH 02/17] add blacklistScript var --- advanced/Scripts/whitelist.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index b294e7b6..2dea6e7c 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -33,6 +33,7 @@ fi #globals basename=pihole piholeDir=/etc/${basename} +blacklistScript=/opt/pihole/blacklist.sh adList=${piholeDir}/gravity.list whitelist=${piholeDir}/whitelist.txt reload=true From 41056ace0264deb0102425e9e5983bae4f7a664d Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 06:29:53 -0400 Subject: [PATCH 03/17] use pihole instead of direct path --- advanced/Scripts/whitelist.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 2dea6e7c..3d0561ef 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -33,7 +33,6 @@ fi #globals basename=pihole piholeDir=/etc/${basename} -blacklistScript=/opt/pihole/blacklist.sh adList=${piholeDir}/gravity.list whitelist=${piholeDir}/whitelist.txt reload=true @@ -100,8 +99,7 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} - #Blacklist unwhitelisted - ${blacklistScript} $1 + pihole -g fi } From bbcf4800de3cf9253502285c3fe40547da13902b Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 06:30:48 -0400 Subject: [PATCH 04/17] use pihole instead of direct path --- advanced/Scripts/whitelist.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 3d0561ef..a2e31c8a 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -99,6 +99,7 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} + #reload gravity to pickup any entries this may have removed pihole -g fi } From 7d7e17b351d8469bb65b8c47284b33c51f286cbb Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 08:45:20 -0400 Subject: [PATCH 05/17] add toggle to enable or disable pi-hole --- gravity.sh | 2 +- pihole | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 990b18ee..3cc621c3 100755 --- a/gravity.sh +++ b/gravity.sh @@ -319,7 +319,7 @@ gravity_reload() { #First escape forward slashes in the path: adList=${adList//\//\\\/} #Now replace the line in dnsmasq file - sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf +# sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf find "$piholeDir" -type f -exec chmod 666 {} \; dnsmasqPid=$(pidof dnsmasq) diff --git a/pihole b/pihole index 6be32acf..8828dfe4 100755 --- a/pihole +++ b/pihole @@ -96,6 +96,50 @@ versionFunc() { exit 0 } +restartDNS() { + dnsmasqPid=$(pidof dnsmasq) + if [[ ${dnsmasqPid} ]]; then + # service already running - reload config + if [ -x "$(command -v systemctl)" ]; then + systemctl restart dnsmasq + else + service dnsmasq restart + fi + else + # service not running, start it up + if [ -x "$(command -v systemctl)" ]; then + systemctl start dnsmasq + else + service dnsmasq start + fi + fi +} + +piholeEnable() { + if [[ "${1}" == "0" ]] ; then + #Disable Pihole + sed -i 's/^addn-hosts/#addn-hosts/' /etc/dnsmasq.d/01-pihole.conf + else + #Enable pihole + sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf + fi + restartDNS +} + +piholeStatus() { + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then + echo "pihole is Diabled" + else + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then + echo "pihole is Enabled" + else + echo "no hosts file linked to dnsmasq, adding it in enabled state" + echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + fi + fi +} + + helpFunc() { echo "::: Control all PiHole specific functions!" echo ":::" @@ -115,6 +159,10 @@ helpFunc() { echo "::: -v, version Show current versions" echo "::: -q, query Query the adlists for a specific domain" echo "::: uninstall Uninstall Pi-Hole from your system :(!" + echo "::: status Is Pi-Hole Enabled or Disabled" + echo "::: enable Enable Pi-Hole DNS Blocking" + echo "::: disable Disable Pi-Hole DNS Blocking" + echo "::: restartdnsmasq Restart dnsmasq" exit 0 } @@ -137,5 +185,10 @@ case "$1" in "-v" | "version" ) versionFunc "$@";; "-q" | "query" ) queryFunc "$@";; "uninstall" ) uninstallFunc;; +"enable" ) piholeEnable 1;; +"disable" ) piholeEnable 0;; +"status" ) piholeStatus;; +"restartdnsmasq" ) restartDNS;; + * ) helpFunc;; esac From aaee895b2bd282ace43ae7f8b504bc81303f1e59 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 08:58:36 -0400 Subject: [PATCH 06/17] add pihole status web option to return 1 or 0 for easy use with php --- pihole | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pihole b/pihole index 8828dfe4..1651ac9c 100755 --- a/pihole +++ b/pihole @@ -128,13 +128,16 @@ piholeEnable() { piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then - echo "pihole is Diabled" + if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Diabled"; fi else if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then - echo "pihole is Enabled" + if [[ "${1}" == "web" ]] ; then echo 1; else echo "::: pihole is Enabled"; fi else - echo "no hosts file linked to dnsmasq, adding it in enabled state" - echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + if [[ "${1}" == "web" ]] ; then echo 1; else + echo "::: no hosts file linked to dnsmasq, adding it in enabled state" + echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + restartDNS + fi fi fi } @@ -187,7 +190,7 @@ case "$1" in "uninstall" ) uninstallFunc;; "enable" ) piholeEnable 1;; "disable" ) piholeEnable 0;; -"status" ) piholeStatus;; +"status" ) piholeStatus "$2";; "restartdnsmasq" ) restartDNS;; * ) helpFunc;; From a9d17c96bee91828148f54f82a6e6a27b5bc2528 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:03:20 -0400 Subject: [PATCH 07/17] include status at end of gravity so if it is disabled you will see it when running --- gravity.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gravity.sh b/gravity.sh index 3cc621c3..d43de697 100755 --- a/gravity.sh +++ b/gravity.sh @@ -375,3 +375,4 @@ gravity_hostFormat gravity_blackbody gravity_reload +pihole status From 60873144ea7d071def63b68a5e860c0d6aaa3de0 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:09:35 -0400 Subject: [PATCH 08/17] make last line of script return a new line been bugging me for awhile --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index d43de697..2d3c4f09 100755 --- a/gravity.sh +++ b/gravity.sh @@ -313,7 +313,7 @@ gravity_reload() { # Reload hosts file echo ":::" - echo -n "::: Refresh lists in dnsmasq..." + echo "::: Refresh lists in dnsmasq..." #ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list! #First escape forward slashes in the path: From dda448e0503eaeb8d95992fbdb3b29dd216c8e4a Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:15:03 -0400 Subject: [PATCH 09/17] use finction in pihole to restart dnsmasq --- gravity.sh | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/gravity.sh b/gravity.sh index 2d3c4f09..d51cc814 100755 --- a/gravity.sh +++ b/gravity.sh @@ -322,23 +322,7 @@ gravity_reload() { # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf find "$piholeDir" -type f -exec chmod 666 {} \; - dnsmasqPid=$(pidof dnsmasq) - - if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - if [ -x "$(command -v systemctl)" ]; then - systemctl restart dnsmasq - else - service dnsmasq restart - fi - else - # service not running, start it up - if [ -x "$(command -v systemctl)" ]; then - systemctl start dnsmasq - else - service dnsmasq start - fi - fi + pihole restartdnsmasq } for var in "$@" From 3ca3eaa62cd229dd4ead714af6ad2b4f2f111419 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:40:45 -0400 Subject: [PATCH 10/17] change restartdnsmasq to restartdns --- gravity.sh | 2 +- pihole | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index d51cc814..cdcf486c 100755 --- a/gravity.sh +++ b/gravity.sh @@ -322,7 +322,7 @@ gravity_reload() { # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf find "$piholeDir" -type f -exec chmod 666 {} \; - pihole restartdnsmasq + pihole restartdns } for var in "$@" diff --git a/pihole b/pihole index 1651ac9c..bd49f63d 100755 --- a/pihole +++ b/pihole @@ -165,7 +165,7 @@ helpFunc() { echo "::: status Is Pi-Hole Enabled or Disabled" echo "::: enable Enable Pi-Hole DNS Blocking" echo "::: disable Disable Pi-Hole DNS Blocking" - echo "::: restartdnsmasq Restart dnsmasq" + echo "::: restartdns Restart dnsmasq" exit 0 } @@ -191,7 +191,7 @@ case "$1" in "enable" ) piholeEnable 1;; "disable" ) piholeEnable 0;; "status" ) piholeStatus "$2";; -"restartdnsmasq" ) restartDNS;; +"restartdns" ) restartDNS;; * ) helpFunc;; esac From 15d68467a1c082b422d2a8be3d3c23e94afbe5a5 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 10:12:02 -0400 Subject: [PATCH 11/17] attempt to fix --- gravity.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/gravity.sh b/gravity.sh index d4298a31..f4f075ad 100755 --- a/gravity.sh +++ b/gravity.sh @@ -319,13 +319,8 @@ gravity_reload() { #First escape forward slashes in the path: adList=${adList//\//\\\/} #Now replace the line in dnsmasq file -<<<<<<< HEAD # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf -======= - sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf ->>>>>>> upstream/promoTweaksTheSecond - pihole restartdns } From e1c56bcbfec8cd9fd00577e51a9196966ff07ef7 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 10:19:03 -0400 Subject: [PATCH 12/17] remove a commit in whitelist --- advanced/Scripts/whitelist.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index a2e31c8a..2b572d00 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -99,8 +99,6 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} - #reload gravity to pickup any entries this may have removed - pihole -g fi } From 9056a5a7b694115fcbdaaa0ba04b3b9f32147cc3 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 11:05:49 -0400 Subject: [PATCH 13/17] fix spelling / replace tabs with spaces in help --- pihole | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pihole b/pihole index bd49f63d..afabe9bb 100755 --- a/pihole +++ b/pihole @@ -128,7 +128,7 @@ piholeEnable() { piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then - if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Diabled"; fi + if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Disabled"; fi else if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then if [[ "${1}" == "web" ]] ; then echo 1; else echo "::: pihole is Enabled"; fi @@ -162,10 +162,10 @@ helpFunc() { echo "::: -v, version Show current versions" echo "::: -q, query Query the adlists for a specific domain" echo "::: uninstall Uninstall Pi-Hole from your system :(!" - echo "::: status Is Pi-Hole Enabled or Disabled" - echo "::: enable Enable Pi-Hole DNS Blocking" - echo "::: disable Disable Pi-Hole DNS Blocking" - echo "::: restartdns Restart dnsmasq" + echo "::: status Is Pi-Hole Enabled or Disabled" + echo "::: enable Enable Pi-Hole DNS Blocking" + echo "::: disable Disable Pi-Hole DNS Blocking" + echo "::: restartdns Restart dnsmasq" exit 0 } From 685b775b680f2724076ae52d997d92651049fdd5 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 11:24:34 -0400 Subject: [PATCH 14/17] rework status if statments --- pihole | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole b/pihole index afabe9bb..29acfe29 100755 --- a/pihole +++ b/pihole @@ -130,10 +130,10 @@ piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Disabled"; fi else - if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then - if [[ "${1}" == "web" ]] ; then echo 1; else echo "::: pihole is Enabled"; fi - else - if [[ "${1}" == "web" ]] ; then echo 1; else + if [[ "${1}" == "web" ]] ; then echo 1; else + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then + echo "::: pihole is Enabled"; + else echo "::: no hosts file linked to dnsmasq, adding it in enabled state" echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf restartDNS From 78fbafa1cd3a2c21ee1cc1b7b9f69017defdff86 Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 18:40:03 -0400 Subject: [PATCH 15/17] test out new status logic --- pihole | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 29acfe29..7d5f59b5 100755 --- a/pihole +++ b/pihole @@ -127,18 +127,30 @@ piholeEnable() { } piholeStatus() { - if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then - if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Disabled"; fi - else - if [[ "${1}" == "web" ]] ; then echo 1; else - if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then - echo "::: pihole is Enabled"; - else - echo "::: no hosts file linked to dnsmasq, adding it in enabled state" - echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf - restartDNS - fi + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=/") ]] ; then + #list is commented out + if [[ "${1}" == "web" ]] ; then + echo 0; + else + echo "::: pihole is Disabled"; fi + elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then + #list set + if [[ "${1}" == "web" ]] ; then + echo 1; + else + echo "::: pihole is Enabled"; + fi + else + #addn-host not found + if [[ "${1}" == "web" ]] ; then + echo 99 + else + echo "::: no hosts file linked to dnsmasq, adding it in enabled state" + fi + #add addn-host= to dnsmasq + echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + restartDNS fi } From c83dd3ccd7dfafbd6e843b5a99df4b67de8549d7 Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 18:45:27 -0400 Subject: [PATCH 16/17] change spacing --- pihole | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 7d5f59b5..1c7d11e3 100755 --- a/pihole +++ b/pihole @@ -130,25 +130,25 @@ piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=/") ]] ; then #list is commented out if [[ "${1}" == "web" ]] ; then - echo 0; - else - echo "::: pihole is Disabled"; + echo 0; + else + echo "::: pihole is Disabled"; fi elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then - #list set - if [[ "${1}" == "web" ]] ; then + #list set + if [[ "${1}" == "web" ]] ; then echo 1; - else - echo "::: pihole is Enabled"; + else + echo "::: pihole is Enabled"; fi else #addn-host not found if [[ "${1}" == "web" ]] ; then - echo 99 - else + echo 99 + else echo "::: no hosts file linked to dnsmasq, adding it in enabled state" - fi - #add addn-host= to dnsmasq + fi + #add addn-host= to dnsmasq echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf restartDNS fi From e199f6db87881ac062a4e31d78a6ba1b3e31841b Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 21:15:11 -0400 Subject: [PATCH 17/17] spelling updates --- pihole | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pihole b/pihole index 1c7d11e3..fa5a95f0 100755 --- a/pihole +++ b/pihole @@ -132,21 +132,21 @@ piholeStatus() { if [[ "${1}" == "web" ]] ; then echo 0; else - echo "::: pihole is Disabled"; + echo "::: Pi-hole is Disabled"; fi elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then #list set if [[ "${1}" == "web" ]] ; then echo 1; else - echo "::: pihole is Enabled"; + echo "::: Pi-hole is Enabled"; fi else #addn-host not found if [[ "${1}" == "web" ]] ; then echo 99 else - echo "::: no hosts file linked to dnsmasq, adding it in enabled state" + echo "::: No hosts file linked to dnsmasq, adding it in enabled state" fi #add addn-host= to dnsmasq echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf