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
|
|
|
|
2023-02-05 16:40:38 +00:00
|
|
|
# PI_HOLE_BIN_DIR is not readonly here because in some functions (checkout),
|
2019-09-16 12:46:09 +00:00
|
|
|
# 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.
|
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}"
|
|
|
|
|
2022-04-12 16:13:50 +00:00
|
|
|
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
2022-01-30 23:05:28 +00:00
|
|
|
source "${utilsfile}"
|
|
|
|
|
2022-12-11 11:39:11 +00:00
|
|
|
versionsfile="/etc/pihole/versions"
|
2023-02-02 10:58:58 +00:00
|
|
|
if [ -f "${versionsfile}" ]; then
|
|
|
|
# Only source versionsfile if the file exits
|
|
|
|
# fixes a warning during installation where versionsfile does not exist yet
|
|
|
|
# but gravity calls `pihole -status` and thereby sourcing the file
|
|
|
|
source "${versionsfile}"
|
|
|
|
fi
|
2022-12-11 11:39:11 +00:00
|
|
|
|
2023-08-04 17:41:19 +00:00
|
|
|
# TODO: We can probably remove the reliance on this function too, just tell people to pihole-FTL --config webserver.api.password "password"
|
|
|
|
SetWebPassword() {
|
|
|
|
if [ -n "$2" ] ; then
|
|
|
|
readonly PASSWORD="$2"
|
|
|
|
readonly CONFIRM="${PASSWORD}"
|
|
|
|
else
|
|
|
|
# Prevents a bug if the user presses Ctrl+C and it continues to hide the text typed.
|
|
|
|
# So we reset the terminal via stty if the user does press Ctrl+C
|
|
|
|
trap '{ echo -e "\nNot changed" ; stty sane ; exit 1; }' INT
|
|
|
|
read -s -r -p "Enter New Password (Blank for no password): " PASSWORD
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
if [ "${PASSWORD}" == "" ]; then
|
|
|
|
setFTLConfigValue "webserver.api.pwhash" "" >/dev/null
|
|
|
|
echo -e " ${TICK} Password Removed"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
read -s -r -p "Confirm Password: " CONFIRM
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${PASSWORD}" == "${CONFIRM}" ] ; then
|
|
|
|
# pihole-FTL will automatically hash the password
|
|
|
|
setFTLConfigValue "webserver.api.password" "${PASSWORD}" >/dev/null
|
|
|
|
echo -e " ${TICK} New password set"
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} Passwords don't match. Your password has not been changed"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-11-16 20:34:43 +00:00
|
|
|
}
|
|
|
|
|
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() {
|
2022-05-29 07:51:33 +00:00
|
|
|
local automated
|
|
|
|
local web
|
|
|
|
local check_database_integrity
|
|
|
|
# Pull off the `debug` leaving passed call augmentation flags in $1
|
|
|
|
shift
|
|
|
|
|
|
|
|
for value in "$@"; do
|
|
|
|
[[ "$value" == *"-a"* ]] && automated="true"
|
|
|
|
[[ "$value" == *"-w"* ]] && web="true"
|
|
|
|
[[ "$value" == *"-c"* ]] && check_database_integrity="true"
|
|
|
|
[[ "$value" == *"--check_database"* ]] && check_database_integrity="true"
|
|
|
|
done
|
|
|
|
|
|
|
|
AUTOMATED=${automated:-} WEBCALL=${web:-} CHECK_DATABASE=${check_database_integrity:-} "${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() {
|
2022-12-11 11:39:11 +00:00
|
|
|
if [ -n "${DOCKER_VERSION}" ]; then
|
|
|
|
unsupportedFunc
|
|
|
|
else
|
|
|
|
shift
|
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/update.sh "$@"
|
|
|
|
exit 0
|
|
|
|
fi
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
reconfigurePiholeFunc() {
|
2022-12-11 11:39:11 +00:00
|
|
|
if [ -n "${DOCKER_VERSION}" ]; then
|
|
|
|
unsupportedFunc
|
|
|
|
else
|
|
|
|
/etc/.pihole/automated\ install/basic-install.sh --reconfigure
|
|
|
|
exit 0;
|
|
|
|
fi
|
2016-10-15 16:07:08 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 16:25:17 +00:00
|
|
|
updateGravityFunc() {
|
2021-12-04 09:50:21 +00:00
|
|
|
exec "${PI_HOLE_SCRIPT_DIR}"/gravity.sh "$@"
|
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() {
|
2023-10-12 11:44:51 +00:00
|
|
|
echo "Chronometer is gone, use PADD (https://github.com/pi-hole/PADD)"
|
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() {
|
2022-12-11 11:39:11 +00:00
|
|
|
if [ -n "${DOCKER_VERSION}" ]; then
|
|
|
|
unsupportedFunc
|
|
|
|
else
|
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/uninstall.sh
|
|
|
|
exit 0
|
|
|
|
fi
|
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
|
2021-12-02 20:46:11 +00:00
|
|
|
exec "${PI_HOLE_SCRIPT_DIR}"/version.sh "$@"
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 12:45:20 +00:00
|
|
|
restartDNS() {
|
2022-07-26 12:38:03 +00:00
|
|
|
local svcOption svc str output status pid icon FTL_PID_FILE
|
2019-08-14 18:58:18 +00:00
|
|
|
svcOption="${1:-restart}"
|
2017-07-24 11:25:04 +00:00
|
|
|
|
2022-09-06 15:09:52 +00:00
|
|
|
# get the current path to the pihole-FTL.pid
|
|
|
|
FTL_PID_FILE="$(getFTLPIDFile)"
|
|
|
|
|
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
|
2020-07-21 19:13:40 +00:00
|
|
|
# Note 1: This will NOT re-read any *.conf files
|
2019-12-11 21:47:46 +00:00
|
|
|
# Note 2: We cannot use killall here as it does
|
|
|
|
# not know about real-time signals
|
2022-07-26 12:38:03 +00:00
|
|
|
|
|
|
|
pid="$(getFTLPID ${FTL_PID_FILE})"
|
2021-04-14 16:33:10 +00:00
|
|
|
if [[ "$pid" -eq "-1" ]]; then
|
|
|
|
svc="true"
|
|
|
|
str="FTL is not running"
|
|
|
|
icon="${INFO}"
|
|
|
|
else
|
|
|
|
svc="kill -RTMIN ${pid}"
|
|
|
|
str="Reloading DNS lists"
|
|
|
|
icon="${TICK}"
|
|
|
|
fi
|
2019-12-11 21:47:46 +00:00
|
|
|
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
|
2022-07-26 12:38:03 +00:00
|
|
|
pid="$(getFTLPID ${FTL_PID_FILE})"
|
2021-04-14 16:33:10 +00:00
|
|
|
if [[ "$pid" -eq "-1" ]]; then
|
|
|
|
svc="true"
|
|
|
|
str="FTL is not running"
|
|
|
|
icon="${INFO}"
|
|
|
|
else
|
|
|
|
svc="kill -HUP ${pid}"
|
|
|
|
str="Flushing DNS cache"
|
|
|
|
icon="${TICK}"
|
|
|
|
fi
|
2017-10-19 06:51:20 +00:00
|
|
|
else
|
2019-08-14 18:58:18 +00:00
|
|
|
# A full restart has been requested
|
2020-07-21 19:13:40 +00:00
|
|
|
svc="service pihole-FTL restart"
|
2019-12-11 21:47:46 +00:00
|
|
|
str="Restarting DNS server"
|
2021-04-14 16:33:10 +00:00
|
|
|
icon="${TICK}"
|
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
|
2021-04-14 16:33:10 +00:00
|
|
|
[[ -t 1 ]] && echo -e "${OVER} ${icon} ${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
|
2023-02-05 16:40:38 +00:00
|
|
|
if ! getFTLConfigValue dns.blocking.active; then
|
2019-01-24 08:16:24 +00:00
|
|
|
echo -e " ${INFO} Blocking already disabled, nothing to do"
|
|
|
|
exit 0
|
|
|
|
fi
|
2023-06-04 19:21:48 +00:00
|
|
|
if [[ $# -gt 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"
|
2023-02-05 16:40:38 +00:00
|
|
|
setFTLConfigValue dns.blocking.active false
|
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
|
2023-02-05 16:40:38 +00:00
|
|
|
if getFTLConfigValue dns.blocking.active; then
|
2019-01-24 08:16:24 +00:00
|
|
|
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
|
|
|
|
2023-02-05 16:40:38 +00:00
|
|
|
setFTLConfigValue dns.blocking.active true
|
2016-10-20 12:45:20 +00:00
|
|
|
fi
|
2017-07-16 12:22:59 +00:00
|
|
|
|
2021-08-06 18:51:48 +00:00
|
|
|
restartDNS reload-lists
|
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:
|
2020-09-05 13:15:03 +00:00
|
|
|
on Enable the Pi-hole log at /var/log/pihole/pihole.log
|
|
|
|
off Disable and flush the Pi-hole log at /var/log/pihole/pihole.log
|
|
|
|
off noflush Disable the Pi-hole log at /var/log/pihole/pihole.log"
|
2017-05-14 01:11:44 +00:00
|
|
|
exit 0
|
|
|
|
elif [[ "${1}" == "off" ]]; then
|
|
|
|
# Disable logging
|
2023-02-05 16:40:38 +00:00
|
|
|
setFTLConfigValue dns.queryLogging false
|
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
|
2023-02-05 16:40:38 +00:00
|
|
|
setFTLConfigValue dns.queryLogging true
|
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() {
|
2022-01-05 16:41:46 +00:00
|
|
|
local lv4 lv6 port=${1}
|
2020-07-01 16:39:09 +00:00
|
|
|
# FTL is listening at least on at least one port when this
|
|
|
|
# function is getting called
|
2020-07-01 16:49:31 +00:00
|
|
|
# Check individual address family/protocol combinations
|
|
|
|
# For a healthy Pi-hole, they should all be up (nothing printed)
|
2022-01-05 16:41:46 +00:00
|
|
|
lv4="$(ss --ipv4 --listening --numeric --tcp --udp src :${port})"
|
|
|
|
if grep -q "udp " <<< "${lv4}"; then
|
2020-07-01 16:49:31 +00:00
|
|
|
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
|
2022-01-05 16:41:46 +00:00
|
|
|
if grep -q "tcp " <<< "${lv4}"; then
|
2020-07-01 16:49:31 +00:00
|
|
|
echo -e " ${TICK} TCP (IPv4)"
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} TCP (IPv4)"
|
|
|
|
fi
|
2022-01-05 16:41:46 +00:00
|
|
|
lv6="$(ss --ipv6 --listening --numeric --tcp --udp src :${port})"
|
|
|
|
if grep -q "udp " <<< "${lv6}"; then
|
2020-07-01 16:49:31 +00:00
|
|
|
echo -e " ${TICK} UDP (IPv6)"
|
|
|
|
else
|
|
|
|
echo -e " ${CROSS} UDP (IPv6)"
|
|
|
|
fi
|
2022-01-05 16:41:46 +00:00
|
|
|
if grep -q "tcp " <<< "${lv6}"; then
|
2020-07-01 16:49:31 +00:00
|
|
|
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() {
|
2022-07-26 12:38:03 +00:00
|
|
|
# Determine if there is pihole-FTL service is listening
|
2023-02-24 20:31:35 +00:00
|
|
|
local pid port ftl_pid_file
|
2021-12-26 16:10:48 +00:00
|
|
|
|
2022-07-26 12:38:03 +00:00
|
|
|
ftl_pid_file="$(getFTLPIDFile)"
|
|
|
|
|
|
|
|
pid="$(getFTLPID ${ftl_pid_file})"
|
|
|
|
|
|
|
|
if [[ "$pid" -eq "-1" ]]; then
|
|
|
|
case "${1}" in
|
|
|
|
"web") echo "-1";;
|
|
|
|
*) echo -e " ${CROSS} DNS service is NOT running";;
|
|
|
|
esac
|
|
|
|
return 0
|
2021-12-28 12:39:45 +00:00
|
|
|
else
|
2023-02-24 20:31:35 +00:00
|
|
|
# get the DNS port pihole-FTL is listening on
|
|
|
|
port="$(getFTLConfigValue dns.port)"
|
2022-07-26 12:38:03 +00:00
|
|
|
if [[ "${port}" == "0" ]]; then
|
|
|
|
case "${1}" in
|
|
|
|
"web") echo "-1";;
|
|
|
|
*) echo -e " ${CROSS} DNS service is NOT listening";;
|
|
|
|
esac
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
if [[ "${1}" != "web" ]]; then
|
|
|
|
echo -e " ${TICK} FTL is listening on port ${port}"
|
|
|
|
analyze_ports "${port}"
|
|
|
|
fi
|
|
|
|
fi
|
2021-12-28 11:11:46 +00:00
|
|
|
fi
|
2021-12-28 12:39:45 +00:00
|
|
|
|
2021-12-28 11:11:46 +00:00
|
|
|
# Determine if Pi-hole's blocking is enabled
|
2023-02-05 16:40:38 +00:00
|
|
|
if getFTLConfigValue dns.blocking.active; then
|
2021-12-28 11:11:46 +00:00
|
|
|
case "${1}" in
|
|
|
|
"web") echo "$port";;
|
2021-12-28 18:52:11 +00:00
|
|
|
*) echo -e " ${TICK} Pi-hole blocking is enabled";;
|
2021-12-28 11:11:46 +00:00
|
|
|
esac
|
|
|
|
else
|
|
|
|
case "${1}" in
|
2023-02-05 16:40:38 +00:00
|
|
|
"web") echo 0;;
|
|
|
|
*) echo -e " ${CROSS} Pi-hole blocking is disabled";;
|
2021-12-28 11:11:46 +00:00
|
|
|
esac
|
|
|
|
fi
|
2022-03-30 20:40:14 +00:00
|
|
|
exit 0
|
2016-10-20 12:45:20 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
# 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
|
2020-09-05 13:15:03 +00:00
|
|
|
tail -f /var/log/pihole/pihole.log | grep --line-buffered "${1}" | sed -E \
|
2020-02-12 20:05:02 +00:00
|
|
|
-e "s,($(date +'%b %d ')| dnsmasq\[[0-9]*\]),,g" \
|
2021-07-16 19:52:12 +00:00
|
|
|
-e "s,(.*(blacklisted |gravity blocked ).*),${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() {
|
2023-10-08 12:23:44 +00:00
|
|
|
if [ -n "${DOCKER_VERSION}" ]; then
|
|
|
|
unsupportedFunc
|
|
|
|
else
|
|
|
|
if [[ "$2" == "-h" ]] || [[ "$2" == "--help" ]]; then
|
|
|
|
echo "Usage: pihole checkout [repo] [branch]
|
|
|
|
Example: 'pihole checkout master' or 'pihole checkout core dev'
|
|
|
|
Switch Pi-hole subsystems to a different GitHub branch
|
|
|
|
|
|
|
|
Repositories:
|
|
|
|
core [branch] Change the branch of Pi-hole's core subsystem
|
|
|
|
web [branch] Change the branch of Web Interface subsystem
|
|
|
|
ftl [branch] Change the branch of Pi-hole's FTL subsystem
|
|
|
|
|
|
|
|
Branches:
|
|
|
|
master Update subsystems to the latest stable release
|
|
|
|
dev Update subsystems to the latest development release
|
|
|
|
branchname Update subsystems to the specified branchname"
|
|
|
|
exit 0
|
|
|
|
fi
|
2017-05-14 01:11:44 +00:00
|
|
|
|
2023-10-08 12:23:44 +00:00
|
|
|
source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh
|
|
|
|
shift
|
|
|
|
checkout "$@"
|
|
|
|
fi
|
2017-03-08 12:16:40 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 19:08:21 +00:00
|
|
|
tricorderFunc() {
|
2021-08-30 13:55:42 +00:00
|
|
|
local tricorder_token
|
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
|
|
|
|
2021-09-07 09:15:36 +00:00
|
|
|
tricorder_token=$(curl --silent --fail --show-error --upload-file "-" https://tricorder.pi-hole.net/upload < /dev/stdin 2>&1)
|
|
|
|
if [[ "${tricorder_token}" != "https://tricorder.pi-hole.net/"* ]]; then
|
|
|
|
echo -e "${CROSS} uploading failed, contact Pi-hole support for assistance."
|
|
|
|
# Log curl error (if available)
|
2021-09-07 09:20:42 +00:00
|
|
|
if [ -n "${tricorder_token}" ]; then
|
2021-09-07 09:15:36 +00:00
|
|
|
echo -e "${INFO} Error message: ${COL_RED}${tricorder_token}${COL_NC}\\n"
|
|
|
|
tricorder_token=""
|
|
|
|
fi
|
|
|
|
exit 1
|
2021-08-30 13:55:42 +00:00
|
|
|
fi
|
2021-09-07 09:15:36 +00:00
|
|
|
echo "Upload successful, your token is: ${COL_GREEN}${tricorder_token}${COL_NC}"
|
2021-08-30 13:55:42 +00:00
|
|
|
exit 0
|
2017-05-13 19:08:21 +00:00
|
|
|
}
|
|
|
|
|
2017-10-28 11:20:02 +00:00
|
|
|
updateCheckFunc() {
|
2022-11-23 18:33:49 +00:00
|
|
|
"${PI_HOLE_SCRIPT_DIR}"/updatecheck.sh "$@"
|
2017-10-28 11:20:02 +00:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2022-12-11 11:39:11 +00:00
|
|
|
unsupportedFunc(){
|
|
|
|
echo "Function not supported in Docker images"
|
|
|
|
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
|
2022-05-29 07:51:33 +00:00
|
|
|
Add '-c' or '--check-database' to include a Pi-hole database integrity check
|
2020-11-15 19:31:47 +00:00
|
|
|
Add '-a' to automatically upload the log to tricorder.pi-hole.net
|
2017-05-14 01:11:44 +00:00
|
|
|
-f, flush Flush the Pi-hole log
|
|
|
|
-r, reconfigure Reconfigure or Repair Pi-hole subsystems
|
2021-06-04 19:59:17 +00:00
|
|
|
-t, tail [arg] View the live output of the Pi-hole log.
|
|
|
|
Add an optional argument to filter the log
|
|
|
|
(regular expressions are supported)
|
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
|
|
|
|
Options:
|
2023-08-04 17:41:19 +00:00
|
|
|
setpassword set the password for the web interface
|
2017-05-14 01:11:44 +00:00
|
|
|
-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
|
|
|
|
|
2022-04-03 11:49:43 +00:00
|
|
|
# functions that do not require sudo power
|
2023-01-24 18:51:01 +00:00
|
|
|
need_root=1
|
2019-01-02 22:41:04 +00:00
|
|
|
case "${1}" in
|
|
|
|
"-h" | "help" | "--help" ) helpFunc;;
|
2022-03-30 19:04:36 +00:00
|
|
|
"-v" | "version" ) versionFunc "$@";;
|
|
|
|
"-c" | "chronometer" ) chronometerFunc "$@";;
|
|
|
|
"-q" | "query" ) queryFunc "$@";;
|
|
|
|
"status" ) statusFunc "$2";;
|
|
|
|
"tricorder" ) tricorderFunc;;
|
2022-03-30 19:24:51 +00:00
|
|
|
|
|
|
|
# we need to add all arguments that require sudo power to not trigger the * argument
|
|
|
|
"-w" | "whitelist" ) ;;
|
|
|
|
"-b" | "blacklist" ) ;;
|
|
|
|
"--wild" | "wildcard" ) ;;
|
|
|
|
"--regex" | "regex" ) ;;
|
|
|
|
"--white-regex" | "white-regex" ) ;;
|
|
|
|
"--white-wild" | "white-wild" ) ;;
|
|
|
|
"-f" | "flush" ) ;;
|
|
|
|
"-up" | "updatePihole" ) ;;
|
|
|
|
"-r" | "reconfigure" ) ;;
|
|
|
|
"-l" | "logging" ) ;;
|
|
|
|
"uninstall" ) ;;
|
|
|
|
"enable" ) ;;
|
|
|
|
"disable" ) ;;
|
|
|
|
"-d" | "debug" ) ;;
|
|
|
|
"restartdns" ) ;;
|
2023-01-24 18:51:01 +00:00
|
|
|
"-g" | "updateGravity" ) need_root=0;;
|
|
|
|
"reloaddns" ) need_root=0;;
|
2023-08-04 17:41:19 +00:00
|
|
|
"setpassword" ) ;;
|
2022-03-30 19:24:51 +00:00
|
|
|
"checkout" ) ;;
|
|
|
|
"updatechecker" ) ;;
|
|
|
|
"arpflush" ) ;;
|
2022-06-19 21:25:53 +00:00
|
|
|
"-t" | "tail" ) ;;
|
2022-03-30 19:04:36 +00:00
|
|
|
* ) helpFunc;;
|
2019-01-02 22:41:04 +00:00
|
|
|
esac
|
|
|
|
|
2023-01-24 18:51:01 +00:00
|
|
|
# Must be root to use this tool for most functions
|
|
|
|
if [[ ! $EUID -eq 0 && need_root -eq 1 ]];then
|
2019-01-02 22:41:04 +00:00
|
|
|
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
|
2023-07-17 20:44:13 +00:00
|
|
|
|
|
|
|
# In the case of alpine running in a container, the USER variable appears to be blank
|
|
|
|
# which prevents the next trap from working correctly. Set it by running whoami
|
|
|
|
if [[ -z ${USER} ]]; then
|
|
|
|
USER=$(whoami)
|
|
|
|
fi
|
|
|
|
|
2023-01-24 18:51:01 +00:00
|
|
|
# Can also be user pihole for other functions
|
|
|
|
if [[ ${USER} != "pihole" && need_root -eq 0 ]];then
|
|
|
|
if [[ -x "$(command -v sudo)" ]]; then
|
|
|
|
exec sudo -u pihole 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
|
2019-01-02 22:41:04 +00:00
|
|
|
|
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 "$@";;
|
|
|
|
"-l" | "logging" ) piholeLogging "$@";;
|
|
|
|
"uninstall" ) uninstallFunc;;
|
|
|
|
"enable" ) piholeEnable 1;;
|
2017-05-14 01:11:44 +00:00
|
|
|
"disable" ) piholeEnable 0 "$2";;
|
2017-09-14 06:39:25 +00:00
|
|
|
"restartdns" ) restartDNS "$2";;
|
2023-01-24 18:51:01 +00:00
|
|
|
"reloaddns" ) restartDNS "reload";;
|
2023-08-04 17:41:19 +00:00
|
|
|
"setpassword" ) SetWebPassword "$@";;
|
2017-03-08 12:16:40 +00:00
|
|
|
"checkout" ) piholeCheckoutFunc "$@";;
|
2022-11-23 18:33:49 +00:00
|
|
|
"updatechecker" ) shift; updateCheckFunc "$@";;
|
2019-05-30 19:23:15 +00:00
|
|
|
"arpflush" ) arpFunc "$@";;
|
2022-06-19 21:25:53 +00:00
|
|
|
"-t" | "tail" ) tailFunc "$2";;
|
2016-10-15 16:25:17 +00:00
|
|
|
esac
|