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}"
|
|
|
|
|
2024-07-16 08:55:28 +00:00
|
|
|
readonly utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
|
2022-01-30 23:05:28 +00:00
|
|
|
source "${utilsfile}"
|
|
|
|
|
2024-07-16 08:55:28 +00:00
|
|
|
# Source api functions
|
|
|
|
readonly apifile="${PI_HOLE_SCRIPT_DIR}/api.sh"
|
|
|
|
source "${apifile}"
|
|
|
|
|
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
|
2023-10-28 18:46:45 +00:00
|
|
|
setFTLConfigValue "webserver.api.password" ""
|
2023-08-04 17:41:19 +00:00
|
|
|
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
|
2023-10-28 18:46:45 +00:00
|
|
|
setFTLConfigValue "webserver.api.password" "${PASSWORD}"
|
2023-08-04 17:41:19 +00:00
|
|
|
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() {
|
2023-12-09 22:09:58 +00:00
|
|
|
exec "${PI_HOLE_SCRIPT_DIR}"/version.sh
|
2016-08-26 22:10:22 +00:00
|
|
|
}
|
|
|
|
|
2024-09-24 13:15:15 +00:00
|
|
|
reloadDNS() {
|
2022-07-26 12:38:03 +00:00
|
|
|
local svcOption svc str output status pid icon FTL_PID_FILE
|
2024-10-02 18:41:17 +00:00
|
|
|
svcOption="${1:-reload}"
|
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
|
2024-07-27 19:55:18 +00:00
|
|
|
FTL_PID_FILE="$(getFTLConfigValue files.pid)"
|
2022-09-06 15:09:52 +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
|
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-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
|
2024-07-16 08:55:28 +00:00
|
|
|
echo "Usage: pihole enable/disable [time]
|
|
|
|
Example: 'pihole enable', or 'pihole disable 5m'
|
|
|
|
En- or disable Pi-hole subsystems
|
2017-05-14 01:11:44 +00:00
|
|
|
|
|
|
|
Time:
|
2024-07-16 08:55:28 +00:00
|
|
|
#s En-/disable Pi-hole functionality for # second(s)
|
|
|
|
#m En-/disable Pi-hole functionality for # minute(s)"
|
2017-05-14 01:11:44 +00:00
|
|
|
exit 0
|
2017-06-21 11:49:05 +00:00
|
|
|
|
2024-07-16 08:55:28 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Get timer
|
|
|
|
local tt="null"
|
|
|
|
if [[ $# -gt 1 ]]; then
|
|
|
|
local error=false
|
|
|
|
if [[ "${2}" == *"s" ]]; then
|
|
|
|
tt=${2%"s"}
|
|
|
|
if [[ ! "${tt}" =~ ^-?[0-9]+$ ]];then
|
2017-06-21 11:49:05 +00:00
|
|
|
local error=true
|
2016-11-17 21:58:00 +00:00
|
|
|
fi
|
2024-07-16 08:55:28 +00:00
|
|
|
elif [[ "${2}" == *"m" ]]; then
|
|
|
|
tt=${2%"m"}
|
|
|
|
if [[ "${tt}" =~ ^-?[0-9]+$ ]];then
|
|
|
|
tt=$((${tt}*60))
|
|
|
|
else
|
|
|
|
local error=true
|
2017-06-21 11:49:05 +00:00
|
|
|
fi
|
2024-07-16 08:55:28 +00:00
|
|
|
elif [[ -n "${2}" ]]; then
|
|
|
|
local error=true
|
2016-11-17 21:58:00 +00:00
|
|
|
fi
|
2024-07-16 08:55:28 +00:00
|
|
|
|
|
|
|
if [[ ${error} == true ]];then
|
|
|
|
echo -e " ${COL_LIGHT_RED}Unknown format for blocking timer!${COL_NC}"
|
|
|
|
echo -e " Try 'pihole disable --help' for more information."
|
|
|
|
exit 1
|
2019-01-24 08:16:24 +00:00
|
|
|
fi
|
2024-07-16 08:55:28 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Authenticate with the API
|
|
|
|
LoginAPI
|
|
|
|
|
|
|
|
# Send the request
|
|
|
|
data=$(PostFTLData "dns/blocking" "{ \"blocking\": ${1}, \"timer\": ${tt} }")
|
2017-07-16 12:22:59 +00:00
|
|
|
|
2024-07-16 08:55:28 +00:00
|
|
|
# Check the response
|
|
|
|
local extra=" forever"
|
|
|
|
local timer="$(echo "${data}"| jq --raw-output '.timer' )"
|
|
|
|
if [[ "${timer}" != "null" ]]; then
|
|
|
|
extra=" for ${timer}s"
|
2016-10-20 12:45:20 +00:00
|
|
|
fi
|
2024-07-16 08:55:28 +00:00
|
|
|
local str="Pi-hole $(echo "${data}" | jq --raw-output '.blocking')${extra}"
|
2017-07-16 12:22:59 +00:00
|
|
|
|
2024-07-16 08:55:28 +00:00
|
|
|
# Logout from the API
|
|
|
|
LogoutAPI
|
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
|
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-10-18 05:07:06 +00:00
|
|
|
local pid port ftl_pid_file block_status
|
2021-12-26 16:10:48 +00:00
|
|
|
|
2024-07-27 19:55:18 +00:00
|
|
|
ftl_pid_file="$(getFTLConfigValue files.pid)"
|
2022-07-26 12:38:03 +00:00
|
|
|
|
|
|
|
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
|
2024-09-02 16:59:42 +00:00
|
|
|
exit 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
|
2024-09-02 16:59:42 +00:00
|
|
|
exit 0
|
2022-07-26 12:38:03 +00:00
|
|
|
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-10-18 05:07:06 +00:00
|
|
|
block_status=$(getFTLConfigValue dns.blocking.active)
|
|
|
|
if [ ${block_status} == "true" ]; 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
|
2024-09-02 16:59:42 +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
|
2024-06-19 20:41:42 +00:00
|
|
|
local logging_enabled=$(getFTLConfigValue dns.queryLogging)
|
|
|
|
if [[ "${logging_enabled}" != "true" ]]; then
|
2018-06-17 11:37:41 +00:00
|
|
|
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
|
|
|
|
2024-06-19 20:41:42 +00:00
|
|
|
# Get logfile path
|
|
|
|
readonly LOGFILE=$(getFTLConfigValue files.log.dnsmasq)
|
|
|
|
|
2017-09-23 01:27:40 +00:00
|
|
|
# Strip date from each line
|
2024-06-22 18:48:07 +00:00
|
|
|
# Color blocklist/denylist/wildcard entries as red
|
2020-03-08 23:53:14 +00:00
|
|
|
# Color A/AAAA/DHCP strings as white
|
|
|
|
# Color everything else as gray
|
2024-06-19 20:41:42 +00:00
|
|
|
tail -f $LOGFILE | grep --line-buffered "${1}" | sed -E \
|
2020-02-12 20:05:02 +00:00
|
|
|
-e "s,($(date +'%b %d ')| dnsmasq\[[0-9]*\]),,g" \
|
2024-06-22 18:48:07 +00:00
|
|
|
-e "s,(.*(denied |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
|
2024-08-22 19:22:52 +00:00
|
|
|
echo "Switch Pi-hole subsystems to a different GitHub branch
|
|
|
|
Usage: ${COL_GREEN}pihole checkout${COL_NC} ${COL_YELLOW}shortcut${COL_NC}
|
|
|
|
or ${COL_GREEN}pihole checkout${COL_NC} ${COL_PURPLE}repo${COL_NC} ${COL_CYAN}branch${COL_NC}
|
2024-08-26 04:11:42 +00:00
|
|
|
|
2024-08-22 19:22:52 +00:00
|
|
|
Example: ${COL_GREEN}pihole checkout${COL_NC} ${COL_YELLOW}master${COL_NC}
|
|
|
|
or ${COL_GREEN}pihole checkout${COL_NC} ${COL_PURPLE}ftl ${COL_CYAN}development${COL_NC}
|
|
|
|
|
|
|
|
Shortcuts:
|
|
|
|
${COL_YELLOW}master${COL_NC} Update all subsystems to the latest stable release
|
|
|
|
${COL_YELLOW}dev${COL_NC} Update all subsystems to the latest development release
|
|
|
|
|
|
|
|
Individual components:
|
|
|
|
${COL_PURPLE}core${COL_NC} ${COL_CYAN}branch${COL_NC} Change the branch of Pi-hole's core subsystem
|
|
|
|
${COL_PURPLE}web${COL_NC} ${COL_CYAN}branch${COL_NC} Change the branch of the web interface subsystem
|
|
|
|
${COL_PURPLE}ftl${COL_NC} ${COL_CYAN}branch${COL_NC} Change the branch of Pi-hole's FTL subsystem"
|
|
|
|
|
2023-10-08 12:23:44 +00:00
|
|
|
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]
|
2024-06-25 11:56:49 +00:00
|
|
|
Example: 'pihole allow -h'
|
2017-05-14 01:11:44 +00:00
|
|
|
Add '-h' after specific commands for more information on usage
|
2017-05-14 15:17:04 +00:00
|
|
|
|
2024-06-22 18:35:06 +00:00
|
|
|
Domain Options:
|
2024-06-25 11:56:49 +00:00
|
|
|
allow, allowlist Allow domain(s)
|
|
|
|
deny, denylist Deny domain(s)
|
|
|
|
--regex, regex Regex deny domains(s)
|
|
|
|
--allow-regex Regex allow domains(s)
|
|
|
|
--wild, wildcard Wildcard deny domain(s)
|
|
|
|
--allow-wild Wildcard allow domain(s)
|
|
|
|
Add '-h' for more info on allow/deny usage
|
2017-05-14 01:11:44 +00:00
|
|
|
|
|
|
|
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)
|
2024-08-26 17:44:42 +00:00
|
|
|
api <endpoint> Query the Pi-hole API at <endpoint>
|
2021-06-04 19:59:17 +00:00
|
|
|
|
2017-05-14 01:11:44 +00:00
|
|
|
|
|
|
|
Options:
|
2023-11-05 20:15:13 +00:00
|
|
|
setpassword [pwd] Set the password for the web interface
|
|
|
|
Without optional argument, password is read interactively.
|
|
|
|
When specifying a password directly, enclose it in single quotes.
|
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 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
|
2024-09-24 13:15:15 +00:00
|
|
|
reloaddns Update the lists and flush the cache without restarting the DNS server
|
2024-10-02 20:19:39 +00:00
|
|
|
reloadlists 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
|
2024-10-02 20:19:39 +00:00
|
|
|
"-h" | "help" | "--help" ) helpFunc;;
|
|
|
|
"-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
|
2024-10-02 20:19:39 +00:00
|
|
|
"allow" | "allowlist" ) need_root=0;;
|
|
|
|
"deny" | "denylist" ) need_root=0;;
|
|
|
|
"--wild" | "wildcard" ) need_root=0;;
|
|
|
|
"--regex" | "regex" ) need_root=0;;
|
2024-06-19 21:04:39 +00:00
|
|
|
"--allow-regex" | "allow-regex" ) need_root=0;;
|
|
|
|
"--allow-wild" | "allow-wild" ) need_root=0;;
|
2024-10-02 20:19:39 +00:00
|
|
|
"-f" | "flush" ) ;;
|
|
|
|
"-up" | "updatePihole" ) ;;
|
|
|
|
"-r" | "reconfigure" ) ;;
|
|
|
|
"-l" | "logging" ) ;;
|
|
|
|
"uninstall" ) ;;
|
|
|
|
"enable" ) need_root=0;;
|
|
|
|
"disable" ) need_root=0;;
|
|
|
|
"-d" | "debug" ) ;;
|
|
|
|
"-g" | "updateGravity" ) ;;
|
|
|
|
"reloaddns" ) ;;
|
|
|
|
"reloadlists" ) ;;
|
|
|
|
"setpassword" ) ;;
|
|
|
|
"checkout" ) ;;
|
|
|
|
"updatechecker" ) ;;
|
|
|
|
"arpflush" ) ;;
|
|
|
|
"-t" | "tail" ) ;;
|
|
|
|
"api" ) need_root=0;;
|
|
|
|
* ) helpFunc;;
|
2019-01-02 22:41:04 +00:00
|
|
|
esac
|
|
|
|
|
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
|
|
|
|
|
2024-06-22 18:41:19 +00:00
|
|
|
# Check if the current user is neither root nor pihole and if the command
|
|
|
|
# requires root. If so, exit with an error message.
|
|
|
|
if [[ $EUID -ne 0 && ${USER} != "pihole" && need_root -eq 1 ]];then
|
|
|
|
echo -e " ${CROSS} The Pi-hole command requires root privileges, try:"
|
2024-06-22 18:49:44 +00:00
|
|
|
echo -e " ${COL_GREEN}sudo pihole $*${COL_NC}"
|
2024-06-22 18:41:19 +00:00
|
|
|
exit 1
|
2023-01-24 18:51:01 +00:00
|
|
|
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
|
2024-10-02 20:19:39 +00:00
|
|
|
"allow" | "allowlist" ) listFunc "$@";;
|
|
|
|
"deny" | "denylist" ) listFunc "$@";;
|
|
|
|
"--wild" | "wildcard" ) listFunc "$@";;
|
|
|
|
"--regex" | "regex" ) listFunc "$@";;
|
2024-06-19 21:04:39 +00:00
|
|
|
"--allow-regex" | "allow-regex" ) listFunc "$@";;
|
|
|
|
"--allow-wild" | "allow-wild" ) listFunc "$@";;
|
2024-10-02 20:19:39 +00:00
|
|
|
"-d" | "debug" ) debugFunc "$@";;
|
|
|
|
"-f" | "flush" ) flushFunc "$@";;
|
|
|
|
"-up" | "updatePihole" ) updatePiholeFunc "$@";;
|
|
|
|
"-r" | "reconfigure" ) reconfigurePiholeFunc;;
|
|
|
|
"-g" | "updateGravity" ) updateGravityFunc "$@";;
|
|
|
|
"-l" | "logging" ) piholeLogging "$@";;
|
|
|
|
"uninstall" ) uninstallFunc;;
|
|
|
|
"enable" ) piholeEnable true "$2";;
|
|
|
|
"disable" ) piholeEnable false "$2";;
|
|
|
|
"reloaddns" ) reloadDNS "reload";;
|
|
|
|
"reloadlists" ) reloadDNS "reload-lists";;
|
|
|
|
"setpassword" ) SetWebPassword "$@";;
|
|
|
|
"checkout" ) piholeCheckoutFunc "$@";;
|
|
|
|
"updatechecker" ) shift; updateCheckFunc "$@";;
|
|
|
|
"arpflush" ) arpFunc "$@";;
|
|
|
|
"-t" | "tail" ) tailFunc "$2";;
|
|
|
|
"api" ) apiFunc "$2";;
|
|
|
|
* ) helpFunc;;
|
2016-10-15 16:25:17 +00:00
|
|
|
esac
|