From db278d81e41e9cba378238a192c7682e0c668b26 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 16 Nov 2016 21:34:43 +0100 Subject: [PATCH 1/7] Added webpage.sh --- advanced/Scripts/webpage.sh | 72 +++++++++++++++++++++++++++++++++++++ pihole | 9 ++++- 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100755 advanced/Scripts/webpage.sh diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh new file mode 100755 index 00000000..9ebe7dd4 --- /dev/null +++ b/advanced/Scripts/webpage.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2015, 2016 by Jacob Salmela +# Network-wide ad blocking via your Raspberry Pi +# http://pi-hole.net +# Whitelists and blacklists domains +# +# Pi-hole is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +#globals +basename=pihole +piholeDir=/etc/${basename} + +helpFunc() { + cat << EOM +::: Set options for the web interface of pihole +::: +::: Usage: pihole -web [options] +::: +::: Options: +::: -p, password Set web interface password +::: -c, celsius Set Celcius temperature unit +::: -f, fahrenheit Set Fahrenheit temperature unit +::: -h, --help Show this help dialog +EOM + exit 1 +} + +args=("$@") + +SetTemperatureUnit(){ + + # Remove setting from file (create backup setupVars.conf.bak) + sed -i.bak '/temperatureunit/d' /etc/pihole/setupVars.conf + # Save setting to file + if [[ $unit == "F" ]] ; then + echo "temperatureunit=F" >> /etc/pihole/setupVars.conf + else + echo "temperatureunit=C" >> /etc/pihole/setupVars.conf + fi + +} + +SetWebPassword(){ + + # Remove password from file (create backup setupVars.conf.bak) + sed -i.bak '/webpassword/d' /etc/pihole/setupVars.conf + # Compute password hash + hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//') + # Save hash to file + echo "webpassword=${hash}" >> /etc/pihole/setupVars.conf + +} + +for var in "$@"; do + case "${var}" in + "-p" | "password" ) SetWebPassword;; + "-c" | "celsius" ) unit="C"; SetTemperatureUnit;; + "-f" | "fahrenheit" ) unit="F"; SetTemperatureUnit;; + "-h" | "--help" ) helpFunc;; + esac +done + +shift + +if [[ $# = 0 ]]; then + helpFunc +fi + diff --git a/pihole b/pihole index 83046675..98b1850b 100755 --- a/pihole +++ b/pihole @@ -22,6 +22,11 @@ if [[ ! $EUID -eq 0 ]];then fi fi +webpageFunc() { + /opt/pihole/webpage.sh "$@" + exit 0 +} + whitelistFunc() { "${PI_HOLE_SCRIPT_DIR}"/list.sh "$@" exit 0 @@ -180,7 +185,7 @@ helpFunc() { ::: Control all PiHole specific functions! ::: ::: Usage: pihole [options] -::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage +::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -web (webpage) for more information on usage ::: ::: Options: ::: -w, whitelist Whitelist domains @@ -195,6 +200,7 @@ helpFunc() { ::: -v, version Show current versions ::: -q, query Query the adlists for a specific domain ::: -l, logging Enable or Disable logging (pass 'on' or 'off') +::: -web, webpage Webpage options ::: uninstall Uninstall Pi-Hole from your system :(! ::: status Is Pi-Hole Enabled or Disabled ::: enable Enable Pi-Hole DNS Blocking @@ -228,5 +234,6 @@ case "${1}" in "disable" ) piholeEnable 0;; "status" ) piholeStatus "$2";; "restartdns" ) restartDNS;; + "-web" | "webpage" ) webpageFunc "$@";; * ) helpFunc;; esac From 9193c71cff31e69c74ad4cd884f376fbc4866e81 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 16 Nov 2016 21:36:19 +0100 Subject: [PATCH 2/7] Minor change --- advanced/Scripts/webpage.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9ebe7dd4..07fbec4c 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -10,9 +10,7 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -#globals -basename=pihole -piholeDir=/etc/${basename} +args=("$@") helpFunc() { cat << EOM @@ -29,8 +27,6 @@ EOM exit 1 } -args=("$@") - SetTemperatureUnit(){ # Remove setting from file (create backup setupVars.conf.bak) From 01bf1ae92d5a51b299aa7a675cb3ffa250149ebf Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 16 Nov 2016 22:13:47 +0100 Subject: [PATCH 3/7] Compute double hashes to avoid rainbow table vulnerability --- advanced/Scripts/webpage.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 07fbec4c..dc1e2644 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -1,9 +1,8 @@ #!/usr/bin/env bash # Pi-hole: A black hole for Internet advertisements -# (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi # http://pi-hole.net -# Whitelists and blacklists domains +# Web interface settings # # Pi-hole is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,8 +43,9 @@ SetWebPassword(){ # Remove password from file (create backup setupVars.conf.bak) sed -i.bak '/webpassword/d' /etc/pihole/setupVars.conf - # Compute password hash + # Compute password hash twice to avoid rainbow table vulnerability hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//') + hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') # Save hash to file echo "webpassword=${hash}" >> /etc/pihole/setupVars.conf From 88c161769de113ecac7944ec27b18d2cec1d38a8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 16 Nov 2016 22:33:28 +0100 Subject: [PATCH 4/7] Capitalized variable names. --- advanced/Scripts/webpage.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index dc1e2644..6d2975ba 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -29,12 +29,12 @@ EOM SetTemperatureUnit(){ # Remove setting from file (create backup setupVars.conf.bak) - sed -i.bak '/temperatureunit/d' /etc/pihole/setupVars.conf + sed -i.bak '/TEMPERATUREUNIT/d' /etc/pihole/setupVars.conf # Save setting to file if [[ $unit == "F" ]] ; then - echo "temperatureunit=F" >> /etc/pihole/setupVars.conf + echo "TEMPERATUREUNIT=F" >> /etc/pihole/setupVars.conf else - echo "temperatureunit=C" >> /etc/pihole/setupVars.conf + echo "TEMPERATUREUNIT=C" >> /etc/pihole/setupVars.conf fi } @@ -42,12 +42,12 @@ SetTemperatureUnit(){ SetWebPassword(){ # Remove password from file (create backup setupVars.conf.bak) - sed -i.bak '/webpassword/d' /etc/pihole/setupVars.conf + sed -i.bak '/WEBPASSWORD/d' /etc/pihole/setupVars.conf # Compute password hash twice to avoid rainbow table vulnerability hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//') hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') # Save hash to file - echo "webpassword=${hash}" >> /etc/pihole/setupVars.conf + echo "WEBPASSWORD=${hash}" >> /etc/pihole/setupVars.conf } From 733919be4a0d22cfb4f93dbaaf3f30e03ed4ce84 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 19 Nov 2016 21:50:15 +0100 Subject: [PATCH 5/7] Implement possibility to remove password using "pihole -web -p" --- advanced/Scripts/webpage.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 6d2975ba..0a66bc62 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -43,11 +43,17 @@ SetWebPassword(){ # Remove password from file (create backup setupVars.conf.bak) sed -i.bak '/WEBPASSWORD/d' /etc/pihole/setupVars.conf - # Compute password hash twice to avoid rainbow table vulnerability - hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//') - hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') - # Save hash to file - echo "WEBPASSWORD=${hash}" >> /etc/pihole/setupVars.conf + # Set password only if there is one to be set + if (( ${#args[2]} > 0 )) ; then + # Compute password hash twice to avoid rainbow table vulnerability + hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//') + hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') + # Save hash to file + echo "WEBPASSWORD=${hash}" >> /etc/pihole/setupVars.conf + echo "New password set" + else + echo "Password removed" + fi } From 33b6fe72dabdf24ffa3494d71f0b4068382a0ac8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 19 Nov 2016 21:57:42 +0100 Subject: [PATCH 6/7] Extended help text --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 0a66bc62..68be534f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -18,7 +18,7 @@ helpFunc() { ::: Usage: pihole -web [options] ::: ::: Options: -::: -p, password Set web interface password +::: -p, password Set web interface password, an empty input will remove any previously set password ::: -c, celsius Set Celcius temperature unit ::: -f, fahrenheit Set Fahrenheit temperature unit ::: -h, --help Show this help dialog From f50cbe74cb4a974ebd9125c3edeb06a9f8b3efad Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 20 Nov 2016 15:15:27 +0100 Subject: [PATCH 7/7] Changed -web (webpage) to -a (admin) --- advanced/Scripts/webpage.sh | 4 ++-- pihole | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 68be534f..bcb45a14 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -13,9 +13,9 @@ args=("$@") helpFunc() { cat << EOM -::: Set options for the web interface of pihole +::: Set admin options for the web interface of pihole ::: -::: Usage: pihole -web [options] +::: Usage: pihole -a [options] ::: ::: Options: ::: -p, password Set web interface password, an empty input will remove any previously set password diff --git a/pihole b/pihole index 98b1850b..530dac8d 100755 --- a/pihole +++ b/pihole @@ -185,7 +185,7 @@ helpFunc() { ::: Control all PiHole specific functions! ::: ::: Usage: pihole [options] -::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -web (webpage) for more information on usage +::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -a (admin) for more information on usage ::: ::: Options: ::: -w, whitelist Whitelist domains @@ -200,7 +200,7 @@ helpFunc() { ::: -v, version Show current versions ::: -q, query Query the adlists for a specific domain ::: -l, logging Enable or Disable logging (pass 'on' or 'off') -::: -web, webpage Webpage options +::: -a, admin Admin webpage options ::: uninstall Uninstall Pi-Hole from your system :(! ::: status Is Pi-Hole Enabled or Disabled ::: enable Enable Pi-Hole DNS Blocking @@ -234,6 +234,6 @@ case "${1}" in "disable" ) piholeEnable 0;; "status" ) piholeStatus "$2";; "restartdns" ) restartDNS;; - "-web" | "webpage" ) webpageFunc "$@";; + "-a" | "admin" ) webpageFunc "$@";; * ) helpFunc;; esac