mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-23 21:30:17 +00:00
Merge branch 'development' into tweak/gravity
This commit is contained in:
commit
34ae4844fa
5 changed files with 104 additions and 211 deletions
|
@ -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='[1m'
|
||||
COL_ULINE='[4m'
|
||||
|
||||
COL_NC='[0m'
|
||||
COL_WHITE='[1;37m'
|
||||
COL_BLACK='[0;30m'
|
||||
COL_BLUE='[0;34m'
|
||||
COL_LIGHT_BLUE='[1;34m'
|
||||
COL_GREEN='[0;32m'
|
||||
COL_LIGHT_GREEN='[1;32m'
|
||||
COL_CYAN='[0;36m'
|
||||
COL_LIGHT_CYAN='[1;36m'
|
||||
COL_RED='[0;31m'
|
||||
COL_LIGHT_RED='[1;31m'
|
||||
COL_URG_RED='[39;41m'
|
||||
COL_PURPLE='[0;35m'
|
||||
COL_LIGHT_PURPLE='[1;35m'
|
||||
COL_BROWN='[0;33m'
|
||||
COL_YELLOW='[1;33m'
|
||||
COL_GRAY='[0;30m'
|
||||
COL_LIGHT_GRAY='[0;37m'
|
||||
COL_DARK_GRAY='[1;30m'
|
||||
COL_GRAY='[90m'
|
||||
COL_RED='[91m'
|
||||
COL_GREEN='[32m'
|
||||
COL_YELLOW='[33m'
|
||||
COL_BLUE='[94m'
|
||||
COL_PURPLE='[95m'
|
||||
COL_CYAN='[96m'
|
||||
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[K"
|
||||
|
|
|
@ -217,6 +217,10 @@ SetExcludeClients() {
|
|||
change_setting "API_EXCLUDE_CLIENTS" "${args[2]}"
|
||||
}
|
||||
|
||||
Poweroff(){
|
||||
nohup bash -c "sleep 5; poweroff" &> /dev/null </dev/null &
|
||||
}
|
||||
|
||||
Reboot() {
|
||||
nohup bash -c "sleep 5; reboot" &> /dev/null </dev/null &
|
||||
}
|
||||
|
@ -467,6 +471,7 @@ main() {
|
|||
"setdns" ) SetDNSServers;;
|
||||
"setexcludedomains" ) SetExcludeDomains;;
|
||||
"setexcludeclients" ) SetExcludeClients;;
|
||||
"poweroff" ) Poweroff;;
|
||||
"reboot" ) Reboot;;
|
||||
"restartdns" ) RestartDNS;;
|
||||
"setquerylog" ) SetQueryLogOptions;;
|
||||
|
|
|
@ -154,7 +154,12 @@ if command -v apt-get &> /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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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('''
|
||||
|
|
Loading…
Reference in a new issue