From 697b0295f39ba135338a8ac2a54dd1749ee9b8cf Mon Sep 17 00:00:00 2001 From: Technicalpyro Date: Sun, 26 Feb 2017 14:24:08 -0600 Subject: [PATCH 001/109] fixes missing dialog package from some ditros --- 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 f168675e..8e8266b8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -80,7 +80,7 @@ if command -v apt-get &> /dev/null; then fi # ######################################### INSTALLER_DEPS=(apt-utils debconf dhcpcd5 git ${iproute_pkg} whiptail) - PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) + PIHOLE_DEPS=(bc cron curl dialog dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi) LIGHTTPD_USER="www-data" LIGHTTPD_GROUP="www-data" @@ -100,7 +100,7 @@ elif command -v rpm &> /dev/null; then PKG_INSTALL=(${PKG_MANAGER} install -y) PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" INSTALLER_DEPS=(git iproute net-tools newt procps-ng) - PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils nmap-ncat sudo unzip wget) + PIHOLE_DEPS=(bc bind-utils cronie curl dialog dnsmasq findutils nmap-ncat sudo unzip wget) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli) if ! grep -q 'Fedora' /etc/redhat-release; then INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release"); From 93dea7b942fff5bff9497cce07cd2bd3a2cfa869 Mon Sep 17 00:00:00 2001 From: Technicalpyro Date: Mon, 27 Feb 2017 15:21:59 -0500 Subject: [PATCH 002/109] Moved to installers dependencies --- automated install/basic-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8e8266b8..9b401203 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -79,8 +79,8 @@ if command -v apt-get &> /dev/null; then phpVer="php5" fi # ######################################### - INSTALLER_DEPS=(apt-utils debconf dhcpcd5 git ${iproute_pkg} whiptail) - PIHOLE_DEPS=(bc cron curl dialog dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) + INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail) + PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi) LIGHTTPD_USER="www-data" LIGHTTPD_GROUP="www-data" @@ -99,8 +99,8 @@ elif command -v rpm &> /dev/null; then UPDATE_PKG_CACHE=":" PKG_INSTALL=(${PKG_MANAGER} install -y) PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" - INSTALLER_DEPS=(git iproute net-tools newt procps-ng) - PIHOLE_DEPS=(bc bind-utils cronie curl dialog dnsmasq findutils nmap-ncat sudo unzip wget) + INSTALLER_DEPS=(dialog git iproute net-tools newt procps-ng) + PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils nmap-ncat sudo unzip wget) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli) if ! grep -q 'Fedora' /etc/redhat-release; then INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release"); From eb763d2dc2da197c2a42a9440e86dd632b7d177a Mon Sep 17 00:00:00 2001 From: raincoats Date: Sun, 5 Mar 2017 16:58:21 +1100 Subject: [PATCH 003/109] Redirect to admin panel when accessing 'http://pi.hole/' If someone tries to access 'http://pi.hole/', it will take them to the "Website blocked" page. Very confusing if you don't know to go to 'http://pi.hole/admin/'. This just redirects them to the admin panel. --- advanced/index.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/advanced/index.php b/advanced/index.php index c076f92d..05b0811f 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -4,6 +4,14 @@ $uri = escapeshellcmd($_SERVER['REQUEST_URI']); $serverName = escapeshellcmd($_SERVER['SERVER_NAME']); +// If the server name is 'pi.hole', it's likely a user trying to get to the admin panel. +// Let's be nice and redirect them. +if ($serverName === 'pi.hole') +{ + header('HTTP/1.1 302 Found'); + header("Location: /admin/"); +} + // Retrieve server URI extension (EG: jpg, exe, php) $uriExt = pathinfo($uri, PATHINFO_EXTENSION); From 1590a179fa37fb8157f5a89639c776034322f13f Mon Sep 17 00:00:00 2001 From: raincoats Date: Thu, 9 Mar 2017 17:38:56 +1100 Subject: [PATCH 004/109] Change 302 redirect to 301 Change "302 Found" response to "301 Moved Permanently", as "302 Found" is meant for temporary redirects. Was asked to do so in this comment: https://github.com/pi-hole/pi-hole/pull/1297#issuecomment-284335421 --- advanced/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index 05b0811f..99f8c1f8 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -8,7 +8,7 @@ $serverName = escapeshellcmd($_SERVER['SERVER_NAME']); // Let's be nice and redirect them. if ($serverName === 'pi.hole') { - header('HTTP/1.1 302 Found'); + header('HTTP/1.1 301 Moved Permanently'); header("Location: /admin/"); } From 9a95531fb917835dfa86994d3476c8a80287d1a4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Mar 2017 00:43:35 +0100 Subject: [PATCH 005/109] Merge pull request #1310 from pi-hole/new/piholecheckout Pi-hole checkout feature --- advanced/Scripts/piholeCheckout.sh | 163 +++++++++++++++++++++++++++++ advanced/bash-completion/pihole | 2 +- pihole | 11 +- 3 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 advanced/Scripts/piholeCheckout.sh diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh new file mode 100644 index 00000000..86ea9a2b --- /dev/null +++ b/advanced/Scripts/piholeCheckout.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2017 Pi-hole, LLC (https://pi-hole.net) +# Network-wide ad blocking via your own hardware. +# +# Checkout other branches than master +# +# This file is copyright under the latest version of the EUPL. +# Please see LICENSE file for your rights under this license. + +readonly PI_HOLE_FILES_DIR="/etc/.pihole" +PH_TEST="true" source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh + +# webInterfaceGitUrl set in basic-install.sh +# webInterfaceDir set in basic-install.sh +# piholeGitURL set in basic-install.sh +# is_repo() sourced from basic-install.sh + +fully_fetch_repo() { + # Add upstream branches to shallow clone + local directory="${1}" + + cd "${directory}" || return 1 + if is_repo "${directory}"; then + git remote set-branches origin '*' || return 1 + git fetch --quiet || return 1 + else + return 1 + fi + return 0 +} + +get_available_branches(){ + # Return available branches + local directory="${1}" + local curdir + + curdir="${PWD}" + cd "${directory}" || return 1 + # Get reachable remote branches + git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g' + cd "${curdir}" || return 1 + return +} + +checkout_pull_branch() { + # Check out specified branch + local directory="${1}" + local branch="${2}" + local curdir + + curdir="${PWD}" + cd "${directory}" || return 1 + git checkout "${branch}" + git pull + cd "${curdir}" || return 1 + return +} + +warning1() { + echo "::: Note that changing the branch is a severe change of your Pi-hole system." + echo "::: This is not supported unless one of the developers explicitly asks you to do this!" + read -r -p "::: Have you read and understood this? [y/N] " response + case ${response} in + [yY][eE][sS]|[yY]) + echo "::: Continuing." + return 0 + ;; + *) + echo "::: Aborting." + return 1 + ;; + esac +} + +checkout() +{ + local corebranches + local webbranches + + # Avoid globbing + set -f + + #This is unlikely + if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${webInterfaceDir}" ; then + echo "::: Critical Error: One or more Pi-Hole repos are missing from your system!" + echo "::: Please re-run the install script from https://github.com/pi-hole/pi-hole" + exit 1 + fi + + if ! warning1 ; then + exit 1 + fi + + echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " + if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then + echo "::: Fetching all branches for Pi-hole core repo failed!" + exit 1 + fi + corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) + echo " done!" + echo "::: ${#corebranches[@]} branches available" + echo ":::" + + echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " + if ! fully_fetch_repo "${webInterfaceDir}" ; then + echo "::: Fetching all branches for Pi-hole web interface repo failed!" + exit 1 + fi + webbranches=($(get_available_branches "${webInterfaceDir}")) + echo " done!" + echo "::: ${#webbranches[@]} branches available" + echo ":::" + + if [[ "${1}" == "dev" ]] ; then + # Shortcut to check out development branches + echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." + echo "::: Pi-hole core" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" + echo "::: Web interface" + checkout_pull_branch "${webInterfaceDir}" "devel" + echo "::: done!" + elif [[ "${1}" == "master" ]] ; then + # Shortcut to check out master branches + echo "::: Shortcut \"master\" detected - checking out master branches ..." + echo "::: Pi-hole core" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" + echo "::: Web interface" + checkout_pull_branch "${webInterfaceDir}" "master" + echo "::: done!" + elif [[ "${1}" == "core" ]] ; then + # Have to user chosing the branch he wants + if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then + echo "::: Requested branch \"${2}\" is not available!" + echo "::: Available branches for core are:" + for e in "${corebranches[@]}"; do echo "::: $e"; done + exit 1 + fi + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" + elif [[ "${1}" == "web" ]] ; then + # Have to user chosing the branch he wants + if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then + echo "::: Requested branch \"${2}\" is not available!" + echo "::: Available branches for web are:" + for e in "${webbranches[@]}"; do echo "::: $e"; done + exit 1 + fi + checkout_pull_branch "${webInterfaceDir}" "${2}" + else + echo "::: Requested option \"${1}\" is not available!" + exit 1 + fi + + # Force updating everything + echo "::: Running installer to upgrade your installation" + if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then + exit 0 + else + echo "Unable to complete update, contact Pi-hole" + exit 1 + fi +} + diff --git a/advanced/bash-completion/pihole b/advanced/bash-completion/pihole index 05baa820..fc8f2162 100644 --- a/advanced/bash-completion/pihole +++ b/advanced/bash-completion/pihole @@ -3,7 +3,7 @@ _pihole() { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="admin blacklist chronometer debug disable enable flush help logging query reconfigure restartdns setupLCD status tail uninstall updateGravity updatePihole version whitelist" + opts="admin blacklist chronometer debug disable enable flush help logging query reconfigure restartdns setupLCD status tail uninstall updateGravity updatePihole version whitelist checkout" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 diff --git a/pihole b/pihole index 41946f35..97f749ab 100755 --- a/pihole +++ b/pihole @@ -8,9 +8,8 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. +readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" - -PI_HOLE_SCRIPT_DIR="/opt/pihole" readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then @@ -278,6 +277,12 @@ tailFunc() { exit 0 } +piholeCheckoutFunc() { + source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh + shift + checkout "$@" +} + helpFunc() { cat << EOM ::: Control all PiHole specific functions! @@ -311,6 +316,7 @@ helpFunc() { ::: Blocking can also be disabled only temporarily, e.g., ::: 'pihole disable 5m' - will disable blocking for 5 minutes ::: restartdns Restart dnsmasq +::: checkout Check out different branches EOM exit 0 } @@ -341,5 +347,6 @@ case "${1}" in "restartdns" ) restartDNS;; "-a" | "admin" ) webpageFunc "$@";; "-t" | "tail" ) tailFunc;; + "checkout" ) piholeCheckoutFunc "$@";; * ) helpFunc;; esac From 0fe64cf5cc14e614cd03d53a1c3bffcfe39f07e9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 16:16:42 +0100 Subject: [PATCH 006/109] Merge pull request #1300 from pi-hole/fix/deletehostrecord Bugfix for when deleting host-record --- 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 a21300ad..5f032ed1 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -134,7 +134,7 @@ trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE3 delete_dnsmasq_setting "host-record" - if [ ! -z "${HOSTRECORD+x}" ]; then + if [ ! -z "${HOSTRECORD}" ]; then add_dnsmasq_setting "host-record" "${HOSTRECORD}" fi From de6aaf18abf414f297abd09f30e767a37341bc37 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 17:03:34 +0100 Subject: [PATCH 007/109] Merge pull request #1302 from pi-hole/fix/nowildcardlistfile Check for existence of wildcard blocking list (query adlists) --- pihole | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 97f749ab..dda6d750 100755 --- a/pihole +++ b/pihole @@ -127,17 +127,19 @@ queryFunc() { done # Scan for possible wildcard matches - 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 [ -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 + fi exit 0 } From 6f8893d9504b6f4cb1503c89c67611b31266571a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 23:53:06 +0100 Subject: [PATCH 008/109] Merge pull request #1301 from pi-hole/fix/removewildcard Remove wildcard entry when adding the very same domain either the white- or blacklist --- advanced/Scripts/list.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 90d1b7f0..2ac1e805 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -84,6 +84,7 @@ PoplistFile() { if ${addmode}; then AddDomain "${dom}" "${listMain}" RemoveDomain "${dom}" "${listAlt}" + RemoveDomain "${dom}" "${wildcardlist}" else RemoveDomain "${dom}" "${listMain}" fi From bc514ea9551a13eaae414c2b2624dfd8a21c3892 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 5 Mar 2017 07:13:41 -0800 Subject: [PATCH 009/109] Merge pull request #1296 from pi-hole/fix/debugVersion Debug version detection improvements --- advanced/Scripts/piholeDebug.sh | 65 +++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 70d73379..0b8a2571 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -24,6 +24,8 @@ WHITELISTFILE="/etc/pihole/whitelist.txt" BLACKLISTFILE="/etc/pihole/blacklist.txt" ADLISTFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" +PIHOLEGITDIR="/etc/.pihole/" +ADMINGITDIR="/var/www/html/admin/" WHITELISTMATCHES="/tmp/whitelistmatches.list" TIMEOUT=60 @@ -111,22 +113,61 @@ version_check() { header_write "Detecting Installed Package Versions:" local error_found + local pi_hole_ver + local pi_hole_branch + local pi_hole_commit + local admin_ver + local admin_branch + local admin_commit + local light_ver + local php_ver + local status error_found=0 - local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_echo -r "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) - local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ - && log_echo -r "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) - local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ - && log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) - local php_ver="$(php -v |& head -n1)" \ - && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) + cd "${PIHOLEGITDIR}" &> /dev/null || \ + { status="Pi-hole git directory not found."; error_found=1; } + if git status &> /dev/null; then + pi_hole_ver=$(git describe --tags --abbrev=0) + pi_hole_branch=$(git rev-parse --abbrev-ref HEAD) + pi_hole_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Pi-hole: ${pi_hole_ver:-Untagged} (${pi_hole_branch:-Detached}:${pi_hole_commit})" + else + status=${status:-"Pi-hole repository damaged."} + error_found=1 + fi + if [[ "${status}" ]]; then + log_echo "${status}" + unset status + fi - (local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}") || log_echo "Unable to obtain Pi-hole branch" - (local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}") || log_echo "Unable to obtain Pi-hole revision" + cd "${ADMINGITDIR}" || \ + { status="Pi-hole Dashboard git directory not found."; error_found=1; } + if git status &> /dev/null; then + admin_ver=$(git describe --tags --abbrev=0) + admin_branch=$(git rev-parse --abbrev-ref HEAD) + admin_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Pi-hole Dashboard: ${admin_ver:-Untagged} (${admin_branch:-Detached}:${admin_commit})" + else + status=${status:-"Pi-hole Dashboard repository damaged."} + error_found=1 + fi + if [[ "${status}" ]]; then + log_echo "${status}" + unset status + fi - (local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AdminLTE branch: ${admin_branch}") || log_echo "Unable to obtain AdminLTE branch" - (local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AdminLTE rev: ${admin_rev}") || log_echo "Unable to obtain AdminLTE revision" + if light_ver=$(lighttpd -v |& head -n1 | cut -d " " -f1); then + log_echo -r "${light_ver}" + else + log_echo "lighttpd not installed." + error_found=1 + fi + if php_ver=$(php -v |& head -n1); then + log_echo -r "${php_ver}" + else + log_echo "PHP not installed." + error_found=1 + fi return "${error_found}" } From 8460b2544bb85ff3cfd640a6e8c28a3553157ec0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 15:17:25 -0800 Subject: [PATCH 010/109] Merge pull request #1295 from pi-hole/tweak/pullapprove Require 4 approvals instead of five for merging into master --- .pullapprove.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pullapprove.yml b/.pullapprove.yml index f9d10062..ff970b29 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -33,6 +33,6 @@ groups: conditions: branches: - master - required: -1 + required: 4 teams: - admin From 33f7979359d148f20e3f97fd3fd62092dd9a9c94 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 5 Mar 2017 07:10:18 -0800 Subject: [PATCH 011/109] Merge pull request #1293 from pi-hole/fix/version Account for hash in versioning --- advanced/Scripts/version.sh | 147 +++++++++++++++++++++--------------- 1 file changed, 88 insertions(+), 59 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 11a7af00..fd74c2de 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -8,67 +8,98 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - - -# Flags: -latest=false -current=false - +# Variables DEFAULT="-1" +PHGITDIR="/etc/.pihole/" +WEBGITDIR="/var/www/html/admin/" + +getLocalVersion() { + # Get the tagged version of the local repository + local directory="${1}" + local version + + cd "${directory}" || { echo "${DEFAULT}"; return 1; } + version=$(git describe --tags --always || \ + echo "${DEFAULT}") + if [[ "${version}" =~ ^v ]]; then + echo "${version}" + elif [[ "${version}" == "${DEFAULT}" ]]; then + echo "ERROR" + return 1 + else + echo "Untagged" + fi + return 0 +} + +getLocalHash() { + # Get the short hash of the local repository + local directory="${1}" + local hash + + cd "${directory}" || { echo "${DEFAULT}"; return 1; } + hash=$(git rev-parse --short HEAD || \ + echo "${DEFAULT}") + if [[ "${hash}" == "${DEFAULT}" ]]; then + echo "ERROR" + return 1 + else + echo "${hash}" + fi + return 0 +} + +getRemoteVersion(){ + # Get the version from the remote origin + local daemon="${1}" + local version + + 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 + echo "${version}" + else + echo "ERROR" + return 1 + fi + 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() { - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - - echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})" - echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})" + echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))" + echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" } webOutput() { - for var in "$@"; do - case "${var}" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; - * ) echo "::: Invalid Option!"; exit 1; - esac - done - - if [[ "${latest}" == true && "${current}" == false ]]; then - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "${webVersionLatest:--1}" - elif [[ "${latest}" == false && "${current}" == true ]]; then - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - echo "${webVersion}" - else - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})" - fi + case "${1}" in + "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; + "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; + "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; + * ) echo "::: Invalid Option!"; exit 1; + esac } coreOutput() { - for var in "$@"; do - case "${var}" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; - * ) echo "::: Invalid Option!"; exit 1; - esac - done - - if [[ "${latest}" == true && "${current}" == false ]]; then - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "${piholeVersionLatest:--1}" - elif [[ "${latest}" == false && "${current}" == true ]]; then - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - echo "${piholeVersion}" - else - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})" - fi + 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 } helpFunc() { @@ -93,10 +124,8 @@ if [[ $# = 0 ]]; then normalOutput fi -for var in "$@"; do - case "${var}" in - "-a" | "--admin" ) shift; webOutput "$@";; - "-p" | "--pihole" ) shift; coreOutput "$@" ;; - "-h" | "--help" ) helpFunc;; - esac -done +case "${1}" in + "-a" | "--admin" ) shift; webOutput "$@";; + "-p" | "--pihole" ) shift; coreOutput "$@" ;; + "-h" | "--help" ) helpFunc;; +esac From 38ba079baaaf3d6109962c724e0e4a55dfcfd77f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Mar 2017 23:54:32 +0100 Subject: [PATCH 012/109] Merge pull request #1307 from pi-hole/fix/versionwithoutwebinterface Don't try to obtain version of web interface it it is not installed --- advanced/Scripts/version.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index fd74c2de..7f96e29a 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -81,16 +81,22 @@ getRemoteVersion(){ normalOutput() { echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))" - echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" + if [ -d "${WEBGITDIR}" ]; then + echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" + fi } webOutput() { - case "${1}" in - "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; - "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; - "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; - * ) echo "::: Invalid Option!"; exit 1; - esac + 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 + else + echo "::: Web interface not installed!"; exit 1; + fi } coreOutput() { From df18c7cd5953512bb7c444a86585f7eadb7b35bf Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 11 Mar 2017 13:01:11 -0800 Subject: [PATCH 013/109] Merge pull request #1313 from pi-hole/new/piholecheckout Checkout adjustments --- advanced/Scripts/piholeCheckout.sh | 131 +++++++++++++++++++---------- 1 file changed, 85 insertions(+), 46 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 86ea9a2b..3b7abbef 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,12 +9,17 @@ # Please see LICENSE file for your rights under this license. readonly PI_HOLE_FILES_DIR="/etc/.pihole" -PH_TEST="true" source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh +PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # webInterfaceGitUrl set in basic-install.sh # webInterfaceDir set in basic-install.sh # piholeGitURL set in basic-install.sh # is_repo() sourced from basic-install.sh +# setupVars set in basic-install.sh + +source "${setupVars}" + +update="false" fully_fetch_repo() { # Add upstream branches to shallow clone @@ -33,28 +38,44 @@ fully_fetch_repo() { get_available_branches(){ # Return available branches local directory="${1}" - local curdir - curdir="${PWD}" cd "${directory}" || return 1 # Get reachable remote branches git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g' - cd "${curdir}" || return 1 return } + +fetch_checkout_pull_branch() { + # Check out specified branch + local directory="${1}" + local branch="${2}" + + # 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 fetch --quiet || return 1 + checkout_pull_branch "${directory}" "${branch}" || return 1 +} + checkout_pull_branch() { # Check out specified branch local directory="${1}" local branch="${2}" - local curdir + local oldbranch - curdir="${PWD}" cd "${directory}" || return 1 - git checkout "${branch}" - git pull - cd "${curdir}" || return 1 - return + + oldbranch="$(git symbolic-ref HEAD)" + + git checkout "${branch}" || return 1 + + if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then + update="true" + fi + + git pull || return 1 + return 0 } warning1() { @@ -82,9 +103,23 @@ checkout() set -f #This is unlikely - if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${webInterfaceDir}" ; then - echo "::: Critical Error: One or more Pi-Hole repos are missing from your system!" - echo "::: Please re-run the install script from https://github.com/pi-hole/pi-hole" + if ! is_repo "${PI_HOLE_FILES_DIR}" ; then + echo "::: Critical Error: Core Pi-Hole repo is missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + if [[ ${INSTALL_WEB} == "true" ]]; then + if ! is_repo "${webInterfaceDir}" ; then + echo "::: Critical Error: Web Admin repo is missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + fi + + if [[ -z "${1}" ]]; then + echo "::: No option detected. Please use 'pihole checkout '." + echo "::: Or enter the repository and branch you would like to check out:" + echo "::: 'pihole checkout '" exit 1 fi @@ -92,43 +127,36 @@ checkout() exit 1 fi - echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " - if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then - echo "::: Fetching all branches for Pi-hole core repo failed!" - exit 1 - fi - corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) - echo " done!" - echo "::: ${#corebranches[@]} branches available" - echo ":::" - - echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " - if ! fully_fetch_repo "${webInterfaceDir}" ; then - echo "::: Fetching all branches for Pi-hole web interface repo failed!" - exit 1 - fi - webbranches=($(get_available_branches "${webInterfaceDir}")) - echo " done!" - echo "::: ${#webbranches[@]} branches available" - echo ":::" - if [[ "${1}" == "dev" ]] ; then # Shortcut to check out development branches echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" - echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "devel" + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } + if [[ ${INSTALL_WEB} == "true" ]]; then + echo "::: Web interface" + fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } + fi echo "::: done!" elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" - echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "master" + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } + if [[ ${INSTALL_WEB} == "true" ]]; then + echo "::: Web interface" + fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } + fi echo "::: done!" elif [[ "${1}" == "core" ]] ; then + echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " + if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then + echo "::: Fetching all branches for Pi-hole core repo failed!" + exit 1 + fi + corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) + echo " done!" + echo "::: ${#corebranches[@]} branches available" + echo ":::" # Have to user chosing the branch he wants if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then echo "::: Requested branch \"${2}\" is not available!" @@ -137,7 +165,16 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" - elif [[ "${1}" == "web" ]] ; then + elif [[ "${1}" == "web" && "${INSTALL_WEB}" == "true" ]] ; then + echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " + if ! fully_fetch_repo "${webInterfaceDir}" ; then + echo "::: Fetching all branches for Pi-hole web interface repo failed!" + exit 1 + fi + webbranches=($(get_available_branches "${webInterfaceDir}")) + echo " done!" + echo "::: ${#webbranches[@]} branches available" + echo ":::" # Have to user chosing the branch he wants if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then echo "::: Requested branch \"${2}\" is not available!" @@ -152,12 +189,14 @@ checkout() fi # Force updating everything - echo "::: Running installer to upgrade your installation" - if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then - exit 0 - else - echo "Unable to complete update, contact Pi-hole" - exit 1 + if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then + echo "::: Running installer to upgrade your installation" + if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then + exit 0 + else + echo "Unable to complete update, contact Pi-hole" + exit 1 + fi fi } From d7b5870ba63c23cb873f541b394d43d669372262 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 12 Mar 2017 23:15:23 +0100 Subject: [PATCH 014/109] Use absolute path for pihole command in gravity.sh. Fixes #1318 --- gravity.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 08590251..7441dd87 100755 --- a/gravity.sh +++ b/gravity.sh @@ -26,10 +26,11 @@ EOM exit 0 } +PIHOLE_COMMAND="/usr/local/bin/pihole" adListFile=/etc/pihole/adlists.list adListDefault=/etc/pihole/adlists.default -whitelistScript="pihole -w" +whitelistScript="${PIHOLE_COMMAND} -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" @@ -385,7 +386,7 @@ gravity_reload() { #Now replace the line in dnsmasq file # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf - pihole restartdns + "${PIHOLE_COMMAND}" restartdns echo " done!" } @@ -423,4 +424,4 @@ gravity_hostFormat gravity_blackbody gravity_reload -pihole status +"${PIHOLE_COMMAND}" status From e45559da206978c2a6b89eadf876180034a0c768 Mon Sep 17 00:00:00 2001 From: georou Date: Tue, 14 Mar 2017 01:13:23 +1100 Subject: [PATCH 015/109] Use Firewalld services instead of ports --- 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 7c9a83d5..b9e38bef 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -965,7 +965,7 @@ configureFirewall() { whiptail --title "Firewall in use" --yesno "We have detected a running firewall\n\nPi-hole currently requires HTTP and DNS port access.\n\n\n\nInstall Pi-hole default firewall rules?" ${r} ${c} || \ { echo -e ":::\n::: Not installing firewall rulesets."; return 0; } echo -e ":::\n:::\n Configuring FirewallD for httpd and dnsmasq." - firewall-cmd --permanent --add-port=80/tcp --add-port=53/tcp --add-port=53/udp + firewall-cmd --permanent --add-service={http,dns} firewall-cmd --reload return 0 # Check for proper kernel modules to prevent failure From 6b862dd9e959a312984b00014d42a938376e4243 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 13 Mar 2017 20:32:23 +0000 Subject: [PATCH 016/109] Only remove from wildcard list if domain is being added to whitelist or blacklist --- advanced/Scripts/list.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 2ac1e805..537ebac3 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -84,7 +84,9 @@ PoplistFile() { if ${addmode}; then AddDomain "${dom}" "${listMain}" RemoveDomain "${dom}" "${listAlt}" - RemoveDomain "${dom}" "${wildcardlist}" + if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then + RemoveDomain "${dom}" "${wildcardlist}" + fi else RemoveDomain "${dom}" "${listMain}" fi From 8fa209f0df06e05328101323627e5de3b757ea91 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 13 Mar 2017 17:50:18 -0400 Subject: [PATCH 017/109] Merge pull request #1322 from pi-hole/FixWildCardBlacklisting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only remove from wildcard list if domain is being added to whitelist … --- advanced/Scripts/list.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 2ac1e805..537ebac3 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -84,7 +84,9 @@ PoplistFile() { if ${addmode}; then AddDomain "${dom}" "${listMain}" RemoveDomain "${dom}" "${listAlt}" - RemoveDomain "${dom}" "${wildcardlist}" + if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then + RemoveDomain "${dom}" "${wildcardlist}" + fi else RemoveDomain "${dom}" "${listMain}" fi From 76bd53ef1fd6dadbc206efda5282bd2742213840 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Mon, 13 Mar 2017 20:24:04 -0400 Subject: [PATCH 018/109] replace instances of "/etc/.pihole" with ${PI_HOLE_LOCAL_REPO} --- automated install/basic-install.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f168675e..dce52a3d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -582,8 +582,8 @@ version_check_dnsmasq() { local dnsmasq_conf="/etc/dnsmasq.conf" local dnsmasq_conf_orig="/etc/dnsmasq.conf.orig" local dnsmasq_pihole_id_string="addn-hosts=/etc/pihole/gravity.list" - local dnsmasq_original_config="/etc/.pihole/advanced/dnsmasq.conf.original" - local dnsmasq_pihole_01_snippet="/etc/.pihole/advanced/01-pihole.conf" + local dnsmasq_original_config="${PI_HOLE_LOCAL_REPO}/advanced/dnsmasq.conf.original" + local dnsmasq_pihole_01_snippet="${PI_HOLE_LOCAL_REPO}/advanced/01-pihole.conf" local dnsmasq_pihole_01_location="/etc/dnsmasq.d/01-pihole.conf" if [ -f ${dnsmasq_conf} ]; then @@ -669,7 +669,7 @@ installScripts() { } installConfigs() { - # Install the configs from /etc/.pihole to their various locations + # Install the configs from ${PI_HOLE_LOCAL_REPO} to their various locations echo ":::" echo "::: Installing configs..." version_check_dnsmasq @@ -682,7 +682,7 @@ installConfigs() { elif [ -f "/etc/lighttpd/lighttpd.conf" ]; then mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig fi - cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf + cp ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf mkdir -p /var/run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd mkdir -p /var/cache/lighttpd/compress @@ -835,7 +835,7 @@ installPiholeWeb() { echo "::: Existing index.php detected, not overwriting" else echo -n "::: index.php missing, replacing... " - cp /etc/.pihole/advanced/index.php /var/www/html/pihole/ + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ echo " done!" fi @@ -843,7 +843,7 @@ installPiholeWeb() { echo "::: Existing index.js detected, not overwriting" else echo -n "::: index.js missing, replacing... " - cp /etc/.pihole/advanced/index.js /var/www/html/pihole/ + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ echo " done!" fi @@ -851,14 +851,14 @@ installPiholeWeb() { echo "::: Existing blockingpage.css detected, not overwriting" else echo -n "::: blockingpage.css missing, replacing... " - cp /etc/.pihole/advanced/blockingpage.css /var/www/html/pihole + 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 /etc/.pihole/advanced/{index,blockingpage}.* /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 @@ -871,7 +871,7 @@ installPiholeWeb() { echo ":::" echo -n "::: Installing sudoer file..." mkdir -p /etc/sudoers.d/ - cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole + cp ${PI_HOLE_LOCAL_REPO}/advanced/pihole.sudo /etc/sudoers.d/pihole # Add lighttpd user (OS dependent) to sudoers file echo "${LIGHTTPD_USER} ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole @@ -889,7 +889,7 @@ installCron() { # Install the cron job echo ":::" echo -n "::: Installing latest Cron script..." - cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole + cp ${PI_HOLE_LOCAL_REPO}/advanced/pihole.cron /etc/cron.d/pihole echo " done!" } @@ -903,7 +903,7 @@ runGravity() { fi # Test if /etc/pihole/adlists.default exists if [[ ! -e /etc/pihole/adlists.default ]]; then - cp /etc/.pihole/adlists.default /etc/pihole/adlists.default + cp ${PI_HOLE_LOCAL_REPO}/adlists.default /etc/pihole/adlists.default fi echo "::: Running gravity.sh" { /opt/pihole/gravity.sh; } @@ -978,7 +978,7 @@ finalExports() { # Look for DNS server settings which would have to be reapplied source "${setupVars}" - source "/etc/.pihole/advanced/Scripts/webpage.sh" + source "${PI_HOLE_LOCAL_REPO}/advanced/Scripts/webpage.sh" if [[ "${DNS_FQDN_REQUIRED}" != "" ]] ; then ProcessDNSSettings @@ -993,7 +993,7 @@ installLogrotate() { # Install the logrotate script echo ":::" echo -n "::: Installing latest logrotate script..." - cp /etc/.pihole/advanced/logrotate /etc/pihole/logrotate + cp ${PI_HOLE_LOCAL_REPO}/advanced/logrotate /etc/pihole/logrotate # Different operating systems have different user / group # settings for logrotate that makes it impossible to create # a static logrotate file that will work with e.g. From c4b43f92ce1a7534c935e6ae0c45b2105dba206b Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Tue, 14 Mar 2017 13:19:43 -0400 Subject: [PATCH 019/109] Fix help text bug Fixes #1325 --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index dda6d750..d2f87b71 100755 --- a/pihole +++ b/pihole @@ -297,7 +297,7 @@ helpFunc() { ::: -b, blacklist Blacklist domain(s) (exact match) ::: -wild, wildcard Blacklist whole domain(s) (wildcard) ::: -d, debug Start a debugging session -::: Automated debugging can be enabled with `-a`. +::: Automated debugging can be enabled with '-a'. ::: 'pihole -d -a' ::: -f, flush Flush the 'pihole.log' file ::: -t, tail Output the last lines of the 'pihole.log' file. Lines are appended as the file grows From cfaf1ac67c6a99735954737dc4c527722a520021 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 15 Mar 2017 18:59:41 +0000 Subject: [PATCH 020/109] add check on file_parse to not include WEBPASSWORD= in the debug log --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index df9ed4f0..4f856546 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -84,7 +84,7 @@ header_write() { file_parse() { while read -r line; do if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ || ! "${line}" ]] && continue + [[ "${line}" =~ ^#.*$ || ! "${line}" || "${line}" == "WEBPASSWORD="* ]] && continue log_write "${line}" fi done < "${1}" From 83662c9e5006361f52a8ad36bb447518c358d62e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 15 Mar 2017 19:50:22 +0000 Subject: [PATCH 021/109] additional requested changes --- 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 d22f8419..dce04e02 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -706,9 +706,9 @@ installScripts() { } installConfigs() { - # Install the configs from ${PI_HOLE_LOCAL_REPO} to their various locations + # Install the configs from PI_HOLE_LOCAL_REPO to their various locations echo ":::" - echo "::: Installing configs..." + echo "::: Installing configs from ${PI_HOLE_LOCAL_REPO}..." version_check_dnsmasq #Only mess with lighttpd configs if user has chosen to install web interface From ab2af11775ab52bc28d0e2258467e69ad9a6cc43 Mon Sep 17 00:00:00 2001 From: Wandmalfarbe Date: Wed, 15 Mar 2017 20:58:41 +0100 Subject: [PATCH 022/109] Fixed minor spelling mistakes in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0a5f7f4c..3369d7e2 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does #### Other Operating Systems -The automated install is only for a clean install of a Debian family or Fedora based system, such as the Raspberry Pi. However, this script will work for most UNIX-like systems, some with some slight **modifications** that we can help you work through. If you can install `dnsmasq` and a Webserver, it should work OK. If there are other platforms you'd like supported, let us know. +The automated install is only for a clean install of a Debian family or Fedora based system, such as the Raspberry Pi. However, this script will work for most UNIX-like systems, some with some slight **modifications** that we can help you work through. If you can install `dnsmasq` and a web server, it should work OK. If there are other platforms you'd like supported, let us know. ### Web Interface @@ -144,7 +144,7 @@ You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my- - [Get LED alerts for each blocked ad](http://thetimmy.silvernight.org/pages/endisbutton/) - [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html) - [Docker Pi-hole container (x86 and ARM)](https://hub.docker.com/r/diginc/pi-hole/) -- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/) +- [Splunk: Pi-hole Visualiser](https://splunkbase.splunk.com/app/3023/) - [Pi-hole Chrome extension](https://chrome.google.com/webstore/detail/pi-hole-list-editor/hlnoeoejkllgkjbnnnhfolapllcnaglh) ([open source](https://github.com/packtloss/pihole-extension)) - [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037) - [Sky-Hole](http://dlaa.me/blog/post/skyhole) From 0d794226ab9ac7c598b7fc7371dbc68a5a2777ba Mon Sep 17 00:00:00 2001 From: georou Date: Thu, 16 Mar 2017 09:29:33 +1100 Subject: [PATCH 023/109] Removed unsupported POSIX brace expansion --- 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 b9e38bef..3373a41c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -965,7 +965,7 @@ configureFirewall() { whiptail --title "Firewall in use" --yesno "We have detected a running firewall\n\nPi-hole currently requires HTTP and DNS port access.\n\n\n\nInstall Pi-hole default firewall rules?" ${r} ${c} || \ { echo -e ":::\n::: Not installing firewall rulesets."; return 0; } echo -e ":::\n:::\n Configuring FirewallD for httpd and dnsmasq." - firewall-cmd --permanent --add-service={http,dns} + firewall-cmd --permanent --add-service=http --add-service=dns firewall-cmd --reload return 0 # Check for proper kernel modules to prevent failure From 6c5666540328d36806a63c12303d467ac092822e Mon Sep 17 00:00:00 2001 From: georou Date: Thu, 16 Mar 2017 10:26:51 +1100 Subject: [PATCH 024/109] updated travis for new firewalld add service --- test/test_automated_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 19c662c6..8e36fc96 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -78,7 +78,7 @@ def test_configureFirewall_firewalld_running_no_errors(Pihole): assert expected_stdout in configureFirewall.stdout firewall_calls = Pihole.run('cat /var/log/firewall-cmd').stdout assert 'firewall-cmd --state' in firewall_calls - assert 'firewall-cmd --permanent --add-port=80/tcp --add-port=53/tcp --add-port=53/udp' in firewall_calls + assert 'firewall-cmd --permanent --add-service=http --add-service=dns' in firewall_calls assert 'firewall-cmd --reload' in firewall_calls def test_configureFirewall_firewalld_disabled_no_errors(Pihole): From 2834f2ccc290b89b043dc0c05d5fd9d95747cf49 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 22:05:48 -0700 Subject: [PATCH 025/109] Let `ip` determine which links are candidates. 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 7c9a83d5..b1ee90d6 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -233,7 +233,7 @@ find_IPv4_information() { get_available_interfaces() { # Get available UP interfaces. - availableInterfaces=$(ip -o link | grep -v "state DOWN\|lo" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) + availableInterfaces=$(ip --oneline link show up | grep -v "lo" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) } welcomeDialogs() { From e9f1ca338ffe1a626eb868693f138430ff1ac67a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 22:49:47 -0700 Subject: [PATCH 026/109] Create temp files for working storage, log to working storage temps. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index df9ed4f0..3ecc3f4b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -52,7 +52,7 @@ source ${VARSFILE} ### Private functions exist here ### log_write() { - echo "${1}" >> "${DEBUG_LOG}" + printf "%b" "${@}" >&3 } log_echo() { @@ -417,7 +417,7 @@ dumpPiHoleLog() { if [ -e "${PIHOLELOG}" ]; then # Dummy process to use for flagging down tail to terminate countdown & - tail -n0 -f --pid=$! "${PIHOLELOG}" >> ${DEBUG_LOG} + tail -n0 -f --pid=$! "${PIHOLELOG}" >&4 else log_write "No pihole.log file found!" printf ":::\tNo pihole.log file found!\n" @@ -456,6 +456,17 @@ finalWork() { } ### END FUNCTIONS ### +# Create temporary file for log +TEMPLOG=$(mktemp /tmp/pihole_temp.XXXXXX) +# Open handle 3 for templog +exec 3>"$TEMPLOG" +# Delete templog, but allow for addressing via file handle. +rm "$TEMPLOG" + +# Create temporary file for logdump using file handle 4 +DUMPLOG=$(mktemp /tmp/pihole_temp.XXXXXX) +exec 4>"$DUMPLOG" +rm "$DUMPLOG" # Gather version of required packages / repositories version_check || echo "REQUIRED FILES MISSING" From 0a0c3a2fb76fdee1c6d01d32d0e18786e8df29f7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:20:12 -0700 Subject: [PATCH 027/109] Copy working temp to final location. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3ecc3f4b..8649bb90 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -43,16 +43,11 @@ cat << EOM ::: Please read and note any issues, and follow any directions advised during this process. EOM -# Ensure the file exists, create if not, clear if exists. -truncate --size=0 "${DEBUG_LOG}" -chmod 644 ${DEBUG_LOG} -chown "$USER":pihole ${DEBUG_LOG} - source ${VARSFILE} ### Private functions exist here ### log_write() { - printf "%b" "${@}" >&3 + echo "${@}" >&3 } log_echo() { @@ -363,9 +358,9 @@ testChaos(){ log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" - dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} + log_write $(dig +short chaos txt cachesize.bind) log_write "Upstream Servers:" - dig +short chaos txt servers.bind >> ${DEBUG_LOG} + log_write $(dig +short chaos txt servers.bind) log_write "" } @@ -378,7 +373,7 @@ checkProcesses() { log_write "" log_write "${i}" log_write " processes status:" - systemctl -l status "${i}" >> "${DEBUG_LOG}" + log_write $(systemctl -l status "${i}") done log_write "" } @@ -428,6 +423,14 @@ dumpPiHoleLog() { finalWork() { local tricorder echo "::: Finshed debugging!" + + # Ensure the file exists, create if not, clear if exists. + truncate --size=0 "${DEBUG_LOG}" + chmod 644 ${DEBUG_LOG} + chown "$USER":pihole ${DEBUG_LOG} + # copy working temp file to final log location + cp /proc/$$/fd/3 "$DEBUG_LOG" + echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." if [[ "${AUTOMATED}" ]]; then echo "::: Debug script running in automated mode, uploading log to tricorder..." From 160030b75f3ad6124001fe97cd8ba5468106c5e9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:27:18 -0700 Subject: [PATCH 028/109] Quiet systemctl output to just the current daemon status. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8649bb90..136d92d1 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -72,7 +72,7 @@ log_echo() { header_write() { log_echo "" - log_echo "${1}" + log_echo "---= ${1}" log_write "" } @@ -370,10 +370,8 @@ checkProcesses() { echo "::: Logging status of lighttpd, dnsmasq and pihole-FTL..." PROCESSES=( lighttpd dnsmasq pihole-FTL ) for i in "${PROCESSES[@]}"; do - log_write "" - log_write "${i}" - log_write " processes status:" - log_write $(systemctl -l status "${i}") + log_write "Status for ${i} daemon:" + log_write $(systemctl is-active "${i}") done log_write "" } From 77378da70ad49f6467ac008e8e3f06dc3c543f8c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:43:41 -0700 Subject: [PATCH 029/109] Cat out temp files to final log. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 136d92d1..d3c85d3a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -427,7 +427,9 @@ finalWork() { chmod 644 ${DEBUG_LOG} chown "$USER":pihole ${DEBUG_LOG} # copy working temp file to final log location - cp /proc/$$/fd/3 "$DEBUG_LOG" + cat /proc/$$/fd/3 >> "${DEBUG_LOG}" + # Straight dump of tailing the logs, can sanitize later if needed. + cat /proc/$$/fd/4 >> "${DEBUG_LOG}" echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." if [[ "${AUTOMATED}" ]]; then From b1f769b671bfdfd424172b754ef2f6cc6cb31aee Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:50:29 -0700 Subject: [PATCH 030/109] Output cleaning, IP stack check headers. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index d3c85d3a..6274e04e 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -226,6 +226,7 @@ ipv6_check() { ip_check() { local protocol=${1} local gravity=${2} + header_write "Checking IPv${protocol} Stack" local ip_addr_list="$(ip -${protocol} addr show dev ${PIHOLE_INTERFACE} | awk -F ' ' '{ for(i=1;i<=NF;i++) if ($i ~ '/^inet/') print $(i+1) }')" if [[ -n ${ip_addr_list} ]]; then From fd584dd03baa7ee15b57590b35113c600e8c986d Mon Sep 17 00:00:00 2001 From: Anthony Giorgio Date: Sat, 18 Mar 2017 20:47:13 -0400 Subject: [PATCH 031/109] Formatting cleanup. Convert backticks to quotes to fix error message. Make Pi-hole capitalization consistent. Make Pi-hole capitalization consistent. --- pihole | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pihole b/pihole index d2f87b71..83e13000 100755 --- a/pihole +++ b/pihole @@ -287,10 +287,10 @@ piholeCheckoutFunc() { helpFunc() { cat << EOM -::: Control all PiHole specific functions! +::: Control all Pi-hole specific functions ::: ::: Usage: pihole [options] -::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -a (admin) 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 domain(s) @@ -306,15 +306,15 @@ helpFunc() { ::: -g, updateGravity Update the list of ad-serving domains ::: -c, chronometer Calculates stats and displays to an LCD ::: -h, help Show this help dialog -::: -v, version Show installed versions of Pi-Hole and Web-Admin +::: -v, version Show installed versions of Pi-hole and Web-Admin ::: -q, query Query the adlists for a specific domain ::: 'pihole -q domain -exact' shows exact matches only ::: -l, logging Enable or Disable logging (pass 'on' or 'off') ::: -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 -::: disable Disable Pi-Hole DNS Blocking +::: uninstall Uninstall Pi-hole from your system! :( +::: status Display if Pi-hole is Enabled or Disabled +::: enable Enable Pi-hole DNS Blocking +::: disable Disable Pi-hole DNS Blocking ::: Blocking can also be disabled only temporarily, e.g., ::: 'pihole disable 5m' - will disable blocking for 5 minutes ::: restartdns Restart dnsmasq From 48c19ade8e449c439341ee12fc6541d6ac7998c1 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Sun, 19 Mar 2017 15:36:22 -0500 Subject: [PATCH 032/109] add trademarks to Pi-hole name in signifigant places --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3369d7e2..0bfd6614 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## The multi-platform, network-wide ad blocker -Block ads for **all** your devices _without_ the need to install client-side software. The Pi-hole blocks ads at the DNS-level, so all your devices are protected. +Block ads for **all** your devices _without_ the need to install client-side software. The Pi-hole™ blocks ads at the DNS-level, so all your devices are protected. - Web Browsers - Cell Phones @@ -53,9 +53,9 @@ wget -O basic-install.sh https://install.pi-hole.net bash basic-install.sh ``` -Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to use Pi-hole as their DNS server. +Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to use Pi-hole™ as their DNS server. -## What is Pi-hole and how do I install it? +## What is Pi-hole™ and how do I install it?

@@ -73,7 +73,7 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei ## Technical Details -The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. +The Pi-hole™ is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. ### Gravity @@ -102,7 +102,7 @@ Domains can be whitelisted and blacklisted using either the web interface or the ### Settings -The settings page lets you control and configure your Pi-hole. You can do things like: +The settings page lets you control and configure your Pi-hole™. You can do things like: - enable Pi-hole's built-in DHCP server - exclude domains from the graphs @@ -113,7 +113,7 @@ The settings page lets you control and configure your Pi-hole. You can do thing #### Built-in DHCP Server -Pi-hole ships with a built-in DHCP server. This allows you to let your network devices use Pi-hole as their DNS server if your router does not let you adjust the DHCP options. +Pi-hole™ ships with a built-in DHCP server. This allows you to let your network devices use Pi-hole™ as their DNS server if your router does not let you adjust the DHCP options.

@@ -137,7 +137,7 @@ The same output can be achieved on the CLI by running `chronometer.sh -j` You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my-pi-holes-stats-over-ssh-or-on-an-lcd-using-chronometer/240) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). ![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) -## Pi-hole Projects +## Pi-hole™ Projects - [An ad blocking Magic Mirror](https://zonksec.com/blog/magic-mirror-dns-filtering/#dnssoftware) - [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) From 1cd4710718fee3247184ddbb0661e304e79c036d Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Sun, 19 Mar 2017 15:41:16 -0500 Subject: [PATCH 033/109] replace logo with TM logo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bfd6614..456eea2f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

- +

## The multi-platform, network-wide ad blocker From af1d1bd9c21e26b4700f8a2853cbdfb9ba4aa9a6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 21 Mar 2017 05:04:58 -0700 Subject: [PATCH 034/109] One more change 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 dce04e02..2a1498c3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1221,7 +1221,7 @@ FTLinstall() { stop_service pihole-FTL &> /dev/null install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL cd "${orig_dir}" - install -T -m 0755 "/etc/.pihole/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL" + install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL" echo "done." return 0 else From fb3e6ee35c6789574fd4165736bef7bce3075a32 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Tue, 21 Mar 2017 18:01:51 -0400 Subject: [PATCH 035/109] Source setupVars before attempting to use it Fixes #1347 --- advanced/Scripts/update.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 4a2e4045..115e2d8c 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -90,6 +90,7 @@ FTLcheckUpdate() { main() { local pihole_version_current local web_version_current + source "${setupVars}" #This is unlikely if ! is_repo "${PI_HOLE_FILES_DIR}" ; then From 598a7b3cc0427cc62bd5e3203fff43b1bd6796ac Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 22 Mar 2017 13:44:04 -0700 Subject: [PATCH 036/109] Add .editorconfig Signed-off-by: Dan Schaper --- .editorconfig | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..325648fc --- /dev/null +++ b/.editorconfig @@ -0,0 +1,38 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = tab +tab_width = 2 +charset = utf-8 +trim_trailing_whitespace = true + +# Matches multiple files with brace expansion notation +# Set default charset +[*.{js,py}] +charset = utf-8 + +# 4 space indentation +[*.py] +indent_style = space +indent_size = 4 + +# Tab indentation (no size specified) +[Makefile] +indent_style = tab + +# Indentation override for all JS under lib directory +[lib/**.js] +indent_style = space +indent_size = 2 + +# Matches the exact files either package.json or .travis.yml +[{package.json,.travis.yml}] +indent_style = space +indent_size = 2 From ee296f36c199bcf26b3d944fb3a4cc7b04fe8cc4 Mon Sep 17 00:00:00 2001 From: Patrick O'Brien Date: Thu, 23 Mar 2017 18:47:30 -0400 Subject: [PATCH 037/109] mask password input on command line --- advanced/Scripts/webpage.sh | 14 ++++++++------ automated install/basic-install.sh | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9637cc6f..55ae3d96 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -81,19 +81,21 @@ SetWebPassword(){ exit 1 fi - # Set password only if there is one to be set - if (( ${#args[2]} > 0 )) ; then + read -s -p "Enter New Password: " PASSWORD + echo "" + read -s -p "Confirm Password: " CONFIRM + echo "" + if [ "${PASSWORD}" == "${CONFIRM}" ] ; then # Compute password hash twice to avoid rainbow table vulnerability - hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//') + hash=$(echo -n ${PASSWORD} | sha256sum | sed 's/\s.*$//') hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') # Save hash to file change_setting "WEBPASSWORD" "${hash}" echo "New password set" else - change_setting "WEBPASSWORD" "" - echo "Password removed" + echo "Passwords don't match. Your password has not been changed" + exit 1 fi - } ProcessDNSSettings() { diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b1ee90d6..bf083adb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1460,7 +1460,7 @@ main() { echo "::: ${pw}" echo ":::" echo "::: You can always change it using" - echo "::: pihole -a -p new_password" + echo "::: pihole -a -p" fi fi From 6eb9192cd196c91dacfbfb9378727fe47000fe2f Mon Sep 17 00:00:00 2001 From: Flo Date: Sat, 25 Mar 2017 16:11:37 +0100 Subject: [PATCH 038/109] Complete site The start -tag was missing. --- advanced/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/index.php b/advanced/index.php index c076f92d..4cce2857 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -48,6 +48,7 @@ if($uri == "/") ?> + Website Blocked From a463250ecf3658fa2b1084261ef7979faf76bdba Mon Sep 17 00:00:00 2001 From: Patrick O'Brien Date: Mon, 27 Mar 2017 13:37:19 -0400 Subject: [PATCH 039/109] don't hash an empty password --- .gitignore | 2 ++ advanced/Scripts/webpage.sh | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 91014dcd..e7ebe0b6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ __pycache__ .cache .pullapprove.yml +Vagrantfile +.vagrant/ diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 55ae3d96..c6717cf1 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -81,8 +81,15 @@ SetWebPassword(){ exit 1 fi - read -s -p "Enter New Password: " PASSWORD + read -s -p "Enter New Password (Blank for no password): " PASSWORD echo "" + + if [ "${PASSWORD}" == "" ]; then + change_setting "WEBPASSWORD" "" + echo "Password Removed" + exit 0 + fi + read -s -p "Confirm Password: " CONFIRM echo "" if [ "${PASSWORD}" == "${CONFIRM}" ] ; then From f09c1663508aceca758a39a1912c549fa6339042 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 28 Mar 2017 23:02:00 +0100 Subject: [PATCH 040/109] Improve Error 404 page behavior --- advanced/index.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/advanced/index.php b/advanced/index.php index 4cce2857..830ff4f5 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -1,15 +1,31 @@ Date: Fri, 31 Mar 2017 18:55:07 +0100 Subject: [PATCH 041/109] trim down default adlist --- adlists.default | 55 +++++++++++-------------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/adlists.default b/adlists.default index 4a5bca3c..94c75beb 100644 --- a/adlists.default +++ b/adlists.default @@ -1,53 +1,22 @@ -## Pi-hole ad-list default sources. Updated 29/10/2016 ######################### -# # -# To make changes to this file: # -# 1. run `cp /etc/pihole/adlists.default /etc/pihole/adlists.list` # -# 2. run `nano /etc/pihole/adlists.list` # -# 3. Uncomment or comment any of the below lists # -# # -# Know of any other lists? Feel free to let us know about them, or add them # -# to this file! # -################################################################################ - # The below list amalgamates several lists we used previously. # See `https://github.com/StevenBlack/hosts` for details +##StevenBlack's list https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -# Other lists we consider safe: +##MalwareDomains https://mirror1.malwaredomains.com/files/justdomains + +##Cameleon http://sysctl.org/cameleon/hosts + +##Zeustracker https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist + +##Disconnect.me Tracking https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt + +##Disconnect.me Ads https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt -# hosts-file.net list. Updated frequently, but has been known to block legitimate sites. -https://hosts-file.net/ad_servers.txt - -# Mahakala list. Has been known to block legitimate domains including the entire .com range. -# Warning: Due to the sheer size of this list, the web admin console will be unresponsive. -#https://adblock.mahakala.is/ - -# ADZHOSTS list. Has been known to block legitimate domains -#http://pilotfiber.dl.sourceforge.net/project/adzhosts/HOSTS.txt - -# Windows 10 telemetry list -#https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/win10/spy.txt - -# Securemecca.com list - Also blocks "adult" sites (pornography/gambling etc) -#http://securemecca.com/Downloads/hosts.txt - -# Quidsup's tracker list -#https://raw.githubusercontent.com/quidsup/notrack/master/trackers.txt - -# Block the BBC News website Breaking News banner -#https://raw.githubusercontent.com/BreakingTheNews/BreakingTheNews.github.io/master/hosts - -# Untested Lists: -#https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt -#https://raw.githubusercontent.com/Dawsey21/Lists/master/main-blacklist.txt -#http://malwaredomains.lehigh.edu/files/domains.txt -# Following two lists should be used simultaneously: (readme https://github.com/notracking/hosts-blocklists/) -#https://raw.github.com/notracking/hosts-blocklists/master/hostnames.txt -#https://raw.github.com/notracking/hosts-blocklists/master/domains.txt -# Combination of several host files on the internet (warning some facebook domains are also blocked but you can go to facebook.com). See https://github.com/mat1th/Dns-add-block for more information. -#https://raw.githubusercontent.com/mat1th/Dns-add-block/master/hosts +##Hosts-file.net +https://hosts-file.net/ad_servers.txt \ No newline at end of file From ce97896ffd9f9cfd7650804c84524978705403eb Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:00:04 +0100 Subject: [PATCH 042/109] account for new `adlists.custom` file --- gravity.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7441dd87..af6c8599 100755 --- a/gravity.sh +++ b/gravity.sh @@ -30,6 +30,7 @@ PIHOLE_COMMAND="/usr/local/bin/pihole" adListFile=/etc/pihole/adlists.list adListDefault=/etc/pihole/adlists.default +adListCustom=/etc/pihole/adlists.custom whitelistScript="${PIHOLE_COMMAND} -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt @@ -75,8 +76,8 @@ gravity_collapse() { echo ":::" #Decide if we're using a custom ad block list, or defaults. if [ -f ${adListFile} ]; then - #custom file found, use this instead of default - echo -n "::: Custom adList file detected. Reading..." + #User has disabled one or more default lists + echo -n "::: Changes to default list detected. Reading adlists.list..." sources=() while IFS= read -r line || [[ -n "$line" ]]; do #Do not read commented out or blank lines @@ -88,8 +89,8 @@ gravity_collapse() { done < ${adListFile} echo " done!" else - #no custom file found, use defaults! - echo -n "::: No custom adlist file detected, reading from default file..." + # + echo -n "::: No changes to default list detected. Reading adlists.default..." sources=() while IFS= read -r line || [[ -n "$line" ]]; do #Do not read commented out or blank lines @@ -101,6 +102,19 @@ gravity_collapse() { done < ${adListDefault} echo " done!" fi + + if [ -f ${adListCustom} ]; then + echo -n "Custom additional lists detected. Reading adlists.custom..." + while IFS= read -r line || [[ -n "$line" ]]; do + #Do not read commented out or blank lines + if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then + echo "" > /dev/null + else + sources+=(${line}) + fi + done < ${adListCustom} + echo " done!" + fi } # patternCheck - check to see if curl downloaded any new files. From e720de401d1a8dbe17006c94addb150ec1f782d6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:16:09 +0100 Subject: [PATCH 043/109] One file to rule them all, same functionality (made changes and want to go back to default? Delete your adlists.list) --- gravity.sh | 72 ++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/gravity.sh b/gravity.sh index af6c8599..17166a85 100755 --- a/gravity.sh +++ b/gravity.sh @@ -29,8 +29,8 @@ EOM PIHOLE_COMMAND="/usr/local/bin/pihole" adListFile=/etc/pihole/adlists.list -adListDefault=/etc/pihole/adlists.default -adListCustom=/etc/pihole/adlists.custom +adListDefault=/etc/pihole/adlists.default #being deprecated +adListRepoDefault=/etc/.pihole/adlists.default whitelistScript="${PIHOLE_COMMAND} -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt @@ -72,49 +72,35 @@ fi ########################### # collapse - begin formation of pihole gravity_collapse() { + + #New Logic: + # Does /etc/pihole/adlists.list exist? If so leave it alone + # If not, cp /etc/.pihole/adlists.default /etc/pihole/adlists.list + # Read from adlists.list + + #The following two blocks will sort out any missing adlists in the /etc/pihole directory, and remove legacy adlists.default + if [ -f ${adListDefault} ] && [ -f ${adListFile} ]; then + rm ${adListDefault} + fi + + if [ ! -f ${adListFile} ]; then + cp ${adListRepoDefault} ${adListFile} + fi + echo "::: Neutrino emissions detected..." echo ":::" - #Decide if we're using a custom ad block list, or defaults. - if [ -f ${adListFile} ]; then - #User has disabled one or more default lists - echo -n "::: Changes to default list detected. Reading adlists.list..." - sources=() - while IFS= read -r line || [[ -n "$line" ]]; do - #Do not read commented out or blank lines - if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then - echo "" > /dev/null - else - sources+=(${line}) - fi - done < ${adListFile} - echo " done!" - else - # - echo -n "::: No changes to default list detected. Reading adlists.default..." - sources=() - while IFS= read -r line || [[ -n "$line" ]]; do - #Do not read commented out or blank lines - if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then - echo "" > /dev/null - else - sources+=(${line}) - fi - done < ${adListDefault} - echo " done!" - fi - - if [ -f ${adListCustom} ]; then - echo -n "Custom additional lists detected. Reading adlists.custom..." - while IFS= read -r line || [[ -n "$line" ]]; do - #Do not read commented out or blank lines - if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then - echo "" > /dev/null - else - sources+=(${line}) - fi - done < ${adListCustom} - echo " done!" - fi + #User has disabled one or more default lists + echo -n "::: Pulling source lists into range..." + sources=() + while IFS= read -r line || [[ -n "$line" ]]; do + #Do not read commented out or blank lines + if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then + echo "" > /dev/null + else + sources+=(${line}) + fi + done < ${adListFile} + echo " done!" } # patternCheck - check to see if curl downloaded any new files. From bdc6bd41358680937c7d904fa51f5ae86a4239ad Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:18:28 +0100 Subject: [PATCH 044/109] Don't need this comment anymore --- gravity.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 17166a85..05593d1e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -89,7 +89,6 @@ gravity_collapse() { echo "::: Neutrino emissions detected..." echo ":::" - #User has disabled one or more default lists echo -n "::: Pulling source lists into range..." sources=() while IFS= read -r line || [[ -n "$line" ]]; do From 02040cd25d4d4035fa0ae4b18ca63ad51ed34a9b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:23:26 +0100 Subject: [PATCH 045/109] We no longer need to do this, either --- gravity.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index 05593d1e..34e03ca2 100755 --- a/gravity.sh +++ b/gravity.sh @@ -403,8 +403,6 @@ if [[ "${forceGrav}" == true ]]; then echo " done!" fi -#Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list -cp /etc/.pihole/adlists.default /etc/pihole/adlists.default gravity_collapse gravity_spinup if [[ "${skipDownload}" == false ]]; then From b4bc90fb8519fec1e1c5b9585aa14996e5b84c13 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:35:52 +0100 Subject: [PATCH 046/109] add in CustomizeAdlists function --- advanced/Scripts/webpage.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9637cc6f..b15daf88 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -319,6 +319,22 @@ SetWebUILayout(){ } +CustomizeAdLists() { + + list = "/etc/pihole/adlists.list" + + if [[ "${args[2]}" == "enable" ]] ; then + sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" + elif [[ "${args[2]}" == "disable" ]] ; then + sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" + elif [[ "${args[2]}" == "add" && "${args[3]}" == "user" ]] ; then + echo "${args[3]}" >> /etc/pihole/adlists.user + else + echo "Not permitted" + return 1 + fi +} + SetPrivacyMode(){ if [[ "${args[2]}" == "true" ]] ; then From 3a3dde629896ba8a02c110e195bec08b19482bf0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:03:56 +0100 Subject: [PATCH 047/109] add adlist argument redirector --- advanced/Scripts/webpage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index b15daf88..02568134 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -458,6 +458,7 @@ main() { "hostrecord" ) SetHostRecord;; "-i" | "interface" ) SetListeningMode;; "-t" | "teleporter" ) Teleporter;; + "adlist" ) CustomizeAdLists;; * ) helpFunc;; esac From 5435b93df2764f7d6e67749e8eac29d180abba27 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:05:45 +0100 Subject: [PATCH 048/109] remove spaces --- 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 02568134..887b8f34 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -321,7 +321,7 @@ SetWebUILayout(){ CustomizeAdLists() { - list = "/etc/pihole/adlists.list" + list="/etc/pihole/adlists.list" if [[ "${args[2]}" == "enable" ]] ; then sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" From af2cff5177be159ad224b0dd2cb3403c375b3b02 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:13:04 +0100 Subject: [PATCH 049/109] remove call to user list --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 887b8f34..974dbdb5 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -327,8 +327,8 @@ CustomizeAdLists() { sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" elif [[ "${args[2]}" == "disable" ]] ; then sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" - elif [[ "${args[2]}" == "add" && "${args[3]}" == "user" ]] ; then - echo "${args[3]}" >> /etc/pihole/adlists.user + elif [[ "${args[2]}" == "add" ]] ; then + echo "${args[3]}" >> ${list} else echo "Not permitted" return 1 From 42393123a0341e8e00eadbdd14ff9dfeb7250489 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:15:13 +0100 Subject: [PATCH 050/109] add newline to adlists.default --- adlists.default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adlists.default b/adlists.default index 94c75beb..f91d7020 100644 --- a/adlists.default +++ b/adlists.default @@ -19,4 +19,4 @@ https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt ##Hosts-file.net -https://hosts-file.net/ad_servers.txt \ No newline at end of file +https://hosts-file.net/ad_servers.txt From 1f74b1e2fdff929ec280573210aa914d7554b03f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 21:12:17 +0100 Subject: [PATCH 051/109] newline --- adlists.default | 1 + 1 file changed, 1 insertion(+) diff --git a/adlists.default b/adlists.default index f91d7020..cbc1bfb3 100644 --- a/adlists.default +++ b/adlists.default @@ -20,3 +20,4 @@ https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt ##Hosts-file.net https://hosts-file.net/ad_servers.txt + From 153031482f77c8ee4757093c8c5b94b3f8afc6f6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 22:51:10 +0100 Subject: [PATCH 052/109] Add delete mode to adlist command. Might be abetter way to do this --- advanced/Scripts/webpage.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 974dbdb5..f604a00f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -329,6 +329,9 @@ CustomizeAdLists() { sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" elif [[ "${args[2]}" == "add" ]] ; then echo "${args[3]}" >> ${list} + elif [[ "${args[2]}" == "del" ]] ; then + var=$(echo "${args[3]}" | sed 's/\//\\\//g') + sed -i "/${var}/Id" "${list}" else echo "Not permitted" return 1 From 3cf9942465d51a94035bedef72349e9889e22da2 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 23:00:56 +0100 Subject: [PATCH 053/109] spacing fixed --- 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 f604a00f..5b121b44 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -329,9 +329,9 @@ CustomizeAdLists() { sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" elif [[ "${args[2]}" == "add" ]] ; then echo "${args[3]}" >> ${list} - elif [[ "${args[2]}" == "del" ]] ; then - var=$(echo "${args[3]}" | sed 's/\//\\\//g') - sed -i "/${var}/Id" "${list}" + elif [[ "${args[2]}" == "del" ]] ; then + var=$(echo "${args[3]}" | sed 's/\//\\\//g') + sed -i "/${var}/Id" "${list}" else echo "Not permitted" return 1 From ce86205df0fbd0499e1770b6d69c7311beaa1d50 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sun, 2 Apr 2017 12:44:00 -0400 Subject: [PATCH 054/109] Use correct agent when downloading adaway.org list See https://discourse.pi-hole.net/t/2278 --- gravity.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7441dd87..c1794c33 100755 --- a/gravity.sh +++ b/gravity.sh @@ -189,17 +189,21 @@ gravity_spinup() { # Use a case statement to download lists that need special cURL commands # to complete properly and reset the user agent when required case "${domain}" in - "adblock.mahakala.is") + "adblock.mahakala.is") agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' cmd_ext="-e http://forum.xda-developers.com/" ;; + + "adaway.org") + agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' + ;; "pgl.yoyo.org") cmd_ext="-d mimetype=plaintext -d hostformat=hosts" ;; - # Default is a simple request - *) cmd_ext="" + # Default is a simple request + *) cmd_ext="" esac if [[ "${skipDownload}" == false ]]; then echo -n "::: Getting $domain list..." From ad9575ce18ddd7c5262c9af7540e7bcc8e9893d1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 3 Apr 2017 16:28:18 +0200 Subject: [PATCH 055/109] Recognize more host names --- advanced/index.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index 830ff4f5..0ff84735 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -19,8 +19,19 @@ $uriExt = pathinfo($uri, PATHINFO_EXTENSION); // Define which URL extensions get rendered as "Website Blocked" $webExt = array('asp', 'htm', 'html', 'php', 'rss', 'xml'); +$AUTHORIZED_HOSTNAMES = array( + $ipv4, + $ipv6, + str_replace(array("[","]"), array("",""), $_SERVER["SERVER_NAME"]), + "pi.hole", + "localhost"); +// Allow user set virtual hostnames +$virtual_host = getenv('VIRTUAL_HOST'); +if (! empty($virtual_host)) + array_push($AUTHORIZED_HOSTNAMES, $virtual_host); + // Immediately quit since we didn't block this page (the IP address or pi.hole is explicitly requested) -if(validIP($serverName) || $serverName === "pi.hole") +if(validIP($serverName) || in_array($serverName,$AUTHORIZED_HOSTNAMES)) { http_response_code(404); die(); From 7e0aa822b6df4d464b8d270381be62270806aaaf Mon Sep 17 00:00:00 2001 From: Flo Date: Mon, 3 Apr 2017 17:29:57 +0200 Subject: [PATCH 056/109] Match the Pi-hole brand (#1358) * Update README.md * Update index.php * Update basic-install.sh * Update piholeCheckout.sh * Update update.sh * Update CONTRIBUTING.md * Update the Pi-hole brand tip in CONTRIBUTING.md Use a better formulation. * Update README.md 2 --- CONTRIBUTING.md | 1 + README.md | 2 +- advanced/Scripts/piholeCheckout.sh | 2 +- advanced/Scripts/update.sh | 2 +- advanced/index.php | 4 ++-- automated install/basic-install.sh | 10 +++++----- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d342a8b5..8cb7ccb9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,4 +35,5 @@ When requesting or submitting new features, first consider whether it might be u - Before Submitting your Pull Request, merge `development` with your new branch and fix any conflicts. (Make sure you don't break anything in development!) - Please use the [Google Style Guide for Shell](https://google.github.io/styleguide/shell.xml) for your code submission styles. - Commit Unix line endings. +- Please use the Pi-hole brand: **Pi-hole** (Take a special look at the capitalized 'P' and a low 'h' with a hyphen) - (Optional fun) keep to the theme of Star Trek/black holes/gravity. diff --git a/README.md b/README.md index 3369d7e2..c0d6cb84 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my- - [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) - [Windows Tray Stat Application](https://github.com/goldbattle/copernicus) - [Let your blink1 device blink when Pi-hole filters ads](https://gist.github.com/elpatron68/ec0b4c582e5abf604885ac1e068d233f) -- [Pi-Hole Prometheus exporter](https://github.com/nlamirault/pihole_exporter) : a [Prometheus](https://prometheus.io/) exporter for Pi-Hole +- [Pi-hole Prometheus exporter](https://github.com/nlamirault/pihole_exporter): a [Prometheus](https://prometheus.io/) exporter for Pi-hole - [Pi-hole Droid - open source Android client](https://github.com/friimaind/pi-hole-droid) ## Coverage diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 3b7abbef..09f20d6b 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -104,7 +104,7 @@ checkout() #This is unlikely if ! is_repo "${PI_HOLE_FILES_DIR}" ; then - echo "::: Critical Error: Core Pi-Hole repo is missing from system!" + echo "::: Critical Error: Core Pi-hole repo is missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 115e2d8c..4fceb931 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -94,7 +94,7 @@ main() { #This is unlikely if ! is_repo "${PI_HOLE_FILES_DIR}" ; then - echo "::: Critical Error: Core Pi-Hole repo is missing from system!" + echo "::: Critical Error: Core Pi-hole repo is missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi diff --git a/advanced/index.php b/advanced/index.php index 0ff84735..eb44ad44 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -1,5 +1,5 @@ Date: Mon, 3 Apr 2017 15:15:44 -0400 Subject: [PATCH 057/109] remove vagrant from gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index e7ebe0b6..91014dcd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,3 @@ __pycache__ .cache .pullapprove.yml -Vagrantfile -.vagrant/ From a832dd7f672340c96e1dfe6a9bad28e8f571b026 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 6 Apr 2017 14:55:21 -0700 Subject: [PATCH 058/109] Update .editorconfig Set path for JS source. --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 325648fc..e5626a07 100644 --- a/.editorconfig +++ b/.editorconfig @@ -28,7 +28,7 @@ indent_size = 4 indent_style = tab # Indentation override for all JS under lib directory -[lib/**.js] +[scripts/**.js] indent_style = space indent_size = 2 From 3eacfa9831507a7fa04ee06ca404b77ba7546328 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 12 Apr 2017 23:13:18 +0200 Subject: [PATCH 059/109] Improve FTL's service script --- advanced/pihole-FTL.service | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index da04738b..a2cbbab1 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -17,7 +17,7 @@ get_pid() { } is_running() { - [ -f "$PIDFILE" ] && ps $(get_pid) > /dev/null 2>&1 + [ -f "$PIDFILE" ] && ps "$(get_pid)" > /dev/null 2>&1 } # Start the service @@ -36,8 +36,8 @@ start() { # Stop the service stop() { if is_running; then - kill $(get_pid) - for i in {1..10}; do + kill "$(get_pid)" + for i in {1..5}; do if ! is_running; then break fi @@ -48,7 +48,8 @@ stop() { echo if is_running; then - echo "Not stopped; may still be shutting down or shutdown may have failed" + echo "Not stopped; may still be shutting down or shutdown may have failed, killing now" + kill -9 "$(get_pid)" exit 1 else echo "Stopped" @@ -61,16 +62,13 @@ stop() { ### main logic ### case "$1" in - start) - start - ;; stop) stop ;; status) status pihole-FTL ;; - restart|reload|condrestart) + start|restart|reload|condrestart) stop start ;; From fcd92d27f706cf2a0fd2049e75960fa1c6deb116 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 12 Apr 2017 19:34:13 +0200 Subject: [PATCH 060/109] Don't use PID file but rather "pidof pihole-FTL" for detecting if another process is already running --- advanced/pihole-FTL.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index a2cbbab1..30cd140f 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -13,11 +13,11 @@ FTLUSER=pihole PIDFILE=/var/run/pihole-FTL.pid get_pid() { - cat "$PIDFILE" + pidof "pihole-FTL" } is_running() { - [ -f "$PIDFILE" ] && ps "$(get_pid)" > /dev/null 2>&1 + ps "$(get_pid)" > /dev/null 2>&1 } # Start the service From 519cb7102234531f1ef17dc63a964138f93d3e7f Mon Sep 17 00:00:00 2001 From: Technicalpyro Date: Wed, 12 Apr 2017 16:05:21 -0400 Subject: [PATCH 061/109] Grammar Fix ] --- .github/ISSUE_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index c985b972..3014625b 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -2,7 +2,7 @@ - [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). - [] The issue I am reporting can be *replicated* -- [] The issue I'm reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)). +- [] The issue I am reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)). **How familiar are you with the codebase?:** From 2e398c5da472a7049f33b8e57efdb59c301e0385 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 14 Apr 2017 17:20:13 +0100 Subject: [PATCH 062/109] 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 320c06e0a4d3f75a0452baab81ebf93c39e3880d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 17 Apr 2017 21:25:15 +0200 Subject: [PATCH 063/109] Flush twice to move data out-of-sight of FTL --- advanced/Scripts/piholeLogFlush.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 63754db2..fd66b255 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -3,18 +3,22 @@ # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. # -# Flushes /var/log/pihole.log +# Flushes Pi-hole's log file # # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - - echo -n "::: Flushing /var/log/pihole.log ..." # Test if logrotate is available on this system 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 else + # Flush both pihole.log and pihole.log.1 (if existing) echo " " > /var/log/pihole.log + if [ -f /var/log/pihole.log.1 ]; then + echo " " > /var/log/pihole.log.1 + fi fi echo "... done!" From 5e308dbd51051177708c1557bfb132f7f5905f8c Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Tue, 18 Apr 2017 20:35:06 -0400 Subject: [PATCH 064/109] Delete the temp files created by gravity --- gravity.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 0dc1e678..0dccd77b 100755 --- a/gravity.sh +++ b/gravity.sh @@ -167,7 +167,11 @@ gravity_transport() { # Process result gravity_patternCheck "${patternBuffer}" ${success} "${err}" - + + # Delete temp file if it hasn't been moved + if [[ -f "${patternBuffer}" ]]; then + rm "${patternBuffer}" + fi } # spinup - main gravity function From f1f70133dc8e61753ffa3515d5afb50a5ea08d93 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 20 Apr 2017 13:52:54 +0200 Subject: [PATCH 065/109] Populate $ipv4 and $ipv6 + fix small error that prevented blocking page from coming up at all. Fixes #1396 --- advanced/index.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index eb44ad44..30bd131c 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -19,15 +19,20 @@ $uriExt = pathinfo($uri, PATHINFO_EXTENSION); // Define which URL extensions get rendered as "Website Blocked" $webExt = array('asp', 'htm', 'html', 'php', 'rss', 'xml'); +// Get IPv4 and IPv6 addresses from setupVars.conf (if available) +$setupVars = parse_ini_file("/etc/pihole/setupVars.conf"); +$ipv4 = isset($setupVars["IPV4_ADDRESS"]) ? explode("/", $setupVars["IPV4_ADDRESS"])[0] : $_SERVER['SERVER_ADDR']; +$ipv6 = isset($setupVars["IPV6_ADDRESS"]) ? explode("/", $setupVars["IPV6_ADDRESS"])[0] : $_SERVER['SERVER_ADDR']; + $AUTHORIZED_HOSTNAMES = array( $ipv4, $ipv6, - str_replace(array("[","]"), array("",""), $_SERVER["SERVER_NAME"]), + str_replace(array("[","]"), array("",""), $_SERVER["SERVER_ADDR"]), "pi.hole", "localhost"); // Allow user set virtual hostnames $virtual_host = getenv('VIRTUAL_HOST'); -if (! empty($virtual_host)) +if (!empty($virtual_host)) array_push($AUTHORIZED_HOSTNAMES, $virtual_host); // Immediately quit since we didn't block this page (the IP address or pi.hole is explicitly requested) From db1e5f10ea1850f0e29a50d6f1beccbf20616e56 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 21 Apr 2017 17:08:15 +0200 Subject: [PATCH 066/109] 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 6a2b885988673ce60de78af85fcb69d284a836c4 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Apr 2017 11:41:08 -0700 Subject: [PATCH 067/109] Update default User Agent to modern browser. Signed-off-by: Dan Schaper --- gravity.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 0dccd77b..a5231d5e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -167,7 +167,7 @@ gravity_transport() { # Process result gravity_patternCheck "${patternBuffer}" ${success} "${err}" - + # Delete temp file if it hasn't been moved if [[ -f "${patternBuffer}" ]]; then rm "${patternBuffer}" @@ -187,7 +187,7 @@ gravity_spinup() { saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension} activeDomains[$i]=${saveLocation} - agent="Mozilla/10.0" + agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36" # Use a case statement to download lists that need special cURL commands # to complete properly and reset the user agent when required @@ -196,7 +196,7 @@ gravity_spinup() { agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' cmd_ext="-e http://forum.xda-developers.com/" ;; - + "adaway.org") agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' ;; From 19e688effbf866416078394e3e25fba75b1519f5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 30 Apr 2017 13:47:07 +0200 Subject: [PATCH 068/109] 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 069/109] 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 070/109] 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 071/109] 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 072/109] 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 073/109] 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 074/109] 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 075/109] 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 076/109] $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 077/109] 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 078/109] 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 079/109] 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 080/109] 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 081/109] 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 082/109] 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 083/109] 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 084/109] 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 085/109] 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 086/109] 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 087/109] 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 088/109] 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 089/109] 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 090/109] 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 091/109] 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 092/109] 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 093/109] 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 094/109] 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 095/109] 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 096/109] 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 097/109] 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 098/109] 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 099/109] 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 100/109] 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) From 7abf3497304075ceafdc370429dada01ea81dfae Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 13 May 2017 21:08:21 +0200 Subject: [PATCH 101/109] Use `echo "ABC" | pihole tricorder` to upload to Pi-hole's medical tricorder. Uses SSL if available. --- pihole | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pihole b/pihole index 4fafe27a..f24461d3 100755 --- a/pihole +++ b/pihole @@ -94,7 +94,7 @@ scanList(){ queryFunc() { method="${3}" - + # If domain contains non ASCII characters, convert domain to punycode if python exists # Cr: https://serverfault.com/a/335079 if [ -z "${2}" ]; then @@ -105,7 +105,7 @@ queryFunc() { else domain="${2}" fi - + # Scan Whitelist, Blacklist and Wildcards lists="/etc/pihole/whitelist.txt /etc/pihole/blacklist.txt $wildcardlist" result=$(scanList ${domain} "${lists}" ${method}) @@ -122,7 +122,7 @@ queryFunc() { [ -n "$method" ] && exact="exact " echo "::: No ${exact}results found for ${domain}" fi - + exit 0 } @@ -268,6 +268,14 @@ piholeCheckoutFunc() { checkout "$@" } +tricorderFunc() { + if command -v openssl &> /dev/null; then + openssl s_client -quiet -connect tricorder.pi-hole.net:9998 2> /dev/null < /dev/stdin + else + nc tricorder.pi-hole.net 9999 < /dev/stdin + fi +} + helpFunc() { cat << EOM ::: Control all Pi-hole specific functions @@ -302,6 +310,7 @@ helpFunc() { ::: 'pihole disable 5m' - will disable blocking for 5 minutes ::: restartdns Restart dnsmasq ::: checkout Check out different branches +::: tricorder Upload log to Pi-hole's medical tricorder (uses SSL when possible) EOM exit 0 } @@ -333,5 +342,6 @@ case "${1}" in "-a" | "admin" ) webpageFunc "$@";; "-t" | "tail" ) tailFunc;; "checkout" ) piholeCheckoutFunc "$@";; + "tricorder" ) tricorderFunc;; * ) helpFunc;; esac From 55f78e3b64470f82e088ecc714187ac5dd972456 Mon Sep 17 00:00:00 2001 From: Adam Hill Date: Sat, 13 May 2017 18:44:41 -0500 Subject: [PATCH 102/109] Update list.sh I believe this has feature parity with `sed /foo/ Id` but also supports busybox, and my alpine docker ;) --- advanced/Scripts/list.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 537ebac3..52c4c569 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -157,8 +157,8 @@ RemoveDomain() { if [[ "${bool}" == true ]]; then # Remove it from the other one echo "::: Removing $1 from $list..." - # /I flag: search case-insensitive - sed -i "/${domain}/Id" "${list}" + # Busybox sed compatible case-insensitive domain removal + sed -i "$(grep -in "^${domain}$" ${list} | awk -F':' '{print $1}' | tr '\n' ',' | sed 's/,$/\n/')d" ${list} reload=true else if [[ "${verbose}" == true ]]; then @@ -174,8 +174,8 @@ RemoveDomain() { if [[ "${bool}" == true ]]; then # Remove it from the other one echo "::: Removing $1 from $list..." - # /I flag: search case-insensitive - sed -i "/address=\/${domain}/Id" "${list}" + # Busybox sed compatible case-insensitive domain removal + sed -i "$(grep -in "/${domain}/" ${list} | awk -F':' '{print $1}' | tr '\n' ',' | sed 's/,$/\n/')d" ${list} reload=true else if [[ "${verbose}" == true ]]; then From 25601b9fcc4a87220cbd641deaf2f079b71994ee Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 13 May 2017 17:49:58 -0700 Subject: [PATCH 103/109] Document `sed` substitution for user readability Comment the oneliner with explanations of what each step does. --- advanced/Scripts/list.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 52c4c569..05806e46 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -158,6 +158,10 @@ RemoveDomain() { # Remove it from the other one echo "::: Removing $1 from $list..." # Busybox sed compatible case-insensitive domain removal + # grep case insensitive domain from list, print line numbers + # split on ':' with awk and print the line number + # For conditions with more than one match, substitute newline with ',' + # sed substitute final trailing ',' with newline sed -i "$(grep -in "^${domain}$" ${list} | awk -F':' '{print $1}' | tr '\n' ',' | sed 's/,$/\n/')d" ${list} reload=true else From b721ed49abaa7cacb743de5547199b3beb11cee4 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Sun, 14 May 2017 11:11:44 +1000 Subject: [PATCH 104/109] Update Help Output (#1467) * File consistency * Tabs to 2 spaces * Corrected indenting * Double braced conditionals * Quoted variables within conditionals * Standardise core help text * Added help text for disable command * Added help text for logging command * Clean up * Fixed certain new lines and spaces * Sync with development branch * Formatting consistency * Tabs to 2 spaces * Corrected indenting * Double braced conditionals * Quoted variables within conditionals * Fixed certain newlines and spaces * Admin help text * Added help text for interface command * Sync with development branch * Formatting consistency * Tabs to 2 spaces * Fixed some wording * Fixed certain spaces * Formatting consistency * Minor wording changes * Tabs to 2 spaces * Corrected indenting * Double braced conditionals * Quoted variables within conditionals * Fixed certain newlines and spaces * Blacklist help text * Formatting consistency * Tabs to 2 spaces * Corrected indenting * Cronometer help text * Formatting consistency * Fixed certain newlines and spaces * Corrected indenting * Checkout warning alteration * Add checkout help text * Corrected help output --- advanced/Scripts/chronometer.sh | 131 ++++++------ advanced/Scripts/list.sh | 313 ++++++++++++++--------------- advanced/Scripts/piholeCheckout.sh | 30 +-- advanced/Scripts/version.sh | 168 +++++++++------- advanced/Scripts/webpage.sh | 187 ++++++++--------- pihole | 250 ++++++++++++----------- 6 files changed, 547 insertions(+), 532 deletions(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 67ff495b..b5d54e5f 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -8,101 +8,98 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -#Functions############################################################################################################## +# Functions piLog="/var/log/pihole.log" gravity="/etc/pihole/gravity.list" . /etc/pihole/setupVars.conf function GetFTLData { - # Open connection to FTL - exec 3<>/dev/tcp/localhost/"$(cat /var/run/pihole-FTL.port)" + # Open connection to FTL + exec 3<>/dev/tcp/localhost/"$(cat /var/run/pihole-FTL.port)" - # Test if connection is open - if { >&3; } 2> /dev/null; then - # Send command to FTL - echo -e ">$1" >&3 + # Test if connection is open + if { >&3; } 2> /dev/null; then + # Send command to FTL + echo -e ">$1" >&3 - # Read input + # Read input + read -r -t 1 LINE <&3 + until [ ! $? ] || [[ "$LINE" == *"EOM"* ]]; do + echo "$LINE" >&1 read -r -t 1 LINE <&3 - until [ ! $? ] || [[ "$LINE" == *"EOM"* ]]; do - echo "$LINE" >&1 - read -r -t 1 LINE <&3 - done + done - # Close connection - exec 3>&- - exec 3<&- - fi + # Close connection + exec 3>&- + exec 3<&- + fi } outputJSON() { - get_summary_data - echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}}" + get_summary_data + echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}}" } get_summary_data() { - local summary=$(GetFTLData "stats") - domains_being_blocked_raw=$(grep "domains_being_blocked" <<< "${summary}" | grep -Eo "[0-9]+$") - domains_being_blocked=$(printf "%'.f" ${domains_being_blocked_raw}) - dns_queries_today_raw=$(grep "dns_queries_today" <<< "$summary" | grep -Eo "[0-9]+$") - dns_queries_today=$(printf "%'.f" ${dns_queries_today_raw}) - ads_blocked_today_raw=$(grep "ads_blocked_today" <<< "$summary" | grep -Eo "[0-9]+$") - ads_blocked_today=$(printf "%'.f" ${ads_blocked_today_raw}) - ads_percentage_today_raw=$(grep "ads_percentage_today" <<< "$summary" | grep -Eo "[0-9.]+$") - LC_NUMERIC=C ads_percentage_today=$(printf "%'.f" ${ads_percentage_today_raw}) + local summary=$(GetFTLData "stats") + domains_being_blocked_raw=$(grep "domains_being_blocked" <<< "${summary}" | grep -Eo "[0-9]+$") + domains_being_blocked=$(printf "%'.f" ${domains_being_blocked_raw}) + dns_queries_today_raw=$(grep "dns_queries_today" <<< "$summary" | grep -Eo "[0-9]+$") + dns_queries_today=$(printf "%'.f" ${dns_queries_today_raw}) + ads_blocked_today_raw=$(grep "ads_blocked_today" <<< "$summary" | grep -Eo "[0-9]+$") + ads_blocked_today=$(printf "%'.f" ${ads_blocked_today_raw}) + ads_percentage_today_raw=$(grep "ads_percentage_today" <<< "$summary" | grep -Eo "[0-9.]+$") + LC_NUMERIC=C ads_percentage_today=$(printf "%'.f" ${ads_percentage_today_raw}) } normalChrono() { - for (( ; ; )); do - get_summary_data - domain=$(GetFTLData recentBlocked) - clear - # Displays a colorful Pi-hole logo - echo " ___ _ _ _" - echo "| _ (_)___| |_ ___| |___" - echo "| _/ |___| ' \/ _ \ / -_)" - echo "|_| |_| |_||_\___/_\___|" - echo "" - echo " ${IPV4_ADDRESS}" - echo "" - uptime | cut -d' ' -f11- - #uptime -p #Doesn't work on all versions of uptime - uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}' - echo "-------------------------------" - echo "Recently blocked:" - echo " $domain" + for (( ; ; )); do + get_summary_data + domain=$(GetFTLData recentBlocked) + clear + # Displays a colorful Pi-hole logo + echo " ___ _ _ _" + echo "| _ (_)___| |_ ___| |___" + echo "| _/ |___| ' \/ _ \ / -_)" + echo "|_| |_| |_||_\___/_\___|" + echo "" + echo " ${IPV4_ADDRESS}" + echo "" + uptime | cut -d' ' -f11- + #uptime -p # Doesn't work on all versions of uptime + uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}' + echo "-------------------------------" + echo "Recently blocked:" + echo " $domain" - echo "Blocking: ${domains_being_blocked}" - echo "Queries: ${dns_queries_today}" - echo "Pi-holed: ${ads_blocked_today} (${ads_percentage_today}%)" + echo "Blocking: ${domains_being_blocked}" + echo "Queries: ${dns_queries_today}" + echo "Pi-holed: ${ads_blocked_today} (${ads_percentage_today}%)" - sleep 5 - done + sleep 5 + done } displayHelp() { - cat << EOM -::: Displays stats about your piHole! -::: -::: Usage: sudo pihole -c [optional:-j] -::: Note: If no option is passed, then stats are displayed on screen, updated every 5 seconds -::: -::: Options: -::: -j, --json output stats as JSON formatted string -::: -h, --help display this help text -EOM - exit 0 + echo "Usage: pihole -c [options] +Example: 'pihole -c -j' +Calculates stats and displays to an LCD + +Options: + -j, --json Output stats as JSON formatted string + -h, --help Display this help text" + exit 0 } if [[ $# = 0 ]]; then - normalChrono + normalChrono fi for var in "$@"; do - case "$var" in - "-j" | "--json" ) outputJSON;; - "-h" | "--help" ) displayHelp;; - * ) exit 1;; - esac + case "$var" in + "-j" | "--json" ) outputJSON;; + "-h" | "--help" ) displayHelp;; + * ) exit 1;; + esac done diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 537ebac3..14b18249 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -3,14 +3,12 @@ # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. # -# Whitelists and blacklists domains +# Whitelist and blacklist domains # # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - - -#globals +# Globals basename=pihole piholeDir=/etc/${basename} whitelist=${piholeDir}/whitelist.txt @@ -27,122 +25,120 @@ listMain="" listAlt="" helpFunc() { + if [[ "${listMain}" == "${whitelist}" ]]; then + letter="w" + word="white" + else + letter="b" + word="black" + fi - if [[ ${listMain} == ${whitelist} ]]; then - letter="w" - word="white" - else - letter="b" - word="black" - fi + echo "Usage: pihole -${letter} [options] +Example: 'pihole -${letter} site.com', or 'pihole -${letter} site1.com site2.com' +${word^}list one or more domains - cat << EOM -::: Immediately ${word}lists one or more domains in the hosts file -::: -::: Usage: pihole -${letter} domain1 [domain2 ...] -::: -::: Options: -::: -d, --delmode Remove domains from the ${word}list -::: -nr, --noreload Update ${word}list without refreshing dnsmasq -::: -q, --quiet Output is less verbose -::: -h, --help Show this help dialog -::: -l, --list Display your ${word}listed domains -EOM -if [[ "${letter}" == "b" ]]; then - echo "::: -wild, --wildcard Add wildcard entry (only blacklist)" -fi - exit 0 +Options:" + + if [[ "${letter}" == "b" ]]; then + echo " -wild, --wildcard Add wildcard entry to blacklist" + fi + +echo " -d, --delmode Remove domain(s) from the ${word}list + -nr, --noreload Update ${word}list without refreshing dnsmasq + -q, --quiet Make output less verbose + -h, --help Show this help dialog + -l, --list Display all your ${word}listed domains" + +exit 0 } EscapeRegexp() { - # This way we may safely insert an arbitrary - # string in our regular expressions - # Also remove leading "." if present - echo $* | sed 's/^\.*//' | sed "s/[]\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g" + # This way we may safely insert an arbitrary + # string in our regular expressions + # Also remove leading "." if present + echo $* | sed 's/^\.*//' | sed "s/[]\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g" } -HandleOther(){ - # First, convert everything to lowercase - domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1") +HandleOther() { + # First, convert everything to lowercase + domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1") - #check validity of domain - validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+\.)*[a-z]{2,63}/') - if [ -z "${validDomain}" ]; then - echo "::: $1 is not a valid argument or domain name" - else - domList=("${domList[@]}" ${validDomain}) - fi + # Check validity of domain + validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+\.)*[a-z]{2,63}/') + if [[ -z "${validDomain}" ]]; then + echo "::: $1 is not a valid argument or domain name" + else + domList=("${domList[@]}" ${validDomain}) + fi } PoplistFile() { - #check whitelist file exists, and if not, create it - if [[ ! -f ${whitelist} ]]; then - touch ${whitelist} - fi - for dom in "${domList[@]}"; do - # Logic : If addmode then add to desired list and remove from the other; if delmode then remove from desired list but do not add to the other - if ${addmode}; then - AddDomain "${dom}" "${listMain}" - RemoveDomain "${dom}" "${listAlt}" - if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then - RemoveDomain "${dom}" "${wildcardlist}" - fi - else - RemoveDomain "${dom}" "${listMain}" - fi - done + # Check whitelist file exists, and if not, create it + if [[ ! -f ${whitelist} ]]; then + touch ${whitelist} + fi + + for dom in "${domList[@]}"; do + # Logic: If addmode then add to desired list and remove from the other; if delmode then remove from desired list but do not add to the other + if ${addmode}; then + AddDomain "${dom}" "${listMain}" + RemoveDomain "${dom}" "${listAlt}" + if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then + RemoveDomain "${dom}" "${wildcardlist}" + fi + else + RemoveDomain "${dom}" "${listMain}" + fi + done } AddDomain() { - list="$2" - domain=$(EscapeRegexp "$1") + list="$2" + domain=$(EscapeRegexp "$1") - if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then + if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then + bool=true + # Is the domain in the list we want to add it to? + grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false - bool=true - #Is the domain in the list we want to add it to? - grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false + if [[ "${bool}" == false ]]; then + # Domain not found in the whitelist file, add it! + if [[ "${verbose}" == true ]]; then + echo "::: Adding $1 to $list..." + fi + reload=true + # Add it to the list we want to add it to + echo "$1" >> "${list}" + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} already exists in ${list}, no need to add!" + fi + fi + elif [[ "${list}" == "${wildcardlist}" ]]; then + source "${piholeDir}/setupVars.conf" + # Remove the /* from the end of the IPv4addr. + IPV4_ADDRESS=${IPV4_ADDRESS%/*} + IPV6_ADDRESS=${IPV6_ADDRESS} - if [[ "${bool}" == false ]]; then - #domain not found in the whitelist file, add it! - if [[ "${verbose}" == true ]]; then - echo "::: Adding $1 to $list..." - fi - reload=true - # Add it to the list we want to add it to - echo "$1" >> "${list}" - else - if [[ "${verbose}" == true ]]; then - echo "::: ${1} already exists in ${list}, no need to add!" - fi - fi + bool=true + # Is the domain in the list? + grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false - elif [[ "${list}" == "${wildcardlist}" ]]; then - - source "${piholeDir}/setupVars.conf" - #Remove the /* from the end of the IPv4addr. - IPV4_ADDRESS=${IPV4_ADDRESS%/*} - IPV6_ADDRESS=${IPV6_ADDRESS} - - bool=true - #Is the domain in the list? - grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false - - if [[ "${bool}" == false ]]; then - if [[ "${verbose}" == true ]]; then - echo "::: Adding $1 to wildcard blacklist..." - fi - reload=true - echo "address=/$1/${IPV4_ADDRESS}" >> "${wildcardlist}" - if [[ ${#IPV6_ADDRESS} > 0 ]] ; then - echo "address=/$1/${IPV6_ADDRESS}" >> "${wildcardlist}" - fi - else - if [[ "${verbose}" == true ]]; then - echo "::: ${1} already exists in wildcard blacklist, no need to add!" - fi - fi - fi + if [[ "${bool}" == false ]]; then + if [[ "${verbose}" == true ]]; then + echo "::: Adding $1 to wildcard blacklist..." + fi + reload=true + echo "address=/$1/${IPV4_ADDRESS}" >> "${wildcardlist}" + if [[ "${#IPV6_ADDRESS}" > 0 ]]; then + echo "address=/$1/${IPV6_ADDRESS}" >> "${wildcardlist}" + fi + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} already exists in wildcard blacklist, no need to add!" + fi + fi + fi } RemoveDomain() { @@ -150,85 +146,82 @@ RemoveDomain() { domain=$(EscapeRegexp "$1") if [[ "${list}" == "${whitelist}" || "${list}" == "${blacklist}" ]]; then - - bool=true - #Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa - grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false - if [[ "${bool}" == true ]]; then - # Remove it from the other one - echo "::: Removing $1 from $list..." - # /I flag: search case-insensitive - sed -i "/${domain}/Id" "${list}" - reload=true - else - if [[ "${verbose}" == true ]]; then - echo "::: ${1} does not exist in ${list}, no need to remove!" - fi + bool=true + # Is it in the list? Logic follows that if its whitelisted it should not be blacklisted and vice versa + grep -Ex -q "${domain}" "${list}" > /dev/null 2>&1 || bool=false + if [[ "${bool}" == true ]]; then + # Remove it from the other one + echo "::: Removing $1 from $list..." + # /I flag: search case-insensitive + sed -i "/${domain}/Id" "${list}" + reload=true + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} does not exist in ${list}, no need to remove!" fi - + fi elif [[ "${list}" == "${wildcardlist}" ]]; then - - bool=true - #Is it in the list? - grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false - if [[ "${bool}" == true ]]; then - # Remove it from the other one - echo "::: Removing $1 from $list..." - # /I flag: search case-insensitive - sed -i "/address=\/${domain}/Id" "${list}" - reload=true - else - if [[ "${verbose}" == true ]]; then - echo "::: ${1} does not exist in ${list}, no need to remove!" - fi + bool=true + # Is it in the list? + grep -e "address=\/${domain}\/" "${wildcardlist}" > /dev/null 2>&1 || bool=false + if [[ "${bool}" == true ]]; then + # Remove it from the other one + echo "::: Removing $1 from $list..." + # /I flag: search case-insensitive + sed -i "/address=\/${domain}/Id" "${list}" + reload=true + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} does not exist in ${list}, no need to remove!" fi + fi fi } Reload() { - # Reload hosts file - pihole -g -sd + # Reload hosts file + pihole -g -sd } Displaylist() { - if [[ ${listMain} == ${whitelist} ]]; then - string="gravity resistant domains" - else - string="domains caught in the sinkhole" - fi - verbose=false - echo -e " Displaying $string \n" - count=1 - while IFS= read -r RD; do - echo "${count}: ${RD}" - count=$((count+1)) - done < "${listMain}" - exit 0; + if [[ "${listMain}" == "${whitelist}" ]]; then + string="gravity resistant domains" + else + string="domains caught in the sinkhole" + fi + verbose=false + echo -e "Displaying $string:\n" + count=1 + while IFS= read -r RD; do + echo "${count}: ${RD}" + count=$((count+1)) + done < "${listMain}" + exit 0; } for var in "$@"; do - case "${var}" in - "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; - "-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";; - "-wild" | "wildcard" ) listMain="${wildcardlist}";; - "-nr"| "--noreload" ) reload=false;; - "-d" | "--delmode" ) addmode=false;; - "-f" | "--force" ) force=true;; - "-q" | "--quiet" ) verbose=false;; - "-h" | "--help" ) helpFunc;; - "-l" | "--list" ) Displaylist;; - * ) HandleOther "${var}";; - esac + case "${var}" in + "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; + "-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";; + "-wild" | "wildcard" ) listMain="${wildcardlist}";; + "-nr"| "--noreload" ) reload=false;; + "-d" | "--delmode" ) addmode=false;; + "-f" | "--force" ) force=true;; + "-q" | "--quiet" ) verbose=false;; + "-h" | "--help" ) helpFunc;; + "-l" | "--list" ) Displaylist;; + * ) HandleOther "${var}";; + esac done shift if [[ $# = 0 ]]; then - helpFunc + helpFunc fi PoplistFile if ${reload}; then - Reload + Reload fi diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 09f20d6b..00bea12c 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -3,7 +3,7 @@ # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. # -# Checkout other branches than master +# Switch Pi-hole subsystems to a different Github branch # # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. @@ -18,9 +18,12 @@ PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # setupVars set in basic-install.sh source "${setupVars}" - update="false" +# Colour codes +red="\e[1;31m" +def="\e[0m" + fully_fetch_repo() { # Add upstream branches to shallow clone local directory="${1}" @@ -35,7 +38,7 @@ fully_fetch_repo() { return 0 } -get_available_branches(){ +get_available_branches() { # Return available branches local directory="${1}" @@ -79,23 +82,23 @@ checkout_pull_branch() { } warning1() { - echo "::: Note that changing the branch is a severe change of your Pi-hole system." - echo "::: This is not supported unless one of the developers explicitly asks you to do this!" - read -r -p "::: Have you read and understood this? [y/N] " response + echo " Please note that changing branches severely alters your Pi-hole subsystems" + echo " Features that work on the master branch, may not on a development branch" + echo -e " ${red}This feature is NOT supported unless a Pi-hole developer explicitly asks!${def}" + read -r -p " Have you read and understood this? [Y/N] " response case ${response} in [yY][eE][sS]|[yY]) - echo "::: Continuing." + echo "::: Continuing with branch change." return 0 ;; *) - echo "::: Aborting." + echo "::: Branch change has been cancelled." return 1 ;; esac } -checkout() -{ +checkout() { local corebranches local webbranches @@ -192,11 +195,10 @@ checkout() if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then echo "::: Running installer to upgrade your installation" if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then - exit 0 + exit 0 else - echo "Unable to complete update, contact Pi-hole" - exit 1 + echo "Unable to complete update, contact Pi-hole" + exit 1 fi fi } - diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 7f96e29a..73888295 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -3,24 +3,29 @@ # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. # -# shows version numbers +# Show version numbers # # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. # Variables DEFAULT="-1" -PHGITDIR="/etc/.pihole/" +COREGITDIR="/etc/.pihole/" WEBGITDIR="/var/www/html/admin/" getLocalVersion() { + # FTL requires a different method + if [[ "$1" == "FTL" ]]; then + pihole-FTL version + return 0 + fi + # Get the tagged version of the local repository local directory="${1}" local version - cd "${directory}" || { echo "${DEFAULT}"; return 1; } - version=$(git describe --tags --always || \ - echo "${DEFAULT}") + cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } + version=$(git describe --tags --always || echo "$DEFAULT") if [[ "${version}" =~ ^v ]]; then echo "${version}" elif [[ "${version}" == "${DEFAULT}" ]]; then @@ -33,13 +38,18 @@ getLocalVersion() { } getLocalHash() { + # Local FTL hash does not exist on filesystem + if [[ "$1" == "FTL" ]]; then + echo "N/A" + return 0 + fi + # Get the short hash of the local repository local directory="${1}" local hash - cd "${directory}" || { echo "${DEFAULT}"; return 1; } - hash=$(git rev-parse --short HEAD || \ - echo "${DEFAULT}") + cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } + hash=$(git rev-parse --short HEAD || echo "$DEFAULT") if [[ "${hash}" == "${DEFAULT}" ]]; then echo "ERROR" return 1 @@ -49,12 +59,33 @@ 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}" 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 @@ -66,72 +97,73 @@ 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 -} - -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 - else - echo "::: Web interface not installed!"; exit 1; +versionOutput() { + [[ "$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") + 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 + output="${1^} version is $current (Latest: $latest)" + elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then + output="Current ${1^} version is $current" + elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then + output="Latest ${1^} version is $latest" + 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" } -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 +errorOutput() { + echo "Invalid Option! Try 'pihole -v -h' for more information." + exit 1 +} + +defaultOutput() { + versionOutput "pi-hole" "$@" + versionOutput "AdminLTE" "$@" + versionOutput "FTL" "$@" } 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 - exit 0 + echo "Usage: pihole -v [REPO | OPTION] [OPTION] +Example: 'pihole -v -p -l' +Show Pi-hole, Admin Console & FTL versions + +Repositories: + -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 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 } -if [[ $# = 0 ]]; then - normalOutput -fi - case "${1}" in - "-a" | "--admin" ) shift; webOutput "$@";; - "-p" | "--pihole" ) shift; coreOutput "$@" ;; - "-h" | "--help" ) helpFunc;; + "-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";; + "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";; + "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; + "--help" ) helpFunc;; + * ) defaultOutput "$@";; esac diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index d3ad3032..6626dab8 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -8,7 +8,6 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - readonly setupVars="/etc/pihole/setupVars.conf" readonly dnsmasqconfig="/etc/dnsmasq.d/01-pihole.conf" readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf" @@ -16,23 +15,19 @@ readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf" readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf" helpFunc() { - cat << EOM -::: Set admin options for the web interface of pihole -::: -::: Usage: pihole -a [options] -::: -::: Options: -::: -p, password Set web interface password, an empty input will remove any previously set password -::: -c, celsius Set Celsius temperature unit -::: -f, fahrenheit Set Fahrenheit temperature unit -::: -k, kelvin Set Kelvin temperature unit -::: -h, --help Show this help dialog -::: -i, interface Setup interface listening behavior of dnsmasq -::: pihole -a -i local : Listen on all interfaces, but allow only queries from -::: devices that are at most one hop away (local devices) -::: pihole -a -i single : Listen only on one interface (see PIHOLE_INTERFACE) -::: pihole -a -i all : Listen on all interfaces, permit all origins -EOM + echo "Usage: pihole -a [options] +Example: pihole -a -p password +Set options for the Admin Console + +Options: + -f, flush Flush the Pi-hole log + -p, password Set Admin Console password + -c, celsius Set Celsius as preferred temperature unit + -f, fahrenheit Set Fahrenheit as preferred temperature unit + -k, kelvin Set Kelvin as preferred temperature unit + -h, --help Show this help dialog + -i, interface Specify dnsmasq's interface listening behavior + Add '-h' for more info on interface usage" exit 0 } @@ -61,21 +56,18 @@ delete_dnsmasq_setting() { sed -i "/${1}/d" "${dnsmasqconfig}" } -SetTemperatureUnit(){ - +SetTemperatureUnit() { change_setting "TEMPERATUREUNIT" "${unit}" - } -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} +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(){ - +SetWebPassword() { if [ "${SUDO_USER}" == "www-data" ]; then echo "Security measure: user www-data is not allowed to change webUI password!" echo "Exiting" @@ -175,8 +167,7 @@ trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE3 } -SetDNSServers(){ - +SetDNSServers() { # Save setting to file delete_setting "PIHOLE_DNS" IFS=',' read -r -a array <<< "${args[2]}" @@ -207,72 +198,59 @@ SetDNSServers(){ # Restart dnsmasq to load new configuration RestartDNS - } -SetExcludeDomains(){ - +SetExcludeDomains() { change_setting "API_EXCLUDE_DOMAINS" "${args[2]}" - } -SetExcludeClients(){ - +SetExcludeClients() { change_setting "API_EXCLUDE_CLIENTS" "${args[2]}" - } -Reboot(){ - +Reboot() { nohup bash -c "sleep 5; reboot" &> /dev/null /dev/null else service dnsmasq restart &> /dev/null fi - } -SetQueryLogOptions(){ - +SetQueryLogOptions() { change_setting "API_QUERY_LOG_SHOW" "${args[2]}" - } ProcessDHCPSettings() { - source "${setupVars}" if [[ "${DHCP_ACTIVE}" == "true" ]]; then + interface=$(grep 'PIHOLE_INTERFACE=' /etc/pihole/setupVars.conf | sed "s/.*=//") - interface=$(grep 'PIHOLE_INTERFACE=' /etc/pihole/setupVars.conf | sed "s/.*=//") + # Use eth0 as fallback interface + if [ -z ${interface} ]; then + interface="eth0" + fi - # Use eth0 as fallback interface - if [ -z ${interface} ]; then - interface="eth0" - fi + if [[ "${PIHOLE_DOMAIN}" == "" ]]; then + PIHOLE_DOMAIN="local" + change_setting "PIHOLE_DOMAIN" "${PIHOLE_DOMAIN}" + fi - if [[ "${PIHOLE_DOMAIN}" == "" ]]; then - PIHOLE_DOMAIN="local" - change_setting "PIHOLE_DOMAIN" "${PIHOLE_DOMAIN}" - fi + if [[ "${DHCP_LEASETIME}" == "0" ]]; then + leasetime="infinite" + elif [[ "${DHCP_LEASETIME}" == "" ]]; then + leasetime="24h" + change_setting "DHCP_LEASETIME" "${leasetime}" + else + leasetime="${DHCP_LEASETIME}h" + fi - if [[ "${DHCP_LEASETIME}" == "0" ]]; then - leasetime="infinite" - elif [[ "${DHCP_LEASETIME}" == "" ]]; then - leasetime="24h" - change_setting "DHCP_LEASETIME" "${leasetime}" - else - leasetime="${DHCP_LEASETIME}h" - fi - - # Write settings to file - echo "############################################################################### + # Write settings to file + echo "############################################################################### # DHCP SERVER CONFIG FILE AUTOMATICALLY POPULATED BY PI-HOLE WEB INTERFACE. # # ANY CHANGES MADE TO THIS FILE WILL BE LOST ON CHANGE # ############################################################################### @@ -283,26 +261,25 @@ dhcp-leasefile=/etc/pihole/dhcp.leases #quiet-dhcp " > "${dhcpconfig}" -if [[ "${PIHOLE_DOMAIN}" != "none" ]]; then - echo "domain=${PIHOLE_DOMAIN}" >> "${dhcpconfig}" -fi + if [[ "${PIHOLE_DOMAIN}" != "none" ]]; then + echo "domain=${PIHOLE_DOMAIN}" >> "${dhcpconfig}" + fi - if [[ "${DHCP_IPv6}" == "true" ]]; then -echo "#quiet-dhcp6 + if [[ "${DHCP_IPv6}" == "true" ]]; then + echo "#quiet-dhcp6 #enable-ra dhcp-option=option6:dns-server,[::] dhcp-range=::100,::1ff,constructor:${interface},ra-names,slaac,${leasetime} ra-param=*,0,0 " >> "${dhcpconfig}" - fi + fi else rm "${dhcpconfig}" &> /dev/null fi } -EnableDHCP(){ - +EnableDHCP() { change_setting "DHCP_ACTIVE" "true" change_setting "DHCP_START" "${args[2]}" change_setting "DHCP_END" "${args[3]}" @@ -320,8 +297,7 @@ EnableDHCP(){ RestartDNS } -DisableDHCP(){ - +DisableDHCP() { change_setting "DHCP_ACTIVE" "false" # Remove possible old setting from file @@ -333,23 +309,20 @@ DisableDHCP(){ RestartDNS } -SetWebUILayout(){ - +SetWebUILayout() { change_setting "WEBUIBOXEDLAYOUT" "${args[2]}" - } CustomizeAdLists() { - list="/etc/pihole/adlists.list" - if [[ "${args[2]}" == "enable" ]] ; then + if [[ "${args[2]}" == "enable" ]]; then sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" - elif [[ "${args[2]}" == "disable" ]] ; then + elif [[ "${args[2]}" == "disable" ]]; then sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" - elif [[ "${args[2]}" == "add" ]] ; then + elif [[ "${args[2]}" == "add" ]]; then echo "${args[3]}" >> ${list} - elif [[ "${args[2]}" == "del" ]] ; then + elif [[ "${args[2]}" == "del" ]]; then var=$(echo "${args[3]}" | sed 's/\//\\\//g') sed -i "/${var}/Id" "${list}" else @@ -358,18 +331,15 @@ CustomizeAdLists() { fi } -SetPrivacyMode(){ - - if [[ "${args[2]}" == "true" ]] ; then +SetPrivacyMode() { + if [[ "${args[2]}" == "true" ]]; then change_setting "API_PRIVACY_MODE" "true" else change_setting "API_PRIVACY_MODE" "false" fi - } ResolutionSettings() { - typ="${args[2]}" state="${args[3]}" @@ -378,11 +348,9 @@ ResolutionSettings() { elif [[ "${typ}" == "clients" ]]; then change_setting "API_GET_CLIENT_HOSTNAME" "${state}" fi - } AddDHCPStaticAddress() { - mac="${args[2]}" ip="${args[3]}" host="${args[4]}" @@ -397,18 +365,14 @@ AddDHCPStaticAddress() { # Full info given echo "dhcp-host=${mac},${ip},${host}" >> "${dhcpstaticconfig}" fi - } RemoveDHCPStaticAddress() { - mac="${args[2]}" sed -i "/dhcp-host=${mac}.*/d" "${dhcpstaticconfig}" - } -SetHostRecord(){ - +SetHostRecord() { if [ -n "${args[3]}" ]; then change_setting "HOSTRECORD" "${args[2]},${args[3]}" echo "Setting host record for ${args[2]} -> ${args[3]}" @@ -421,17 +385,28 @@ SetHostRecord(){ # Restart dnsmasq to load new configuration RestartDNS - } -SetListeningMode(){ - +SetListeningMode() { source "${setupVars}" + + if [[ "$3" == "-h" ]]; then + echo "Usage: pihole -a -i [interface] +Example: 'pihole -a -i local' +Specify dnsmasq's network interface listening behavior - if [[ "${args[2]}" == "all" ]] ; then +Interfaces: + local Listen on all interfaces, but only allow queries from + devices that are at most one hop away (local devices) + single Listen only on ${PIHOLE_INTERFACE} interface + all Listen on all interfaces, permit all origins" + exit 0 + fi + + if [[ "${args[2]}" == "all" ]]; then echo "Listening on all interfaces, permiting all origins, hope you have a firewall!" change_setting "DNSMASQ_LISTENING" "all" - elif [[ "${args[2]}" == "local" ]] ; then + elif [[ "${args[2]}" == "local" ]]; then echo "Listening on all interfaces, permitting only origins that are at most one hop away (local devices)" change_setting "DNSMASQ_LISTENING" "local" else @@ -446,17 +421,14 @@ SetListeningMode(){ # Restart dnsmasq to load new configuration RestartDNS fi - } -Teleporter() -{ +Teleporter() { local datetimestamp=$(date "+%Y-%m-%d_%H-%M-%S") php /var/www/html/admin/scripts/pi-hole/php/teleporter.php > "pi-hole-teleporter_${datetimestamp}.zip" } main() { - args=("$@") case "${args[1]}" in @@ -479,7 +451,7 @@ main() { "addstaticdhcp" ) AddDHCPStaticAddress;; "removestaticdhcp" ) RemoveDHCPStaticAddress;; "hostrecord" ) SetHostRecord;; - "-i" | "interface" ) SetListeningMode;; + "-i" | "interface" ) SetListeningMode "$@";; "-t" | "teleporter" ) Teleporter;; "adlist" ) CustomizeAdLists;; * ) helpFunc;; @@ -490,5 +462,4 @@ main() { if [[ $# = 0 ]]; then helpFunc fi - } diff --git a/pihole b/pihole index 83e13000..79a5c35d 100755 --- a/pihole +++ b/pihole @@ -9,11 +9,11 @@ # Please see LICENSE file for your rights under this license. readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" - readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" + # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then - if [ -x "$(command -v sudo)" ];then + if [[ -x "$(command -v sudo)" ]]; then exec sudo bash "$0" "$@" exit $? else @@ -80,66 +80,49 @@ updateGravityFunc() { exit 0 } -scanList(){ +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 "(^|\s|\/)${domain}($|\s|\/)" ${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 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" + [[ ! -t 1 ]] && 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 } @@ -163,16 +146,16 @@ versionFunc() { restartDNS() { dnsmasqPid=$(pidof dnsmasq) - if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - if [ -x "$(command -v systemctl)" ]; then + if [[ "${dnsmasqPid}" ]]; then + # Service already running - reload config + if [[ -x "$(command -v systemctl)" ]]; then systemctl restart dnsmasq else service dnsmasq restart fi else - # service not running, start it up - if [ -x "$(command -v systemctl)" ]; then + # Service not running, start it up + if [[ -x "$(command -v systemctl)" ]]; then systemctl start dnsmasq else service dnsmasq start @@ -181,16 +164,25 @@ restartDNS() { } piholeEnable() { - if [[ "${1}" == "0" ]] ; then - #Disable Pihole + if [[ "${2}" == "-h" ]]; then + echo "Usage: pihole disable [time] +Example: 'pihole disable', or 'pihole disable 5m' +Disable Pi-hole subsystems + +Time: + #s Disable Pi-hole functionality for # second(s) + #m Disable Pi-hole functionality for # minute(s)" + exit 0 + elif [[ "${1}" == "0" ]]; then + # Disable Pi-hole sed -i 's/^addn-hosts=\/etc\/pihole\/gravity.list/#addn-hosts=\/etc\/pihole\/gravity.list/' /etc/dnsmasq.d/01-pihole.conf echo "::: Blocking has been disabled!" - if [[ $# > 1 ]] ; then - if [[ ${2} == *"s"* ]] ; then + if [[ $# > 1 ]]; then + if [[ "${2}" == *"s"* ]]; then tt=${2%"s"} echo "::: Blocking will be re-enabled in ${tt} seconds" nohup bash -c "sleep ${tt}; pihole enable" /dev/null & - elif [[ ${2} == *"m"* ]] ; then + elif [[ "${2}" == *"m"* ]]; then tt=${2%"m"} echo "::: Blocking will be re-enabled in ${tt} minutes" tt=$((${tt}*60)) @@ -204,7 +196,7 @@ piholeEnable() { fi fi else - #Enable pihole + # Enable Pi-hole echo "::: Blocking has been enabled!" sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf fi @@ -213,15 +205,23 @@ piholeEnable() { piholeLogging() { shift + if [[ "${1}" == "-h" ]]; then + echo "Usage: pihole logging [options] +Example: 'pihole logging on' +Specify whether the Pi-hole log should be used - if [[ "${1}" == "off" ]] ; then - #Disable Logging +Options: + on Enable the Pi-hole log at /var/log/pihole.log + off Disable the Pi-hole log at /var/log/pihole.log" + exit 0 + elif [[ "${1}" == "off" ]]; then + # Disable logging sed -i 's/^log-queries/#log-queries/' /etc/dnsmasq.d/01-pihole.conf sed -i 's/^QUERY_LOGGING=true/QUERY_LOGGING=false/' /etc/pihole/setupVars.conf pihole -f echo "::: Logging has been disabled!" - elif [[ "${1}" == "on" ]] ; then - #Enable logging + elif [[ "${1}" == "on" ]]; then + # Enable logging sed -i 's/^#log-queries/log-queries/' /etc/dnsmasq.d/01-pihole.conf sed -i 's/^QUERY_LOGGING=false/QUERY_LOGGING=true/' /etc/pihole/setupVars.conf echo "::: Logging has been enabled!" @@ -233,12 +233,12 @@ piholeLogging() { } piholeStatus() { - if [[ $(netstat -plnt | grep -c ':53 ') > 0 ]]; then - if [[ "${1}" != "web" ]] ; then + if [[ "$(netstat -plnt | grep -c ':53 ')" -gt "0" ]]; then + if [[ "${1}" != "web" ]]; then echo "::: DNS service is running" fi else - if [[ "${1}" == "web" ]] ; then + if [[ "${1}" == "web" ]]; then echo "-1"; else echo "::: DNS service is NOT running" @@ -246,28 +246,28 @@ piholeStatus() { return fi - if [[ $(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf) ]] ; then - #list is commented out - if [[ "${1}" == "web" ]] ; then + if [[ "$(grep -i "^#addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then + # List is commented out + if [[ "${1}" == "web" ]]; then echo 0; else echo "::: Pi-hole blocking is Disabled"; fi - elif [[ $(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf) ]] ; then - #list set - if [[ "${1}" == "web" ]] ; then + elif [[ "$(grep -i "^addn-hosts=/" /etc/dnsmasq.d/01-pihole.conf)" ]]; then + # List set + if [[ "${1}" == "web" ]]; then echo 1; else echo "::: Pi-hole blocking is Enabled"; fi else - #addn-host not found - if [[ "${1}" == "web" ]] ; then + # Addn-host not found + if [[ "${1}" == "web" ]]; then echo 99 else echo "::: No hosts file linked to dnsmasq, adding it in enabled state" fi - #add addn-host= to dnsmasq + # Add addn-host= to dnsmasq echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf restartDNS fi @@ -280,46 +280,66 @@ tailFunc() { } piholeCheckoutFunc() { + if [[ "$2" == "-h" ]]; then + echo "Usage: pihole checkout [repo] [branch] +Example: 'pihole checkout master' or 'pihole checkout core dev' +Switch Pi-hole subsystems to a different Github branch + +Repositories: + core [branch] Change the branch of Pi-hole's core subsystem + web [branch] Change the branch of Admin Console subsystem + +Branches: + master Update subsystems to the latest stable release + dev Update subsystems to the latest development release" + exit 0 + fi + source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh shift checkout "$@" } helpFunc() { - cat << EOM -::: Control all Pi-hole specific functions -::: -::: Usage: pihole [options] -::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -a (admin) for more information on usage -::: -::: Options: -::: -w, whitelist Whitelist domain(s) -::: -b, blacklist Blacklist domain(s) (exact match) -::: -wild, wildcard Blacklist whole domain(s) (wildcard) -::: -d, debug Start a debugging session -::: Automated debugging can be enabled with '-a'. -::: 'pihole -d -a' -::: -f, flush Flush the 'pihole.log' file -::: -t, tail Output the last lines of the 'pihole.log' file. Lines are appended as the file grows -::: -up, updatePihole Update Pi-hole components -::: -r, reconfigure Reconfigure or Repair Pi-hole -::: -g, updateGravity Update the list of ad-serving domains -::: -c, chronometer Calculates stats and displays to an LCD -::: -h, help Show this help dialog -::: -v, version Show installed versions of Pi-hole and Web-Admin -::: -q, query Query the adlists for a specific domain -::: 'pihole -q domain -exact' shows exact matches only -::: -l, logging Enable or Disable logging (pass 'on' or 'off') -::: -a, admin Admin webpage options -::: uninstall Uninstall Pi-hole from your system! :( -::: status Display if Pi-hole is Enabled or Disabled -::: enable Enable Pi-hole DNS Blocking -::: disable Disable Pi-hole DNS Blocking -::: Blocking can also be disabled only temporarily, e.g., -::: 'pihole disable 5m' - will disable blocking for 5 minutes -::: restartdns Restart dnsmasq -::: checkout Check out different branches -EOM + echo "Usage: pihole [options] +Example: 'pihole -w -h' +Add '-h' after specific commands for more information on usage + +Whitelist/Blacklist Options: + -w, whitelist Whitelist domain(s) + -b, blacklist Blacklist domain(s) + -wild, wildcard Blacklist domain(s), and all its subdomains + Add '-h' for more info on whitelist/blacklist usage + +Debugging Options: + -d, debug Start a debugging session + Add '-a' to enable automated debugging + -f, flush Flush the Pi-hole log + -r, reconfigure Reconfigure or Repair Pi-hole subsystems + -t, tail View the live output of the Pi-hole log + +Options: + -a, admin Admin Console options + Add '-h' for more info on admin console usage + -c, chronometer Calculates stats and displays to an LCD + Add '-h' for more info on chronometer usage + -g, updateGravity Update the list of ad-serving domains + -h, --help, help Show this help dialog + -l, logging Specify whether the Pi-hole log should be used + Add '-h' for more info on logging usage + -q, query Query the adlists for a specified domain + Add '-exact' AFTER a specified domain for exact match + -up, updatePihole Update Pi-hole subsystems + -v, version Show installed versions of Pi-hole, Admin Console & FTL + Add '-h' for more info on version usage + uninstall Uninstall Pi-hole from your system + status Display the running status of Pi-hole subsystems + enable Enable Pi-hole subsystems + disable Disable Pi-hole subsystems + Add '-h' for more info on disable usage + restartdns Restart Pi-hole subsystems + checkout Switch Pi-hole subsystems to a different Github branch + Add '-h' for more info on checkout usage"; exit 0 } @@ -344,7 +364,7 @@ case "${1}" in "-l" | "logging" ) piholeLogging "$@";; "uninstall" ) uninstallFunc;; "enable" ) piholeEnable 1;; - "disable" ) piholeEnable 0 $2;; + "disable" ) piholeEnable 0 "$2";; "status" ) piholeStatus "$2";; "restartdns" ) restartDNS;; "-a" | "admin" ) webpageFunc "$@";; From 0e4473685bb9fdc00f196cf2751be99c6877368c Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Sun, 14 May 2017 11:47:56 +1000 Subject: [PATCH 105/109] Show help for "pihole -a -i --help" --- 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 6626dab8..8419aa8d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -390,7 +390,7 @@ SetHostRecord() { SetListeningMode() { source "${setupVars}" - if [[ "$3" == "-h" ]]; then + if [[ "$3" == "-h" ]] || [[ "$3" == "--help" ]]; then echo "Usage: pihole -a -i [interface] Example: 'pihole -a -i local' Specify dnsmasq's network interface listening behavior From 4eb7d2868ca2d347ed0a497b6fb5c3a195ac4bf6 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Sun, 14 May 2017 11:53:40 +1000 Subject: [PATCH 106/109] Fix "pihole disable --help" and "pihole -l --help" --- pihole | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index 79a5c35d..1b75add5 100755 --- a/pihole +++ b/pihole @@ -164,7 +164,7 @@ restartDNS() { } piholeEnable() { - if [[ "${2}" == "-h" ]]; then + if [[ "${2}" == "-h" ]] || [[ "${2}" == "--help" ]]; then echo "Usage: pihole disable [time] Example: 'pihole disable', or 'pihole disable 5m' Disable Pi-hole subsystems @@ -205,7 +205,7 @@ Time: piholeLogging() { shift - if [[ "${1}" == "-h" ]]; then + if [[ "${1}" == "-h" ]] || [[ "${1}" == "--help" ]]; then echo "Usage: pihole logging [options] Example: 'pihole logging on' Specify whether the Pi-hole log should be used From 3bd677c102fddcce8ce72c81ae811b7453b8caa8 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Sun, 14 May 2017 11:57:46 +1000 Subject: [PATCH 107/109] Show help for "pihole -v -h" * Indent output text * Minor help text change --- advanced/Scripts/version.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 73888295..50bdb608 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -104,7 +104,7 @@ versionOutput() { [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR) [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "$1") - if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then + if [[ "$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 @@ -127,11 +127,11 @@ versionOutput() { errorOutput fi - [[ -n "$output" ]] && echo "$output" + [[ -n "$output" ]] && echo " $output" } errorOutput() { - echo "Invalid Option! Try 'pihole -v -h' for more information." + echo " Invalid Option! Try 'pihole -v -h' for more information." exit 1 } @@ -142,7 +142,7 @@ defaultOutput() { } helpFunc() { - echo "Usage: pihole -v [REPO | OPTION] [OPTION] + echo "Usage: pihole -v [repo | option] [option] Example: 'pihole -v -p -l' Show Pi-hole, Admin Console & FTL versions @@ -154,8 +154,8 @@ Repositories: Options: -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 + --hash Return the Github hash from your local repositories + -h, --help Show this help dialog " exit 0 } @@ -164,6 +164,6 @@ case "${1}" in "-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";; "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";; "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; - "--help" ) helpFunc;; + "-h" | "--help" ) helpFunc;; * ) defaultOutput "$@";; esac From 39b74ebfd47e1847ebaff7cfabccb6fdc7d20f90 Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Sun, 14 May 2017 12:22:19 +1000 Subject: [PATCH 108/109] Show help for "pihole checkout --help" --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index 1b75add5..c1359ef9 100755 --- a/pihole +++ b/pihole @@ -280,7 +280,7 @@ tailFunc() { } piholeCheckoutFunc() { - if [[ "$2" == "-h" ]]; then + if [[ "$2" == "-h" ]] || [[ "$2" == "--help" ]]; then echo "Usage: pihole checkout [repo] [branch] Example: 'pihole checkout master' or 'pihole checkout core dev' Switch Pi-hole subsystems to a different Github branch From 69f361a3a1884879fe18ec8c1dccc09fabfc3815 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 14 May 2017 16:28:35 +0200 Subject: [PATCH 109/109] :taco: is the new :shipit: squirrel --- .pullapprove.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pullapprove.yml b/.pullapprove.yml index 39566b34..188a64f2 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -10,7 +10,7 @@ group_defaults: reset_on_push: enabled: true reject_value: -2 - approve_regex: '^(Approved|:shipit:|:\+1:|Engage)' + approve_regex: '^(Approved|:shipit:|:\+1:|Engage|:taco:)' reject_regex: '^(Rejected|:-1:|Borg)' author_approval: auto: true