2019-11-05 21:11:47 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-08-31 07:39:41 +00:00
|
|
|
|
2016-08-26 22:10:22 +00:00
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
2017-02-22 17:55:20 +00:00
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2016-08-26 22:10:22 +00:00
|
|
|
# Controller for all pihole scripts and functions.
|
|
|
|
#
|
2017-02-22 17:55:20 +00:00
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
2017-03-08 12:16:40 +00:00
|
|
|
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
|
2018-09-02 02:11:45 +00:00
|
|
|
|
2019-09-16 12:46:09 +00:00
|
|
|
# setupVars and PI_HOLE_BIN_DIR are not readonly here because in some functions (checkout),
|
|
|
|
# they might get set again when the installer is sourced. This causes an
|
2018-09-02 02:11:45 +00:00
|
|
|
# error due to modifying a readonly variable.
|
|
|
|
setupVars="/etc/pihole/setupVars.conf"
|
2019-08-30 21:06:14 +00:00
|
|
|
PI_HOLE_BIN_DIR="/usr/local/bin"
|
2018-09-02 02:11:45 +00:00
|
|
|
|
2017-08-31 07:39:41 +00:00
|
|
|
readonly colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
|
2017-07-24 11:25:04 +00:00
|
|
|
source "${colfile}"
|
|
|
|
|
2018-02-25 08:34:04 +00:00
|
|
|
resolver="pihole-FTL"
|
|
|
|
|
2016-11-16 20:34:43 +00:00
|
|
|
webpageFunc() {
|
2017-07-24 11:25:04 +00:00
|
|
|
source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"
|
2016-12-28 16:25:14 +00:00
|
|
|
main "$@"
|
2016-11-16 20:34:43 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2018-07-08 18:37:33 +00:00
|
|
|
listFunc() {
|
2016-12-31 12:49:04 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/list.sh "$@"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
debugFunc() {
|
2017-02-26 23:36:53 +00:00
|
|
|
local automated
|
2017-02-27 19:03:57 +00:00
|
|
|
local web
|
|
|
|
|
|
|
|
# Pull off the `debug` leaving passed call augmentation flags in $1
|
2017-02-26 23:36:53 +00:00
|
|
|
shift
|
2017-02-27 19:40:20 +00:00
|
|
|
if [[ "$@" == *"-a"* ]]; then
|
2017-02-26 23:36:53 +00:00
|
|
|
automated="true"
|
|
|
|
fi
|
2017-02-27 19:40:20 +00:00
|
|
|
if [[ "$@" == *"-w"* ]]; then
|
2017-02-27 19:03:57 +00:00
|
|
|
web="true"
|
|
|
|
fi
|
|
|
|
|
|
|
|
AUTOMATED=${automated:-} WEBCALL=${web:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh
|
2016-11-02 16:36:30 +00:00
|
|
|
exit 0
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
flushFunc() {
|
2017-05-17 10:44:35 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/piholeLogFlush.sh "$@"
|
2016-11-02 16:36:30 +00:00
|
|
|
exit 0
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 19:23:15 +00:00
|
|
|
arpFunc() {
|
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/piholeARPTable.sh "$@"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
updatePiholeFunc() {
|
2018-04-15 17:37:32 +00:00
|
|
|
shift
|
2018-04-15 17:25:35 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/update.sh "$@"
|
2016-11-02 16:36:30 +00:00
|
|
|
exit 0
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
reconfigurePiholeFunc() {
|
2016-11-02 16:36:30 +00:00
|
|
|
/etc/.pihole/automated\ install/basic-install.sh --reconfigure
|
|
|
|
exit 0;
|
2016-10-15 16:07:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
updateGravityFunc() {
|
2016-11-02 17:39:27 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/gravity.sh "$@"
|
2018-10-19 05:27:35 +00:00
|
|
|
exit $?
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
queryFunc() {
|
2017-09-17 14:41:26 +00:00
|
|
|
shift
|
2018-06-13 05:49:52 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/query.sh "$@"
|
2016-11-02 16:36:30 +00:00
|
|
|
exit 0
|
2016-08-26 08:39:27 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
chronometerFunc() {
|
2016-11-02 16:36:30 +00:00
|
|
|
shift
|
2016-11-02 17:39:27 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/chronometer.sh "$@"
|
2016-11-02 16:36:30 +00:00
|
|
|
exit 0
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
uninstallFunc() {
|
2016-11-02 17:39:27 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/uninstall.sh
|
2016-11-02 16:36:30 +00:00
|
|
|
exit 0
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
versionFunc() {
|
2016-11-02 16:36:30 +00:00
|
|
|
shift
|
2016-11-02 17:39:27 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/version.sh "$@"
|
2016-11-02 16:36:30 +00:00
|
|
|
exit 0
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 12:45:20 +00:00
|
|
|
restartDNS() {
|
2017-08-01 10:48:43 +00:00
|
|
|
local svcOption svc str output status
|
2019-08-14 18:58:18 +00:00
|
|
|
svcOption="${1:-restart}"
|
2017-07-24 11:25:04 +00:00
|
|
|
|
2019-08-14 18:58:18 +00:00
|
|
|
# Determine if we should reload or restart
|
2019-12-11 21:47:46 +00:00
|
|
|
if [[ "${svcOption}" =~ "reload-lists" ]]; then
|
|
|
|
# Reloading of the lists has been requested
|
|
|
|
# Note: This will NOT re-read any *.conf files
|
|
|
|
# Note 2: We cannot use killall here as it does
|
|
|
|
# not know about real-time signals
|
|
|
|
svc="kill -SIGRTMIN $(pidof ${resolver})"
|
|
|
|
str="Reloading DNS lists"
|
|
|
|
elif [[ "${svcOption}" =~ "reload" ]]; then
|
|
|
|
# Reloading of the DNS cache has been requested
|
2019-08-14 18:58:18 +00:00
|
|
|
# Note: This will NOT re-read any *.conf files
|
2018-02-26 16:26:51 +00:00
|
|
|
svc="killall -s SIGHUP ${resolver}"
|
2019-12-11 21:47:46 +00:00
|
|
|
str="Flushing DNS cache"
|
2017-10-19 06:51:20 +00:00
|
|
|
else
|
2019-08-14 18:58:18 +00:00
|
|
|
# A full restart has been requested
|
|
|
|
svc="service ${resolver} restart"
|
2019-12-11 21:47:46 +00:00
|
|
|
str="Restarting DNS server"
|
2017-07-24 11:25:04 +00:00
|
|
|
fi
|
|
|
|
|
2017-09-14 06:39:25 +00:00
|
|
|
# Print output to Terminal, but not to Web Admin
|
2017-07-24 11:25:04 +00:00
|
|
|
[[ -t 1 ]] && echo -ne " ${INFO} ${str}..."
|
|
|
|
|
2017-08-01 10:48:43 +00:00
|
|
|
output=$( { ${svc}; } 2>&1 )
|
2017-07-24 11:25:04 +00:00
|
|
|
status="$?"
|
|
|
|
|
2017-08-01 10:48:43 +00:00
|
|
|
if [[ "${status}" -eq 0 ]]; then
|
2017-07-24 11:25:04 +00:00
|
|
|
[[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}"
|
2018-11-09 03:00:13 +00:00
|
|
|
return 0
|
2016-10-20 12:45:20 +00:00
|
|
|
else
|
2017-08-01 10:48:43 +00:00
|
|
|
[[ ! -t 1 ]] && local OVER=""
|
2017-07-24 11:25:04 +00:00
|
|
|
echo -e "${OVER} ${CROSS} ${output}"
|
2018-11-09 03:00:13 +00:00
|
|
|
return 1
|
2016-10-20 12:45:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
piholeEnable() {
|
2017-05-14 01:53:40 +00:00
|
|
|
if [[ "${2}" == "-h" ]] || [[ "${2}" == "--help" ]]; then
|
2017-05-14 01:11:44 +00:00
|
|
|
echo "Usage: pihole disable [time]
|
|
|
|
Example: 'pihole disable', or 'pihole disable 5m'
|
|
|
|
Disable Pi-hole subsystems
|
|
|
|
|
|
|
|
Time:
|
|
|
|
#s Disable Pi-hole functionality for # second(s)
|
|
|
|
#m Disable Pi-hole functionality for # minute(s)"
|
|
|
|
exit 0
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
elif [[ "${1}" == "0" ]]; then
|
|
|
|
# Disable Pi-hole
|
2019-01-24 08:16:24 +00:00
|
|
|
if grep -cq "BLOCKING_ENABLED=false" "${setupVars}"; then
|
|
|
|
echo -e " ${INFO} Blocking already disabled, nothing to do"
|
|
|
|
exit 0
|
|
|
|
fi
|
2017-05-14 01:11:44 +00:00
|
|
|
if [[ $# > 1 ]]; then
|
2017-06-21 11:49:05 +00:00
|
|
|
local error=false
|
|
|
|
if [[ "${2}" == *"s" ]]; then
|
2016-11-17 22:31:11 +00:00
|
|
|
tt=${2%"s"}
|
2017-06-21 11:49:05 +00:00
|
|
|
if [[ "${tt}" =~ ^-?[0-9]+$ ]];then
|
|
|
|
local str="Disabling blocking for ${tt} seconds"
|
|
|
|
echo -e " ${INFO} ${str}..."
|
|
|
|
local str="Blocking will be re-enabled in ${tt} seconds"
|
2019-08-23 17:49:13 +00:00
|
|
|
nohup "${PI_HOLE_SCRIPT_DIR}"/pihole-reenable.sh ${tt} </dev/null &>/dev/null &
|
2017-06-21 11:49:05 +00:00
|
|
|
else
|
|
|
|
local error=true
|
|
|
|
fi
|
|
|
|
elif [[ "${2}" == *"m" ]]; then
|
2016-11-17 22:31:11 +00:00
|
|
|
tt=${2%"m"}
|
2017-06-21 11:49:05 +00:00
|
|
|
if [[ "${tt}" =~ ^-?[0-9]+$ ]];then
|
|
|
|
local str="Disabling blocking for ${tt} minutes"
|
|
|
|
echo -e " ${INFO} ${str}..."
|
|
|
|
local str="Blocking will be re-enabled in ${tt} minutes"
|
|
|
|
tt=$((${tt}*60))
|
2019-08-23 17:49:13 +00:00
|
|
|
nohup "${PI_HOLE_SCRIPT_DIR}"/pihole-reenable.sh ${tt} </dev/null &>/dev/null &
|
2017-06-21 11:49:05 +00:00
|
|
|
else
|
|
|
|
local error=true
|
|
|
|
fi
|
|
|
|
elif [[ -n "${2}" ]]; then
|
|
|
|
local error=true
|
2016-11-17 21:58:00 +00:00
|
|
|
else
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Disabling blocking"
|
2016-11-17 21:58:00 +00:00
|
|
|
fi
|
2017-06-21 11:49:05 +00:00
|
|
|
|
|
|
|
if [[ ${error} == true ]];then
|
|
|
|
echo -e " ${COL_LIGHT_RED}Unknown format for delayed reactivation of the blocking!${COL_NC}"
|
|
|
|
echo -e " Try 'pihole disable --help' for more information."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local str="Pi-hole Disabled"
|
2018-08-13 15:22:10 +00:00
|
|
|
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
|
|
|
|
echo "BLOCKING_ENABLED=false" >> "${setupVars}"
|
2016-11-17 21:58:00 +00:00
|
|
|
fi
|
2016-10-20 12:45:20 +00:00
|
|
|
else
|
2017-05-14 01:11:44 +00:00
|
|
|
# Enable Pi-hole
|
2019-08-23 17:49:13 +00:00
|
|
|
killall -q pihole-reenable
|
2019-01-24 08:16:24 +00:00
|
|
|
if grep -cq "BLOCKING_ENABLED=true" "${setupVars}"; then
|
|
|
|
echo -e " ${INFO} Blocking already enabled, nothing to do"
|
|
|
|
exit 0
|
|
|
|
fi
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Enabling blocking"
|
|
|
|
local str="Pi-hole Enabled"
|
2017-07-16 12:22:59 +00:00
|
|
|
|
2018-08-13 15:22:10 +00:00
|
|
|
sed -i "/BLOCKING_ENABLED=/d" "${setupVars}"
|
|
|
|
echo "BLOCKING_ENABLED=true" >> "${setupVars}"
|
2016-10-20 12:45:20 +00:00
|
|
|
fi
|
2017-07-16 12:22:59 +00:00
|
|
|
|
2018-08-12 16:36:07 +00:00
|
|
|
restartDNS reload
|
2017-07-16 12:22:59 +00:00
|
|
|
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e "${OVER} ${TICK} ${str}"
|
2016-10-20 12:45:20 +00:00
|
|
|
}
|
|
|
|
|
2016-10-31 22:02:20 +00:00
|
|
|
piholeLogging() {
|
2016-11-02 09:35:48 +00:00
|
|
|
shift
|
2017-05-14 01:53:40 +00:00
|
|
|
if [[ "${1}" == "-h" ]] || [[ "${1}" == "--help" ]]; then
|
2017-05-14 01:11:44 +00:00
|
|
|
echo "Usage: pihole logging [options]
|
|
|
|
Example: 'pihole logging on'
|
|
|
|
Specify whether the Pi-hole log should be used
|
|
|
|
|
|
|
|
Options:
|
|
|
|
on Enable the Pi-hole log at /var/log/pihole.log
|
2018-01-18 16:08:46 +00:00
|
|
|
off Disable and flush the Pi-hole log at /var/log/pihole.log
|
|
|
|
off noflush Disable the Pi-hole log at /var/log/pihole.log"
|
2017-05-14 01:11:44 +00:00
|
|
|
exit 0
|
|
|
|
elif [[ "${1}" == "off" ]]; then
|
|
|
|
# Disable logging
|
2016-11-02 09:35:48 +00:00
|
|
|
sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
|
|
|
sed -i 's/^QUERY_LOGGING=true/QUERY_LOGGING=false/' /etc/pihole/setupVars.conf
|
2018-01-18 16:08:46 +00:00
|
|
|
if [[ "${2}" != "noflush" ]]; then
|
|
|
|
# Flush logs
|
2019-08-24 11:33:32 +00:00
|
|
|
"${PI_HOLE_BIN_DIR}"/pihole -f
|
2018-01-18 16:08:46 +00:00
|
|
|
fi
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Disabling logging..."
|
|
|
|
local str="Logging has been disabled!"
|
2017-05-14 01:11:44 +00:00
|
|
|
elif [[ "${1}" == "on" ]]; then
|
|
|
|
# Enable logging
|
2016-11-02 09:35:48 +00:00
|
|
|
sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf
|
|
|
|
sed -i 's/^QUERY_LOGGING=false/QUERY_LOGGING=true/' /etc/pihole/setupVars.conf
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Enabling logging..."
|
|
|
|
local str="Logging has been enabled!"
|
2016-11-02 09:35:48 +00:00
|
|
|
else
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${COL_LIGHT_RED}Invalid option${COL_NC}
|
|
|
|
Try 'pihole logging --help' for more information."
|
2016-11-02 09:35:48 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
restartDNS
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e "${OVER} ${TICK} ${str}"
|
2016-10-31 22:02:20 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 16:39:09 +00:00
|
|
|
analyze_ports() {
|
|
|
|
# FTL is listening at least on at least one port when this
|
|
|
|
# function is getting called
|
2020-07-01 16:49:31 +00:00
|
|
|
echo -e " ${TICK} DNS service is listening"
|
|
|
|
# Check individual address family/protocol combinations
|
|
|
|
# For a healthy Pi-hole, they should all be up (nothing printed)
|
|
|
|
if grep -q "IPv4.*UDP" <<< "${1}"; then
|
|
|
|
echo -e " ${TICK} UDP (IPv4)"
|
2020-07-01 16:39:09 +00:00
|
|
|
else
|
2020-07-01 16:49:31 +00:00
|
|
|
echo -e " ${CROSS} UDP (IPv4)"
|
|
|
|
fi
|
|
|
|
if grep -q "IPv4.*TCP" <<< "${1}"; then
|
|
|
|
echo -e " ${TICK} TCP (IPv4)"
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} TCP (IPv4)"
|
|
|
|
fi
|
|
|
|
if grep -q "IPv6.*UDP" <<< "${1}"; then
|
|
|
|
echo -e " ${TICK} UDP (IPv6)"
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} UDP (IPv6)"
|
|
|
|
fi
|
|
|
|
if grep -q "IPv6.*TCP" <<< "${1}"; then
|
|
|
|
echo -e " ${TICK} TCP (IPv6)"
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} TCP (IPv6)"
|
2020-07-01 16:39:09 +00:00
|
|
|
fi
|
2020-07-01 16:49:31 +00:00
|
|
|
echo ""
|
2020-07-01 16:39:09 +00:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:39:41 +00:00
|
|
|
statusFunc() {
|
2020-07-01 16:39:09 +00:00
|
|
|
# Determine if there is a pihole service is listening on port 53
|
|
|
|
local listening
|
|
|
|
listening="$(lsof -Pni:53)"
|
|
|
|
if grep -q "pihole" <<< "${listening}"; then
|
2017-05-14 01:11:44 +00:00
|
|
|
if [[ "${1}" != "web" ]]; then
|
2020-07-01 16:39:09 +00:00
|
|
|
analyze_ports "${listening}"
|
2016-12-28 15:58:48 +00:00
|
|
|
fi
|
|
|
|
else
|
2017-08-31 07:39:41 +00:00
|
|
|
case "${1}" in
|
|
|
|
"web") echo "-1";;
|
2020-07-01 16:39:09 +00:00
|
|
|
*) echo -e " ${CROSS} DNS service is NOT listening";;
|
2017-08-31 07:39:41 +00:00
|
|
|
esac
|
|
|
|
return 0
|
2016-12-28 15:58:48 +00:00
|
|
|
fi
|
|
|
|
|
2018-08-13 13:01:46 +00:00
|
|
|
# Determine if Pi-hole's blocking is enabled
|
2018-08-13 15:22:10 +00:00
|
|
|
if grep -q "BLOCKING_ENABLED=false" /etc/pihole/setupVars.conf; then
|
2017-08-31 07:39:41 +00:00
|
|
|
# A config is commented out
|
|
|
|
case "${1}" in
|
|
|
|
"web") echo 0;;
|
2020-07-01 16:39:09 +00:00
|
|
|
*) echo -e " ${CROSS} Pi-hole blocking is disabled";;
|
2017-08-31 07:39:41 +00:00
|
|
|
esac
|
2018-08-13 15:22:10 +00:00
|
|
|
elif grep -q "BLOCKING_ENABLED=true" /etc/pihole/setupVars.conf; then
|
2017-08-31 07:39:41 +00:00
|
|
|
# Configs are set
|
|
|
|
case "${1}" in
|
|
|
|
"web") echo 1;;
|
2020-07-01 16:39:09 +00:00
|
|
|
*) echo -e " ${TICK} Pi-hole blocking is enabled";;
|
2017-08-31 07:39:41 +00:00
|
|
|
esac
|
2016-10-20 22:40:03 +00:00
|
|
|
else
|
2017-08-31 07:39:41 +00:00
|
|
|
# No configs were found
|
|
|
|
case "${1}" in
|
|
|
|
"web") echo 99;;
|
2018-08-30 20:28:15 +00:00
|
|
|
*) echo -e " ${INFO} Pi-hole blocking will be enabled";;
|
2017-08-31 07:39:41 +00:00
|
|
|
esac
|
2018-08-13 13:01:46 +00:00
|
|
|
# Enable blocking
|
2019-08-24 11:33:32 +00:00
|
|
|
"${PI_HOLE_BIN_DIR}"/pihole enable
|
2016-10-20 12:45:20 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-12-08 20:15:03 +00:00
|
|
|
tailFunc() {
|
2018-06-17 11:37:41 +00:00
|
|
|
# Warn user if Pi-hole's logging is disabled
|
|
|
|
local logging_enabled=$(grep -c "^log-queries" /etc/dnsmasq.d/01-pihole.conf)
|
|
|
|
if [[ "${logging_enabled}" == "0" ]]; then
|
|
|
|
# No "log-queries" lines are found.
|
|
|
|
# Commented out lines (such as "#log-queries") are ignored
|
|
|
|
echo " ${CROSS} Warning: Query logging is disabled"
|
|
|
|
fi
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Press Ctrl-C to exit"
|
2017-09-23 01:27:40 +00:00
|
|
|
|
|
|
|
# Retrieve IPv4/6 addresses
|
|
|
|
source /etc/pihole/setupVars.conf
|
|
|
|
|
|
|
|
# Strip date from each line
|
2020-03-08 23:53:14 +00:00
|
|
|
# Color blocklist/blacklist/wildcard entries as red
|
|
|
|
# Color A/AAAA/DHCP strings as white
|
|
|
|
# Color everything else as gray
|
2017-09-23 01:27:40 +00:00
|
|
|
tail -f /var/log/pihole.log | sed -E \
|
2020-02-12 20:05:02 +00:00
|
|
|
-e "s,($(date +'%b %d ')| dnsmasq\[[0-9]*\]),,g" \
|
2020-01-23 18:18:22 +00:00
|
|
|
-e "s,(.*(blacklisted |gravity blocked ).* is (0.0.0.0|::|NXDOMAIN|${IPV4_ADDRESS%/*}|${IPV6_ADDRESS:-NULL}).*),${COL_RED}&${COL_NC}," \
|
2017-09-23 01:27:40 +00:00
|
|
|
-e "s,.*(query\\[A|DHCP).*,${COL_NC}&${COL_NC}," \
|
|
|
|
-e "s,.*,${COL_GRAY}&${COL_NC},"
|
2016-12-08 20:15:03 +00:00
|
|
|
exit 0
|
|
|
|
}
|
2016-10-20 12:45:20 +00:00
|
|
|
|
2017-03-08 12:16:40 +00:00
|
|
|
piholeCheckoutFunc() {
|
2017-05-14 02:22:19 +00:00
|
|
|
if [[ "$2" == "-h" ]] || [[ "$2" == "--help" ]]; then
|
2017-05-14 01:11:44 +00:00
|
|
|
echo "Usage: pihole checkout [repo] [branch]
|
|
|
|
Example: 'pihole checkout master' or 'pihole checkout core dev'
|
2020-05-13 10:49:00 +00:00
|
|
|
Switch Pi-hole subsystems to a different GitHub branch
|
2017-05-14 01:11:44 +00:00
|
|
|
|
|
|
|
Repositories:
|
|
|
|
core [branch] Change the branch of Pi-hole's core subsystem
|
2018-06-04 03:34:42 +00:00
|
|
|
web [branch] Change the branch of Web Interface subsystem
|
2017-07-16 12:22:59 +00:00
|
|
|
ftl [branch] Change the branch of Pi-hole's FTL subsystem
|
2017-05-14 15:17:04 +00:00
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
Branches:
|
|
|
|
master Update subsystems to the latest stable release
|
2018-06-04 03:34:42 +00:00
|
|
|
dev Update subsystems to the latest development release
|
|
|
|
branchname Update subsystems to the specified branchname"
|
2017-05-14 01:11:44 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2017-03-08 12:16:40 +00:00
|
|
|
source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh
|
2017-03-08 21:57:35 +00:00
|
|
|
shift
|
2017-03-08 12:16:40 +00:00
|
|
|
checkout "$@"
|
|
|
|
}
|
|
|
|
|
2017-05-13 19:08:21 +00:00
|
|
|
tricorderFunc() {
|
2017-05-18 02:53:32 +00:00
|
|
|
if [[ ! -p "/dev/stdin" ]]; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} Please do not call Tricorder directly"
|
2017-05-14 09:27:14 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-05-27 15:51:41 +00:00
|
|
|
|
2017-08-31 10:32:02 +00:00
|
|
|
if ! (echo > /dev/tcp/tricorder.pi-hole.net/9998) >/dev/null 2>&1; then
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${CROSS} Unable to connect to Pi-hole's Tricorder server"
|
2017-05-18 02:43:17 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-05-14 09:27:14 +00:00
|
|
|
|
2017-05-13 19:08:21 +00:00
|
|
|
if command -v openssl &> /dev/null; then
|
|
|
|
openssl s_client -quiet -connect tricorder.pi-hole.net:9998 2> /dev/null < /dev/stdin
|
2017-05-18 02:43:17 +00:00
|
|
|
exit "$?"
|
2017-05-13 19:08:21 +00:00
|
|
|
else
|
2017-06-21 11:49:05 +00:00
|
|
|
echo -e " ${INFO} ${COL_YELLOW}Security Notice${COL_NC}: ${COL_WHITE}openssl${COL_NC} is not installed
|
|
|
|
Your debug log will be transmitted unencrypted via plain-text
|
|
|
|
There is a possibility that this could be intercepted by a third party
|
|
|
|
If you wish to cancel, press Ctrl-C to exit within 10 seconds"
|
2017-05-14 09:27:14 +00:00
|
|
|
secs="10"
|
2017-05-18 02:53:32 +00:00
|
|
|
while [[ "$secs" -gt "0" ]]; do
|
2017-05-14 09:27:14 +00:00
|
|
|
echo -ne "."
|
|
|
|
sleep 1
|
|
|
|
: $((secs--))
|
|
|
|
done
|
|
|
|
echo " "
|
2017-05-15 23:48:46 +00:00
|
|
|
nc tricorder.pi-hole.net 9999 < /dev/stdin
|
2017-05-18 02:43:17 +00:00
|
|
|
exit "$?"
|
2017-05-13 19:08:21 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-10-28 11:20:02 +00:00
|
|
|
updateCheckFunc() {
|
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/updatecheck.sh "$@"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
helpFunc() {
|
2017-05-14 01:11:44 +00:00
|
|
|
echo "Usage: pihole [options]
|
|
|
|
Example: 'pihole -w -h'
|
|
|
|
Add '-h' after specific commands for more information on usage
|
2017-05-14 15:17:04 +00:00
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
Whitelist/Blacklist Options:
|
|
|
|
-w, whitelist Whitelist domain(s)
|
|
|
|
-b, blacklist Blacklist domain(s)
|
2019-08-22 11:57:01 +00:00
|
|
|
--regex, regex Regex blacklist domains(s)
|
|
|
|
--white-regex Regex whitelist domains(s)
|
|
|
|
--wild, wildcard Wildcard blacklist domain(s)
|
|
|
|
--white-wild Wildcard whitelist domain(s)
|
2017-05-14 01:11:44 +00:00
|
|
|
Add '-h' for more info on whitelist/blacklist usage
|
|
|
|
|
|
|
|
Debugging Options:
|
|
|
|
-d, debug Start a debugging session
|
|
|
|
Add '-a' to enable automated debugging
|
|
|
|
-f, flush Flush the Pi-hole log
|
|
|
|
-r, reconfigure Reconfigure or Repair Pi-hole subsystems
|
|
|
|
-t, tail View the live output of the Pi-hole log
|
|
|
|
|
|
|
|
Options:
|
2018-06-04 03:34:42 +00:00
|
|
|
-a, admin Web interface options
|
|
|
|
Add '-h' for more info on Web Interface usage
|
2017-05-14 01:11:44 +00:00
|
|
|
-c, chronometer Calculates stats and displays to an LCD
|
|
|
|
Add '-h' for more info on chronometer usage
|
|
|
|
-g, updateGravity Update the list of ad-serving domains
|
|
|
|
-h, --help, help Show this help dialog
|
|
|
|
-l, logging Specify whether the Pi-hole log should be used
|
|
|
|
Add '-h' for more info on logging usage
|
|
|
|
-q, query Query the adlists for a specified domain
|
2017-07-15 10:56:40 +00:00
|
|
|
Add '-h' for more info on query usage
|
2017-05-14 15:17:04 +00:00
|
|
|
-up, updatePihole Update Pi-hole subsystems
|
2018-04-15 17:30:13 +00:00
|
|
|
Add '--check-only' to exit script before update is performed.
|
2018-06-04 03:34:42 +00:00
|
|
|
-v, version Show installed versions of Pi-hole, Web Interface & FTL
|
2017-05-14 15:17:04 +00:00
|
|
|
Add '-h' for more info on version usage
|
2017-05-14 01:11:44 +00:00
|
|
|
uninstall Uninstall Pi-hole from your system
|
|
|
|
status Display the running status of Pi-hole subsystems
|
|
|
|
enable Enable Pi-hole subsystems
|
|
|
|
disable Disable Pi-hole subsystems
|
|
|
|
Add '-h' for more info on disable usage
|
2020-04-05 06:49:35 +00:00
|
|
|
restartdns Full restart Pi-hole subsystems
|
2020-04-05 09:44:44 +00:00
|
|
|
Add 'reload' to update the lists and flush the cache without restarting the DNS server
|
|
|
|
Add 'reload-lists' to only update the lists WITHOUT flushing the cache or restarting the DNS server
|
2020-05-13 10:49:00 +00:00
|
|
|
checkout Switch Pi-hole subsystems to a different GitHub branch
|
2019-06-15 07:06:10 +00:00
|
|
|
Add '-h' for more info on checkout usage
|
|
|
|
arpflush Flush information stored in Pi-hole's network tables";
|
2016-12-01 20:21:08 +00:00
|
|
|
exit 0
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [[ $# = 0 ]]; then
|
2016-11-02 16:36:30 +00:00
|
|
|
helpFunc
|
2016-08-26 22:10:22 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-02 22:41:04 +00:00
|
|
|
case "${1}" in
|
|
|
|
"-h" | "help" | "--help" ) helpFunc;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Must be root to use this tool
|
|
|
|
if [[ ! $EUID -eq 0 ]];then
|
|
|
|
if [[ -x "$(command -v sudo)" ]]; then
|
|
|
|
exec sudo bash "$0" "$@"
|
|
|
|
exit $?
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} sudo is needed to run pihole commands. Please run this script as root or install sudo."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-08-26 22:10:22 +00:00
|
|
|
# Handle redirecting to specific functions based on arguments
|
2016-10-22 06:17:14 +00:00
|
|
|
case "${1}" in
|
2018-07-08 18:37:33 +00:00
|
|
|
"-w" | "whitelist" ) listFunc "$@";;
|
|
|
|
"-b" | "blacklist" ) listFunc "$@";;
|
2019-05-30 19:23:15 +00:00
|
|
|
"--wild" | "wildcard" ) listFunc "$@";;
|
|
|
|
"--regex" | "regex" ) listFunc "$@";;
|
2019-08-05 19:10:52 +00:00
|
|
|
"--white-regex" | "white-regex" ) listFunc "$@";;
|
|
|
|
"--white-wild" | "white-wild" ) listFunc "$@";;
|
2017-02-26 23:36:53 +00:00
|
|
|
"-d" | "debug" ) debugFunc "$@";;
|
2017-05-17 10:44:35 +00:00
|
|
|
"-f" | "flush" ) flushFunc "$@";;
|
2018-04-15 17:25:35 +00:00
|
|
|
"-up" | "updatePihole" ) updatePiholeFunc "$@";;
|
2016-11-02 16:36:30 +00:00
|
|
|
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
|
|
|
|
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
|
|
|
"-c" | "chronometer" ) chronometerFunc "$@";;
|
|
|
|
"-h" | "help" ) helpFunc;;
|
|
|
|
"-v" | "version" ) versionFunc "$@";;
|
|
|
|
"-q" | "query" ) queryFunc "$@";;
|
|
|
|
"-l" | "logging" ) piholeLogging "$@";;
|
|
|
|
"uninstall" ) uninstallFunc;;
|
|
|
|
"enable" ) piholeEnable 1;;
|
2017-05-14 01:11:44 +00:00
|
|
|
"disable" ) piholeEnable 0 "$2";;
|
2017-08-31 07:39:41 +00:00
|
|
|
"status" ) statusFunc "$2";;
|
2017-09-14 06:39:25 +00:00
|
|
|
"restartdns" ) restartDNS "$2";;
|
2016-11-20 14:15:27 +00:00
|
|
|
"-a" | "admin" ) webpageFunc "$@";;
|
2016-12-08 20:15:03 +00:00
|
|
|
"-t" | "tail" ) tailFunc;;
|
2017-03-08 12:16:40 +00:00
|
|
|
"checkout" ) piholeCheckoutFunc "$@";;
|
2017-06-03 17:13:40 +00:00
|
|
|
"tricorder" ) tricorderFunc;;
|
2017-12-09 18:00:46 +00:00
|
|
|
"updatechecker" ) updateCheckFunc "$@";;
|
2019-05-30 19:23:15 +00:00
|
|
|
"arpflush" ) arpFunc "$@";;
|
2016-11-02 16:36:30 +00:00
|
|
|
* ) helpFunc;;
|
2016-10-15 16:25:17 +00:00
|
|
|
esac
|