From 2e398c5da472a7049f33b8e57efdb59c301e0385 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 14 Apr 2017 17:20:13 +0100 Subject: [PATCH 01/35] stash changes on branch switch, else it fails if any changes have been made. --- advanced/Scripts/piholeCheckout.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 09f20d6b..66e435c7 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -54,6 +54,8 @@ fetch_checkout_pull_branch() { # Set the reference for the requested branch, fetch, check it put and pull it cd "${directory}" git remote set-branches origin "${branch}" || return 1 + git stash --all --quiet &> /dev/null || return 1 + git clean --force -d || return 1 git fetch --quiet || return 1 checkout_pull_branch "${directory}" "${branch}" || return 1 } From db1e5f10ea1850f0e29a50d6f1beccbf20616e56 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 21 Apr 2017 17:08:15 +0200 Subject: [PATCH 02/35] Make changes according to comment in #1384 --- advanced/Scripts/piholeCheckout.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 66e435c7..c5b77368 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -54,8 +54,8 @@ fetch_checkout_pull_branch() { # Set the reference for the requested branch, fetch, check it put and pull it cd "${directory}" git remote set-branches origin "${branch}" || return 1 - git stash --all --quiet &> /dev/null || return 1 - git clean --force -d || return 1 + git stash --all --quiet &> /dev/null || true + git clean --force -d || true git fetch --quiet || return 1 checkout_pull_branch "${directory}" "${branch}" || return 1 } From 19e688effbf866416078394e3e25fba75b1519f5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Apr 2017 13:47:07 +0200 Subject: [PATCH 03/35] Add localise-queries flag to 01-pihole.conf --- advanced/01-pihole.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 0ddf1caa..1b157f88 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -25,6 +25,8 @@ addn-hosts=/etc/pihole/local.list domain-needed +localise-queries + bogus-priv no-resolv From a0603ad3b701abde6e392a72a407260c012a9a9c Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Tue, 2 May 2017 17:13:55 +1000 Subject: [PATCH 04/35] Update queryFunc() * Allow scanList() to search files using a wildcard by removing quotes wrapped around `${list}` * scanList() will not provide a domain ouput on each string if exact is specified (`grep -l`) * Remove unused processWildcards() function * Return a message if no domain is specified * IDN domains are converted to punycode when running a `pihole -q` search if the `python` package is available, otherwise will revert to current behaviour * Scan Blacklist & Wildcards first, exiting from search if a match is found (Fixes #1330) * Use one `grep` subshell to search for all "*.domains" lists at once (opposed to looping to get every matching file name, and then spawning a `grep` instance for every matching file) * queryFunc() will not return "(0 results)" output from files where no match is found * Sort results based off list number * Return a message if no results are found --- pihole | 83 +++++++++++++++++++++++----------------------------------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/pihole b/pihole index 83e13000..eaf4e955 100755 --- a/pihole +++ b/pihole @@ -84,62 +84,45 @@ scanList(){ domain="${1}" list="${2}" method="${3}" - if [[ ${method} == "-exact" ]] ; then - grep -i -E "(^|\s)${domain}($|\s)" "${list}" - else - grep -i "${domain}" "${list}" - fi -} -processWildcards() { - IFS="." read -r -a array <<< "${1}" - for (( i=${#array[@]}-1; i>=0; i-- )); do - ar="" - for (( j=${#array[@]}-1; j>${#array[@]}-i-2; j-- )); do - if [[ $j == $((${#array[@]}-1)) ]]; then - ar="${array[$j]}" - else - ar="${array[$j]}.${ar}" - fi - done - echo "${ar}" - done + if [[ ${method} == "-exact" ]]; then + grep -i -E -l "(^|\/)${domain}($|\/)" ${list} + else + grep -i "${domain}" ${list} + fi } queryFunc() { - domain="${2}" method="${3}" - lists=( /etc/pihole/list.* /etc/pihole/blacklist.txt) - for list in ${lists[@]}; do - if [ -e "${list}" ]; then - result=$(scanList ${domain} ${list} ${method}) - # Remove empty lines before couting number of results - count=$(sed '/^\s*$/d' <<< "$result" | wc -l) - echo "::: ${list} (${count} results)" - if [[ ${count} > 0 ]]; then - echo "${result}" - fi - echo "" - else - echo "::: ${list} does not exist" - echo "" - fi - done - - # Scan for possible wildcard matches - if [ -e "${wildcardlist}" ]; then - local wildcards=($(processWildcards "${domain}")) - for domain in ${wildcards[@]}; do - result=$(scanList "\/${domain}\/" ${wildcardlist}) - # Remove empty lines before couting number of results - count=$(sed '/^\s*$/d' <<< "$result" | wc -l) - if [[ ${count} > 0 ]]; then - echo "::: Wildcard blocking ${domain} (${count} results)" - echo "${result}" - echo "" - fi - done + + # If domain contains non ASCII characters, convert domain to punycode if python exists + # Cr: https://serverfault.com/a/335079 + if [ -z "${2}" ]; then + echo "::: No domain specified" + exit 1 + elif [[ ${2} = *[![:ascii:]]* ]]; then + [ `which python` ] && domain=$(python -c 'import sys;print sys.argv[1].decode("utf-8").encode("idna")' "${2}") + else + domain="${2}" fi + + # Scan Blacklist and Wildcards + lists="/etc/pihole/blacklist.txt $wildcardlist" + result=$(scanList ${domain} "${lists}" ${method}) + if [ -n "$result" ]; then + echo "$result" + exit 0 + fi + + # Scan Domains lists + result=$(scanList ${domain} "/etc/pihole/*.domains" ${method}) + if [ -n "$result" ]; then + sort -t . -k 2 -g <<< "$result" + else + [ -n "$method" ] && exact="exact " + echo "::: No ${exact}results found for ${domain}" + fi + exit 0 } From 30dcf6ff4719d88bae3507c021da9925ded0e03d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 2 May 2017 09:18:58 +0200 Subject: [PATCH 05/35] Include pihole-FTL.log in debug report --- advanced/Scripts/piholeDebug.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 945cd81c..10dd1e8b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -27,6 +27,7 @@ PIHOLELOG="/var/log/pihole.log" PIHOLEGITDIR="/etc/.pihole/" ADMINGITDIR="/var/www/html/admin/" WHITELISTMATCHES="/tmp/whitelistmatches.list" +readonly FTLLOG="/var/log/pihole-FTL.log" TIMEOUT=60 # Header info and introduction @@ -523,6 +524,18 @@ header_write "Analyzing pihole.log" && log_write "${PIHOLELOG} is ${pihole_size}." \ || log_echo "Warning: No pihole.log file found!" +header_write "Analyzing pihole-FTL.log" + + FTL_length=$(grep -c ^ "${FTLLOG}") \ + && log_write "${FTLLOG} is ${FTL_length} lines long." \ + || log_echo "Warning: No pihole-FTL.log file found!" + + FTL_size=$(du -h "${FTLLOG}" | awk '{ print $1 }') \ + && log_write "${FTLLOG} is ${FTL_size}." \ + || log_echo "Warning: No pihole-FTL.log file found!" + +tail -n50 "${FTLLOG}" >&3 + trap finalWork EXIT ### Method calls for additional logging ### From a5733508ae1ae625efcfd48190eab4b6a963d599 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 2 May 2017 21:36:08 +0100 Subject: [PATCH 06/35] Double hash the password directly in the install script --- automated install/basic-install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d7075088..c9f4d659 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1413,7 +1413,9 @@ main() { pw="" if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) - /usr/local/bin/pihole -a -p "${pw}" + hash=$(echo -n ${pw} | sha256sum | sed 's/\s.*$//') + hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') + echo "WEBPASSWORD=${hash}" >> ${setupVars} fi fi From 9c136a5579cbfd3a151a3068bfe1abb8ef578c09 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 2 May 2017 22:24:37 +0100 Subject: [PATCH 07/35] functionise Hashing --- advanced/Scripts/webpage.sh | 11 ++++++++--- automated install/basic-install.sh | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7804fc8f..1169d6f0 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -67,6 +67,13 @@ SetTemperatureUnit(){ } +HashPassword(){ + # Compute password hash twice to avoid rainbow table vulnerability + return=$(echo -n ${1} | sha256sum | sed 's/\s.*$//') + return=$(echo -n ${return} | sha256sum | sed 's/\s.*$//') + echo ${return} +} + SetWebPassword(){ if [ "${SUDO_USER}" == "www-data" ]; then @@ -93,9 +100,7 @@ SetWebPassword(){ read -s -p "Confirm Password: " CONFIRM echo "" if [ "${PASSWORD}" == "${CONFIRM}" ] ; then - # Compute password hash twice to avoid rainbow table vulnerability - hash=$(echo -n ${PASSWORD} | sha256sum | sed 's/\s.*$//') - hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') + hash=$(HashPassword ${PASSWORD}) # Save hash to file change_setting "WEBPASSWORD" "${hash}" echo "New password set" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c9f4d659..e3f48536 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1413,9 +1413,9 @@ main() { pw="" if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) - hash=$(echo -n ${pw} | sha256sum | sed 's/\s.*$//') + hash=$(echo -n ${pw} | sha256sum | sed 's/\s.*$//' | sha256sum | sed 's/\s.*$//') hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') - echo "WEBPASSWORD=${hash}" >> ${setupVars} + echo "WEBPASSWORD=$(echo -n ${pw} | sha256sum | sed 's/\s.*$//' | sha256sum | sed 's/\s.*$//')" >> ${setupVars} fi fi From 61ec7723f6abd599e6bd8f41e741a9ed31cf620d Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 2 May 2017 22:25:47 +0100 Subject: [PATCH 08/35] use function in install script --- automated install/basic-install.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e3f48536..e535d115 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1413,9 +1413,8 @@ main() { pw="" if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) - hash=$(echo -n ${pw} | sha256sum | sed 's/\s.*$//' | sha256sum | sed 's/\s.*$//') - hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') - echo "WEBPASSWORD=$(echo -n ${pw} | sha256sum | sed 's/\s.*$//' | sha256sum | sed 's/\s.*$//')" >> ${setupVars} + . /opt/pihole/webpage.sh + echo "WEBPASSWORD=$(HashPassword ${1}) fi fi From bb6f409e89c931a313d12dbe2e3050d72bbde76a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 2 May 2017 22:28:32 +0100 Subject: [PATCH 09/35] dropped a " --- 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 e535d115..cd39d225 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1414,7 +1414,7 @@ main() { if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) . /opt/pihole/webpage.sh - echo "WEBPASSWORD=$(HashPassword ${1}) + echo "WEBPASSWORD=$(HashPassword ${1})" fi fi From 9c645e2010342cd47cf308555560b30783ce3153 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 2 May 2017 22:30:02 +0100 Subject: [PATCH 10/35] Seriously. --- 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 cd39d225..311adb72 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1414,7 +1414,7 @@ main() { if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) . /opt/pihole/webpage.sh - echo "WEBPASSWORD=$(HashPassword ${1})" + echo "WEBPASSWORD=$(HashPassword ${1})" >> ${setupVars} fi fi From b13171cc4549ff894c6336bbd31ac9f32a0271d4 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 2 May 2017 22:37:38 +0100 Subject: [PATCH 11/35] $1 is not $pw. Seriously, who let me onto this project --- 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 311adb72..c65ef49f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1414,7 +1414,7 @@ main() { if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) . /opt/pihole/webpage.sh - echo "WEBPASSWORD=$(HashPassword ${1})" >> ${setupVars} + echo "WEBPASSWORD=$(HashPassword ${pw})" >> ${setupVars} fi fi From 9cc392fa0207b9b7840e4ac810f6eb42832990b5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 4 May 2017 11:43:48 +0200 Subject: [PATCH 12/35] Update Marks PR after the Promo code has been merged --- advanced/Scripts/webpage.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 1169d6f0..d3ad3032 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -88,17 +88,23 @@ SetWebPassword(){ exit 1 fi - read -s -p "Enter New Password (Blank for no password): " PASSWORD - echo "" + if (( ${#args[2]} > 0 )) ; then + readonly PASSWORD="${args[2]}" + readonly CONFIRM="${PASSWORD}" + else + read -s -p "Enter New Password (Blank for no password): " PASSWORD + echo "" - if [ "${PASSWORD}" == "" ]; then - change_setting "WEBPASSWORD" "" - echo "Password Removed" - exit 0 - fi + if [ "${PASSWORD}" == "" ]; then + change_setting "WEBPASSWORD" "" + echo "Password Removed" + exit 0 + fi + + read -s -p "Confirm Password: " CONFIRM + echo "" + fi - read -s -p "Confirm Password: " CONFIRM - echo "" if [ "${PASSWORD}" == "${CONFIRM}" ] ; then hash=$(HashPassword ${PASSWORD}) # Save hash to file From 99b23627d0d8cb6036cf69e46de042a80b570ac0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 5 May 2017 12:03:51 -0700 Subject: [PATCH 13/35] Update basic-install.sh --- 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 c65ef49f..3ca90db6 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -408,7 +408,7 @@ setDHCPCD() { echo "interface ${PIHOLE_INTERFACE} static ip_address=${IPV4_ADDRESS} static routers=${IPv4gw} - static domain_name_servers=${IPv4gw}" | tee -a /etc/dhcpcd.conf >/dev/null + static domain_name_servers=127.0.0.1" | tee -a /etc/dhcpcd.conf >/dev/null } setStaticIPv4() { From f270f7430c655249d9274553697c558c3b9b04e9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:10:24 +0100 Subject: [PATCH 14/35] Update block page. Allow for setupVars setting of CUSTOMBLOCKPAGE (bool) to prevent it being overwritten --- automated install/basic-install.sh | 34 +++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c65ef49f..ca45a256 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -35,7 +35,7 @@ IPV4_ADDRESS="" IPV6_ADDRESS="" QUERY_LOGGING=true INSTALL_WEB=true - +CUSTOMBLOCKPAGE=false # Find the rows and columns will default to 80x24 is it can not be detected screen_size=$(stty size 2>/dev/null || echo 24 80) @@ -866,30 +866,48 @@ CreateLogFile() { } installPiholeWeb() { + + if [ -f ${setupVars} ]; then + . ${setupVars} + fi # Install the web interface echo ":::" - echo "::: Installing pihole custom index page..." + echo -n "::: Installing index.php..." if [ -d "/var/www/html/pihole" ]; then if [ -f "/var/www/html/pihole/index.php" ]; then - echo "::: Existing index.php detected, not overwriting" + if [[ ${CUSTOMBLOCKPAGE} == true ]]; then + echo " Existing index.php detected, not overwriting" + else + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ + echo " done!" + fi else - echo -n "::: index.php missing, replacing... " cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ echo " done!" fi + echo -n "::: Installing index.js..." if [ -f "/var/www/html/pihole/index.js" ]; then - echo "::: Existing index.js detected, not overwriting" + if [[ ${CUSTOMBLOCKPAGE} == true ]]; then + echo " Existing index.js detected, not overwriting" + else + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ + echo " done!" + fi else - echo -n "::: index.js missing, replacing... " cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ echo " done!" fi + echo -n "::: Installing blockingpage.css..." if [ -f "/var/www/html/pihole/blockingpage.css" ]; then - echo "::: Existing blockingpage.css detected, not overwriting" + if [[ ${CUSTOMBLOCKPAGE} == true ]]; then + echo " Existing blockingpage.css detected, not overwriting" + else + cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole + echo " done!" + fi else - echo -n "::: blockingpage.css missing, replacing... " cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole echo " done!" fi From 5cd2c77d9897ae84d6494a4397fbbd22013289d2 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:24:40 +0100 Subject: [PATCH 15/35] simplify --- automated install/basic-install.sh | 35 +----------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ca45a256..eaa3413d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -874,44 +874,11 @@ installPiholeWeb() { echo ":::" echo -n "::: Installing index.php..." if [ -d "/var/www/html/pihole" ]; then - if [ -f "/var/www/html/pihole/index.php" ]; then - if [[ ${CUSTOMBLOCKPAGE} == true ]]; then - echo " Existing index.php detected, not overwriting" - else + if [[ ${CUSTOMBLOCKPAGE} == false ]]; then cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ - echo " done!" - fi - else - cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ - echo " done!" - fi - - echo -n "::: Installing index.js..." - if [ -f "/var/www/html/pihole/index.js" ]; then - if [[ ${CUSTOMBLOCKPAGE} == true ]]; then - echo " Existing index.js detected, not overwriting" - else cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ - echo " done!" - fi - else - cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ - echo " done!" - fi - - echo -n "::: Installing blockingpage.css..." - if [ -f "/var/www/html/pihole/blockingpage.css" ]; then - if [[ ${CUSTOMBLOCKPAGE} == true ]]; then - echo " Existing blockingpage.css detected, not overwriting" - else cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole - echo " done!" fi - else - cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole - echo " done!" - fi - else echo "::: Creating directory for blocking page" install -d /var/www/html/pihole From 41dd163453cc37a2962a6d5cbf4851f53c74c49b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:27:33 +0100 Subject: [PATCH 16/35] further simplify --- automated install/basic-install.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index eaa3413d..d603585f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -872,15 +872,14 @@ installPiholeWeb() { fi # Install the web interface echo ":::" - echo -n "::: Installing index.php..." if [ -d "/var/www/html/pihole" ]; then if [[ ${CUSTOMBLOCKPAGE} == false ]]; then - cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ - cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ - cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole + echo -n "::: Installing block page..." + install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + echo " done!" fi else - echo "::: Creating directory for blocking page" + echo "::: Creating directory for blocking page" install -d /var/www/html/pihole install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ if [ -f /var/www/html/index.lighttpd.html ]; then From 615ca56ea3967e915fb38a660ef9fe336e056126 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:27:58 +0100 Subject: [PATCH 17/35] fix inteliJ IDEA complaints --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d603585f..908902f3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -875,13 +875,13 @@ installPiholeWeb() { if [ -d "/var/www/html/pihole" ]; then if [[ ${CUSTOMBLOCKPAGE} == false ]]; then echo -n "::: Installing block page..." - install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + install -D ${PI_HOLE_LOCAL_REPO}/advanced/index.* /advanced/blockingpage.* /var/www/html/pihole/ echo " done!" fi else echo "::: Creating directory for blocking page" install -d /var/www/html/pihole - install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + install -D ${PI_HOLE_LOCAL_REPO}/advanced/index.* /advanced/blockingpage.* /var/www/html/pihole/ if [ -f /var/www/html/index.lighttpd.html ]; then mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else From 324d4433c3fc616ba25e9fe58e534e3bfc30e6f6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:31:31 +0100 Subject: [PATCH 18/35] even further simplify --- automated install/basic-install.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 908902f3..feeb2791 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -872,24 +872,20 @@ installPiholeWeb() { fi # Install the web interface echo ":::" - if [ -d "/var/www/html/pihole" ]; then - if [[ ${CUSTOMBLOCKPAGE} == false ]]; then - echo -n "::: Installing block page..." - install -D ${PI_HOLE_LOCAL_REPO}/advanced/index.* /advanced/blockingpage.* /var/www/html/pihole/ - echo " done!" - fi - else - echo "::: Creating directory for blocking page" + + if [[ ${CUSTOMBLOCKPAGE} == false ]]; then + echo -n "::: Installing block page..." install -d /var/www/html/pihole install -D ${PI_HOLE_LOCAL_REPO}/advanced/index.* /advanced/blockingpage.* /var/www/html/pihole/ - if [ -f /var/www/html/index.lighttpd.html ]; then - mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig - else - printf "\n:::\tNo default index.lighttpd.html file found... not backing up" - fi echo " done!" fi + if [ -f /var/www/html/index.lighttpd.html ]; then + mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + else + printf "\n:::\tNo default index.lighttpd.html file found... not backing up" + fi + # Install Sudoer file echo ":::" echo -n "::: Installing sudoer file..." From 5b0927ca4b735a9f3b996ec38877df3a0852cf29 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:32:27 +0100 Subject: [PATCH 19/35] tidy up output --- automated install/basic-install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index feeb2791..62130ca6 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -880,10 +880,12 @@ installPiholeWeb() { echo " done!" fi + echo -n "::: Backing up default lighttpd index page..." if [ -f /var/www/html/index.lighttpd.html ]; then mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + echo " done!" else - printf "\n:::\tNo default index.lighttpd.html file found... not backing up" + echo " No default index.lighttpd.html file found... not backing up" fi # Install Sudoer file From 19fd25c7cd54b3cfc19ded79373869c9d035dbb4 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:40:10 +0100 Subject: [PATCH 20/35] revert line, looks tidyer --- 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 62130ca6..516f8ebf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -876,7 +876,7 @@ installPiholeWeb() { if [[ ${CUSTOMBLOCKPAGE} == false ]]; then echo -n "::: Installing block page..." install -d /var/www/html/pihole - install -D ${PI_HOLE_LOCAL_REPO}/advanced/index.* /advanced/blockingpage.* /var/www/html/pihole/ + install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ echo " done!" fi From 525a1228c3c999ffc4b0dfd523c0c8b9cf3cb784 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 5 May 2017 22:43:37 +0100 Subject: [PATCH 21/35] clarify --- automated install/basic-install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 516f8ebf..df60e59f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -878,6 +878,8 @@ installPiholeWeb() { install -d /var/www/html/pihole install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ echo " done!" + else + echo "::: Custom block page detected... not overwriting!" fi echo -n "::: Backing up default lighttpd index page..." From 89fd962615339336886e3b7ad543746cb6f7f790 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 6 May 2017 11:45:31 +0100 Subject: [PATCH 22/35] Revert "Ensure any changes to blocking page are updated." --- automated install/basic-install.sh | 50 ++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 537da830..3ca90db6 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -35,7 +35,7 @@ IPV4_ADDRESS="" IPV6_ADDRESS="" QUERY_LOGGING=true INSTALL_WEB=true -CUSTOMBLOCKPAGE=false + # Find the rows and columns will default to 80x24 is it can not be detected screen_size=$(stty size 2>/dev/null || echo 24 80) @@ -866,28 +866,44 @@ CreateLogFile() { } installPiholeWeb() { - - if [ -f ${setupVars} ]; then - . ${setupVars} - fi # Install the web interface echo ":::" + echo "::: Installing pihole custom index page..." + if [ -d "/var/www/html/pihole" ]; then + if [ -f "/var/www/html/pihole/index.php" ]; then + echo "::: Existing index.php detected, not overwriting" + else + echo -n "::: index.php missing, replacing... " + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ + echo " done!" + fi - if [[ ${CUSTOMBLOCKPAGE} == false ]]; then - echo -n "::: Installing block page..." + if [ -f "/var/www/html/pihole/index.js" ]; then + echo "::: Existing index.js detected, not overwriting" + else + echo -n "::: index.js missing, replacing... " + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ + echo " done!" + fi + + if [ -f "/var/www/html/pihole/blockingpage.css" ]; then + echo "::: Existing blockingpage.css detected, not overwriting" + else + echo -n "::: blockingpage.css missing, replacing... " + cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole + echo " done!" + fi + + else + echo "::: Creating directory for blocking page" install -d /var/www/html/pihole install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + if [ -f /var/www/html/index.lighttpd.html ]; then + mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + else + printf "\n:::\tNo default index.lighttpd.html file found... not backing up" + fi echo " done!" - else - echo "::: Custom block page detected... not overwriting!" - fi - - echo -n "::: Backing up default lighttpd index page..." - if [ -f /var/www/html/index.lighttpd.html ]; then - mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig - echo " done!" - else - echo " No default index.lighttpd.html file found... not backing up" fi # Install Sudoer file From dfc32b26a6ffa1bd2ea2feac4c46b2ed683df170 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 9 May 2017 13:11:28 -0700 Subject: [PATCH 23/35] We test for dpkg lock on line 830 directly, no need for the check also in the template section. Signed-off-by: Dan Schaper --- 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 cb5dd6fc..2e3410d7 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -86,7 +86,7 @@ if command -v apt-get &> /dev/null; then #Debian Family ############################################# PKG_MANAGER="apt-get" - UPDATE_PKG_CACHE="test_dpkg_lock; ${PKG_MANAGER} update" + UPDATE_PKG_CACHE="${PKG_MANAGER} update" PKG_INSTALL=(${PKG_MANAGER} --yes --no-install-recommends install) # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" From 03201e2f201420626c61a8d8890e7079c1e35ac6 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Wed, 10 May 2017 13:07:56 +1000 Subject: [PATCH 24/35] Display FTL version & version.sh rewrite While testing to make sure `pihole -v` would output `pihole-FTL version`, I noticed some options didn't work how I expected them to. For example, if I use `pihole -v -p`, I would expect to see the version output of Pi-hole Core. Instead, I'm informed that it's an invalid option. I've had the following things in mind while rewriting this: * I'm operating under the assumption that FTL is only installed if the Admin Console is (Line 113 exit 0) * I have modified the help text to only output with `pihole -v --help` * I have modified all output to be more similar to the output style of `grep` and `curl` (Ditching ":::") Testing output: ``` w3k@MCT:~$ pihole -v Pi-hole version is v3.0.1-14-ga928cd3 (Latest: v3.0.1) Admin Console version is v3.0-9-g3760482 (Latest: v3.0.1) FTL version is v2.6.2 (Latest: v2.6.2) w3k@MCT:~$ pihole -v -c Current Pi-hole version is v3.0.1-14-ga928cd3 Current Admin Console version is v3.0-9-g3760482 Current FTL version is v2.6.2 w3k@MCT:~$ pihole -v -l Latest Pi-hole version is v3.0.1 Latest Admin Console version is v3.0.1 Latest FTL version is v2.6.2 w3k@MCT:~$ pihole -v -p --hash Current Pi-hole hash is a928cd3 w3k@MCT:~$ pihole -v -a --hash Current Admin Console hash is 3760482 w3k@MCT:~$ pihole -v --help Usage: pihole -v [REPO | OPTION] [OPTION] Show Pi-hole, Web Admin & FTL versions w3k@MCT:~$ pihole -v -foo Invalid Option! ``` --- advanced/Scripts/version.sh | 127 +++++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 53 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 7f96e29a..289e4d93 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -66,72 +66,93 @@ getRemoteVersion(){ return 0 } -#PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ -# grep sha | \ -# head -n1 | \ -# awk -F ' ' '{ print $2 }' | \ -# tr -cd '[[:alnum:]]._-') - -#WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ -# grep sha | \ -# head -n1 | \ -# awk -F ' ' '{ print $2 }' | \ -# tr -cd '[[:alnum:]]._-') - - -normalOutput() { - echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))" - if [ -d "${WEBGITDIR}" ]; then - echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" - fi +coreOutput() { + [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${PHGITDIR})" + [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion pi-hole)" + [ "$1" = "--hash" ] && hash="$(getLocalHash ${PHGITDIR})" + + if [ -n "$current" -a -n "$latest" ]; then + str="Pi-hole version is $current (Latest: $latest)" + elif [ -n "$current" -a -z "$latest" ]; then + str="Current Pi-hole version is $current" + elif [ -z "$current" -a -n "$latest" ]; then + str="Latest Pi-hole version is $latest" + elif [ -n "$hash" ]; then + str="Current Pi-hole hash is $hash" + else + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 + fi + echo " $str" } webOutput() { - if [ -d "${WEBGITDIR}" ]; then - case "${1}" in - "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; - "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; - "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; - * ) echo "::: Invalid Option!"; exit 1; - esac + [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${WEBGITDIR})" + [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion AdminLTE)" + [ "$1" = "--hash" ] && hash="$(getLocalHash ${WEBGITDIR})" + [ ! -d "${WEBGITDIR}" ] && str="Web interface not installed!" + + if [ -n "$current" -a -n "$latest" ]; then + str="Admin Console version is $current (Latest: $latest)" + elif [ -n "$current" -a -z "$latest" ]; then + str="Current Admin Console version is $current" + elif [ -z "$current" -a -n "$latest" ]; then + str="Latest Admin Console version is $latest" + elif [ -n "$hash" ]; then + str="Current Admin Console hash is $hash" else - echo "::: Web interface not installed!"; exit 1; + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 fi + echo " $str" } -coreOutput() { - case "${1}" in - "-l" | "--latest" ) echo $(getRemoteVersion pi-hole);; - "-c" | "--current" ) echo $(getLocalVersion "${PHGITDIR}");; - "-h" | "--hash" ) echo $(getLocalHash "${PHGITDIR}");; - * ) echo "::: Invalid Option!"; exit 1; - esac +ftlOutput() { + [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(pihole-FTL version)" + [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion FTL)" + [ ! -d "${WEBGITDIR}" ] && exit 0 + + if [ -n "$current" -a -n "$latest" ]; then + str="FTL version is $current (Latest: $latest)" + elif [ -n "$current" -a -z "$latest" ]; then + str="Current FTL version is $current" + elif [ -z "$current" -a -n "$latest" ]; then + str="Latest FTL version is $latest" + else + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 + fi + echo " $str" +} + +defaultOutput() { + coreOutput "$1" + webOutput "$1" + ftlOutput "$1" } helpFunc() { - cat << EOM -::: -::: Show Pi-hole/Web Admin versions -::: -::: Usage: pihole -v [ -a | -p ] [ -l | -c ] -::: -::: Options: -::: -a, --admin Show both current and latest versions of web admin -::: -p, --pihole Show both current and latest versions of Pi-hole core files -::: -l, --latest (Only after -a | -p) Return only latest version -::: -c, --current (Only after -a | -p) Return only current version -::: -h, --help Show this help dialog -::: -EOM + echo "Usage: pihole -v [REPO | OPTION] [OPTION] +Show Pi-hole, Web Admin & FTL versions + +Repositories: + -a, --admin Show both current and latest versions of Web Admin + -f, --ftl Show both current and latest versions of FTL + -p, --pihole Show both current and latest versions of Pi-hole Core + +Options: + -c, --current (Only after -a | -p | -f) Return the current version + -l, --latest (Only after -a | -p | -f) Return the latest version + -h, --hash (Only after -a | -p) Return the current Github hash + --help Show this help dialog +" exit 0 } -if [[ $# = 0 ]]; then - normalOutput -fi - case "${1}" in "-a" | "--admin" ) shift; webOutput "$@";; - "-p" | "--pihole" ) shift; coreOutput "$@" ;; - "-h" | "--help" ) helpFunc;; + "-p" | "--pihole" ) shift; coreOutput "$@";; + "-f" | "--ftl" ) shift; ftlOutput "$@";; + "--help" ) helpFunc;; + * ) defaultOutput "$@";; esac From fe0a35cc7ab50f54f465b6571a3dcefa8f6f1472 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 11 May 2017 08:30:49 +1000 Subject: [PATCH 25/35] Update -h to work as --hash Also provide error output as per https://github.com/pi-hole/pi-hole/pull/1447#issuecomment-300600093 --- advanced/Scripts/version.sh | 43 ++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 289e4d93..9b878c8e 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -69,8 +69,9 @@ getRemoteVersion(){ coreOutput() { [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${PHGITDIR})" [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion pi-hole)" - [ "$1" = "--hash" ] && hash="$(getLocalHash ${PHGITDIR})" - + [ "$1" = "-h" -o "$1" = "--hash" ] && hash="$(getLocalHash ${PHGITDIR})" + [ -n "$2" ] && error="true" + if [ -n "$current" -a -n "$latest" ]; then str="Pi-hole version is $current (Latest: $latest)" elif [ -n "$current" -a -z "$latest" ]; then @@ -80,17 +81,24 @@ coreOutput() { elif [ -n "$hash" ]; then str="Current Pi-hole hash is $hash" else - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 + error="true" fi + + if [ "$error" = "true" ]; then + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 + fi + echo " $str" } webOutput() { [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${WEBGITDIR})" [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion AdminLTE)" - [ "$1" = "--hash" ] && hash="$(getLocalHash ${WEBGITDIR})" + [ "$1" = "-h" -o "$1" = "--hash" ] && hash="$(getLocalHash ${WEBGITDIR})" [ ! -d "${WEBGITDIR}" ] && str="Web interface not installed!" + [ -n "$2" ] && error="true" + if [ -n "$current" -a -n "$latest" ]; then str="Admin Console version is $current (Latest: $latest)" @@ -101,9 +109,14 @@ webOutput() { elif [ -n "$hash" ]; then str="Current Admin Console hash is $hash" else - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 + error="true" fi + + if [ "$error" = "true" ]; then + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 + fi + echo " $str" } @@ -111,6 +124,7 @@ ftlOutput() { [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(pihole-FTL version)" [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion FTL)" [ ! -d "${WEBGITDIR}" ] && exit 0 + [ -n "$2" ] && error="true" if [ -n "$current" -a -n "$latest" ]; then str="FTL version is $current (Latest: $latest)" @@ -119,16 +133,21 @@ ftlOutput() { elif [ -z "$current" -a -n "$latest" ]; then str="Latest FTL version is $latest" else - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 + error="true" fi + + if [ "$error" = "true" ]; then + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 + fi + echo " $str" } defaultOutput() { - coreOutput "$1" - webOutput "$1" - ftlOutput "$1" + coreOutput "$1" "$2" + webOutput "$1" "$2" + ftlOutput "$1" "$2" } helpFunc() { From 3081c151bd1e88d12ef527d40075cbfc7a18d890 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 11 May 2017 09:13:32 +1000 Subject: [PATCH 26/35] Perform EXACT searches on HOSTS lists correctly `\s` on the end may be overkill, but it is the existing scanList() behaviour. --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index eaf4e955..6bd5fb1f 100755 --- a/pihole +++ b/pihole @@ -86,7 +86,7 @@ scanList(){ method="${3}" if [[ ${method} == "-exact" ]]; then - grep -i -E -l "(^|\/)${domain}($|\/)" ${list} + grep -i -E -l "(^|\s|\/)${domain}($|\s|\/)" ${list} else grep -i "${domain}" ${list} fi From 7fef1fdc831db0c3bafba4c53a888cc492c63c87 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 11 May 2017 10:11:04 +1000 Subject: [PATCH 27/35] Fixed indentation --- advanced/Scripts/version.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 9b878c8e..62106342 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -81,12 +81,12 @@ coreOutput() { elif [ -n "$hash" ]; then str="Current Pi-hole hash is $hash" else - error="true" + error="true" fi if [ "$error" = "true" ]; then - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 fi echo " $str" @@ -109,12 +109,12 @@ webOutput() { elif [ -n "$hash" ]; then str="Current Admin Console hash is $hash" else - error="true" + error="true" fi if [ "$error" = "true" ]; then - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 fi echo " $str" @@ -133,12 +133,12 @@ ftlOutput() { elif [ -z "$current" -a -n "$latest" ]; then str="Latest FTL version is $latest" else - error="true" + error="true" fi if [ "$error" = "true" ]; then - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 fi echo " $str" From 2863308090296a43ae69c7ecc4f1ef176b756090 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 11 May 2017 13:34:58 +1000 Subject: [PATCH 28/35] Minimise string duplication & other minor changes Instead of duplicating output strings, rewrite core/web/ftlOutput() into one neat versionOutput(). --- advanced/Scripts/version.sh | 123 +++++++++++++----------------------- 1 file changed, 44 insertions(+), 79 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 62106342..8ab95367 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -10,10 +10,16 @@ # Variables DEFAULT="-1" -PHGITDIR="/etc/.pihole/" +COREGITDIR="/etc/.pihole/" WEBGITDIR="/var/www/html/admin/" getLocalVersion() { + # FTL requires a different method + if [ "$1" == "FTL" ]; then + echo $(pihole-FTL version) + return 0 + fi + # Get the tagged version of the local repository local directory="${1}" local version @@ -33,6 +39,12 @@ getLocalVersion() { } getLocalHash() { + # FTL hash is not applicable + if [ "$1" == "FTL" ]; then + echo "N/A" + return 0 + fi + # Get the short hash of the local repository local directory="${1}" local hash @@ -66,88 +78,41 @@ getRemoteVersion(){ return 0 } -coreOutput() { - [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${PHGITDIR})" - [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion pi-hole)" - [ "$1" = "-h" -o "$1" = "--hash" ] && hash="$(getLocalHash ${PHGITDIR})" - [ -n "$2" ] && error="true" - - if [ -n "$current" -a -n "$latest" ]; then - str="Pi-hole version is $current (Latest: $latest)" - elif [ -n "$current" -a -z "$latest" ]; then - str="Current Pi-hole version is $current" - elif [ -z "$current" -a -n "$latest" ]; then - str="Latest Pi-hole version is $latest" - elif [ -n "$hash" ]; then - str="Current Pi-hole hash is $hash" - else - error="true" - fi - - if [ "$error" = "true" ]; then - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 - fi - - echo " $str" -} - -webOutput() { - [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(getLocalVersion ${WEBGITDIR})" - [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion AdminLTE)" - [ "$1" = "-h" -o "$1" = "--hash" ] && hash="$(getLocalHash ${WEBGITDIR})" - [ ! -d "${WEBGITDIR}" ] && str="Web interface not installed!" - [ -n "$2" ] && error="true" - +versionOutput() { + [ "$1" == "pi-hole" ] && GITDIR=${COREGITDIR} + [ "$1" == "AdminLTE" ] && GITDIR=${WEBGITDIR} + [ "$1" == "FTL" ] && GITDIR="FTL" + [ "$2" == "-c" -o "$2" == "--current" -o -z "$2" ] && current=$(getLocalVersion $GITDIR) + [ "$2" == "-l" -o "$2" == "--latest" -o -z "$2" ] && latest=$(getRemoteVersion $1) + [ "$2" == "-h" -o "$2" == "--hash" ] && hash=$(getLocalHash $GITDIR) + if [ -n "$current" -a -n "$latest" ]; then - str="Admin Console version is $current (Latest: $latest)" + output="${1^} version is $current (Latest: $latest)" elif [ -n "$current" -a -z "$latest" ]; then - str="Current Admin Console version is $current" + output="Current ${1^} version is $current" elif [ -z "$current" -a -n "$latest" ]; then - str="Latest Admin Console version is $latest" + output="Latest ${1^} version is $latest" + elif [ "$hash" == "N/A" ]; then + output="" elif [ -n "$hash" ]; then - str="Current Admin Console hash is $hash" + output="Current ${1^} hash is $hash" else - error="true" + errorOutput fi - if [ "$error" = "true" ]; then - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 - fi - - echo " $str" + [ -n "$output" ] && echo " $output" } -ftlOutput() { - [ "$1" = "-c" -o "$1" = "--current" -o -z "$1" ] && current="$(pihole-FTL version)" - [ "$1" = "-l" -o "$1" = "--latest" -o -z "$1" ] && latest="$(getRemoteVersion FTL)" - [ ! -d "${WEBGITDIR}" ] && exit 0 - [ -n "$2" ] && error="true" - - if [ -n "$current" -a -n "$latest" ]; then - str="FTL version is $current (Latest: $latest)" - elif [ -n "$current" -a -z "$latest" ]; then - str="Current FTL version is $current" - elif [ -z "$current" -a -n "$latest" ]; then - str="Latest FTL version is $latest" - else - error="true" - fi - - if [ "$error" = "true" ]; then - echo " Invalid Option! Try 'pihole -v --help' for more information." - exit 1 - fi - - echo " $str" +errorOutput() { + echo " Invalid Option! Try 'pihole -v --help' for more information." + exit 1 } defaultOutput() { - coreOutput "$1" "$2" - webOutput "$1" "$2" - ftlOutput "$1" "$2" + versionOutput "pi-hole" "$@" + versionOutput "AdminLTE" "$@" + versionOutput "FTL" "$@" } helpFunc() { @@ -155,23 +120,23 @@ helpFunc() { Show Pi-hole, Web Admin & FTL versions Repositories: - -a, --admin Show both current and latest versions of Web Admin - -f, --ftl Show both current and latest versions of FTL - -p, --pihole Show both current and latest versions of Pi-hole Core + -p, --pihole Only retrieve info regarding Pi-hole repository + -a, --admin Only retrieve info regarding AdminLTE repository + -f, --ftl Only retrieve info regarding FTL repository Options: - -c, --current (Only after -a | -p | -f) Return the current version - -l, --latest (Only after -a | -p | -f) Return the latest version - -h, --hash (Only after -a | -p) Return the current Github hash + -c, --current Return the current version + -l, --latest Return the latest version + -h, --hash Return the Github hash from your local repositories --help Show this help dialog " exit 0 } case "${1}" in - "-a" | "--admin" ) shift; webOutput "$@";; - "-p" | "--pihole" ) shift; coreOutput "$@";; - "-f" | "--ftl" ) shift; ftlOutput "$@";; + "-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";; + "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";; + "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; "--help" ) helpFunc;; * ) defaultOutput "$@";; esac From c6596f2c5481d5d266b0bb25db2e9b38dff9f6da Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 11 May 2017 14:19:13 +1000 Subject: [PATCH 29/35] Modified syntax to be valid for Shellcheck --- advanced/Scripts/version.sh | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 8ab95367..923d86d8 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -16,7 +16,7 @@ WEBGITDIR="/var/www/html/admin/" getLocalVersion() { # FTL requires a different method if [ "$1" == "FTL" ]; then - echo $(pihole-FTL version) + pihole-FTL version return 0 fi @@ -25,8 +25,7 @@ getLocalVersion() { local version cd "${directory}" || { echo "${DEFAULT}"; return 1; } - version=$(git describe --tags --always || \ - echo "${DEFAULT}") + version=$(git describe --tags --always || echo "$DEFAULT") if [[ "${version}" =~ ^v ]]; then echo "${version}" elif [[ "${version}" == "${DEFAULT}" ]]; then @@ -50,8 +49,7 @@ getLocalHash() { local hash cd "${directory}" || { echo "${DEFAULT}"; return 1; } - hash=$(git rev-parse --short HEAD || \ - echo "${DEFAULT}") + hash=$(git rev-parse --short HEAD || echo "$DEFAULT") if [[ "${hash}" == "${DEFAULT}" ]]; then echo "ERROR" return 1 @@ -66,7 +64,7 @@ getRemoteVersion(){ local daemon="${1}" local version - version=$(curl --silent --fail https://api.github.com/repos/pi-hole/${daemon}/releases/latest | \ + version=$(curl --silent --fail "https://api.github.com/repos/pi-hole/${daemon}/releases/latest" | \ awk -F: '$1 ~/tag_name/ { print $2 }' | \ tr -cd '[[:alnum:]]._-') if [[ "${version}" =~ ^v ]]; then @@ -79,19 +77,19 @@ getRemoteVersion(){ } versionOutput() { - [ "$1" == "pi-hole" ] && GITDIR=${COREGITDIR} - [ "$1" == "AdminLTE" ] && GITDIR=${WEBGITDIR} + [ "$1" == "pi-hole" ] && GITDIR=$COREGITDIR + [ "$1" == "AdminLTE" ] && GITDIR=$WEBGITDIR [ "$1" == "FTL" ] && GITDIR="FTL" - [ "$2" == "-c" -o "$2" == "--current" -o -z "$2" ] && current=$(getLocalVersion $GITDIR) - [ "$2" == "-l" -o "$2" == "--latest" -o -z "$2" ] && latest=$(getRemoteVersion $1) - [ "$2" == "-h" -o "$2" == "--hash" ] && hash=$(getLocalHash $GITDIR) + [ "$2" == "-c" ] || [ "$2" == "--current" ] || [ -z "$2" ] && current=$(getLocalVersion $GITDIR) + [ "$2" == "-l" ] || [ "$2" == "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "$1") + [ "$2" == "-h" ] || [ "$2" == "--hash" ] && hash=$(getLocalHash "$GITDIR") - if [ -n "$current" -a -n "$latest" ]; then + if [ -n "$current" ] && [ -n "$latest" ]; then output="${1^} version is $current (Latest: $latest)" - elif [ -n "$current" -a -z "$latest" ]; then + elif [ -n "$current" ] && [ -z "$latest" ]; then output="Current ${1^} version is $current" - elif [ -z "$current" -a -n "$latest" ]; then + elif [ -z "$current" ] && [ -n "$latest" ]; then output="Latest ${1^} version is $latest" elif [ "$hash" == "N/A" ]; then output="" From 501b26decdeff6ba2131bf85fadf243dde49f1b3 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 10 May 2017 22:08:06 -0700 Subject: [PATCH 30/35] Log and echo gateway responses --- advanced/Scripts/piholeDebug.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 10dd1e8b..8020cc80 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -260,18 +260,18 @@ ip_ping_check() { if [[ -n ${ip_def_gateway} ]]; then echo -n "::: Pinging default IPv${protocol} gateway: " if ! ping_gateway="$(${cmd} -q -W 3 -c 3 -n ${ip_def_gateway} -I ${PIHOLE_INTERFACE} | tail -n 3)"; then - echo "Gateway did not respond." + log_echo "Gateway did not respond." return 1 else - echo "Gateway responded." + log_echo "Gateway responded." log_write "${ping_gateway}" fi echo -n "::: Pinging Internet via IPv${protocol}: " if ! ping_inet="$(${cmd} -q -W 3 -c 3 -n ${g_addr} -I ${PIHOLE_INTERFACE} | tail -n 3)"; then - echo "Query did not respond." + log_echo "Query did not respond." return 1 else - echo "Query responded." + log_echo "Query responded." log_write "${ping_inet}" fi else From 58353e28399c1e36568526475d71114558db392c Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 11 May 2017 19:58:35 +1000 Subject: [PATCH 31/35] Update queryFunc() to search Whitelist If there is a match in Whitelist/Blacklist/Wildcards, `[ ! -t 1 ]` will cause the search to end if the terminal is closed when the script is called. This has the intended effect of allowing a user to search for a W/B/W domain (as well as all the adlists it's found in) using `pihole -q` via Terminal, but the script will stop searching after a W/B/W match when called by the block page. --- pihole | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pihole b/pihole index 6bd5fb1f..95dd7a1c 100755 --- a/pihole +++ b/pihole @@ -106,12 +106,12 @@ queryFunc() { domain="${2}" fi - # Scan Blacklist and Wildcards - lists="/etc/pihole/blacklist.txt $wildcardlist" + # Scan Whitelist, Blacklist and Wildcards + lists="/etc/pihole/whitelist.txt /etc/pihole/blacklist.txt $wildcardlist" result=$(scanList ${domain} "${lists}" ${method}) if [ -n "$result" ]; then echo "$result" - exit 0 + [ ! -t 1 ] && exit 0 fi # Scan Domains lists From c35c7b2cea71a629805e89803618ce754d058eba Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Thu, 11 May 2017 20:21:23 +1000 Subject: [PATCH 32/35] Wrap in double brackets --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index 95dd7a1c..4fafe27a 100755 --- a/pihole +++ b/pihole @@ -111,7 +111,7 @@ queryFunc() { result=$(scanList ${domain} "${lists}" ${method}) if [ -n "$result" ]; then echo "$result" - [ ! -t 1 ] && exit 0 + [[ ! -t 1 ]] && exit 0 fi # Scan Domains lists From ea0a9ceb37d8d58ba19a1238cfd85de8844bfcf5 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Fri, 12 May 2017 15:25:01 +1000 Subject: [PATCH 33/35] Provide remote hashes for version.sh * Provide remote hashes for comparison * Use double braces for all conditions (for consistency) * Suppress potential "cd" error output * Provide "not applicable" output upon any hash request for FTL --- advanced/Scripts/version.sh | 66 ++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 19 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 923d86d8..cd4054fb 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -15,7 +15,7 @@ WEBGITDIR="/var/www/html/admin/" getLocalVersion() { # FTL requires a different method - if [ "$1" == "FTL" ]; then + if [[ "$1" == "FTL" ]]; then pihole-FTL version return 0 fi @@ -24,7 +24,7 @@ getLocalVersion() { local directory="${1}" local version - cd "${directory}" || { echo "${DEFAULT}"; return 1; } + cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } version=$(git describe --tags --always || echo "$DEFAULT") if [[ "${version}" =~ ^v ]]; then echo "${version}" @@ -38,8 +38,8 @@ getLocalVersion() { } getLocalHash() { - # FTL hash is not applicable - if [ "$1" == "FTL" ]; then + # Local FTL hash does not exist on filesystem + if [[ "$1" == "FTL" ]]; then echo "N/A" return 0 fi @@ -48,7 +48,7 @@ getLocalHash() { local directory="${1}" local hash - cd "${directory}" || { echo "${DEFAULT}"; return 1; } + cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } hash=$(git rev-parse --short HEAD || echo "$DEFAULT") if [[ "${hash}" == "${DEFAULT}" ]]; then echo "ERROR" @@ -59,6 +59,27 @@ getLocalHash() { return 0 } +getRemoteHash(){ + # Remote FTL hash is not applicable + if [[ "$1" == "FTL" ]]; then + echo "N/A" + return 0 + fi + + local daemon="${1}" + local branch="${2}" + + hash=$(git ls-remote --heads "https://github.com/pi-hole/${daemon}" | \ + awk -v bra="$branch" '$0~bra {print substr($0,0,8);exit}') + if [[ -n "$hash" ]]; then + echo "$hash" + else + echo "ERROR" + return 1 + fi + return 0 +} + getRemoteVersion(){ # Get the version from the remote origin local daemon="${1}" @@ -77,29 +98,36 @@ getRemoteVersion(){ } versionOutput() { - [ "$1" == "pi-hole" ] && GITDIR=$COREGITDIR - [ "$1" == "AdminLTE" ] && GITDIR=$WEBGITDIR - [ "$1" == "FTL" ] && GITDIR="FTL" + [[ "$1" == "pi-hole" ]] && GITDIR=$COREGITDIR + [[ "$1" == "AdminLTE" ]] && GITDIR=$WEBGITDIR + [[ "$1" == "FTL" ]] && GITDIR="FTL" - [ "$2" == "-c" ] || [ "$2" == "--current" ] || [ -z "$2" ] && current=$(getLocalVersion $GITDIR) - [ "$2" == "-l" ] || [ "$2" == "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "$1") - [ "$2" == "-h" ] || [ "$2" == "--hash" ] && hash=$(getLocalHash "$GITDIR") + [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR) + [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "$1") + if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then + [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "$GITDIR") + [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "$1" "$(cd "$GITDIR" 2> /dev/null && git rev-parse --abbrev-ref HEAD)") + fi - if [ -n "$current" ] && [ -n "$latest" ]; then + if [[ -n "$current" ]] && [[ -n "$latest" ]]; then output="${1^} version is $current (Latest: $latest)" - elif [ -n "$current" ] && [ -z "$latest" ]; then + elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then output="Current ${1^} version is $current" - elif [ -z "$current" ] && [ -n "$latest" ]; then + elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then output="Latest ${1^} version is $latest" - elif [ "$hash" == "N/A" ]; then - output="" - elif [ -n "$hash" ]; then - output="Current ${1^} hash is $hash" + elif [[ "$curHash" == "N/A" ]] || [[ "$latHash" == "N/A" ]]; then + output="${1^} hash is not applicable" + elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then + output="${1^} hash is $curHash (Latest: $latHash)" + elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then + output="Current ${1^} hash is $curHash" + elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then + output="Latest ${1^} hash is $latHash" else errorOutput fi - [ -n "$output" ] && echo " $output" + [[ -n "$output" ]] && echo " $output" } errorOutput() { From 31d5a7ae9ea77e4174da0c1010c5538ef1ebeff9 Mon Sep 17 00:00:00 2001 From: 0412465564 Date: Fri, 12 May 2017 22:29:07 +0200 Subject: [PATCH 34/35] whitelist on website blocked doesnt work (#1452) Since Pi-hole redirects ad domains to itself, accessing the script via de.ign.com is the same as pi.hole in this case. The fix should be as simple as adding a / before admin on this line. --- advanced/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index bfc44a1d..1dd5acc7 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -185,7 +185,7 @@ function add() { } $.ajax({ - url: "admin/scripts/pi-hole/php/add.php", + url: "/admin/scripts/pi-hole/php/add.php", method: "post", data: {"domain":domain.val(), "list":"white", "pw":pw.val()}, success: function(response) { From b166410cbf71f8ef1e9e5519f8f446a8b626b0e2 Mon Sep 17 00:00:00 2001 From: Hans Geiblinger Date: Fri, 12 May 2017 16:39:55 -0400 Subject: [PATCH 35/35] Solve piholeLogFlush.sh having to be issued 2 x to clear logs (#1460) Simplified the command -v syntax, and added a sleep 3 timer to the first execution of the log rotation. The second execution was being issued while the first was still running, thus it would fail and you would have to issue the "Flush Logs" command a second time. --- 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 fd66b255..8e4c8266 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -10,9 +10,9 @@ echo -n "::: Flushing /var/log/pihole.log ..." # Test if logrotate is available on this system -if command -v /usr/sbin/logrotate &> /dev/null; then +if command -v /usr/sbin/logrotate >/dev/null; then # Flush twice to move all data out of sight of FTL - /usr/sbin/logrotate --force /etc/pihole/logrotate + /usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3 /usr/sbin/logrotate --force /etc/pihole/logrotate else # Flush both pihole.log and pihole.log.1 (if existing)