Merge branch 'development' into tweak/gravity

This commit is contained in:
WaLLy3K 2017-09-14 16:44:14 +10:00 committed by GitHub
commit 34ae4844fa
5 changed files with 104 additions and 211 deletions

View file

@ -1,28 +1,49 @@
# Determine if terminal is capable of showing colours
if [[ -t 1 ]] && [[ $(tput colors) -ge 8 ]]; then 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_NC=''
COL_WHITE='' COL_GRAY=''
COL_BLACK='' COL_RED=''
COL_BLUE='' COL_GREEN=''
COL_LIGHT_BLUE='' COL_YELLOW=''
COL_GREEN='' COL_BLUE=''
COL_LIGHT_GREEN='' COL_PURPLE=''
COL_CYAN='' COL_CYAN=''
COL_LIGHT_CYAN='' else
COL_RED='' # Provide empty variables for `set -u`
COL_LIGHT_RED='' COL_BOLD=""
COL_URG_RED='' COL_ULINE=""
COL_PURPLE=''
COL_LIGHT_PURPLE='' COL_NC=""
COL_BROWN='' COL_GRAY=""
COL_YELLOW='' COL_RED=""
COL_GRAY='' COL_GREEN=""
COL_LIGHT_GRAY='' COL_YELLOW=""
COL_DARK_GRAY='' COL_BLUE=""
COL_PURPLE=""
COL_CYAN=""
fi fi
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]" # Deprecated variables
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]" 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]" INFO="[i]"
QST="[?]" QST="[?]"
DONE="${COL_LIGHT_GREEN} done!${COL_NC}" DONE="${COL_GREEN} done!${COL_NC}"
OVER="\r\033[K" OVER="\\r"

View file

@ -217,6 +217,10 @@ SetExcludeClients() {
change_setting "API_EXCLUDE_CLIENTS" "${args[2]}" change_setting "API_EXCLUDE_CLIENTS" "${args[2]}"
} }
Poweroff(){
nohup bash -c "sleep 5; poweroff" &> /dev/null </dev/null &
}
Reboot() { Reboot() {
nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null & nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null &
} }
@ -467,6 +471,7 @@ main() {
"setdns" ) SetDNSServers;; "setdns" ) SetDNSServers;;
"setexcludedomains" ) SetExcludeDomains;; "setexcludedomains" ) SetExcludeDomains;;
"setexcludeclients" ) SetExcludeClients;; "setexcludeclients" ) SetExcludeClients;;
"poweroff" ) Poweroff;;
"reboot" ) Reboot;; "reboot" ) Reboot;;
"restartdns" ) RestartDNS;; "restartdns" ) RestartDNS;;
"setquerylog" ) SetQueryLogOptions;; "setquerylog" ) SetQueryLogOptions;;

View file

@ -154,7 +154,12 @@ if command -v apt-get &> /dev/null; then
# fall back on the php5 packages # fall back on the php5 packages
phpVer="php5" phpVer="php5"
fi 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 # 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 # 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) 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) 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 # 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 # 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, # The Web server user,
LIGHTTPD_USER="www-data" LIGHTTPD_USER="www-data"
# group, # group,
@ -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" PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l"
INSTALLER_DEPS=(dialog git iproute net-tools newt procps-ng) 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_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 if ! grep -q 'Fedora' /etc/redhat-release; then
INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release"); INSTALLER_DEPS=("${INSTALLER_DEPS[@]}" "epel-release");
fi fi
@ -1077,6 +1082,10 @@ installConfigs() {
fi fi
# and copy in the config file Pi-hole needs # and copy in the config file Pi-hole needs
cp ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf 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 # Make the directories if they do not exist and set the owners
mkdir -p /var/run/lighttpd mkdir -p /var/run/lighttpd
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd
@ -1288,46 +1297,7 @@ CreateLogFile() {
installPiholeWeb() { installPiholeWeb() {
echo "" echo ""
echo " ${INFO} Installing blocking page..." 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="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" local str="Creating directory for blocking page, and copying files"
echo -ne " ${INFO} ${str}..." echo -ne " ${INFO} ${str}..."
# Install the directory # Install the directory
@ -1350,8 +1320,6 @@ installPiholeWeb() {
No default index.lighttpd.html file found... not backing up" No default index.lighttpd.html file found... not backing up"
fi fi
fi
# Install Sudoers file # Install Sudoers file
echo "" echo ""
local str="Installing sudoer file" local str="Installing sudoer file"

View file

@ -45,7 +45,7 @@ if [ -x "$(command -v rpm)" ]; then
PKG_MANAGER="yum" PKG_MANAGER="yum"
fi 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 ) PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-pdo git curl unzip wget findutils )
package_check() { package_check() {
rpm -qa | grep ^$1- > /dev/null rpm -qa | grep ^$1- > /dev/null
} }
@ -56,7 +56,7 @@ elif [ -x "$(command -v apt-get)" ]; then
# Debian Family # Debian Family
PKG_MANAGER="apt-get" 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 ) PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common php5-sqlite git curl unzip wget )
package_check() { package_check() {
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
} }

View file

@ -189,107 +189,6 @@ def test_installPiholeWeb_fresh_install_no_errors(Pihole):
assert 'index.js' in web_directory assert 'index.js' in web_directory
assert 'blockingpage.css' 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): def test_update_package_cache_success_no_errors(Pihole):
''' confirms package cache was updated without any errors''' ''' confirms package cache was updated without any errors'''
updateCache = Pihole.run(''' updateCache = Pihole.run('''