Modify pihole arpflush to stop FTL while performing the action and use the new TOML config values

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2024-06-19 22:49:11 +02:00
parent 8f24e8aa5f
commit 92b15cf744
No known key found for this signature in database
GPG key ID: 00135ACBD90B28DD

View file

@ -15,27 +15,29 @@ if [[ -f ${coltable} ]]; then
source ${coltable} source ${coltable}
fi fi
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
source "${utilsfile}"
# Determine database location # Determine database location
# Obtain DBFILE=... setting from pihole-FTL.db DBFILE=$(getFTLConfigValue "files.database")
# Constructed to return nothing when
# a) the setting is not present in the config file, or
# b) the setting is commented out (e.g. "#DBFILE=...")
FTLconf="/etc/pihole/pihole-FTL.conf"
if [ -e "$FTLconf" ]; then
DBFILE="$(sed -n -e 's/^\s*DBFILE\s*=\s*//p' ${FTLconf})"
fi
# Test for empty string. Use standard path in this case.
if [ -z "$DBFILE" ]; then if [ -z "$DBFILE" ]; then
DBFILE="/etc/pihole/pihole-FTL.db" DBFILE="/etc/pihole/pihole-FTL.db"
fi fi
flushARP(){ flushARP(){
local output local output
if [[ "${args[1]}" != "quiet" ]]; then if [[ "${args[1]}" != "quiet" ]]; then
echo -ne " ${INFO} Flushing network table ..." echo -ne " ${INFO} Flushing network table ..."
fi fi
# Stop FTL to prevent database access
if ! output=$(pihole-FTL service stop 2>&1); then
echo -e "${OVER} ${CROSS} Failed to stop FTL"
echo " Output: ${output}"
return 1
fi
# Truncate network_addresses table in pihole-FTL.db # Truncate network_addresses table in pihole-FTL.db
# This needs to be done before we can truncate the network table due to # This needs to be done before we can truncate the network table due to
# foreign key constraints # foreign key constraints
@ -54,6 +56,20 @@ flushARP(){
return 1 return 1
fi fi
# Flush ARP cache of the host
if ! output=$(ip -s -s neigh flush all 2>&1); then
echo -e "${OVER} ${CROSS} Failed to flush ARP cache"
echo " Output: ${output}"
return 1
fi
# Start FTL again
if ! output=$(pihole-FTL service restart 2>&1); then
echo -e "${OVER} ${CROSS} Failed to restart FTL"
echo " Output: ${output}"
return 1
fi
if [[ "${args[1]}" != "quiet" ]]; then if [[ "${args[1]}" != "quiet" ]]; then
echo -e "${OVER} ${TICK} Flushed network table" echo -e "${OVER} ${TICK} Flushed network table"
fi fi