From 7d7e17b351d8469bb65b8c47284b33c51f286cbb Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 08:45:20 -0400 Subject: [PATCH] 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