From 4aafa8cf4797711d982958427bb0105946923d4a Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 20 Aug 2018 19:04:58 -0400 Subject: [PATCH 1/5] Set the FTL privacy level during install Signed-off-by: Mcat12 --- automated install/basic-install.sh | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9f596b45..f8da68ab 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -59,6 +59,7 @@ IPV6_ADDRESS="" # By default, query logging is enabled and the dashboard is set to be installed QUERY_LOGGING=true INSTALL_WEB_INTERFACE=true +PRIVACY_LEVEL=0 if [ -z "${USER}" ]; then USER="$(id -un)" @@ -1015,6 +1016,47 @@ setLogging() { esac } +# Allow the user to set their FTL privacy level +setPrivacyLevel() { + local LevelCommand + local LevelOptions + local LevelChoice + + LevelCommand=(whiptail --separate-output --radiolist "Select a privacy mode for FTL." "${r}" "${c}" 6) + + # The default selection is level 0 + LevelOptions=( + "0 - Show everything" on + "1 - Hide domains" off + "2 - Hide domains and clients" off + "3 - Anonymous mode" off + "4 - Disabled statistics" off + ) + + # Get the user's choice + LevelChoice=$("${LevelCommand[@]}" "${LevelOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1) + + case "${LevelChoice}" in + "0 - Show everything") + PRIVACY_LEVEL=0 + ;; + "1 - Hide domains") + PRIVACY_LEVEL=1 + ;; + "2 - Hide domains and clients") + PRIVACY_LEVEL=2 + ;; + "3 - Anonymous mode") + PRIVACY_LEVEL=3 + ;; + "4 - Disabled statistics") + PRIVACY_LEVEL=4 + ;; + esac + + echo -en " ${INFO} Privacy level ${PRIVACY_LEVEL}" +} + # Function to ask the user if they want to install the dashboard setAdminFlag() { # Local, named variables @@ -1718,6 +1760,10 @@ finalExports() { echo "LIGHTTPD_ENABLED=${LIGHTTPD_ENABLED}" }>> "${setupVars}" + # Set the privacy level + sed -i '/PRIVACYLEVEL/d' "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" + echo "PRIVACYLEVEL=${PRIVACY_LEVEL}" >> "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" + # Bring in the current settings and the functions to manipulate them source "${setupVars}" source "${PI_HOLE_LOCAL_REPO}/advanced/Scripts/webpage.sh" @@ -2413,11 +2459,22 @@ main() { setAdminFlag # Let the user decide if they want query logging enabled... setLogging + # Let the user decide the FTL privacy level + setPrivacyLevel else # Setup adlist file if not exists installDefaultBlocklists + # Source ${setupVars} to use predefined user variables in the functions source ${setupVars} + + # Get the privacy level if it exists (default is 0) + if [[ -f "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then + PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf") + + # If no setting was found, default to 0 + PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}" + fi fi # Clone/Update the repos clone_or_update_repos From c22e94c9c736e48cad889fad8ce656a91012a59d Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 20 Aug 2018 19:33:15 -0400 Subject: [PATCH 2/5] Update test to include empty FTL config The installer ensures that an FTL config will exist, and creates an empty file if it doesn't. Signed-off-by: Mcat12 --- test/test_automated_install.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 2cded451..a2593d83 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -81,6 +81,7 @@ def test_setupVars_saved_to_file(Pihole): {} mkdir -p /etc/dnsmasq.d version_check_dnsmasq + echo "" > /etc/pihole/pihole-FTL.conf finalExports cat /etc/pihole/setupVars.conf '''.format(set_setup_vars)) From 6a26a05dbf1a0dcc576e61946a83b0069b59d27a Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 20 Aug 2018 19:40:43 -0400 Subject: [PATCH 3/5] Fix privacy level whiptail option format Signed-off-by: Mcat12 --- automated install/basic-install.sh | 31 ++++++------------------------ 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f8da68ab..e255fd7e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1020,39 +1020,20 @@ setLogging() { setPrivacyLevel() { local LevelCommand local LevelOptions - local LevelChoice LevelCommand=(whiptail --separate-output --radiolist "Select a privacy mode for FTL." "${r}" "${c}" 6) # The default selection is level 0 LevelOptions=( - "0 - Show everything" on - "1 - Hide domains" off - "2 - Hide domains and clients" off - "3 - Anonymous mode" off - "4 - Disabled statistics" off + "0" "Show everything" on + "1" "Hide domains" off + "2" "Hide domains and clients" off + "3" "Anonymous mode" off + "4" "Disabled statistics" off ) # Get the user's choice - LevelChoice=$("${LevelCommand[@]}" "${LevelOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1) - - case "${LevelChoice}" in - "0 - Show everything") - PRIVACY_LEVEL=0 - ;; - "1 - Hide domains") - PRIVACY_LEVEL=1 - ;; - "2 - Hide domains and clients") - PRIVACY_LEVEL=2 - ;; - "3 - Anonymous mode") - PRIVACY_LEVEL=3 - ;; - "4 - Disabled statistics") - PRIVACY_LEVEL=4 - ;; - esac + PRIVACY_LEVEL=$("${LevelCommand[@]}" "${LevelOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1) echo -en " ${INFO} Privacy level ${PRIVACY_LEVEL}" } From 5d0d7336ff9b6791ba1dd3b28f435ce8900a9102 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 20 Aug 2018 20:21:03 -0400 Subject: [PATCH 4/5] Echo with newline when setting privacy level Signed-off-by: Mcat12 --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e255fd7e..d339c271 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1035,7 +1035,7 @@ setPrivacyLevel() { # Get the user's choice PRIVACY_LEVEL=$("${LevelCommand[@]}" "${LevelOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1) - echo -en " ${INFO} Privacy level ${PRIVACY_LEVEL}" + echo -e " ${INFO} Privacy level ${PRIVACY_LEVEL}" } # Function to ask the user if they want to install the dashboard From c270b8334142d167d1c9de6e17a9f53b43033ff4 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 1 Nov 2018 15:14:26 -0400 Subject: [PATCH 5/5] Use printf instead of echo Co-Authored-By: Mcat12 --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d339c271..8e0b0e82 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1035,7 +1035,7 @@ setPrivacyLevel() { # Get the user's choice PRIVACY_LEVEL=$("${LevelCommand[@]}" "${LevelOptions[@]}" 2>&1 >/dev/tty) || (echo -e " ${COL_LIGHT_RED}Cancel was selected, exiting installer${COL_NC}" && exit 1) - echo -e " ${INFO} Privacy level ${PRIVACY_LEVEL}" + printf " %b Privacy level %d" "${INFO}" "${PRIVACY_LEVEL}" } # Function to ask the user if they want to install the dashboard