From ff6df76e3612483c693bbc6b2b2d1bd663cb75e4 Mon Sep 17 00:00:00 2001 From: gedetil Date: Tue, 11 Apr 2017 12:04:44 -0500 Subject: [PATCH 01/12] Update webpage.sh Implement "Halt system" button, next to "Restart system" button, on admin/settings page. Useful for doing clean shutdown before powering off. (This affects 4 files, 3 for the web content, 1 for backend script.) Gilbert Detillieux 2017-04-11 --- advanced/Scripts/webpage.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7804fc8f..4247ee54 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -211,6 +211,10 @@ SetExcludeClients(){ } +Halt(){ + nohup bash -c "sleep 5; halt" &> /dev/null /dev/null Date: Wed, 5 Jul 2017 17:18:21 +1000 Subject: [PATCH 02/12] Add "php5-sqlite" to dependencies --- 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 3c6b77af..0dd2ee48 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -122,7 +122,7 @@ if command -v apt-get &> /dev/null; then # ######################################### INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail) PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) - PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi) + PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer}-sqlite) LIGHTTPD_USER="www-data" LIGHTTPD_GROUP="www-data" LIGHTTPD_CFG="lighttpd.conf.debian" From d0492898eb9bd244895fa90a8bc5cf12ba70a73c Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Wed, 5 Jul 2017 17:21:17 +1000 Subject: [PATCH 03/12] Add "php5-sqlite" to uninstall dependencies --- automated install/uninstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 336bb953..eaf5a40b 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -45,7 +45,7 @@ if [ -x "$(command -v rpm)" ]; then PKG_MANAGER="yum" fi PKG_REMOVE="${PKG_MANAGER} remove -y" - PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common git curl unzip wget findutils ) + PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-sqlite git curl unzip wget findutils ) package_check() { rpm -qa | grep ^$1- > /dev/null } @@ -56,7 +56,7 @@ elif [ -x "$(command -v apt-get)" ]; then # Debian Family PKG_MANAGER="apt-get" PKG_REMOVE="${PKG_MANAGER} -y remove --purge" - PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common git curl unzip wget ) + PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common php5-sqlite git curl unzip wget ) package_check() { dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" } From 56f2ea3ec2d243076553b67774ca7c97c13e824a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 16 Aug 2017 15:56:39 +0100 Subject: [PATCH 04/12] Add Fedora/Centos dependency Signed-off-by: Adam Warner --- 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 0dd2ee48..31320182 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -153,7 +153,7 @@ elif command -v rpm &> /dev/null; then PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" INSTALLER_DEPS=(dialog git iproute net-tools newt procps-ng) PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils nmap-ncat sudo unzip wget) - PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli) + PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php php-common php-cli php-pdo) if ! grep -q 'Fedora' /etc/redhat-release; then INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release"); fi From 01cd056bcc661abb67799ad8dad28cc3d89fd327 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 16 Aug 2017 16:27:50 +0100 Subject: [PATCH 05/12] Work out correct SQLITE version for php-sqlite Signed-off-by: Adam Warner --- automated install/basic-install.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 31320182..b38f2827 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -119,10 +119,16 @@ if command -v apt-get &> /dev/null; then else phpVer="php5" fi + # We also need the correct version for `php-sqlite` (which differs across distros) + if ${PKG_MANAGER} install --dry-run ${phpVer}-sqlite3 > /dev/null 2>&1; then + phpSqlite="sqlite3" + else + phpSqlite="sqlite" + fi # ######################################### INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail) PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) - PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer}-sqlite) + PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer}-${phpSqlite}) LIGHTTPD_USER="www-data" LIGHTTPD_GROUP="www-data" LIGHTTPD_CFG="lighttpd.conf.debian" From 64f29120c87961bc786276453ac0e14a12968e71 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Thu, 17 Aug 2017 19:43:07 +0100 Subject: [PATCH 06/12] indent nested function in basic-install.sh fix dependency in uninstall.sh Signed-off-by: Adam Warner --- automated install/basic-install.sh | 32 +++++++++++++++--------------- automated install/uninstall.sh | 18 ++++++++--------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b5010299..902c6483 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -177,22 +177,22 @@ if command -v apt-get &> /dev/null; then # The DNS server user DNSMASQ_USER="dnsmasq" -# A function to check... -test_dpkg_lock() { - # An iterator used for counting loop iterations - i=0 - # fuser is a program to show which processes use the named files, sockets, or filesystems - # So while the command is true - while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do - # Wait half a second - sleep 0.5 - # and increase the iterator - ((i=i+1)) - done - # Always return success, since we only return if there is no - # lock (anymore) - return 0 - } + # A function to check... + test_dpkg_lock() { + # An iterator used for counting loop iterations + i=0 + # fuser is a program to show which processes use the named files, sockets, or filesystems + # So while the command is true + while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do + # Wait half a second + sleep 0.5 + # and increase the iterator + ((i=i+1)) + done + # Always return success, since we only return if there is no + # lock (anymore) + return 0 + } # If apt-get is not found, check for rpm to see if it's a Red Hat family OS elif command -v rpm &> /dev/null; then diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index eaf5a40b..08869b2e 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -45,7 +45,7 @@ if [ -x "$(command -v rpm)" ]; then PKG_MANAGER="yum" fi PKG_REMOVE="${PKG_MANAGER} remove -y" - PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-sqlite git curl unzip wget findutils ) + PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-pdo git curl unzip wget findutils ) package_check() { rpm -qa | grep ^$1- > /dev/null } @@ -94,12 +94,12 @@ removeAndPurge() { # Remove dnsmasq config files ${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null echo -e " ${TICK} Removing dnsmasq config files" - + # Take care of any additional package cleaning echo -ne " ${INFO} Removing & cleaning remaining dependencies..." package_cleanup &> /dev/null echo -e "${OVER} ${TICK} Removed & cleaned up remaining dependencies" - + # Call removeNoPurge to remove Pi-hole specific files removeNoPurge } @@ -145,7 +145,7 @@ removeNoPurge() { ${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf fi fi - + ${SUDO} rm /etc/dnsmasq.d/adList.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm -rf /var/log/*pihole* &> /dev/null @@ -156,23 +156,23 @@ removeNoPurge() { ${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null ${SUDO} rm /etc/sudoers.d/pihole &> /dev/null echo -e " ${TICK} Removed config files" - + # Remove FTL if command -v pihole-FTL &> /dev/null; then echo -ne " ${INFO} Removing pihole-FTL..." - + if [[ -x "$(command -v systemctl)" ]]; then systemctl stop pihole-FTL else service pihole-FTL stop fi - + ${SUDO} rm /etc/init.d/pihole-FTL ${SUDO} rm /usr/bin/pihole-FTL - + echo -e "${OVER} ${TICK} Removed pihole-FTL" fi - + # If the pihole user exists, then remove if id "pihole" &> /dev/null; then ${SUDO} userdel -r pihole 2> /dev/null From bea99abd8dc9b2459a6ba23396ee59f62293a79a Mon Sep 17 00:00:00 2001 From: WaLLy3K Date: Tue, 5 Sep 2017 23:28:33 +1000 Subject: [PATCH 07/12] Ensure colour consistency between terminal themes * Comment file for review-ability * Add BOLD and UNDERLINE options * Select most readable colours out of LIGHT/DARK options * Provide empty variables for `set -u` * Deprecate unnecessary variables * Correct colours for TICK/CROSS/DONE * Escape r twice and add ESC to OVER --- advanced/Scripts/COL_TABLE | 65 +++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/advanced/Scripts/COL_TABLE b/advanced/Scripts/COL_TABLE index 20dd98b0..57aab4dd 100644 --- a/advanced/Scripts/COL_TABLE +++ b/advanced/Scripts/COL_TABLE @@ -1,28 +1,49 @@ +# Determine if terminal is capable of showing colours if [[ -t 1 ]] && [[ $(tput colors) -ge 8 ]]; then + # Bold and underline may not show up on all clients + # If something MUST be emphasised, use both + COL_BOLD='' + COL_ULINE='' + COL_NC='' - COL_WHITE='' - COL_BLACK='' - COL_BLUE='' - COL_LIGHT_BLUE='' - COL_GREEN='' - COL_LIGHT_GREEN='' - COL_CYAN='' - COL_LIGHT_CYAN='' - COL_RED='' - COL_LIGHT_RED='' - COL_URG_RED='' - COL_PURPLE='' - COL_LIGHT_PURPLE='' - COL_BROWN='' - COL_YELLOW='' - COL_GRAY='' - COL_LIGHT_GRAY='' - COL_DARK_GRAY='' + COL_GRAY='' + COL_RED='' + COL_GREEN='' + COL_YELLOW='' + COL_BLUE='' + COL_PURPLE='' + COL_CYAN='' +else + # Provide empty variables for `set -u` + COL_BOLD="" + COL_ULINE="" + + COL_NC="" + COL_GRAY="" + COL_RED="" + COL_GREEN="" + COL_YELLOW="" + COL_BLUE="" + COL_PURPLE="" + COL_CYAN="" fi -TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]" -CROSS="[${COL_LIGHT_RED}✗${COL_NC}]" +# Deprecated variables +COL_WHITE="${COL_BOLD}" +COL_BLACK="${COL_NC}" +COL_LIGHT_BLUE="${COL_BLUE}" +COL_LIGHT_GREEN="${COL_GREEN}" +COL_LIGHT_CYAN="${COL_CYAN}" +COL_LIGHT_RED="${COL_RED}" +COL_URG_RED="${COL_RED}${COL_BOLD}${COL_ULINE}" +COL_LIGHT_PURPLE="${COL_PURPLE}" +COL_BROWN="${COL_YELLOW}" +COL_LIGHT_GRAY="${COL_GRAY}" +COL_DARK_GRAY="${COL_GRAY}" + +TICK="[${COL_GREEN}✓${COL_NC}]" +CROSS="[${COL_RED}✗${COL_NC}]" INFO="[i]" QST="[?]" -DONE="${COL_LIGHT_GREEN} done!${COL_NC}" -OVER="\r\033[K" +DONE="${COL_GREEN} done!${COL_NC}" +OVER="\\r" From 2624e56de55fc860f47c82359d45e4d62f38d70d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 6 Sep 2017 16:54:41 +0200 Subject: [PATCH 08/12] Parse /etc/openvpn/ipp.txt (if existing) and add entries to local.list. Signed-off-by: DL6ER --- gravity.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index 168a4350..78b7ebb6 100755 --- a/gravity.sh +++ b/gravity.sh @@ -53,6 +53,7 @@ piholeDir=/etc/${basename} adList=${piholeDir}/gravity.list blackList=${piholeDir}/black.list localList=${piholeDir}/local.list +VPNList=/etc/openvpn/ipp.txt justDomainsExtension=domains matterAndLight=${basename}.0.matterandlight.txt supernova=${basename}.1.supernova.txt @@ -217,7 +218,7 @@ gravity_Schwarzchild() { # Find all active domains and compile them into one file and remove CRs local str="Aggregating list of domains" echo -ne " ${INFO} ${str}..." - + truncate -s 0 ${piholeDir}/${matterAndLight} for i in "${activeDomains[@]}"; do # Only assimilate list if it is available (download might have failed permanently) @@ -337,6 +338,11 @@ gravity_hostFormatLocal() { rm "${localList}" gravity_doHostFormat "${localList}.tmp" "${localList}" rm "${localList}.tmp" + + # Generate local HOSTS list with information obtained from OpenVPN (if available) + if [[ -f ${VPNList} ]]; then + awk -F, '{for (i=NF; i>=1; i-=2) printf $i"\t"$(i-1) "\n" }' "${VPNList}" >> "${localList}" + fi } gravity_hostFormatGravity() { @@ -468,7 +474,7 @@ if [[ ! "${blackListOnly}" == true ]]; then echo -ne " ${INFO} ${str}..." rm ${piholeDir}/pihole.*.txt 2> /dev/null - + echo -e "${OVER} ${TICK} ${str}" fi From 4a90dac68e971b02ce3394bfc85fcd0933bd7d05 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 7 Sep 2017 19:42:00 +0200 Subject: [PATCH 09/12] Simplify awk code as the format of ipp.txt is actually fixed (only one entry per line is allowed) Signed-off-by: DL6ER --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 78b7ebb6..5519d11a 100755 --- a/gravity.sh +++ b/gravity.sh @@ -341,7 +341,7 @@ gravity_hostFormatLocal() { # Generate local HOSTS list with information obtained from OpenVPN (if available) if [[ -f ${VPNList} ]]; then - awk -F, '{for (i=NF; i>=1; i-=2) printf $i"\t"$(i-1) "\n" }' "${VPNList}" >> "${localList}" + awk -F, '{printf $2"\t"$1"\n"}' "${VPNList}" >> "${localList}" fi } From f5a1fa21f7ac500d8d6e786b1b288a63a286cf38 Mon Sep 17 00:00:00 2001 From: spacedingo Date: Fri, 8 Sep 2017 20:36:14 +0400 Subject: [PATCH 10/12] Add ignore-case switch to sort (domains) Domains with caps pass off as unique. It is necessary for proper duplicate removal. Example: ::: /etc/pihole/list.preEventHorizon (2 results) adsatt.abcnews.starwave.com Adsatt.ABCNews.starwave.com --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 168a4350..8db7f167 100755 --- a/gravity.sh +++ b/gravity.sh @@ -296,7 +296,7 @@ gravity_unique() { local str="Removing duplicate domains" echo -ne " ${INFO} ${str}..." - sort -u ${piholeDir}/${supernova} > ${piholeDir}/${preEventHorizon} + sort -u -f ${piholeDir}/${supernova} > ${piholeDir}/${preEventHorizon} echo -e "${OVER} ${TICK} ${str}" numberOf=$(wc -l < ${piholeDir}/${preEventHorizon}) From 279e809aafff801291de5ecb8fcc62f792f8409a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 8 Sep 2017 19:33:06 +0200 Subject: [PATCH 11/12] Use `poweroff` instead of `halt` Signed-off-by: DL6ER --- advanced/Scripts/webpage.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index ae115aed..4441575f 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -217,8 +217,8 @@ SetExcludeClients() { change_setting "API_EXCLUDE_CLIENTS" "${args[2]}" } -Halt(){ - nohup bash -c "sleep 5; halt" &> /dev/null /dev/null Date: Fri, 8 Sep 2017 19:35:05 +0200 Subject: [PATCH 12/12] Update to comply with current development code Signed-off-by: DL6ER --- 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 4441575f..fbba3f74 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -234,8 +234,8 @@ RestartDNS() { output=$( { service dnsmasq restart; } 2>&1 ) fi - if [[ "$?" == 0 ]]; then - echo -e "${OVER} ${TICK} ${str}" + if [[ -z "${output}" ]]; then + [[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}" else [[ ! -t 1 ]] && OVER="" echo -e "${OVER} ${CROSS} ${output}"