From 158ea1d43b6023574f71dc8665b194c05094b06b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 21 Jan 2018 11:54:49 +0100 Subject: [PATCH 1/4] Add sqlite3 dependency Signed-off-by: DL6ER --- advanced/Scripts/piholeLogFlush.sh | 1 + automated install/basic-install.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 2187f3ac70..8685012d45 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -41,6 +41,7 @@ else echo " " > /var/log/pihole.log.1 fi fi + # Delete most recent 24 hours from FTL's database fi if [[ "$@" != *"quiet"* ]]; then diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 550f26ad06..de9eddf4c8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -163,7 +163,7 @@ if command -v apt-get &> /dev/null; then # These programs are stored in an array so they can be looped through later INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail) # Pi-hole itself has several dependencies that also need to be installed - PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget idn2) + PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget idn2 sqlite3) # The Web dashboard has some that also need to be installed # It's useful to separate the two since our repos are also setup as "Core" code and "Web" code PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer}-${phpSqlite}) From 4c249a1186dfa1023567cfd250b689ff72996d92 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 21 Jan 2018 13:48:13 +0100 Subject: [PATCH 2/4] Flush most recent 24 hours from FTL's database Signed-off-by: DL6ER --- advanced/Scripts/piholeLogFlush.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 8685012d45..0816678fd7 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -42,8 +42,11 @@ else fi fi # Delete most recent 24 hours from FTL's database + deleted=$(sqlite3 /etc/pihole/pihole-FTL.db "DELETE FROM queries WHERE timestamp >= strftime('%s','now')-86400; select changes() from queries limit 1") + fi if [[ "$@" != *"quiet"* ]]; then echo -e "${OVER} ${TICK} Flushed /var/log/pihole.log" + echo -e " ${TICK} Deleted ${deleted} queries from database" fi From 5d274008db4e38332538d0c25d6e49afd08d839d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 17 Feb 2018 12:58:57 +0100 Subject: [PATCH 3/4] Use possibly user-defined database location when flushing Signed-off-by: DL6ER --- advanced/Scripts/piholeLogFlush.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 0816678fd7..bbe68c7ec4 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -11,6 +11,17 @@ colfile="/opt/pihole/COL_TABLE" source ${colfile} +# Determine database location +# Obtain DBFILE=... setting from pihole-FTL.db +# 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=...") +DBFILE=$(sed -n -e 's/^\s^.DBFILE\s*=\s*//p' /etc/pihole/pihole-FTL.conf) +# Test for empty string. Use standard path in this case. +if [ -z $DBFILE ]; then + DBFILE="/etc/pihole/pihole-FTL.db" +fi + if [[ "$@" != *"quiet"* ]]; then echo -ne " ${INFO} Flushing /var/log/pihole.log ..." fi @@ -41,8 +52,8 @@ else echo " " > /var/log/pihole.log.1 fi fi - # Delete most recent 24 hours from FTL's database - deleted=$(sqlite3 /etc/pihole/pihole-FTL.db "DELETE FROM queries WHERE timestamp >= strftime('%s','now')-86400; select changes() from queries limit 1") + # Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history) + deleted=$(sqlite3 "${DBFILE}" "DELETE FROM queries WHERE timestamp >= strftime('%s','now')-86400; select changes() from queries limit 1") fi From b8eaa9a52742437ba073927ee51bb7be2af9ced9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 17 Feb 2018 13:01:00 +0100 Subject: [PATCH 4/4] Use double quotes to precent globbing and word splitting Signed-off-by: DL6ER --- advanced/Scripts/piholeLogFlush.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index bbe68c7ec4..5fd9832e7c 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -16,9 +16,9 @@ source ${colfile} # 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=...") -DBFILE=$(sed -n -e 's/^\s^.DBFILE\s*=\s*//p' /etc/pihole/pihole-FTL.conf) +DBFILE="$(sed -n -e 's/^\s^.DBFILE\s*=\s*//p' /etc/pihole/pihole-FTL.conf)" # Test for empty string. Use standard path in this case. -if [ -z $DBFILE ]; then +if [ -z "$DBFILE" ]; then DBFILE="/etc/pihole/pihole-FTL.db" fi