mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-22 06:03:43 +00:00
Improve pihole -f
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
25f384a923
commit
5dfcd02c40
2 changed files with 64 additions and 23 deletions
|
@ -21,7 +21,7 @@
|
||||||
TestAPIAvailability() {
|
TestAPIAvailability() {
|
||||||
|
|
||||||
# as we are running locally, we can get the port value from FTL directly
|
# as we are running locally, we can get the port value from FTL directly
|
||||||
local chaos_api_list availabilityResonse
|
local chaos_api_list availabilityResponse
|
||||||
|
|
||||||
# Query the API URLs from FTL using CHAOS TXT local.api.ftl
|
# Query the API URLs from FTL using CHAOS TXT local.api.ftl
|
||||||
# The result is a space-separated enumeration of full URLs
|
# The result is a space-separated enumeration of full URLs
|
||||||
|
@ -43,16 +43,16 @@ TestAPIAvailability() {
|
||||||
API_URL="${API_URL#\"}"
|
API_URL="${API_URL#\"}"
|
||||||
|
|
||||||
# Test if the API is available at this URL
|
# Test if the API is available at this URL
|
||||||
availabilityResonse=$(curl -skS -o /dev/null -w "%{http_code}" "${API_URL}auth")
|
availabilityResponse=$(curl -skS -o /dev/null -w "%{http_code}" "${API_URL}auth")
|
||||||
|
|
||||||
# Test if http status code was 200 (OK) or 401 (authentication required)
|
# Test if http status code was 200 (OK) or 401 (authentication required)
|
||||||
if [ ! "${availabilityResonse}" = 200 ] && [ ! "${availabilityResonse}" = 401 ]; then
|
if [ ! "${availabilityResponse}" = 200 ] && [ ! "${availabilityResponse}" = 401 ]; then
|
||||||
# API is not available at this port/protocol combination
|
# API is not available at this port/protocol combination
|
||||||
API_PORT=""
|
API_PORT=""
|
||||||
else
|
else
|
||||||
# API is available at this URL combination
|
# API is available at this URL combination
|
||||||
|
|
||||||
if [ "${availabilityResonse}" = 200 ]; then
|
if [ "${availabilityResponse}" = 200 ]; then
|
||||||
# API is available without authentication
|
# API is available without authentication
|
||||||
needAuth=false
|
needAuth=false
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -29,16 +29,21 @@ fi
|
||||||
# Determine log file location
|
# Determine log file location
|
||||||
LOGFILE=$(getFTLConfigValue "files.log.dnsmasq")
|
LOGFILE=$(getFTLConfigValue "files.log.dnsmasq")
|
||||||
if [ -z "$LOGFILE" ]; then
|
if [ -z "$LOGFILE" ]; then
|
||||||
LOGFILE="/var/log/pihole.log"
|
LOGFILE="/var/log/pihole/pihole.log"
|
||||||
|
fi
|
||||||
|
FTLFILE=$(getFTLConfigValue "files.log.ftl")
|
||||||
|
if [ -z "$FTLFILE" ]; then
|
||||||
|
FTLFILE="/var/log/pihole/FTL.log"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$*" != *"quiet"* ]]; then
|
|
||||||
echo -ne " ${INFO} Flushing "${LOGFILE}" ..."
|
|
||||||
fi
|
|
||||||
if [[ "$*" == *"once"* ]]; then
|
if [[ "$*" == *"once"* ]]; then
|
||||||
# Nightly logrotation
|
# Nightly logrotation
|
||||||
if command -v /usr/sbin/logrotate >/dev/null; then
|
if command -v /usr/sbin/logrotate >/dev/null; then
|
||||||
# Logrotate once
|
# Logrotate once
|
||||||
|
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -ne " ${INFO} Running logrotate ..."
|
||||||
|
fi
|
||||||
/usr/sbin/logrotate --force --state "${STATEFILE}" /etc/pihole/logrotate
|
/usr/sbin/logrotate --force --state "${STATEFILE}" /etc/pihole/logrotate
|
||||||
else
|
else
|
||||||
# Copy pihole.log over to pihole.log.1
|
# Copy pihole.log over to pihole.log.1
|
||||||
|
@ -46,23 +51,60 @@ if [[ "$*" == *"once"* ]]; then
|
||||||
# Note that moving the file is not an option, as
|
# Note that moving the file is not an option, as
|
||||||
# dnsmasq would happily continue writing into the
|
# dnsmasq would happily continue writing into the
|
||||||
# moved file (it will have the same file handler)
|
# moved file (it will have the same file handler)
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -ne " ${INFO} Rotating ${LOGFILE} ..."
|
||||||
|
fi
|
||||||
cp -p "${LOGFILE}" "${LOGFILE}.1"
|
cp -p "${LOGFILE}" "${LOGFILE}.1"
|
||||||
echo " " > "${LOGFILE}"
|
echo " " > "${LOGFILE}"
|
||||||
chmod 640 "${LOGFILE}"
|
chmod 640 "${LOGFILE}"
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -e "${OVER} ${TICK} Rotated ${LOGFILE} ..."
|
||||||
|
fi
|
||||||
|
# Copy FTL.log over to FTL.log.1
|
||||||
|
# and empty out FTL.log
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -ne " ${INFO} Rotating ${FTLFILE} ..."
|
||||||
|
fi
|
||||||
|
cp -p "${FTLFILE}" "${FTLFILE}.1"
|
||||||
|
echo " " > "${FTLFILE}"
|
||||||
|
chmod 640 "${FTLFILE}"
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -e "${OVER} ${TICK} Rotated ${FTLFILE} ..."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Manual flushing
|
# Manual flushing
|
||||||
if command -v /usr/sbin/logrotate >/dev/null; then
|
|
||||||
# Logrotate twice to move all data out of sight of FTL
|
# Flush both pihole.log and pihole.log.1 (if existing)
|
||||||
/usr/sbin/logrotate --force --state "${STATEFILE}" /etc/pihole/logrotate; sleep 3
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
/usr/sbin/logrotate --force --state "${STATEFILE}" /etc/pihole/logrotate
|
echo -ne " ${INFO} Flushing ${LOGFILE} ..."
|
||||||
else
|
fi
|
||||||
# Flush both pihole.log and pihole.log.1 (if existing)
|
echo " " > "${LOGFILE}"
|
||||||
echo " " > "${LOGFILE}"
|
chmod 640 "${LOGFILE}"
|
||||||
if [ -f "${LOGFILE}.1" ]; then
|
if [ -f "${LOGFILE}.1" ]; then
|
||||||
echo " " > "${LOGFILE}.1"
|
echo " " > "${LOGFILE}.1"
|
||||||
chmod 640 "${LOGFILE}.1"
|
chmod 640 "${LOGFILE}.1"
|
||||||
fi
|
fi
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -e "${OVER} ${TICK} Flushed ${LOGFILE} ..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Flush both FTL.log and FTL.log.1 (if existing)
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -ne " ${INFO} Flushing ${FTLFILE} ..."
|
||||||
|
fi
|
||||||
|
echo " " > "${FTLFILE}"
|
||||||
|
chmod 640 "${FTLFILE}"
|
||||||
|
if [ -f "${FTLFILE}.1" ]; then
|
||||||
|
echo " " > "${FTLFILE}.1"
|
||||||
|
chmod 640 "${FTLFILE}.1"
|
||||||
|
fi
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -e "${OVER} ${TICK} Flushed ${FTLFILE} ..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -ne " ${INFO} Flushing database, DNS resolution temporarily unavailable ..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Stop FTL to make sure it doesn't write to the database while we're deleting data
|
# Stop FTL to make sure it doesn't write to the database while we're deleting data
|
||||||
|
@ -73,9 +115,8 @@ else
|
||||||
|
|
||||||
# Restart FTL
|
# Restart FTL
|
||||||
service pihole-FTL restart
|
service pihole-FTL restart
|
||||||
|
if [[ "$*" != *"quiet"* ]]; then
|
||||||
|
echo -e "${OVER} ${TICK} Deleted ${deleted} queries from long-term query database"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$*" != *"quiet"* ]]; then
|
|
||||||
echo -e "${OVER} ${TICK} Flushed /var/log/pihole/pihole.log"
|
|
||||||
echo -e " ${TICK} Deleted ${deleted} queries from database"
|
|
||||||
fi
|
|
||||||
|
|
Loading…
Reference in a new issue