From 4301b9a12a472f0e82ac64c421793ffa7145abf3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 25 Jan 2017 10:33:25 +0100 Subject: [PATCH 01/28] Add static DHCP leases to new file --- advanced/Scripts/webpage.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 02610d85..10d53045 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -12,6 +12,8 @@ readonly setupVars="/etc/pihole/setupVars.conf" readonly dnsmasqconfig="/etc/dnsmasq.d/01-pihole.conf" readonly dhcpconfig="/etc/dnsmasq.d/02-pihole-dhcp.conf" +# 03 -> wildcards +readonly dhcpstaticconfig="/etc/dnsmasq.d/04-pihole-static-dhcp.conf" helpFunc() { cat << EOM @@ -313,6 +315,24 @@ ResolutionSettings() { fi } +AddDHCPStaticAddress() { + + mac="${args[2]}" + ip="${args[3]}" + host="${args[4]}" + + if [[ "${ip}" == "noip" ]]; then + # Static host name + echo "dhcp-host=${mac},${host}" >> "dhcpstaticconfig" + elif [[ "${host}" == "nohost" ]]; then + # Static IP + echo "dhcp-host=${mac},${ip}" >> "dhcpstaticconfig" + else + # Full info given + echo "dhcp-host=${mac},${ip},${host}" >> "dhcpstaticconfig" + fi +} + main() { args=("$@") @@ -334,6 +354,7 @@ main() { "-h" | "--help" ) helpFunc;; "privacymode" ) SetPrivacyMode;; "resolve" ) ResolutionSettings;; + "addstatic" ) AddDHCPStaticAddress;; * ) helpFunc;; esac From 5c95c4074b404cb6022c4d381b92a4db53a160ab Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 25 Jan 2017 10:35:03 +0100 Subject: [PATCH 02/28] Remove static leases from DHCP static leases file --- advanced/Scripts/webpage.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 10d53045..f10f79f3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -323,16 +323,23 @@ AddDHCPStaticAddress() { if [[ "${ip}" == "noip" ]]; then # Static host name - echo "dhcp-host=${mac},${host}" >> "dhcpstaticconfig" + echo "dhcp-host=${mac},${host}" >> "${dhcpstaticconfig}" elif [[ "${host}" == "nohost" ]]; then # Static IP - echo "dhcp-host=${mac},${ip}" >> "dhcpstaticconfig" + echo "dhcp-host=${mac},${ip}" >> "${dhcpstaticconfig}" else # Full info given - echo "dhcp-host=${mac},${ip},${host}" >> "dhcpstaticconfig" + echo "dhcp-host=${mac},${ip},${host}" >> "${dhcpstaticconfig}" fi } +RemoveDHCPStaticAddress() { + + mac="${args[2]}" + sed -i "/dhcp-host=${mac}.*/d" "${dhcpstaticconfig}" + +} + main() { args=("$@") @@ -355,6 +362,7 @@ main() { "privacymode" ) SetPrivacyMode;; "resolve" ) ResolutionSettings;; "addstatic" ) AddDHCPStaticAddress;; + "removestatic" ) RemoveDHCPStaticAddress;; * ) helpFunc;; esac From dad18dc5def0753a27f2c631fbd3a8686ab9a32f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 25 Jan 2017 10:35:45 +0100 Subject: [PATCH 03/28] Changed keywords --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f10f79f3..fd882bd3 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -361,8 +361,8 @@ main() { "-h" | "--help" ) helpFunc;; "privacymode" ) SetPrivacyMode;; "resolve" ) ResolutionSettings;; - "addstatic" ) AddDHCPStaticAddress;; - "removestatic" ) RemoveDHCPStaticAddress;; + "addstaticdhcp" ) AddDHCPStaticAddress;; + "removestaticdhcp" ) RemoveDHCPStaticAddress;; * ) helpFunc;; esac From 85b3fef08d6b6dd145e66e9cc7e5db9db3c408e3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 28 Jan 2017 00:39:10 +0100 Subject: [PATCH 04/28] Use perl instead of grep? --- 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 dce274c5..828bb2bc 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -66,11 +66,11 @@ HandleOther(){ domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1") #check validity of domain - validDomain=$(echo "${domain}" | grep -P '^(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b') + validDomain=$(echo "${domain}" | perl -lne 'print $1 if /^(?!.*[^a-z0-9-\.].*)\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[@]}" ${domain}) fi } From 5b43f1393527b49a557c3f84a72b26155831091c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 20:24:20 -0800 Subject: [PATCH 05/28] Fresh install web page directory tests --- automated install/basic-install.sh | 2 +- test/test_automated_install.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a98eb3aa..16b72230 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -809,7 +809,7 @@ installPiholeWeb() { if [ -f "/var/www/html/pihole/blockingpage.css" ]; then echo "::: Existing blockingpage.css detected, not overwriting" else - echo -n "::: index.css missing, replacing... " + echo -n "::: blockingpage.css missing, replacing... " cp /etc/.pihole/advanced/blockingpage.css /var/www/html/pihole echo " done!" fi diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 211364ed..29c62f45 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -167,6 +167,20 @@ def test_configureFirewall_IPTables_enabled_not_exist_no_errors(Pihole): assert 'iptables -I INPUT 1 -p tcp -m tcp --dport 53 -j ACCEPT' in firewall_calls assert 'iptables -I INPUT 1 -p udp -m udp --dport 53 -j ACCEPT' in firewall_calls +def test_installPiholeWeb_fresh_install_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed on a fresh build ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 91bcc18e6a50bb9b57543a82d15f813ea4beac3e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 20:28:03 -0800 Subject: [PATCH 06/28] Make full path to directory for pihole web page. --- automated install/basic-install.sh | 2 +- test/test_automated_install.py | 35 ++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 16b72230..ce5d044e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -815,7 +815,7 @@ installPiholeWeb() { fi else - mkdir /var/www/html/pihole + mkdir -p /var/www/html/pihole if [ -f /var/www/html/index.lighttpd.html ]; then mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 29c62f45..2a39085d 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -180,6 +180,41 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_installPiholeWeb_empty_directory_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed in an emtpy directory ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'index.php missing, replacing...' in installWeb.stdout + assert 'index.js missing, replacing...' in installWeb.stdout + assert 'blockingpage.css missing, replacing...' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + +def test_installPiholeWeb_index_php_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed in an emtpy directory ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/index.php + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'Existing index.php detected, not overwriting' in installWeb.stdout + assert 'index.js missing, replacing...' in installWeb.stdout + assert 'blockingpage.css missing, replacing...' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + # Helper functions def mock_command(script, args, container): From 28eb3487070f54abc9ed53a4a9f2594d64d2a150 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:23:49 -0800 Subject: [PATCH 07/28] Individual Page tests --- test/test_automated_install.py | 39 ++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 2a39085d..b7c82f88 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -198,11 +198,11 @@ def test_installPiholeWeb_empty_directory_no_errors(Pihole): assert 'blockingpage.css' in web_directory def test_installPiholeWeb_index_php_no_errors(Pihole): - ''' confirms all web page assets from Core repo are installed in an emtpy directory ''' + ''' confirms all web page assets from Core repo are installed when necessary ''' installWeb = Pihole.run(''' source /opt/pihole/basic-install.sh mkdir -p /var/www/html/pihole - touch /var/www/html/index.php + touch /var/www/html/pihole/index.php installPiholeWeb ''') assert 'Installing pihole custom index page...' in installWeb.stdout @@ -215,6 +215,41 @@ def test_installPiholeWeb_index_php_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_installPiholeWeb_index_js_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed when necessary ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/pihole/index.js + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'index.php missing, replacing...' in installWeb.stdout + assert 'Existing index.js detected, not overwriting' in installWeb.stdout + assert 'blockingpage.css missing, replacing...' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + +def test_installPiholeWeb_blockingpage_css_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed when necessary ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/pihole/blockingpage.css + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'index.php missing, replacing...' in installWeb.stdout + assert 'index.js missing, replacing...' in installWeb.stdout + assert 'Existing blockingpage.css detected, not overwriting' in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory # Helper functions def mock_command(script, args, container): From d5587e32d01dbd79c218b5b0377fd4a947519017 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:29:17 -0800 Subject: [PATCH 08/28] Populated directory test --- test/test_automated_install.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index b7c82f88..f8e2ec3d 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -251,6 +251,29 @@ def test_installPiholeWeb_blockingpage_css_no_errors(Pihole): assert 'index.js' in web_directory assert 'blockingpage.css' in web_directory +def test_installPiholeWeb_already_populated_no_errors(Pihole): + ''' confirms all web page assets from Core repo are installed when necessary ''' + installWeb = Pihole.run(''' + source /opt/pihole/basic-install.sh + mkdir -p /var/www/html/pihole + touch /var/www/html/pihole/index.php + touch /var/www/html/pihole/index.js + touch /var/www/html/pihole/blockingpage.css + installPiholeWeb + ''') + assert 'Installing pihole custom index page...' in installWeb.stdout + assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout + assert 'Existing index.php detected, not overwriting' in installWeb.stdout + assert 'index.php missing, replacing...' not in installWeb.stdout + assert 'Existing index.js detected, not overwriting' in installWeb.stdout + assert 'index.js missing, replacing...' not in installWeb.stdout + assert 'Existing blockingpage.css detected, not overwriting' in installWeb.stdout + assert 'blockingpage.css missing, replacing... ' not in installWeb.stdout + web_directory = Pihole.run('ls -r /var/www/html/pihole').stdout + assert 'index.php' in web_directory + assert 'index.js' in web_directory + assert 'blockingpage.css' in web_directory + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 1421c31179bae16ea77520c036324150cfcec848 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:32:52 -0800 Subject: [PATCH 09/28] `install` index and blockingpage assets. --- 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 ce5d044e..591415bd 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -821,7 +821,7 @@ installPiholeWeb() { else printf "\n:::\tNo default index.lighttpd.html file found... not backing up" fi - cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. + install /etc/.pihole/advanced/{index,blockingpage}.* /var/www/html/pihole/. echo " done!" fi # Install Sudoer file From 52e0aa11afcabd512c1238ff16cb3cdc000fda93 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 27 Jan 2017 21:50:32 -0800 Subject: [PATCH 10/28] Have install create directory --- automated install/basic-install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 591415bd..9fed0bca 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -815,15 +815,17 @@ installPiholeWeb() { fi else - mkdir -p /var/www/html/pihole + echo "::: Creating directory for blocking page" + install -d /var/www/html/pihole + install -D /etc/.pihole/advanced/{index,blockingpage}.* /var/www/html/pihole/ if [ -f /var/www/html/index.lighttpd.html ]; then mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else printf "\n:::\tNo default index.lighttpd.html file found... not backing up" fi - install /etc/.pihole/advanced/{index,blockingpage}.* /var/www/html/pihole/. echo " done!" fi + # Install Sudoer file echo ":::" echo -n "::: Installing sudoer file..." From 1bf43b04254559896f5e3a59667a18520401cb78 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 28 Jan 2017 21:48:19 +0100 Subject: [PATCH 11/28] Improved regex: Remove all leading points from domain (.....xyz => .xyz). Return not only a part, but fill validated domain --- advanced/Scripts/list.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 828bb2bc..d2438a43 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -58,7 +58,7 @@ EscapeRegexp() { # This way we may safely insert an arbitrary # string in our regular expressions # Also remove leading "." if present - echo $* | sed 's/^\.//' | sed "s/[]\\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g" + echo $* | sed 's/^\.*//' | sed "s/[]\.|$(){}?+*^]/\\\\&/g" | sed "s/\\//\\\\\//g" } HandleOther(){ @@ -66,11 +66,12 @@ HandleOther(){ domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1") #check validity of domain - validDomain=$(echo "${domain}" | perl -lne 'print $1 if /^(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') + validDomain=$(echo "${domain}" | perl -lne 'print if /^(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)*[a-z]{2,63}\b/') + echo $validDomain if [ -z "${validDomain}" ]; then echo "::: $1 is not a valid argument or domain name" else - domList=("${domList[@]}" ${domain}) + domList=("${domList[@]}" ${validDomain}) fi } From 08cddba2005f9ffe3a527bf080f9d178445c1cc9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 28 Jan 2017 21:49:31 +0100 Subject: [PATCH 12/28] There should be no echo here --- advanced/Scripts/list.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index d2438a43..c916e021 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -67,7 +67,6 @@ HandleOther(){ #check validity of domain validDomain=$(echo "${domain}" | perl -lne 'print if /^(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)*[a-z]{2,63}\b/') - echo $validDomain if [ -z "${validDomain}" ]; then echo "::: $1 is not a valid argument or domain name" else From 033ba2604131fa33d91a88bb9878f5873369cf89 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 28 Jan 2017 20:00:02 -0500 Subject: [PATCH 13/28] Stay in repo directory until we error check --- advanced/Scripts/update.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index df71e9a9..10afded4 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -105,9 +105,6 @@ GitCheckUpdateAvail() { # defaults to the current one. REMOTE="$(git rev-parse @{upstream})" - # Change back to original directory - cd "${curdir}" - if [[ ${#LOCAL} == 0 ]]; then echo "::: Error: Local revision could not be optained, ask Pi-hole support." echo "::: Additional debugging output:" @@ -120,6 +117,9 @@ GitCheckUpdateAvail() { git status exit fi + + # Change back to original directory + cd "${curdir}" if [[ "${LOCAL}" != "${REMOTE}" ]]; then # Local branch is behind remote branch -> Update From 99a4a8001759da332a81b62810da36ffc4dc43cc Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 17:08:38 -0800 Subject: [PATCH 14/28] Spelling --- advanced/Scripts/update.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 10afded4..32fb712b 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -106,13 +106,13 @@ GitCheckUpdateAvail() { REMOTE="$(git rev-parse @{upstream})" if [[ ${#LOCAL} == 0 ]]; then - echo "::: Error: Local revision could not be optained, ask Pi-hole support." + echo "::: Error: Local revision could not be obtained, ask Pi-hole support." echo "::: Additional debugging output:" git status exit fi if [[ ${#REMOTE} == 0 ]]; then - echo "::: Error: Remote revision could not be optained, ask Pi-hole support." + echo "::: Error: Remote revision could not be obtained, ask Pi-hole support." echo "::: Additional debugging output:" git status exit From 3861b57dc6bd5144d11a8f53d649dfd1ec4829fe Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 17:32:42 -0800 Subject: [PATCH 15/28] Start moving reused utility functions to one script. --- advanced/Scripts/update.sh | 69 +++--------------------------- automated install/basic-install.sh | 22 ++++++---- 2 files changed, 20 insertions(+), 71 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index df71e9a9..426d3580 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -19,70 +19,13 @@ readonly ADMIN_INTERFACE_DIR="/var/www/html/admin" readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_FILES_DIR="/etc/.pihole" -is_repo() { - # Use git to check if directory is currently under VCS, return the value - local directory="${1}" - local curdir - local rc +PH_TEST=true +source ${PI_HOLE_GIT_URL}/automated\ install/basic-install.sh - curdir="${PWD}" - cd "${directory}" &> /dev/null || return 1 - git status --short &> /dev/null - rc=$? - cd "${curdir}" &> /dev/null || return 1 - return "${rc}" -} - -prep_repo() { - # Prepare directory for local repository building - local directory="${1}" - - rm -rf "${directory}" &> /dev/null - return -} - -make_repo() { - # Remove the non-repod interface and clone the interface - local remoteRepo="${2}" - local directory="${1}" - - (prep_repo "${directory}" && git clone -q --depth 1 "${remoteRepo}" "${directory}") - return -} - -update_repo() { - local directory="${1}" - local curdir - - curdir="${PWD}" - cd "${directory}" &> /dev/null || return 1 - # Pull the latest commits - # Stash all files not tracked for later retrieval - git stash --all --quiet - # Force a clean working directory for cloning - git clean --force -d - # Fetch latest changes and apply - git pull --quiet - cd "${curdir}" &> /dev/null || return 1 -} - -getGitFiles() { - # Setup git repos for directory and repository passed - # as arguments 1 and 2 - local directory="${1}" - local remoteRepo="${2}" - echo ":::" - echo "::: Checking for existing repository..." - if is_repo "${directory}"; then - echo -n "::: Updating repository in ${directory}..." - update_repo "${directory}" || (echo "*** Error: Could not update local repository. Contact support."; exit 1) - echo " done!" - else - echo -n "::: Cloning ${remoteRepo} into ${directory}..." - make_repo "${directory}" "${remoteRepo}" || (echo "Unable to clone repository, please contact support"; exit 1) - echo " done!" - fi -} +# is_repo() sourced from basic-install.sh +# make_repo() sourced from basic-install.sh +# update_repo() source from basic-install.sh +# getGitFiles() sourced from basic-install.sh GitCheckUpdateAvail() { local directory="${1}" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9fed0bca..7d1e09b3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -149,15 +149,17 @@ make_repo() { update_repo() { local directory="${1}" + local curdir + curdir="${PWD}" + cd "${directory}" &> /dev/null || return 1 # Pull the latest commits echo -n "::: Updating repo in ${1}..." - if [[ -d "${directory}" ]]; then - cd "${directory}" - git stash -q &> /dev/null || true # Okay for stash failure - git pull -q &> /dev/null || return $? - echo " done!" - fi + git stash --all --quiet &> /dev/null || true # Okay for stash failure + git clean --force -d || true # Okay for already clean directory + git pull --quiet &> /dev/null || return $? + echo " done!" + cd "${curdir}" &> /dev/null || return 1 return 0 } @@ -169,9 +171,13 @@ getGitFiles() { echo ":::" echo "::: Checking for existing repository..." if is_repo "${directory}"; then - update_repo "${directory}" || return 1 + echo -n "::: Updating repository in ${directory}..." + update_repo "${directory}" || { echo "*** Error: Could not update local repository. Contact support."; exit 1; } + echo " done!" else - make_repo "${directory}" "${remoteRepo}" || return 1 + echo -n "::: Cloning ${remoteRepo} into ${directory}..." + make_repo "${directory}" "${remoteRepo}" || { echo "Unable to clone repository, please contact support"; exit 1; } + echo " done!" fi return 0 } From 745adabb05a839c942b0a961e9c77aeaa7292f60 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 17:38:14 -0800 Subject: [PATCH 16/28] Path to source basic-install.sh --- advanced/Scripts/update.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 426d3580..1db9cfc9 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -20,7 +20,7 @@ readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" readonly PI_HOLE_FILES_DIR="/etc/.pihole" PH_TEST=true -source ${PI_HOLE_GIT_URL}/automated\ install/basic-install.sh +source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh # is_repo() sourced from basic-install.sh # make_repo() sourced from basic-install.sh @@ -29,7 +29,7 @@ source ${PI_HOLE_GIT_URL}/automated\ install/basic-install.sh GitCheckUpdateAvail() { local directory="${1}" - curdir=$PWD; + curdir=$PWD cd "${directory}" # Fetch latest changes in this repo From 3d9d13222b08a49c7b2b78142a6cce5781501258 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 28 Jan 2017 17:42:55 -0800 Subject: [PATCH 17/28] Use constants for leading paths. --- advanced/Scripts/update.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 1db9cfc9..3b32fa73 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -128,13 +128,13 @@ main() { echo ":::" echo "::: Pi-hole core files out of date" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" - /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 + ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 elif ${core_update} && ${web_update} ; then echo ":::" echo "::: Updating Everything" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" - /etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 + ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 else echo "*** Update script has malfunctioned, fallthrough reached. Please contact support" exit 1 From a8ac212ee627f0f72aad5e65322541c4b265e5a6 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 29 Jan 2017 13:46:27 +0100 Subject: [PATCH 18/28] Show number of wildcard blocked domains in gravity's summary --- gravity.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gravity.sh b/gravity.sh index b1cd57a6..31bc6bd0 100755 --- a/gravity.sh +++ b/gravity.sh @@ -32,6 +32,7 @@ adListDefault=/etc/pihole/adlists.default whitelistScript="pihole -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt +readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" #Source the setupVars from install script for the IP setupVars=/etc/pihole/setupVars.conf @@ -235,6 +236,21 @@ gravity_Blacklist() { } +gravity_Wildcard() { + # Return number of wildcards in output - don't actually handle wildcards + if [[ -f "${wildcardlist}" ]]; then + num=$(grep -c ^ "${wildcardlist}") + if [[ -n "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then + let num/=2 + fi + plural=; [[ "$num" != "1" ]] && plural=s + echo "::: Wildcard blocked domain${plural}: $numBlacklisted" + else + echo "::: No wildcards used!" + fi + +} + gravity_Whitelist() { #${piholeDir}/${eventHorizon}) echo ":::" @@ -401,6 +417,7 @@ else fi gravity_Whitelist gravity_Blacklist +gravity_Wildcard gravity_hostFormat gravity_blackbody From 06873fe69e74e52b8cd723ad718d0ea4e9ac13f1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 29 Jan 2017 13:54:39 +0100 Subject: [PATCH 19/28] Remove misplaced start of string expression. Fixes #1191 --- advanced/Scripts/list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index c916e021..e8cfdc6b 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -66,7 +66,7 @@ HandleOther(){ domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1") #check validity of domain - validDomain=$(echo "${domain}" | perl -lne 'print if /^(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)*[a-z]{2,63}\b/') + validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)\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 From f8944177a046f5aae36e77b44750ef395dffd8d6 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sun, 29 Jan 2017 13:32:48 -0500 Subject: [PATCH 20/28] Fix chronometer interpreting summaryRaw --- advanced/Scripts/chronometer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 93b0cbb1..3dce9c3e 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -22,7 +22,7 @@ function GetJSONValue { retVal=$(echo $1 | sed 's/\\\\\//\//g' | \ sed 's/[{}]//g' | \ awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | \ - sed 's/\"\:\"/\|/g' | \ + sed 's/\"\:/\|/g' | \ sed 's/[\,]/ /g' | \ sed 's/\"//g' | \ grep -w $2) From 8b22f435adff664c1bc7361137a3bf0fe6f0c8bb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 29 Jan 2017 19:58:53 +0100 Subject: [PATCH 21/28] Change how user and group are stored in the logrotate config file (necessary on Ubuntu 16.04.1) --- advanced/logrotate | 1 + automated install/basic-install.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/logrotate b/advanced/logrotate index e9be016d..570e7548 100644 --- a/advanced/logrotate +++ b/advanced/logrotate @@ -1,4 +1,5 @@ /var/log/pihole.log { + # su # daily copytruncate rotate 5 diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9fed0bca..94f26be9 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -949,7 +949,7 @@ installLogrotate() { # the local properties of the /var/log directory logusergroup="$(stat -c '%U %G' /var/log)" if [[ ! -z $logusergroup ]]; then - echo "su ${logusergroup}" >> /etc/pihole/logrotate + sed -i "s/# su #/su ${logusergroup}/" /etc/pihole/logrotate fi echo " done!" } From 3d4516dc9550e7721811c447094d3bf1e5f81252 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 29 Jan 2017 20:27:20 +0100 Subject: [PATCH 22/28] Improve regex --- advanced/Scripts/list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index e8cfdc6b..7cbe6beb 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -66,7 +66,7 @@ HandleOther(){ domain=$(sed -e "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" <<< "$1") #check validity of domain - validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)*[a-z]{2,63}\b/') + validDomain=$(echo "${domain}" | perl -lne 'print if /(?!.*[^a-z0-9-\.].*)^((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9-]+\.)*[a-z]{2,63}/') if [ -z "${validDomain}" ]; then echo "::: $1 is not a valid argument or domain name" else From 72a1fc3f6438f3346c382991a85275f52857433e Mon Sep 17 00:00:00 2001 From: Markus Napp Date: Wed, 1 Feb 2017 00:07:47 +0100 Subject: [PATCH 23/28] Fix output for wildcards in gravity.sh --- gravity.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 31bc6bd0..c1938229 100755 --- a/gravity.sh +++ b/gravity.sh @@ -239,12 +239,12 @@ gravity_Blacklist() { gravity_Wildcard() { # Return number of wildcards in output - don't actually handle wildcards if [[ -f "${wildcardlist}" ]]; then - num=$(grep -c ^ "${wildcardlist}") + numWildcards=$(grep -c ^ "${wildcardlist}") if [[ -n "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then - let num/=2 + let numWildcards/=2 fi plural=; [[ "$num" != "1" ]] && plural=s - echo "::: Wildcard blocked domain${plural}: $numBlacklisted" + echo "::: Wildcard blocked domain${plural}: $numWildcards" else echo "::: No wildcards used!" fi From 66616eb0f05fa9cc775dea46d42f0ffd84093841 Mon Sep 17 00:00:00 2001 From: Markus Napp Date: Wed, 1 Feb 2017 19:55:33 +0100 Subject: [PATCH 24/28] Rename missing plurals check --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index c1938229..1c9da96a 100755 --- a/gravity.sh +++ b/gravity.sh @@ -243,7 +243,7 @@ gravity_Wildcard() { if [[ -n "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then let numWildcards/=2 fi - plural=; [[ "$num" != "1" ]] && plural=s + plural=; [[ "$numWildcards" != "1" ]] && plural=s echo "::: Wildcard blocked domain${plural}: $numWildcards" else echo "::: No wildcards used!" From 26ad23f01ef66d017ce46b72c13b17661e7adfc9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 1 Feb 2017 18:33:42 -0800 Subject: [PATCH 25/28] Remove comment leaders from DHCPCD interface We need to set the interface in DHCPCD, comments were inadvertently added a while ago. --- 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 94f26be9..20934618 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -361,7 +361,7 @@ 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 ${PIHOLE_INTERFACE} + echo "interface ${PIHOLE_INTERFACE} static ip_address=${IPV4_ADDRESS} static routers=${IPv4gw} static domain_name_servers=${IPv4gw}" | tee -a /etc/dhcpcd.conf >/dev/null From f767f066ada9fd2adef5a78895f50842570fa23a Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Fri, 3 Feb 2017 15:18:28 -0600 Subject: [PATCH 26/28] Update outdated text and describe features from recent versions --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 561e4f09..6ae8d628 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ wget -O basic-install.sh https://install.pi-hole.net bash basic-install.sh ``` -Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to [use the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/). +Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to use Pi-hole as their DNS server. ## What is Pi-hole and how do I install it?

@@ -100,6 +100,17 @@ Domains can be whitelisted and blacklisted using either the web interface or the

+### Settings + +The settings page lets you control and configure your Pi-hole. You can do things like: + +- enable Pi-hole's built-in DHCP server +- exclude domains from the graphs +- configure upstream DNS servers +- and more! + + + ## API A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: From fcdd33b585bc941c2d87f190b8264064dcd64687 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Fri, 3 Feb 2017 15:21:42 -0600 Subject: [PATCH 27/28] Update and remove old FAQ links --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6ae8d628..c9f16d9e 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei ## Technical Details -The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. 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. +The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. ### Gravity @@ -103,7 +103,7 @@ Domains can be whitelisted and blacklisted using either the web interface or the ### Settings The settings page lets you control and configure your Pi-hole. You can do things like: - + - enable Pi-hole's built-in DHCP server - exclude domains from the graphs - configure upstream DNS servers @@ -128,7 +128,7 @@ The same output can be achieved on the CLI by running `chronometer.sh -j` ## Real-time Statistics -You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-monitor-chronometer/) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). ![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) +You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my-pi-holes-stats-over-ssh-or-on-an-lcd-using-chronometer/240) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). ![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) ## Pi-hole Projects From ad5c011b6c3d8d933310f1aa697aa3a9f0e1a259 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Fri, 3 Feb 2017 15:33:44 -0600 Subject: [PATCH 28/28] Add new screenshots from latest version --- README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c9f16d9e..429fc275 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei ## What is Pi-hole and how do I install it?

- +

@@ -73,7 +73,7 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei ## Technical Details -The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. +The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. ### Gravity @@ -91,13 +91,13 @@ The [Web interface](https://github.com/pi-hole/AdminLTE#pi-hole-admin-dashboard) `http://192.168.1.x/admin/index.php` or `http://pi.hole/admin` -![Pi-hole Advanced Stats Dashboard](https://assets.pi-hole.net/static/dashboard.png) +![Pi-hole Advanced Stats Dashboard](https://assets.pi-hole.net/static/dashboard212.png) ### Whitelist and blacklist 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

- +

### Settings @@ -109,7 +109,14 @@ The settings page lets you control and configure your Pi-hole. You can do thing - configure upstream DNS servers - and more! +![Settings page](https://assets.pi-hole.net/static/settings212.png) +#### Built-in DHCP Server + +Pi-hole ships with a built-in DHCP server. This allows you to let your network devices use Pi-hole as their DNS server if your router does not let you adjust the DHCP options. +

+ +

## API