|
|
@ -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
|
|
|
|
|
|
|
|
if [[ -e "${blacklist}.bck" ]]; then
|
|
|
|
|
|
|
|
mv "${blacklist}.bck" "${blacklist}"
|
|
|
|
fi
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|