From 47cba8345080894fd494f99cea3e69bda08d27bd Mon Sep 17 00:00:00 2001 From: Steve Dobinson Date: Tue, 20 Sep 2016 10:34:21 +0100 Subject: [PATCH 001/172] Update lighttpd.conf.debian Allow for password protection (or other user-initiated options) without clobbering already chosen user options. --- advanced/lighttpd.conf.debian | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 8b62f448..81f1b765 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -12,6 +12,7 @@ server.modules = ( "mod_access", "mod_accesslog", + "mod_auth", "mod_expire", "mod_compress", "mod_redirect", @@ -59,3 +60,6 @@ $HTTP["url"] =~ "^(?!/admin)/.*" { # rewrite only js requests url.rewrite = ("(.*).js" => "pihole/index.js") } + +# Add user chosen options held in external file +include_shell "cat external.conf 2>/dev/null" From 737b510116d673dd2799a40a4365ca626867223d Mon Sep 17 00:00:00 2001 From: Steve Dobinson Date: Tue, 20 Sep 2016 10:38:58 +0100 Subject: [PATCH 002/172] Update lighttpd.conf.fedora Allow for password protection (or other user-initiated options) without clobbering already chosen user options. --- advanced/lighttpd.conf.fedora | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 30784b1a..3719d502 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -11,6 +11,7 @@ server.modules = ( "mod_access", + "mod_auth", "mod_fastcgi", "mod_accesslog", "mod_expire", @@ -75,3 +76,6 @@ $HTTP["url"] =~ "^(?!/admin)/.*" { # rewrite only js requests url.rewrite = ("(.*).js" => "pihole/index.js") } + +# Add user chosen options held in external file +include_shell "cat external.conf 2>/dev/null" From 9354799a26b856f9902ff2eff4fe476c62da42bb Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 8 Oct 2016 12:06:23 -0400 Subject: [PATCH 003/172] Move contributer file This will make it more visible to a user and fixes the link in the PR template. --- .github/CONTRIBUTING.md => CONTRIBUTING.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/CONTRIBUTING.md => CONTRIBUTING.md (100%) diff --git a/.github/CONTRIBUTING.md b/CONTRIBUTING.md similarity index 100% rename from .github/CONTRIBUTING.md rename to CONTRIBUTING.md From fbe35471296856638b4f929c872fef72c67b01ab Mon Sep 17 00:00:00 2001 From: bcambl Date: Tue, 11 Oct 2016 00:01:11 -0600 Subject: [PATCH 004/172] EPEL is not required on Fedora epel-release installs the EPEL package repository (Extra Packages for Enterprise Linux) Dependencies from this repository should available by default on Fedora --- automated install/basic-install.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 945fa1e1..5c713030 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -99,6 +99,10 @@ elif [ -x "$(command -v rpm)" ];then PKG_COUNT="$PKG_MANAGER check-update | grep -v ^Last | grep -c ^[a-zA-Z0-9]" INSTALLER_DEPS=( iproute net-tools procps-ng newt git ) PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat ) + if grep -q 'Fedora' /etc/redhat-release; then + remove_deps=(epel-release); + PIHOLE_DEPS=( ${PIHOLE_DEPS[@]/$remove_deps} ); + fi LIGHTTPD_USER="lighttpd" LIGHTTPD_GROUP="lighttpd" LIGHTTPD_CFG="lighttpd.conf.fedora" From e5ede16749e71b57587952c742493f6029a5f036 Mon Sep 17 00:00:00 2001 From: bcambl Date: Wed, 12 Oct 2016 20:04:20 -0600 Subject: [PATCH 005/172] update yum/dnf package count grepfu see pull #774 --- 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 5c713030..7ca12943 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -96,7 +96,7 @@ elif [ -x "$(command -v rpm)" ];then UPDATE_PKG_CACHE="$PKG_MANAGER check-update" PKG_UPDATE="$PKG_MANAGER update -y" PKG_INSTALL="$PKG_MANAGER install -y" - PKG_COUNT="$PKG_MANAGER check-update | grep -v ^Last | grep -c ^[a-zA-Z0-9]" + PKG_COUNT="$PKG_MANAGER check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" INSTALLER_DEPS=( iproute net-tools procps-ng newt git ) PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat ) if grep -q 'Fedora' /etc/redhat-release; then From f4f8b967885dbe25b928c317fda630a11061bf92 Mon Sep 17 00:00:00 2001 From: bcambl Date: Wed, 12 Oct 2016 20:08:22 -0600 Subject: [PATCH 006/172] remove systemd selinux rules on init systems fixes the failing SELinux policy compile on init based systems --- automated install/basic-install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7ca12943..2021cc9e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -841,6 +841,9 @@ configureSelinux() { printf "::: Enabling httpd server side includes (SSI).. " setsebool -P httpd_ssi_exec on &> /dev/null && echo "Success" || echo "SELinux not enabled" printf "\n:::\tCompiling Pi-Hole SELinux policy..\n" + if ! [ -x "$(command -v systemctl)" ]; then + sed -i.bak '/systemd/d' /etc/.pihole/advanced/selinux/pihole.te + fi checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod semodule -i /etc/pihole/pihole.pp From 26202014a28bbfa58cf2bc15b87cad4d98c1095a Mon Sep 17 00:00:00 2001 From: bcambl Date: Wed, 12 Oct 2016 20:23:12 -0600 Subject: [PATCH 007/172] stdout formatting --- automated install/basic-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2021cc9e..752a0a1a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -838,7 +838,7 @@ configureSelinux() { printf ":::\tChecking for SELinux policy development packages..." package_check_install "selinux-policy-devel" > /dev/null echo " installed!" - printf "::: Enabling httpd server side includes (SSI).. " + printf ":::\tEnabling httpd server side includes (SSI).. " setsebool -P httpd_ssi_exec on &> /dev/null && echo "Success" || echo "SELinux not enabled" printf "\n:::\tCompiling Pi-Hole SELinux policy..\n" if ! [ -x "$(command -v systemctl)" ]; then @@ -954,13 +954,13 @@ if [[ ${useUpdateVars} == false ]]; then displayFinalMessage fi -echo -n "::: Restarting services..." +echo "::: Restarting services..." # Start services start_service dnsmasq enable_service dnsmasq start_service lighttpd enable_service lighttpd -echo " done." +echo "::: done." echo ":::" if [[ ${useUpdateVars} == false ]]; then From 99878ae7d6206cd09914a678452011d9b7ca8703 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 15:40:12 +0100 Subject: [PATCH 008/172] reflect name change of some of the variables in setupVars --- automated install/basic-install.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 945fa1e1..88a6f364 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -817,6 +817,11 @@ installPihole() { } updatePihole() { + # Refactoring of install script has changed the name of a couple of variables. Sort them out here. + sed -i 's/IPv4addr/IPv4_address/g' ${setupVars} + sed -i 's/piholeIPv6/IPv6_address/g' ${setupVars} + # Source ${setupVars} for use in the rest of the functions. + . ${setupVars} # Install base files and web interface installScripts installConfigs @@ -868,7 +873,6 @@ update_dialogs(){ case ${UpdateCmd} in Update) echo "::: Updating existing install" - . ${setupVars} useUpdateVars=true ;; Install) From a6fa60868b011d9aa04031e5d1127288d176edad Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 15:41:48 +0100 Subject: [PATCH 009/172] spacing --- automated install/basic-install.sh | 62 +++++++++++++++--------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 88a6f364..d7d9ca08 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -792,28 +792,28 @@ finalExports() { installPihole() { - # Install base files and web interface - create_pihole_user - if [ ! -d "/var/www/html" ]; then - mkdir -p /var/www/html - fi - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html - chmod 775 /var/www/html - usermod -a -G ${LIGHTTPD_GROUP} pihole - if [ -x "$(command -v lighty-enable-mod)" ]; then - lighty-enable-mod fastcgi fastcgi-php > /dev/null || true - else - printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" - fi - installScripts - installConfigs - CreateLogFile - configureSelinux - installPiholeWeb - installCron - configureFirewall - finalExports - runGravity + # Install base files and web interface + create_pihole_user + if [ ! -d "/var/www/html" ]; then + mkdir -p /var/www/html + fi + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html + chmod 775 /var/www/html + usermod -a -G ${LIGHTTPD_GROUP} pihole + if [ -x "$(command -v lighty-enable-mod)" ]; then + lighty-enable-mod fastcgi fastcgi-php > /dev/null || true + else + printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" + fi + installScripts + installConfigs + CreateLogFile + configureSelinux + installPiholeWeb + installCron + configureFirewall + finalExports + runGravity } updatePihole() { @@ -822,15 +822,15 @@ updatePihole() { sed -i 's/piholeIPv6/IPv6_address/g' ${setupVars} # Source ${setupVars} for use in the rest of the functions. . ${setupVars} - # Install base files and web interface - installScripts - installConfigs - CreateLogFile - configureSelinux - installPiholeWeb - installCron - configureFirewall - runGravity + # Install base files and web interface + installScripts + installConfigs + CreateLogFile + configureSelinux + installPiholeWeb + installCron + configureFirewall + runGravity } configureSelinux() { From 5ea08a2120bbe2e771085e9a6f49aba66e25c7c9 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 17:07:08 +0100 Subject: [PATCH 010/172] add -r to reconfigure pihole (basically runs basic-install.sh from /etc/.pihole) --- pihole | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pihole b/pihole index e0d1715a..b96df225 100755 --- a/pihole +++ b/pihole @@ -116,6 +116,11 @@ function updatePiholeFunc { exit 1 } +function reconfigurePiholeFunc { + ${SUDO} /etc/.pihole/automated\ install/basic-install.sh + exit 1; +} + function updateGravityFunc { ${SUDO} /opt/pihole/gravity.sh "$@" exit 1 @@ -190,6 +195,7 @@ case "$1" in "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-up" | "updatePihole" ) updatePiholeFunc;; +"-r" | "reconfigure" ) reconfigurePiholeFunc;; "-g" | "updateGravity" ) updateGravityFunc "$@";; "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; @@ -198,4 +204,4 @@ case "$1" in "-q" | "query" ) queryFunc "$@";; "uninstall" ) uninstallFunc;; * ) helpFunc;; -esac +esac \ No newline at end of file From 5e883239f98eb5ff2f017c6370c9bd37dc686255 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 17:15:59 +0100 Subject: [PATCH 011/172] remove calls for ${SUDO} as per basic-install.sh. --- pihole | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/pihole b/pihole index b96df225..e1e18898 100755 --- a/pihole +++ b/pihole @@ -12,38 +12,35 @@ # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then - #echo "::: You are root." -#else - #echo "::: Sudo will be used for this tool." - # Check if it is actually installed - # If it isn't, exit because the pihole cannot be invoked without privileges. - if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this as root." - exit 1 - fi + if [ -x "$(command -v sudo)" ];then + echo "::: Elevating to root with sudo" + exec sudo bash "$0" "$@" + exit $? + else + echo "::: sudo is needed to run pihole commands. Please run this script as root or install sudo." + exit 1 + fi fi function whitelistFunc { shift - ${SUDO} /opt/pihole/whitelist.sh "$@" + /opt/pihole/whitelist.sh "$@" exit 1 } function blacklistFunc { shift - ${SUDO} /opt/pihole/blacklist.sh "$@" + /opt/pihole/blacklist.sh "$@" exit 1 } function debugFunc { - ${SUDO} /opt/pihole/piholeDebug.sh + /opt/pihole/piholeDebug.sh exit 1 } function flushFunc { - ${SUDO} /opt/pihole/piholeLogFlush.sh + /opt/pihole/piholeLogFlush.sh exit 1 } @@ -86,7 +83,7 @@ function updatePiholeFunc { echo ":::" echo "::: Fetching latest changes from GitHub..." cd /var/www/html/admin - ${SUDO} git pull origin master + git pull origin master echo ":::" echo "::: Pi-hole Web Admin has been updated to ${webVersion}" echo "::: See https://changes.pi-hole.net for details" @@ -101,8 +98,8 @@ function updatePiholeFunc { echo "::: Fetching latest changes from GitHub..." cd /etc/.pihole - ${SUDO} git pull origin master - ${SUDO} /etc/.pihole/automated\ install/basic-install.sh pihole + git pull origin master + /etc/.pihole/automated\ install/basic-install.sh pihole echo ":::" echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" @@ -117,17 +114,17 @@ function updatePiholeFunc { } function reconfigurePiholeFunc { - ${SUDO} /etc/.pihole/automated\ install/basic-install.sh + /etc/.pihole/automated\ install/basic-install.sh exit 1; } function updateGravityFunc { - ${SUDO} /opt/pihole/gravity.sh "$@" + /opt/pihole/gravity.sh "$@" exit 1 } function setupLCDFunction { - ${SUDO} /opt/pihole/setupLCD.sh + /opt/pihole/setupLCD.sh exit 1 } @@ -147,18 +144,18 @@ function queryFunc { function chronometerFunc { shift - ${SUDO} /opt/pihole/chronometer.sh "$@" + /opt/pihole/chronometer.sh "$@" exit 1 } function uninstallFunc { - ${SUDO} /opt/pihole/uninstall.sh + /opt/pihole/uninstall.sh exit 1 } function versionFunc { - ${SUDO} /opt/pihole/version.sh + /opt/pihole/version.sh exit 1 } From 9352ba6e4a76a721cd6ad9d82bca54fc93f26913 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 17:16:44 +0100 Subject: [PATCH 012/172] about time we exit 0'd --- pihole | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pihole b/pihole index e1e18898..0406d19c 100755 --- a/pihole +++ b/pihole @@ -25,23 +25,23 @@ fi function whitelistFunc { shift /opt/pihole/whitelist.sh "$@" - exit 1 + exit 0 } function blacklistFunc { shift /opt/pihole/blacklist.sh "$@" - exit 1 + exit 0 } function debugFunc { /opt/pihole/piholeDebug.sh - exit 1 + exit 0 } function flushFunc { /opt/pihole/piholeLogFlush.sh - exit 1 + exit 0 } @@ -110,22 +110,22 @@ function updatePiholeFunc { echo "::: See https://changes.pi-hole.net for details" fi - exit 1 + exit 0 } function reconfigurePiholeFunc { /etc/.pihole/automated\ install/basic-install.sh - exit 1; + exit 0; } function updateGravityFunc { /opt/pihole/gravity.sh "$@" - exit 1 + exit 0 } function setupLCDFunction { /opt/pihole/setupLCD.sh - exit 1 + exit 0 } function queryFunc { @@ -139,24 +139,24 @@ function queryFunc { fi echo "" done - exit 1 + exit 0 } function chronometerFunc { shift /opt/pihole/chronometer.sh "$@" - exit 1 + exit 0 } function uninstallFunc { /opt/pihole/uninstall.sh - exit 1 + exit 0 } function versionFunc { /opt/pihole/version.sh - exit 1 + exit 0 } function helpFunc { @@ -178,7 +178,7 @@ function helpFunc { echo "::: -v, version Show current versions" echo "::: -q, query Query the adlists for a specific domain" echo "::: uninstall Uninstall Pi-Hole from your system :(!" - exit 1 + exit 0 } if [[ $# = 0 ]]; then From 461de48625739d36c1113df978b21a4533760cf2 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 17:25:17 +0100 Subject: [PATCH 013/172] function declarations as per basic-install.sh --- pihole | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pihole b/pihole index 0406d19c..dd50481a 100755 --- a/pihole +++ b/pihole @@ -22,30 +22,30 @@ if [[ ! $EUID -eq 0 ]];then fi fi -function whitelistFunc { +whitelistFunc() { shift /opt/pihole/whitelist.sh "$@" exit 0 } -function blacklistFunc { +blacklistFunc() { shift /opt/pihole/blacklist.sh "$@" exit 0 } -function debugFunc { +debugFunc() { /opt/pihole/piholeDebug.sh exit 0 } -function flushFunc { +flushFunc() { /opt/pihole/piholeLogFlush.sh exit 0 } -function updatePiholeFunc { +updatePiholeFunc() { if [ ! -d "/etc/.pihole" ]; then #This is unlikely echo "::: Critical Error: Pi-Hole repo missing from system!" @@ -113,22 +113,22 @@ function updatePiholeFunc { exit 0 } -function reconfigurePiholeFunc { +reconfigurePiholeFunc() { /etc/.pihole/automated\ install/basic-install.sh exit 0; } -function updateGravityFunc { +updateGravityFunc() { /opt/pihole/gravity.sh "$@" exit 0 } -function setupLCDFunction { +setupLCDFunction() { /opt/pihole/setupLCD.sh exit 0 } -function queryFunc { +queryFunc() { domain=$2 for list in /etc/pihole/list.* do @@ -142,24 +142,24 @@ function queryFunc { exit 0 } -function chronometerFunc { +chronometerFunc() { shift /opt/pihole/chronometer.sh "$@" exit 0 } -function uninstallFunc { +uninstallFunc() { /opt/pihole/uninstall.sh exit 0 } -function versionFunc { +versionFunc() { /opt/pihole/version.sh exit 0 } -function helpFunc { +helpFunc() { echo "::: Control all PiHole specific functions!" echo ":::" echo "::: Usage: pihole [options]" @@ -201,4 +201,4 @@ case "$1" in "-q" | "query" ) queryFunc "$@";; "uninstall" ) uninstallFunc;; * ) helpFunc;; -esac \ No newline at end of file +esac From 090fbd04afea455c0fcdfffc20e85d698cb099d4 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 17:54:04 +0100 Subject: [PATCH 014/172] Remove ${SUDO} usages and root checks from scripts called by `pihole` command as they should not be called directly. --- advanced/Scripts/blacklist.sh | 35 ++++++++------------------- advanced/Scripts/chronometer.sh | 16 ++++++------ advanced/Scripts/setupLCD.sh | 43 +++++++++++---------------------- advanced/Scripts/whitelist.sh | 36 +++++++++------------------ pihole | 16 ++++++------ 5 files changed, 51 insertions(+), 95 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index a289a9a5..feeca9da 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -10,22 +10,7 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -#rootcheck -if [[ $EUID -eq 0 ]];then - echo "::: You are root." -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this script as root." - exit 1 - fi -fi - -function helpFunc() +helpFunc() { echo "::: Immediately blacklists one or more domains in the hosts file" echo ":::" @@ -86,7 +71,7 @@ if [[ -f ${piholeIPv6file} ]];then piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi -function HandleOther(){ +HandleOther(){ #check validity of domain validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') if [ -z "$validDomain" ]; then @@ -96,7 +81,7 @@ function HandleOther(){ fi } -function PopBlacklistFile(){ +PopBlacklistFile(){ #check blacklist file exists, and if not, create it if [[ ! -f ${blacklist} ]];then touch ${blacklist} @@ -110,7 +95,7 @@ function PopBlacklistFile(){ done } -function AddDomain(){ +AddDomain(){ #| sed 's/\./\\./g' bool=false grep -Ex -q "$1" ${blacklist} || bool=true @@ -129,7 +114,7 @@ function AddDomain(){ fi } -function RemoveDomain(){ +RemoveDomain(){ bool=false grep -Ex -q "$1" ${blacklist} || bool=true @@ -148,7 +133,7 @@ function RemoveDomain(){ fi } -function ModifyHostFile(){ +ModifyHostFile(){ if ${addmode}; then #add domains to the hosts file if [[ -r ${blacklist} ]];then @@ -178,7 +163,7 @@ function ModifyHostFile(){ fi } -function Reload() { +Reload() { # Reload hosts file echo ":::" echo -n "::: Refresh lists in dnsmasq..." @@ -187,15 +172,15 @@ function Reload() { if [[ ${dnsmasqPid} ]]; then # service already running - reload config - ${SUDO} killall -s HUP dnsmasq + killall -s HUP dnsmasq else # service not running, start it up - ${SUDO} service dnsmasq start + service dnsmasq start fi echo " done!" } -function DisplayBlist() { +DisplayBlist() { verbose=false echo -e " Displaying Gravity Affected Domains \n" count=1 diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index eae7cf1c..c03b4649 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -17,7 +17,7 @@ gravity="/etc/pihole/gravity.list" today=$(date "+%b %e") -function CalcBlockedDomains(){ +CalcBlockedDomains(){ CheckIPv6 if [ -e "$gravity" ]; then #Are we IPV6 or IPV4? @@ -33,7 +33,7 @@ function CalcBlockedDomains(){ fi } -function CalcQueriesToday(){ +CalcQueriesToday(){ if [ -e "$piLog" ];then queriesToday=$(cat "$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l) else @@ -41,7 +41,7 @@ function CalcQueriesToday(){ fi } -function CalcblockedToday(){ +CalcblockedToday(){ if [ -e "$piLog" ] && [ -e "$gravity" ];then blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) else @@ -49,7 +49,7 @@ function CalcblockedToday(){ fi } -function CalcPercentBlockedToday(){ +CalcPercentBlockedToday(){ if [ "$queriesToday" != "Err." ] && [ "$blockedToday" != "Err." ]; then if [ "$queriesToday" != 0 ]; then #Fixes divide by zero error :) #scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros @@ -61,7 +61,7 @@ function CalcPercentBlockedToday(){ fi } -function CheckIPv6(){ +CheckIPv6(){ piholeIPv6file="/etc/pihole/.useIPv6" if [[ -f ${piholeIPv6file} ]];then # If the file exists, then the user previously chose to use IPv6 in the automated installer @@ -69,7 +69,7 @@ function CheckIPv6(){ fi } -function outputJSON(){ +outputJSON(){ CalcQueriesToday CalcblockedToday CalcPercentBlockedToday @@ -79,7 +79,7 @@ function outputJSON(){ printf '{"domains_being_blocked":"%s","dns_queries_today":"%s","ads_blocked_today":"%s","ads_percentage_today":"%s"}\n' "$blockedDomainsTotal" "$queriesToday" "$blockedToday" "$percentBlockedToday" } -function normalChrono(){ +normalChrono(){ for (( ; ; )) do clear @@ -121,7 +121,7 @@ function normalChrono(){ done } -function displayHelp(){ +displayHelp(){ echo "::: Displays stats about your piHole!" echo ":::" echo "::: Usage: sudo pihole -c [optional:-j]" diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh index c77f1f4a..5ef324fe 100755 --- a/advanced/Scripts/setupLCD.sh +++ b/advanced/Scripts/setupLCD.sh @@ -11,21 +11,6 @@ # (at your option) any later version. ############ FUNCTIONS ########### -# Run this script as root or under sudo -echo ":::" -if [[ $EUID -eq 0 ]];then - echo "::: You are root." -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this script as root." - exit 1 - fi -fi # Borrowed from adafruit-pitft-helper < borrowed from raspi-config # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L324-L334 @@ -45,11 +30,11 @@ getInitSys() { autoLoginPiToConsole() { if [ -e /etc/init.d/lightdm ]; then if [ ${SYSTEMD} -eq 1 ]; then - ${SUDO} systemctl set-default multi-user.target - ${SUDO} ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service + systemctl set-default multi-user.target + ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service else - ${SUDO} update-rc.d lightdm disable 2 - ${SUDO} sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" + update-rc.d lightdm disable 2 + sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" fi fi } @@ -66,23 +51,23 @@ echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc # Set up the LCD screen based on Adafruits instuctions: # https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install -curl -SLs https://apt.adafruit.com/add-pin | ${SUDO} bash -${SUDO} apt-get -y install raspberrypi-bootloader -${SUDO} apt-get -y install adafruit-pitft-helper -${SUDO} adafruit-pitft-helper -t 28r +curl -SLs https://apt.adafruit.com/add-pin | bash +apt-get -y install raspberrypi-bootloader +apt-get -y install adafruit-pitft-helper +adafruit-pitft-helper -t 28r # Download the cmdline.txt file that prevents the screen from going blank after a period of time -${SUDO} mv /boot/cmdline.txt /boot/cmdline.orig -${SUDO} curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt +mv /boot/cmdline.txt /boot/cmdline.orig +curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt # Back up the original file and download the new one -${SUDO} mv /etc/default/console-setup /etc/default/console-setup.orig -${SUDO} curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup +mv /etc/default/console-setup /etc/default/console-setup.orig +curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup # Instantly apply the font change to the LCD screen -${SUDO} setupcon +setupcon -${SUDO} reboot +reboot # Start showing the stats on the screen by running the command on another tty: # http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 75d62173..d6a09b35 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -10,22 +10,8 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -#rootcheck -if [[ $EUID -eq 0 ]];then - echo "::: You are root." -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this script as root." - exit 1 - fi -fi -function helpFunc() +helpFunc() { echo "::: Immediately whitelists one or more domains in the hosts file" echo ":::" @@ -85,7 +71,7 @@ if [[ -f ${piholeIPv6file} ]];then piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi -function HandleOther(){ +HandleOther(){ #check validity of domain validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') if [ -z "$validDomain" ]; then @@ -95,7 +81,7 @@ function HandleOther(){ fi } -function PopWhitelistFile(){ +PopWhitelistFile(){ #check whitelist file exists, and if not, create it if [[ ! -f ${whitelist} ]];then touch ${whitelist} @@ -110,7 +96,7 @@ function PopWhitelistFile(){ done } -function AddDomain(){ +AddDomain(){ #| sed 's/\./\\./g' bool=false @@ -132,7 +118,7 @@ function AddDomain(){ fi } -function RemoveDomain(){ +RemoveDomain(){ bool=false grep -Ex -q "$1" ${whitelist} || bool=true @@ -151,7 +137,7 @@ function RemoveDomain(){ fi } -function ModifyHostFile(){ +ModifyHostFile(){ if ${addmode}; then #remove domains in from hosts file if [[ -r ${whitelist} ]];then @@ -195,7 +181,7 @@ function ModifyHostFile(){ fi } -function Reload() { +Reload() { # Reload hosts file echo ":::" echo -n "::: Refresh lists in dnsmasq..." @@ -203,15 +189,15 @@ function Reload() { if [[ ${dnsmasqPid} ]]; then # service already running - reload config - ${SUDO} killall -s HUP dnsmasq + killall -s HUP dnsmasq else # service not running, start it up - ${SUDO} service dnsmasq start + service dnsmasq start fi echo " done!" } -function DisplayWlist() { +DisplayWlist() { verbose=false echo -e " Displaying Gravity Resistant Domains \n" count=1 @@ -251,4 +237,4 @@ fi if ${reload}; then Reload -fi +fi \ No newline at end of file diff --git a/pihole b/pihole index dd50481a..30b13403 100755 --- a/pihole +++ b/pihole @@ -12,14 +12,14 @@ # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then - if [ -x "$(command -v sudo)" ];then - echo "::: Elevating to root with sudo" - exec sudo bash "$0" "$@" - exit $? - else - echo "::: sudo is needed to run pihole commands. Please run this script as root or install sudo." - exit 1 - fi + if [ -x "$(command -v sudo)" ];then + echo "::: Elevating to root with sudo" + exec sudo bash "$0" "$@" + exit $? + else + echo "::: sudo is needed to run pihole commands. Please run this script as root or install sudo." + exit 1 + fi fi whitelistFunc() { From 4c42f00a8636acc8d30b65aff05c826f8a68def4 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 18:42:53 +0100 Subject: [PATCH 015/172] remove uses of ${SUDO} and root check from gravity. As this is handled by `pihole` command. --- gravity.sh | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/gravity.sh b/gravity.sh index bcfcc9ee..94360b70 100755 --- a/gravity.sh +++ b/gravity.sh @@ -13,20 +13,6 @@ # Run this script as root or under sudo echo ":::" -if [[ $EUID -eq 0 ]];then - echo "::: You are root." -else - echo "::: sudo will be used." - # Check if it is actually installed - # If it isn't, exit because the install cannot complete - if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this script as root." - exit 1 - fi -fi - function helpFunc() { echo "::: Pull in domains from adlists" @@ -105,13 +91,13 @@ function gravity_collapse() { # Temporary hack to allow non-root access to pihole directory # Will update later, needed for existing installs, new installs should # create this directory as non-root - ${SUDO} chmod 777 ${piholeDir} + chmod 777 ${piholeDir} echo ":::" echo "::: Existing pihole directory found" else echo "::: Creating pihole directory..." mkdir ${piholeDir} - ${SUDO} chmod 777 ${piholeDir} + chmod 777 ${piholeDir} fi } @@ -305,7 +291,7 @@ function gravity_reload() { #Clear no longer needed files... echo ":::" echo -n "::: Cleaning up un-needed files..." - ${SUDO} rm ${piholeDir}/pihole.*.txt + rm ${piholeDir}/pihole.*.txt echo " done!" # Reload hosts file @@ -316,17 +302,17 @@ function gravity_reload() { #First escape forward slashes in the path: adList=${adList//\//\\\/} #Now replace the line in dnsmasq file - ${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf + sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf dnsmasqPid=$(pidof dnsmasq) - find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \; + find "$piholeDir" -type f -exec chmod 666 {} \; if [[ ${dnsmasqPid} ]]; then # service already running - reload config - ${SUDO} killall -s HUP dnsmasq + killall -s HUP dnsmasq else # service not running, start it up - ${SUDO} service dnsmasq start + service dnsmasq start fi echo " done!" } @@ -342,12 +328,12 @@ done if [[ ${forceGrav} == true ]]; then echo -n "::: Deleting exising list cache..." - ${SUDO} rm /etc/pihole/list.* + rm /etc/pihole/list.* echo " done!" fi #Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list -${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default +cp /etc/.pihole/adlists.default /etc/pihole/adlists.default gravity_collapse gravity_spinup gravity_Schwarzchild From fc4fe5409989d059f9c11096f07bc5a7191c266a Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 20:02:57 +0100 Subject: [PATCH 016/172] standardise function naming --- gravity.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/gravity.sh b/gravity.sh index 94360b70..0aaf2b88 100755 --- a/gravity.sh +++ b/gravity.sh @@ -13,7 +13,7 @@ # Run this script as root or under sudo echo ":::" -function helpFunc() +helpFunc() { echo "::: Pull in domains from adlists" echo ":::" @@ -54,7 +54,7 @@ fi ########################### # collapse - begin formation of pihole -function gravity_collapse() { +gravity_collapse() { echo "::: Neutrino emissions detected..." echo ":::" #Decide if we're using a custom ad block list, or defaults. @@ -102,7 +102,7 @@ function gravity_collapse() { } # patternCheck - check to see if curl downloaded any new files. -function gravity_patternCheck() { +gravity_patternCheck() { patternBuffer=$1 # check if the patternbuffer is a non-zero length file if [[ -s "$patternBuffer" ]];then @@ -118,7 +118,7 @@ function gravity_patternCheck() { } # transport - curl the specified url with any needed command extentions -function gravity_transport() { +gravity_transport() { url=$1 cmd_ext=$2 agent=$3 @@ -140,7 +140,7 @@ function gravity_transport() { } # spinup - main gravity function -function gravity_spinup() { +gravity_spinup() { echo ":::" # Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines for ((i = 0; i < "${#sources[@]}"; i++)) @@ -177,7 +177,7 @@ function gravity_spinup() { } # Schwarzchild - aggregate domains to one list and add blacklisted domains -function gravity_Schwarzchild() { +gravity_Schwarzchild() { echo "::: " # Find all active domains and compile them into one file and remove CRs echo -n "::: Aggregating list of domains..." @@ -189,7 +189,7 @@ function gravity_Schwarzchild() { echo " done!" } -function gravity_Blacklist(){ +gravity_Blacklist(){ # Append blacklist entries if they exist echo -n "::: Running blacklist script to update HOSTS file...." ${blacklistScript} -f -nr -q > /dev/null @@ -199,7 +199,7 @@ function gravity_Blacklist(){ echo " $numBlacklisted domain${plural} blacklisted!" } -function gravity_Whitelist() { +gravity_Whitelist() { echo ":::" # Prevent our sources from being pulled into the hole plural=; [[ "${sources[@]}" != "1" ]] && plural=s @@ -220,7 +220,7 @@ function gravity_Whitelist() { echo " $numWhitelisted domain${plural} whitelisted!" } -function gravity_unique() { +gravity_unique() { # Sort and remove duplicates echo -n "::: Removing duplicate domains...." sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon} @@ -229,7 +229,7 @@ function gravity_unique() { echo "::: $numberOf unique domains trapped in the event horizon." } -function gravity_hostFormat() { +gravity_hostFormat() { # Format domain list as "192.168.x.x domain.com" echo "::: Formatting domains into a HOSTS file..." if [[ -f /etc/hostname ]]; then @@ -256,7 +256,7 @@ function gravity_hostFormat() { } # blackbody - remove any remnant files from script processes -function gravity_blackbody() { +gravity_blackbody() { # Loop through list files for file in ${piholeDir}/*.${justDomainsExtension} do @@ -269,7 +269,7 @@ function gravity_blackbody() { done } -function gravity_advanced() { +gravity_advanced() { # Remove comments and print only the domain name # Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious # This helps with that and makes it easier to read @@ -287,7 +287,7 @@ function gravity_advanced() { gravity_unique } -function gravity_reload() { +gravity_reload() { #Clear no longer needed files... echo ":::" echo -n "::: Cleaning up un-needed files..." From 51c4c51d9e1ca21c8454fb999d3691c0eea598a0 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 20:03:33 +0100 Subject: [PATCH 017/172] Add trap to check existence of setupVars --- gravity.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 0aaf2b88..4ef440a5 100755 --- a/gravity.sh +++ b/gravity.sh @@ -32,7 +32,15 @@ whitelistScript=/opt/pihole/whitelist.sh blacklistScript=/opt/pihole/blacklist.sh #Source the setupVars from install script for the IP -. /etc/pihole/setupVars.conf +setupVars=/etc/pihole/setupVars.conf +if [[ -f ${setupVars} ]];then + . /etc/pihole/setupVars.conf +else + echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure." + echo "::: Please run 'pihole -r', and choose the 'install' option to reconfigure." + exit 1 +fi + #Remove the /* from the end of the IPv4addr. IPv4addr=${IPv4_address%/*} From 7ee1110351fe5bffc6cc9de7c29fd24b440c7213 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 20:09:38 +0100 Subject: [PATCH 018/172] ugh. pihole.conf. --- gravity.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 4ef440a5..5f0606b4 100755 --- a/gravity.sh +++ b/gravity.sh @@ -54,10 +54,9 @@ supernova=${basename}.1.supernova.txt eventHorizon=${basename}.2.eventHorizon.txt accretionDisc=${basename}.3.accretionDisc.txt -# After setting defaults, check if there's local overrides +# Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it) if [[ -r ${piholeDir}/pihole.conf ]];then - echo "::: Local calibration requested..." - . ${piholeDir}/pihole.conf + echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored." fi ########################### From 7e10dcdcf05034416920a8f0c5a3a16557951d34 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 20:12:16 +0100 Subject: [PATCH 019/172] update pihole bash-completion --- advanced/bash-completion/pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/bash-completion/pihole b/advanced/bash-completion/pihole index 2d6aafae..1fae988d 100644 --- a/advanced/bash-completion/pihole +++ b/advanced/bash-completion/pihole @@ -4,7 +4,7 @@ _pihole() COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="blacklist chronometer debug flush help query setupLCD uninstall updateDashboard updateGravity updatePihole version whitelist" + opts="blacklist chronometer debug flush help query reconfigure setupLCD uninstall updateGravity updatePihole version whitelist" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 From a43577fa26c4c2c9852f4ec9a330101463073025 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 20:43:03 +0100 Subject: [PATCH 020/172] add reconfigure flag to -r command --- automated install/basic-install.sh | 19 +++++++++++++++++-- pihole | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 945fa1e1..ccb84667 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -40,6 +40,11 @@ columns=$(tput cols) r=$(( rows / 2 )) c=$(( columns / 2 )) +######## Flags. Shhh ######## +skipSpaceCheck=false +skipRepoUpdate=false +runUnattended=false + ######## FIRST CHECK ######## # Must be root to install echo ":::" @@ -884,8 +889,18 @@ update_dialogs(){ } main() { + +for var in "$@" +do + case "$var" in + "--reconfigure" ) skipRepoUpdate=true;; + "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; + "--unattended" ) runUnattended=true;; + esac +done + if [[ -f ${setupVars} ]];then - if [ "$1" == "pihole" ]; then + if [ "$runUnattended" = true ]; then useUpdateVars=true else update_dialogs @@ -894,7 +909,7 @@ fi # Start the installer # Verify there is enough disk space for the install -if [[ $1 = "--i_do_not_follow_recommendations" ]]; then +if [[ "$skipSpaceCheck" = true ]]; then echo "::: --i_do_not_follow_recommendations passed to script" echo "::: skipping free disk space verification!" else diff --git a/pihole b/pihole index 30b13403..4ed446be 100755 --- a/pihole +++ b/pihole @@ -99,7 +99,7 @@ updatePiholeFunc() { echo "::: Fetching latest changes from GitHub..." cd /etc/.pihole git pull origin master - /etc/.pihole/automated\ install/basic-install.sh pihole + /etc/.pihole/automated\ install/basic-install.sh --unattended echo ":::" echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" @@ -114,7 +114,7 @@ updatePiholeFunc() { } reconfigurePiholeFunc() { - /etc/.pihole/automated\ install/basic-install.sh + /etc/.pihole/automated\ install/basic-install.sh --reconfigure exit 0; } From e612003293a5b4e217ad61beec386ffeaa6f7510 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 20:52:20 +0100 Subject: [PATCH 021/172] handle arguments better, convert to flags, echo when they're set to true. --- automated install/basic-install.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ccb84667..9e9a7367 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -40,7 +40,7 @@ columns=$(tput cols) r=$(( rows / 2 )) c=$(( columns / 2 )) -######## Flags. Shhh ######## +######## Undocumented Flags. Shhh ######## skipSpaceCheck=false skipRepoUpdate=false runUnattended=false @@ -890,6 +890,7 @@ update_dialogs(){ main() { +# Check arguments for the undocumented flags for var in "$@" do case "$var" in @@ -901,6 +902,7 @@ done if [[ -f ${setupVars} ]];then if [ "$runUnattended" = true ]; then + echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" useUpdateVars=true else update_dialogs @@ -910,8 +912,7 @@ fi # Start the installer # Verify there is enough disk space for the install if [[ "$skipSpaceCheck" = true ]]; then - echo "::: --i_do_not_follow_recommendations passed to script" - echo "::: skipping free disk space verification!" + echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" else verifyFreeDiskSpace fi @@ -928,6 +929,14 @@ install_dependent_packages INSTALLER_DEPS[@] # Install packages used by the Pi-hole install_dependent_packages PIHOLE_DEPS[@] +if [[ "$skipRepoUpdate" = true ]]; then + echo "::: --reconfigure passed to install script. Not downloading/updating local repos" +else + # Get Git files for Core and Admin + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} +fi + if [[ ${useUpdateVars} == false ]]; then # Display welcome dialogs welcomeDialogs @@ -935,9 +944,6 @@ if [[ ${useUpdateVars} == false ]]; then mkdir -p /etc/pihole/ # Remove legacy scripts from previous storage location remove_legacy_scripts - # Get Git files for Core and Admin - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} # Stop resolver and webserver while installing proceses stop_service dnsmasq stop_service lighttpd From 3a9b39b842086799b2fb3b3a6ff959f33a5088fd Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 21:12:13 +0100 Subject: [PATCH 022/172] adjust text in update_dialogs() whiptail --- automated install/basic-install.sh | 39 +++++++++++++++++++----------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9e9a7367..a5de9863 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -42,7 +42,7 @@ c=$(( columns / 2 )) ######## Undocumented Flags. Shhh ######## skipSpaceCheck=false -skipRepoUpdate=false +reconfigure=false runUnattended=false ######## FIRST CHECK ######## @@ -864,13 +864,25 @@ View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admi } update_dialogs(){ + # reconfigure + if [ "$reconfigure" = true ]; then + opt1a="Refresh" + opt1b="Refresh will retain existing settings" + strAdd="You will remain on the same version" + else + opt1a="Update" + opt1b="Update will retain existing settings." + strAdd="You will be updated to the latest version." + fi + opt2a="Reconfigure" + opt2b="Reconfigure will allow you to enter new settings" - UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options:" ${r} ${c} 2 \ - "Update" "Update install will retain existing settings." \ - "Install" "Install will allow you to enter new settings." 3>&2 2>&1 1>&3) + UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \ + "$opt1a" "$opt1b" \ + "$opt2a" "$opt2b" 3>&2 2>&1 1>&3) - if [[ $? = 0 ]];then - case ${UpdateCmd} in + if [[ $? = 0 ]];then + case ${UpdateCmd} in Update) echo "::: Updating existing install" . ${setupVars} @@ -880,21 +892,20 @@ update_dialogs(){ echo "::: Running complete install script" useUpdateVars=false ;; - esac - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi + esac + else + echo "::: Cancel selected. Exiting..." + exit 1 + fi } main() { - # Check arguments for the undocumented flags for var in "$@" do case "$var" in - "--reconfigure" ) skipRepoUpdate=true;; + "--reconfigure" ) reconfigure=true;; "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; "--unattended" ) runUnattended=true;; esac @@ -929,7 +940,7 @@ install_dependent_packages INSTALLER_DEPS[@] # Install packages used by the Pi-hole install_dependent_packages PIHOLE_DEPS[@] -if [[ "$skipRepoUpdate" = true ]]; then +if [[ "$reconfigure" = true ]]; then echo "::: --reconfigure passed to install script. Not downloading/updating local repos" else # Get Git files for Core and Admin From 05dadad2e1568ac5f5c383be526f9501197514dc Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 21:22:46 +0100 Subject: [PATCH 023/172] repair sounds better than refresh --- 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 a5de9863..82ef1a53 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -866,8 +866,8 @@ View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admi update_dialogs(){ # reconfigure if [ "$reconfigure" = true ]; then - opt1a="Refresh" - opt1b="Refresh will retain existing settings" + opt1a="Repair" + opt1b="Repair will retain existing settings" strAdd="You will remain on the same version" else opt1a="Update" From a65b784907e3d845ffd78f661930916205f0c75b Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 21:26:41 +0100 Subject: [PATCH 024/172] repeat after me: repetition is a bit repetitive. --- automated install/basic-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 82ef1a53..00acf333 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -867,15 +867,15 @@ update_dialogs(){ # reconfigure if [ "$reconfigure" = true ]; then opt1a="Repair" - opt1b="Repair will retain existing settings" + opt1b="This will retain existing settings" strAdd="You will remain on the same version" else opt1a="Update" - opt1b="Update will retain existing settings." + opt1b="This will retain existing settings." strAdd="You will be updated to the latest version." fi opt2a="Reconfigure" - opt2b="Reconfigure will allow you to enter new settings" + opt2b="This will allow you to enter new settings" UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \ "$opt1a" "$opt1b" \ From a84c3adeabb95ce2dba9f73ed9db32f84eff5361 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 23:19:26 +0100 Subject: [PATCH 025/172] if uniformity then dan = happy --- automated install/basic-install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 00acf333..c4d7c01d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -912,7 +912,7 @@ do done if [[ -f ${setupVars} ]];then - if [ "$runUnattended" = true ]; then + if [[ "${runUnattended}" == true ]]; then echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" useUpdateVars=true else @@ -922,7 +922,7 @@ fi # Start the installer # Verify there is enough disk space for the install -if [[ "$skipSpaceCheck" = true ]]; then +if [[ "${skipSpaceCheck}" ==true ]]; then echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" else verifyFreeDiskSpace @@ -940,7 +940,7 @@ install_dependent_packages INSTALLER_DEPS[@] # Install packages used by the Pi-hole install_dependent_packages PIHOLE_DEPS[@] -if [[ "$reconfigure" = true ]]; then +if [[ "${reconfigure}" == true ]]; then echo "::: --reconfigure passed to install script. Not downloading/updating local repos" else # Get Git files for Core and Admin @@ -975,7 +975,7 @@ fi # Move the log file into /etc/pihole for storage mv ${tmpLog} ${instalLogLoc} -if [[ ${useUpdateVars} == false ]]; then +if [[ "${useUpdateVars}" == false ]]; then displayFinalMessage fi @@ -988,7 +988,7 @@ enable_service lighttpd echo " done." echo ":::" -if [[ ${useUpdateVars} == false ]]; then +if [[ "${useUpdateVars}" == false ]]; then echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" echo "::: ${IPv4_address%/*}" echo "::: $IPv6_address" From 3884b01503d86f747424d8e96379bfd27b13acc0 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sat, 15 Oct 2016 23:21:13 +0100 Subject: [PATCH 026/172] Forgot 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 c4d7c01d..a423f795 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -922,7 +922,7 @@ fi # Start the installer # Verify there is enough disk space for the install -if [[ "${skipSpaceCheck}" ==true ]]; then +if [[ "${skipSpaceCheck}" == true ]]; then echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" else verifyFreeDiskSpace From 8c0f860601ac0e906d7871690e7cec49c8448275 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 16 Oct 2016 17:16:59 +0100 Subject: [PATCH 027/172] Use systemctl/service calls instead of killall to restart/reload dnsmasq --- advanced/Scripts/blacklist.sh | 18 +++++++++++++----- advanced/Scripts/whitelist.sh | 18 +++++++++++++----- gravity.sh | 21 ++++++++++++++------- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index feeca9da..8bcf22bf 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -168,14 +168,22 @@ Reload() { echo ":::" echo -n "::: Refresh lists in dnsmasq..." - dnsmasqPid=$(pidof dnsmasq) + dnsmasqPid=$(pidof dnsmasq) if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - killall -s HUP dnsmasq + # 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 - service dnsmasq start + # service not running, start it up + if [ -x "$(command -v systemctl)" ]; then + systemctl start dnsmasq + else + service dnsmasq start + fi fi echo " done!" } diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index d6a09b35..f715a2fd 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -185,14 +185,22 @@ Reload() { # Reload hosts file echo ":::" echo -n "::: Refresh lists in dnsmasq..." - dnsmasqPid=$(pidof dnsmasq) + dnsmasqPid=$(pidof dnsmasq) if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - killall -s HUP dnsmasq + # 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 - service dnsmasq start + # service not running, start it up + if [ -x "$(command -v systemctl)" ]; then + systemctl start dnsmasq + else + service dnsmasq start + fi fi echo " done!" } diff --git a/gravity.sh b/gravity.sh index 5f0606b4..46be515c 100755 --- a/gravity.sh +++ b/gravity.sh @@ -310,18 +310,25 @@ gravity_reload() { adList=${adList//\//\\\/} #Now replace the line in dnsmasq file sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf - dnsmasqPid=$(pidof dnsmasq) + find "$piholeDir" -type f -exec chmod 666 {} \; - find "$piholeDir" -type f -exec chmod 666 {} \; + dnsmasqPid=$(pidof dnsmasq) if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - killall -s HUP dnsmasq + # 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 - service dnsmasq start + # service not running, start it up + if [ -x "$(command -v systemctl)" ]; then + systemctl start dnsmasq + else + service dnsmasq start + fi fi - echo " done!" } From 42c93917ef112378e78f4bbd1a69ea25ebc923d3 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 16 Oct 2016 17:19:44 +0100 Subject: [PATCH 028/172] bug I forgot to fix before piholeUpdate was merged to development --- 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 26f66e0a..361fb089 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -895,11 +895,11 @@ update_dialogs(){ if [[ $? = 0 ]];then case ${UpdateCmd} in - Update) + ${opt1a}) echo "::: Updating existing install" useUpdateVars=true ;; - Install) + ${opt2a}) echo "::: Running complete install script" useUpdateVars=false ;; From 5792fc0befda7117667b9aab9c34cafa4e59e3d5 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 16 Oct 2016 17:23:26 +0100 Subject: [PATCH 029/172] change wording depending on choice --- 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 361fb089..0d6ea97b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -896,11 +896,11 @@ update_dialogs(){ if [[ $? = 0 ]];then case ${UpdateCmd} in ${opt1a}) - echo "::: Updating existing install" + echo "::: $opt1a option selected." useUpdateVars=true ;; ${opt2a}) - echo "::: Running complete install script" + echo "::: $opt2a option selected" useUpdateVars=false ;; esac From ee114b307590a94b1c24d983b9e694fca412580b Mon Sep 17 00:00:00 2001 From: bcambl Date: Sun, 16 Oct 2016 13:28:14 -0600 Subject: [PATCH 030/172] use an excluded extension for ifcfg backup --- 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 0d6ea97b..bfa4eee2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -360,7 +360,7 @@ setStaticIPv4() { IPADDR=$(echo "${IPv4_address}" | cut -f1 -d/) CIDR=$(echo "${IPv4_address}" | cut -f2 -d/) # Backup existing interface configuration: - cp "${IFCFG_FILE}" "${IFCFG_FILE}".backup-"$(date +%Y-%m-%d-%H%M%S)" + cp "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig" # Build Interface configuration file: { echo "# Configured via Pi-Hole installer" From fb9664b6361687676b0f7dc35cd81ddbdb7ee55e Mon Sep 17 00:00:00 2001 From: bcambl Date: Sun, 16 Oct 2016 15:11:47 -0600 Subject: [PATCH 031/172] fix typo --- 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 bfa4eee2..1fb1a49f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -360,7 +360,7 @@ setStaticIPv4() { IPADDR=$(echo "${IPv4_address}" | cut -f1 -d/) CIDR=$(echo "${IPv4_address}" | cut -f2 -d/) # Backup existing interface configuration: - cp "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig" + cp "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig # Build Interface configuration file: { echo "# Configured via Pi-Hole installer" From 49f48e2aaa5ea4082b56535140949fbd055c31cb Mon Sep 17 00:00:00 2001 From: Promofaux Date: Mon, 17 Oct 2016 22:24:59 +0100 Subject: [PATCH 032/172] wrong word. #admincrimes --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 46be515c..3d9c05c4 100755 --- a/gravity.sh +++ b/gravity.sh @@ -37,7 +37,7 @@ if [[ -f ${setupVars} ]];then . /etc/pihole/setupVars.conf else echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure." - echo "::: Please run 'pihole -r', and choose the 'install' option to reconfigure." + echo "::: Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure." exit 1 fi From 2220d2dab83cfac2dccac02fd98f94e22d3a3394 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 17 Oct 2016 18:28:38 -0700 Subject: [PATCH 033/172] Create .gitattributes --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..459b62dd --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto +*.sh text +*.py text From 0ad704e5324cf76495f60338e04bb28a374d23c6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 17 Oct 2016 18:31:06 -0700 Subject: [PATCH 034/172] Update .gitattributes --- .gitattributes | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index 459b62dd..57faaa8b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,38 @@ +# FROM https://github.com/libgit2/libgit2sharp +# Text files that should be normalized to LF in odb. +*.cs text diff=csharp +*.config text + +*.sln text +*.csproj text + +*.md text +*.sh text +*.ps1 text +*.cmd text +*.bat text +*.markdown text +*.msbuild text + +Lib/* binary +GitHub.Tests.Integration/Resources/* binary + + +# Binary files that should not be normalized or diffed +*.png binary +*.jpg binary +*.gif binary + +*.pfx binary +*.snk binary +*.dll binary +*.exe binary +*.lib binary +*.exp binary +*.pdb binary +*.sdf binary +*.7z binary + + +# Catch all for anything we forgot. Add rules if you get CRLF -> LF warnings. * text=auto -*.sh text -*.py text From ef3c13fe2b08396f23f9563dcf872ed338a19ea7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 17 Oct 2016 19:22:56 -0700 Subject: [PATCH 035/172] Refire with curl --- 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 1fb1a49f..7c26019e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -58,7 +58,7 @@ else echo "::: Detecting the presence of the sudo utility for continuation of this install..." if [ -x "$(command -v sudo)" ];then echo "::: Utility sudo located." - exec sudo bash "$0" "$@" + exec curl -sSL https://install.pi-hole.net | sudo bash "$@" exit $? else echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed." From 77808223dc3d4730c3053b14300b98fe996b8377 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 10:05:10 +0100 Subject: [PATCH 036/172] remove stock comments from 01-pihole.conf and add warning to the top --- advanced/01-pihole.conf | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 339bbf90..e7e627a4 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -9,53 +9,31 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# If you want dnsmasq to read another file, as well as /etc/hosts, use -# this. -addn-hosts=/etc/pihole/gravity.list +############################################################################### +# FILE AUTOMATICALLY POPULATED BY PI-HOLE INSTALL/UPDATE PROCEDURE. # +# ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # +############################################################################### -# The following two options make you a better netizen, since they -# tell dnsmasq to filter out queries which the public DNS cannot -# answer, and which load the servers (especially the root servers) -# unnecessarily. If you have a dial-on-demand link they also stop -# these requests from bringing up the link unnecessarily. +addn-hosts=/etc/pihole/gravity.list -# Never forward plain names (without a dot or domain part) domain-needed -# Never forward addresses in the non-routed address spaces. + bogus-priv -# If you don't want dnsmasq to read /etc/resolv.conf or any other -# file, getting its servers from this file instead (see below), then -# uncomment this. no-resolv -# Add other name servers here, with domain specs if they are for -# non-public domains. server=@DNS1@ server=@DNS2@ -# If you want dnsmasq to listen for DHCP and DNS requests only on -# specified interfaces (and the loopback) give the name of the -# interface (eg eth0) here. interface=@INT@ -# Or which to listen on by address (remember to include 127.0.0.1 if -# you use this.) + listen-address=127.0.0.1 -# Set the cachesize here. cache-size=10000 -# For debugging purposes, log each DNS query as it passes through -# dnsmasq. log-queries log-facility=/var/log/pihole.log -# Normally responses which come from /etc/hosts and the DHCP lease -# file have Time-To-Live set as zero, which conventionally means -# do not cache further. If you are happy to trade lower load on the -# server for potentially stale date, you can set a time-to-live (in -# seconds) here. local-ttl=300 -# This allows it to continue functioning without being blocked by syslog, and allows syslog to use dnsmasq for DNS queries without risking deadlock log-async From 97a013b2b7de5f09c88fc0d35881feb00706f710 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 10:34:05 +0100 Subject: [PATCH 037/172] Add direction to change upstream servers in setupVars.conf --- advanced/01-pihole.conf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index e7e627a4..fd8e27f2 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -12,6 +12,12 @@ ############################################################################### # FILE AUTOMATICALLY POPULATED BY PI-HOLE INSTALL/UPDATE PROCEDURE. # # ANY CHANGES MADE TO THIS FILE AFTER INSTALL WILL BE LOST ON THE NEXT UPDATE # +# # +# IF YOU WISH TO CHANGE THE UPSTREAM SERVERS, CHANGE THEM IN: # +# /etc/pihole/setupVars.conf # +# # +# ANY OTHER CHANGES SHOULD BE MADE IN A SEPERATE CONFIG FILE # +# OR IN /etc/dnsmasq.conf # ############################################################################### addn-hosts=/etc/pihole/gravity.list From 29ad2496b63a0a838e11873eaa4e089d232d3de7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:05:48 +0100 Subject: [PATCH 038/172] don't output "elevating with sudo" in pihole script, just do it. --- advanced/Scripts/update.sh | 12 +++++++++ advanced/Scripts/version.sh | 17 +++++++++++- pihole | 52 ++++++++++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 advanced/Scripts/update.sh diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh new file mode 100644 index 00000000..bdd6ab88 --- /dev/null +++ b/advanced/Scripts/update.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2015, 2016 by Jacob Salmela +# Network-wide ad blocking via your Raspberry Pi +# http://pi-hole.net +# Whitelists domains +# +# Pi-hole is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index e7e7c782..521fa26c 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -10,6 +10,10 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. + + + +normalOutput(){ piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) @@ -17,4 +21,15 @@ piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/relea 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)" -echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" \ No newline at end of file +echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" + +} + +for var in "$@" +do + case "$var" in + "-j" | "--json" ) outputJSON;; + "-h" | "--help" ) displayHelp;; + * ) normalOutput;; + esac +done \ No newline at end of file diff --git a/pihole b/pihole index 4ed446be..25a03864 100755 --- a/pihole +++ b/pihole @@ -13,7 +13,6 @@ # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then if [ -x "$(command -v sudo)" ];then - echo "::: Elevating to root with sudo" exec sudo bash "$0" "$@" exit $? else @@ -44,9 +43,48 @@ flushFunc() { exit 0 } +getGitFiles() { + # Setup git repos for directory and repository passed + # as arguments 1 and 2 + echo ":::" + echo "::: Checking for existing repository..." + if is_repo "${1}"; then + update_repo "${1}" + else + make_repo "${1}" "${2}" + fi +} + +is_repo() { + # Use git to check if directory is currently under VCS + echo -n "::: Checking $1 is a repo..." + cd "${1}" &> /dev/null || return 1 + git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 +} + +make_repo() { + # Remove the non-repod interface and clone the interface + echo -n "::: Cloning $2 into $1..." + rm -rf "${1}" + git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! + echo " done!" +} + +update_repo() { + # Pull the latest commits + echo -n "::: Updating repo in $1..." + cd "${1}" || exit 1 + git pull -q > /dev/null & spinner $! + echo " done!" +} updatePiholeFunc() { + webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" + webInterfaceDir="/var/www/html/admin" + piholeGitUrl="https://github.com/pi-hole/pi-hole.git" + piholeFilesDir="/etc/.pihole" + if [ ! -d "/etc/.pihole" ]; then #This is unlikely echo "::: Critical Error: Pi-Hole repo missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" @@ -75,17 +113,17 @@ updatePiholeFunc() { echo ":::" if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo "::: Web Admin files are already up to date!" + echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" echo "::: No need to update!" echo ":::" else echo "::: An Update is available for the Web Admin!" echo ":::" echo "::: Fetching latest changes from GitHub..." - cd /var/www/html/admin - git pull origin master + # Update Git files for Core + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} echo ":::" - echo "::: Pi-hole Web Admin has been updated to ${webVersion}" + echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" echo "::: See https://changes.pi-hole.net for details" fi else @@ -97,8 +135,8 @@ updatePiholeFunc() { fi echo "::: Fetching latest changes from GitHub..." - cd /etc/.pihole - git pull origin master + # Update Git files for Core + getGitFiles ${piholeFilesDir} ${piholeGitUrl} /etc/.pihole/automated\ install/basic-install.sh --unattended echo ":::" From 013d77488af0375cd485540cae8f487b4e784318 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:07:11 +0100 Subject: [PATCH 039/172] complete overhaul of version script. Now with optional arguments! --- advanced/Scripts/version.sh | 87 ++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 521fa26c..e77fdfc2 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -10,26 +10,93 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# Flags: +latest=false +current=false +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/",$//') -normalOutput(){ -piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) -webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) + echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" + echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" +} + +webOutput(){ + for var in "$@" + do + case "$var" in + "-l" | "--latest" ) latest=true;; + "-c" | "--current" ) current=true;; + * ) echo "::: Invalid Option!"; exit 1; + esac + done -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/",$//') + 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} + 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/",$//') + fi +} + +coreOutput(){ + for var in "$@" + do + case "$var" in + "-l" | "--latest" ) latest=true;; + "-c" | "--current" ) current=true;; + * ) echo "::: Invalid Option!"; exit 1; + esac + done -echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" -echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" + 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} + 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)" + fi +} +helpFunc() +{ + echo ":::" + echo "::: Show Pi-hole/Web Admin versions" + echo ":::" + echo "::: Usage: pihole -v [ -a | -p ] [ -l | -c ]" + echo ":::" + echo "::: Options:" + echo "::: -a, --admin Show both current and latest versions of web admin" + echo "::: -p, --pihole Show both current and latest versions of Pi-hole core files" + echo "::: -l, --latest (Only after -a | -p) Return only latest version" + echo "::: -c, --current (Only after -a | -p) Return only current version" + echo "::: -h, --help Show this help dialog" + echo ":::" + exit 0 } +if [[ $# = 0 ]]; then + normalOutput +fi + for var in "$@" do case "$var" in - "-j" | "--json" ) outputJSON;; - "-h" | "--help" ) displayHelp;; - * ) normalOutput;; + "-a" | "--admin" ) shift; webOutput "$@";; + "-p" | "--pihole" ) shift; coreOutput "$@" ;; + "-h" | "--help" ) helpFunc;; + * ) helpFunc;; esac done \ No newline at end of file From 77e8be09a1c33445cd2046ec23d8df5a430723b9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:07:42 +0100 Subject: [PATCH 040/172] handle passing arguments to version script --- pihole | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index 25a03864..c4faad57 100755 --- a/pihole +++ b/pihole @@ -193,7 +193,8 @@ uninstallFunc() { } versionFunc() { - /opt/pihole/version.sh + shift + /opt/pihole/version.sh "$@" exit 0 } @@ -235,7 +236,7 @@ case "$1" in "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; -"-v" | "version" ) versionFunc;; +"-v" | "version" ) versionFunc "$@";; "-q" | "query" ) queryFunc "$@";; "uninstall" ) uninstallFunc;; * ) helpFunc;; From ce46c4dec47940e74d93082a55b27f66bb907e6b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 12:11:02 +0100 Subject: [PATCH 041/172] remove prematurely added code --- advanced/Scripts/update.sh | 70 +++++++++++++++++++++++++++ pihole | 96 +------------------------------------- 2 files changed, 72 insertions(+), 94 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index bdd6ab88..e471ab39 100644 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -10,3 +10,73 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# Variables +webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" +webInterfaceDir="/var/www/html/admin" +piholeGitUrl="https://github.com/pi-hole/pi-hole.git" +piholeFilesDir="/etc/.pihole" + + if [ ! -d "/etc/.pihole" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + if [ ! -d "/var/www/html/admin" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + + echo "::: Checking for updates..." + 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/",$//') + + 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 "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" + echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" + echo ":::" + + if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then + echo "::: Pi-hole Base files are already up to date! Version: ${piholeVersionLatest}" + echo "::: No need to update!" + echo ":::" + + if [[ ${webVersion} == ${webVersionLatest} ]] ; then + echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" + echo "::: No need to update!" + echo ":::" + else + echo "::: An Update is available for the Web Admin!" + echo ":::" + echo "::: Fetching latest changes from GitHub..." + # Update Git files for Core + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} + echo ":::" + echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" + echo "::: See https://changes.pi-hole.net for details" + fi + else + echo -n "::: An update is available for " + if [[ ${webVersion} == ${webVersionLatest} ]] ; then + echo " Pi-Hole!" + else + echo " Pi-Hole base files and the Web Admin. Both will be updated!" + fi + + echo "::: Fetching latest changes from GitHub..." + # Update Git files for Core + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --unattended + + echo ":::" + echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" + if [[ ${webVersion} != ${webVersionLatest} ]] ; then + echo "::: Web Admin has been updated to version ${webVersionLatest}" + fi + echo ":::" + echo "::: See https://changes.pi-hole.net for details" + fi + + exit 0 \ No newline at end of file diff --git a/pihole b/pihole index c4faad57..0e29b23e 100755 --- a/pihole +++ b/pihole @@ -55,100 +55,8 @@ getGitFiles() { fi } -is_repo() { - # Use git to check if directory is currently under VCS - echo -n "::: Checking $1 is a repo..." - cd "${1}" &> /dev/null || return 1 - git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 -} - -make_repo() { - # Remove the non-repod interface and clone the interface - echo -n "::: Cloning $2 into $1..." - rm -rf "${1}" - git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! - echo " done!" -} - -update_repo() { - # Pull the latest commits - echo -n "::: Updating repo in $1..." - cd "${1}" || exit 1 - git pull -q > /dev/null & spinner $! - echo " done!" -} - updatePiholeFunc() { - - webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" - webInterfaceDir="/var/www/html/admin" - piholeGitUrl="https://github.com/pi-hole/pi-hole.git" - piholeFilesDir="/etc/.pihole" - - if [ ! -d "/etc/.pihole" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi - if [ ! -d "/var/www/html/admin" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi - - echo "::: Checking for updates..." - 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/",$//') - - 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 "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" - echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" - echo ":::" - - if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then - echo "::: Pi-hole Base files are already up to date! Version: ${piholeVersionLatest}" - echo "::: No need to update!" - echo ":::" - - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" - echo "::: No need to update!" - echo ":::" - else - echo "::: An Update is available for the Web Admin!" - echo ":::" - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} - echo ":::" - echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" - echo "::: See https://changes.pi-hole.net for details" - fi - else - echo -n "::: An update is available for " - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo " Pi-Hole!" - else - echo " Pi-Hole base files and the Web Admin. Both will be updated!" - fi - - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - /etc/.pihole/automated\ install/basic-install.sh --unattended - - echo ":::" - echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" - if [[ ${webVersion} != ${webVersionLatest} ]] ; then - echo "::: Web Admin has been updated to version ${webVersionLatest}" - fi - echo ":::" - echo "::: See https://changes.pi-hole.net for details" - fi - - exit 0 + echo "Not Implemented" } reconfigurePiholeFunc() { @@ -202,7 +110,7 @@ helpFunc() { echo "::: Control all PiHole specific functions!" echo ":::" echo "::: Usage: pihole [options]" - echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" + echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer), or -v (version) for more information on usage" echo ":::" echo "::: Options:" echo "::: -w, whitelist Whitelist domains" From ff5d5b97c33d1ec1e1a2d47cd0b81acf9cd1d303 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 13:54:09 +0100 Subject: [PATCH 042/172] stash any changes in local repo --- automated install/basic-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7c26019e..8072f79a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -702,6 +702,7 @@ update_repo() { # Pull the latest commits echo -n "::: Updating repo in $1..." cd "${1}" || exit 1 + git stash -q > /dev/null & spinner $! git pull -q > /dev/null & spinner $! echo " done!" } From 27d6e5d8cf4a47f4eb030cbaf1f729d5eaa5b751 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 14:19:25 +0100 Subject: [PATCH 043/172] Complete overhaul of update logic. Moved to seperate script --- advanced/Scripts/update.sh | 187 +++++++++++++++++++++++++------------ 1 file changed, 125 insertions(+), 62 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index e471ab39..34c12cfd 100644 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -11,72 +11,135 @@ # (at your option) any later version. # Variables + webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" webInterfaceDir="/var/www/html/admin" piholeGitUrl="https://github.com/pi-hole/pi-hole.git" piholeFilesDir="/etc/.pihole" - if [ ! -d "/etc/.pihole" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi - if [ ! -d "/var/www/html/admin" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; - fi - - echo "::: Checking for updates..." - 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/",$//') - - 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 "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" - echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" +spinner() +{ + local pid=$1 + local delay=0.50 + local spinstr='/-\|' + while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=${temp}${spinstr%"$temp"} + sleep ${delay} + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" +} + +getGitFiles() { + # Setup git repos for directory and repository passed + # as arguments 1 and 2 + echo ":::" + echo "::: Checking for existing repository..." + if is_repo "${1}"; then + update_repo "${1}" + else + make_repo "${1}" "${2}" + fi +} + +is_repo() { + # Use git to check if directory is currently under VCS + echo -n "::: Checking $1 is a repo..." + cd "${1}" &> /dev/null || return 1 + git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 +} + +make_repo() { + # Remove the non-repod interface and clone the interface + echo -n "::: Cloning $2 into $1..." + rm -rf "${1}" + git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! + echo " done!" +} + +update_repo() { + # Pull the latest commits + echo -n "::: Updating repo in $1..." + cd "${1}" || exit 1 + git stash -q > /dev/null & spinner $! + git pull -q > /dev/null & spinner $! + echo " done!" +} + +if [ ! -d "/etc/.pihole" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; +fi +if [ ! -d "/var/www/html/admin" ]; then #This is unlikely + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; +fi + +echo "::: Checking for updates..." +piholeVersion=$(pihole -v -p -c) +piholeVersionLatest=$(pihole -v -p -l) + +webVersion=$(pihole -v -a -c) +webVersionLatest=$(pihole -v -a -l) + +echo ":::" +echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" +echo "::: Web Admin version is $webVersion (Latest version is $webVersionLatest)" +echo ":::" + +# Logic +# If latest versions are blank - we've probably hit Github rate limit (stop running `pihole -up so often!): +# Update anyway +# If Core up to date AND web up to date: +# Do nothing +# If Core up to date AND web NOT up to date: +# Pull web repo +# If Core NOT up to date AND web up to date: +# pull pihole repo, run install --unattended -- reconfigure +# if Core NOT up to date AND web NOT up to date: +# pull pihole repo run install --unattended + + + +if [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then + echo "::: Everything is up to date!" + echo "" + exit 0 + +elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then + echo "::: Pi-hole Web Admin files out of date" + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} echo ":::" + webVersion=$(pihole -v -a -c) + echo "::: Web Admin version is now at ${webVersion}" + echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'" + echo "" - if [[ ${piholeVersion} == ${piholeVersionLatest} ]] ; then - echo "::: Pi-hole Base files are already up to date! Version: ${piholeVersionLatest}" - echo "::: No need to update!" - echo ":::" - - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo "::: Web Admin files are already up to date! Version: ${webVersionLatest}" - echo "::: No need to update!" - echo ":::" - else - echo "::: An Update is available for the Web Admin!" - echo ":::" - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} - echo ":::" - echo "::: Pi-hole Web Admin has been updated to ${webVersionLatest}" - echo "::: See https://changes.pi-hole.net for details" - fi - else - echo -n "::: An update is available for " - if [[ ${webVersion} == ${webVersionLatest} ]] ; then - echo " Pi-Hole!" - else - echo " Pi-Hole base files and the Web Admin. Both will be updated!" - fi - - echo "::: Fetching latest changes from GitHub..." - # Update Git files for Core - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - /etc/.pihole/automated\ install/basic-install.sh --unattended - - echo ":::" - echo "::: Pi-hole has been updated to version ${piholeVersionLatest}" - if [[ ${webVersion} != ${webVersionLatest} ]] ; then - echo "::: Web Admin has been updated to version ${webVersionLatest}" - fi - echo ":::" - echo "::: See https://changes.pi-hole.net for details" - fi - - exit 0 \ No newline at end of file +elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then + echo "::: Pi-hole core files out of date" + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended + echo ":::" + piholeVersion=$(pihole -v -p -c) + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo "" + +elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then + echo "::: Updating Everything" + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --unattended + webVersion=$(pihole -v -a -c) + piholeVersion=$(pihole -v -p -c) + echo ":::" + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo ":::" + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo "" +fi \ No newline at end of file From b66f23cfd0778d57eb13baa209b4632726ada32f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 18 Oct 2016 14:19:44 +0100 Subject: [PATCH 044/172] account for new update script --- advanced/Scripts/version.sh | 4 ++-- pihole | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index e77fdfc2..61ff7502 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -3,7 +3,7 @@ # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi # http://pi-hole.net -# Whitelists domains +# shows version numbers # # Pi-hole is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,6 +44,7 @@ webOutput(){ 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)" fi } @@ -97,6 +98,5 @@ do "-a" | "--admin" ) shift; webOutput "$@";; "-p" | "--pihole" ) shift; coreOutput "$@" ;; "-h" | "--help" ) helpFunc;; - * ) helpFunc;; esac done \ No newline at end of file diff --git a/pihole b/pihole index 0e29b23e..6be32acf 100755 --- a/pihole +++ b/pihole @@ -43,20 +43,10 @@ flushFunc() { exit 0 } -getGitFiles() { - # Setup git repos for directory and repository passed - # as arguments 1 and 2 - echo ":::" - echo "::: Checking for existing repository..." - if is_repo "${1}"; then - update_repo "${1}" - else - make_repo "${1}" "${2}" - fi -} updatePiholeFunc() { - echo "Not Implemented" + /opt/pihole/update.sh + exit 0 } reconfigurePiholeFunc() { @@ -110,7 +100,7 @@ helpFunc() { echo "::: Control all PiHole specific functions!" echo ":::" echo "::: Usage: pihole [options]" - echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer), or -v (version) for more information on usage" + echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" echo ":::" echo "::: Options:" echo "::: -w, whitelist Whitelist domains" From 8872594ab9069216c77e843d9f7f7f445b50a7ed Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 19 Oct 2016 14:27:17 +0200 Subject: [PATCH 045/172] create upload dir for lighttpd directory is missing in the installation process but is used in the lighttpd.conf --- 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 8072f79a..fa0af816 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -583,6 +583,8 @@ installConfigs() { chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd mkdir -p /var/cache/lighttpd/compress chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress + mkdir -p /var/cache/lighttpd/uploads + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/uploads } stop_service() { From 8cb72d87e46e8b9091d82aab105c48a7ec90510e Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 19:50:21 +0100 Subject: [PATCH 046/172] make IPv4/IPv6 checking more robust in gravity --- gravity.sh | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/gravity.sh b/gravity.sh index 3d9c05c4..49a3e2bc 100755 --- a/gravity.sh +++ b/gravity.sh @@ -42,7 +42,7 @@ else fi #Remove the /* from the end of the IPv4addr. -IPv4addr=${IPv4_address%/*} +IPv4_address=${IPv4_address%/*} # Variables for various stages of downloading and formatting the list basename=pihole @@ -246,17 +246,30 @@ gravity_hostFormat() { else echo "::: Error: Unable to determine fully qualified domain name of host" fi - # If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols - if [[ -n "${IPv6_address}" ]];then - # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) - echo -e "$IPv4addr $hostname\n$IPv6_address $hostname\n$IPv4addr pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} - cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} - else - # Otherwise, just create gravity.list as normal using IPv4 - # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) - echo -e "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc} - cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} - fi + + # Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both. + if [[ -n "${IPv4_address}" && -n "${IPv6_address}" ]];then + + # Both IPv4 and IPv6 + echo -e "$IPv4_address $hostname\n$IPv6_address $hostname\n$IPv4_address pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} + + elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then + + # Only IPv4 + echo -e "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} + + elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then + + # Only IPv6 + echo -e "$IPv6_address $hostname\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} + + elif [[ -z "${IPv4_address}" && -z "${IPv6_address}" ]];then + echo "::: No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values" + exit 1 + fi # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it cp ${piholeDir}/${accretionDisc} ${adList} From 60d17b97f521595562cc1dba6cd13104e4f9eea1 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 19:51:32 +0100 Subject: [PATCH 047/172] spacing --- gravity.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gravity.sh b/gravity.sh index 49a3e2bc..4cfe7bfc 100755 --- a/gravity.sh +++ b/gravity.sh @@ -248,27 +248,27 @@ gravity_hostFormat() { fi # Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both. - if [[ -n "${IPv4_address}" && -n "${IPv6_address}" ]];then + if [[ -n "${IPv4_address}" && -n "${IPv6_address}" ]];then # Both IPv4 and IPv6 - echo -e "$IPv4_address $hostname\n$IPv6_address $hostname\n$IPv4_address pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} - cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} + echo -e "$IPv4_address $hostname\n$IPv6_address $hostname\n$IPv4_address pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then # Only IPv4 echo -e "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc} - cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then # Only IPv6 echo -e "$IPv6_address $hostname\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} - cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -z "${IPv4_address}" && -z "${IPv6_address}" ]];then echo "::: No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values" - exit 1 + exit 1 fi # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it From 25343da6b7baa44ce7c82cb5725af7fdd6ed113f Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 20:03:29 +0100 Subject: [PATCH 048/172] wrong variable name --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 4cfe7bfc..0b0e78b5 100755 --- a/gravity.sh +++ b/gravity.sh @@ -257,7 +257,7 @@ gravity_hostFormat() { elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then # Only IPv4 - echo -e "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc} + echo -e "$IPv4_address $hostname\n$IPv4_address pi.hole" > ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then From 59ba6f8aec071d10956f5e11d28c91a1fdacba66 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 22:06:19 +0100 Subject: [PATCH 049/172] add flag to skip download of lists --- gravity.sh | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 0b0e78b5..d214b57e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -54,6 +54,8 @@ supernova=${basename}.1.supernova.txt eventHorizon=${basename}.2.eventHorizon.txt accretionDisc=${basename}.3.accretionDisc.txt +skipDownload=false + # Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it) if [[ -r ${piholeDir}/pihole.conf ]];then echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored." @@ -162,7 +164,7 @@ gravity_spinup() { agent="Mozilla/10.0" - echo -n "::: Getting $domain list..." + # Use a case statement to download lists that need special cURL commands # to complete properly and reset the user agent when required @@ -179,7 +181,12 @@ gravity_spinup() { # Default is a simple request *) cmd_ext="" esac - gravity_transport "$url" "$cmd_ext" "$agent" + if [[ "${skipDownload}" == false ]]; then + echo -n "::: Getting $domain list..." + gravity_transport "$url" "$cmd_ext" "$agent" + else + echo "::: Using cached $domain list" + fi done } @@ -317,7 +324,7 @@ gravity_reload() { # Reload hosts file echo ":::" echo -n "::: Refresh lists in dnsmasq..." - + #ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list! #First escape forward slashes in the path: adList=${adList//\//\\\/} @@ -345,15 +352,18 @@ gravity_reload() { } + + for var in "$@" do case "$var" in "-f" | "--force" ) forceGrav=true;; "-h" | "--help" ) helpFunc;; + "-sd" | "--skip-download" ) skipDownload=true;; esac done -if [[ ${forceGrav} == true ]]; then +if [[ "${forceGrav}" == true ]]; then echo -n "::: Deleting exising list cache..." rm /etc/pihole/list.* echo " done!" From b88fe572fe53b8354686facce9a58d0c9f093df8 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 23:15:05 +0100 Subject: [PATCH 050/172] Whitelist/Blacklist domains directly in the Event Horizon. --- gravity.sh | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/gravity.sh b/gravity.sh index d214b57e..6c143cfb 100755 --- a/gravity.sh +++ b/gravity.sh @@ -30,6 +30,8 @@ adListFile=/etc/pihole/adlists.list adListDefault=/etc/pihole/adlists.default whitelistScript=/opt/pihole/whitelist.sh blacklistScript=/opt/pihole/blacklist.sh +whitelistFile=/etc/pihole/whitelist.txt +blacklistFile=/etc/pihole/blacklist.txt #Source the setupVars from install script for the IP setupVars=/etc/pihole/setupVars.conf @@ -205,19 +207,20 @@ gravity_Schwarzchild() { gravity_Blacklist(){ # Append blacklist entries if they exist - echo -n "::: Running blacklist script to update HOSTS file...." - ${blacklistScript} -f -nr -q > /dev/null - - numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt") + numBlacklisted=$(wc -l < "${blacklistFile}") plural=; [[ "$numBlacklisted" != "1" ]] && plural=s - echo " $numBlacklisted domain${plural} blacklisted!" + + echo -n "::: BlackListing $numBlacklisted domain${plural}..." + cat ${blacklistFile} >> ${piholeDir}/${eventHorizon} + echo " done!" } gravity_Whitelist() { + #${piholeDir}/${eventHorizon}) echo ":::" # Prevent our sources from being pulled into the hole plural=; [[ "${sources[@]}" != "1" ]] && plural=s - echo -n "::: Adding ${#sources[@]} adlist source${plural} to the whitelist..." + echo -n "::: Adding adlist source${plural} to the whitelist..." urls=() for url in "${sources[@]}" @@ -227,11 +230,16 @@ gravity_Whitelist() { done echo " done!" - echo -n "::: Running whitelist script to update HOSTS file...." - ${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null - numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") + # Ensure adlist domains are in whitelist.txt + ${whitelistScript} -nr -q "${urls[@]}" > /dev/null + + # Remove anything in whitelist.txt from the Event Horizon + numWhitelisted=$(wc -l < "${whitelistFile}") plural=; [[ "$numWhitelisted" != "1" ]] && plural=s - echo " $numWhitelisted domain${plural} whitelisted!" + echo -n "::: Whitelisting $numWhitelisted domain${plural}..." + grep -F -x -v -f ${whitelistFile} ${piholeDir}/${eventHorizon} > ${piholeDir}/${eventHorizon}.tmp + mv ${piholeDir}/${eventHorizon}.tmp ${piholeDir}/${eventHorizon} + echo " done!" } gravity_unique() { @@ -351,9 +359,6 @@ gravity_reload() { fi } - - - for var in "$@" do case "$var" in @@ -375,8 +380,11 @@ gravity_collapse gravity_spinup gravity_Schwarzchild gravity_advanced -gravity_hostFormat -gravity_blackbody + gravity_Whitelist gravity_Blacklist + +gravity_hostFormat +gravity_blackbody + gravity_reload From a41eff1276f31a2c7f0840a4c3d042be0d7ad382 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 23:16:52 +0100 Subject: [PATCH 051/172] Blacklist script now only directly edits blacklist.txt. DOES NOT TOUCH HOST FILE, instead calls gravity with a no download argument --- advanced/Scripts/blacklist.sh | 99 ++--------------------------------- 1 file changed, 3 insertions(+), 96 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 8bcf22bf..87e117bf 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -19,7 +19,6 @@ helpFunc() echo "::: Options:" echo "::: -d, --delmode Remove domains from the blacklist" echo "::: -nr, --noreload Update blacklist without refreshing dnsmasq" - echo "::: -f, --force Force updating of the hosts files, even if there are no changes" echo "::: -q, --quiet output is less verbose" echo "::: -h, --help Show this help dialog" echo "::: -l, --list Display your blacklisted domains" @@ -37,40 +36,11 @@ adList=${piholeDir}/gravity.list blacklist=${piholeDir}/blacklist.txt reload=true addmode=true -force=false verbose=true domList=() domToRemoveList=() -piholeIPfile=/etc/pihole/piholeIP -piholeIPv6file=/etc/pihole/.useIPv6 - -if [[ -f ${piholeIPfile} ]];then - # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script - piholeIP=$(cat ${piholeIPfile}) - #rm $piholeIPfile -else - # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') - piholeIP=${piholeIPCIDR%/*} -fi - -modifyHost=false - -# After setting defaults, check if there's local overrides -if [[ -r ${piholeDir}/pihole.conf ]];then - echo "::: Local calibration requested..." - . ${piholeDir}/pihole.conf -fi - - -if [[ -f ${piholeIPv6file} ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') -fi - HandleOther(){ #check validity of domain validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') @@ -105,7 +75,6 @@ AddDomain(){ echo -n "::: Adding $1 to blacklist file..." fi echo "$1" >> ${blacklist} - modifyHost=true echo " done!" else if ${verbose}; then @@ -124,68 +93,16 @@ RemoveDomain(){ echo "::: $1 is NOT blacklisted! No need to remove" fi else - #Domain is in the blacklist file, add to a temporary array + #Domain is in the blacklist file,remove it if ${verbose}; then echo "::: Un-blacklisting $dom..." fi - domToRemoveList=("${domToRemoveList[@]}" $1) - modifyHost=true + echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} fi } -ModifyHostFile(){ - if ${addmode}; then - #add domains to the hosts file - if [[ -r ${blacklist} ]];then - numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l) - plural=; [[ "$numberOf" != "1" ]] && plural=s - echo ":::" - echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." - if [[ -n ${piholeIPv6} ]];then - cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} - else - cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} - fi - fi - else - echo ":::" - for dom in "${domToRemoveList[@]}" - do - #we need to remove the domains from the blacklist file and the host file - echo "::: $dom" - echo -n "::: removing from HOSTS file..." - echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList} - echo " done!" - echo -n "::: removing from blackist.txt..." - echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} - echo " done!" - done - fi -} - Reload() { - # Reload hosts file - echo ":::" - echo -n "::: Refresh lists in dnsmasq..." - - dnsmasqPid=$(pidof dnsmasq) - - 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 - systemctl start dnsmasq - else - service dnsmasq start - fi - fi - echo " done!" + pihole -g -sd } DisplayBlist() { @@ -206,7 +123,6 @@ do case "$var" in "-nr"| "--noreload" ) reload=false;; "-d" | "--delmode" ) addmode=false;; - "-f" | "--force" ) force=true;; "-q" | "--quiet" ) verbose=false;; "-h" | "--help" ) helpFunc;; "-l" | "--list" ) DisplayBlist;; @@ -216,15 +132,6 @@ done PopBlacklistFile -if ${modifyHost} || ${force}; then - ModifyHostFile -else - if ${verbose}; then - echo "::: No changes need to be made" - fi - exit 1 -fi - if ${reload}; then Reload fi From a64f4cd8712d3be1fabc4d943b3c68811797b80e Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 23:17:20 +0100 Subject: [PATCH 052/172] whitelist script now only directly edits whitelist.txt. DOES NOT TOUCH HOST FILE, instead calls gravity with a no download argument --- advanced/Scripts/whitelist.sh | 119 ++-------------------------------- 1 file changed, 6 insertions(+), 113 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index f715a2fd..2b572d00 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -20,7 +20,6 @@ helpFunc() echo "::: Options:" echo "::: -d, --delmode Remove domains from the whitelist" echo "::: -nr, --noreload Update Whitelist without refreshing dnsmasq" - echo "::: -f, --force Force updating of the hosts files, even if there are no changes" echo "::: -q, --quiet output is less verbose" echo "::: -h, --help Show this help dialog" echo "::: -l, --list Display your whitelisted domains" @@ -38,39 +37,11 @@ adList=${piholeDir}/gravity.list whitelist=${piholeDir}/whitelist.txt reload=true addmode=true -force=false verbose=true domList=() domToRemoveList=() -piholeIPfile=/etc/pihole/piholeIP -piholeIPv6file=/etc/pihole/.useIPv6 - -if [[ -f ${piholeIPfile} ]];then - # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script - piholeIP=$(cat ${piholeIPfile}) - #rm $piholeIPfile -else - # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') - piholeIP=${piholeIPCIDR%/*} -fi - -modifyHost=false - -# After setting defaults, check if there's local overrides -if [[ -r ${piholeDir}/pihole.conf ]];then - echo "::: Local calibration requested..." - . ${piholeDir}/pihole.conf -fi - -if [[ -f ${piholeIPv6file} ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') -fi - HandleOther(){ #check validity of domain validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') @@ -107,8 +78,7 @@ AddDomain(){ echo -n "::: Adding $1 to $whitelist..." fi echo "$1" >> ${whitelist} - modifyHost=true - if ${verbose}; then + if ${verbose}; then echo " done!" fi else @@ -128,81 +98,13 @@ RemoveDomain(){ echo "::: $1 is NOT whitelisted! No need to remove" fi else - #Domain is in the whitelist file, add to a temporary array and remove from whitelist file - #if $verbose; then - #echo "::: Un-whitelisting $dom..." - #fi - domToRemoveList=("${domToRemoveList[@]}" $1) - modifyHost=true + echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} fi } -ModifyHostFile(){ - if ${addmode}; then - #remove domains in from hosts file - if [[ -r ${whitelist} ]];then - # Remove whitelist entries - numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l) - plural=; [[ "$numberOf" != "1" ]] && plural=s - echo ":::" - echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." - awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp - awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp - echo "l" >> /etc/pihole/whitelist.tmp - grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp - rm ${adList} - mv ${piholeDir}/gravity.tmp ${adList} - rm ${piholeDir}/whitelist.tmp - echo " done!" - - fi - else - #we need to add the removed domains to the hosts file - echo ":::" - echo "::: Modifying HOSTS file to un-whitelist domains..." - for rdom in "${domToRemoveList[@]}" - do - if grep -q "$rdom" /etc/pihole/*.domains; then - echo "::: AdLists contain $rdom, re-adding block" - if [[ -n ${piholeIPv6} ]];then - echo -n "::: Restoring block for $rdom on IPv4 and IPv6..." - echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} - echo " done!" - else - echo -n "::: Restoring block for $rdom on IPv4..." - echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} - echo " done!" - fi - fi - echo -n "::: Removing $rdom from $whitelist..." - echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} - echo " done!" - done - fi -} - Reload() { # Reload hosts file - echo ":::" - echo -n "::: Refresh lists in dnsmasq..." - dnsmasqPid=$(pidof dnsmasq) - - 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 - systemctl start dnsmasq - else - service dnsmasq start - fi - fi - echo " done!" + pihole -g -sd } DisplayWlist() { @@ -223,7 +125,6 @@ do case "$var" in "-nr"| "--noreload" ) reload=false;; "-d" | "--delmode" ) addmode=false;; - "-f" | "--force" ) force=true;; "-q" | "--quiet" ) verbose=false;; "-h" | "--help" ) helpFunc;; "-l" | "--list" ) DisplayWlist;; @@ -233,16 +134,8 @@ done PopWhitelistFile -if ${modifyHost} || ${force}; then - ModifyHostFile -else - if ${verbose}; then - echo ":::" - echo "::: No changes need to be made" - fi - exit 1 -fi - if ${reload}; then Reload -fi \ No newline at end of file +fi + + From 3f73c61cee236ed1a53cbe76d59b983b10e9769a Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 23:52:54 +0100 Subject: [PATCH 053/172] cache event horizon before white/blacklists are applied for quicker processing on white/blacklist calls of gravity --- gravity.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/gravity.sh b/gravity.sh index 6c143cfb..b525e936 100755 --- a/gravity.sh +++ b/gravity.sh @@ -53,7 +53,8 @@ adList=${piholeDir}/gravity.list justDomainsExtension=domains matterAndLight=${basename}.0.matterandlight.txt supernova=${basename}.1.supernova.txt -eventHorizon=${basename}.2.eventHorizon.txt +preEventHorizon=list.preEventHorizon +eventHorizon=${basename}.2.supernova.txt accretionDisc=${basename}.3.accretionDisc.txt skipDownload=false @@ -186,8 +187,6 @@ gravity_spinup() { if [[ "${skipDownload}" == false ]]; then echo -n "::: Getting $domain list..." gravity_transport "$url" "$cmd_ext" "$agent" - else - echo "::: Using cached $domain list" fi done } @@ -237,17 +236,16 @@ gravity_Whitelist() { numWhitelisted=$(wc -l < "${whitelistFile}") plural=; [[ "$numWhitelisted" != "1" ]] && plural=s echo -n "::: Whitelisting $numWhitelisted domain${plural}..." - grep -F -x -v -f ${whitelistFile} ${piholeDir}/${eventHorizon} > ${piholeDir}/${eventHorizon}.tmp - mv ${piholeDir}/${eventHorizon}.tmp ${piholeDir}/${eventHorizon} + grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} echo " done!" } gravity_unique() { # Sort and remove duplicates echo -n "::: Removing duplicate domains...." - sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon} + sort -u ${piholeDir}/${supernova} > ${piholeDir}/${preEventHorizon} echo " done!" - numberOf=$(wc -l < ${piholeDir}/${eventHorizon}) + numberOf=$(wc -l < ${piholeDir}/${preEventHorizon}) echo "::: $numberOf unique domains trapped in the event horizon." } @@ -378,9 +376,14 @@ fi cp /etc/.pihole/adlists.default /etc/pihole/adlists.default gravity_collapse gravity_spinup -gravity_Schwarzchild -gravity_advanced - +if [[ "${skipDownload}" == false ]]; then + gravity_Schwarzchild + gravity_advanced +else + echo "::: Using cached Event Horizon list..." + numberOf=$(wc -l < ${piholeDir}/${preEventHorizon}) + echo "::: $numberOf unique domains trapped in the event horizon." +fi gravity_Whitelist gravity_Blacklist From a7fa7466fb59d3af2f643abc76c50c752652ffea Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 23:54:43 +0100 Subject: [PATCH 054/172] remove no longer needed code --- gravity.sh | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/gravity.sh b/gravity.sh index b525e936..a5e7c047 100755 --- a/gravity.sh +++ b/gravity.sh @@ -97,20 +97,6 @@ gravity_collapse() { done < ${adListDefault} echo " done!" fi - - # Create the pihole resource directory if it doesn't exist. Future files will be stored here - if [[ -d ${piholeDir} ]];then - # Temporary hack to allow non-root access to pihole directory - # Will update later, needed for existing installs, new installs should - # create this directory as non-root - chmod 777 ${piholeDir} - echo ":::" - echo "::: Existing pihole directory found" - else - echo "::: Creating pihole directory..." - mkdir ${piholeDir} - chmod 777 ${piholeDir} - fi } # patternCheck - check to see if curl downloaded any new files. From 9aa38cf0ae11b0142ba7ac74341701f953af3c8f Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 19 Oct 2016 23:57:43 +0100 Subject: [PATCH 055/172] mv patternbuffer instead of cp, then no need to clean up --- gravity.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index a5e7c047..990b18ee 100755 --- a/gravity.sh +++ b/gravity.sh @@ -107,7 +107,7 @@ gravity_patternCheck() { # Some of the blocklists are copyright, they need to be downloaded # and stored as is. They can be processed for content after they # have been saved. - cp "$patternBuffer" "$saveLocation" + mv "$patternBuffer" "$saveLocation" echo " List updated, transport successful!" else # curl didn't download any host files, probably because of the date check @@ -133,8 +133,6 @@ gravity_transport() { curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "$agent" ${url} > ${patternBuffer} # Check for list updates gravity_patternCheck "$patternBuffer" - # Cleanup - rm -f "$patternBuffer" } # spinup - main gravity function From 16f1d7fad9420b8fb6aa83cbcd9c82400f122444 Mon Sep 17 00:00:00 2001 From: tuplink Date: Wed, 19 Oct 2016 21:50:34 -0400 Subject: [PATCH 056/172] Blacklist unwhitelisted --- advanced/Scripts/whitelist.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 2b572d00..b294e7b6 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -99,6 +99,8 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} + #Blacklist unwhitelisted + ${blacklistScript} $1 fi } From 74bfcea6a8653299f261efe89228654b1b1b1f16 Mon Sep 17 00:00:00 2001 From: tuplink Date: Wed, 19 Oct 2016 22:00:03 -0400 Subject: [PATCH 057/172] add blacklistScript var --- advanced/Scripts/whitelist.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index b294e7b6..2dea6e7c 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -33,6 +33,7 @@ fi #globals basename=pihole piholeDir=/etc/${basename} +blacklistScript=/opt/pihole/blacklist.sh adList=${piholeDir}/gravity.list whitelist=${piholeDir}/whitelist.txt reload=true From 28eeaf201b9fb87d08a8c920ec5ef803e49766df Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Wed, 19 Oct 2016 19:47:45 -0700 Subject: [PATCH 058/172] Standardize function declaration There were no fewer than three styles of function declaration going on in these files, so I attempted to standardize them to the typical myfucn() { } style. --- advanced/Scripts/blacklist.sh | 13 ++++++------- advanced/Scripts/chronometer.sh | 16 ++++++++-------- advanced/Scripts/piholeDebug.sh | 24 ++++++++++++------------ advanced/Scripts/update.sh | 5 ++--- advanced/Scripts/version.sh | 11 +++++------ advanced/Scripts/whitelist.sh | 15 +++++++-------- automated install/basic-install.sh | 20 +++++++++----------- automated install/uninstall.sh | 9 ++++----- gravity.sh | 5 ++--- 9 files changed, 55 insertions(+), 63 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 8bcf22bf..b7b9c360 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -10,8 +10,7 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -helpFunc() -{ +helpFunc() { echo "::: Immediately blacklists one or more domains in the hosts file" echo ":::" echo ":::" @@ -71,7 +70,7 @@ if [[ -f ${piholeIPv6file} ]];then piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi -HandleOther(){ +HandleOther() { #check validity of domain validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') if [ -z "$validDomain" ]; then @@ -81,7 +80,7 @@ HandleOther(){ fi } -PopBlacklistFile(){ +PopBlacklistFile() { #check blacklist file exists, and if not, create it if [[ ! -f ${blacklist} ]];then touch ${blacklist} @@ -95,7 +94,7 @@ PopBlacklistFile(){ done } -AddDomain(){ +AddDomain() { #| sed 's/\./\\./g' bool=false grep -Ex -q "$1" ${blacklist} || bool=true @@ -114,7 +113,7 @@ AddDomain(){ fi } -RemoveDomain(){ +RemoveDomain() { bool=false grep -Ex -q "$1" ${blacklist} || bool=true @@ -133,7 +132,7 @@ RemoveDomain(){ fi } -ModifyHostFile(){ +ModifyHostFile() { if ${addmode}; then #add domains to the hosts file if [[ -r ${blacklist} ]];then diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index c03b4649..28b7276e 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -17,7 +17,7 @@ gravity="/etc/pihole/gravity.list" today=$(date "+%b %e") -CalcBlockedDomains(){ +CalcBlockedDomains() { CheckIPv6 if [ -e "$gravity" ]; then #Are we IPV6 or IPV4? @@ -33,7 +33,7 @@ CalcBlockedDomains(){ fi } -CalcQueriesToday(){ +CalcQueriesToday() { if [ -e "$piLog" ];then queriesToday=$(cat "$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l) else @@ -41,7 +41,7 @@ CalcQueriesToday(){ fi } -CalcblockedToday(){ +CalcblockedToday() { if [ -e "$piLog" ] && [ -e "$gravity" ];then blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) else @@ -49,7 +49,7 @@ CalcblockedToday(){ fi } -CalcPercentBlockedToday(){ +CalcPercentBlockedToday() { if [ "$queriesToday" != "Err." ] && [ "$blockedToday" != "Err." ]; then if [ "$queriesToday" != 0 ]; then #Fixes divide by zero error :) #scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros @@ -61,7 +61,7 @@ CalcPercentBlockedToday(){ fi } -CheckIPv6(){ +CheckIPv6() { piholeIPv6file="/etc/pihole/.useIPv6" if [[ -f ${piholeIPv6file} ]];then # If the file exists, then the user previously chose to use IPv6 in the automated installer @@ -69,7 +69,7 @@ CheckIPv6(){ fi } -outputJSON(){ +outputJSON() { CalcQueriesToday CalcblockedToday CalcPercentBlockedToday @@ -79,7 +79,7 @@ outputJSON(){ printf '{"domains_being_blocked":"%s","dns_queries_today":"%s","ads_blocked_today":"%s","ads_percentage_today":"%s"}\n' "$blockedDomainsTotal" "$queriesToday" "$blockedToday" "$percentBlockedToday" } -normalChrono(){ +normalChrono() { for (( ; ; )) do clear @@ -121,7 +121,7 @@ normalChrono(){ done } -displayHelp(){ +displayHelp() { echo "::: Displays stats about your piHole!" echo ":::" echo "::: Usage: sudo pihole -c [optional:-j]" diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index aadb083b..287d03f6 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#/usr/bin/env bash # Pi-hole: A black hole for Internet advertisements # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi @@ -61,11 +61,11 @@ else fi ### Private functions exist here ### -function log_write { +log_write() { echo "$1" >> "${DEBUG_LOG}" } -function version_check { +version_check() { log_write "############################################################" log_write "########## Installed Versions ##########" log_write "############################################################" @@ -83,7 +83,7 @@ function version_check { php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." } -function distro_check { +distro_check() { echo "############################################################" >> ${DEBUG_LOG} echo "######## Installed OS Distribution #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} @@ -96,7 +96,7 @@ function distro_check { echo >> ${DEBUG_LOG} } -function ip_check { +ip_check() { echo "############################################################" >> ${DEBUG_LOG} echo "######## IP Address Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} @@ -166,7 +166,7 @@ function ip_check { echo >> ${DEBUG_LOG} } -function hostnameCheck { +hostnameCheck() { echo "############################################################" >> ${DEBUG_LOG} echo "######## Hostname Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} @@ -188,7 +188,7 @@ function hostnameCheck { fi } -function portCheck { +portCheck() { echo "############################################################" >> ${DEBUG_LOG} echo "######## Open Port Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} @@ -200,7 +200,7 @@ function portCheck { echo >> ${DEBUG_LOG} } -function testResolver { +testResolver() { echo "############################################################" >> ${DEBUG_LOG} echo "############ Resolver Functions Check ############" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} @@ -262,7 +262,7 @@ function testResolver { echo >> ${DEBUG_LOG} } -function checkProcesses { +checkProcesses() { echo "#######################################" >> ${DEBUG_LOG} echo "########### Processes Check ###########" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} @@ -279,7 +279,7 @@ function checkProcesses { echo >> ${DEBUG_LOG} } -function debugLighttpd { +debugLighttpd() { echo "::: Writing lighttpd to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "############ lighttpd.conf ############" >> ${DEBUG_LOG} @@ -420,7 +420,7 @@ fi # Continuously append the pihole.log file to the pihole_debug.log file -function dumpPiHoleLog { +dumpPiHoleLog() { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT echo -e "::: Writing current Pi-hole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" echo "#######################################" >> ${DEBUG_LOG} @@ -439,7 +439,7 @@ function dumpPiHoleLog { } # Anything to be done after capturing of pihole.log terminates -function finalWork { +finalWork() { echo "::: Finshed debugging!" echo "::: The debug log can be uploaded to Termbin.com for easier sharing." read -r -p "::: Would you like to upload the log? [y/N] " response diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 34c12cfd..e42724d6 100644 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -17,8 +17,7 @@ webInterfaceDir="/var/www/html/admin" piholeGitUrl="https://github.com/pi-hole/pi-hole.git" piholeFilesDir="/etc/.pihole" -spinner() -{ +spinner() { local pid=$1 local delay=0.50 local spinstr='/-\|' @@ -142,4 +141,4 @@ elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVers echo "::: Pi-hole version is now at ${piholeVersion}" echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" echo "" -fi \ No newline at end of file +fi diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 61ff7502..d749406e 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -14,7 +14,7 @@ latest=false current=false -normalOutput(){ +normalOutput() { piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) @@ -25,7 +25,7 @@ normalOutput(){ echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" } -webOutput(){ +webOutput() { for var in "$@" do case "$var" in @@ -48,7 +48,7 @@ webOutput(){ fi } -coreOutput(){ +coreOutput() { for var in "$@" do case "$var" in @@ -71,8 +71,7 @@ coreOutput(){ fi } -helpFunc() -{ +helpFunc() { echo ":::" echo "::: Show Pi-hole/Web Admin versions" echo ":::" @@ -99,4 +98,4 @@ do "-p" | "--pihole" ) shift; coreOutput "$@" ;; "-h" | "--help" ) helpFunc;; esac -done \ No newline at end of file +done diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index f715a2fd..4f1aa0f3 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -11,8 +11,7 @@ # (at your option) any later version. -helpFunc() -{ +helpFunc() { echo "::: Immediately whitelists one or more domains in the hosts file" echo ":::" echo "::: Usage: pihole -w domain1 [domain2 ...]" @@ -71,7 +70,7 @@ if [[ -f ${piholeIPv6file} ]];then piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi -HandleOther(){ +HandleOther() { #check validity of domain validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') if [ -z "$validDomain" ]; then @@ -81,7 +80,7 @@ HandleOther(){ fi } -PopWhitelistFile(){ +PopWhitelistFile() { #check whitelist file exists, and if not, create it if [[ ! -f ${whitelist} ]];then touch ${whitelist} @@ -96,7 +95,7 @@ PopWhitelistFile(){ done } -AddDomain(){ +AddDomain() { #| sed 's/\./\\./g' bool=false @@ -118,7 +117,7 @@ AddDomain(){ fi } -RemoveDomain(){ +RemoveDomain() { bool=false grep -Ex -q "$1" ${whitelist} || bool=true @@ -137,7 +136,7 @@ RemoveDomain(){ fi } -ModifyHostFile(){ +ModifyHostFile() { if ${addmode}; then #remove domains in from hosts file if [[ -r ${whitelist} ]];then @@ -245,4 +244,4 @@ fi if ${reload}; then Reload -fi \ No newline at end of file +fi diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8072f79a..af3ab962 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -121,8 +121,7 @@ else fi ####### FUNCTIONS ########## -spinner() -{ +spinner() { local pid=$1 local delay=0.50 local spinstr='/-\|' @@ -389,8 +388,7 @@ setStaticIPv4() { fi } -function valid_ip() -{ +valid_ip() { local ip=$1 local stat=1 @@ -406,7 +404,7 @@ function valid_ip() return ${stat} } -setDNS(){ +setDNS() { DNSChooseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 6) DNSChooseOptions=(Google "" on OpenDNS "" off @@ -497,7 +495,7 @@ setDNS(){ fi } -version_check_dnsmasq(){ +version_check_dnsmasq() { # Check if /etc/dnsmasq.conf is from pihole. If so replace with an original and install new in .d directory local dnsmasq_conf="/etc/dnsmasq.conf" local dnsmasq_conf_orig="/etc/dnsmasq.conf.orig" @@ -542,7 +540,7 @@ version_check_dnsmasq(){ sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsmasq_conf} } -remove_legacy_scripts(){ +remove_legacy_scripts() { #Tidy up /usr/local/bin directory if installing over previous install. oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) for i in "${oldFiles[@]}"; do @@ -642,7 +640,7 @@ update_pacakge_cache() { fi } -notify_package_updates_available(){ +notify_package_updates_available() { # Let user know if they have outdated packages on their system and # advise them to run a package update at soonest possible. echo ":::" @@ -659,7 +657,7 @@ notify_package_updates_available(){ fi } -install_dependent_packages(){ +install_dependent_packages() { # Install packages passed in via argument array # No spinner - conflicts with set -e declare -a argArray1=("${!1}") @@ -765,7 +763,7 @@ runGravity() { /opt/pihole/gravity.sh } -create_pihole_user(){ +create_pihole_user() { # Check if user pihole exists and create if not echo "::: Checking if user 'pihole' exists..." id -u pihole &> /dev/null && echo "::: User 'pihole' already exists" || (echo "::: User 'pihole' doesn't exist. Creating..." && useradd -r -s /usr/sbin/nologin pihole) @@ -876,7 +874,7 @@ The install log is in /etc/pihole. View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admin" ${r} ${c} } -update_dialogs(){ +update_dialogs() { # reconfigure if [ "$reconfigure" = true ]; then opt1a="Repair" diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 01e76cad..b7d82ef9 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -58,8 +58,7 @@ else exit fi -spinner() -{ +spinner() { local pid=$1 local delay=0.50 local spinstr='/-\|' @@ -73,9 +72,9 @@ spinner() printf " \b\b\b\b" } -function removeAndPurge { +removeAndPurge() { # Purge dependencies -echo ":::" + echo ":::" for i in "${PIHOLE_DEPS[@]}"; do package_check ${i} > /dev/null if [ $? -eq 0 ]; then @@ -104,7 +103,7 @@ echo ":::" removeNoPurge } -function removeNoPurge { +removeNoPurge() { echo ":::" # Only web directories/files that are created by pihole should be removed. echo "::: Removing the Pi-hole Web server files..." diff --git a/gravity.sh b/gravity.sh index 3d9c05c4..f781866d 100755 --- a/gravity.sh +++ b/gravity.sh @@ -13,8 +13,7 @@ # Run this script as root or under sudo echo ":::" -helpFunc() -{ +helpFunc() { echo "::: Pull in domains from adlists" echo ":::" echo "::: Usage: pihole -g" @@ -196,7 +195,7 @@ gravity_Schwarzchild() { echo " done!" } -gravity_Blacklist(){ +gravity_Blacklist() { # Append blacklist entries if they exist echo -n "::: Running blacklist script to update HOSTS file...." ${blacklistScript} -f -nr -q > /dev/null From 8819e58882838be199f25b1a5f90d2bbef25f1c2 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 19 Oct 2016 20:15:36 -0700 Subject: [PATCH 059/172] Remove problem list, sends in Unicode - Not adware Fixes #816 --- adlists.default | 3 --- 1 file changed, 3 deletions(-) diff --git a/adlists.default b/adlists.default index 5a803400..20b48008 100644 --- a/adlists.default +++ b/adlists.default @@ -42,9 +42,6 @@ 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 -# List of known C&C malware servers (see https://github.com/pi-hole/pi-hole/issues/528) -https://ransomwaretracker.abuse.ch/downloads/RW_DOMBL.txt - # 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 From 0efda049203a200ea8f19ce64ccf540d3a422de1 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Wed, 19 Oct 2016 20:46:37 -0700 Subject: [PATCH 060/172] Use heredocs instead of multiple calls to echo There were a lot of places (like in help functions) that used multiple echo calls instead of heredocs. Personal opinion but this seems cleaner. --- advanced/Scripts/blacklist.sh | 24 +++++++++++++----------- advanced/Scripts/chronometer.sh | 19 ++++++++++--------- advanced/Scripts/piholeDebug.sh | 14 ++++++++------ advanced/Scripts/version.sh | 28 +++++++++++++++------------- advanced/Scripts/whitelist.sh | 24 +++++++++++++----------- gravity.sh | 16 +++++++++------- 6 files changed, 68 insertions(+), 57 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index b7b9c360..dc815b58 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -11,17 +11,19 @@ # (at your option) any later version. helpFunc() { - echo "::: Immediately blacklists one or more domains in the hosts file" - echo ":::" - echo ":::" - echo "::: Usage: pihole -b domain1 [domain2 ...]" - echo "::: Options:" - echo "::: -d, --delmode Remove domains from the blacklist" - echo "::: -nr, --noreload Update blacklist without refreshing dnsmasq" - echo "::: -f, --force Force updating of the hosts files, even if there are no changes" - echo "::: -q, --quiet output is less verbose" - echo "::: -h, --help Show this help dialog" - echo "::: -l, --list Display your blacklisted domains" + cat << EOM +::: Immediately blacklists one or more domains in the hosts file +::: +::: +::: Usage: pihole -b domain1 [domain2 ...] +::: Options: +::: -d, --delmode Remove domains from the blacklist +::: -nr, --noreload Update blacklist without refreshing dnsmasq +::: -f, --force Force updating of the hosts files, even if there are no changes +::: -q, --quiet output is less verbose +::: -h, --help Show this help dialog +::: -l, --list Display your blacklisted domains +EOM exit 1 } diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 28b7276e..c0b93e78 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -122,15 +122,16 @@ normalChrono() { } displayHelp() { - echo "::: Displays stats about your piHole!" - echo ":::" - echo "::: Usage: sudo pihole -c [optional:-j]" - echo "::: Note: If no option is passed, then stats are displayed on screen, updated every 5 seconds" - echo ":::" - echo "::: Options:" - echo "::: -j, --json output stats as JSON formatted string" - echo "::: -h, --help display this help text" - + 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 1 } diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 287d03f6..a49133fd 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -27,12 +27,14 @@ PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" # Header info and introduction -echo "::: Beginning Pi-hole debug at $(date)!" -echo "::: This debugging process will collect information from your running configuration," -echo "::: and optionally upload the generated log to a unique and random directory on" -echo "::: Termbin.com. NOTE: All log files auto-delete after 1 month and you are the only" -echo "::: person who is given the unique URL. Please consider where you post this link." -echo "::: " +cat << EOM +::: Beginning Pi-hole debug at $(date)! +::: This debugging process will collect information from your running configuration, +::: and optionally upload the generated log to a unique and random directory on +::: Termbin.com. NOTE: All log files auto-delete after 1 month and you are the only +::: person who is given the unique URL. Please consider where you post this link. +::: +EOM ######## FIRST CHECK ######## diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index d749406e..7b2e3f68 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -72,19 +72,21 @@ coreOutput() { } helpFunc() { - echo ":::" - echo "::: Show Pi-hole/Web Admin versions" - echo ":::" - echo "::: Usage: pihole -v [ -a | -p ] [ -l | -c ]" - echo ":::" - echo "::: Options:" - echo "::: -a, --admin Show both current and latest versions of web admin" - echo "::: -p, --pihole Show both current and latest versions of Pi-hole core files" - echo "::: -l, --latest (Only after -a | -p) Return only latest version" - echo "::: -c, --current (Only after -a | -p) Return only current version" - echo "::: -h, --help Show this help dialog" - echo ":::" - exit 0 + 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 1 } if [[ $# = 0 ]]; then diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 4f1aa0f3..ae4a7321 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -12,17 +12,19 @@ helpFunc() { - echo "::: Immediately whitelists one or more domains in the hosts file" - echo ":::" - echo "::: Usage: pihole -w domain1 [domain2 ...]" - echo ":::" - echo "::: Options:" - echo "::: -d, --delmode Remove domains from the whitelist" - echo "::: -nr, --noreload Update Whitelist without refreshing dnsmasq" - echo "::: -f, --force Force updating of the hosts files, even if there are no changes" - echo "::: -q, --quiet output is less verbose" - echo "::: -h, --help Show this help dialog" - echo "::: -l, --list Display your whitelisted domains" + cat << EOM +::: Immediately whitelists one or more domains in the hosts file +::: +::: Usage: pihole -w domain1 [domain2 ...] +::: +::: Options: +::: -d, --delmode Remove domains from the whitelist +::: -nr, --noreload Update Whitelist without refreshing dnsmasq +::: -f, --force Force updating of the hosts files, even if there are no changes +::: -q, --quiet output is less verbose +::: -h, --help Show this help dialog +::: -l, --list Display your whitelisted domains +EOM exit 1 } diff --git a/gravity.sh b/gravity.sh index f781866d..607a5eba 100755 --- a/gravity.sh +++ b/gravity.sh @@ -14,13 +14,15 @@ echo ":::" helpFunc() { - echo "::: Pull in domains from adlists" - echo ":::" - echo "::: Usage: pihole -g" - echo ":::" - echo "::: Options:" - echo "::: -f, --force Force lists to be downloaded, even if they don't need updating." - echo "::: -h, --help Show this help dialog" + cat << EOM +::: Pull in domains from adlists +::: +::: Usage: pihole -g +::: +::: Options: +::: -f, --force Force lists to be downloaded, even if they don't need updating. +::: -h, --help Show this help dialog +EOM exit 1 } From 41056ace0264deb0102425e9e5983bae4f7a664d Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 06:29:53 -0400 Subject: [PATCH 061/172] use pihole instead of direct path --- advanced/Scripts/whitelist.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 2dea6e7c..3d0561ef 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -33,7 +33,6 @@ fi #globals basename=pihole piholeDir=/etc/${basename} -blacklistScript=/opt/pihole/blacklist.sh adList=${piholeDir}/gravity.list whitelist=${piholeDir}/whitelist.txt reload=true @@ -100,8 +99,7 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} - #Blacklist unwhitelisted - ${blacklistScript} $1 + pihole -g fi } From bbcf4800de3cf9253502285c3fe40547da13902b Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 06:30:48 -0400 Subject: [PATCH 062/172] use pihole instead of direct path --- advanced/Scripts/whitelist.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 3d0561ef..a2e31c8a 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -99,6 +99,7 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} + #reload gravity to pickup any entries this may have removed pihole -g fi } From b5b6350cc7b1c3860dd8e7fdec23566b4ea2f86f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 20 Oct 2016 03:42:25 -0700 Subject: [PATCH 063/172] Add file change warning to header --- advanced/pihole.cron | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/advanced/pihole.cron b/advanced/pihole.cron index 2d06fbbc..ca1639f6 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -8,6 +8,11 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# +# This file is under source-control of the Pi-hole installtion and update +# scripts, any changes made to this file will be overwritten when the softare +# is updated or re-installed. Please make any changes to the appropriate crontab +# or other cron file snippets. # Pi-hole: Update the ad sources once a week on Sunday at 01:59 # Download any updates from the adlists From e6bd979aeb0d8632bab491af3ccbf34d03ba60ad Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 20 Oct 2016 04:27:12 -0700 Subject: [PATCH 064/172] Can't spell Fix spelling error --- advanced/pihole.cron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/pihole.cron b/advanced/pihole.cron index ca1639f6..fd557fbd 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -9,7 +9,7 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # -# This file is under source-control of the Pi-hole installtion and update +# This file is under source-control of the Pi-hole installation and update # scripts, any changes made to this file will be overwritten when the softare # is updated or re-installed. Please make any changes to the appropriate crontab # or other cron file snippets. From 36231830728c530566a3ae7c227d42884601bee8 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 20 Oct 2016 13:29:12 +0100 Subject: [PATCH 065/172] Remove reference to non-existent script --- advanced/pihole.cron | 4 ---- 1 file changed, 4 deletions(-) diff --git a/advanced/pihole.cron b/advanced/pihole.cron index 2d06fbbc..c86dded3 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -16,10 +16,6 @@ # Pi-hole: Update Pi-hole! Uncomment to enable auto update #30 2 * * 7 root /usr/local/bin/pihole updatePihole -# Pi-hole: Parse the log file before it is flushed and save the stats to a database -# This will be used for a historical view of your Pi-hole's performance -#50 23 * * * root /usr/local/bin/dailyLog.sh # note: this is outdated - # Pi-hole: Flush the log daily at 00:00 so it doesn't get out of control # Stats will be viewable in the Web interface thanks to the cron job above 00 00 * * * root /usr/local/bin/pihole flush From c71a976e7634e5c2cf7e5103c506c8c0513406a8 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 20 Oct 2016 13:37:07 +0100 Subject: [PATCH 066/172] kill off an old ugly hack --- gravity.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 990b18ee..a7439bf5 100755 --- a/gravity.sh +++ b/gravity.sh @@ -320,7 +320,6 @@ gravity_reload() { adList=${adList//\//\\\/} #Now replace the line in dnsmasq file sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf - find "$piholeDir" -type f -exec chmod 666 {} \; dnsmasqPid=$(pidof dnsmasq) From 7d7e17b351d8469bb65b8c47284b33c51f286cbb Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 08:45:20 -0400 Subject: [PATCH 067/172] add toggle to enable or disable pi-hole --- gravity.sh | 2 +- pihole | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 990b18ee..3cc621c3 100755 --- a/gravity.sh +++ b/gravity.sh @@ -319,7 +319,7 @@ gravity_reload() { #First escape forward slashes in the path: adList=${adList//\//\\\/} #Now replace the line in dnsmasq file - sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf +# sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf find "$piholeDir" -type f -exec chmod 666 {} \; dnsmasqPid=$(pidof dnsmasq) diff --git a/pihole b/pihole index 6be32acf..8828dfe4 100755 --- a/pihole +++ b/pihole @@ -96,6 +96,50 @@ versionFunc() { exit 0 } +restartDNS() { + dnsmasqPid=$(pidof dnsmasq) + 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 + systemctl start dnsmasq + else + service dnsmasq start + fi + fi +} + +piholeEnable() { + if [[ "${1}" == "0" ]] ; then + #Disable Pihole + sed -i 's/^addn-hosts/#addn-hosts/' /etc/dnsmasq.d/01-pihole.conf + else + #Enable pihole + sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf + fi + restartDNS +} + +piholeStatus() { + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then + echo "pihole is Diabled" + else + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then + echo "pihole is Enabled" + else + echo "no hosts file linked to dnsmasq, adding it in enabled state" + echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + fi + fi +} + + helpFunc() { echo "::: Control all PiHole specific functions!" echo ":::" @@ -115,6 +159,10 @@ helpFunc() { echo "::: -v, version Show current versions" echo "::: -q, query Query the adlists for a specific domain" echo "::: uninstall Uninstall Pi-Hole from your system :(!" + echo "::: status Is Pi-Hole Enabled or Disabled" + echo "::: enable Enable Pi-Hole DNS Blocking" + echo "::: disable Disable Pi-Hole DNS Blocking" + echo "::: restartdnsmasq Restart dnsmasq" exit 0 } @@ -137,5 +185,10 @@ case "$1" in "-v" | "version" ) versionFunc "$@";; "-q" | "query" ) queryFunc "$@";; "uninstall" ) uninstallFunc;; +"enable" ) piholeEnable 1;; +"disable" ) piholeEnable 0;; +"status" ) piholeStatus;; +"restartdnsmasq" ) restartDNS;; + * ) helpFunc;; esac From aaee895b2bd282ace43ae7f8b504bc81303f1e59 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 08:58:36 -0400 Subject: [PATCH 068/172] add pihole status web option to return 1 or 0 for easy use with php --- pihole | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pihole b/pihole index 8828dfe4..1651ac9c 100755 --- a/pihole +++ b/pihole @@ -128,13 +128,16 @@ piholeEnable() { piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then - echo "pihole is Diabled" + if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Diabled"; fi else if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then - echo "pihole is Enabled" + if [[ "${1}" == "web" ]] ; then echo 1; else echo "::: pihole is Enabled"; fi else - echo "no hosts file linked to dnsmasq, adding it in enabled state" - echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + if [[ "${1}" == "web" ]] ; then echo 1; else + echo "::: no hosts file linked to dnsmasq, adding it in enabled state" + echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + restartDNS + fi fi fi } @@ -187,7 +190,7 @@ case "$1" in "uninstall" ) uninstallFunc;; "enable" ) piholeEnable 1;; "disable" ) piholeEnable 0;; -"status" ) piholeStatus;; +"status" ) piholeStatus "$2";; "restartdnsmasq" ) restartDNS;; * ) helpFunc;; From a9d17c96bee91828148f54f82a6e6a27b5bc2528 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:03:20 -0400 Subject: [PATCH 069/172] include status at end of gravity so if it is disabled you will see it when running --- gravity.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gravity.sh b/gravity.sh index 3cc621c3..d43de697 100755 --- a/gravity.sh +++ b/gravity.sh @@ -375,3 +375,4 @@ gravity_hostFormat gravity_blackbody gravity_reload +pihole status From 60873144ea7d071def63b68a5e860c0d6aaa3de0 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:09:35 -0400 Subject: [PATCH 070/172] make last line of script return a new line been bugging me for awhile --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index d43de697..2d3c4f09 100755 --- a/gravity.sh +++ b/gravity.sh @@ -313,7 +313,7 @@ gravity_reload() { # Reload hosts file echo ":::" - echo -n "::: Refresh lists in dnsmasq..." + echo "::: Refresh lists in dnsmasq..." #ensure /etc/dnsmasq.d/01-pihole.conf is pointing at the correct list! #First escape forward slashes in the path: From dda448e0503eaeb8d95992fbdb3b29dd216c8e4a Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:15:03 -0400 Subject: [PATCH 071/172] use finction in pihole to restart dnsmasq --- gravity.sh | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/gravity.sh b/gravity.sh index 2d3c4f09..d51cc814 100755 --- a/gravity.sh +++ b/gravity.sh @@ -322,23 +322,7 @@ gravity_reload() { # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf find "$piholeDir" -type f -exec chmod 666 {} \; - dnsmasqPid=$(pidof dnsmasq) - - 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 - systemctl start dnsmasq - else - service dnsmasq start - fi - fi + pihole restartdnsmasq } for var in "$@" From 3ca3eaa62cd229dd4ead714af6ad2b4f2f111419 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 09:40:45 -0400 Subject: [PATCH 072/172] change restartdnsmasq to restartdns --- gravity.sh | 2 +- pihole | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index d51cc814..cdcf486c 100755 --- a/gravity.sh +++ b/gravity.sh @@ -322,7 +322,7 @@ gravity_reload() { # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf find "$piholeDir" -type f -exec chmod 666 {} \; - pihole restartdnsmasq + pihole restartdns } for var in "$@" diff --git a/pihole b/pihole index 1651ac9c..bd49f63d 100755 --- a/pihole +++ b/pihole @@ -165,7 +165,7 @@ helpFunc() { echo "::: status Is Pi-Hole Enabled or Disabled" echo "::: enable Enable Pi-Hole DNS Blocking" echo "::: disable Disable Pi-Hole DNS Blocking" - echo "::: restartdnsmasq Restart dnsmasq" + echo "::: restartdns Restart dnsmasq" exit 0 } @@ -191,7 +191,7 @@ case "$1" in "enable" ) piholeEnable 1;; "disable" ) piholeEnable 0;; "status" ) piholeStatus "$2";; -"restartdnsmasq" ) restartDNS;; +"restartdns" ) restartDNS;; * ) helpFunc;; esac From 15d68467a1c082b422d2a8be3d3c23e94afbe5a5 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 10:12:02 -0400 Subject: [PATCH 073/172] attempt to fix --- gravity.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/gravity.sh b/gravity.sh index d4298a31..f4f075ad 100755 --- a/gravity.sh +++ b/gravity.sh @@ -319,13 +319,8 @@ gravity_reload() { #First escape forward slashes in the path: adList=${adList//\//\\\/} #Now replace the line in dnsmasq file -<<<<<<< HEAD # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf -======= - sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf ->>>>>>> upstream/promoTweaksTheSecond - pihole restartdns } From e1c56bcbfec8cd9fd00577e51a9196966ff07ef7 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 10:19:03 -0400 Subject: [PATCH 074/172] remove a commit in whitelist --- advanced/Scripts/whitelist.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index a2e31c8a..2b572d00 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -99,8 +99,6 @@ RemoveDomain(){ fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} - #reload gravity to pickup any entries this may have removed - pihole -g fi } From 9056a5a7b694115fcbdaaa0ba04b3b9f32147cc3 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 11:05:49 -0400 Subject: [PATCH 075/172] fix spelling / replace tabs with spaces in help --- pihole | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pihole b/pihole index bd49f63d..afabe9bb 100755 --- a/pihole +++ b/pihole @@ -128,7 +128,7 @@ piholeEnable() { piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then - if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Diabled"; fi + if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Disabled"; fi else if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then if [[ "${1}" == "web" ]] ; then echo 1; else echo "::: pihole is Enabled"; fi @@ -162,10 +162,10 @@ helpFunc() { echo "::: -v, version Show current versions" echo "::: -q, query Query the adlists for a specific domain" echo "::: uninstall Uninstall Pi-Hole from your system :(!" - echo "::: status Is Pi-Hole Enabled or Disabled" - echo "::: enable Enable Pi-Hole DNS Blocking" - echo "::: disable Disable Pi-Hole DNS Blocking" - echo "::: restartdns Restart dnsmasq" + echo "::: status Is Pi-Hole Enabled or Disabled" + echo "::: enable Enable Pi-Hole DNS Blocking" + echo "::: disable Disable Pi-Hole DNS Blocking" + echo "::: restartdns Restart dnsmasq" exit 0 } From 685b775b680f2724076ae52d997d92651049fdd5 Mon Sep 17 00:00:00 2001 From: Tommy Huff Date: Thu, 20 Oct 2016 11:24:34 -0400 Subject: [PATCH 076/172] rework status if statments --- pihole | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole b/pihole index afabe9bb..29acfe29 100755 --- a/pihole +++ b/pihole @@ -130,10 +130,10 @@ piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Disabled"; fi else - if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then - if [[ "${1}" == "web" ]] ; then echo 1; else echo "::: pihole is Enabled"; fi - else - if [[ "${1}" == "web" ]] ; then echo 1; else + if [[ "${1}" == "web" ]] ; then echo 1; else + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then + echo "::: pihole is Enabled"; + else echo "::: no hosts file linked to dnsmasq, adding it in enabled state" echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf restartDNS From c0012540ed3cf5897b2d4387665248454a7af2a2 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Thu, 20 Oct 2016 21:08:07 +0100 Subject: [PATCH 077/172] Re-add shebang --- 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 a49133fd..bc926495 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1,4 +1,4 @@ -#/usr/bin/env bash +#!/usr/bin/env bash # Pi-hole: A black hole for Internet advertisements # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi From 78fbafa1cd3a2c21ee1cc1b7b9f69017defdff86 Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 18:40:03 -0400 Subject: [PATCH 078/172] test out new status logic --- pihole | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 29acfe29..7d5f59b5 100755 --- a/pihole +++ b/pihole @@ -127,18 +127,30 @@ piholeEnable() { } piholeStatus() { - if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=") ]] ; then - if [[ "${1}" == "web" ]] ; then echo 0; else echo "::: pihole is Disabled"; fi - else - if [[ "${1}" == "web" ]] ; then echo 1; else - if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=") ]] ; then - echo "::: pihole is Enabled"; - else - echo "::: no hosts file linked to dnsmasq, adding it in enabled state" - echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf - restartDNS - fi + if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=/") ]] ; then + #list is commented out + if [[ "${1}" == "web" ]] ; then + echo 0; + else + echo "::: pihole is Disabled"; + fi + elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then + #list set + if [[ "${1}" == "web" ]] ; then + echo 1; + else + echo "::: pihole is Enabled"; fi + else + #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 + echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf + restartDNS fi } From c83dd3ccd7dfafbd6e843b5a99df4b67de8549d7 Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 18:45:27 -0400 Subject: [PATCH 079/172] change spacing --- pihole | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 7d5f59b5..1c7d11e3 100755 --- a/pihole +++ b/pihole @@ -130,25 +130,25 @@ piholeStatus() { if [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "#addn-hosts=/") ]] ; then #list is commented out if [[ "${1}" == "web" ]] ; then - echo 0; - else - echo "::: pihole is Disabled"; + echo 0; + else + echo "::: pihole is Disabled"; fi elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then - #list set - if [[ "${1}" == "web" ]] ; then + #list set + if [[ "${1}" == "web" ]] ; then echo 1; - else - echo "::: pihole is Enabled"; + else + echo "::: pihole is Enabled"; fi else #addn-host not found if [[ "${1}" == "web" ]] ; then - echo 99 - else + echo 99 + else echo "::: no hosts file linked to dnsmasq, adding it in enabled state" - fi - #add addn-host= to dnsmasq + fi + #add addn-host= to dnsmasq echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf restartDNS fi From e199f6db87881ac062a4e31d78a6ba1b3e31841b Mon Sep 17 00:00:00 2001 From: tuplink Date: Thu, 20 Oct 2016 21:15:11 -0400 Subject: [PATCH 080/172] spelling updates --- pihole | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pihole b/pihole index 1c7d11e3..fa5a95f0 100755 --- a/pihole +++ b/pihole @@ -132,21 +132,21 @@ piholeStatus() { if [[ "${1}" == "web" ]] ; then echo 0; else - echo "::: pihole is Disabled"; + echo "::: Pi-hole is Disabled"; fi elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then #list set if [[ "${1}" == "web" ]] ; then echo 1; else - echo "::: pihole is Enabled"; + echo "::: Pi-hole is Enabled"; fi else #addn-host not found if [[ "${1}" == "web" ]] ; then echo 99 else - echo "::: no hosts file linked to dnsmasq, adding it in enabled state" + echo "::: No hosts file linked to dnsmasq, adding it in enabled state" fi #add addn-host= to dnsmasq echo "addn-hosts=/etc/pihole/gravity.list" >> /etc/dnsmasq.d/01-pihole.conf From 5ebfa5ecf749a3bda3f7dc8880855d5a6e9a5e66 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Fri, 21 Oct 2016 22:53:04 -0700 Subject: [PATCH 081/172] heredoc for helpfunc in pihole --- pihole | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/pihole b/pihole index 6be32acf..d9599907 100755 --- a/pihole +++ b/pihole @@ -97,25 +97,27 @@ versionFunc() { } helpFunc() { - echo "::: Control all PiHole specific functions!" - echo ":::" - echo "::: Usage: pihole [options]" - echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" - echo ":::" - echo "::: Options:" - echo "::: -w, whitelist Whitelist domains" - echo "::: -b, blacklist Blacklist domains" - echo "::: -d, debug Start a debugging session if having trouble" - echo "::: -f, flush Flush the pihole.log file" - echo "::: -up, updatePihole Update Pi-hole" - echo "::: -g, updateGravity Update the list of ad-serving domains" - echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it" - echo "::: -c, chronometer Calculates stats and displays to an LCD" - echo "::: -h, help Show this help dialog" - echo "::: -v, version Show current versions" - echo "::: -q, query Query the adlists for a specific domain" - echo "::: uninstall Uninstall Pi-Hole from your system :(!" - exit 0 + cat << EOM +::: Control all PiHole specific functions! +::: +::: Usage: pihole [options] +::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage +::: +::: Options: +::: -w, whitelist Whitelist domains +::: -b, blacklist Blacklist domains +::: -d, debug Start a debugging session if having trouble +::: -f, flush Flush the pihole.log file +::: -up, updatePihole Update Pi-hole +::: -g, updateGravity Update the list of ad-serving domains +::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it +::: -c, chronometer Calculates stats and displays to an LCD +::: -h, help Show this help dialog +::: -v, version Show current versions +::: -q, query Query the adlists for a specific domain +::: uninstall Uninstall Pi-Hole from your system :(! +EOM + exit 1 } if [[ $# = 0 ]]; then From aac8e45397d5a1df246fb6435f7eebb5f6132ca8 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Fri, 21 Oct 2016 23:02:45 -0700 Subject: [PATCH 082/172] Imbue gravity.sh with some consistency Mish-mash of tabs and spaces used for indentation. Mostly tabs though, so going with those. Also indenting blocks and enforcing the loop statement; do done style over the newline for do since it seemed to be more common. --- gravity.sh | 145 ++++++++++++++++++++++++++--------------------------- 1 file changed, 70 insertions(+), 75 deletions(-) diff --git a/gravity.sh b/gravity.sh index 607a5eba..928027e4 100755 --- a/gravity.sh +++ b/gravity.sh @@ -35,11 +35,11 @@ blacklistScript=/opt/pihole/blacklist.sh #Source the setupVars from install script for the IP setupVars=/etc/pihole/setupVars.conf if [[ -f ${setupVars} ]];then - . /etc/pihole/setupVars.conf + . /etc/pihole/setupVars.conf else - echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure." - echo "::: Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure." - exit 1 + echo "::: WARNING: /etc/pihole/setupVars.conf missing. Possible installation failure." + echo "::: Please run 'pihole -r', and choose the 'reconfigure' option to reconfigure." + exit 1 fi #Remove the /* from the end of the IPv4addr. @@ -56,8 +56,8 @@ eventHorizon=${basename}.2.eventHorizon.txt accretionDisc=${basename}.3.accretionDisc.txt # Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it) -if [[ -r ${piholeDir}/pihole.conf ]];then - echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored." +if [[ -r ${piholeDir}/pihole.conf ]]; then + echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored." fi ########################### @@ -95,17 +95,17 @@ gravity_collapse() { fi # Create the pihole resource directory if it doesn't exist. Future files will be stored here - if [[ -d ${piholeDir} ]];then - # Temporary hack to allow non-root access to pihole directory - # Will update later, needed for existing installs, new installs should - # create this directory as non-root - chmod 777 ${piholeDir} - echo ":::" - echo "::: Existing pihole directory found" + if [[ -d ${piholeDir} ]]; then + # Temporary hack to allow non-root access to pihole directory + # Will update later, needed for existing installs, new installs should + # create this directory as non-root + chmod 777 ${piholeDir} + echo ":::" + echo "::: Existing pihole directory found" else - echo "::: Creating pihole directory..." - mkdir ${piholeDir} - chmod 777 ${piholeDir} + echo "::: Creating pihole directory..." + mkdir ${piholeDir} + chmod 777 ${piholeDir} fi } @@ -113,7 +113,7 @@ gravity_collapse() { gravity_patternCheck() { patternBuffer=$1 # check if the patternbuffer is a non-zero length file - if [[ -s "$patternBuffer" ]];then + if [[ -s "$patternBuffer" ]]; then # Some of the blocklists are copyright, they need to be downloaded # and stored as is. They can be processed for content after they # have been saved. @@ -151,36 +151,35 @@ gravity_transport() { gravity_spinup() { echo ":::" # Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines - for ((i = 0; i < "${#sources[@]}"; i++)) - do - url=${sources[$i]} - # Get just the domain from the URL - domain=$(echo "$url" | cut -d'/' -f3) - - # Save the file as list.#.domain - saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension} - activeDomains[$i]=${saveLocation} - - agent="Mozilla/10.0" - - echo -n "::: Getting $domain list..." - - # 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") - 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/" - ;; - - "pgl.yoyo.org") - cmd_ext="-d mimetype=plaintext -d hostformat=hosts" - ;; - - # Default is a simple request - *) cmd_ext="" - esac - gravity_transport "$url" "$cmd_ext" "$agent" + for ((i = 0; i < "${#sources[@]}"; i++)); do + url=${sources[$i]} + # Get just the domain from the URL + domain=$(echo "$url" | cut -d'/' -f3) + + # Save the file as list.#.domain + saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension} + activeDomains[$i]=${saveLocation} + + agent="Mozilla/10.0" + + echo -n "::: Getting $domain list..." + + # 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") + 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/" + ;; + + "pgl.yoyo.org") + cmd_ext="-d mimetype=plaintext -d hostformat=hosts" + ;; + + # Default is a simple request + *) cmd_ext="" + esac + gravity_transport "$url" "$cmd_ext" "$agent" done } @@ -190,8 +189,7 @@ gravity_Schwarzchild() { # Find all active domains and compile them into one file and remove CRs echo -n "::: Aggregating list of domains..." truncate -s 0 ${piholeDir}/${matterAndLight} - for i in "${activeDomains[@]}" - do + for i in "${activeDomains[@]}"; do cat "$i" | tr -d '\r' >> ${piholeDir}/${matterAndLight} done echo " done!" @@ -214,10 +212,9 @@ gravity_Whitelist() { echo -n "::: Adding ${#sources[@]} adlist source${plural} to the whitelist..." urls=() - for url in "${sources[@]}" - do - tmp=$(echo "$url" | awk -F '/' '{print $3}') - urls=("${urls[@]}" ${tmp}) + for url in "${sources[@]}"; do + tmp=$(echo "$url" | awk -F '/' '{print $3}') + urls=("${urls[@]}" ${tmp}) done echo " done!" @@ -248,7 +245,7 @@ gravity_hostFormat() { echo "::: Error: Unable to determine fully qualified domain name of host" fi # If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols - if [[ -n "${IPv6_address}" ]];then + if [[ -n "${IPv6_address}" ]]; then # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) echo -e "$IPv4addr $hostname\n$IPv6_address $hostname\n$IPv4addr pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} @@ -266,8 +263,7 @@ gravity_hostFormat() { # blackbody - remove any remnant files from script processes gravity_blackbody() { # Loop through list files - for file in ${piholeDir}/*.${justDomainsExtension} - do + for file in ${piholeDir}/*.${justDomainsExtension}; do # If list is in active array then leave it (noop) else rm the list if [[ " ${activeDomains[@]} " =~ ${file} ]]; then : @@ -313,32 +309,31 @@ gravity_reload() { sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf find "$piholeDir" -type f -exec chmod 666 {} \; - dnsmasqPid=$(pidof dnsmasq) + dnsmasqPid=$(pidof dnsmasq) if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - if [ -x "$(command -v systemctl)" ]; then - systemctl restart dnsmasq - else - service dnsmasq restart - fi + # 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 - systemctl start dnsmasq - else - service dnsmasq start - fi + # service not running, start it up + if [ -x "$(command -v systemctl)" ]; then + systemctl start dnsmasq + else + service dnsmasq start + fi fi } -for var in "$@" -do - case "$var" in - "-f" | "--force" ) forceGrav=true;; - "-h" | "--help" ) helpFunc;; - esac +for var in "$@"; do + case "$var" in + "-f" | "--force" ) forceGrav=true;; + "-h" | "--help" ) helpFunc;; + esac done if [[ ${forceGrav} == true ]]; then From ebbe1fc236baf9cbd03d7c64631748543fac9dbb Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Fri, 21 Oct 2016 23:11:17 -0700 Subject: [PATCH 083/172] More consistency Odd mix of variables quoted with and without no-op parameter expansion (i.e. ${thing}) More ${thing} than not, make that the standard --- gravity.sh | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/gravity.sh b/gravity.sh index 928027e4..da1009e6 100755 --- a/gravity.sh +++ b/gravity.sh @@ -113,11 +113,11 @@ gravity_collapse() { gravity_patternCheck() { patternBuffer=$1 # check if the patternbuffer is a non-zero length file - if [[ -s "$patternBuffer" ]]; then + if [[ -s "${patternBuffer}" ]]; then # Some of the blocklists are copyright, they need to be downloaded # and stored as is. They can be processed for content after they # have been saved. - cp "$patternBuffer" "$saveLocation" + cp "${patternBuffer}" "${saveLocation}" echo " List updated, transport successful!" else # curl didn't download any host files, probably because of the date check @@ -136,15 +136,15 @@ gravity_transport() { heisenbergCompensator="" if [[ -r ${saveLocation} ]]; then # if domain has been saved, add file for date check to only download newer - heisenbergCompensator="-z $saveLocation" + heisenbergCompensator="-z ${saveLocation}" fi # Silently curl url - curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "$agent" ${url} > ${patternBuffer} + curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "${agent}" ${url} > ${patternBuffer} # Check for list updates - gravity_patternCheck "$patternBuffer" + gravity_patternCheck "${patternBuffer}" # Cleanup - rm -f "$patternBuffer" + rm -f "${patternBuffer}" } # spinup - main gravity function @@ -154,7 +154,7 @@ gravity_spinup() { for ((i = 0; i < "${#sources[@]}"; i++)); do url=${sources[$i]} # Get just the domain from the URL - domain=$(echo "$url" | cut -d'/' -f3) + domain=$(echo "${url}" | cut -d'/' -f3) # Save the file as list.#.domain saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension} @@ -162,11 +162,11 @@ gravity_spinup() { agent="Mozilla/10.0" - echo -n "::: Getting $domain list..." + echo -n "::: Getting ${domain} list..." # 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 + case "${domain}" in "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/" @@ -179,7 +179,7 @@ gravity_spinup() { # Default is a simple request *) cmd_ext="" esac - gravity_transport "$url" "$cmd_ext" "$agent" + gravity_transport "${url}" "${cmd_ext}" "${agent}" done } @@ -190,7 +190,7 @@ gravity_Schwarzchild() { echo -n "::: Aggregating list of domains..." truncate -s 0 ${piholeDir}/${matterAndLight} for i in "${activeDomains[@]}"; do - cat "$i" | tr -d '\r' >> ${piholeDir}/${matterAndLight} + cat "${i}" | tr -d '\r' >> ${piholeDir}/${matterAndLight} done echo " done!" } @@ -201,8 +201,8 @@ gravity_Blacklist() { ${blacklistScript} -f -nr -q > /dev/null numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt") - plural=; [[ "$numBlacklisted" != "1" ]] && plural=s - echo " $numBlacklisted domain${plural} blacklisted!" + plural=; [[ "${numBlacklisted}" != "1" ]] && plural=s + echo " ${numBlacklisted} domain${plural} blacklisted!" } gravity_Whitelist() { @@ -213,7 +213,7 @@ gravity_Whitelist() { urls=() for url in "${sources[@]}"; do - tmp=$(echo "$url" | awk -F '/' '{print $3}') + tmp=$(echo "${url}" | awk -F '/' '{print $3}') urls=("${urls[@]}" ${tmp}) done echo " done!" @@ -221,8 +221,8 @@ gravity_Whitelist() { echo -n "::: Running whitelist script to update HOSTS file...." ${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") - plural=; [[ "$numWhitelisted" != "1" ]] && plural=s - echo " $numWhitelisted domain${plural} whitelisted!" + plural=; [[ "${numWhitelisted}" != "1" ]] && plural=s + echo " ${numWhitelisted} domain${plural} whitelisted!" } gravity_unique() { @@ -231,7 +231,7 @@ gravity_unique() { sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon} echo " done!" numberOf=$(wc -l < ${piholeDir}/${eventHorizon}) - echo "::: $numberOf unique domains trapped in the event horizon." + echo "::: ${numberOf} unique domains trapped in the event horizon." } gravity_hostFormat() { @@ -247,13 +247,13 @@ gravity_hostFormat() { # If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols if [[ -n "${IPv6_address}" ]]; then # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) - echo -e "$IPv4addr $hostname\n$IPv6_address $hostname\n$IPv4addr pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} - cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} + echo -e "${IPv4addr} ${hostname}\n${IPv6_address} ${hostname}\n${IPv4addr} pi.hole\n${IPv6_address} pi.hole" > ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="${IPv4addr}" -v ipv6addr="${IPv6_address}" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} else # Otherwise, just create gravity.list as normal using IPv4 # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) - echo -e "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc} - cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} + echo -e "${IPv4addr} ${hostname}\n${IPv4addr} pi.hole" > ${piholeDir}/${accretionDisc} + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="${IPv4addr}" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} fi # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it @@ -268,7 +268,7 @@ gravity_blackbody() { if [[ " ${activeDomains[@]} " =~ ${file} ]]; then : else - rm -f "$file" + rm -f "${file}" fi done } @@ -286,7 +286,7 @@ gravity_advanced() { echo " done!" numberOf=$(wc -l < ${piholeDir}/${supernova}) - echo "::: $numberOf domains being pulled in by gravity..." + echo "::: ${numberOf} domains being pulled in by gravity..." gravity_unique } @@ -306,8 +306,8 @@ gravity_reload() { #First escape forward slashes in the path: adList=${adList//\//\\\/} #Now replace the line in dnsmasq file - sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf - find "$piholeDir" -type f -exec chmod 666 {} \; + sed -i "s/^addn-hosts.*/addn-hosts=${adList}/" /etc/dnsmasq.d/01-pihole.conf + find "${piholeDir}" -type f -exec chmod 666 {} \; dnsmasqPid=$(pidof dnsmasq) @@ -330,7 +330,7 @@ gravity_reload() { for var in "$@"; do - case "$var" in + case "${var}" in "-f" | "--force" ) forceGrav=true;; "-h" | "--help" ) helpFunc;; esac From 640398ced46475ad8d67621a9fdc2465dedb51c6 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Fri, 21 Oct 2016 23:17:14 -0700 Subject: [PATCH 084/172] Consistency We went with tabs earlier, may as well make that the "standard". Easy enough to switch to spaces too if that's desired with expand(1) --- pihole | 121 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/pihole b/pihole index d9599907..42a390f2 100755 --- a/pihole +++ b/pihole @@ -12,88 +12,87 @@ # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then - if [ -x "$(command -v sudo)" ];then - exec sudo bash "$0" "$@" - exit $? - else - echo "::: sudo is needed to run pihole commands. Please run this script as root or install sudo." - exit 1 - fi + if [ -x "$(command -v sudo)" ];then + exec sudo bash "$0" "$@" + exit $? + else + echo "::: sudo is needed to run pihole commands. Please run this script as root or install sudo." + exit 1 + fi fi whitelistFunc() { - shift - /opt/pihole/whitelist.sh "$@" - exit 0 + shift + /opt/pihole/whitelist.sh "$@" + exit 0 } blacklistFunc() { - shift - /opt/pihole/blacklist.sh "$@" - exit 0 + shift + /opt/pihole/blacklist.sh "$@" + exit 0 } debugFunc() { - /opt/pihole/piholeDebug.sh - exit 0 + /opt/pihole/piholeDebug.sh + exit 0 } flushFunc() { - /opt/pihole/piholeLogFlush.sh - exit 0 + /opt/pihole/piholeLogFlush.sh + exit 0 } updatePiholeFunc() { - /opt/pihole/update.sh - exit 0 + /opt/pihole/update.sh + exit 0 } reconfigurePiholeFunc() { - /etc/.pihole/automated\ install/basic-install.sh --reconfigure - exit 0; + /etc/.pihole/automated\ install/basic-install.sh --reconfigure + exit 0; } updateGravityFunc() { - /opt/pihole/gravity.sh "$@" - exit 0 + /opt/pihole/gravity.sh "$@" + exit 0 } setupLCDFunction() { - /opt/pihole/setupLCD.sh - exit 0 + /opt/pihole/setupLCD.sh + exit 0 } queryFunc() { - domain=$2 - for list in /etc/pihole/list.* - do - count=$(grep ${domain} $list | wc -l) - echo "::: ${list} (${count} results)" - if [[ ${count} > 0 ]]; then - grep ${domain} ${list} - fi - echo "" - done - exit 0 + domain=$2 + for list in /etc/pihole/list.*; do + count=$(grep ${domain} $list | wc -l) + echo "::: ${list} (${count} results)" + if [[ ${count} > 0 ]]; then + grep ${domain} ${list} + fi + echo "" + done + exit 0 } chronometerFunc() { - shift - /opt/pihole/chronometer.sh "$@" - exit 0 + shift + /opt/pihole/chronometer.sh "$@" + exit 0 } uninstallFunc() { - /opt/pihole/uninstall.sh - exit 0 + /opt/pihole/uninstall.sh + exit 0 } versionFunc() { - shift - /opt/pihole/version.sh "$@" - exit 0 + shift + /opt/pihole/version.sh "$@" + exit 0 } helpFunc() { @@ -117,27 +116,27 @@ helpFunc() { ::: -q, query Query the adlists for a specific domain ::: uninstall Uninstall Pi-Hole from your system :(! EOM - exit 1 + exit 1 } if [[ $# = 0 ]]; then - helpFunc + helpFunc fi # Handle redirecting to specific functions based on arguments -case "$1" in -"-w" | "whitelist" ) whitelistFunc "$@";; -"-b" | "blacklist" ) blacklistFunc "$@";; -"-d" | "debug" ) debugFunc;; -"-f" | "flush" ) flushFunc;; -"-up" | "updatePihole" ) updatePiholeFunc;; -"-r" | "reconfigure" ) reconfigurePiholeFunc;; -"-g" | "updateGravity" ) updateGravityFunc "$@";; -"-s" | "setupLCD" ) setupLCDFunction;; -"-c" | "chronometer" ) chronometerFunc "$@";; -"-h" | "help" ) helpFunc;; -"-v" | "version" ) versionFunc "$@";; -"-q" | "query" ) queryFunc "$@";; -"uninstall" ) uninstallFunc;; -* ) helpFunc;; +case "${1}" in + "-w" | "whitelist" ) whitelistFunc "$@";; + "-b" | "blacklist" ) blacklistFunc "$@";; + "-d" | "debug" ) debugFunc;; + "-f" | "flush" ) flushFunc;; + "-up" | "updatePihole" ) updatePiholeFunc;; + "-r" | "reconfigure" ) reconfigurePiholeFunc;; + "-g" | "updateGravity" ) updateGravityFunc "$@";; + "-s" | "setupLCD" ) setupLCDFunction;; + "-c" | "chronometer" ) chronometerFunc "$@";; + "-h" | "help" ) helpFunc;; + "-v" | "version" ) versionFunc "$@";; + "-q" | "query" ) queryFunc "$@";; + "uninstall" ) uninstallFunc;; + * ) helpFunc;; esac From 7ebaf8e8437ef7e16cbda410a14c9715367fadae Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Fri, 21 Oct 2016 23:23:31 -0700 Subject: [PATCH 085/172] Consistency Now with block indents! --- automated install/uninstall.sh | 56 +++++++++++++++++----------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index b7d82ef9..98da8e28 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -11,29 +11,29 @@ # (at your option) any later version. # Must be root to uninstall -if [[ $EUID -eq 0 ]];then +if [[ ${EUID} -eq 0 ]]; then echo "::: You are root." else echo "::: Sudo will be used for the uninstall." - # Check if it is actually installed - # If it isn't, exit because the unnstall cannot complete - if [ -x "$(command -v sudo)" ];then + # Check if it is actually installed + # If it isn't, exit because the unnstall cannot complete + if [ -x "$(command -v sudo)" ]; then export SUDO="sudo" - else - echo "::: Please install sudo or run this as root." - exit 1 - fi + else + echo "::: Please install sudo or run this as root." + exit 1 + fi fi # Compatability -if [ -x "$(command -v rpm)" ];then +if [ -x "$(command -v rpm)" ]; then # Fedora Family - if [ -x "$(command -v dnf)" ];then + if [ -x "$(command -v dnf)" ]; then PKG_MANAGER="dnf" else PKG_MANAGER="yum" fi - PKG_REMOVE="$PKG_MANAGER remove -y" + PKG_REMOVE="${PKG_MANAGER} remove -y" PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common git curl unzip wget findutils ) package_check() { rpm -qa | grep ^$1- > /dev/null @@ -41,10 +41,10 @@ if [ -x "$(command -v rpm)" ];then package_cleanup() { ${SUDO} ${PKG_MANAGER} -y autoremove } -elif [ -x "$(command -v apt-get)" ];then +elif [ -x "$(command -v apt-get)" ]; then # Debian Family PKG_MANAGER="apt-get" - PKG_REMOVE="$PKG_MANAGER -y remove --purge" + PKG_REMOVE="${PKG_MANAGER} -y remove --purge" PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common git curl unzip wget ) package_check() { dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" @@ -59,17 +59,17 @@ else fi spinner() { - local pid=$1 - local delay=0.50 - local spinstr='/-\|' - while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do - local temp=${spinstr#?} - printf " [%c] " "$spinstr" - local spinstr=${temp}${spinstr%"$temp"} - sleep ${delay} - printf "\b\b\b\b\b\b" - done - printf " \b\b\b\b" + local pid=$1 + local delay=0.50 + local spinstr='/-\|' + while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do + local temp=${spinstr#?} + printf " [%c] " "${spinstr}" + local spinstr=${temp}${spinstr%"${temp}"} + sleep ${delay} + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" } removeAndPurge() { @@ -79,15 +79,15 @@ removeAndPurge() { package_check ${i} > /dev/null if [ $? -eq 0 ]; then while true; do - read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn + read -rp "::: Do you wish to remove ${i} from your system? [y/n]: " yn case ${yn} in - [Yy]* ) printf ":::\tRemoving %s..." "$i"; ${SUDO} ${PKG_REMOVE} "$i" &> /dev/null & spinner $!; printf "done!\n"; break;; - [Nn]* ) printf ":::\tSkipping %s" "$i\n"; break;; + [Yy]* ) printf ":::\tRemoving %s..." "${i}"; ${SUDO} ${PKG_REMOVE} "${i}" &> /dev/null & spinner $!; printf "done!\n"; break;; + [Nn]* ) printf ":::\tSkipping %s" "${i}\n"; break;; * ) printf "::: You must answer yes or no!\n";; esac done else - printf ":::\tPackage %s not installed... Not removing.\n" "$i" + printf ":::\tPackage %s not installed... Not removing.\n" "${i}" fi done From 21b906e0e034f57a8a300522a1d6db5e11311bdb Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Fri, 21 Oct 2016 23:57:47 -0700 Subject: [PATCH 086/172] Consistency More of the same --- automated install/basic-install.sh | 728 ++++++++++++++--------------- 1 file changed, 362 insertions(+), 366 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index af3ab962..7796fb52 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -48,18 +48,19 @@ runUnattended=false ######## FIRST CHECK ######## # Must be root to install echo ":::" -if [[ $EUID -eq 0 ]];then +if [[ ${EUID} -eq 0 ]]; then echo "::: You are root." else - echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures" - echo "::: system networking, it requires elevated rights. Please check the contents of the script for" - echo "::: any concerns with this requirement. Please be sure to download this script from a trusted source." - echo ":::" - echo "::: Detecting the presence of the sudo utility for continuation of this install..." - if [ -x "$(command -v sudo)" ];then + echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures" + echo "::: system networking, it requires elevated rights. Please check the contents of the script for" + echo "::: any concerns with this requirement. Please be sure to download this script from a trusted source." + echo ":::" + echo "::: Detecting the presence of the sudo utility for continuation of this install..." + + if [ -x "$(command -v sudo)" ]; then echo "::: Utility sudo located." - exec curl -sSL https://install.pi-hole.net | sudo bash "$@" - exit $? + exec curl -sSL https://install.pi-hole.net | sudo bash "$@" + exit $? else echo "::: sudo is needed for the Web interface to run pihole commands. Please run this script as root and it will be automatically installed." exit 1 @@ -68,7 +69,7 @@ fi # Compatibility -if [ -x "$(command -v apt-get)" ];then +if [ -x "$(command -v apt-get)" ]; then #Debian Family #Decide if php should be `php5` or just `php` (Fixes issues with Ubuntu 16.04 LTS) phpVer="php5" @@ -76,11 +77,11 @@ if [ -x "$(command -v apt-get)" ];then ############################################# PKG_MANAGER="apt-get" PKG_CACHE="/var/lib/apt/lists/" - UPDATE_PKG_CACHE="$PKG_MANAGER update" - PKG_UPDATE="$PKG_MANAGER upgrade" - PKG_INSTALL="$PKG_MANAGER --yes --fix-missing install" + UPDATE_PKG_CACHE="${PKG_MANAGER} update" + PKG_UPDATE="${PKG_MANAGER} upgrade" + PKG_INSTALL="${PKG_MANAGER} --yes --fix-missing 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" + PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" INSTALLER_DEPS=( apt-utils whiptail git dhcpcd5) PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron iproute2 ) LIGHTTPD_USER="www-data" @@ -88,20 +89,20 @@ if [ -x "$(command -v apt-get)" ];then LIGHTTPD_CFG="lighttpd.conf.debian" DNSMASQ_USER="dnsmasq" package_check_install() { - dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "$1" + dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}" } -elif [ -x "$(command -v rpm)" ];then +elif [ -x "$(command -v rpm)" ]; then # Fedora Family - if [ -x "$(command -v dnf)" ];then + if [ -x "$(command -v dnf)" ]; then PKG_MANAGER="dnf" else PKG_MANAGER="yum" fi - PKG_CACHE="/var/cache/$PKG_MANAGER" - UPDATE_PKG_CACHE="$PKG_MANAGER check-update" - PKG_UPDATE="$PKG_MANAGER update -y" - PKG_INSTALL="$PKG_MANAGER install -y" - PKG_COUNT="$PKG_MANAGER check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" + PKG_CACHE="/var/cache/${PKG_MANAGER}" + UPDATE_PKG_CACHE="${PKG_MANAGER} check-update" + PKG_UPDATE="${PKG_MANAGER} update -y" + PKG_INSTALL="${PKG_MANAGER} install -y" + PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" INSTALLER_DEPS=( iproute net-tools procps-ng newt git ) PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat ) if grep -q 'Fedora' /etc/redhat-release; then @@ -113,7 +114,7 @@ elif [ -x "$(command -v rpm)" ];then LIGHTTPD_CFG="lighttpd.conf.fedora" DNSMASQ_USER="nobody" package_check_install() { - rpm -qa | grep ^"$1"- > /dev/null || ${PKG_INSTALL} "$1" + rpm -qa | grep ^"${1}"- > /dev/null || ${PKG_INSTALL} "${1}" } else echo "OS distribution not supported" @@ -123,16 +124,16 @@ fi ####### FUNCTIONS ########## spinner() { local pid=$1 - local delay=0.50 - local spinstr='/-\|' - while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local delay=0.50 + local spinstr='/-\|' + while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do local temp=${spinstr#?} - printf " [%c] " "$spinstr" - local spinstr=${temp}${spinstr%"$temp"} - sleep ${delay} - printf "\b\b\b\b\b\b" - done - printf " \b\b\b\b" + printf " [%c] " "${spinstr}" + local spinstr=${temp}${spinstr%"$temp"} + sleep ${delay} + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" } find_IPv4_information() { @@ -143,7 +144,7 @@ find_IPv4_information() { } get_available_interfaces() { - # Get available interfaces. Consider only getting UP interfaces in the future, and leaving DOWN interfaces out of list. + # Get available interfaces. Consider only getting UP interfaces in the future, and leaving DOWN interfaces out of list. availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1 | cut -d'@' -f1) } @@ -170,21 +171,21 @@ verifyFreeDiskSpace() { local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') # - Unknown free disk space , not a integer - if ! [[ "$existing_free_kilobytes" =~ ^([0-9])+$ ]]; then - echo "::: Unknown free disk space!" - echo "::: We were unable to determine available free disk space on this system." - echo "::: You may override this check and force the installation, however, it is not recommended" - echo "::: To do so, pass the argument '--i_do_not_follow_recommendations' to the install script" - echo "::: eg. curl -L https://install.pi-hole.net | bash /dev/stdin --i_do_not_follow_recommendations" - exit 1 + if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then + echo "::: Unknown free disk space!" + echo "::: We were unable to determine available free disk space on this system." + echo "::: You may override this check and force the installation, however, it is not recommended" + echo "::: To do so, pass the argument '--i_do_not_follow_recommendations' to the install script" + echo "::: eg. curl -L https://install.pi-hole.net | bash /dev/stdin --i_do_not_follow_recommendations" + exit 1 # - Insufficient free disk space elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then - echo "::: Insufficient Disk Space!" - echo "::: Your system appears to be low on disk space. pi-hole recommends a minimum of $required_free_kilobytes KiloBytes." - echo "::: You only have $existing_free_kilobytes KiloBytes free." - echo "::: If this is a new install you may need to expand your disk." - echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'" - echo "::: After rebooting, run this installation again. (curl -L https://install.pi-hole.net | bash)" + echo "::: Insufficient Disk Space!" + echo "::: Your system appears to be low on disk space. pi-hole recommends a minimum of $required_free_kilobytes KiloBytes." + echo "::: You only have ${existing_free_kilobytes} KiloBytes free." + echo "::: If this is a new install you may need to expand your disk." + echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'" + echo "::: After rebooting, run this installation again. (curl -L https://install.pi-hole.net | bash)" echo "Insufficient free space, exiting..." exit 1 @@ -206,23 +207,21 @@ chooseInterface() { # Loop sentinel variable local firstLoop=1 - while read -r line - do + while read -r line; do mode="OFF" if [[ ${firstLoop} -eq 1 ]]; then firstLoop=0 mode="ON" fi - interfacesArray+=("$line" "available" "$mode") - done <<< "$availableInterfaces" + interfacesArray+=("${line}" "available" "${mode}") + done <<< "${availableInterfaces}" # Find out how many interfaces are available to choose from - interfaceCount=$(echo "$availableInterfaces" | wc -l) + interfaceCount=$(echo "${availableInterfaces}" | wc -l) chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount}) chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) if [[ $? = 0 ]]; then - for desiredInterface in ${chooseInterfaceOptions} - do + for desiredInterface in ${chooseInterfaceOptions}; do piholeInterface=${desiredInterface} echo "::: Using interface: $piholeInterface" done @@ -256,15 +255,15 @@ use4andor6() { esac done if [[ ${useIPv4} ]]; then - find_IPv4_information - getStaticIPv4Settings - setStaticIPv4 + find_IPv4_information + getStaticIPv4Settings + setStaticIPv4 fi if [[ ${useIPv6} ]]; then - useIPv6dialog - fi - echo "::: IPv4 address: ${IPv4_address}" - echo "::: IPv6 address: ${IPv6_address}" + useIPv6dialog + fi + echo "::: IPv4 address: ${IPv4_address}" + echo "::: IPv6 address: ${IPv6_address}" if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then echo "::: Cannot continue, neither IPv4 or IPv6 selected" echo "::: Exiting" @@ -279,8 +278,8 @@ use4andor6() { getStaticIPv4Settings() { # Ask if the user wants to use DHCP settings as their static IP if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? - IP address: $IPv4_address - Gateway: $IPv4gw" ${r} ${c}); then + IP address: ${IPv4_address} + Gateway: ${IPv4gw}" ${r} ${c}); then # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. @@ -290,20 +289,19 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Otherwise, we need to ask the user to input their desired settings. # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) # Start a loop to let the user enter their information with the chance to go back and edit it if necessary - until [[ ${ipSettingsCorrect} = True ]] - do + until [[ ${ipSettingsCorrect} = True ]]; do # Ask for the IPv4 address - IPv4_address=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "$IPv4_address" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]];then - echo "::: Your static IPv4 address: $IPv4_address" + IPv4_address=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4_address}" 3>&1 1>&2 2>&3) + if [[ $? = 0 ]]; then + echo "::: Your static IPv4 address: ${IPv4_address}" # Ask for the gateway - IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "$IPv4gw" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]];then - echo "::: Your static IPv4 gateway: $IPv4gw" + IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3) + if [[ $? = 0 ]]; then + echo "::: Your static IPv4 gateway: ${IPv4gw}" # Give the user a chance to review their settings before moving on if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? - IP address: $IPv4_address - Gateway: $IPv4gw" ${r} ${c}); then + IP address: ${IPv4_address} + Gateway: ${IPv4gw}" ${r} ${c}); then # After that's done, the loop ends and we move on ipSettingsCorrect=True else @@ -329,31 +327,31 @@ It is also possible to use a DHCP reservation, but if you are going to do that, setDHCPCD() { # Append these lines to dhcpcd.conf to enable a static IP - echo "## interface $piholeInterface - static ip_address=$IPv4_address - static routers=$IPv4gw - static domain_name_servers=$IPv4gw" | tee -a /etc/dhcpcd.conf >/dev/null + echo "## interface ${piholeInterface} + static ip_address=${IPv4_address} + static routers=${IPv4gw} + static domain_name_servers=${IPv4gw}" | tee -a /etc/dhcpcd.conf >/dev/null } setStaticIPv4() { - local IFCFG_FILE - local IPADDR - local CIDR - if [[ -f /etc/dhcpcd.conf ]];then + local IFCFG_FILE + local IPADDR + local CIDR + if [[ -f /etc/dhcpcd.conf ]]; then # Debian Family - if grep -q "$IPv4_address" /etc/dhcpcd.conf; then + if grep -q "${IPv4_address}" /etc/dhcpcd.conf; then echo "::: Static IP already configured" else setDHCPCD - ip addr replace dev "$piholeInterface" "$IPv4_address" + ip addr replace dev "${piholeInterface}" "${IPv4_address}" echo ":::" - echo "::: Setting IP to $IPv4_address. You may need to restart after the install is complete." + echo "::: Setting IP to ${IPv4_address}. You may need to restart after the install is complete." echo ":::" fi elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${piholeInterface} ]];then # Fedora Family IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${piholeInterface} - if grep -q "$IPv4_address" "${IFCFG_FILE}"; then + if grep -q "${IPv4_address}" "${IFCFG_FILE}"; then echo "::: Static IP already configured" else IPADDR=$(echo "${IPv4_address}" | cut -f1 -d/) @@ -362,18 +360,18 @@ setStaticIPv4() { cp "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig # Build Interface configuration file: { - echo "# Configured via Pi-Hole installer" - echo "DEVICE=$piholeInterface" - echo "BOOTPROTO=none" - echo "ONBOOT=yes" - echo "IPADDR=$IPADDR" - echo "PREFIX=$CIDR" - echo "GATEWAY=$IPv4gw" - echo "DNS1=$piholeDNS1" - echo "DNS2=$piholeDNS2" - echo "USERCTL=no" + echo "# Configured via Pi-Hole installer" + echo "DEVICE=$piholeInterface" + echo "BOOTPROTO=none" + echo "ONBOOT=yes" + echo "IPADDR=$IPADDR" + echo "PREFIX=$CIDR" + echo "GATEWAY=$IPv4gw" + echo "DNS1=$piholeDNS1" + echo "DNS2=$piholeDNS2" + echo "USERCTL=no" }>> "${IFCFG_FILE}" - ip addr replace dev "$piholeInterface" "$IPv4_address" + ip addr replace dev "${piholeInterface}" "${IPv4_address}" if [ -x "$(command -v nmcli)" ];then # Tell NetworkManager to read our new sysconfig file nmcli con load "${IFCFG_FILE}" > /dev/null @@ -389,8 +387,8 @@ setStaticIPv4() { } valid_ip() { - local ip=$1 - local stat=1 + local ip=${1} + local stat=1 if [[ ${ip} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then OIFS=$IFS @@ -415,80 +413,80 @@ setDNS() { DNSchoices=$("${DNSChooseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) if [[ $? = 0 ]];then case ${DNSchoices} in - Google) - echo "::: Using Google DNS servers." - piholeDNS1="8.8.8.8" - piholeDNS2="8.8.4.4" - ;; - OpenDNS) - echo "::: Using OpenDNS servers." - piholeDNS1="208.67.222.222" - piholeDNS2="208.67.220.220" - ;; - Level3) - echo "::: Using Level3 servers." - piholeDNS1="4.2.2.1" - piholeDNS2="4.2.2.2" - ;; - Norton) - echo "::: Using Norton ConnectSafe servers." - piholeDNS1="199.85.126.10" - piholeDNS2="199.85.127.10" - ;; - Comodo) - echo "::: Using Comodo Secure servers." - piholeDNS1="8.26.56.26" - piholeDNS2="8.20.247.20" - ;; - Custom) - until [[ ${DNSSettingsCorrect} = True ]] - do - strInvalid="Invalid" - if [ ! ${piholeDNS1} ]; then - if [ ! ${piholeDNS2} ]; then - prePopulate="" - else - prePopulate=", $piholeDNS2" - fi - elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then - prePopulate="$piholeDNS1" - elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then - prePopulate="$piholeDNS1, $piholeDNS2" - fi - piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "$prePopulate" 3>&1 1>&2 2>&3) - if [[ $? = 0 ]];then - piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') - piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') - if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then - piholeDNS1=${strInvalid} - fi - if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then - piholeDNS2=${strInvalid} - fi - else - echo "::: Cancel selected, exiting...." - exit 1 - fi - if [[ ${piholeDNS1} == "$strInvalid" ]] || [[ ${piholeDNS2} == "$strInvalid" ]]; then - whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" ${r} ${c} - if [[ ${piholeDNS1} == "$strInvalid" ]]; then - piholeDNS1="" - fi - if [[ ${piholeDNS2} == "$strInvalid" ]]; then - piholeDNS2="" - fi - DNSSettingsCorrect=False - else - if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" ${r} ${c}); then - DNSSettingsCorrect=True - else - # If the settings are wrong, the loop continues - DNSSettingsCorrect=False - fi - fi - done - ;; - esac + Google) + echo "::: Using Google DNS servers." + piholeDNS1="8.8.8.8" + piholeDNS2="8.8.4.4" + ;; + OpenDNS) + echo "::: Using OpenDNS servers." + piholeDNS1="208.67.222.222" + piholeDNS2="208.67.220.220" + ;; + Level3) + echo "::: Using Level3 servers." + piholeDNS1="4.2.2.1" + piholeDNS2="4.2.2.2" + ;; + Norton) + echo "::: Using Norton ConnectSafe servers." + piholeDNS1="199.85.126.10" + piholeDNS2="199.85.127.10" + ;; + Comodo) + echo "::: Using Comodo Secure servers." + piholeDNS1="8.26.56.26" + piholeDNS2="8.20.247.20" + ;; + Custom) + until [[ ${DNSSettingsCorrect} = True ]]; do + strInvalid="Invalid" + if [ ! ${piholeDNS1} ]; then + if [ ! ${piholeDNS2} ]; then + prePopulate="" + else + prePopulate=", ${piholeDNS2}" + fi + elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then + prePopulate="${piholeDNS1}" + elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then + prePopulate="${piholeDNS1}, ${piholeDNS2}" + fi + + piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "${prePopulate}" 3>&1 1>&2 2>&3) + + if [[ $? = 0 ]]; then + piholeDNS1=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') + piholeDNS2=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') + if ! valid_ip "${piholeDNS1}" || [ ! "${piholeDNS1}" ]; then + piholeDNS1=${strInvalid} + fi + if ! valid_ip "${piholeDNS2}" && [ "${piholeDNS2}" ]; then + piholeDNS2=${strInvalid} + fi + else + echo "::: Cancel selected, exiting...." + exit 1 + fi + if [[ ${piholeDNS1} == "${strInvalid}" ]] || [[ ${piholeDNS2} == "${strInvalid}" ]]; then + whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: ${piholeDNS2}" ${r} ${c} if [[ ${piholeDNS1} == "${strInvalid}" ]]; then + piholeDNS1="" + fi + if [[ ${piholeDNS2} == "${strInvalid}" ]]; then + piholeDNS2="" + fi + DNSSettingsCorrect=False + else + if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: ${piholeDNS2}" ${r} ${c}); then + DNSSettingsCorrect=True + else + # If the settings are wrong, the loop continues + DNSSettingsCorrect=False + fi + fi + done + ;; + esac else echo "::: Cancel selected. Exiting..." exit 1 @@ -527,12 +525,12 @@ version_check_dnsmasq() { cp ${dnsmasq_pihole_01_snippet} ${dnsmasq_pihole_01_location} echo " done." sed -i "s/@INT@/$piholeInterface/" ${dnsmasq_pihole_01_location} - if [[ "$piholeDNS1" != "" ]]; then + if [[ "${piholeDNS1}" != "" ]]; then sed -i "s/@DNS1@/$piholeDNS1/" ${dnsmasq_pihole_01_location} else sed -i '/^server=@DNS1@/d' ${dnsmasq_pihole_01_location} fi - if [[ "$piholeDNS2" != "" ]]; then + if [[ "${piholeDNS2}" != "" ]]; then sed -i "s/@DNS2@/$piholeDNS2/" ${dnsmasq_pihole_01_location} else sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location} @@ -573,7 +571,7 @@ installConfigs() { version_check_dnsmasq if [ ! -d "/etc/lighttpd" ]; then mkdir /etc/lighttpd - chown "$USER":root /etc/lighttpd + chown "${USER}":root /etc/lighttpd mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig fi cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf @@ -597,8 +595,8 @@ stop_service() { } start_service() { - # Start/Restart service passed in as argument - # This should not fail, it's an error if it does + # Start/Restart service passed in as argument + # This should not fail, it's an error if it does echo ":::" echo -n "::: Starting ${1} service..." if [ -x "$(command -v systemctl)" ]; then @@ -610,7 +608,7 @@ start_service() { } enable_service() { - # Enable service so that it will start with next reboot + # Enable service so that it will start with next reboot echo ":::" echo -n "::: Enabling ${1} service to start on reboot..." if [ -x "$(command -v systemctl)" ]; then @@ -628,13 +626,13 @@ update_pacakge_cache() { #Check to see if apt-get update has already been run today #it needs to have been run at least once on new installs! timestamp=$(stat -c %Y ${PKG_CACHE}) - timestampAsDate=$(date -d @"$timestamp" "+%b %e") + timestampAsDate=$(date -d @"${timestamp}" "+%b %e") today=$(date "+%b %e") - if [ ! "$today" == "$timestampAsDate" ]; then + if [ ! "${today}" == "${timestampAsDate}" ]; then #update package lists echo ":::" - echo -n "::: $PKG_MANAGER update has not been run today. Running now..." + echo -n "::: ${PKG_MANAGER} update has not been run today. Running now..." ${UPDATE_PKG_CACHE} &> /dev/null & spinner $! echo " done!" fi @@ -644,23 +642,23 @@ notify_package_updates_available() { # Let user know if they have outdated packages on their system and # advise them to run a package update at soonest possible. echo ":::" - echo -n "::: Checking $PKG_MANAGER for upgraded packages...." + echo -n "::: Checking ${PKG_MANAGER} for upgraded packages...." updatesToInstall=$(eval "${PKG_COUNT}") echo " done!" echo ":::" if [[ ${updatesToInstall} -eq "0" ]]; then echo "::: Your system is up to date! Continuing with Pi-hole installation..." else - echo "::: There are $updatesToInstall updates available for your system!" - echo "::: We recommend you run '$PKG_UPDATE' after installing Pi-Hole! " + echo "::: There are ${updatesToInstall} updates available for your system!" + echo "::: We recommend you run '${PKG_UPDATE}' after installing Pi-Hole! " echo ":::" fi } install_dependent_packages() { - # Install packages passed in via argument array - # No spinner - conflicts with set -e - declare -a argArray1=("${!1}") + # Install packages passed in via argument array + # No spinner - conflicts with set -e + declare -a argArray1=("${!1}") for i in "${argArray1[@]}"; do echo -n "::: Checking for $i..." @@ -678,37 +676,37 @@ getGitFiles() { update_repo "${1}" else make_repo "${1}" "${2}" - fi + fi } is_repo() { - # Use git to check if directory is currently under VCS + # Use git to check if directory is currently under VCS echo -n "::: Checking $1 is a repo..." cd "${1}" &> /dev/null || return 1 git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 } make_repo() { - # Remove the non-repod interface and clone the interface - echo -n "::: Cloning $2 into $1..." - rm -rf "${1}" - git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! - echo " done!" + # Remove the non-repod interface and clone the interface + echo -n "::: Cloning $2 into $1..." + rm -rf "${1}" + git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! + echo " done!" } update_repo() { - # Pull the latest commits - echo -n "::: Updating repo in $1..." - cd "${1}" || exit 1 - git stash -q > /dev/null & spinner $! - git pull -q > /dev/null & spinner $! - echo " done!" + # Pull the latest commits + echo -n "::: Updating repo in $1..." + cd "${1}" || exit 1 + git stash -q > /dev/null & spinner $! + git pull -q > /dev/null & spinner $! + echo " done!" } CreateLogFile() { # Create logfiles if necessary echo ":::" - echo -n "::: Creating log file and changing owner to dnsmasq..." + echo -n "::: Creating log file and changing owner to dnsmasq..." if [ ! -f /var/log/pihole.log ]; then touch /var/log/pihole.log chmod 644 /var/log/pihole.log @@ -785,60 +783,59 @@ configureFirewall() { } finalExports() { - #If it already exists, lets overwrite it with the new values. - if [[ -f ${setupVars} ]];then - rm ${setupVars} - fi + #If it already exists, lets overwrite it with the new values. + if [[ -f ${setupVars} ]]; then + rm ${setupVars} + fi { - echo "piholeInterface=${piholeInterface}" - echo "IPv4_address=${IPv4_address}" - echo "IPv6_address=${IPv6_address}" - echo "piholeDNS1=${piholeDNS1}" - echo "piholeDNS2=${piholeDNS2}" + echo "piholeInterface=${piholeInterface}" + echo "IPv4_address=${IPv4_address}" + echo "IPv6_address=${IPv6_address}" + echo "piholeDNS1=${piholeDNS1}" + echo "piholeDNS2=${piholeDNS2}" }>> "${setupVars}" } - installPihole() { - # Install base files and web interface - create_pihole_user - if [ ! -d "/var/www/html" ]; then - mkdir -p /var/www/html - fi - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html - chmod 775 /var/www/html - usermod -a -G ${LIGHTTPD_GROUP} pihole - if [ -x "$(command -v lighty-enable-mod)" ]; then - lighty-enable-mod fastcgi fastcgi-php > /dev/null || true - else - printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" - fi - installScripts - installConfigs - CreateLogFile - configureSelinux - installPiholeWeb - installCron - configureFirewall - finalExports - runGravity + # Install base files and web interface + create_pihole_user + if [ ! -d "/var/www/html" ]; then + mkdir -p /var/www/html + fi + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html + chmod 775 /var/www/html + usermod -a -G ${LIGHTTPD_GROUP} pihole + if [ -x "$(command -v lighty-enable-mod)" ]; then + lighty-enable-mod fastcgi fastcgi-php > /dev/null || true + else + printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" + fi + installScripts + installConfigs + CreateLogFile + configureSelinux + installPiholeWeb + installCron + configureFirewall + finalExports + runGravity } updatePihole() { - # Refactoring of install script has changed the name of a couple of variables. Sort them out here. - sed -i 's/IPv4addr/IPv4_address/g' ${setupVars} - sed -i 's/piholeIPv6/IPv6_address/g' ${setupVars} - # Source ${setupVars} for use in the rest of the functions. - . ${setupVars} - # Install base files and web interface - installScripts - installConfigs - CreateLogFile - configureSelinux - installPiholeWeb - installCron - configureFirewall - runGravity + # Refactoring of install script has changed the name of a couple of variables. Sort them out here. + sed -i 's/IPv4addr/IPv4_address/g' ${setupVars} + sed -i 's/piholeIPv6/IPv6_address/g' ${setupVars} + # Source ${setupVars} for use in the rest of the functions. + . ${setupVars} + # Install base files and web interface + installScripts + installConfigs + CreateLogFile + configureSelinux + installPiholeWeb + installCron + configureFirewall + runGravity } configureSelinux() { @@ -866,7 +863,7 @@ displayFinalMessage() { whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using: IPv4: ${IPv4_address%/*} -IPv6: $IPv6_address +IPv6: ${IPv6_address} If you set a new IP address, you should restart the Pi. @@ -875,142 +872,141 @@ View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admi } update_dialogs() { - # reconfigure - if [ "$reconfigure" = true ]; then - opt1a="Repair" - opt1b="This will retain existing settings" - strAdd="You will remain on the same version" - else - opt1a="Update" - opt1b="This will retain existing settings." - strAdd="You will be updated to the latest version." - fi - opt2a="Reconfigure" - opt2b="This will allow you to enter new settings" - - UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \ - "$opt1a" "$opt1b" \ - "$opt2a" "$opt2b" 3>&2 2>&1 1>&3) - - if [[ $? = 0 ]];then - case ${UpdateCmd} in - ${opt1a}) - echo "::: $opt1a option selected." - useUpdateVars=true - ;; - ${opt2a}) - echo "::: $opt2a option selected" - useUpdateVars=false - ;; - esac - else - echo "::: Cancel selected. Exiting..." - exit 1 - fi + # reconfigure + if [ "${reconfigure}" = true ]; then + opt1a="Repair" + opt1b="This will retain existing settings" + strAdd="You will remain on the same version" + else + opt1a="Update" + opt1b="This will retain existing settings." + strAdd="You will be updated to the latest version." + fi + opt2a="Reconfigure" + opt2b="This will allow you to enter new settings" + + UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \ + "${opt1a}" "${opt1b}" \ + "${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3) + + if [[ $? = 0 ]];then + case ${UpdateCmd} in + ${opt1a}) + echo "::: ${opt1a} option selected." + useUpdateVars=true + ;; + ${opt2a}) + echo "::: ${opt2a} option selected" + useUpdateVars=false + ;; + esac + else + echo "::: Cancel selected. Exiting..." + exit 1 + fi } main() { # Check arguments for the undocumented flags -for var in "$@" -do - case "$var" in - "--reconfigure" ) reconfigure=true;; - "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; - "--unattended" ) runUnattended=true;; - esac -done - -if [[ -f ${setupVars} ]];then - if [[ "${runUnattended}" == true ]]; then - echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" - useUpdateVars=true - else - update_dialogs - fi -fi + for var in "$@"; do + case "$var" in + "--reconfigure" ) reconfigure=true;; + "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; + "--unattended" ) runUnattended=true;; + esac + done -# Start the installer -# Verify there is enough disk space for the install -if [[ "${skipSpaceCheck}" == true ]]; then - echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" -else - verifyFreeDiskSpace -fi + if [[ -f ${setupVars} ]]; then + if [[ "${runUnattended}" == true ]]; then + echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" + useUpdateVars=true + else + update_dialogs + fi + fi -# Update package cache -update_pacakge_cache + # Start the installer + # Verify there is enough disk space for the install + if [[ "${skipSpaceCheck}" == true ]]; then + echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" + else + verifyFreeDiskSpace + fi -# Notify user of package availability -notify_package_updates_available + # Update package cache + update_pacakge_cache -# Install packages used by this installation script -install_dependent_packages INSTALLER_DEPS[@] + # Notify user of package availability + notify_package_updates_available -# Install packages used by the Pi-hole -install_dependent_packages PIHOLE_DEPS[@] + # Install packages used by this installation script + install_dependent_packages INSTALLER_DEPS[@] -if [[ "${reconfigure}" == true ]]; then - echo "::: --reconfigure passed to install script. Not downloading/updating local repos" -else - # Get Git files for Core and Admin - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} -fi + # Install packages used by the Pi-hole + install_dependent_packages PIHOLE_DEPS[@] -if [[ ${useUpdateVars} == false ]]; then - # Display welcome dialogs - welcomeDialogs - # Create directory for Pi-hole storage - mkdir -p /etc/pihole/ - # Remove legacy scripts from previous storage location - remove_legacy_scripts - # Stop resolver and webserver while installing proceses - stop_service dnsmasq - stop_service lighttpd - # Determine available interfaces - get_available_interfaces - # Find interfaces and let the user choose one - chooseInterface - # Let the user decide if they want to block ads over IPv4 and/or IPv6 - use4andor6 - # Decide what upstream DNS Servers to use - setDNS - # Install and log everything to a file - installPihole | tee ${tmpLog} -else - updatePihole | tee ${tmpLog} -fi + if [[ "${reconfigure}" == true ]]; then + echo "::: --reconfigure passed to install script. Not downloading/updating local repos" + else + # Get Git files for Core and Admin + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} + fi -# Move the log file into /etc/pihole for storage -mv ${tmpLog} ${instalLogLoc} + if [[ ${useUpdateVars} == false ]]; then + # Display welcome dialogs + welcomeDialogs + # Create directory for Pi-hole storage + mkdir -p /etc/pihole/ + # Remove legacy scripts from previous storage location + remove_legacy_scripts + # Stop resolver and webserver while installing proceses + stop_service dnsmasq + stop_service lighttpd + # Determine available interfaces + get_available_interfaces + # Find interfaces and let the user choose one + chooseInterface + # Let the user decide if they want to block ads over IPv4 and/or IPv6 + use4andor6 + # Decide what upstream DNS Servers to use + setDNS + # Install and log everything to a file + installPihole | tee ${tmpLog} + else + updatePihole | tee ${tmpLog} + fi -if [[ "${useUpdateVars}" == false ]]; then - displayFinalMessage -fi + # Move the log file into /etc/pihole for storage + mv ${tmpLog} ${instalLogLoc} -echo "::: Restarting services..." -# Start services -start_service dnsmasq -enable_service dnsmasq -start_service lighttpd -enable_service lighttpd -echo "::: done." + if [[ "${useUpdateVars}" == false ]]; then + displayFinalMessage + fi -echo ":::" -if [[ "${useUpdateVars}" == false ]]; then - echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" - echo "::: ${IPv4_address%/*}" - echo "::: $IPv6_address" - echo ":::" - echo "::: If you set a new IP address, you should restart the Pi." -else - echo "::: Update complete!" -fi + echo "::: Restarting services..." + # Start services + start_service dnsmasq + enable_service dnsmasq + start_service lighttpd + enable_service lighttpd + echo "::: done." -echo ":::" -echo "::: The install log is located at: /etc/pihole/install.log" -echo "::: View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admin" + echo ":::" + if [[ "${useUpdateVars}" == false ]]; then + echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" + echo "::: ${IPv4_address%/*}" + echo "::: ${IPv6_address}" + echo ":::" + echo "::: If you set a new IP address, you should restart the Pi." + else + echo "::: Update complete!" + fi + + echo ":::" + echo "::: The install log is located at: /etc/pihole/install.log" + echo "::: View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admin" } main "$@" From ec4f5007e7f6b40d953e504137f47c4854e3a32d Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Fri, 21 Oct 2016 23:59:31 -0700 Subject: [PATCH 087/172] remove bad { --- automated install/uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 98da8e28..abba88a5 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -65,7 +65,7 @@ spinner() { while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do local temp=${spinstr#?} printf " [%c] " "${spinstr}" - local spinstr=${temp}${spinstr%"${temp}"} + local spinstr=${temp}${spinstr%"$temp}"} sleep ${delay} printf "\b\b\b\b\b\b" done From 0f04e270a76b66c8cbf04f2697dc10182550f9df Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sat, 22 Oct 2016 00:10:25 -0700 Subject: [PATCH 088/172] consistency Just more cleanup --- advanced/Scripts/blacklist.sh | 194 +++++++++++++++++----------------- 1 file changed, 95 insertions(+), 99 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index dc815b58..46c6833e 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -47,119 +47,117 @@ domToRemoveList=() piholeIPfile=/etc/pihole/piholeIP piholeIPv6file=/etc/pihole/.useIPv6 -if [[ -f ${piholeIPfile} ]];then - # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script - piholeIP=$(cat ${piholeIPfile}) - #rm $piholeIPfile +if [[ -f ${piholeIPfile} ]]; then + # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script + piholeIP=$(cat ${piholeIPfile}) + #rm $piholeIPfile else - # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') - piholeIP=${piholeIPCIDR%/*} + # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script + IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') + piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') + piholeIP=${piholeIPCIDR%/*} fi modifyHost=false # After setting defaults, check if there's local overrides -if [[ -r ${piholeDir}/pihole.conf ]];then - echo "::: Local calibration requested..." - . ${piholeDir}/pihole.conf +if [[ -r ${piholeDir}/pihole.conf ]]; then + echo "::: Local calibration requested..." + . ${piholeDir}/pihole.conf fi -if [[ -f ${piholeIPv6file} ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') +if [[ -f ${piholeIPv6file} ]]; then + # If the file exists, then the user previously chose to use IPv6 in the automated installer + piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi HandleOther() { - #check validity of domain - validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - if [ -z "$validDomain" ]; then - echo "::: $1 is not a valid argument or domain name" + #check validity of domain + validDomain=$(echo "${1}" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') + if [ -z "${validDomain}" ]; then + echo "::: ${1} is not a valid argument or domain name" else - domList=("${domList[@]}" ${validDomain}) + domList=("${domList[@]}" ${validDomain}) fi } PopBlacklistFile() { #check blacklist file exists, and if not, create it - if [[ ! -f ${blacklist} ]];then - touch ${blacklist} + if [[ ! -f ${blacklist} ]]; then + touch ${blacklist} fi for dom in "${domList[@]}"; do - if "$addmode"; then - AddDomain "$dom" - else - RemoveDomain "$dom" - fi + if "${addmode}"; then + AddDomain "${dom}" + else + RemoveDomain "${dom}" + fi done } AddDomain() { -#| sed 's/\./\\./g' + #| sed 's/\./\\./g' bool=false grep -Ex -q "$1" ${blacklist} || bool=true if ${bool}; then - #domain not found in the blacklist file, add it! - if ${verbose}; then - echo -n "::: Adding $1 to blacklist file..." - fi - echo "$1" >> ${blacklist} + #domain not found in the blacklist file, add it! + if ${verbose}; then + echo -n "::: Adding $1 to blacklist file..." + fi + echo "${1}" >> ${blacklist} modifyHost=true echo " done!" else if ${verbose}; then - echo "::: $1 already exists in $blacklist! No need to add" + echo "::: ${1} already exists in ${blacklist}! No need to add" fi fi } RemoveDomain() { - - bool=false - grep -Ex -q "$1" ${blacklist} || bool=true - if ${bool}; then - #Domain is not in the blacklist file, no need to Remove - if ${verbose}; then - echo "::: $1 is NOT blacklisted! No need to remove" - fi - else - #Domain is in the blacklist file, add to a temporary array - if ${verbose}; then - echo "::: Un-blacklisting $dom..." - fi - domToRemoveList=("${domToRemoveList[@]}" $1) - modifyHost=true - fi + bool=false + grep -Ex -q "$1" ${blacklist} || bool=true + if ${bool}; then + #Domain is not in the blacklist file, no need to Remove + if ${verbose}; then + echo "::: $1 is NOT blacklisted! No need to remove" + fi + else + #Domain is in the blacklist file, add to a temporary array + if ${verbose}; then + echo "::: Un-blacklisting ${dom}..." + fi + domToRemoveList=("${domToRemoveList[@]}" $1) + modifyHost=true + fi } ModifyHostFile() { - if ${addmode}; then - #add domains to the hosts file - if [[ -r ${blacklist} ]];then - numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l) - plural=; [[ "$numberOf" != "1" ]] && plural=s - echo ":::" - echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." - if [[ -n ${piholeIPv6} ]];then + if ${addmode}; then + #add domains to the hosts file + if [[ -r ${blacklist} ]]; then + numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l) + plural=; [[ "${numberOf}" != "1" ]] && plural=s + echo ":::" + echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." + if [[ -n ${piholeIPv6} ]]; then cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} - else + else cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} - fi - fi - else + fi + fi + else echo ":::" - for dom in "${domToRemoveList[@]}" - do - #we need to remove the domains from the blacklist file and the host file - echo "::: $dom" + for dom in "${domToRemoveList[@]}"; do + #we need to remove the domains from the blacklist file and the host file + echo "::: ${dom}" echo -n "::: removing from HOSTS file..." - echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList} - echo " done!" - echo -n "::: removing from blackist.txt..." - echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} - echo " done!" + echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList} + echo " done!" + echo -n "::: removing from blackist.txt..." + echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} + echo " done!" done fi } @@ -169,22 +167,22 @@ Reload() { echo ":::" echo -n "::: Refresh lists in dnsmasq..." - dnsmasqPid=$(pidof dnsmasq) + dnsmasqPid=$(pidof dnsmasq) if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - if [ -x "$(command -v systemctl)" ]; then - systemctl restart dnsmasq - else - service dnsmasq restart - fi + # 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 - systemctl start dnsmasq - else - service dnsmasq start - fi + # service not running, start it up + if [ -x "$(command -v systemctl)" ]; then + systemctl start dnsmasq + else + service dnsmasq start + fi fi echo " done!" } @@ -193,26 +191,24 @@ DisplayBlist() { verbose=false echo -e " Displaying Gravity Affected Domains \n" count=1 - while IFS= read -r AD - do - echo "${count}: $AD" + while IFS= read -r AD; do + echo "${count}: ${AD}" count=$((count+1)) - done < "$blacklist" + done < "${blacklist}" } ################################################### -for var in "$@" -do - case "$var" in - "-nr"| "--noreload" ) reload=false;; - "-d" | "--delmode" ) addmode=false;; - "-f" | "--force" ) force=true;; - "-q" | "--quiet" ) verbose=false;; - "-h" | "--help" ) helpFunc;; - "-l" | "--list" ) DisplayBlist;; - * ) HandleOther "$var";; - esac +for var in "$@"; do + case "$var" in + "-nr"| "--noreload" ) reload=false;; + "-d" | "--delmode" ) addmode=false;; + "-f" | "--force" ) force=true;; + "-q" | "--quiet" ) verbose=false;; + "-h" | "--help" ) helpFunc;; + "-l" | "--list" ) DisplayBlist;; + * ) HandleOther "$var";; + esac done PopBlacklistFile @@ -220,7 +216,7 @@ PopBlacklistFile if ${modifyHost} || ${force}; then ModifyHostFile else - if ${verbose}; then + if ${verbose}; then echo "::: No changes need to be made" fi exit 1 From 6e94bf5b6dae4324a5e1ee67da71e8292be2b141 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sat, 22 Oct 2016 00:14:38 -0700 Subject: [PATCH 089/172] Consistency You know the drill --- advanced/Scripts/chronometer.sh | 46 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index c0b93e78..2c305d53 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -19,9 +19,9 @@ today=$(date "+%b %e") CalcBlockedDomains() { CheckIPv6 - if [ -e "$gravity" ]; then + if [ -e "${gravity}" ]; then #Are we IPV6 or IPV4? - if [[ -n ${piholeIPv6} ]];then + if [[ -n ${piholeIPv6} ]]; then #We are IPV6 blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}') else @@ -34,15 +34,15 @@ CalcBlockedDomains() { } CalcQueriesToday() { - if [ -e "$piLog" ];then - queriesToday=$(cat "$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l) + if [ -e "${piLog}" ]; then + queriesToday=$(cat "${piLog}" | grep "${today}" | awk '/query/ {print $6}' | wc -l) else queriesToday="Err." fi } CalcblockedToday() { - if [ -e "$piLog" ] && [ -e "$gravity" ];then + if [ -e "${piLog}" ] && [ -e "${gravity}" ];then blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) else blockedToday="Err." @@ -50,11 +50,11 @@ CalcblockedToday() { } CalcPercentBlockedToday() { - if [ "$queriesToday" != "Err." ] && [ "$blockedToday" != "Err." ]; then - if [ "$queriesToday" != 0 ]; then #Fixes divide by zero error :) - #scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros - percentBlockedToday=$(echo "scale=4; $blockedToday/$queriesToday*100" | bc) - percentBlockedToday=$(sed 's/.\{2\}$//' <<< "$percentBlockedToday") + if [ "${queriesToday}" != "Err." ] && [ "${blockedToday}" != "Err." ]; then + if [ "${queriesToday}" != 0 ]; then #Fixes divide by zero error :) + #scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros + percentBlockedToday=$(echo "scale=4; ${blockedToday}/${queriesToday}*100" | bc) + percentBlockedToday=$(sed 's/.\{2\}$//' <<< "${percentBlockedToday}") else percentBlockedToday=0 fi @@ -64,8 +64,8 @@ CalcPercentBlockedToday() { CheckIPv6() { piholeIPv6file="/etc/pihole/.useIPv6" if [[ -f ${piholeIPv6file} ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') + # If the file exists, then the user previously chose to use IPv6 in the automated installer + piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi } @@ -80,8 +80,7 @@ outputJSON() { } normalChrono() { - for (( ; ; )) - do + for (( ; ; )); do clear # Displays a colorful Pi-hole logo echo " ___ _ _ _" @@ -111,11 +110,11 @@ normalChrono() { CalcBlockedDomains - echo "Blocking: $blockedDomainsTotal" + echo "Blocking: ${blockedDomainsTotal}" #below commented line does not add up to todaysQueryCount #echo "Queries: $todaysQueryCountV4 / $todaysQueryCountV6" - echo "Queries: $queriesToday" #same total calculation as dashboard - echo "Pi-holed: $blockedToday ($percentBlockedToday%)" + echo "Queries: ${queriesToday}" #same total calculation as dashboard + echo "Pi-holed: ${blockedToday} (${percentBlockedToday}%)" sleep 5 done @@ -139,11 +138,10 @@ if [[ $# = 0 ]]; then normalChrono fi -for var in "$@" -do - case "$var" in - "-j" | "--json" ) outputJSON;; - "-h" | "--help" ) displayHelp;; - * ) exit 1;; - esac +for var in "$@"; do + case "$var" in + "-j" | "--json" ) outputJSON;; + "-h" | "--help" ) displayHelp;; + * ) exit 1;; + esac done From d0b3727c5dac0f1e4844aa72b3416aad717786bd Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sat, 22 Oct 2016 00:32:36 -0700 Subject: [PATCH 090/172] Consistency Yet more cleanup --- advanced/Scripts/piholeDebug.sh | 382 +++++++++++++++----------------- 1 file changed, 181 insertions(+), 201 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index a49133fd..4c0629e3 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1,4 +1,4 @@ -#/usr/bin/env bash +usr/bin/env bash # Pi-hole: A black hole for Internet advertisements # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi @@ -39,7 +39,7 @@ EOM ######## FIRST CHECK ######## # Must be root to debug -if [[ "$EUID" -eq 0 ]]; then +if [[ "${EUID}" -eq 0 ]]; then echo "::: Script is executing as root user..." else echo "::: Non-root user detected..." @@ -54,7 +54,7 @@ else fi # Ensure the file exists, create if not, clear if exists. -if [ ! -f "$DEBUG_LOG" ]; then +if [ ! -f "${DEBUG_LOG}" ]; then ${SUDO} touch ${DEBUG_LOG} ${SUDO} chmod 644 ${DEBUG_LOG} ${SUDO} chown "$USER":root ${DEBUG_LOG} @@ -64,25 +64,25 @@ fi ### Private functions exist here ### log_write() { - echo "$1" >> "${DEBUG_LOG}" + echo "${1}" >> "${DEBUG_LOG}" } version_check() { - log_write "############################################################" - log_write "########## Installed Versions ##########" - log_write "############################################################" + log_write "############################################################" + log_write "########## Installed Versions ##########" + log_write "############################################################" - echo "::: Detecting Pi-hole installed versions." - pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_write "Pi-hole Version: $pi_hole_ver" || log_write "Pi-hole git repository not detected." - admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ - && log_write "WebUI Version: $admin_ver" || log_write "Pi-hole Admin Pages git repository not detected." + echo "::: Detecting Pi-hole installed versions." + pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ + && log_write "Pi-hole Version: $pi_hole_ver" || log_write "Pi-hole git repository not detected." + admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ + && log_write "WebUI Version: $admin_ver" || log_write "Pi-hole Admin Pages git repository not detected." - echo "::: Writing lighttpd version to logfile." - light_ver="$(lighttpd -v |& head -n1)" && log_write "${light_ver}" || log_write "lighttpd not installed." + echo "::: Writing lighttpd version to logfile." + light_ver="$(lighttpd -v |& head -n1)" && log_write "${light_ver}" || log_write "lighttpd not installed." - echo "::: Writing PHP version to logfile." - php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." + echo "::: Writing PHP version to logfile." + php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." } distro_check() { @@ -94,7 +94,7 @@ distro_check() { TMP=$(cat /etc/*release || echo "Failed to find release") echo "::: Writing OS Distribution release to logfile." - echo "$TMP" >> ${DEBUG_LOG} + echo "${TMP}" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} } @@ -103,103 +103,96 @@ ip_check() { echo "######## IP Address Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} - echo "::: Writing local IPs to logfile" - IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" - echo "$IPADDR" >> ${DEBUG_LOG} - - IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ - && echo "$IP6ADDR" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} - - echo "::: Locating default gateway and checking connectivity" - GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]] - then - echo "::: Pinging default IPv4 gateway..." - GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) - if [[ $? = 0 ]] - then - echo "IPv4 Gateway check:" >> ${DEBUG_LOG} - else - echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG} - fi - echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} - - echo "::: Pinging Internet via IPv4..." - INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) - if [[ $? = 0 ]] - then - echo "IPv4 Internet check:" >> ${DEBUG_LOG} - else - echo "IPv4 Internet check failed:" >> ${DEBUG_LOG} - fi - echo "$INET_CHECK" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} - fi - - GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]] - then - echo "::: Pinging default IPv6 gateway..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3) - if [[ $? = 0 ]] - then - echo "IPv6 Gateway check:" >> ${DEBUG_LOG} - else - echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG} - fi - - echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) - if [[ $? = 0 ]] - then - echo "IPv6 Internet check:" >> ${DEBUG_LOG} - else - echo "IPv6 Internet check failed:" >> ${DEBUG_LOG} - fi - - else - GATEWAY_CHECK="No IPv6 Gateway Detected" - fi - echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} - - - echo >> ${DEBUG_LOG} + echo "::: Writing local IPs to logfile" + IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" + echo "${IPADDR}" >> ${DEBUG_LOG} + + IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ + && echo "${IP6ADDR}" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + + echo "::: Locating default gateway and checking connectivity" + GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) + if [[ $? = 0 ]]; then + echo "::: Pinging default IPv4 gateway..." + GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) + if [[ $? = 0 ]]; then + echo "IPv4 Gateway check:" >> ${DEBUG_LOG} + else + echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG} + fi + echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + + echo "::: Pinging Internet via IPv4..." + INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) + if [[ $? = 0 ]]; then + echo "IPv4 Internet check:" >> ${DEBUG_LOG} + else + echo "IPv4 Internet check failed:" >> ${DEBUG_LOG} + fi + echo "${INET_CHECK}" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + fi + + GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) + if [[ $? = 0 ]]; then + echo "::: Pinging default IPv6 gateway..." + GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3) + if [[ $? = 0 ]]; then + echo "IPv6 Gateway check:" >> ${DEBUG_LOG} + else + echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG} + fi + + echo "::: Pinging Internet via IPv6..." + GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) + if [[ $? = 0 ]]; then + echo "IPv6 Internet check:" >> ${DEBUG_LOG} + else + echo "IPv6 Internet check failed:" >> ${DEBUG_LOG} + fi + + else + GATEWAY_CHECK="No IPv6 Gateway Detected" + fi + echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG} + + + echo >> ${DEBUG_LOG} } hostnameCheck() { - echo "############################################################" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} echo "######## Hostname Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} - echo "::: Writing locally configured hostnames to logfile" - # Write the hostname output to compare against entries in /etc/hosts, which is logged next - echo "This Pi-hole is: $(hostname)" >> ${DEBUG_LOG} - - echo "::: Writing hosts file to debug log..." - echo "### Hosts ###" >> ${DEBUG_LOG} - - if [ -e "$HOSTSFILE" ] - then - cat "$HOSTSFILE" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} - else - echo "No hosts file found!" >> ${DEBUG_LOG} - printf ":::\tNo hosts file found!\n" - fi + echo "::: Writing locally configured hostnames to logfile" + # Write the hostname output to compare against entries in /etc/hosts, which is logged next + echo "This Pi-hole is: $(hostname)" >> ${DEBUG_LOG} + + echo "::: Writing hosts file to debug log..." + echo "### Hosts ###" >> ${DEBUG_LOG} + + if [ -e "${HOSTSFILE}" ]; then + cat "${HOSTSFILE}" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + else + echo "No hosts file found!" >> ${DEBUG_LOG} + printf ":::\tNo hosts file found!\n" + fi } portCheck() { - echo "############################################################" >> ${DEBUG_LOG} + echo "############################################################" >> ${DEBUG_LOG} echo "######## Open Port Information #########" >> ${DEBUG_LOG} echo "############################################################" >> ${DEBUG_LOG} - echo "::: Detecting local server port 80 and 53 processes." + echo "::: Detecting local server port 80 and 53 processes." - ${SUDO} lsof -i :80 >> ${DEBUG_LOG} - ${SUDO} lsof -i :53 >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + ${SUDO} lsof -i :80 >> ${DEBUG_LOG} + ${SUDO} lsof -i :53 >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } testResolver() { @@ -209,59 +202,57 @@ testResolver() { # Find a blocked url that has not been whitelisted. - TESTURL="doubleclick.com" - if [ -s "$WHITELISTMATCHES" ]; then + TESTURL="doubleclick.com" + if [ -s "${WHITELISTMATCHES}" ]; then while read -r line; do CUTURL=${line#*" "} - if [ "$CUTURL" != "Pi-Hole.IsWorking.OK" ]; then + if [ "${CUTURL}" != "Pi-Hole.IsWorking.OK" ]; then while read -r line2; do CUTURL2=${line2#*" "} - if [ "$CUTURL" != "$CUTURL2" ]; then - TESTURL="$CUTURL" + if [ "${CUTURL}" != "${CUTURL2}" ]; then + TESTURL="${CUTURL}" break 2 fi - done < "$WHITELISTMATCHES" + done < "${WHITELISTMATCHES}" fi - done < "$GRAVITYFILE" + done < "${GRAVITYFILE}" fi - echo "Resolution of $TESTURL from Pi-hole:" >> ${DEBUG_LOG} - LOCALDIG=$(dig "$TESTURL" @127.0.0.1) - if [[ $? = 0 ]] - then - echo "$LOCALDIG" >> ${DEBUG_LOG} + echo "Resolution of ${TESTURL} from Pi-hole:" >> ${DEBUG_LOG} + LOCALDIG=$(dig "${TESTURL}" @127.0.0.1) + if [[ $? = 0 ]]; then + echo "${LOCALDIG}" >> ${DEBUG_LOG} else - echo "Failed to resolve $TESTURL on Pi-hole" >> ${DEBUG_LOG} + echo "Failed to resolve ${TESTURL} on Pi-hole" >> ${DEBUG_LOG} fi echo >> ${DEBUG_LOG} - echo "Resolution of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} - REMOTEDIG=$(dig "$TESTURL" @8.8.8.8) - if [[ $? = 0 ]] - then - echo "$REMOTEDIG" >> ${DEBUG_LOG} + echo "Resolution of ${TESTURL} from 8.8.8.8:" >> ${DEBUG_LOG} + REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8) + if [[ $? = 0 ]]; then + echo "${REMOTEDIG}" >> ${DEBUG_LOG} else - echo "Failed to resolve $TESTURL on 8.8.8.8" >> ${DEBUG_LOG} + echo "Failed to resolve ${TESTURL} on 8.8.8.8" >> ${DEBUG_LOG} fi echo >> ${DEBUG_LOG} echo "Pi-hole dnsmasq specific records lookups" >> ${DEBUG_LOG} - echo "Cache Size:" >> ${DEBUG_LOG} - dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} - echo "Insertions count:" >> ${DEBUG_LOG} - dig +short chaos txt insertions.bind >> ${DEBUG_LOG} - echo "Evictions count:" >> ${DEBUG_LOG} - dig +short chaos txt evictions.bind >> ${DEBUG_LOG} - echo "Misses count:" >> ${DEBUG_LOG} - dig +short chaos txt misses.bind >> ${DEBUG_LOG} - echo "Hits count:" >> ${DEBUG_LOG} - dig +short chaos txt hits.bind >> ${DEBUG_LOG} - echo "Auth count:" >> ${DEBUG_LOG} - dig +short chaos txt auth.bind >> ${DEBUG_LOG} - echo "Upstream Servers:" >> ${DEBUG_LOG} - dig +short chaos txt servers.bind >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + echo "Cache Size:" >> ${DEBUG_LOG} + dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} + echo "Insertions count:" >> ${DEBUG_LOG} + dig +short chaos txt insertions.bind >> ${DEBUG_LOG} + echo "Evictions count:" >> ${DEBUG_LOG} + dig +short chaos txt evictions.bind >> ${DEBUG_LOG} + echo "Misses count:" >> ${DEBUG_LOG} + dig +short chaos txt misses.bind >> ${DEBUG_LOG} + echo "Hits count:" >> ${DEBUG_LOG} + dig +short chaos txt hits.bind >> ${DEBUG_LOG} + echo "Auth count:" >> ${DEBUG_LOG} + dig +short chaos txt auth.bind >> ${DEBUG_LOG} + echo "Upstream Servers:" >> ${DEBUG_LOG} + dig +short chaos txt servers.bind >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } checkProcesses() { @@ -271,12 +262,11 @@ checkProcesses() { echo ":::" echo "::: Logging status of lighttpd and dnsmasq..." PROCESSES=( lighttpd dnsmasq ) - for i in "${PROCESSES[@]}" - do + for i in "${PROCESSES[@]}"; do echo "" >> ${DEBUG_LOG} - echo -n "$i" >> "$DEBUG_LOG" + echo -n "${i}" >> "${DEBUG_LOG}" echo " processes status:" >> ${DEBUG_LOG} - ${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG" + ${SUDO} systemctl -l status "${i}" >> "${DEBUG_LOG}" done echo >> ${DEBUG_LOG} } @@ -286,26 +276,24 @@ debugLighttpd() { echo "#######################################" >> ${DEBUG_LOG} echo "############ lighttpd.conf ############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} - if [ -e "$LIGHTTPDFILE" ] - then + if [ -e "${LIGHTTPDFILE}" ]; then while read -r line; do - if [ ! -z "$line" ]; then - [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> ${DEBUG_LOG} + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue + echo "${line}" >> ${DEBUG_LOG} fi - done < "$LIGHTTPDFILE" + done < "${LIGHTTPDFILE}" echo >> ${DEBUG_LOG} else echo "No lighttpd.conf file found!" >> ${DEBUG_LOG} printf ":::\tNo lighttpd.conf file found\n" fi - if [ -e "$LIGHTTPDERRFILE" ] - then + if [ -e "${LIGHTTPDERRFILE}" ]; then echo "#######################################" >> ${DEBUG_LOG} echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} - cat "$LIGHTTPDERRFILE" >> ${DEBUG_LOG} + cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG} else echo "No lighttpd error.log file found!" >> ${DEBUG_LOG} printf ":::\tNo lighttpd error.log file found\n" @@ -328,15 +316,14 @@ echo "::: Writing dnsmasq.conf to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "############### Dnsmasq ###############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} -if [ -e "$DNSMASQFILE" ] -then +if [ -e "${DNSMASQFILE}" ]; then #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do - if [ ! -z "$line" ]; then - [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> ${DEBUG_LOG} - fi - done < "$DNSMASQFILE" + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue + echo "${line}" >> ${DEBUG_LOG} + fi + done < "${DNSMASQFILE}" echo >> ${DEBUG_LOG} else echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG} @@ -347,14 +334,13 @@ echo "::: Writing 01-pihole.conf to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} -if [ -e "$PIHOLECONFFILE" ] -then +if [ -e "${PIHOLECONFFILE}" ]; then while read -r line; do - if [ ! -z "$line" ]; then - [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> ${DEBUG_LOG} - fi - done < "$PIHOLECONFFILE" + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue + echo "${line}" >> ${DEBUG_LOG} + fi + done < "${PIHOLECONFFILE}" echo >> ${DEBUG_LOG} else echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG} @@ -365,9 +351,8 @@ echo "::: Writing size of gravity.list to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "############ gravity.list #############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} -if [ -e "$GRAVITYFILE" ] -then - wc -l "$GRAVITYFILE" >> ${DEBUG_LOG} +if [ -e "${GRAVITYFILE}" ]; then + wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} else echo "No gravity.list file found!" >> ${DEBUG_LOG} @@ -380,9 +365,8 @@ echo "::: Writing whitelist to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "############## Whitelist ##############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} -if [ -e "$WHITELISTFILE" ] -then - cat "$WHITELISTFILE" >> ${DEBUG_LOG} +if [ -e "${WHITELISTFILE}" ]; then + cat "${WHITELISTFILE}" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} else echo "No whitelist.txt file found!" >> ${DEBUG_LOG} @@ -393,9 +377,8 @@ echo "::: Writing blacklist to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "############## Blacklist ##############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} -if [ -e "$BLACKLISTFILE" ] -then - cat "$BLACKLISTFILE" >> ${DEBUG_LOG} +if [ -e "${BLACKLISTFILE}" ]; then + cat "${BLACKLISTFILE}" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} else echo "No blacklist.txt file found!" >> ${DEBUG_LOG} @@ -406,14 +389,13 @@ echo "::: Writing adlists.list to debug log..." echo "#######################################" >> ${DEBUG_LOG} echo "############ adlists.list #############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} -if [ -e "$ADLISTSFILE" ] -then - while read -r line; do - if [ ! -z "$line" ]; then - [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> ${DEBUG_LOG} - fi - done < "$ADLISTSFILE" +if [ -e "${ADLISTSFILE}" ]; then + while read -r line; do + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue + echo "${line}" >> ${DEBUG_LOG} + fi + done < "${ADLISTSFILE}" echo >> ${DEBUG_LOG} else echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG} @@ -428,10 +410,9 @@ dumpPiHoleLog() { echo "#######################################" >> ${DEBUG_LOG} echo "############# pihole.log ##############" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG} - if [ -e "$PIHOLELOG" ] - then + if [ -e "${PIHOLELOG}" ]; then while true; do - tail -f "$PIHOLELOG" >> ${DEBUG_LOG} + tail -f "${PIHOLELOG}" >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} done else @@ -442,25 +423,24 @@ dumpPiHoleLog() { # Anything to be done after capturing of pihole.log terminates finalWork() { - echo "::: Finshed debugging!" - echo "::: The debug log can be uploaded to Termbin.com for easier sharing." - read -r -p "::: Would you like to upload the log? [y/N] " response - case ${response} in - [yY][eE][sS]|[yY]) - TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) - ;; - *) - echo "::: Log will NOT be uploaded to Termbin." - ;; - esac - - # Check if termbin.com is reachable. When it's not, point to local log instead - if [ -n "$TERMBIN" ] - then - echo "::: Debug log can be found at : $TERMBIN" - else - echo "::: Debug log can be found at : /var/log/pihole_debug.log" - fi + echo "::: Finshed debugging!" + echo "::: The debug log can be uploaded to Termbin.com for easier sharing." + read -r -p "::: Would you like to upload the log? [y/N] " response + case ${response} in + [yY][eE][sS]|[yY]) + TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) + ;; + *) + echo "::: Log will NOT be uploaded to Termbin." + ;; + esac + + # Check if termbin.com is reachable. When it's not, point to local log instead + if [ -n "${TERMBIN}" ]; then + echo "::: Debug log can be found at : ${TERMBIN}" + else + echo "::: Debug log can be found at : /var/log/pihole_debug.log" + fi } trap finalWork EXIT From a30c75ef71c2f36e02e48a682098aabb3e847004 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sat, 22 Oct 2016 00:35:44 -0700 Subject: [PATCH 091/172] Consistency Cleanup! --- advanced/Scripts/setupLCD.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh index 5ef324fe..e5a01911 100755 --- a/advanced/Scripts/setupLCD.sh +++ b/advanced/Scripts/setupLCD.sh @@ -15,28 +15,28 @@ # Borrowed from adafruit-pitft-helper < borrowed from raspi-config # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L324-L334 getInitSys() { - if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then - SYSTEMD=1 - elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then - SYSTEMD=0 - else - echo "Unrecognised init system" - return 1 - fi + if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then + SYSTEMD=1 + elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then + SYSTEMD=0 + else + echo "Unrecognised init system" + return 1 + fi } # Borrowed from adafruit-pitft-helper: # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 autoLoginPiToConsole() { - if [ -e /etc/init.d/lightdm ]; then - if [ ${SYSTEMD} -eq 1 ]; then - systemctl set-default multi-user.target - ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service - else - update-rc.d lightdm disable 2 - sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" - fi - fi + if [ -e /etc/init.d/lightdm ]; then + if [ ${SYSTEMD} -eq 1 ]; then + systemctl set-default multi-user.target + ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service + else + update-rc.d lightdm disable 2 + sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" + fi + fi } ######### SCRIPT ########### From 69ba8a3c2f14f351d1322d77a38f6eb7db7902a2 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sat, 22 Oct 2016 10:01:15 -0700 Subject: [PATCH 092/172] Consistency Again trying to move the repo to one style. Doesn't matter if it's changed afterwards, but one style instead of about five seems saner. --- advanced/Scripts/update.sh | 124 ++++++++++++++++++------------------ advanced/Scripts/version.sh | 99 ++++++++++++++-------------- 2 files changed, 109 insertions(+), 114 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index e42724d6..a2220d57 100644 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -18,17 +18,17 @@ piholeGitUrl="https://github.com/pi-hole/pi-hole.git" piholeFilesDir="/etc/.pihole" spinner() { - local pid=$1 - local delay=0.50 - local spinstr='/-\|' - while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local pid=${1} + local delay=0.50 + local spinstr='/-\|' + while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do local temp=${spinstr#?} - printf " [%c] " "$spinstr" - local spinstr=${temp}${spinstr%"$temp"} - sleep ${delay} - printf "\b\b\b\b\b\b" - done - printf " \b\b\b\b" + printf " [%c] " "${spinstr}" + local spinstr=${temp}${spinstr%"$temp"} + sleep ${delay} + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" } getGitFiles() { @@ -37,45 +37,45 @@ getGitFiles() { echo ":::" echo "::: Checking for existing repository..." if is_repo "${1}"; then - update_repo "${1}" + update_repo "${1}" else - make_repo "${1}" "${2}" - fi + make_repo "${1}" "${2}" + fi } is_repo() { - # Use git to check if directory is currently under VCS + # Use git to check if directory is currently under VCS echo -n "::: Checking $1 is a repo..." cd "${1}" &> /dev/null || return 1 git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 } make_repo() { - # Remove the non-repod interface and clone the interface - echo -n "::: Cloning $2 into $1..." - rm -rf "${1}" - git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! - echo " done!" + # Remove the non-repod interface and clone the interface + echo -n "::: Cloning $2 into $1..." + rm -rf "${1}" + git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! + echo " done!" } update_repo() { - # Pull the latest commits - echo -n "::: Updating repo in $1..." - cd "${1}" || exit 1 - git stash -q > /dev/null & spinner $! - git pull -q > /dev/null & spinner $! - echo " done!" +# Pull the latest commits + echo -n "::: Updating repo in $1..." + cd "${1}" || exit 1 + git stash -q > /dev/null & spinner $! + git pull -q > /dev/null & spinner $! + echo " done!" } if [ ! -d "/etc/.pihole" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; fi if [ ! -d "/var/www/html/admin" ]; then #This is unlikely - echo "::: Critical Error: Pi-Hole repo missing from system!" - echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" - exit 1; + echo "::: Critical Error: Pi-Hole repo missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; fi echo "::: Checking for updates..." @@ -105,40 +105,38 @@ echo ":::" if [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then - echo "::: Everything is up to date!" - echo "" - exit 0 + echo "::: Everything is up to date!" + echo "" + exit 0 elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then - echo "::: Pi-hole Web Admin files out of date" - getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} - echo ":::" - webVersion=$(pihole -v -a -c) - echo "::: Web Admin version is now at ${webVersion}" - echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'" - echo "" - + echo "::: Pi-hole Web Admin files out of date" + getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} + echo ":::" + webVersion=$(pihole -v -a -c) + echo "::: Web Admin version is now at ${webVersion}" + echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'" + echo "" elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then - echo "::: Pi-hole core files out of date" - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended - echo ":::" - piholeVersion=$(pihole -v -p -c) - echo "::: Pi-hole version is now at ${piholeVersion}" - echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" - echo "" - + echo "::: Pi-hole core files out of date" + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended + echo ":::" + piholeVersion=$(pihole -v -p -c) + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo "" elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then - echo "::: Updating Everything" - getGitFiles ${piholeFilesDir} ${piholeGitUrl} - /etc/.pihole/automated\ install/basic-install.sh --unattended - webVersion=$(pihole -v -a -c) - piholeVersion=$(pihole -v -p -c) - echo ":::" - echo "::: Pi-hole version is now at ${piholeVersion}" - echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" - echo ":::" - echo "::: Pi-hole version is now at ${piholeVersion}" - echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" - echo "" + echo "::: Updating Everything" + getGitFiles ${piholeFilesDir} ${piholeGitUrl} + /etc/.pihole/automated\ install/basic-install.sh --unattended + webVersion=$(pihole -v -a -c) + piholeVersion=$(pihole -v -p -c) + echo ":::" + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo ":::" + echo "::: Pi-hole version is now at ${piholeVersion}" + echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" + echo "" fi diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 7b2e3f68..ca78032a 100644 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -15,60 +15,58 @@ latest=false current=false normalOutput() { - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) + 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/",$//') + 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)" - echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" + echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest})" + echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest})" } webOutput() { - for var in "$@" - do - case "$var" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; - * ) echo "::: Invalid Option!"; exit 1; - esac - done + 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} - 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)" - fi + 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} + 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)" + fi } coreOutput() { - for var in "$@" - do - case "$var" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; - * ) echo "::: Invalid Option!"; exit 1; - esac - done + 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} - 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)" - fi + 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} + 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)" + fi } helpFunc() { @@ -93,11 +91,10 @@ if [[ $# = 0 ]]; then normalOutput fi -for var in "$@" -do - case "$var" in - "-a" | "--admin" ) shift; webOutput "$@";; - "-p" | "--pihole" ) shift; coreOutput "$@" ;; - "-h" | "--help" ) helpFunc;; - esac +for var in "$@"; do + case "${var}" in + "-a" | "--admin" ) shift; webOutput "$@";; + "-p" | "--pihole" ) shift; coreOutput "$@" ;; + "-h" | "--help" ) helpFunc;; + esac done From 07a66a70fccc1b64e29d7d97454da0ec7d012b56 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sat, 22 Oct 2016 10:12:05 -0700 Subject: [PATCH 093/172] Consistency More of the same --- advanced/Scripts/whitelist.sh | 242 +++++++++++++++++----------------- 1 file changed, 119 insertions(+), 123 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index ae4a7321..f1a9fb73 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -48,160 +48,158 @@ domToRemoveList=() piholeIPfile=/etc/pihole/piholeIP piholeIPv6file=/etc/pihole/.useIPv6 -if [[ -f ${piholeIPfile} ]];then - # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script - piholeIP=$(cat ${piholeIPfile}) - #rm $piholeIPfile +if [[ -f ${piholeIPfile} ]]; then + # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script + piholeIP=$(cat ${piholeIPfile}) + #rm $piholeIPfile else - # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script - IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') - piholeIP=${piholeIPCIDR%/*} + # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script + IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') + piholeIPCIDR=$(ip -o -f inet addr show dev "${IPv4dev}" | awk '{print $4}' | awk 'END {print}') + piholeIP=${piholeIPCIDR%/*} fi modifyHost=false # After setting defaults, check if there's local overrides -if [[ -r ${piholeDir}/pihole.conf ]];then - echo "::: Local calibration requested..." - . ${piholeDir}/pihole.conf +if [[ -r ${piholeDir}/pihole.conf ]]; then + echo "::: Local calibration requested..." + . ${piholeDir}/pihole.conf fi -if [[ -f ${piholeIPv6file} ]];then - # If the file exists, then the user previously chose to use IPv6 in the automated installer - piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') +if [[ -f ${piholeIPv6file} ]]; then +# If the file exists, then the user previously chose to use IPv6 in the automated installer + piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi HandleOther() { - #check validity of domain + #check validity of domain validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - if [ -z "$validDomain" ]; then + if [ -z "${validDomain}" ]; then echo "::: $1 is not a valid argument or domain name" else - domList=("${domList[@]}" ${validDomain}) + domList=("${domList[@]}" ${validDomain}) fi } PopWhitelistFile() { #check whitelist file exists, and if not, create it - if [[ ! -f ${whitelist} ]];then - touch ${whitelist} + if [[ ! -f ${whitelist} ]]; then + touch ${whitelist} fi - for dom in "${domList[@]}" - do - if ${addmode}; then - AddDomain "$dom" - else - RemoveDomain "$dom" - fi + for dom in "${domList[@]}"; do + if ${addmode}; then + AddDomain "${dom}" + else + RemoveDomain "${dom}" + fi done } AddDomain() { -#| sed 's/\./\\./g' + #| sed 's/\./\\./g' bool=false grep -Ex -q "$1" ${whitelist} || bool=true if ${bool}; then - #domain not found in the whitelist file, add it! - if ${verbose}; then - echo -n "::: Adding $1 to $whitelist..." - fi - echo "$1" >> ${whitelist} - modifyHost=true + #domain not found in the whitelist file, add it! + if ${verbose}; then + echo -n "::: Adding ${1}to ${whitelist}..." + fi + echo "${1}" >> ${whitelist} + modifyHost=true if ${verbose}; then - echo " done!" - fi + echo " done!" + fi else if ${verbose}; then - echo "::: $1 already exists in $whitelist, no need to add!" + echo "::: ${1} already exists in ${whitelist}, no need to add!" fi fi } RemoveDomain() { - bool=false - grep -Ex -q "$1" ${whitelist} || bool=true - if ${bool}; then - #Domain is not in the whitelist file, no need to Remove - if ${verbose}; then - echo "::: $1 is NOT whitelisted! No need to remove" - fi - else - #Domain is in the whitelist file, add to a temporary array and remove from whitelist file - #if $verbose; then - #echo "::: Un-whitelisting $dom..." - #fi - domToRemoveList=("${domToRemoveList[@]}" $1) - modifyHost=true - fi + bool=false + grep -Ex -q "$1" ${whitelist} || bool=true + if ${bool}; then + #Domain is not in the whitelist file, no need to Remove + if ${verbose}; then + echo "::: ${1} is NOT whitelisted! No need to remove" + fi + else + #Domain is in the whitelist file, add to a temporary array and remove from whitelist file + #if $verbose; then + #echo "::: Un-whitelisting $dom..." + #fi + domToRemoveList=("${domToRemoveList[@]}" ${1}) + modifyHost=true +fi } ModifyHostFile() { - if ${addmode}; then - #remove domains in from hosts file - if [[ -r ${whitelist} ]];then - # Remove whitelist entries - numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l) - plural=; [[ "$numberOf" != "1" ]] && plural=s - echo ":::" - echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." - awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp - awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp - echo "l" >> /etc/pihole/whitelist.tmp - grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp - rm ${adList} - mv ${piholeDir}/gravity.tmp ${adList} - rm ${piholeDir}/whitelist.tmp - echo " done!" - - fi - else - #we need to add the removed domains to the hosts file - echo ":::" - echo "::: Modifying HOSTS file to un-whitelist domains..." - for rdom in "${domToRemoveList[@]}" - do - if grep -q "$rdom" /etc/pihole/*.domains; then - echo "::: AdLists contain $rdom, re-adding block" - if [[ -n ${piholeIPv6} ]];then - echo -n "::: Restoring block for $rdom on IPv4 and IPv6..." - echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} - echo " done!" - else - echo -n "::: Restoring block for $rdom on IPv4..." - echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} - echo " done!" - fi - fi - echo -n "::: Removing $rdom from $whitelist..." - echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} - echo " done!" - done - fi + if ${addmode}; then + #remove domains in from hosts file + if [[ -r ${whitelist} ]]; then + # Remove whitelist entries + numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l) + plural=; [[ "${numberOf}" != "1" ]] && plural=s + echo ":::" + echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." + awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "${piholeIP} ${line}"; done > /etc/pihole/whitelist.tmp + awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "${piholeIPv6} ${line}"; done >> /etc/pihole/whitelist.tmp + echo "l" >> /etc/pihole/whitelist.tmp + grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp + rm ${adList} + mv ${piholeDir}/gravity.tmp ${adList} + rm ${piholeDir}/whitelist.tmp + echo " done!" + + fi + else + #we need to add the removed domains to the hosts file + echo ":::" + echo "::: Modifying HOSTS file to un-whitelist domains..." + for rdom in "${domToRemoveList[@]}"; do + if grep -q "${rdom}" /etc/pihole/*.domains; then + echo "::: AdLists contain ${rdom}, re-adding block" + if [[ -n ${piholeIPv6} ]]; then + echo -n "::: Restoring block for ${rdom} on IPv4 and IPv6..." + echo "${rdom}" | awk -v ipv4addr="${piholeIP}" -v ipv6addr="${piholeIPv6}" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} + echo " done!" + else + echo -n "::: Restoring block for ${rdom} on IPv4..." + echo "${rdom}" | awk -v ipv4addr="${piholeIP}" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} + echo " done!" + fi + fi + echo -n "::: Removing $rdom from $whitelist..." + echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} + echo " done!" + done + fi } Reload() { # Reload hosts file echo ":::" echo -n "::: Refresh lists in dnsmasq..." - dnsmasqPid=$(pidof dnsmasq) + dnsmasqPid=$(pidof dnsmasq) if [[ ${dnsmasqPid} ]]; then - # service already running - reload config - if [ -x "$(command -v systemctl)" ]; then - systemctl restart dnsmasq - else - service dnsmasq restart - fi + # 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 - systemctl start dnsmasq - else - service dnsmasq start - fi + # service not running, start it up + if [ -x "$(command -v systemctl)" ]; then + systemctl start dnsmasq + else + service dnsmasq start + fi fi echo " done!" } @@ -210,35 +208,33 @@ DisplayWlist() { verbose=false echo -e " Displaying Gravity Resistant Domains \n" count=1 - while IFS= read -r RD - do - echo "${count}: $RD" + while IFS= read -r RD; do + echo "${count}: ${RD}" count=$((count+1)) - done < "$whitelist" + done < "${whitelist}" } ################################################### -for var in "$@" -do - case "$var" in - "-nr"| "--noreload" ) reload=false;; - "-d" | "--delmode" ) addmode=false;; - "-f" | "--force" ) force=true;; - "-q" | "--quiet" ) verbose=false;; - "-h" | "--help" ) helpFunc;; - "-l" | "--list" ) DisplayWlist;; - * ) HandleOther "$var";; - esac +for var in "$@"; do + case "${var}" in + "-nr"| "--noreload" ) reload=false;; + "-d" | "--delmode" ) addmode=false;; + "-f" | "--force" ) force=true;; + "-q" | "--quiet" ) verbose=false;; + "-h" | "--help" ) helpFunc;; + "-l" | "--list" ) DisplayWlist;; + * ) HandleOther "${var}";; + esac done PopWhitelistFile if ${modifyHost} || ${force}; then - ModifyHostFile + ModifyHostFile else - if ${verbose}; then - echo ":::" + if ${verbose}; then + echo ":::" echo "::: No changes need to be made" fi exit 1 From 5d6072524c63909f0052f80aa13582d359dd28ee Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sat, 22 Oct 2016 10:26:00 -0700 Subject: [PATCH 094/172] Consistency Missed one --- advanced/bash-completion/pihole | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/advanced/bash-completion/pihole b/advanced/bash-completion/pihole index 1fae988d..dd3f050d 100644 --- a/advanced/bash-completion/pihole +++ b/advanced/bash-completion/pihole @@ -1,12 +1,11 @@ -_pihole() -{ - local cur prev opts - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="blacklist chronometer debug flush help query reconfigure setupLCD uninstall updateGravity updatePihole version whitelist" +_pihole() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + opts="blacklist chronometer debug flush help query reconfigure setupLCD uninstall updateGravity updatePihole version whitelist" - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - return 0 + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 } -complete -F _pihole pihole \ No newline at end of file +complete -F _pihole pihole From 82e78fb6518b47e81f22ee8022677288b70513f5 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 19:44:40 +0100 Subject: [PATCH 095/172] Add output to `pihole disable` and `pihole enable` --- pihole | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index 0f0e67c1..6346f32d 100755 --- a/pihole +++ b/pihole @@ -118,8 +118,10 @@ piholeEnable() { if [[ "${1}" == "0" ]] ; then #Disable Pihole sed -i 's/^addn-hosts/#addn-hosts/' /etc/dnsmasq.d/01-pihole.conf + echo "::: Blocking has been disabled!" else #Enable pihole + echo "::: Blocking has been enabled!" sed -i 's/^#addn-hosts/addn-hosts/' /etc/dnsmasq.d/01-pihole.conf fi restartDNS @@ -131,14 +133,14 @@ piholeStatus() { if [[ "${1}" == "web" ]] ; then echo 0; else - echo "::: Pi-hole is Disabled"; + echo "::: Pi-hole blocking is Disabled"; fi elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then #list set if [[ "${1}" == "web" ]] ; then echo 1; else - echo "::: Pi-hole is Enabled"; + echo "::: Pi-hole blocking is Enabled"; fi else #addn-host not found From 8ee98f0a4aa9b7127e8b1e0955f296ba7340d942 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 19:47:31 +0100 Subject: [PATCH 096/172] remove a space --- pihole | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index 6346f32d..9a678393 100755 --- a/pihole +++ b/pihole @@ -133,14 +133,14 @@ piholeStatus() { if [[ "${1}" == "web" ]] ; then echo 0; else - echo "::: Pi-hole blocking is Disabled"; + echo "::: Pi-hole blocking is Disabled"; fi elif [[ $(cat /etc/dnsmasq.d/01-pihole.conf | grep "addn-hosts=/") ]] ; then #list set if [[ "${1}" == "web" ]] ; then echo 1; else - echo "::: Pi-hole blocking is Enabled"; + echo "::: Pi-hole blocking is Enabled"; fi else #addn-host not found From b79392ba2c737de2a1759ee0a399dcbbb6578673 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 19:49:51 +0100 Subject: [PATCH 097/172] exit after displaying white/blacklist --- advanced/Scripts/blacklist.sh | 1 + advanced/Scripts/whitelist.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 10adc2d7..2a088318 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -143,6 +143,7 @@ DisplayBlist() { echo "${count}: ${AD}" count=$((count+1)) done < "${blacklist}" + exit 0; } ################################################### diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 2da6adb0..ee5958bf 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -115,6 +115,7 @@ DisplayWlist() { echo "${count}: ${RD}" count=$((count+1)) done < "${whitelist}" + exit 0; } ################################################### From 2b2c240d39d741cf7dc5a5f93cc4d979a0921fa3 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 22:15:10 +0100 Subject: [PATCH 098/172] Fix shebang line broken in #831 Remove root check and references to ${SUDO} Check for /etc/pihole/setupVars.conf and use piholeInterace in IPv6 checks as suggest by @jacobsalmela https://github.com/pi-hole/pi-hole/pull/831#issuecomment-255606854 --- advanced/Scripts/piholeDebug.sh | 72 ++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 4c0629e3..4accb79f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1,4 +1,4 @@ -usr/bin/env bash +#!/usr/bin/env bash # Pi-hole: A black hole for Internet advertisements # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi @@ -33,32 +33,15 @@ cat << EOM ::: and optionally upload the generated log to a unique and random directory on ::: Termbin.com. NOTE: All log files auto-delete after 1 month and you are the only ::: person who is given the unique URL. Please consider where you post this link. -::: +::: EOM - -######## FIRST CHECK ######## -# Must be root to debug -if [[ "${EUID}" -eq 0 ]]; then - echo "::: Script is executing as root user..." -else - echo "::: Non-root user detected..." - # Check if sudo is actually installed - if [ -x "$(command -v sudo)" ]; then - export SUDO="sudo" - echo "::: sudo command located, debug will run under sudo." - else - echo "::: Unable to locate sudo command. Please install sudo or run this as root." - exit 1 - fi -fi - # Ensure the file exists, create if not, clear if exists. if [ ! -f "${DEBUG_LOG}" ]; then - ${SUDO} touch ${DEBUG_LOG} - ${SUDO} chmod 644 ${DEBUG_LOG} - ${SUDO} chown "$USER":root ${DEBUG_LOG} -else + touch ${DEBUG_LOG} + chmod 644 ${DEBUG_LOG} + chown "$USER":root ${DEBUG_LOG} +else truncate -s 0 ${DEBUG_LOG} fi @@ -85,6 +68,36 @@ version_check() { php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." } +files_check() { + log_write "############################################################" + log_write "########## Files Check ##########" + log_write "############################################################" + + #Check existence of setupVars.conf, and source it to get configured network interface for later use in script. + echo -n "::: Detecting existence setupVars.conf..." + setupVars=/etc/pihole/setupVars.conf + if [[ -f ${setupVars} ]];then + echo " found!" + log_write "/etc/pihole/setupVars.conf exists! Contents:" + while read -r line; do + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue + log_write "${line}" + fi + done < "${setupVars}" + log_write "" + + . "${setupVars}" + if [[ -n "${piholeInterface}" ]]; then + # prepend % to the beginning of piholeInterface for later use + piholeInterface="%${piholeInterface}" + fi + else + echo " NOT FOUND!" + log_write "/etc/pihole/setupVars.conf not found!" + fi +} + distro_check() { echo "############################################################" >> ${DEBUG_LOG} echo "######## Installed OS Distribution #########" >> ${DEBUG_LOG} @@ -138,7 +151,7 @@ ip_check() { GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo "::: Pinging default IPv6 gateway..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}""${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then echo "IPv6 Gateway check:" >> ${DEBUG_LOG} else @@ -146,7 +159,7 @@ ip_check() { fi echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888"${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then echo "IPv6 Internet check:" >> ${DEBUG_LOG} else @@ -190,8 +203,8 @@ portCheck() { echo "::: Detecting local server port 80 and 53 processes." - ${SUDO} lsof -i :80 >> ${DEBUG_LOG} - ${SUDO} lsof -i :53 >> ${DEBUG_LOG} + lsof -i :80 >> ${DEBUG_LOG} + lsof -i :53 >> ${DEBUG_LOG} echo >> ${DEBUG_LOG} } @@ -266,7 +279,7 @@ checkProcesses() { echo "" >> ${DEBUG_LOG} echo -n "${i}" >> "${DEBUG_LOG}" echo " processes status:" >> ${DEBUG_LOG} - ${SUDO} systemctl -l status "${i}" >> "${DEBUG_LOG}" + systemctl -l status "${i}" >> "${DEBUG_LOG}" done echo >> ${DEBUG_LOG} } @@ -288,7 +301,7 @@ debugLighttpd() { echo "No lighttpd.conf file found!" >> ${DEBUG_LOG} printf ":::\tNo lighttpd.conf file found\n" fi - + if [ -e "${LIGHTTPDERRFILE}" ]; then echo "#######################################" >> ${DEBUG_LOG} echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG} @@ -304,6 +317,7 @@ debugLighttpd() { ### END FUNCTIONS ### version_check +files_check distro_check ip_check hostnameCheck From c958bed4186802fa01f73a5b739740142ac9d29d Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 22:31:20 +0100 Subject: [PATCH 099/172] Consistency changes. Replace MOST uses of `echo >> ${DebugLog}` with usage of `log_write` function --- advanced/Scripts/piholeDebug.sh | 228 ++++++++++++++++---------------- 1 file changed, 114 insertions(+), 114 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 4accb79f..ea1e409b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -99,30 +99,30 @@ files_check() { } distro_check() { - echo "############################################################" >> ${DEBUG_LOG} - echo "######## Installed OS Distribution #########" >> ${DEBUG_LOG} - echo "############################################################" >> ${DEBUG_LOG} + log_write "############################################################" + log_write "######## Installed OS Distribution #########" + log_write "############################################################" echo "::: Checking installed OS Distribution release." TMP=$(cat /etc/*release || echo "Failed to find release") echo "::: Writing OS Distribution release to logfile." - echo "${TMP}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "${TMP}" + log_write "" } ip_check() { - echo "############################################################" >> ${DEBUG_LOG} - echo "######## IP Address Information #########" >> ${DEBUG_LOG} - echo "############################################################" >> ${DEBUG_LOG} + log_write "############################################################" + log_write "######## IP Address Information #########" + log_write "############################################################" echo "::: Writing local IPs to logfile" IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" - echo "${IPADDR}" >> ${DEBUG_LOG} + log_write "${IPADDR}" IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ - && echo "${IP6ADDR}" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + && log_write "${IP6ADDR}" || log_write "No IPv6 addresses found." + log_write "" echo "::: Locating default gateway and checking connectivity" GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) @@ -130,22 +130,22 @@ ip_check() { echo "::: Pinging default IPv4 gateway..." GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) if [[ $? = 0 ]]; then - echo "IPv4 Gateway check:" >> ${DEBUG_LOG} + log_write "IPv4 Gateway check:" else - echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG} + log_write "IPv4 Gateway check failed:" fi - echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "${GATEWAY_CHECK}" + log_write "" echo "::: Pinging Internet via IPv4..." INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) if [[ $? = 0 ]]; then - echo "IPv4 Internet check:" >> ${DEBUG_LOG} + log_write "IPv4 Internet check:" else - echo "IPv4 Internet check failed:" >> ${DEBUG_LOG} + log_write "IPv4 Internet check failed:" fi - echo "${INET_CHECK}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "${INET_CHECK}" + log_write "" fi GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) @@ -153,65 +153,65 @@ ip_check() { echo "::: Pinging default IPv6 gateway..." GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}""${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then - echo "IPv6 Gateway check:" >> ${DEBUG_LOG} + log_write "IPv6 Gateway check:" else - echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG} + log_write "IPv6 Gateway check failed:" fi echo "::: Pinging Internet via IPv6..." GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888"${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then - echo "IPv6 Internet check:" >> ${DEBUG_LOG} + log_write "IPv6 Internet check:" else - echo "IPv6 Internet check failed:" >> ${DEBUG_LOG} + log_write "IPv6 Internet check failed:" fi else GATEWAY_CHECK="No IPv6 Gateway Detected" fi - echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG} + log_write "${GATEWAY_CHECK}" - echo >> ${DEBUG_LOG} + log_write "" } hostnameCheck() { - echo "############################################################" >> ${DEBUG_LOG} - echo "######## Hostname Information #########" >> ${DEBUG_LOG} - echo "############################################################" >> ${DEBUG_LOG} + log_write "############################################################" + log_write "######## Hostname Information #########" + log_write "############################################################" echo "::: Writing locally configured hostnames to logfile" # Write the hostname output to compare against entries in /etc/hosts, which is logged next - echo "This Pi-hole is: $(hostname)" >> ${DEBUG_LOG} + log_write "This Pi-hole is: $(hostname)" echo "::: Writing hosts file to debug log..." - echo "### Hosts ###" >> ${DEBUG_LOG} + log_write "### Hosts ###" if [ -e "${HOSTSFILE}" ]; then cat "${HOSTSFILE}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "" else - echo "No hosts file found!" >> ${DEBUG_LOG} + log_write "No hosts file found!" printf ":::\tNo hosts file found!\n" fi } portCheck() { - echo "############################################################" >> ${DEBUG_LOG} - echo "######## Open Port Information #########" >> ${DEBUG_LOG} - echo "############################################################" >> ${DEBUG_LOG} + log_write "############################################################" + log_write "######## Open Port Information #########" + log_write "############################################################" echo "::: Detecting local server port 80 and 53 processes." lsof -i :80 >> ${DEBUG_LOG} lsof -i :53 >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "" } testResolver() { - echo "############################################################" >> ${DEBUG_LOG} - echo "############ Resolver Functions Check ############" >> ${DEBUG_LOG} - echo "############################################################" >> ${DEBUG_LOG} + log_write "############################################################" + log_write "############ Resolver Functions Check ############" + log_write "############################################################" # Find a blocked url that has not been whitelisted. @@ -231,87 +231,87 @@ testResolver() { done < "${GRAVITYFILE}" fi - echo "Resolution of ${TESTURL} from Pi-hole:" >> ${DEBUG_LOG} + log_write "Resolution of ${TESTURL} from Pi-hole:" LOCALDIG=$(dig "${TESTURL}" @127.0.0.1) if [[ $? = 0 ]]; then - echo "${LOCALDIG}" >> ${DEBUG_LOG} + log_write "${LOCALDIG}" else - echo "Failed to resolve ${TESTURL} on Pi-hole" >> ${DEBUG_LOG} + log_write "Failed to resolve ${TESTURL} on Pi-hole" fi - echo >> ${DEBUG_LOG} + log_write "" - echo "Resolution of ${TESTURL} from 8.8.8.8:" >> ${DEBUG_LOG} + log_write "Resolution of ${TESTURL} from 8.8.8.8:" REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8) if [[ $? = 0 ]]; then - echo "${REMOTEDIG}" >> ${DEBUG_LOG} + log_write "${REMOTEDIG}" else - echo "Failed to resolve ${TESTURL} on 8.8.8.8" >> ${DEBUG_LOG} + log_write "Failed to resolve ${TESTURL} on 8.8.8.8" fi - echo >> ${DEBUG_LOG} + log_write "" - echo "Pi-hole dnsmasq specific records lookups" >> ${DEBUG_LOG} - echo "Cache Size:" >> ${DEBUG_LOG} + log_write "Pi-hole dnsmasq specific records lookups" + log_write "Cache Size:" dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} - echo "Insertions count:" >> ${DEBUG_LOG} + log_write "Insertions count:" dig +short chaos txt insertions.bind >> ${DEBUG_LOG} - echo "Evictions count:" >> ${DEBUG_LOG} + log_write "Evictions count:" dig +short chaos txt evictions.bind >> ${DEBUG_LOG} - echo "Misses count:" >> ${DEBUG_LOG} + log_write "Misses count:" dig +short chaos txt misses.bind >> ${DEBUG_LOG} - echo "Hits count:" >> ${DEBUG_LOG} + log_write "Hits count:" dig +short chaos txt hits.bind >> ${DEBUG_LOG} - echo "Auth count:" >> ${DEBUG_LOG} + log_write "Auth count:" dig +short chaos txt auth.bind >> ${DEBUG_LOG} - echo "Upstream Servers:" >> ${DEBUG_LOG} + log_write "Upstream Servers:" dig +short chaos txt servers.bind >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "" } checkProcesses() { - echo "#######################################" >> ${DEBUG_LOG} - echo "########### Processes Check ###########" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} - echo ":::" + log_write "#######################################" + log_write "########### Processes Check ###########" + log_write "#######################################" + log_write ":::" echo "::: Logging status of lighttpd and dnsmasq..." PROCESSES=( lighttpd dnsmasq ) for i in "${PROCESSES[@]}"; do - echo "" >> ${DEBUG_LOG} - echo -n "${i}" >> "${DEBUG_LOG}" - echo " processes status:" >> ${DEBUG_LOG} + log_write "" + log_write -n "${i}" + log_write " processes status:" systemctl -l status "${i}" >> "${DEBUG_LOG}" done - echo >> ${DEBUG_LOG} + log_write "" } debugLighttpd() { - echo "::: Writing lighttpd to debug log..." - echo "#######################################" >> ${DEBUG_LOG} - echo "############ lighttpd.conf ############" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} + log_write "::: Writing lighttpd to debug log..." + log_write "#######################################" + log_write "############ lighttpd.conf ############" + log_write "#######################################" if [ -e "${LIGHTTPDFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue - echo "${line}" >> ${DEBUG_LOG} + log_write "${line}" fi done < "${LIGHTTPDFILE}" - echo >> ${DEBUG_LOG} + log_write "" else - echo "No lighttpd.conf file found!" >> ${DEBUG_LOG} + log_write "No lighttpd.conf file found!" printf ":::\tNo lighttpd.conf file found\n" fi if [ -e "${LIGHTTPDERRFILE}" ]; then - echo "#######################################" >> ${DEBUG_LOG} - echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} + log_write "#######################################" + log_write "######### lighttpd error.log ##########" + log_write "#######################################" cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG} else - echo "No lighttpd error.log file found!" >> ${DEBUG_LOG} + log_write "No lighttpd error.log file found!" printf ":::\tNo lighttpd error.log file found\n" fi - echo >> ${DEBUG_LOG} + log_write "" } ### END FUNCTIONS ### @@ -327,92 +327,92 @@ testResolver debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." -echo "#######################################" >> ${DEBUG_LOG} -echo "############### Dnsmasq ###############" >> ${DEBUG_LOG} -echo "#######################################" >> ${DEBUG_LOG} +log_write "#######################################" +log_write "############### Dnsmasq ###############" +log_write "#######################################" if [ -e "${DNSMASQFILE}" ]; then #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue - echo "${line}" >> ${DEBUG_LOG} + log_write "${line}" fi done < "${DNSMASQFILE}" - echo >> ${DEBUG_LOG} + log_write "" else - echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG} + log_write "No dnsmasq.conf file found!" printf ":::\tNo dnsmasq.conf file found!\n" fi echo "::: Writing 01-pihole.conf to debug log..." -echo "#######################################" >> ${DEBUG_LOG} -echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG} -echo "#######################################" >> ${DEBUG_LOG} +log_write "#######################################" +log_write "########### 01-pihole.conf ############" +log_write "#######################################" if [ -e "${PIHOLECONFFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue - echo "${line}" >> ${DEBUG_LOG} + log_write "${line}" fi done < "${PIHOLECONFFILE}" - echo >> ${DEBUG_LOG} + log_write else - echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG} + log_write "No 01-pihole.conf file found!" printf ":::\tNo 01-pihole.conf file found\n" fi echo "::: Writing size of gravity.list to debug log..." -echo "#######################################" >> ${DEBUG_LOG} -echo "############ gravity.list #############" >> ${DEBUG_LOG} -echo "#######################################" >> ${DEBUG_LOG} +log_write "#######################################" +log_write "############ gravity.list #############" +log_write "#######################################" if [ -e "${GRAVITYFILE}" ]; then wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "" else - echo "No gravity.list file found!" >> ${DEBUG_LOG} + log_write "No gravity.list file found!" printf ":::\tNo gravity.list file found\n" fi ### Pi-hole application specific logging ### echo "::: Writing whitelist to debug log..." -echo "#######################################" >> ${DEBUG_LOG} -echo "############## Whitelist ##############" >> ${DEBUG_LOG} -echo "#######################################" >> ${DEBUG_LOG} +log_write "#######################################" +log_write "############## Whitelist ##############" +log_write "#######################################" if [ -e "${WHITELISTFILE}" ]; then cat "${WHITELISTFILE}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write else - echo "No whitelist.txt file found!" >> ${DEBUG_LOG} + log_write "No whitelist.txt file found!" printf ":::\tNo whitelist.txt file found!\n" fi echo "::: Writing blacklist to debug log..." -echo "#######################################" >> ${DEBUG_LOG} -echo "############## Blacklist ##############" >> ${DEBUG_LOG} -echo "#######################################" >> ${DEBUG_LOG} +log_write "#######################################" +log_write "############## Blacklist ##############" +log_write "#######################################" if [ -e "${BLACKLISTFILE}" ]; then cat "${BLACKLISTFILE}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write else - echo "No blacklist.txt file found!" >> ${DEBUG_LOG} + log_write "No blacklist.txt file found!" printf ":::\tNo blacklist.txt file found!\n" fi echo "::: Writing adlists.list to debug log..." -echo "#######################################" >> ${DEBUG_LOG} -echo "############ adlists.list #############" >> ${DEBUG_LOG} -echo "#######################################" >> ${DEBUG_LOG} +log_write "#######################################" +log_write "############ adlists.list #############" +log_write "#######################################" if [ -e "${ADLISTSFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue - echo "${line}" >> ${DEBUG_LOG} + log_write "${line}" fi done < "${ADLISTSFILE}" - echo >> ${DEBUG_LOG} + log_write else - echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG} + log_write "No adlists.list file found... using adlists.default!" printf ":::\tNo adlists.list file found... using adlists.default!\n" fi @@ -421,16 +421,16 @@ fi dumpPiHoleLog() { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT echo -e "::: Writing current Pi-hole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" - echo "#######################################" >> ${DEBUG_LOG} - echo "############# pihole.log ##############" >> ${DEBUG_LOG} - echo "#######################################" >> ${DEBUG_LOG} + log_write "#######################################" + log_write "############# pihole.log ##############" + log_write "#######################################" if [ -e "${PIHOLELOG}" ]; then while true; do tail -f "${PIHOLELOG}" >> ${DEBUG_LOG} - echo >> ${DEBUG_LOG} + log_write "" done else - echo "No pihole.log file found!" >> ${DEBUG_LOG} + log_write "No pihole.log file found!" printf ":::\tNo pihole.log file found!\n" fi } From 96053d13be419ae06f18d0d5b8f73a751283bdb7 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 22:36:50 +0100 Subject: [PATCH 100/172] Flip reload logic. Do not reload lists if no changes made to whitelist.txt --- advanced/Scripts/blacklist.sh | 2 +- advanced/Scripts/whitelist.sh | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 2a088318..f97e4b9e 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -35,7 +35,7 @@ basename=pihole piholeDir=/etc/${basename} adList=${piholeDir}/gravity.list blacklist=${piholeDir}/blacklist.txt -reload=true +reload=false addmode=true verbose=true diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index ee5958bf..07e976a3 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -36,7 +36,7 @@ basename=pihole piholeDir=/etc/${basename} adList=${piholeDir}/gravity.list whitelist=${piholeDir}/whitelist.txt -reload=true +reload=false addmode=true verbose=true @@ -77,6 +77,7 @@ AddDomain() { if ${verbose}; then echo -n "::: Adding $1 to $whitelist..." fi + reload=true echo "$1" >> ${whitelist} if ${verbose}; then echo " done!" @@ -99,6 +100,7 @@ RemoveDomain() { fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} + reload=true fi } From 476fd1f6959cd19e1914b4daa4d38c9251813fea Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 22:38:18 +0100 Subject: [PATCH 101/172] indentation --- advanced/Scripts/whitelist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 07e976a3..82ff3bb3 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -96,7 +96,7 @@ RemoveDomain() { if ${bool}; then #Domain is not in the whitelist file, no need to Remove if ${verbose}; then - echo "::: $1 is NOT whitelisted! No need to remove" + echo "::: $1 is NOT whitelisted! No need to remove" fi else echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} From bd0cc134bf1687143182e072aa747e1a4d472f4a Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 22:43:11 +0100 Subject: [PATCH 102/172] MERGE FAIL :ashamed_face: --- advanced/Scripts/blacklist.sh | 116 +++++++++++++--------------------- 1 file changed, 44 insertions(+), 72 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index f97e4b9e..0c780f24 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -35,7 +35,7 @@ basename=pihole piholeDir=/etc/${basename} adList=${piholeDir}/gravity.list blacklist=${piholeDir}/blacklist.txt -reload=false +reload=true addmode=true verbose=true @@ -48,87 +48,58 @@ HandleOther(){ if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" else - domList=("${domList[@]}" ${validDomain}) + domList=("${domList[@]}" ${validDomain}) fi } PopBlacklistFile() { #check blacklist file exists, and if not, create it - if [[ ! -f ${blacklist} ]]; then - touch ${blacklist} + if [[ ! -f ${blacklist} ]];then + touch ${blacklist} fi for dom in "${domList[@]}"; do - if "${addmode}"; then - AddDomain "${dom}" - else - RemoveDomain "${dom}" - fi + if "$addmode"; then + AddDomain "$dom" + else + RemoveDomain "$dom" + fi done } AddDomain() { - #| sed 's/\./\\./g' +#| sed 's/\./\\./g' bool=false grep -Ex -q "$1" ${blacklist} || bool=true if ${bool}; then - #domain not found in the blacklist file, add it! - if ${verbose}; then - echo -n "::: Adding $1 to blacklist file..." - fi - echo "${1}" >> ${blacklist} - modifyHost=true + #domain not found in the blacklist file, add it! + if ${verbose}; then + echo -n "::: Adding $1 to blacklist file..." + fi + echo "$1" >> ${blacklist} echo " done!" else if ${verbose}; then - echo "::: ${1} already exists in ${blacklist}! No need to add" + echo "::: $1 already exists in $blacklist! No need to add" fi fi } RemoveDomain() { - bool=false - grep -Ex -q "$1" ${blacklist} || bool=true - if ${bool}; then - #Domain is not in the blacklist file, no need to Remove - if ${verbose}; then - echo "::: $1 is NOT blacklisted! No need to remove" - fi - else - #Domain is in the blacklist file, remove it - if ${verbose}; then - echo "::: Un-blacklisting ${dom}..." - fi - echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} - fi -} -ModifyHostFile() { - if ${addmode}; then - #add domains to the hosts file - if [[ -r ${blacklist} ]]; then - numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l) - plural=; [[ "${numberOf}" != "1" ]] && plural=s - echo ":::" - echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." - if [[ -n ${piholeIPv6} ]]; then - cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} - else - cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList} - fi - fi - else - echo ":::" - for dom in "${domToRemoveList[@]}"; do - #we need to remove the domains from the blacklist file and the host file - echo "::: ${dom}" - echo -n "::: removing from HOSTS file..." - echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList} - echo " done!" - echo -n "::: removing from blackist.txt..." - echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} - echo " done!" - done - fi + bool=false + grep -Ex -q "$1" ${blacklist} || bool=true + if ${bool}; then + #Domain is not in the blacklist file, no need to Remove + if ${verbose}; then + echo "::: $1 is NOT blacklisted! No need to remove" + fi + else + #Domain is in the blacklist file,remove it + if ${verbose}; then + echo "::: Un-blacklisting $dom..." + fi + echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} + fi } Reload() { @@ -139,24 +110,25 @@ DisplayBlist() { verbose=false echo -e " Displaying Gravity Affected Domains \n" count=1 - while IFS= read -r AD; do - echo "${count}: ${AD}" + while IFS= read -r AD + do + echo "${count}: $AD" count=$((count+1)) - done < "${blacklist}" - exit 0; + done < "$blacklist" } ################################################### -for var in "$@"; do - case "$var" in - "-nr"| "--noreload" ) reload=false;; - "-d" | "--delmode" ) addmode=false;; - "-q" | "--quiet" ) verbose=false;; - "-h" | "--help" ) helpFunc;; - "-l" | "--list" ) DisplayBlist;; - * ) HandleOther "$var";; - esac +for var in "$@" +do + case "$var" in + "-nr"| "--noreload" ) reload=false;; + "-d" | "--delmode" ) addmode=false;; + "-q" | "--quiet" ) verbose=false;; + "-h" | "--help" ) helpFunc;; + "-l" | "--list" ) DisplayBlist;; + * ) HandleOther "$var";; + esac done PopBlacklistFile From 7fb622638bba81ff7ff941471b02c7df1f3dda5f Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 22:44:06 +0100 Subject: [PATCH 103/172] flip reload logic. Do not reload if there are not changes made to blacklist.txt --- advanced/Scripts/blacklist.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 0c780f24..2ce1c674 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -35,7 +35,7 @@ basename=pihole piholeDir=/etc/${basename} adList=${piholeDir}/gravity.list blacklist=${piholeDir}/blacklist.txt -reload=true +reload=false addmode=true verbose=true @@ -76,6 +76,7 @@ AddDomain() { echo -n "::: Adding $1 to blacklist file..." fi echo "$1" >> ${blacklist} + reload=true echo " done!" else if ${verbose}; then @@ -99,6 +100,7 @@ RemoveDomain() { echo "::: Un-blacklisting $dom..." fi echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} + reload=true fi } From b49384ffe41781511132b056daa5f2d14603428c Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 23 Oct 2016 22:44:21 +0100 Subject: [PATCH 104/172] intent --- advanced/Scripts/blacklist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 2ce1c674..acf0cf60 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -73,7 +73,7 @@ AddDomain() { if ${bool}; then #domain not found in the blacklist file, add it! if ${verbose}; then - echo -n "::: Adding $1 to blacklist file..." + echo -n "::: Adding $1 to blacklist file..." fi echo "$1" >> ${blacklist} reload=true From cb38f5f0d7b0d3217ef2cc35cf7b69e1149978cf Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 23 Oct 2016 15:50:03 -0700 Subject: [PATCH 105/172] Move attribution to bottom since our bots quote from top Bot's keeps quoting the attribution line in snippets (Discourse, GitLab, Mattermost) --- .github/ISSUE_TEMPLATE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index fc2d528e..08d2917d 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,5 +1,3 @@ -_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._ - **In raising this issue, I confirm the following (please check boxes, eg [X]):** - [ ] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). @@ -40,3 +38,5 @@ _{replace this section with your content or delete if not a FEATURE REQUEST/QUES **(Optional) Debug Log generated by `pihole -d`:** `http://termbin.com/` + +_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._ From 12596dd697dbf9b36f91b75bdb27757fc44b4d29 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 23 Oct 2016 15:50:59 -0700 Subject: [PATCH 106/172] Update PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 3eb26862..049928bd 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,5 +1,3 @@ -_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._ - **By submitting this pull request, I confirm the following (please check boxes, eg [X]):** - [ ] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). @@ -23,3 +21,6 @@ _This template was created based on the work of [`udemy-dl`](https://github.com/ --- _{replace this line with your pull request content}_ + + +_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._ From 519d731ddd4172ae20e312019ec3e8e1f3521ba3 Mon Sep 17 00:00:00 2001 From: Marcus Hildum Date: Sun, 23 Oct 2016 16:45:51 -0700 Subject: [PATCH 107/172] Fix missing newline My mistake --- automated install/basic-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7796fb52..dfed93a1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -469,7 +469,8 @@ setDNS() { exit 1 fi if [[ ${piholeDNS1} == "${strInvalid}" ]] || [[ ${piholeDNS2} == "${strInvalid}" ]]; then - whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: ${piholeDNS2}" ${r} ${c} if [[ ${piholeDNS1} == "${strInvalid}" ]]; then + whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: ${piholeDNS2}" ${r} ${c} + if [[ ${piholeDNS1} == "${strInvalid}" ]]; then piholeDNS1="" fi if [[ ${piholeDNS2} == "${strInvalid}" ]]; then From acff90c000e0483ccb282cdbb9d2d4a8abc2556d Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Mon, 24 Oct 2016 14:58:13 -0500 Subject: [PATCH 108/172] fix check box spacing I have seen several issues/PRs with the extra space. removing the extra whitespace might help to keep the formatting when being submitted. --- .github/ISSUE_TEMPLATE.md | 26 +++++++++++++------------- .github/PULL_REQUEST_TEMPLATE.md | 30 +++++++++++++++--------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 08d2917d..e265f6d0 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,21 +1,21 @@ **In raising this issue, I confirm the following (please check boxes, eg [X]):** -- [ ] 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)). +- [] 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)). **How familiar are you with the codebase?:** -- [ ] 1 (very unfamiliar) -- [ ] 2 -- [ ] 3 -- [ ] 4 -- [ ] 5 -- [ ] 6 -- [ ] 7 -- [ ] 8 -- [ ] 9 -- [ ] 10 (very familiar) +- [] 1 (very unfamiliar) +- [] 2 +- [] 3 +- [] 4 +- [] 5 +- [] 6 +- [] 7 +- [] 8 +- [] 9 +- [] 10 (very familiar) --- **[FEATURE REQUEST | QUESTION | OTHER]:** diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 049928bd..5f55e443 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,23 +1,23 @@ **By submitting this pull request, I confirm the following (please check boxes, eg [X]):** -- [ ] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). -- [ ] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist. -- [ ] I have considered, and confirmed that this submission will be valuable to others. -- [ ] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. -- [ ] I give this submission freely, and claim no ownership to its content. +- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). +- [] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist. +- [] I have considered, and confirmed that this submission will be valuable to others. +- [] I accept that this submission may not be used, and the pull request closed at the will of the maintainer. +- [] I give this submission freely, and claim no ownership to its content. **How familiar are you with the codebase?:** -- [ ] 1 (very unfamiliar) -- [ ] 2 -- [ ] 3 -- [ ] 4 -- [ ] 5 -- [ ] 6 -- [ ] 7 -- [ ] 8 -- [ ] 9 -- [ ] 10 (very familiar) +- [] 1 (very unfamiliar) +- [] 2 +- [] 3 +- [] 4 +- [] 5 +- [] 6 +- [] 7 +- [] 8 +- [] 9 +- [] 10 (very familiar) --- _{replace this line with your pull request content}_ From f3bf7c4b384941254f0bfa5621cee3b84682312e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 24 Oct 2016 14:48:38 -0700 Subject: [PATCH 109/172] Update ISSUE_TEMPLATE.md --- .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 e265f6d0..53f5b429 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,4 +1,4 @@ -**In raising this issue, I confirm the following (please check boxes, eg [X]):** +**In raising this issue, I confirm the following (please check boxes, eg [X]) Failure to fill the template will close your issue:** - [] 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* From 2f8015cbcaa6541eb1aaf0cfb25084abb8ef2d49 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 24 Oct 2016 14:50:47 -0700 Subject: [PATCH 110/172] Update PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 5f55e443..7291be41 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,4 +1,4 @@ -**By submitting this pull request, I confirm the following (please check boxes, eg [X]):** +**By submitting this pull request, I confirm the following (please check boxes, eg [X])Failure to fill the template will close your PR:** - [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). - [] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist. From ee927346b7cfcee3948a30ab797e745e4dd916d4 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Oct 2016 12:36:05 +0100 Subject: [PATCH 111/172] Update .pullapprove.yml Update to V2. Only require 2 approvers on development, and 3 on master --- .pullapprove.yml | 49 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/.pullapprove.yml b/.pullapprove.yml index db3c0a90..68b9acfc 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -1,19 +1,38 @@ -approve_by_comment: true -approve_regex: '^(Approved|:shipit:|:\+1:|Engage)' -reject_regex: '^(Rejected|:-1:|Borg)' -reset_on_push: true -author_approval: required -reviewers: - members: - - brantje - - dschaper - - jacobsalmela - - Mcat12 - - PromoFaux - name: pullapprove - required: 3 +version: 2 + always_pending: - title_regex: '(WIP|wip)' + title_regex: '(WIP|wip)' labels: - wip explanation: 'This PR is a work in progress...' + +group_defaults: + reset_on_push: + enabled: true + reject_value: -2 + approve_regex: '^(Approved|:shipit:|:\+1:|Engage)' + reject_regex: '^(Rejected|:-1:|Borg)' + author_approval: + auto: true + + +groups: + development: + approve_by_comment: + enabled: true + conditions: + branches: + - development + required: 2 + teams: + - gravity + + master: + approve_by_comment: + enabled: true + conditions: + branches: + - master + required: 3 + teams: + - gravity From eb52f81a5c3412a231bb6fa3ffd7b17ef8f0e8e3 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Oct 2016 14:54:10 +0100 Subject: [PATCH 112/172] add pi.hole entries to 01-pihole.conf --- advanced/01-pihole.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index fd8e27f2..02fc786a 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -20,6 +20,9 @@ # OR IN /etc/dnsmasq.conf # ############################################################################### +address=/pi.hole/@IPv4@ +address=/pi.hole/@IPv6@ + addn-hosts=/etc/pihole/gravity.list domain-needed From 911053f63f341b38dc484ba60a5943167b87528b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Oct 2016 15:00:18 +0100 Subject: [PATCH 113/172] Replace IPv4 and IPv6 tokens in 01-pihole.conf for pi.hole resolution. --- automated install/basic-install.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index dfed93a1..72e893b0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -536,6 +536,11 @@ version_check_dnsmasq() { else sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location} fi + #Replace IPv4 and IPv6 tokens in 01-pihole.conf for pi.hole resolution. + tmp = ${IPv4_address%/*} + sed -i "s/@IPv4@/$tmp/" ${dnsmasq_pihole_01_location} + sed -i "s/@IPv6@/$IPv6_address/" ${dnsmasq_pihole_01_location} + sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsmasq_conf} } From 7653b3d08831ada4f951ff1efc284e11ce387cc8 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Oct 2016 15:01:16 +0100 Subject: [PATCH 114/172] Remove pi.hole references in gravity.sh --- gravity.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 03aafabb..b4a512c6 100755 --- a/gravity.sh +++ b/gravity.sh @@ -244,19 +244,19 @@ gravity_hostFormat() { if [[ -n "${IPv4_address}" && -n "${IPv6_address}" ]];then # Both IPv4 and IPv6 - echo -e "$IPv4_address $hostname\n$IPv6_address $hostname\n$IPv4_address pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} + echo -e "$IPv4_address $hostname\n$IPv6_address $hostname" > ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then # Only IPv4 - echo -e "$IPv4_address $hostname\n$IPv4_address pi.hole" > ${piholeDir}/${accretionDisc} + echo -e "$IPv4_address $hostname" > ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then # Only IPv6 - echo -e "$IPv6_address $hostname\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc} + echo -e "$IPv6_address $hostname" > ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -z "${IPv4_address}" && -z "${IPv6_address}" ]];then From 18005ceee821b177426f95e24a53a096549f0f68 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Oct 2016 15:03:49 +0100 Subject: [PATCH 115/172] add hostname lines in 01-pihole.conf --- advanced/01-pihole.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 02fc786a..7ec37e3f 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -23,6 +23,9 @@ address=/pi.hole/@IPv4@ address=/pi.hole/@IPv6@ +address=/@HOSTNAME@/@IPv4@ +address=/@HOSTNAME@/@IPv6@ + addn-hosts=/etc/pihole/gravity.list domain-needed From 86349527e7c509f0152fc5370d27b2edd08c86dd Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Oct 2016 15:06:37 +0100 Subject: [PATCH 116/172] replace HOSTNAME tokens in 01-pihole.conf --- automated install/basic-install.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 72e893b0..0bc43b49 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -536,6 +536,18 @@ version_check_dnsmasq() { else sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location} fi + + if [[ -f /etc/hostname ]]; then + hostname=$( Date: Tue, 25 Oct 2016 15:07:29 +0100 Subject: [PATCH 117/172] remove hostname insertion into gravity.list from gravity.sh --- gravity.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/gravity.sh b/gravity.sh index b4a512c6..3268020e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -232,31 +232,20 @@ gravity_unique() { gravity_hostFormat() { # Format domain list as "192.168.x.x domain.com" echo "::: Formatting domains into a HOSTS file..." - if [[ -f /etc/hostname ]]; then - hostname=$( ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then # Only IPv4 - echo -e "$IPv4_address $hostname" > ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then # Only IPv6 - echo -e "$IPv6_address $hostname" > ${piholeDir}/${accretionDisc} cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} elif [[ -z "${IPv4_address}" && -z "${IPv6_address}" ]];then From 95f0b3710dea79da87856f724684c34106df8ee2 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Oct 2016 15:27:13 +0100 Subject: [PATCH 118/172] fix up logic --- automated install/basic-install.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0bc43b49..b03aaff7 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -537,21 +537,35 @@ version_check_dnsmasq() { sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location} fi + #sed -i "s/@HOSTNAME@/$hostname/" ${dnsmasq_pihole_01_location} + if [[ -f /etc/hostname ]]; then hostname=$( Date: Tue, 25 Oct 2016 15:29:02 +0100 Subject: [PATCH 119/172] actually fix up logic --- 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 b03aaff7..0f36a722 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -547,7 +547,7 @@ version_check_dnsmasq() { #Replace IPv4 and IPv6 tokens in 01-pihole.conf for pi.hole resolution. if [[ "${IPv4_address}" != "" ]]; then - tmp = ${IPv4_address%/*} + tmp=${IPv4_address%/*} sed -i "s/@IPv4@/$tmp/" ${dnsmasq_pihole_01_location} else sed -i '/^address=/pi.hole/@IPv4@/d' ${dnsmasq_pihole_01_location} @@ -555,7 +555,7 @@ version_check_dnsmasq() { fi if [[ "${IPv6_address}" != "" ]]; then - sed -i "s/@IPv4@/$IPv6_address/" ${dnsmasq_pihole_01_location} + sed -i "s/@IPv6@/$IPv6_address/" ${dnsmasq_pihole_01_location} else sed -i '/^address=/pi.hole/@IPv6@/d' ${dnsmasq_pihole_01_location} sed -i '/^address=/@HOSTNAME@/@IPv6@/d' ${dnsmasq_pihole_01_location} From 4c853defb25d9e51b82ed8aa9fdbf9d9834dea2d Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 25 Oct 2016 22:27:35 +0100 Subject: [PATCH 120/172] add if traps to check for existence of whitelist.txt / blacklist.txt --- gravity.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/gravity.sh b/gravity.sh index 03aafabb..f524e587 100755 --- a/gravity.sh +++ b/gravity.sh @@ -187,12 +187,16 @@ gravity_Schwarzchild() { gravity_Blacklist() { # Append blacklist entries if they exist - numBlacklisted=$(wc -l < "${blacklistFile}") - plural=; [[ "$numBlacklisted" != "1" ]] && plural=s + if [[ -f "${blacklistFile}" ]]; then + numBlacklisted=$(wc -l < "${blacklistFile}") + plural=; [[ "$numBlacklisted" != "1" ]] && plural=s + echo -n "::: BlackListing $numBlacklisted domain${plural}..." + cat ${blacklistFile} >> ${piholeDir}/${eventHorizon} + echo " done!" + else + echo "::: Nothing to blacklist!" + fi - echo -n "::: BlackListing $numBlacklisted domain${plural}..." - cat ${blacklistFile} >> ${piholeDir}/${eventHorizon} - echo " done!" } gravity_Whitelist() { @@ -209,15 +213,19 @@ gravity_Whitelist() { done echo " done!" - # Ensure adlist domains are in whitelist.txt + # Ensure adlist domains are in whitelist.txt ${whitelistScript} -nr -q "${urls[@]}" > /dev/null - # Remove anything in whitelist.txt from the Event Horizon - numWhitelisted=$(wc -l < "${whitelistFile}") - plural=; [[ "$numWhitelisted" != "1" ]] && plural=s - echo -n "::: Whitelisting $numWhitelisted domain${plural}..." - grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} - echo " done!" + if [[ -f "${whitelistFile}" ]]; then + # Remove anything in whitelist.txt from the Event Horizon + numWhitelisted=$(wc -l < "${whitelistFile}") + plural=; [[ "$numWhitelisted" != "1" ]] && plural=s + echo -n "::: Whitelisting $numWhitelisted domain${plural}..." + grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} + echo " done!" + else + echo "::: Nothing to whitelist!" + fi } gravity_unique() { From 01f17f9cbbcba0f4fb3f2f2089f4b325f6782cd4 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 17:19:33 -0700 Subject: [PATCH 121/172] Reduce header verbosity. New header writer. --- advanced/Scripts/piholeDebug.sh | 118 +++++++++++++------------------- 1 file changed, 47 insertions(+), 71 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ea1e409b..8f8425df 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -50,31 +50,33 @@ log_write() { echo "${1}" >> "${DEBUG_LOG}" } +header_write() { + echo "" >> "${DEBUG_LOG}" + echo "::: ${1}" >> "${DEBUG_LOG}" + echo "" >> "${DEBUG_LOG}" +} + version_check() { - log_write "############################################################" - log_write "########## Installed Versions ##########" - log_write "############################################################" + header_write "Installed Package Versions" + echo "::: Detecting Pi-hole installed versions." - echo "::: Detecting Pi-hole installed versions." pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ && log_write "Pi-hole Version: $pi_hole_ver" || log_write "Pi-hole git repository not detected." admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ && log_write "WebUI Version: $admin_ver" || log_write "Pi-hole Admin Pages git repository not detected." - echo "::: Writing lighttpd version to logfile." + echo "::: Writing lighttpd version to logfile." light_ver="$(lighttpd -v |& head -n1)" && log_write "${light_ver}" || log_write "lighttpd not installed." - echo "::: Writing PHP version to logfile." + echo "::: Writing PHP version to logfile." php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." } files_check() { - log_write "############################################################" - log_write "########## Files Check ##########" - log_write "############################################################" + header_write "Files Check" #Check existence of setupVars.conf, and source it to get configured network interface for later use in script. - echo -n "::: Detecting existence setupVars.conf..." + echo -n "::: Detecting existence setupVars.conf..." setupVars=/etc/pihole/setupVars.conf if [[ -f ${setupVars} ]];then echo " found!" @@ -93,30 +95,26 @@ files_check() { piholeInterface="%${piholeInterface}" fi else - echo " NOT FOUND!" + echo " NOT FOUND!" log_write "/etc/pihole/setupVars.conf not found!" fi } distro_check() { - log_write "############################################################" - log_write "######## Installed OS Distribution #########" - log_write "############################################################" + header_write "Installed OS Distribution" - echo "::: Checking installed OS Distribution release." + echo "::: Checking installed OS Distribution release." TMP=$(cat /etc/*release || echo "Failed to find release") - echo "::: Writing OS Distribution release to logfile." + echo "::: Writing OS Distribution release to logfile." log_write "${TMP}" log_write "" } ip_check() { - log_write "############################################################" - log_write "######## IP Address Information #########" - log_write "############################################################" + header_write "IP Address Information" - echo "::: Writing local IPs to logfile" + echo "::: Writing local IPs to logfile" IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" log_write "${IPADDR}" @@ -124,10 +122,10 @@ ip_check() { && log_write "${IP6ADDR}" || log_write "No IPv6 addresses found." log_write "" - echo "::: Locating default gateway and checking connectivity" + echo "::: Locating default gateway and checking connectivity" GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv4 gateway..." + echo "::: Pinging default IPv4 gateway..." GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) if [[ $? = 0 ]]; then log_write "IPv4 Gateway check:" @@ -137,7 +135,7 @@ ip_check() { log_write "${GATEWAY_CHECK}" log_write "" - echo "::: Pinging Internet via IPv4..." + echo "::: Pinging Internet via IPv4..." INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) if [[ $? = 0 ]]; then log_write "IPv4 Internet check:" @@ -150,7 +148,7 @@ ip_check() { GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv6 gateway..." + echo "::: Pinging default IPv6 gateway..." GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}""${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Gateway check:" @@ -158,7 +156,7 @@ ip_check() { log_write "IPv6 Gateway check failed:" fi - echo "::: Pinging Internet via IPv6..." + echo "::: Pinging Internet via IPv6..." GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888"${piholeInterface}" | tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Internet check:" @@ -176,15 +174,13 @@ ip_check() { } hostnameCheck() { - log_write "############################################################" - log_write "######## Hostname Information #########" - log_write "############################################################" + header_write "Hostname Information" - echo "::: Writing locally configured hostnames to logfile" + echo "::: Writing locally configured hostnames to logfile" # Write the hostname output to compare against entries in /etc/hosts, which is logged next log_write "This Pi-hole is: $(hostname)" - echo "::: Writing hosts file to debug log..." + echo "::: Writing hosts file to debug log..." log_write "### Hosts ###" if [ -e "${HOSTSFILE}" ]; then @@ -197,11 +193,9 @@ hostnameCheck() { } portCheck() { - log_write "############################################################" - log_write "######## Open Port Information #########" - log_write "############################################################" + header_write "Open Port Information" - echo "::: Detecting local server port 80 and 53 processes." + echo "::: Detecting local server port 80 and 53 processes." lsof -i :80 >> ${DEBUG_LOG} lsof -i :53 >> ${DEBUG_LOG} @@ -209,10 +203,7 @@ portCheck() { } testResolver() { - log_write "############################################################" - log_write "############ Resolver Functions Check ############" - log_write "############################################################" - + header_write "Resolver Functions Check" # Find a blocked url that has not been whitelisted. TESTURL="doubleclick.com" @@ -269,11 +260,9 @@ testResolver() { } checkProcesses() { - log_write "#######################################" - log_write "########### Processes Check ###########" - log_write "#######################################" - log_write ":::" - echo "::: Logging status of lighttpd and dnsmasq..." + header_write "Processes Check" + + echo "::: Logging status of lighttpd and dnsmasq..." PROCESSES=( lighttpd dnsmasq ) for i in "${PROCESSES[@]}"; do log_write "" @@ -285,10 +274,8 @@ checkProcesses() { } debugLighttpd() { - log_write "::: Writing lighttpd to debug log..." - log_write "#######################################" - log_write "############ lighttpd.conf ############" - log_write "#######################################" + header_write "lighttpd.conf" + if [ -e "${LIGHTTPDFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then @@ -303,9 +290,10 @@ debugLighttpd() { fi if [ -e "${LIGHTTPDERRFILE}" ]; then - log_write "#######################################" - log_write "######### lighttpd error.log ##########" - log_write "#######################################" + log_write "" + log_write "::: lighttpd error.log" + log_write "" + cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG} else log_write "No lighttpd error.log file found!" @@ -327,9 +315,7 @@ testResolver debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." -log_write "#######################################" -log_write "############### Dnsmasq ###############" -log_write "#######################################" +header_write "Dnsmasq configuration" if [ -e "${DNSMASQFILE}" ]; then #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do @@ -345,9 +331,8 @@ else fi echo "::: Writing 01-pihole.conf to debug log..." -log_write "#######################################" -log_write "########### 01-pihole.conf ############" -log_write "#######################################" +header_write "01-pihole.conf" + if [ -e "${PIHOLECONFFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then @@ -362,9 +347,8 @@ else fi echo "::: Writing size of gravity.list to debug log..." -log_write "#######################################" -log_write "############ gravity.list #############" -log_write "#######################################" +header_write "gravity.list" + if [ -e "${GRAVITYFILE}" ]; then wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG} log_write "" @@ -376,9 +360,7 @@ fi ### Pi-hole application specific logging ### echo "::: Writing whitelist to debug log..." -log_write "#######################################" -log_write "############## Whitelist ##############" -log_write "#######################################" +header_write "Whitelist" if [ -e "${WHITELISTFILE}" ]; then cat "${WHITELISTFILE}" >> ${DEBUG_LOG} log_write @@ -388,9 +370,7 @@ else fi echo "::: Writing blacklist to debug log..." -log_write "#######################################" -log_write "############## Blacklist ##############" -log_write "#######################################" +header_write "Blacklist" if [ -e "${BLACKLISTFILE}" ]; then cat "${BLACKLISTFILE}" >> ${DEBUG_LOG} log_write @@ -400,9 +380,7 @@ else fi echo "::: Writing adlists.list to debug log..." -log_write "#######################################" -log_write "############ adlists.list #############" -log_write "#######################################" +header_write "adlists.list" if [ -e "${ADLISTSFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then @@ -421,9 +399,7 @@ fi dumpPiHoleLog() { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT echo -e "::: Writing current Pi-hole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" - log_write "#######################################" - log_write "############# pihole.log ##############" - log_write "#######################################" + header_write "pihole.log" if [ -e "${PIHOLELOG}" ]; then while true; do tail -f "${PIHOLELOG}" >> ${DEBUG_LOG} From fb70fd77e8d0e05ebe7836d32c9bed3edd7eb0e7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 17:50:14 -0700 Subject: [PATCH 122/172] Prototype version_check, add helper functions for logging and echo. --- advanced/Scripts/piholeDebug.sh | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8f8425df..c62aa1eb 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -56,20 +56,24 @@ header_write() { echo "" >> "${DEBUG_LOG}" } +log_echo() { + echo "::: ${1}" + log_write "${1}" +} + version_check() { header_write "Installed Package Versions" echo "::: Detecting Pi-hole installed versions." pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_write "Pi-hole Version: $pi_hole_ver" || log_write "Pi-hole git repository not detected." + && log_echo "Pi-hole: $pi_hole_ver" || log_echo "Pi-hole git repository not detected." admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ - && log_write "WebUI Version: $admin_ver" || log_write "Pi-hole Admin Pages git repository not detected." - - echo "::: Writing lighttpd version to logfile." - light_ver="$(lighttpd -v |& head -n1)" && log_write "${light_ver}" || log_write "lighttpd not installed." - - echo "::: Writing PHP version to logfile." - php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed." + && log_echo "WebUI: $admin_ver" || log_echo "Pi-hole Admin Pages git repository not detected." + light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ + && log_echo "${light_ver}" || log_echo "lighttpd not installed." + php_ver="$(php -v |& head -n1)" \ + && log_echo "${php_ver}" || log_echo "PHP not installed." + echo ":::" } files_check() { From b0874fb23afba0a754c6c5bcc4bdaa8083a99bb9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 19:53:00 -0700 Subject: [PATCH 123/172] Temporarily get rid of gateway sourcing from setupVars, temporarily. --- advanced/Scripts/piholeDebug.sh | 54 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c62aa1eb..ef031108 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -65,43 +65,41 @@ version_check() { header_write "Installed Package Versions" echo "::: Detecting Pi-hole installed versions." - pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ + local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ && log_echo "Pi-hole: $pi_hole_ver" || log_echo "Pi-hole git repository not detected." - admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ + local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ && log_echo "WebUI: $admin_ver" || log_echo "Pi-hole Admin Pages git repository not detected." - light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ + local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ && log_echo "${light_ver}" || log_echo "lighttpd not installed." - php_ver="$(php -v |& head -n1)" \ + local php_ver="$(php -v |& head -n1)" \ && log_echo "${php_ver}" || log_echo "PHP not installed." echo ":::" } +source_variable() { + # Source file passed in as ${1} and add variable at ${2} to environment + source ${1} + echo $piholeInterface +} + files_check() { - header_write "Files Check" - - #Check existence of setupVars.conf, and source it to get configured network interface for later use in script. - echo -n "::: Detecting existence setupVars.conf..." - setupVars=/etc/pihole/setupVars.conf - if [[ -f ${setupVars} ]];then - echo " found!" - log_write "/etc/pihole/setupVars.conf exists! Contents:" - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue + header_write "File Check" + + #Check non-zero length existence of ${1} + echo "::: Detecting existence of ${1}..." + local searchFile=/etc/pihole/"${1}" + if [[ -s ${searchFile} ]]; then + log_echo "/etc/pihole/${1} exists!" + while read -r line; do + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${setupVars}" - log_write "" - - . "${setupVars}" - if [[ -n "${piholeInterface}" ]]; then - # prepend % to the beginning of piholeInterface for later use - piholeInterface="%${piholeInterface}" - fi - else - echo " NOT FOUND!" - log_write "/etc/pihole/setupVars.conf not found!" - fi + done < "${searchFile}" + else + log_echo "/etc/pihole/${1} not found!" + fi + echo ":::" } distro_check() { @@ -309,7 +307,7 @@ debugLighttpd() { ### END FUNCTIONS ### version_check -files_check +files_check "setupVars.conf" distro_check ip_check hostnameCheck From 2fa47aaf31607cb5c0364dcda298fedeb9c940fc Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 20:53:18 -0700 Subject: [PATCH 124/172] Source routing is deprecated by RFC5095 --- advanced/Scripts/piholeDebug.sh | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ef031108..1c060a92 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -115,27 +115,23 @@ distro_check() { ip_check() { header_write "IP Address Information" + echo $piholeInterface - echo "::: Writing local IPs to logfile" - IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" - log_write "${IPADDR}" + echo "::: Collecting local IP info." + local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ + && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." + + local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ + && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") || log_echo "No IPv6 addresses found." - IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ - && log_write "${IP6ADDR}" || log_write "No IPv6 addresses found." - log_write "" echo "::: Locating default gateway and checking connectivity" - GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) + local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo "::: Pinging default IPv4 gateway..." - GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) - if [[ $? = 0 ]]; then - log_write "IPv4 Gateway check:" - else - log_write "IPv4 Gateway check failed:" - fi - log_write "${GATEWAY_CHECK}" - log_write "" + local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ + && echo "::: IPv4 Default Gateway Responded." || echo "::: IPv4 Default Gateway did not respond." + log_write "${IPv4_def_gateway_check}" echo "::: Pinging Internet via IPv4..." INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) @@ -151,7 +147,7 @@ ip_check() { GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo "::: Pinging default IPv6 gateway..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}""${piholeInterface}" | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n "${GATEWAY6}" ) if [[ $? = 0 ]]; then log_write "IPv6 Gateway check:" else @@ -159,7 +155,7 @@ ip_check() { fi echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888"${piholeInterface}" | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Internet check:" else @@ -167,7 +163,7 @@ ip_check() { fi else - GATEWAY_CHECK="No IPv6 Gateway Detected" + GATEWAY6_CHECK="No IPv6 Gateway Detected" fi log_write "${GATEWAY_CHECK}" From f549618d127f3b2313c04581b9b730001c2d69ac Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 21:25:57 -0700 Subject: [PATCH 125/172] Move environment IPv6 interface check to `ip_check` and fix IPv6 source routing issue. --- advanced/Scripts/piholeDebug.sh | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 1c060a92..c09dfed9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -115,7 +115,10 @@ distro_check() { ip_check() { header_write "IP Address Information" - echo $piholeInterface + # Get the current interface for Internet traffic + local IPv6_temp_interface=$(ip -6 r | grep default | cut -d ' ' -f 5) + # If declared in setupVars.conf use it, otherwise defer to default + local IPv6_interface=${piholeInterface:-$IPv6_temp_interface} echo "::: Collecting local IP info." local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ @@ -134,28 +137,20 @@ ip_check() { log_write "${IPv4_def_gateway_check}" echo "::: Pinging Internet via IPv4..." - INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) - if [[ $? = 0 ]]; then - log_write "IPv4 Internet check:" - else - log_write "IPv4 Internet check failed:" - fi - log_write "${INET_CHECK}" - log_write "" + local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ + && echo "::: IPv4 Internet query responded." || echo "::: IPv4 Internet query did not respond." + log_write "${IPv4_inet_check}" fi - GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) + local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo "::: Pinging default IPv6 gateway..." - GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n "${GATEWAY6}" ) - if [[ $? = 0 ]]; then - log_write "IPv6 Gateway check:" - else - log_write "IPv6 Gateway check failed:" - fi + local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ + && echo "::: IPv6 Default Gateway Responded." || echo "::: IPv6 Default Gateway did not respond." + log_write "${IPv6_def_gateway_check}" echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) + GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) if [[ $? = 0 ]]; then log_write "IPv6 Internet check:" else @@ -165,7 +160,7 @@ ip_check() { else GATEWAY6_CHECK="No IPv6 Gateway Detected" fi - log_write "${GATEWAY_CHECK}" + log_write "${GATEWAY6_CHECK}" log_write "" From 8fa897aadb57f6a4a499b86c28e10181ab21338e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 21:39:28 -0700 Subject: [PATCH 126/172] Add back in sourcing files (setupVars.conf) and tweak `ip_check` --- advanced/Scripts/piholeDebug.sh | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c09dfed9..e71c34a8 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -76,26 +76,21 @@ version_check() { echo ":::" } -source_variable() { - # Source file passed in as ${1} and add variable at ${2} to environment - source ${1} - echo $piholeInterface -} - files_check() { header_write "File Check" #Check non-zero length existence of ${1} echo "::: Detecting existence of ${1}..." - local searchFile=/etc/pihole/"${1}" - if [[ -s ${searchFile} ]]; then + local search_file=/etc/pihole/"${1}" + if [[ -s ${search_file} ]]; then log_echo "/etc/pihole/${1} exists!" + source "${search_file}" &> /dev/null && log_echo "Successfully sourced ${search_file}" || log_echo "Could not source ${search_file}" while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${searchFile}" + done < "${search_file}" else log_echo "/etc/pihole/${1} not found!" fi @@ -150,20 +145,14 @@ ip_check() { log_write "${IPv6_def_gateway_check}" echo "::: Pinging Internet via IPv6..." - GATEWAY6_CHECK=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) - if [[ $? = 0 ]]; then - log_write "IPv6 Internet check:" - else - log_write "IPv6 Internet check failed:" - fi - + local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ + && echo "::: IPv6 Internet query responded." || echo "::: IPv6 Internet query did not respond." else - GATEWAY6_CHECK="No IPv6 Gateway Detected" + IPv6_inet_check="No IPv6 Gateway Detected" fi - log_write "${GATEWAY6_CHECK}" - - + log_write "${IPv6_inet_check}" log_write "" + echo ":::" } hostnameCheck() { From 4269626f5d426406f4ed98cb74322870b77aaef9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 25 Oct 2016 21:53:41 -0700 Subject: [PATCH 127/172] Attribute source for bashism. --- 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 e71c34a8..e87703de 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -101,11 +101,8 @@ distro_check() { header_write "Installed OS Distribution" echo "::: Checking installed OS Distribution release." - TMP=$(cat /etc/*release || echo "Failed to find release") - - echo "::: Writing OS Distribution release to logfile." - log_write "${TMP}" - log_write "" + local distro="$(cat /etc/*release)" && log_write "${distro}" || log_write "Distribution details not found." + echo ":::" } ip_check() { @@ -113,6 +110,7 @@ ip_check() { # Get the current interface for Internet traffic local IPv6_temp_interface=$(ip -6 r | grep default | cut -d ' ' -f 5) # If declared in setupVars.conf use it, otherwise defer to default + # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash local IPv6_interface=${piholeInterface:-$IPv6_temp_interface} echo "::: Collecting local IP info." From 469ff45f0100d22c3419489a60c292018f15c544 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 26 Oct 2016 09:36:02 +0100 Subject: [PATCH 128/172] create list.sh. Combines whitelist and blacklist scripts in an effort to reduce code duplication. update pihole script to reflect new white/blacklist command. --- advanced/Scripts/list.sh | 166 +++++++++++++++++++++++++++++++++++++++ pihole | 6 +- 2 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 advanced/Scripts/list.sh diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh new file mode 100644 index 00000000..4884e354 --- /dev/null +++ b/advanced/Scripts/list.sh @@ -0,0 +1,166 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2015, 2016 by Jacob Salmela +# Network-wide ad blocking via your Raspberry Pi +# http://pi-hole.net +# Whitelists and blacklists domains +# +# Pi-hole is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +#globals +basename=pihole +piholeDir=/etc/${basename} +whitelist=${piholeDir}/whitelist.txt +blacklist=${piholeDir}/blacklist.txt +reload=false +addmode=true +verbose=true + +domList=() +domToRemoveList=() + +listMain="" +listAlt="" + +helpFunc() { + + if [[ ${listMain} == ${whitelist} ]]; then + letter="w" + word="white" + else + letter="b" + word="black" + fi + + 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 + exit 1 +} + +HandleOther(){ + #check validity of domain + validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') + 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}" + else + RemoveDomain "${dom}" "${listMain}" + fi + done +} + +AddDomain() { + + list="$2" + + bool=true + #Is the domain in the list we want to add it to? + grep -Ex -q "$1" ${list} || 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 +} + +RemoveDomain() { + list="$2" + + bool=true + #Is it in the other list? Logic follows that if its whitelisted it should not be blacklisted and vice versa + grep -Ex -q "$1" ${list} || bool=false + if [[ "${bool}" == true ]]; then + # Remove it from the other one + echo "::: Removing $1 from $list..." + echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${list} + reload=true + else + if [[ "${verbose}" == true ]]; then + echo "::: ${1} does not exist in ${list}, no need to remove!" + fi + fi +} + +Reload() { + # 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; +} + +for var in "$@"; do + case "${var}" in + "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; + "-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";; + "-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 +fi + +PoplistFile + +if ${reload}; then + Reload +fi + diff --git a/pihole b/pihole index 9a678393..4b197d12 100755 --- a/pihole +++ b/pihole @@ -22,14 +22,12 @@ if [[ ! $EUID -eq 0 ]];then fi whitelistFunc() { - shift - /opt/pihole/whitelist.sh "$@" + /opt/pihole/list.sh "$@" exit 0 } blacklistFunc() { - shift - /opt/pihole/blacklist.sh "$@" + /opt/pihole/list.sh "$@" exit 0 } From 0d6a6b97f96906ec8fa7eeb202d27f037389c213 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 26 Oct 2016 09:56:45 +0100 Subject: [PATCH 129/172] remove whitelist and blacklist scripts --- advanced/Scripts/blacklist.sh | 140 --------------------------------- advanced/Scripts/whitelist.sh | 141 ---------------------------------- 2 files changed, 281 deletions(-) delete mode 100755 advanced/Scripts/blacklist.sh delete mode 100755 advanced/Scripts/whitelist.sh diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh deleted file mode 100755 index acf0cf60..00000000 --- a/advanced/Scripts/blacklist.sh +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env bash -# Pi-hole: A black hole for Internet advertisements -# (c) 2015, 2016 by Jacob Salmela -# Network-wide ad blocking via your Raspberry Pi -# http://pi-hole.net -# Blacklists domains -# -# Pi-hole is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -helpFunc() { - cat << EOM -::: Immediately blacklists one or more domains in the hosts file -::: -::: -::: Usage: pihole -b domain1 [domain2 ...] -::: Options: -::: -d, --delmode Remove domains from the blacklist -::: -nr, --noreload Update blacklist without refreshing dnsmasq -::: -q, --quiet output is less verbose -::: -h, --help Show this help dialog -::: -l, --list Display your blacklisted domains -EOM - exit 1 -} - -if [[ $# = 0 ]]; then - helpFunc -fi - -#globals -basename=pihole -piholeDir=/etc/${basename} -adList=${piholeDir}/gravity.list -blacklist=${piholeDir}/blacklist.txt -reload=false -addmode=true -verbose=true - -domList=() -domToRemoveList=() - -HandleOther(){ - #check validity of domain - validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - if [ -z "$validDomain" ]; then - echo "::: $1 is not a valid argument or domain name" - else - domList=("${domList[@]}" ${validDomain}) - fi -} - -PopBlacklistFile() { - #check blacklist file exists, and if not, create it - if [[ ! -f ${blacklist} ]];then - touch ${blacklist} - fi - for dom in "${domList[@]}"; do - if "$addmode"; then - AddDomain "$dom" - else - RemoveDomain "$dom" - fi - done -} - -AddDomain() { -#| sed 's/\./\\./g' - bool=false - grep -Ex -q "$1" ${blacklist} || bool=true - if ${bool}; then - #domain not found in the blacklist file, add it! - if ${verbose}; then - echo -n "::: Adding $1 to blacklist file..." - fi - echo "$1" >> ${blacklist} - reload=true - echo " done!" - else - if ${verbose}; then - echo "::: $1 already exists in $blacklist! No need to add" - fi - fi -} - -RemoveDomain() { - - bool=false - grep -Ex -q "$1" ${blacklist} || bool=true - if ${bool}; then - #Domain is not in the blacklist file, no need to Remove - if ${verbose}; then - echo "::: $1 is NOT blacklisted! No need to remove" - fi - else - #Domain is in the blacklist file,remove it - if ${verbose}; then - echo "::: Un-blacklisting $dom..." - fi - echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} - reload=true - fi -} - -Reload() { - pihole -g -sd -} - -DisplayBlist() { - verbose=false - echo -e " Displaying Gravity Affected Domains \n" - count=1 - while IFS= read -r AD - do - echo "${count}: $AD" - count=$((count+1)) - done < "$blacklist" -} - -################################################### - -for var in "$@" -do - case "$var" in - "-nr"| "--noreload" ) reload=false;; - "-d" | "--delmode" ) addmode=false;; - "-q" | "--quiet" ) verbose=false;; - "-h" | "--help" ) helpFunc;; - "-l" | "--list" ) DisplayBlist;; - * ) HandleOther "$var";; - esac -done - -PopBlacklistFile - -if ${reload}; then - Reload -fi diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh deleted file mode 100755 index 82ff3bb3..00000000 --- a/advanced/Scripts/whitelist.sh +++ /dev/null @@ -1,141 +0,0 @@ -#!/usr/bin/env bash -# Pi-hole: A black hole for Internet advertisements -# (c) 2015, 2016 by Jacob Salmela -# Network-wide ad blocking via your Raspberry Pi -# http://pi-hole.net -# Whitelists domains -# -# Pi-hole is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - - -helpFunc() { - cat << EOM -::: Immediately whitelists one or more domains in the hosts file -::: -::: Usage: pihole -w domain1 [domain2 ...] -::: -::: Options: -::: -d, --delmode Remove domains from the whitelist -::: -nr, --noreload Update Whitelist without refreshing dnsmasq -::: -q, --quiet output is less verbose -::: -h, --help Show this help dialog -::: -l, --list Display your whitelisted domains -EOM - exit 1 -} - -if [[ $# = 0 ]]; then - helpFunc -fi - -#globals -basename=pihole -piholeDir=/etc/${basename} -adList=${piholeDir}/gravity.list -whitelist=${piholeDir}/whitelist.txt -reload=false -addmode=true -verbose=true - -domList=() -domToRemoveList=() - -HandleOther(){ - #check validity of domain - validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - if [ -z "${validDomain}" ]; then - echo "::: $1 is not a valid argument or domain name" - else - domList=("${domList[@]}" ${validDomain}) - fi -} - -PopWhitelistFile() { - #check whitelist file exists, and if not, create it - if [[ ! -f ${whitelist} ]]; then - touch ${whitelist} - fi - for dom in "${domList[@]}"; do - if ${addmode}; then - AddDomain "${dom}" - else - RemoveDomain "${dom}" - fi - done -} - -AddDomain() { - #| sed 's/\./\\./g' - bool=false - - grep -Ex -q "$1" ${whitelist} || bool=true - if ${bool}; then - #domain not found in the whitelist file, add it! - if ${verbose}; then - echo -n "::: Adding $1 to $whitelist..." - fi - reload=true - echo "$1" >> ${whitelist} - if ${verbose}; then - echo " done!" - fi - else - if ${verbose}; then - echo "::: ${1} already exists in ${whitelist}, no need to add!" - fi - fi -} - -RemoveDomain() { - - bool=false - grep -Ex -q "$1" ${whitelist} || bool=true - if ${bool}; then - #Domain is not in the whitelist file, no need to Remove - if ${verbose}; then - echo "::: $1 is NOT whitelisted! No need to remove" - fi - else - echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist} - reload=true - fi -} - -Reload() { - # Reload hosts file - pihole -g -sd -} - -DisplayWlist() { - verbose=false - echo -e " Displaying Gravity Resistant Domains \n" - count=1 - while IFS= read -r RD; do - echo "${count}: ${RD}" - count=$((count+1)) - done < "${whitelist}" - exit 0; -} - -################################################### - -for var in "$@"; do - case "${var}" in - "-nr"| "--noreload" ) reload=false;; - "-d" | "--delmode" ) addmode=false;; - "-f" | "--force" ) force=true;; - "-q" | "--quiet" ) verbose=false;; - "-h" | "--help" ) helpFunc;; - "-l" | "--list" ) DisplayWlist;; - * ) HandleOther "${var}";; - esac -done - -PopWhitelistFile - -if ${reload}; then - Reload -fi From 55a653aca422b0c3614c8bce21ce12cc4e7b5c64 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 26 Oct 2016 10:00:00 +0100 Subject: [PATCH 130/172] clear out /opt/pihole folder before installing scripts --- 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 dfed93a1..c2396bf5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -553,6 +553,8 @@ installScripts() { # Install the scripts from /etc/.pihole to their various locations echo ":::" echo -n "::: Installing scripts to /opt/pihole..." + #clear out /opt/pihole and recreate it. This allows us to remove scripts from future installs + rm -rf /opt/pihole install -o "${USER}" -m755 -d /opt/pihole cd /etc/.pihole/ From fc776921d5e19f5bfd71e2d88adc8b2977867508 Mon Sep 17 00:00:00 2001 From: Eric Warnke Date: Wed, 26 Oct 2016 09:59:22 -0400 Subject: [PATCH 131/172] stty is more compatible and does not require any additional dependancies for busybox --- 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 dfed93a1..2f55e1b0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -33,8 +33,8 @@ IPv4_address="" IPv6_address="" # Find the rows and columns -rows=$(tput lines) -columns=$(tput cols) +rows=$(stty size | awk '{print $1}') +columns=$(stty size | awk '{print $2}') # Divide by two so the dialogs take up half of the screen, which looks nice. r=$(( rows / 2 )) From ac8d24a1cea3a09877d97299e24adb2d8ec0cbd7 Mon Sep 17 00:00:00 2001 From: Eric Warnke Date: Wed, 26 Oct 2016 10:08:23 -0400 Subject: [PATCH 132/172] Even with no detected screen size, it should presume 80x24 --- automated install/basic-install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2f55e1b0..7af51c5b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -32,9 +32,10 @@ useUpdateVars=false IPv4_address="" IPv6_address="" -# Find the rows and columns -rows=$(stty size | awk '{print $1}') -columns=$(stty size | awk '{print $2}') +# 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) +rows=$(echo $screen_size | awk '{print $1}') +columns=$(echo $screen_size | awk '{print $2}') # Divide by two so the dialogs take up half of the screen, which looks nice. r=$(( rows / 2 )) From 4ed6e4d016d9c0aead21edb92cada243d248bd49 Mon Sep 17 00:00:00 2001 From: Eric Warnke Date: Wed, 26 Oct 2016 10:44:15 -0400 Subject: [PATCH 133/172] Tiny screens get sane minimums --- automated install/basic-install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7af51c5b..ae3a4529 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -40,6 +40,9 @@ columns=$(echo $screen_size | awk '{print $2}') # Divide by two so the dialogs take up half of the screen, which looks nice. r=$(( rows / 2 )) c=$(( columns / 2 )) +# Unless the screen is tiny +r=$(( r < 20 ? 20 : r )) +c=$(( c < 70 ? 70 : c )) ######## Undocumented Flags. Shhh ######## skipSpaceCheck=false From e2997b81352e9a68a46187c109df7c7f5360ad93 Mon Sep 17 00:00:00 2001 From: Eric Warnke Date: Tue, 25 Oct 2016 14:46:26 -0400 Subject: [PATCH 134/172] Due to lighttpd bug 2526 the url.rewrite for javascript must be placed outside of the $HTTP block or it will never evaluate. --- advanced/lighttpd.conf.debian | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/advanced/lighttpd.conf.debian b/advanced/lighttpd.conf.debian index 8b62f448..bf2e5104 100644 --- a/advanced/lighttpd.conf.debian +++ b/advanced/lighttpd.conf.debian @@ -52,10 +52,11 @@ $HTTP["url"] =~ "^/admin/" { ) } +# Rewite js requests, must be out of $HTTP block due to bug #2526 +url.rewrite = ( "^(?!/admin/).*\.js$" => "pihole/index.js" ) + # If the URL does not start with /admin, then it is a query for an ad domain $HTTP["url"] =~ "^(?!/admin)/.*" { # Create a response header for debugging using curl -I setenv.add-response-header = ( "X-Pi-hole" => "A black hole for Internet advertisements." ) - # rewrite only js requests - url.rewrite = ("(.*).js" => "pihole/index.js") } From f1c1caf7bdac56e4ae22d600cad9f5e70bbeac80 Mon Sep 17 00:00:00 2001 From: Eric Warnke Date: Tue, 25 Oct 2016 14:48:32 -0400 Subject: [PATCH 135/172] url.rewrite does not work in $HTTP block lighttpd bug #2526 --- advanced/lighttpd.conf.fedora | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/advanced/lighttpd.conf.fedora b/advanced/lighttpd.conf.fedora index 8b8e0692..fc00923c 100644 --- a/advanced/lighttpd.conf.fedora +++ b/advanced/lighttpd.conf.fedora @@ -69,10 +69,11 @@ $HTTP["url"] =~ "^/admin/" { setenv.add-response-header = ( "X-Pi-hole" => "The Pi-hole Web interface is working!" ) } +# Rewite js requests, must be out of $HTTP block due to bug #2526 +url.rewrite = ( "^(?!/admin/).*\.js$" => "pihole/index.js" ) + # If the URL does not start with /admin, then it is a query for an ad domain $HTTP["url"] =~ "^(?!/admin)/.*" { # Create a response header for debugging using curl -I setenv.add-response-header = ( "X-Pi-hole" => "A black hole for Internet advertisements." ) - # rewrite only js requests - url.rewrite = ("(.*).js" => "pihole/index.js") } From 98db002770fd2862c484a8c98103f71c8262a4c9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 11:38:19 -0700 Subject: [PATCH 136/172] Tighten IP test reponse to user. --- advanced/Scripts/piholeDebug.sh | 39 +++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e87703de..8636ef52 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -124,27 +124,27 @@ ip_check() { echo "::: Locating default gateway and checking connectivity" local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv4 gateway..." + echo -n "::: Pinging default IPv4 gateway: " local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ - && echo "::: IPv4 Default Gateway Responded." || echo "::: IPv4 Default Gateway did not respond." + && echo "Gateway responded." || echo "Gateway did not respond." log_write "${IPv4_def_gateway_check}" - echo "::: Pinging Internet via IPv4..." + echo -n "::: Pinging Internet via IPv4: " local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ - && echo "::: IPv4 Internet query responded." || echo "::: IPv4 Internet query did not respond." + && echo "Query responded." || echo "Query did not respond." log_write "${IPv4_inet_check}" fi local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo "::: Pinging default IPv6 gateway..." + echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ - && echo "::: IPv6 Default Gateway Responded." || echo "::: IPv6 Default Gateway did not respond." + && echo "Gateway Responded." || echo "Gateway did not respond." log_write "${IPv6_def_gateway_check}" - echo "::: Pinging Internet via IPv6..." + echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ - && echo "::: IPv6 Internet query responded." || echo "::: IPv6 Internet query did not respond." + && echo "Query responded." || echo "Query did not respond." else IPv6_inet_check="No IPv6 Gateway Detected" fi @@ -172,14 +172,18 @@ hostnameCheck() { fi } -portCheck() { - header_write "Open Port Information" - - echo "::: Detecting local server port 80 and 53 processes." - - lsof -i :80 >> ${DEBUG_LOG} - lsof -i :53 >> ${DEBUG_LOG} - log_write "" +daemon_check() { + # Check for daemon ${1} on port ${2} + header_write "Daemon Port Listening Information" + + echo "::: Checking port ${2} for ${1} listener." + local found_daemon=false + local ret_Val=$(lsof -i :${2} -FcL) \ + && (echo "::: Port ${2} is in use." && found_daemon=true) \ + || (echo "::: Port ${2} is not in use.") + if [[ found_daemon ]]; then + log_echo "Temporary holding place for evaluation code ${ret_Val}" + fi } testResolver() { @@ -289,7 +293,8 @@ files_check "setupVars.conf" distro_check ip_check hostnameCheck -portCheck +daemon_check lighttpd http +daemon_check dnsmasq domain checkProcesses testResolver debugLighttpd From 3a4fe3e391392e81bd00e05f2d0762aae63ca7b9 Mon Sep 17 00:00:00 2001 From: Eric Warnke Date: Wed, 26 Oct 2016 14:47:29 -0400 Subject: [PATCH 137/172] Wheezy install fix by selecting appropriate deps, made the php check the same --- automated install/basic-install.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ae3a4529..d8023637 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -75,9 +75,6 @@ fi if [ -x "$(command -v apt-get)" ]; then #Debian Family - #Decide if php should be `php5` or just `php` (Fixes issues with Ubuntu 16.04 LTS) - phpVer="php5" - apt-get install --dry-run php5 > /dev/null 2>&1 || phpVer="php" ############################################# PKG_MANAGER="apt-get" PKG_CACHE="/var/lib/apt/lists/" @@ -86,8 +83,15 @@ if [ -x "$(command -v apt-get)" ]; then PKG_INSTALL="${PKG_MANAGER} --yes --fix-missing 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" + # ######################################### + # fixes for dependancy differences + # Debian 7 doesn't have iproute2 use iproute + ${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1 && IPROUTE_PKG="iproute2" || IPROUTE_PKG="iproute" + # Ubuntu 16.04 LTS php / php5 fix + ${PKG_MANAGER} install --dry-run php5 > /dev/null 2>&1 && phpVer="php5" || phpVer="php" + # ######################################### INSTALLER_DEPS=( apt-utils whiptail git dhcpcd5) - PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron iproute2 ) + PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron ${IPROUTE_PKG} ) LIGHTTPD_USER="www-data" LIGHTTPD_GROUP="www-data" LIGHTTPD_CFG="lighttpd.conf.debian" From fc360abe43fae7ecf868bb904cc51ca353b79ce9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 12:22:20 -0700 Subject: [PATCH 138/172] Only check IPv6 if system is enabled. --- advanced/Scripts/piholeDebug.sh | 61 +++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8636ef52..2e457e31 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -26,6 +26,9 @@ ADLISTSFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" +# Default to no IPv6, will check and enable if needed. +IPV6=ENABLED=false + # Header info and introduction cat << EOM ::: Beginning Pi-hole debug at $(date)! @@ -105,22 +108,30 @@ distro_check() { echo ":::" } +ipv6_check() { + # Check if system is IPv6 enabled, for use in other functions + if [[ -a /proc/net/if_inet6 ]]; then + IPV6_ENABLED=true + return 0 + else + return 1 + fi +} + ip_check() { header_write "IP Address Information" # Get the current interface for Internet traffic - local IPv6_temp_interface=$(ip -6 r | grep default | cut -d ' ' -f 5) + + # Check if IPv6 enabled + local IPv6_interface + ipv6_check && IPv6_interface=${piholeInterface:-$(ip -6 r | grep default | cut -d ' ' -f 5)} # If declared in setupVars.conf use it, otherwise defer to default # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash - local IPv6_interface=${piholeInterface:-$IPv6_temp_interface} echo "::: Collecting local IP info." local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." - local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ - && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") || log_echo "No IPv6 addresses found." - - echo "::: Locating default gateway and checking connectivity" local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then @@ -135,22 +146,28 @@ ip_check() { log_write "${IPv4_inet_check}" fi - local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]]; then - echo -n "::: Pinging default IPv6 gateway: " - local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ - && echo "Gateway Responded." || echo "Gateway did not respond." - log_write "${IPv6_def_gateway_check}" - - echo -n "::: Pinging Internet via IPv6: " - local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ - && echo "Query responded." || echo "Query did not respond." - else - IPv6_inet_check="No IPv6 Gateway Detected" - fi - log_write "${IPv6_inet_check}" - log_write "" - echo ":::" + if [[ IPV6_ENABLED ]]; then + local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ + && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") \ + || log_echo "No IPv6 addresses found." + + local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) + if [[ $? = 0 ]]; then + echo -n "::: Pinging default IPv6 gateway: " + local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ + && echo "Gateway Responded." || echo "Gateway did not respond." + log_write "${IPv6_def_gateway_check}" + + echo -n "::: Pinging Internet via IPv6: " + local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ + && echo "Query responded." || echo "Query did not respond." + else + IPv6_inet_check="No IPv6 Gateway Detected" + fi + log_write "${IPv6_inet_check}" + log_write "" + echo ":::" + fi } hostnameCheck() { From f73734acb06a4d82db8b38c8f156e13abfce37bc Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 13:57:57 -0700 Subject: [PATCH 139/172] Only check IPv6 Gateway if it exists. --- advanced/Scripts/piholeDebug.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 2e457e31..39431371 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -152,7 +152,7 @@ ip_check() { || log_echo "No IPv6 addresses found." local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]]; then + if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ && echo "Gateway Responded." || echo "Gateway did not respond." @@ -164,8 +164,7 @@ ip_check() { else IPv6_inet_check="No IPv6 Gateway Detected" fi - log_write "${IPv6_inet_check}" - log_write "" + log_echo "${IPv6_inet_check}" echo ":::" fi } From 60741298b7332931c9d6a8f2d5c3573718223703 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 14:33:47 -0700 Subject: [PATCH 140/172] Cut more verbosity. Prep for `lsof` parsing and daemon tests. --- advanced/Scripts/piholeDebug.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 39431371..3071df07 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -132,7 +132,6 @@ ip_check() { local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." - echo "::: Locating default gateway and checking connectivity" local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo -n "::: Pinging default IPv4 gateway: " @@ -161,10 +160,10 @@ ip_check() { echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ && echo "Query responded." || echo "Query did not respond." + log_write "${IPv6_inet_check}" else - IPv6_inet_check="No IPv6 Gateway Detected" + log_echo="No IPv6 Gateway Detected" fi - log_echo "${IPv6_inet_check}" echo ":::" fi } @@ -188,18 +187,29 @@ hostnameCheck() { fi } +lsof_parse() { + # Dummy function for now + echo "Dummy function lsof_parse got called" + log_echo ${1} +} + daemon_check() { # Check for daemon ${1} on port ${2} header_write "Daemon Port Listening Information" echo "::: Checking port ${2} for ${1} listener." local found_daemon=false - local ret_Val=$(lsof -i :${2} -FcL) \ - && (echo "::: Port ${2} is in use." && found_daemon=true) \ - || (echo "::: Port ${2} is not in use.") - if [[ found_daemon ]]; then - log_echo "Temporary holding place for evaluation code ${ret_Val}" + local lsof_value + + if [[ ${IPV6_ENABLED} ]]; then + lsof_value=$(lsof -i 6:${2} -FcL) \ + && (echo "::: Port ${2} is in use on IPv6." && found_daemon=true && echo "${lsof_value}") \ + || (echo "::: Port ${2} is not in use.") fi + + lsof_value=$(lsof -i 4:${2} -FcL) \ + && (echo "::: Port ${2} is in use on IPv4." && found_daemon=true && echo "${lsof_value}") \ + || (echo "::: Port ${2} is not in use.") } testResolver() { From f169da8fd086ff7f962c1e6ba6f7c7eb4243bb29 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 26 Oct 2016 14:48:11 -0700 Subject: [PATCH 141/172] Set for quiet temporarily. --- advanced/Scripts/piholeDebug.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3071df07..a0385ceb 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -190,7 +190,6 @@ hostnameCheck() { lsof_parse() { # Dummy function for now echo "Dummy function lsof_parse got called" - log_echo ${1} } daemon_check() { @@ -202,12 +201,12 @@ daemon_check() { local lsof_value if [[ ${IPV6_ENABLED} ]]; then - lsof_value=$(lsof -i 6:${2} -FcL) \ + lsof_value=$(lsof -i 6:${2} -F0cL) \ && (echo "::: Port ${2} is in use on IPv6." && found_daemon=true && echo "${lsof_value}") \ || (echo "::: Port ${2} is not in use.") fi - lsof_value=$(lsof -i 4:${2} -FcL) \ + lsof_value=$(lsof -i 4:${2} -F0cL) \ && (echo "::: Port ${2} is in use on IPv4." && found_daemon=true && echo "${lsof_value}") \ || (echo "::: Port ${2} is not in use.") } From 13e488dacef0fcec941208cc0aed4d4062cb757f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Oct 2016 00:30:51 -0700 Subject: [PATCH 142/172] Daemon check for lighttpd and dnsmasq. --- advanced/Scripts/piholeDebug.sh | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index a0385ceb..ed22afa9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -188,10 +188,21 @@ hostnameCheck() { } lsof_parse() { - # Dummy function for now - echo "Dummy function lsof_parse got called" + local user + local process + local match + + user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) + process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) + if [[ ${2} -eq ${process} ]]; then + match="as required." + else + match="incorrectly." + fi + log_echo "by ${user} for ${process} ${match}" } + daemon_check() { # Check for daemon ${1} on port ${2} header_write "Daemon Port Listening Information" @@ -200,15 +211,19 @@ daemon_check() { local found_daemon=false local lsof_value + if [[ ${IPV6_ENABLED} ]]; then - lsof_value=$(lsof -i 6:${2} -F0cL) \ - && (echo "::: Port ${2} is in use on IPv6." && found_daemon=true && echo "${lsof_value}") \ - || (echo "::: Port ${2} is not in use.") + lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ + && (log_echo "Port ${2} is in use on IPv6" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + || (log_echo "Port ${2} is not in use on IPv6.") fi - lsof_value=$(lsof -i 4:${2} -F0cL) \ - && (echo "::: Port ${2} is in use on IPv4." && found_daemon=true && echo "${lsof_value}") \ - || (echo "::: Port ${2} is not in use.") + lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ + && (log_echo "Port ${2} is in use on IPv4" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + || (log_echo "Port ${2} is not in use on IPv4.") + if [[ "${found_daemon}" == false ]]; then + log_echo "Missing required daemon ${1}, please check configuration." + fi } testResolver() { From 36285ead57278c0ffd71f0f0a424fa66101a43eb Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Oct 2016 00:32:18 -0700 Subject: [PATCH 143/172] Just becuase this is bugging me, but I'll fix it later. --- 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 ed22afa9..07557891 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -418,7 +418,7 @@ else log_write "No adlists.list file found... using adlists.default!" printf ":::\tNo adlists.list file found... using adlists.default!\n" fi - +echo # Continuously append the pihole.log file to the pihole_debug.log file dumpPiHoleLog() { From f9570a82ccb93427783aa6060ebc2354b757f60c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Oct 2016 00:58:24 -0700 Subject: [PATCH 144/172] Remove glitchy daemon detection. --- advanced/Scripts/piholeDebug.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 07557891..b9216191 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -211,19 +211,15 @@ daemon_check() { local found_daemon=false local lsof_value - if [[ ${IPV6_ENABLED} ]]; then lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv6" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + && (log_echo "Port ${2} is in use on IPv6" && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv6.") fi lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv4" && (lsof_parse "${lsof_value}" "${1}" && found_daemon=true)) \ + && (log_echo "Port ${2} is in use on IPv4" && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") - if [[ "${found_daemon}" == false ]]; then - log_echo "Missing required daemon ${1}, please check configuration." - fi } testResolver() { From 60142cd960cecd6abac329243aa9e6c85b86521d Mon Sep 17 00:00:00 2001 From: Promofaux Date: Thu, 27 Oct 2016 11:06:11 +0100 Subject: [PATCH 145/172] remove reference to whitelist.sh (no longer exists) replace with `pihole -w` --- gravity.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index f524e587..1e4a3a93 100755 --- a/gravity.sh +++ b/gravity.sh @@ -29,8 +29,7 @@ EOM adListFile=/etc/pihole/adlists.list adListDefault=/etc/pihole/adlists.default -whitelistScript=/opt/pihole/whitelist.sh -blacklistScript=/opt/pihole/blacklist.sh +whitelistScript="pihole -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt From 9e4e1d1cb2d7b8a1293e510289a6c91581cf2985 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Thu, 27 Oct 2016 11:09:24 +0100 Subject: [PATCH 146/172] improve comments --- gravity.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 1e4a3a93..8373b4aa 100755 --- a/gravity.sh +++ b/gravity.sh @@ -185,7 +185,7 @@ gravity_Schwarzchild() { } gravity_Blacklist() { - # Append blacklist entries if they exist + # Append blacklist entries to eventHorizon if they exist if [[ -f "${blacklistFile}" ]]; then numBlacklisted=$(wc -l < "${blacklistFile}") plural=; [[ "$numBlacklisted" != "1" ]] && plural=s @@ -215,11 +215,13 @@ gravity_Whitelist() { # Ensure adlist domains are in whitelist.txt ${whitelistScript} -nr -q "${urls[@]}" > /dev/null + # Check whitelist.txt exists. if [[ -f "${whitelistFile}" ]]; then # Remove anything in whitelist.txt from the Event Horizon numWhitelisted=$(wc -l < "${whitelistFile}") plural=; [[ "$numWhitelisted" != "1" ]] && plural=s echo -n "::: Whitelisting $numWhitelisted domain${plural}..." + #print everything from preEventHorizon into eventHorizon EXCEPT domains in whitelist.txt grep -F -x -v -f ${whitelistFile} ${piholeDir}/${preEventHorizon} > ${piholeDir}/${eventHorizon} echo " done!" else From cde003bc98c965c1fba15cde9498a46311df5301 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Thu, 27 Oct 2016 11:13:00 +0100 Subject: [PATCH 147/172] \ all the /s! --- automated install/basic-install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0f36a722..6a305106 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -550,21 +550,21 @@ version_check_dnsmasq() { tmp=${IPv4_address%/*} sed -i "s/@IPv4@/$tmp/" ${dnsmasq_pihole_01_location} else - sed -i '/^address=/pi.hole/@IPv4@/d' ${dnsmasq_pihole_01_location} - sed -i '/^address=/@HOSTNAME@/@IPv4@/d' ${dnsmasq_pihole_01_location} + sed -i '/^address=\/pi.hole\/@IPv4@/d' ${dnsmasq_pihole_01_location} + sed -i '/^address=\/@HOSTNAME@\/@IPv4@/d' ${dnsmasq_pihole_01_location} fi if [[ "${IPv6_address}" != "" ]]; then sed -i "s/@IPv6@/$IPv6_address/" ${dnsmasq_pihole_01_location} else - sed -i '/^address=/pi.hole/@IPv6@/d' ${dnsmasq_pihole_01_location} - sed -i '/^address=/@HOSTNAME@/@IPv6@/d' ${dnsmasq_pihole_01_location} + sed -i '/^address=\/pi.hole\/@IPv6@/d' ${dnsmasq_pihole_01_location} + sed -i '/^address=\/@HOSTNAME@\/@IPv6@/d' ${dnsmasq_pihole_01_location} fi if [[ "${hostname}" != "" ]]; then sed -i "s/@HOSTNAME@/$hostname/" ${dnsmasq_pihole_01_location} else - sed -i '/^address=/@HOSTNAME@*/d' ${dnsmasq_pihole_01_location} + sed -i '/^address=\/@HOSTNAME@*/d' ${dnsmasq_pihole_01_location} fi sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsmasq_conf} From 794fa211372a4b6daa5e311d4454277abe229d57 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Thu, 27 Oct 2016 12:44:21 +0100 Subject: [PATCH 148/172] install uninstall.sh... --- automated install/basic-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 620ac17f..89191fed 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -565,6 +565,7 @@ installScripts() { install -o "${USER}" -Dm755 -t /opt/pihole/ gravity.sh install -o "${USER}" -Dm755 -t /opt/pihole/ ./advanced/Scripts/*.sh + install -o "${USER}" -Dm755 -t /opt/pihole/ ./automated\ install/uninstall.sh install -o "${USER}" -Dm755 -t /usr/local/bin/ pihole install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole From 300001e766b85ac67b847f213079a79fb2c7478d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 27 Oct 2016 11:56:16 -0700 Subject: [PATCH 149/172] Remove `listen-address` directive Since we declare an `interface` `dnsmasq` should ignore the `listen-address` directive thus making redundant. Removed. --- advanced/01-pihole.conf | 2 -- 1 file changed, 2 deletions(-) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index 7ec37e3f..f4707ef4 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -39,8 +39,6 @@ server=@DNS2@ interface=@INT@ -listen-address=127.0.0.1 - cache-size=10000 log-queries From 0debbffa703e73ad83387588da524bbe9e53ca74 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 03:45:07 -0700 Subject: [PATCH 150/172] Add a couple of parsing utility functions. --- advanced/Scripts/piholeDebug.sh | 70 ++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b9216191..b80c9584 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -50,7 +50,7 @@ fi ### Private functions exist here ### log_write() { - echo "${1}" >> "${DEBUG_LOG}" + echo "${1}" >> "${DEBUG_LOG}" } header_write() { @@ -60,7 +60,31 @@ header_write() { } log_echo() { - echo "::: ${1}" + case ${1} in + -n) + echo -n "::: ${2}" + log_write ${2} + ;; + -l) + echo "${2}" + log_write "${2}" + ;; + *) + echo "::: ${1}" + log_write "${1}" + esac +} + +file_parse() { + while read -r line; do + if [ ! -z "${line}" ]; then + [[ "${line}" =~ ^#.*$ ]] && continue + log_write "${line}" + fi + done < "${1}" +} + +block_parse() { log_write "${1}" } @@ -84,18 +108,13 @@ files_check() { #Check non-zero length existence of ${1} echo "::: Detecting existence of ${1}..." - local search_file=/etc/pihole/"${1}" + local search_file="${1}" if [[ -s ${search_file} ]]; then - log_echo "/etc/pihole/${1} exists!" - source "${search_file}" &> /dev/null && log_echo "Successfully sourced ${search_file}" || log_echo "Could not source ${search_file}" - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${search_file}" + log_echo -n "${1} exists" + source "${search_file}" &> /dev/null && log_echo -l " and successfully was sourced" || log_echo -l " and could not be sourced" + file_parse "${search_file}" else - log_echo "/etc/pihole/${1} not found!" + log_echo "${1} not found!" fi echo ":::" } @@ -104,7 +123,7 @@ distro_check() { header_write "Installed OS Distribution" echo "::: Checking installed OS Distribution release." - local distro="$(cat /etc/*release)" && log_write "${distro}" || log_write "Distribution details not found." + local distro="$(cat /etc/*release)" && block_parse "${distro}" || log_echo "Distribution details not found." echo ":::" } @@ -130,19 +149,22 @@ ip_check() { echo "::: Collecting local IP info." local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ - && (log_write "${IPv4_addr_list}" && echo "::: IPv4 addresses located") || log_echo "No IPv4 addresses found." + && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ + || log_echo "No IPv4 addresses found." local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then echo -n "::: Pinging default IPv4 gateway: " local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ - && echo "Gateway responded." || echo "Gateway did not respond." - log_write "${IPv4_def_gateway_check}" + && echo "Gateway responded." \ + || echo "Gateway did not respond." + block_parse "${IPv4_def_gateway_check}" echo -n "::: Pinging Internet via IPv4: " local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ - && echo "Query responded." || echo "Query did not respond." - log_write "${IPv4_inet_check}" + && echo "Query responded." \ + || echo "Query did not respond." + block_parse "${IPv4_inet_check}" fi if [[ IPV6_ENABLED ]]; then @@ -154,13 +176,15 @@ ip_check() { if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ - && echo "Gateway Responded." || echo "Gateway did not respond." - log_write "${IPv6_def_gateway_check}" + && echo "Gateway Responded." \ + || echo "Gateway did not respond." + block_parse "${IPv6_def_gateway_check}" echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ - && echo "Query responded." || echo "Query did not respond." - log_write "${IPv6_inet_check}" + && echo "Query responded." \ + || echo "Query did not respond." + block_parse "${IPv6_inet_check}" else log_echo="No IPv6 Gateway Detected" fi @@ -325,7 +349,7 @@ debugLighttpd() { ### END FUNCTIONS ### version_check -files_check "setupVars.conf" +files_check "/etc/pihole/setupVars.conf" distro_check ip_check hostnameCheck From e3c7a1f31f5d16fdb8543d3f523f021268fb630b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 03:49:03 -0700 Subject: [PATCH 151/172] Top half user output updated. --- advanced/Scripts/piholeDebug.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b80c9584..22a2a51a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -223,7 +223,7 @@ lsof_parse() { else match="incorrectly." fi - log_echo "by ${user} for ${process} ${match}" + log_echo -l "by ${user} for ${process} ${match}" } @@ -237,12 +237,12 @@ daemon_check() { if [[ ${IPV6_ENABLED} ]]; then lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv6" && lsof_parse "${lsof_value}" "${1}") \ + && (log_echo -n "IPv6 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv6.") fi lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ - && (log_echo "Port ${2} is in use on IPv4" && lsof_parse "${lsof_value}" "${1}") \ + && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") } From 42bff1ce1bda887b9cc49752667a0caee8390ce2 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 03:53:53 -0700 Subject: [PATCH 152/172] Move parse utility to be near other parsing functions. --- advanced/Scripts/piholeDebug.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 22a2a51a..385ca230 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -88,6 +88,20 @@ block_parse() { log_write "${1}" } +lsof_parse() { + local user + local process + local match + + user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) + process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) + if [[ ${2} -eq ${process} ]]; then + match="as required." + else + match="incorrectly." + fi + log_echo -l "by ${user} for ${process} ${match}" +} version_check() { header_write "Installed Package Versions" echo "::: Detecting Pi-hole installed versions." @@ -209,21 +223,7 @@ hostnameCheck() { log_write "No hosts file found!" printf ":::\tNo hosts file found!\n" fi -} - -lsof_parse() { - local user - local process - local match - - user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) - process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) - if [[ ${2} -eq ${process} ]]; then - match="as required." - else - match="incorrectly." - fi - log_echo -l "by ${user} for ${process} ${match}" + echo ":::" } From 90ec0a610e66734d57af0614fe0550dd10df9d00 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 04:42:45 -0700 Subject: [PATCH 153/172] Tricorder is introduced. --- advanced/Scripts/piholeDebug.sh | 48 ++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 385ca230..b9d18833 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -32,10 +32,15 @@ IPV6=ENABLED=false # Header info and introduction cat << EOM ::: Beginning Pi-hole debug at $(date)! -::: This debugging process will collect information from your running configuration, +::: +::: This debugging process will collect information from your Pi-hole, ::: and optionally upload the generated log to a unique and random directory on -::: Termbin.com. NOTE: All log files auto-delete after 1 month and you are the only -::: person who is given the unique URL. Please consider where you post this link. +::: tricorder.pi-hole.net. NOTE: All log files auto-delete after 24 hours and only +::: the Pi-hole developers can access your data via the generated token. We have taken +::: these extra steps to secure your data and we will work to further reduce any +::: personal information gathered. +::: +::: Please read and note any issues, and follow any directions advised during this process. ::: EOM @@ -214,15 +219,14 @@ hostnameCheck() { log_write "This Pi-hole is: $(hostname)" echo "::: Writing hosts file to debug log..." - log_write "### Hosts ###" + log_write "::: Hosts File Contents" - if [ -e "${HOSTSFILE}" ]; then - cat "${HOSTSFILE}" >> ${DEBUG_LOG} - log_write "" - else - log_write "No hosts file found!" - printf ":::\tNo hosts file found!\n" + if [[ -e "${HOSTSFILE}" ]]; then + file_parse "${HOSTSFILE}" + else + log_echo "No hosts file found!" fi + echo ":::" } @@ -244,6 +248,8 @@ daemon_check() { lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") + + echo ":::" } testResolver() { @@ -288,16 +294,10 @@ testResolver() { log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} - log_write "Insertions count:" - dig +short chaos txt insertions.bind >> ${DEBUG_LOG} - log_write "Evictions count:" - dig +short chaos txt evictions.bind >> ${DEBUG_LOG} log_write "Misses count:" dig +short chaos txt misses.bind >> ${DEBUG_LOG} log_write "Hits count:" dig +short chaos txt hits.bind >> ${DEBUG_LOG} - log_write "Auth count:" - dig +short chaos txt auth.bind >> ${DEBUG_LOG} log_write "Upstream Servers:" dig +short chaos txt servers.bind >> ${DEBUG_LOG} log_write "" @@ -458,24 +458,24 @@ dumpPiHoleLog() { # Anything to be done after capturing of pihole.log terminates finalWork() { + local tricorder echo "::: Finshed debugging!" - echo "::: The debug log can be uploaded to Termbin.com for easier sharing." + echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." read -r -p "::: Would you like to upload the log? [y/N] " response case ${response} in [yY][eE][sS]|[yY]) - TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) + tricorder=$(cat /var/log/pihole_debug.log | nc tricorder.pi-hole.net 9999) ;; *) - echo "::: Log will NOT be uploaded to Termbin." + echo "::: Log will NOT be uploaded to tricorder." ;; esac - # Check if termbin.com is reachable. When it's not, point to local log instead - if [ -n "${TERMBIN}" ]; then - echo "::: Debug log can be found at : ${TERMBIN}" - else - echo "::: Debug log can be found at : /var/log/pihole_debug.log" + # Check if tricorder.pi-hole.net is reachable and provide token. + if [ -n "${tricorder}" ]; then + echo "::: Your debug token is : ${tricorder}" fi + echo "::: Debug log can be found at : /var/log/pihole_debug.log" } trap finalWork EXIT From 01f10b56e8e4cc9a42f01d7571f8084bc16d2983 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 06:51:30 -0700 Subject: [PATCH 154/172] Refactor out some more reudndant code. --- advanced/Scripts/piholeDebug.sh | 49 ++++++++++++--------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b9d18833..fee8e87c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -107,6 +107,8 @@ lsof_parse() { fi log_echo -l "by ${user} for ${process} ${match}" } + + version_check() { header_write "Installed Package Versions" echo "::: Detecting Pi-hole installed versions." @@ -126,18 +128,25 @@ files_check() { header_write "File Check" #Check non-zero length existence of ${1} - echo "::: Detecting existence of ${1}..." + log_echo -n "Detecting existence of ${1}:" local search_file="${1}" if [[ -s ${search_file} ]]; then - log_echo -n "${1} exists" - source "${search_file}" &> /dev/null && log_echo -l " and successfully was sourced" || log_echo -l " and could not be sourced" - file_parse "${search_file}" + log_echo -l " exists" + file_parse "${search_file}" + return 0 else log_echo "${1} not found!" + return 1 fi echo ":::" } +source_file() { + local file_found=$(files_check "${1}") \ + && (source "${1}" &> /dev/null && log_echo -l "${file_found} and was successfully sourced") \ + || log_echo -l "${file_found} and could not be sourced" +} + distro_check() { header_write "Installed OS Distribution" @@ -318,38 +327,17 @@ checkProcesses() { } debugLighttpd() { - header_write "lighttpd.conf" - if [ -e "${LIGHTTPDFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${LIGHTTPDFILE}" - log_write "" - else - log_write "No lighttpd.conf file found!" - printf ":::\tNo lighttpd.conf file found\n" - fi - - if [ -e "${LIGHTTPDERRFILE}" ]; then - log_write "" - log_write "::: lighttpd error.log" - log_write "" - - cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG} - else - log_write "No lighttpd error.log file found!" - printf ":::\tNo lighttpd error.log file found\n" - fi - log_write "" + echo "::: Checking for necessary lighttpd files." + files_check "${LIGHTTPDFILE}" + files_check "${LIGHTTPDERRFILE}" + echo ":::" } ### END FUNCTIONS ### version_check -files_check "/etc/pihole/setupVars.conf" +source_file "/etc/pihole/setupVars.conf" distro_check ip_check hostnameCheck @@ -362,7 +350,6 @@ debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." header_write "Dnsmasq configuration" if [ -e "${DNSMASQFILE}" ]; then - #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue From 6a4a468022515797bfdca924a8bc51547703aeff Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 28 Oct 2016 15:02:03 +0100 Subject: [PATCH 155/172] Create .codeclimate.yml --- .codeclimate.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 00000000..e1cb3b50 --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,3 @@ +engines: + shellcheck: + enabled: true From c2cfc09f634c3d2a25028c2e07956a702c578927 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 07:06:05 -0700 Subject: [PATCH 156/172] Clean up more of the UX and log. Lots to go. --- advanced/Scripts/piholeDebug.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index fee8e87c..0d9317bd 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -68,7 +68,7 @@ log_echo() { case ${1} in -n) echo -n "::: ${2}" - log_write ${2} + log_write "${2}" ;; -l) echo "${2}" @@ -131,7 +131,7 @@ files_check() { log_echo -n "Detecting existence of ${1}:" local search_file="${1}" if [[ -s ${search_file} ]]; then - log_echo -l " exists" + echo " exists" file_parse "${search_file}" return 0 else From 71e3a473d6043a25d91a465c177a0faa9a937e61 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 07:16:16 -0700 Subject: [PATCH 157/172] Fix = underbar --- 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 0d9317bd..370049bb 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -27,7 +27,7 @@ PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" # Default to no IPv6, will check and enable if needed. -IPV6=ENABLED=false +IPV6_ENABLED=false # Header info and introduction cat << EOM From d4a3a5c18000492d1511e9e1362dc382d9e73f14 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 10:42:30 -0700 Subject: [PATCH 158/172] Trying to implement The Brontide Idiom for design. --- advanced/Scripts/piholeDebug.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 370049bb..71a3ce27 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -111,17 +111,22 @@ lsof_parse() { version_check() { header_write "Installed Package Versions" + + local error_found + error_found=0 + echo "::: Detecting Pi-hole installed versions." local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_echo "Pi-hole: $pi_hole_ver" || log_echo "Pi-hole git repository not detected." + && log_echo "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 "WebUI: $admin_ver" || log_echo "Pi-hole Admin Pages git repository not detected." + && log_echo "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 "${light_ver}" || log_echo "lighttpd not installed." + && log_echo "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) local php_ver="$(php -v |& head -n1)" \ - && log_echo "${php_ver}" || log_echo "PHP not installed." + && log_echo "${php_ver}" || (log_echo "PHP not installed." && error_found=1) echo ":::" + return "${error_found}" } files_check() { @@ -242,7 +247,7 @@ hostnameCheck() { daemon_check() { # Check for daemon ${1} on port ${2} - header_write "Daemon Port Listening Information" + header_write "Daemon Process Information" echo "::: Checking port ${2} for ${1} listener." local found_daemon=false @@ -258,6 +263,8 @@ daemon_check() { && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ || (log_echo "Port ${2} is not in use on IPv4.") + echo "${1}file" + echo ":::" } @@ -327,7 +334,6 @@ checkProcesses() { } debugLighttpd() { - echo "::: Checking for necessary lighttpd files." files_check "${LIGHTTPDFILE}" files_check "${LIGHTTPDERRFILE}" @@ -336,11 +342,15 @@ debugLighttpd() { ### END FUNCTIONS ### -version_check +# Gather version of required packages / repositories +version_check || echo "REQUIRED FILES MISSING" + source_file "/etc/pihole/setupVars.conf" distro_check ip_check -hostnameCheck +#hostnameCheck + + daemon_check lighttpd http daemon_check dnsmasq domain checkProcesses From 3da75d61253efe9ec293a5f747cf6d4fcd3e2698 Mon Sep 17 00:00:00 2001 From: Eric Warnke Date: Fri, 28 Oct 2016 17:28:04 -0400 Subject: [PATCH 159/172] Grep was leaking a file not found if blacklist didn't exist --- advanced/Scripts/list.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 4884e354..24f6d055 100644 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -82,7 +82,7 @@ AddDomain() { bool=true #Is the domain in the list we want to add it to? - grep -Ex -q "$1" ${list} || bool=false + grep -Ex -q "$1" ${list} > /dev/null 2>&1 || bool=false if [[ "${bool}" == false ]]; then #domain not found in the whitelist file, add it! @@ -104,7 +104,7 @@ RemoveDomain() { bool=true #Is it in the other list? Logic follows that if its whitelisted it should not be blacklisted and vice versa - grep -Ex -q "$1" ${list} || bool=false + grep -Ex -q "$1" ${list} > /dev/null 2>&1 || bool=false if [[ "${bool}" == true ]]; then # Remove it from the other one echo "::: Removing $1 from $list..." From 85fbd66871f5d5e5a3a42556183600dfe0d520c1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 14:52:08 -0700 Subject: [PATCH 160/172] Good commit point, number of changes --- advanced/Scripts/piholeDebug.sh | 192 ++++++++++++++------------------ 1 file changed, 85 insertions(+), 107 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 71a3ce27..20abe318 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -13,73 +13,77 @@ set -o pipefail ######## GLOBAL VARS ######## +VARSFILE="/etc/pihole/setupVars.conf" DEBUG_LOG="/var/log/pihole_debug.log" DNSMASQFILE="/etc/dnsmasq.conf" -PIHOLECONFFILE="/etc/dnsmasq.d/01-pihole.conf" +DNSMASQCONFFILE="/etc/dnsmasq.d/01-pihole.conf" LIGHTTPDFILE="/etc/lighttpd/lighttpd.conf" LIGHTTPDERRFILE="/var/log/lighttpd/error.log" GRAVITYFILE="/etc/pihole/gravity.list" -HOSTSFILE="/etc/hosts" WHITELISTFILE="/etc/pihole/whitelist.txt" BLACKLISTFILE="/etc/pihole/blacklist.txt" -ADLISTSFILE="/etc/pihole/adlists.list" +ADLISTFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" WHITELISTMATCHES="/tmp/whitelistmatches.list" -# Default to no IPv6, will check and enable if needed. -IPV6_ENABLED=false +IPV6_READY=false # Header info and introduction cat << EOM ::: Beginning Pi-hole debug at $(date)! ::: -::: This debugging process will collect information from your Pi-hole, -::: and optionally upload the generated log to a unique and random directory on -::: tricorder.pi-hole.net. NOTE: All log files auto-delete after 24 hours and only -::: the Pi-hole developers can access your data via the generated token. We have taken -::: these extra steps to secure your data and we will work to further reduce any -::: personal information gathered. +::: This process collects information from your Pi-hole, and optionally uploads +::: it to a unique and random directory on tricorder.pi-hole.net. ::: -::: Please read and note any issues, and follow any directions advised during this process. +::: NOTE: All log files auto-delete after 24 hours and ONLY the Pi-hole developers +::: can access your data via the given token. We have taken these extra steps to +::: secure your data and will work to further reduce any personal information gathered. ::: +::: 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. -if [ ! -f "${DEBUG_LOG}" ]; then - touch ${DEBUG_LOG} - chmod 644 ${DEBUG_LOG} - chown "$USER":root ${DEBUG_LOG} -else - truncate -s 0 ${DEBUG_LOG} -fi +truncate --size=0 "${DEBUG_LOG}" +chmod 644 ${DEBUG_LOG} +chown "$USER":pihole ${DEBUG_LOG} + +source ${VARSFILE} ### Private functions exist here ### log_write() { echo "${1}" >> "${DEBUG_LOG}" } -header_write() { - echo "" >> "${DEBUG_LOG}" - echo "::: ${1}" >> "${DEBUG_LOG}" - echo "" >> "${DEBUG_LOG}" -} - log_echo() { case ${1} in -n) echo -n "::: ${2}" log_write "${2}" ;; + -r) + echo "::: ${2}" + log_write "${2}" + ;; -l) echo "${2}" log_write "${2}" ;; + -e) + echo "${2}" + log_write + ;; *) - echo "::: ${1}" + echo "::: ${1}" log_write "${1}" esac } +header_write() { + log_echo "" + log_echo "${1}" + log_write "" +} + file_parse() { while read -r line; do if [ ! -z "${line}" ]; then @@ -87,6 +91,7 @@ file_parse() { log_write "${line}" fi done < "${1}" + log_write "" } block_parse() { @@ -101,42 +106,37 @@ lsof_parse() { user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) if [[ ${2} -eq ${process} ]]; then - match="as required." + echo "::: Correctly configured." else - match="incorrectly." + log_echo "::: Failure: Incorrectly configured daemon." fi - log_echo -l "by ${user} for ${process} ${match}" + log_write "Found user ${user} with process ${process}" } version_check() { - header_write "Installed Package Versions" + header_write "Detecting Installed Package Versions:" local error_found error_found=0 - echo "::: Detecting Pi-hole installed versions." - local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_echo "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) + && 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 "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) + && 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 "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) + && log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) local php_ver="$(php -v |& head -n1)" \ - && log_echo "${php_ver}" || (log_echo "PHP not installed." && error_found=1) - echo ":::" + && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) return "${error_found}" } files_check() { - header_write "File Check" - #Check non-zero length existence of ${1} - log_echo -n "Detecting existence of ${1}:" + header_write "Detecting existence of ${1}:" local search_file="${1}" if [[ -s ${search_file} ]]; then - echo " exists" + echo "::: File exists" file_parse "${search_file}" return 0 else @@ -148,22 +148,31 @@ files_check() { source_file() { local file_found=$(files_check "${1}") \ - && (source "${1}" &> /dev/null && log_echo -l "${file_found} and was successfully sourced") \ + && (source "${1}" &> /dev/null && echo "${file_found} and was successfully sourced") \ || log_echo -l "${file_found} and could not be sourced" } distro_check() { - header_write "Installed OS Distribution" + local soft_fail + header_write "Detecting installed OS Distribution" + soft_fail=0 + local distro="$(cat /etc/*release)" && block_parse "${distro}" || (log_echo "Distribution details not found." && soft_fail=1) + return "${soft_fail}" +} - echo "::: Checking installed OS Distribution release." - local distro="$(cat /etc/*release)" && block_parse "${distro}" || log_echo "Distribution details not found." - echo ":::" +processor_check() { + local soft_fail + header_write "Checking processor variety" + + soft_fail=0 + log_write $(uname -m) || soft_fail=1 + return "${soft_fail}" } ipv6_check() { # Check if system is IPv6 enabled, for use in other functions - if [[ -a /proc/net/if_inet6 ]]; then - IPV6_ENABLED=true + if [[ $IPv6_address ]]; then + ls /proc/net/if_inet6 &>/dev/null && IPV6_READY=true return 0 else return 1 @@ -180,40 +189,39 @@ ip_check() { # If declared in setupVars.conf use it, otherwise defer to default # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash - echo "::: Collecting local IP info." - local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ +local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ || log_echo "No IPv4 addresses found." local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]]; then - echo -n "::: Pinging default IPv4 gateway: " + echo -n "::: Pinging default IPv4 gateway: " local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ && echo "Gateway responded." \ || echo "Gateway did not respond." block_parse "${IPv4_def_gateway_check}" - echo -n "::: Pinging Internet via IPv4: " + echo -n "::: Pinging Internet via IPv4: " local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ && echo "Query responded." \ || echo "Query did not respond." block_parse "${IPv4_inet_check}" fi - if [[ IPV6_ENABLED ]]; then + if [[ IPV6_READY ]]; then local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") \ || log_echo "No IPv6 addresses found." local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then - echo -n "::: Pinging default IPv6 gateway: " + echo -n "::: Pinging default IPv6 gateway: " local IPv6_def_gateway_check="$(ping6 -q -W 3 -c 3 -n "${IPv6_def_gateway}" -I "${IPv6_interface}"| tail -n3)" \ && echo "Gateway Responded." \ || echo "Gateway did not respond." block_parse "${IPv6_def_gateway_check}" - echo -n "::: Pinging Internet via IPv6: " + echo -n "::: Pinging Internet via IPv6: " local IPv6_inet_check=$(ping6 -q -W 3 -c 3 -n 2001:4860:4860::8888 -I "${IPv6_interface}"| tail -n3) \ && echo "Query responded." \ || echo "Query did not respond." @@ -221,51 +229,28 @@ ip_check() { else log_echo="No IPv6 Gateway Detected" fi - echo ":::" fi } -hostnameCheck() { - header_write "Hostname Information" - - echo "::: Writing locally configured hostnames to logfile" - # Write the hostname output to compare against entries in /etc/hosts, which is logged next - log_write "This Pi-hole is: $(hostname)" +port_check() { + local lsof_value - echo "::: Writing hosts file to debug log..." - log_write "::: Hosts File Contents" - - if [[ -e "${HOSTSFILE}" ]]; then - file_parse "${HOSTSFILE}" - else - log_echo "No hosts file found!" - fi - - echo ":::" + lsof_value=$(lsof -i ${1}:${2} -FcL | tr '\n' ' ') \ + && lsof_parse "${lsof_value}" "${3}" \ + || log_echo "Failure: IPv${1} Port not in use" } - daemon_check() { # Check for daemon ${1} on port ${2} header_write "Daemon Process Information" - echo "::: Checking port ${2} for ${1} listener." - local found_daemon=false - local lsof_value - - if [[ ${IPV6_ENABLED} ]]; then - lsof_value=$(lsof -i 6:${2} -FcL | tr '\n' ' ') \ - && (log_echo -n "IPv6 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ - || (log_echo "Port ${2} is not in use on IPv6.") - fi + echo "::: Checking ${2} port for ${1} listener." + if [[ ${IPV6_READY} ]]; then + port_check 6 "${2}" "${1}" + fi lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ - && (log_echo -n "IPv4 Port ${2} is in use " && lsof_parse "${lsof_value}" "${1}") \ - || (log_echo "Port ${2} is not in use on IPv4.") - - echo "${1}file" - - echo ":::" + port_check 4 "${2}" "${1}" } testResolver() { @@ -344,9 +329,13 @@ debugLighttpd() { # Gather version of required packages / repositories version_check || echo "REQUIRED FILES MISSING" - +# Check for newer setupVars storage file source_file "/etc/pihole/setupVars.conf" -distro_check +# Gather information about the running distribution +distro_check || echo "Distro Check soft fail" +# Gather processor type +processor_check || echo "Processor Check soft fail" + ip_check #hostnameCheck @@ -357,31 +346,20 @@ checkProcesses testResolver debugLighttpd -echo "::: Writing dnsmasq.conf to debug log..." header_write "Dnsmasq configuration" -if [ -e "${DNSMASQFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${DNSMASQFILE}" - log_write "" -else - log_write "No dnsmasq.conf file found!" - printf ":::\tNo dnsmasq.conf file found!\n" -fi +files_check ${DNSMASQFILE} + echo "::: Writing 01-pihole.conf to debug log..." header_write "01-pihole.conf" -if [ -e "${PIHOLECONFFILE}" ]; then +if [ -e "${DNSMASQCONFFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${PIHOLECONFFILE}" + done < "${DNSMASQCONFFILE}" log_write else log_write "No 01-pihole.conf file found!" @@ -423,13 +401,13 @@ fi echo "::: Writing adlists.list to debug log..." header_write "adlists.list" -if [ -e "${ADLISTSFILE}" ]; then +if [ -e "${ADLISTFILE}" ]; then while read -r line; do if [ ! -z "${line}" ]; then [[ "${line}" =~ ^#.*$ ]] && continue log_write "${line}" fi - done < "${ADLISTSFILE}" + done < "${ADLISTFILE}" log_write else log_write "No adlists.list file found... using adlists.default!" From cb5c94ef5e5ab6e4c9b5b25b6559480b4c40e80c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:13:04 -0700 Subject: [PATCH 161/172] Sorry, left that gravity.list parser in. Big debug files. Cleared that up. --- advanced/Scripts/piholeDebug.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 20abe318..eac4a30f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -366,16 +366,12 @@ else printf ":::\tNo 01-pihole.conf file found\n" fi -echo "::: Writing size of gravity.list to debug log..." -header_write "gravity.list" -if [ -e "${GRAVITYFILE}" ]; then - wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG} - log_write "" -else - log_write "No gravity.list file found!" - printf ":::\tNo gravity.list file found\n" -fi +header_write "Analyzing gravity.list" + + gravity_length=$(wc -l "${GRAVITYFILE}") \ + && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ + || log_echo "Warning: No gravity.list file found!" ### Pi-hole application specific logging ### From d9a16b0ff406dba1ad68ed600eb80d3c821ce16b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:25:06 -0700 Subject: [PATCH 162/172] Clear up bottom half of script with fewer redundenicies. --- advanced/Scripts/piholeDebug.sh | 66 +++------------------------------ 1 file changed, 5 insertions(+), 61 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index eac4a30f..8ae9759c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -295,10 +295,6 @@ testResolver() { log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} - log_write "Misses count:" - dig +short chaos txt misses.bind >> ${DEBUG_LOG} - log_write "Hits count:" - dig +short chaos txt hits.bind >> ${DEBUG_LOG} log_write "Upstream Servers:" dig +short chaos txt servers.bind >> ${DEBUG_LOG} log_write "" @@ -346,25 +342,11 @@ checkProcesses testResolver debugLighttpd -header_write "Dnsmasq configuration" -files_check ${DNSMASQFILE} - - -echo "::: Writing 01-pihole.conf to debug log..." -header_write "01-pihole.conf" - -if [ -e "${DNSMASQCONFFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${DNSMASQCONFFILE}" - log_write -else - log_write "No 01-pihole.conf file found!" - printf ":::\tNo 01-pihole.conf file found\n" -fi +files_check "${DNSMASQFILE}" +files_check "${DNSMASQCONFFILE}" +files_check "${WHITELISTFILE}" +files_check "${BLACKLISTFILE}" +files_check "${ADLISTFILE}" header_write "Analyzing gravity.list" @@ -373,44 +355,6 @@ header_write "Analyzing gravity.list" && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ || log_echo "Warning: No gravity.list file found!" - -### Pi-hole application specific logging ### -echo "::: Writing whitelist to debug log..." -header_write "Whitelist" -if [ -e "${WHITELISTFILE}" ]; then - cat "${WHITELISTFILE}" >> ${DEBUG_LOG} - log_write -else - log_write "No whitelist.txt file found!" - printf ":::\tNo whitelist.txt file found!\n" -fi - -echo "::: Writing blacklist to debug log..." -header_write "Blacklist" -if [ -e "${BLACKLISTFILE}" ]; then - cat "${BLACKLISTFILE}" >> ${DEBUG_LOG} - log_write -else - log_write "No blacklist.txt file found!" - printf ":::\tNo blacklist.txt file found!\n" -fi - -echo "::: Writing adlists.list to debug log..." -header_write "adlists.list" -if [ -e "${ADLISTFILE}" ]; then - while read -r line; do - if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue - log_write "${line}" - fi - done < "${ADLISTFILE}" - log_write -else - log_write "No adlists.list file found... using adlists.default!" - printf ":::\tNo adlists.list file found... using adlists.default!\n" -fi -echo - # Continuously append the pihole.log file to the pihole_debug.log file dumpPiHoleLog() { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT From 9cd830b6aa5b46a0e41cfbfe57bfac59b889c8b5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:37:45 -0700 Subject: [PATCH 163/172] Start to refine tests and clean up code. --- advanced/Scripts/piholeDebug.sh | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8ae9759c..e218d7f6 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -68,10 +68,6 @@ log_echo() { echo "${2}" log_write "${2}" ;; - -e) - echo "${2}" - log_write - ;; *) echo "::: ${1}" log_write "${1}" @@ -87,7 +83,7 @@ header_write() { file_parse() { while read -r line; do if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ ]] && continue + [[ "${line}" =~ ^#.*$ || ! "${line}" ]] && continue log_write "${line}" fi done < "${1}" @@ -101,15 +97,13 @@ block_parse() { lsof_parse() { local user local process - local match user=$(echo ${1} | cut -f 3 -d ' ' | cut -c 2-) process=$(echo ${1} | cut -f 2 -d ' ' | cut -c 2-) - if [[ ${2} -eq ${process} ]]; then - echo "::: Correctly configured." - else - log_echo "::: Failure: Incorrectly configured daemon." - fi + [[ ${2} -eq ${process} ]] \ + && echo "::: Correctly configured." \ + || log_echo "::: Failure: Incorrectly configured daemon." + log_write "Found user ${user} with process ${process}" } @@ -333,8 +327,6 @@ distro_check || echo "Distro Check soft fail" processor_check || echo "Processor Check soft fail" ip_check -#hostnameCheck - daemon_check lighttpd http daemon_check dnsmasq domain From fad2d6b1d1da5a6c442c24d0ff978e9a8f0be163 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 28 Oct 2016 15:53:18 -0700 Subject: [PATCH 164/172] Return values start showin up now. Logic operators too... --- advanced/Scripts/piholeDebug.sh | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e218d7f6..b228b0c9 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -155,12 +155,8 @@ distro_check() { } processor_check() { - local soft_fail header_write "Checking processor variety" - - soft_fail=0 - log_write $(uname -m) || soft_fail=1 - return "${soft_fail}" + log_write $(uname -m) && return 0 || return 1 } ipv6_check() { @@ -173,34 +169,19 @@ ipv6_check() { fi } + ip_check() { header_write "IP Address Information" # Get the current interface for Internet traffic # Check if IPv6 enabled local IPv6_interface + local IPv4_interface ipv6_check && IPv6_interface=${piholeInterface:-$(ip -6 r | grep default | cut -d ' ' -f 5)} # If declared in setupVars.conf use it, otherwise defer to default # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash + IPv4_interface=${piholeInterface:-$(ip r | grep default | cut -d ' ' -f 5)} -local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ - && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ - || log_echo "No IPv4 addresses found." - - local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) - if [[ $? = 0 ]]; then - echo -n "::: Pinging default IPv4 gateway: " - local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" | tail -n3)" \ - && echo "Gateway responded." \ - || echo "Gateway did not respond." - block_parse "${IPv4_def_gateway_check}" - - echo -n "::: Pinging Internet via IPv4: " - local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)" \ - && echo "Query responded." \ - || echo "Query did not respond." - block_parse "${IPv4_inet_check}" - fi if [[ IPV6_READY ]]; then local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ @@ -223,6 +204,26 @@ local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet" else log_echo="No IPv6 Gateway Detected" fi + +local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ + && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ + || log_echo "No IPv4 addresses found." + + local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) + if [[ $? = 0 ]]; then + echo -n "::: Pinging default IPv4 gateway: " + local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" -I "${IPv4_interface}" | tail -n3)" \ + && echo "Gateway responded." \ + || echo "Gateway did not respond." + block_parse "${IPv4_def_gateway_check}" + + echo -n "::: Pinging Internet via IPv4: " + local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 -I "${IPv4_interface}" | tail -n3)" \ + && echo "Query responded." \ + || echo "Query did not respond." + block_parse "${IPv4_inet_check}" + fi + fi } From beb0dae5a7afda83807b325574e4aab13dcba5d7 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 29 Oct 2016 14:46:09 +0100 Subject: [PATCH 165/172] Update README.md Add code climate badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c242d56..7257ba4e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=3011939)](https://www.bountysource.com/trackers/3011939-pi-hole-pi-hole?utm_source=3011939&utm_medium=shield&utm_campaign=TRACKER_BADGE) +[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=3011939)](https://www.bountysource.com/trackers/3011939-pi-hole-pi-hole?utm_source=3011939&utm_medium=shield&utm_campaign=TRACKER_BADGE) [![Code Climate](https://codeclimate.com/github/pi-hole/pi-hole/badges/gpa.svg)](https://codeclimate.com/github/pi-hole/pi-hole) # Automated Install From 908697a963c49ce9de0aa3178279c4fdb56fcb95 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 29 Oct 2016 12:04:18 -0700 Subject: [PATCH 166/172] User token instructions, and small bugfix for missing separator. --- 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 b228b0c9..665c1f28 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -302,7 +302,7 @@ checkProcesses() { PROCESSES=( lighttpd dnsmasq ) for i in "${PROCESSES[@]}"; do log_write "" - log_write -n "${i}" + log_write "${i}" log_write " processes status:" systemctl -l status "${i}" >> "${DEBUG_LOG}" done @@ -382,6 +382,8 @@ finalWork() { # Check if tricorder.pi-hole.net is reachable and provide token. if [ -n "${tricorder}" ]; then echo "::: Your debug token is : ${tricorder}" + echo "::: Please contact the Pi-hole team with your token to being assistance." + echo "::: Thank you." fi echo "::: Debug log can be found at : /var/log/pihole_debug.log" } From dcf6e6b14d35424923ec9b622d8ff8921fc6cafe Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 29 Oct 2016 12:24:22 -0700 Subject: [PATCH 167/172] Clarify user action required to end the scripts. --- 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 665c1f28..6768a8ea 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -351,7 +351,9 @@ header_write "Analyzing gravity.list" # Continuously append the pihole.log file to the pihole_debug.log file dumpPiHoleLog() { trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT - echo -e "::: Writing current Pi-hole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" + echo "::: " + echo "::: --= User Action Required =--" + echo -e "::: Try loading a site that you are having trouble with now from a client web browser.. \n:::\t(Press CTRL+C to finish logging.)" header_write "pihole.log" if [ -e "${PIHOLELOG}" ]; then while true; do From 05c8406fca53a47b3e13d7f55d8e4391919c8266 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 30 Oct 2016 06:37:36 -0700 Subject: [PATCH 168/172] Update last modified date for adlist --- adlists.default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adlists.default b/adlists.default index 20b48008..57860b3f 100644 --- a/adlists.default +++ b/adlists.default @@ -1,4 +1,4 @@ -## Pi-hole ad-list default sources. Updated 22/05/2016 ######################### +## 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` # From fa36fdeb033a113e93a5fc6eb0d587083310c1e7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 30 Oct 2016 07:06:27 -0700 Subject: [PATCH 169/172] Update README Add discourse links, remove last of Optimal, bring Other Devices up to the top, update alternate install instructions. --- README.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7257ba4e..a8cdf268 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,15 @@ Works on most Debian and CentOS/RHEL based distributions! 1. Install Raspbian 2. Run the command below (downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!) -## `curl -L https://install.pi-hole.net | bash` +## `curl -sSL https://install.pi-hole.net | bash` ### Alternative Semi-Automated install ```bash wget -O basic-install.sh https://install.pi-hole.net -chmod +x basic-install.sh -./basic-install.sh +cat basic-install.sh | bash ``` - -If you wish to read over the script before running it, then after the `wget` command, do `nano basic-install.sh` to open a text viewer +If you wish to read over the script before running it, then after the `wget` command, do `nano basic-install.sh` to open a text viewer. Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) 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 the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/). @@ -34,7 +32,7 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei ## Pi-hole Is Free, But Powered By Your Donations -Send a one-time donation or sign up for Optimal.com's service using our link below to provide us with a small portion of the monthly fee. +Send a one-time donation using our link below to provide us with a small portion of the monthly fee. - ![Paypal](http://i.imgur.com/3muNfxu.png) : [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY) - ![Flattr](http://i.imgur.com/ZFceFRu.png) : [Donate](https://flattr.com/submit/auto?user_id=jacobsalmela&url=https://github.com/pi-hole/pi-hole) @@ -43,19 +41,24 @@ Send a one-time donation or sign up for Optimal.com's service using our link bel ## Get Help Or Connect With Us On The Web - [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) +- [Discourse](https://discourse.pi-hole.net/) - [/r/pihole](https://www.reddit.com/r/pihole/) - [Pi-hole YouTube channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) - [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) -- [FAQs](https://pi-hole.net/help/) +- [FAQs](https://discourse.pi-hole.net/c/faqs) - [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ## 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. You can also [replace ads with any image you want](http://pi-hole.net/faq/is-it-possible-to-change-the-blank-page-that-takes-place-of-the-ads-to-something-else/) since it is just a simple Webpage taking place of the ads. +#### Other Operating Systems + +This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install is only for a clean install of a Debian family or Fedora based system, such as the Raspberry Pi. If there are other platforms you'd like supported, let us know. + ### Gravity -The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)). +The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)). This script is controlled by the `pihole` command. Please run `pihole -h` to see what commands can be run via `pihole`. ## Web Interface @@ -67,13 +70,13 @@ The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashb ### Whitelist and blacklist -Domains can be whitelisted and blacklisted using two pre-installed scripts. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details ![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png) +Domains can be whitelisted and blacklisted using either the web interface or the command line. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details ![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png) ## API A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: -```json +``` json { "domains_being_blocked": "136708", "dns_queries_today": "18108", @@ -119,7 +122,3 @@ You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd- - [Foolish Tech Show](https://youtu.be/bYyena0I9yc?t=2m4s) - [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/) - [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) - -## Other Operating Systems - -This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install is only for a clean install of a Debian based system, such as the Raspberry Pi. From 7920fcbb5ea14981bf6acaa7b9575321d49ced6b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 30 Oct 2016 07:09:03 -0700 Subject: [PATCH 170/172] Add linux.die.net links Add links for online manpages. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8cdf268..3d2b285f 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Works on most Debian and CentOS/RHEL based distributions! wget -O basic-install.sh https://install.pi-hole.net cat basic-install.sh | bash ``` -If you wish to read over the script before running it, then after the `wget` command, do `nano basic-install.sh` to open a text viewer. +If you wish to read over the script before running it, then after the [`wget`](https://linux.die.net/man/1/wget) command, run `nano basic-install.sh` to open the file in a text viewer. Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) 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 the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/). From ef13e67572e77fb0e4577d93f21f20d8a7db870e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 30 Oct 2016 07:11:34 -0700 Subject: [PATCH 171/172] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d2b285f..b28b3f3e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Works on most Debian and CentOS/RHEL based distributions! 1. Install Raspbian 2. Run the command below (downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!) -## `curl -sSL https://install.pi-hole.net | bash` +### `curl -sSL https://install.pi-hole.net | bash` ### Alternative Semi-Automated install From 126f275e189bdb9dc3b9f36fc7d50b647dc0c3cc Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 30 Oct 2016 17:15:35 +0000 Subject: [PATCH 172/172] Update pullapprove into master Requires approval of ALL members of the `admin` team. --- .pullapprove.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pullapprove.yml b/.pullapprove.yml index 68b9acfc..3b421dd2 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -33,6 +33,6 @@ groups: conditions: branches: - master - required: 3 + required: -1 teams: - - gravity + - admin