mirror of
https://github.com/pi-hole/pi-hole
synced 2024-12-22 06:48:07 +00:00
add toggle to enable or disable pi-hole
This commit is contained in:
parent
9aa38cf0ae
commit
7d7e17b351
@ -319,7 +319,7 @@ gravity_reload() {
|
|||||||
#First escape forward slashes in the path:
|
#First escape forward slashes in the path:
|
||||||
adList=${adList//\//\\\/}
|
adList=${adList//\//\\\/}
|
||||||
#Now replace the line in dnsmasq file
|
#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 {} \;
|
find "$piholeDir" -type f -exec chmod 666 {} \;
|
||||||
|
|
||||||
dnsmasqPid=$(pidof dnsmasq)
|
dnsmasqPid=$(pidof dnsmasq)
|
||||||
|
53
pihole
53
pihole
@ -96,6 +96,50 @@ versionFunc() {
|
|||||||
exit 0
|
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() {
|
helpFunc() {
|
||||||
echo "::: Control all PiHole specific functions!"
|
echo "::: Control all PiHole specific functions!"
|
||||||
echo ":::"
|
echo ":::"
|
||||||
@ -115,6 +159,10 @@ helpFunc() {
|
|||||||
echo "::: -v, version Show current versions"
|
echo "::: -v, version Show current versions"
|
||||||
echo "::: -q, query Query the adlists for a specific domain"
|
echo "::: -q, query Query the adlists for a specific domain"
|
||||||
echo "::: uninstall Uninstall Pi-Hole from your system :(!"
|
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
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,5 +185,10 @@ case "$1" in
|
|||||||
"-v" | "version" ) versionFunc "$@";;
|
"-v" | "version" ) versionFunc "$@";;
|
||||||
"-q" | "query" ) queryFunc "$@";;
|
"-q" | "query" ) queryFunc "$@";;
|
||||||
"uninstall" ) uninstallFunc;;
|
"uninstall" ) uninstallFunc;;
|
||||||
|
"enable" ) piholeEnable 1;;
|
||||||
|
"disable" ) piholeEnable 0;;
|
||||||
|
"status" ) piholeStatus;;
|
||||||
|
"restartdnsmasq" ) restartDNS;;
|
||||||
|
|
||||||
* ) helpFunc;;
|
* ) helpFunc;;
|
||||||
esac
|
esac
|
||||||
|
Loading…
Reference in New Issue
Block a user