mirror of
https://github.com/pi-hole/pi-hole
synced 2024-11-18 06:08:21 +00:00
Merge branch 'development' into tweak/gravity
This commit is contained in:
commit
56b8c4bfdb
68
pihole
68
pihole
@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Pi-hole: A black hole for Internet advertisements
|
# Pi-hole: A black hole for Internet advertisements
|
||||||
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
||||||
# Network-wide ad blocking via your own hardware.
|
# Network-wide ad blocking via your own hardware.
|
||||||
@ -10,6 +11,9 @@
|
|||||||
|
|
||||||
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
||||||
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||||
|
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||||
|
|
||||||
|
source ${colfile}
|
||||||
|
|
||||||
colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
||||||
source "${colfile}"
|
source "${colfile}"
|
||||||
@ -482,41 +486,43 @@ Options:
|
|||||||
echo -e "${OVER} ${TICK} ${str}"
|
echo -e "${OVER} ${TICK} ${str}"
|
||||||
}
|
}
|
||||||
|
|
||||||
piholeStatus() {
|
statusFunc() {
|
||||||
if [[ "$(netstat -plnt | grep -c ':53 ')" -gt "0" ]]; then
|
local addnConfigs
|
||||||
|
|
||||||
|
# Determine if service is running on port 53 (Cr: https://superuser.com/a/806331)
|
||||||
|
if (echo > /dev/tcp/localhost/53) >/dev/null 2>&1; then
|
||||||
if [[ "${1}" != "web" ]]; then
|
if [[ "${1}" != "web" ]]; then
|
||||||
echo -e " ${TICK} DNS service is running"
|
echo -e " ${TICK} DNS service is running"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ "${1}" == "web" ]]; then
|
case "${1}" in
|
||||||
echo "-1";
|
"web") echo "-1";;
|
||||||
else
|
*) echo -e " ${CROSS} DNS service is NOT running";;
|
||||||
echo -e " ${CROSS} DNS service is NOT running"
|
esac
|
||||||
fi
|
return 0
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
|
# Determine if Pi-hole's addn-hosts configs are commented out
|
||||||
# List is commented out
|
addnConfigs=$(grep -i "addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)
|
||||||
if [[ "${1}" == "web" ]]; then
|
|
||||||
echo 0;
|
if [[ "${addnConfigs}" =~ "#" ]]; then
|
||||||
|
# A config is commented out
|
||||||
|
case "${1}" in
|
||||||
|
"web") echo 0;;
|
||||||
|
*) echo -e " ${CROSS} Pi-hole blocking is Disabled";;
|
||||||
|
esac
|
||||||
|
elif [[ -n "${addnConfigs}" ]]; then
|
||||||
|
# Configs are set
|
||||||
|
case "${1}" in
|
||||||
|
"web") echo 1;;
|
||||||
|
*) echo -e " ${TICK} Pi-hole blocking is Enabled";;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
echo -e " ${CROSS} Pi-hole blocking is Disabled";
|
# No configs were found
|
||||||
fi
|
case "${1}" in
|
||||||
elif [[ "$(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then
|
"web") echo 99;;
|
||||||
# List set
|
*) echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state";;
|
||||||
if [[ "${1}" == "web" ]]; then
|
esac
|
||||||
echo 1;
|
|
||||||
else
|
|
||||||
echo -e " ${TICK} Pi-hole blocking is Enabled";
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Addn-host not found
|
|
||||||
if [[ "${1}" == "web" ]]; then
|
|
||||||
echo 99
|
|
||||||
else
|
|
||||||
echo -e " ${INFO} No hosts file linked to dnsmasq, adding it in enabled state"
|
|
||||||
fi
|
|
||||||
# Add addn-host= to dnsmasq
|
# Add addn-host= to dnsmasq
|
||||||
echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf
|
echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf
|
||||||
restartDNS
|
restartDNS
|
||||||
@ -562,7 +568,7 @@ tricorderFunc() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! timeout 2 nc -z tricorder.pi-hole.net 9998 &> /dev/null; then
|
if ! (echo > /dev/tcp/tricorder.pi-hole.net/9998) >/dev/null 2>&1; then
|
||||||
echo -e " ${CROSS} Unable to connect to Pi-hole's Tricorder server"
|
echo -e " ${CROSS} Unable to connect to Pi-hole's Tricorder server"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -652,8 +658,8 @@ case "${1}" in
|
|||||||
"uninstall" ) uninstallFunc;;
|
"uninstall" ) uninstallFunc;;
|
||||||
"enable" ) piholeEnable 1;;
|
"enable" ) piholeEnable 1;;
|
||||||
"disable" ) piholeEnable 0 "$2";;
|
"disable" ) piholeEnable 0 "$2";;
|
||||||
"status" ) piholeStatus "$2";;
|
"status" ) statusFunc "$2";;
|
||||||
"restartdns" ) restartDNS "$2";;
|
"restartdns" ) restartDNS;;
|
||||||
"-a" | "admin" ) webpageFunc "$@";;
|
"-a" | "admin" ) webpageFunc "$@";;
|
||||||
"-t" | "tail" ) tailFunc;;
|
"-t" | "tail" ) tailFunc;;
|
||||||
"checkout" ) piholeCheckoutFunc "$@";;
|
"checkout" ) piholeCheckoutFunc "$@";;
|
||||||
|
Loading…
Reference in New Issue
Block a user