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" diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 4b7c6f26..adc2616b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -217,6 +217,10 @@ SetExcludeClients() { change_setting "API_EXCLUDE_CLIENTS" "${args[2]}" } +Poweroff(){ + nohup bash -c "sleep 5; poweroff" &> /dev/null /dev/null /dev/null; then # fall back on the php5 packages 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 # Since our install script is so large, we need several other programs to successfuly get a machine provisioned # These programs are stored in an array so they can be looped through later INSTALLER_DEPS=(apt-utils dialog debconf dhcpcd5 git ${iproute_pkg} whiptail) @@ -162,7 +167,7 @@ if command -v apt-get &> /dev/null; then PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget) # The Web dashboard has some that also need to be installed # It's useful to separate the two since our repos are also setup as "Core" code and "Web" code - PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi) + PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi ${phpVer}-${phpSqlite}) # The Web server user, LIGHTTPD_USER="www-data" # group, @@ -172,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 @@ -204,7 +209,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 @@ -1077,6 +1082,10 @@ installConfigs() { fi # and copy in the config file Pi-hole needs cp ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf + # if there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config + if [[ -f "/var/www/html/pihole/custom.php" ]]; then + sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"pihole\/custom\.php"/' /etc/lighttpd/lighttpd.conf + fi # Make the directories if they do not exist and set the owners mkdir -p /var/run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd @@ -1288,68 +1297,27 @@ CreateLogFile() { installPiholeWeb() { echo "" echo " ${INFO} Installing blocking page..." - # If the pihole Web directory exists, - if [[ -d "/var/www/html/pihole" ]]; then - local str="Installing index.php" - echo -ne " ${INFO} ${str}..." - # and if the index file exists, - if [[ -f "/var/www/html/pihole/index.php" ]]; then - # do not overwrite it, - echo -e " ${COL_LIGHT_GREEN}detected index.php, not overwriting${COL_NC}" - # if it doesn't exist - else - # install it by copying it from the repo - cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ - echo -e "${OVER} ${TICK} ${str}" - fi - local str="Installing index.js" - echo -ne " ${INFO} ${str}..." - # and if the index file exists, - if [[ -f "/var/www/html/pihole/index.js" ]]; then - # do not overwrite it, - echo -e " ${COL_LIGHT_GREEN}detected index.js, not overwriting${COL_NC}" - else - # install it by copying it from the repo - cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ - echo -e "${OVER} ${TICK} ${str}" - fi + local str="Creating directory for blocking page, and copying files" + echo -ne " ${INFO} ${str}..." + # Install the directory + install -d /var/www/html/pihole + # and the blockpage + install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + echo -e "${OVER} ${TICK} ${str}" - local str="Installing blockingpage.css" - echo -ne " ${INFO} ${str}..." - # and if the index file exists, - if [[ -f "/var/www/html/pihole/blockingpage.css" ]]; then - # do not overwrite it, - echo -e " ${COL_LIGHT_GREEN}detected blockingpage.css, not overwriting${COL_NC}" - else - # install it by copying it from the repo - cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole - echo -e "${OVER} ${TICK} ${str}" - fi - # If the pihole Web directory does not exist, - else - local str="Creating directory for blocking page, and copying files" - echo -ne " ${INFO} ${str}..." - # Install the directory - install -d /var/www/html/pihole - # and the blockpage - install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + local str="Backing up index.lighttpd.html" + echo -ne " ${INFO} ${str}..." + # If the default index file exists, + if [[ -f "/var/www/html/index.lighttpd.html" ]]; then + # back it up + mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig echo -e "${OVER} ${TICK} ${str}" - - local str="Backing up index.lighttpd.html" - echo -ne " ${INFO} ${str}..." - # If the default index file exists, - if [[ -f "/var/www/html/index.lighttpd.html" ]]; then - # back it up - mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig - echo -e "${OVER} ${TICK} ${str}" - # Othwerwise, - else - # don't do anything - echo -e "${OVER} ${CROSS} ${str} - No default index.lighttpd.html file found... not backing up" - fi - + # Othwerwise, + else + # don't do anything + echo -e "${OVER} ${CROSS} ${str} + No default index.lighttpd.html file found... not backing up" fi # Install Sudoers file diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 336bb953..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 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 } @@ -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" } @@ -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 diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 7f1a86a1..3f0bd969 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -189,107 +189,6 @@ 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 info_box + ' Installing blocking page...' in installWeb.stdout - assert info_box + ' Installing index.php' in installWeb.stdout - assert info_box + ' Installing index.js' in installWeb.stdout - assert info_box + ' Installing blockingpage.css' in installWeb.stdout - assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout - assert tick_box + ' Installing sudoer file' 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 when necessary ''' - installWeb = Pihole.run(''' - source /opt/pihole/basic-install.sh - mkdir -p /var/www/html/pihole - touch /var/www/html/pihole/index.php - installPiholeWeb - ''') - assert info_box + ' Installing blocking page...' in installWeb.stdout - assert info_box + ' Installing index.php' in installWeb.stdout - assert 'detected index.php, not overwriting' in installWeb.stdout - assert info_box + ' Installing index.js' in installWeb.stdout - assert info_box + ' Installing blockingpage.css' in installWeb.stdout - assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout - assert tick_box + ' Installing sudoer file' 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_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 info_box + ' Installing blocking page...' in installWeb.stdout - assert info_box + ' Installing index.php' in installWeb.stdout - assert info_box + ' Installing index.js' in installWeb.stdout - assert 'detected index.js, not overwriting' in installWeb.stdout - assert info_box + ' Installing blockingpage.css' in installWeb.stdout - assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout - assert tick_box + ' Installing sudoer file' 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 info_box + ' Installing blocking page...' in installWeb.stdout - assert info_box + ' Installing index.php' in installWeb.stdout - assert info_box + ' Installing index.js' in installWeb.stdout - assert info_box + ' Installing blockingpage.css' in installWeb.stdout - assert 'detected blockingpage.css, not overwriting' in installWeb.stdout - assert 'No default index.lighttpd.html file found... not backing up' not in installWeb.stdout - assert tick_box + ' Installing sudoer file' 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_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 info_box + ' Installing blocking page...' in installWeb.stdout - assert info_box + ' Installing index.php' in installWeb.stdout - assert 'detected index.php, not overwriting' in installWeb.stdout - assert info_box + ' Installing index.js' in installWeb.stdout - assert 'detected index.js, not overwriting' in installWeb.stdout - assert info_box + ' Installing blockingpage.css' in installWeb.stdout - assert 'detected blockingpage.css, not overwriting' in installWeb.stdout - assert tick_box + ' Installing sudoer file' 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_update_package_cache_success_no_errors(Pihole): ''' confirms package cache was updated without any errors''' updateCache = Pihole.run('''