From 4df5c0bb9675eda8d00f8e073f428d1434cd18c6 Mon Sep 17 00:00:00 2001 From: Jack'lul <8418678+jacklul@users.noreply.github.com> Date: Wed, 5 Mar 2025 22:25:33 +0100 Subject: [PATCH] Add webserver log to piholeLogFlush.sh Signed-off-by: Jack'lul <8418678+jacklul@users.noreply.github.com> --- advanced/Scripts/piholeLogFlush.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 34d96318..58c6a41d 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -35,6 +35,10 @@ FTLFILE=$(getFTLConfigValue "files.log.ftl") if [ -z "$FTLFILE" ]; then FTLFILE="/var/log/pihole/FTL.log" fi +WEBFILE=$(getFTLConfigValue "files.log.webserver") +if [ -z "$WEBFILE" ]; then + WEBFILE="/var/log/pihole/webserver.log" +fi if [[ "$*" == *"once"* ]]; then # Nightly logrotation @@ -71,6 +75,17 @@ if [[ "$*" == *"once"* ]]; then if [[ "$*" != *"quiet"* ]]; then echo -e "${OVER} ${TICK} Rotated ${FTLFILE} ..." fi + # Copy webserver.log over to webserver.log.1 + # and empty out webserver.log + if [[ "$*" != *"quiet"* ]]; then + echo -ne " ${INFO} Rotating ${WEBFILE} ..." + fi + cp -p "${WEBFILE}" "${WEBFILE}.1" + echo " " > "${WEBFILE}" + chmod 640 "${WEBFILE}" + if [[ "$*" != *"quiet"* ]]; then + echo -e "${OVER} ${TICK} Rotated ${WEBFILE} ..." + fi fi else # Manual flushing @@ -103,6 +118,20 @@ else echo -e "${OVER} ${TICK} Flushed ${FTLFILE} ..." fi + # Flush both webserver.log and webserver.log.1 (if existing) + if [[ "$*" != *"quiet"* ]]; then + echo -ne " ${INFO} Flushing ${WEBFILE} ..." + fi + echo " " > "${WEBFILE}" + chmod 640 "${WEBFILE}" + if [ -f "${WEBFILE}.1" ]; then + echo " " > "${WEBFILE}.1" + chmod 640 "${WEBFILE}.1" + fi + if [[ "$*" != *"quiet"* ]]; then + echo -e "${OVER} ${TICK} Flushed ${WEBFILE} ..." + fi + if [[ "$*" != *"quiet"* ]]; then echo -ne " ${INFO} Flushing database, DNS resolution temporarily unavailable ..." fi