Merge pull request #2356 from pi-hole/tweak/reload_on_enable_disable

Change the enable/disable method
This commit is contained in:
DL6ER 2018-08-30 22:37:57 +02:00 committed by GitHub
commit b78aef1e7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 20 deletions

View file

@ -13,6 +13,7 @@ basename=pihole
piholeDir=/etc/"${basename}" piholeDir=/etc/"${basename}"
whitelist="${piholeDir}"/whitelist.txt whitelist="${piholeDir}"/whitelist.txt
blacklist="${piholeDir}"/blacklist.txt blacklist="${piholeDir}"/blacklist.txt
readonly regexlist="/etc/pihole/regex.list" readonly regexlist="/etc/pihole/regex.list"
reload=false reload=false
addmode=true addmode=true

View file

@ -73,6 +73,20 @@ if [[ -r "${piholeDir}/pihole.conf" ]]; then
echo -e " ${COL_LIGHT_RED}Ignoring overrides specified within pihole.conf! ${COL_NC}" echo -e " ${COL_LIGHT_RED}Ignoring overrides specified within pihole.conf! ${COL_NC}"
fi fi
# Determine if Pi-hole blocking is disabled
# If this is the case, we want to update
# gravity.list.bck and black.list.bck instead of
# gravity.list and black.list
detect_pihole_blocking_status() {
if [[ "${BLOCKING_ENABLED}" == false ]]; then
echo -e " ${INFO} Pi-hole blocking is disabled"
adList="${adList}.bck"
blackList="${blackList}.bck"
else
echo -e " ${INFO} Pi-hole blocking is enabled"
fi
}
# Determine if DNS resolution is available before proceeding # Determine if DNS resolution is available before proceeding
gravity_CheckDNSResolutionAvailable() { gravity_CheckDNSResolutionAvailable() {
local lookupDomain="pi.hole" local lookupDomain="pi.hole"
@ -621,6 +635,8 @@ if [[ "${forceDelete:-}" == true ]]; then
echo -e "${OVER} ${TICK} ${str}" echo -e "${OVER} ${TICK} ${str}"
fi fi
detect_pihole_blocking_status
# Determine which functions to run # Determine which functions to run
if [[ "${skipDownload}" == false ]]; then if [[ "${skipDownload}" == false ]]; then
# Gravity needs to download blocklists # Gravity needs to download blocklists

46
pihole
View file

@ -10,7 +10,9 @@
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" readonly gravitylist="/etc/pihole/gravity.list"
readonly blacklist="/etc/pihole/black.list"
readonly setupVars="/etc/pihole/setupVars.conf"
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE" readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
source "${colfile}" source "${colfile}"
@ -146,10 +148,13 @@ Time:
elif [[ "${1}" == "0" ]]; then elif [[ "${1}" == "0" ]]; then
# Disable Pi-hole # Disable Pi-hole
sed -i 's/^addn-hosts=\/etc\/pihole\/gravity.list/#addn-hosts=\/etc\/pihole\/gravity.list/' /etc/dnsmasq.d/01-pihole.conf if [[ -e "${gravitylist}" ]]; then
sed -i 's/^addn-hosts=\/etc\/pihole\/black.list/#addn-hosts=\/etc\/pihole\/black.list/' /etc/dnsmasq.d/01-pihole.conf mv "${gravitylist}" "${gravitylist}.bck"
if [[ -e "$wildcardlist" ]]; then echo "" > "${gravitylist}"
mv "$wildcardlist" "/etc/pihole/wildcard.list" fi
if [[ -e "${blacklist}" ]]; then
mv "${blacklist}" "${blacklist}.bck"
echo "" > "${blacklist}"
fi fi
if [[ $# > 1 ]]; then if [[ $# > 1 ]]; then
local error=false local error=false
@ -187,19 +192,25 @@ Time:
fi fi
local str="Pi-hole Disabled" local str="Pi-hole Disabled"
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
echo "BLOCKING_ENABLED=false" >> "${setupVars}"
fi fi
else else
# Enable Pi-hole # Enable Pi-hole
echo -e " ${INFO} Enabling blocking" echo -e " ${INFO} Enabling blocking"
local str="Pi-hole Enabled" local str="Pi-hole Enabled"
sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf if [[ -e "${gravitylist}.bck" ]]; then
if [[ -e "/etc/pihole/wildcard.list" ]]; then mv "${gravitylist}.bck" "${gravitylist}"
mv "/etc/pihole/wildcard.list" "$wildcardlist"
fi fi
if [[ -e "${blacklist}.bck" ]]; then
mv "${blacklist}.bck" "${blacklist}"
fi
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
echo "BLOCKING_ENABLED=true" >> "${setupVars}"
fi fi
restartDNS restartDNS reload
echo -e "${OVER} ${TICK} ${str}" echo -e "${OVER} ${TICK} ${str}"
} }
@ -242,8 +253,6 @@ Options:
} }
statusFunc() { statusFunc() {
local addnConfigs
# Determine if service is running on port 53 (Cr: https://superuser.com/a/806331) # Determine if service is running on port 53 (Cr: https://superuser.com/a/806331)
if (echo > /dev/tcp/127.0.0.1/53) >/dev/null 2>&1; then if (echo > /dev/tcp/127.0.0.1/53) >/dev/null 2>&1; then
if [[ "${1}" != "web" ]]; then if [[ "${1}" != "web" ]]; then
@ -257,16 +266,14 @@ statusFunc() {
return 0 return 0
fi fi
# Determine if Pi-hole's addn-hosts configs are commented out # Determine if Pi-hole's blocking is enabled
addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf) if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then
if [[ "${addnConfigs}" =~ "#" ]]; then
# A config is commented out # A config is commented out
case "${1}" in case "${1}" in
"web") echo 0;; "web") echo 0;;
*) echo -e " ${CROSS} Pi-hole blocking is Disabled";; *) echo -e " ${CROSS} Pi-hole blocking is Disabled";;
esac esac
elif [[ -n "${addnConfigs}" ]]; then elif grep -q "BLOCKING_ENABLED=true" /etc/pihole/setupVars.conf; then
# Configs are set # Configs are set
case "${1}" in case "${1}" in
"web") echo 1;; "web") echo 1;;
@ -276,11 +283,10 @@ statusFunc() {
# No configs were found # No configs were found
case "${1}" in case "${1}" in
"web") echo 99;; "web") echo 99;;
*) echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state";; *) echo -e " ${INFO} Pi-hole blocking will be enabled";;
esac esac
# Add addn-host= to dnsmasq # Enable blocking
echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf pihole enable
restartDNS
fi fi
} }