1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 23:08:07 +00:00

Merge pull request #1182 from pi-hole/adminPageAsOption

Give user the choice to install web admin or not
This commit is contained in:
Mcat12 2017-02-09 20:20:08 -05:00 committed by GitHub
commit cd608d9d5b
2 changed files with 225 additions and 114 deletions

View File

@ -80,8 +80,8 @@ main() {
local web_version_current local web_version_current
#This is unlikely #This is unlikely
if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${ADMIN_INTERFACE_DIR}" ; then if ! is_repo "${PI_HOLE_FILES_DIR}" ; then
echo "::: Critical Error: One or more Pi-Hole repos are missing from system!" echo "::: Critical Error: Core Pi-Hole repo is missing from system!"
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
exit 1; exit 1;
fi fi
@ -96,6 +96,13 @@ main() {
echo "::: Pi-hole Core: up to date" echo "::: Pi-hole Core: up to date"
fi fi
if [[ ${INSTALL_WEB} == true ]]; then
if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then
echo "::: Critical Error: Web Admin repo is missing from system!"
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
exit 1;
fi
if GitCheckUpdateAvail "${ADMIN_INTERFACE_DIR}" ; then if GitCheckUpdateAvail "${ADMIN_INTERFACE_DIR}" ; then
web_update=true web_update=true
echo "::: Web Interface: update available" echo "::: Web Interface: update available"
@ -139,6 +146,18 @@ main() {
echo "*** Update script has malfunctioned, fallthrough reached. Please contact support" echo "*** Update script has malfunctioned, fallthrough reached. Please contact support"
exit 1 exit 1
fi fi
else # Web Admin not installed, so only verify if core is up to date
if ! ${core_update}; then
echo ":::"
echo "::: Everything is up to date!"
exit 0
else
echo ":::"
echo "::: Pi-hole core files out of date"
getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}"
${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --reconfigure --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1
fi
fi
if [[ "${web_update}" == true ]]; then if [[ "${web_update}" == true ]]; then
web_version_current="$(/usr/local/bin/pihole version --admin --current)" web_version_current="$(/usr/local/bin/pihole version --admin --current)"

View File

@ -34,6 +34,8 @@ useUpdateVars=false
IPV4_ADDRESS="" IPV4_ADDRESS=""
IPV6_ADDRESS="" IPV6_ADDRESS=""
QUERY_LOGGING=true QUERY_LOGGING=true
INSTALL_WEB=true
# Find the rows and columns will default to 80x24 is it can not be detected # Find the rows and columns will default to 80x24 is it can not be detected
screen_size=$(stty size 2>/dev/null || echo 24 80) screen_size=$(stty size 2>/dev/null || echo 24 80)
@ -63,14 +65,14 @@ if command -v apt-get &> /dev/null; then
# grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE
PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"
# ######################################### # #########################################
# fixes for dependancy differences # fixes for dependency differences
# Debian 7 doesn't have iproute2 use iproute # Debian 7 doesn't have iproute2 use iproute
if ${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1; then if ${PKG_MANAGER} install --dry-run iproute2 > /dev/null 2>&1; then
iproute_pkg="iproute2" iproute_pkg="iproute2"
else else
iproute_pkg="iproute" iproute_pkg="iproute"
fi fi
# Prefer the php metapackage if it's there, fall back on the php5 pacakges # Prefer the php metapackage if it's there, fall back on the php5 packages
if ${PKG_MANAGER} install --dry-run php > /dev/null 2>&1; then if ${PKG_MANAGER} install --dry-run php > /dev/null 2>&1; then
phpVer="php" phpVer="php"
else else
@ -78,7 +80,8 @@ if command -v apt-get &> /dev/null; then
fi fi
# ######################################### # #########################################
INSTALLER_DEPS=(apt-utils debconf dhcpcd5 git ${iproute_pkg} whiptail) INSTALLER_DEPS=(apt-utils debconf dhcpcd5 git ${iproute_pkg} whiptail)
PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lighttpd lsof netcat ${phpVer}-common ${phpVer}-cgi sudo unzip wget) PIHOLE_DEPS=(bc cron curl dnsmasq dnsutils iputils-ping lsof netcat sudo unzip wget)
PIHOLE_WEB_DEPS=(lighttpd ${phpVer}-common ${phpVer}-cgi)
LIGHTTPD_USER="www-data" LIGHTTPD_USER="www-data"
LIGHTTPD_GROUP="www-data" LIGHTTPD_GROUP="www-data"
LIGHTTPD_CFG="lighttpd.conf.debian" LIGHTTPD_CFG="lighttpd.conf.debian"
@ -97,8 +100,8 @@ elif command -v rpm &> /dev/null; then
PKG_INSTALL=(${PKG_MANAGER} install -y) PKG_INSTALL=(${PKG_MANAGER} install -y)
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=(git iproute net-tools newt procps-ng) INSTALLER_DEPS=(git iproute net-tools newt procps-ng)
PIHOLE_DEPS=(bc bind-utils cronie curl dnsmasq findutils lighttpd lighttpd-fastcgi nmap-ncat php php-common php-cli 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)
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
@ -546,6 +549,27 @@ setLogging() {
esac esac
} }
setAdminFlag() {
local WebToggleCommand
local WebChooseOptions
local WebChoices
WebToggleCommand=(whiptail --separate-output --radiolist "Do you wish to install the web admin interface?" ${r} ${c} 6)
WebChooseOptions=("On (Recommended)" "" on
Off "" off)
WebChoices=$("${WebToggleCommand[@]}" "${WebChooseOptions[@]}" 2>&1 >/dev/tty) || (echo "::: Cancel selected. Exiting..." && exit 1)
case ${WebChoices} in
"On (Recommended)")
echo "::: Web Interface On."
INSTALL_WEB=true
;;
Off)
echo "::: Web Interface off."
INSTALL_WEB=false
;;
esac
}
version_check_dnsmasq() { version_check_dnsmasq() {
# Check if /etc/dnsmasq.conf is from pihole. If so replace with an original and install new in .d directory # Check if /etc/dnsmasq.conf is from pihole. If so replace with an original and install new in .d directory
@ -643,6 +667,9 @@ installConfigs() {
echo ":::" echo ":::"
echo "::: Installing configs..." echo "::: Installing configs..."
version_check_dnsmasq version_check_dnsmasq
#Only mess with lighttpd configs if user has chosen to install web interface
if [[ ${INSTALL_WEB} == true ]]; then
if [ ! -d "/etc/lighttpd" ]; then if [ ! -d "/etc/lighttpd" ]; then
mkdir /etc/lighttpd mkdir /etc/lighttpd
chown "${USER}":root /etc/lighttpd chown "${USER}":root /etc/lighttpd
@ -656,6 +683,7 @@ installConfigs() {
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress
mkdir -p /var/cache/lighttpd/uploads mkdir -p /var/cache/lighttpd/uploads
chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/uploads chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/uploads
fi
} }
stop_service() { stop_service() {
@ -917,6 +945,17 @@ configureFirewall() {
} }
finalExports() { finalExports() {
if [[ ${INSTALL_WEB} == false ]]; then
#No web interface installed, and therefore no block page set IPV4/6 to 0.0.0.0 and ::/0
if [ ${IPV4_ADDRESS} ]; then
IPV4_ADDRESS="0.0.0.0"
fi
if [ ${IPV6_ADDRESS} ]; then
IPV6_ADDRESS="::/0"
fi
fi
# Update variables in setupVars.conf file # Update variables in setupVars.conf file
if [ -e "${setupVars}" ]; then if [ -e "${setupVars}" ]; then
sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/QUERY_LOGGING/d;' "${setupVars}" sed -i.update.bak '/PIHOLE_INTERFACE/d;/IPV4_ADDRESS/d;/IPV6_ADDRESS/d;/PIHOLE_DNS_1/d;/PIHOLE_DNS_2/d;/QUERY_LOGGING/d;' "${setupVars}"
@ -928,6 +967,7 @@ finalExports() {
echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}" echo "PIHOLE_DNS_1=${PIHOLE_DNS_1}"
echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}" echo "PIHOLE_DNS_2=${PIHOLE_DNS_2}"
echo "QUERY_LOGGING=${QUERY_LOGGING}" echo "QUERY_LOGGING=${QUERY_LOGGING}"
echo "INSTALL_WEB=${INSTALL_WEB}"
}>> "${setupVars}" }>> "${setupVars}"
# Look for DNS server settings which would have to be reapplied # Look for DNS server settings which would have to be reapplied
@ -964,6 +1004,8 @@ installLogrotate() {
installPihole() { installPihole() {
# Install base files and web interface # Install base files and web interface
create_pihole_user create_pihole_user
if [[ ${INSTALL_WEB} == true ]]; then
if [ ! -d "/var/www/html" ]; then if [ ! -d "/var/www/html" ]; then
mkdir -p /var/www/html mkdir -p /var/www/html
fi fi
@ -975,15 +1017,18 @@ installPihole() {
else else
printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n"
fi fi
fi
installScripts installScripts
installConfigs installConfigs
CreateLogFile CreateLogFile
if [[ ${INSTALL_WEB} == true ]]; then
installPiholeWeb installPiholeWeb
fi
installCron installCron
installLogrotate installLogrotate
configureFirewall configureFirewall
finalExports finalExports
runGravity #runGravity
} }
accountForRefactor() { accountForRefactor() {
@ -1003,17 +1048,17 @@ accountForRefactor() {
updatePihole() { updatePihole() {
accountForRefactor accountForRefactor
# Source ${setupVars} for use in the rest of the functions.
source ${setupVars}
# Install base files and web interface # Install base files and web interface
installScripts installScripts
installConfigs installConfigs
CreateLogFile CreateLogFile
if [[ ${INSTALL_WEB} == true ]]; then
installPiholeWeb installPiholeWeb
fi
installCron installCron
installLogrotate installLogrotate
finalExports #re-export setupVars.conf to account for any new vars added in new versions finalExports #re-export setupVars.conf to account for any new vars added in new versions
runGravity #runGravity
} }
@ -1035,6 +1080,13 @@ checkSelinux() {
} }
displayFinalMessage() { displayFinalMessage() {
if [[ ${INSTALL_WEB} == true ]]; then
additional="View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin
Your Admin Webpage login password is ${1:-"NOT SET"}"
fi
# Final completion message to user # Final completion message to user
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using: whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using:
@ -1044,9 +1096,8 @@ IPv6: ${IPV6_ADDRESS:-"Not Configured"}
If you set a new IP address, you should restart the Pi. If you set a new IP address, you should restart the Pi.
The install log is in /etc/pihole. The install log is in /etc/pihole.
View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin
Your Admin Webpage login password is ${1:-"NOT SET"}" ${r} ${c} ${additional}" ${r} ${c}
} }
update_dialogs() { update_dialogs() {
@ -1080,6 +1131,25 @@ update_dialogs() {
esac esac
} }
clone_or_update_repos() {
if [[ "${reconfigure}" == true ]]; then
echo "::: --reconfigure passed to install script. Not downloading/updating local repos"
else
# Get Git files for Core and Admin
getGitFiles ${PI_HOLE_LOCAL_REPO} ${piholeGitUrl} || \
{ echo "!!! Unable to clone ${piholeGitUrl} into ${PI_HOLE_LOCAL_REPO}, unable to continue."; \
exit 1; \
}
if [[ ${INSTALL_WEB} == true ]]; then
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} || \
{ echo "!!! Unable to clone ${webInterfaceGitUrl} into ${webInterfaceDir}, unable to continue."; \
exit 1; \
}
fi
fi
}
main() { main() {
######## FIRST CHECK ######## ######## FIRST CHECK ########
@ -1145,28 +1215,17 @@ main() {
# Check if SELinux is Enforcing # Check if SELinux is Enforcing
checkSelinux checkSelinux
if [[ "${reconfigure}" == true ]]; then
echo "::: --reconfigure passed to install script. Not downloading/updating local repos"
else
# Get Git files for Core and Admin
getGitFiles ${PI_HOLE_LOCAL_REPO} ${piholeGitUrl} || \
{ echo "!!! Unable to clone ${piholeGitUrl} into ${PI_HOLE_LOCAL_REPO}, unable to continue."; \
exit 1; \
}
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} || \
{ echo "!!! Unable to clone ${webInterfaceGitUrl} into ${webInterfaceDir}, unable to continue."; \
exit 1; \
}
fi
if [[ ${useUpdateVars} == false ]]; then if [[ ${useUpdateVars} == false ]]; then
# Display welcome dialogs # Display welcome dialogs
welcomeDialogs welcomeDialogs
# Create directory for Pi-hole storage # Create directory for Pi-hole storage
mkdir -p /etc/pihole/ mkdir -p /etc/pihole/
# Stop resolver and webserver while installing proceses
stop_service dnsmasq stop_service dnsmasq
if [[ ${INSTALL_WEB} == true ]]; then
stop_service lighttpd stop_service lighttpd
fi
# Determine available interfaces # Determine available interfaces
get_available_interfaces get_available_interfaces
# Find interfaces and let the user choose one # Find interfaces and let the user choose one
@ -1175,17 +1234,38 @@ main() {
setDNS setDNS
# Let the user decide if they want to block ads over IPv4 and/or IPv6 # Let the user decide if they want to block ads over IPv4 and/or IPv6
use4andor6 use4andor6
# Let the user decide if they want the web interface to be installed automatically
setAdminFlag
# Let the user decide if they want query logging enabled... # Let the user decide if they want query logging enabled...
setLogging setLogging
# Clone/Update the repos
clone_or_update_repos
# Install packages used by the Pi-hole # Install packages used by the Pi-hole
install_dependent_packages PIHOLE_DEPS[@] if [[ ${INSTALL_WEB} == true ]]; then
DEPS=("${PIHOLE_DEPS[@]}" "${PIHOLE_WEB_DEPS[@]}")
else
DEPS=("${PIHOLE_DEPS[@]}")
fi
install_dependent_packages DEPS[@]
# Install and log everything to a file # Install and log everything to a file
installPihole | tee ${tmpLog} installPihole | tee ${tmpLog}
else else
# update packages used by the Pi-hole # Clone/Update the repos
install_dependent_packages PIHOLE_DEPS[@] clone_or_update_repos
# Source ${setupVars} for use in the rest of the functions.
source ${setupVars}
# Install packages used by the Pi-hole
if [[ ${INSTALL_WEB} == true ]]; then
DEPS=("${PIHOLE_DEPS[@]}" "${PIHOLE_WEB_DEPS[@]}")
else
DEPS=("${PIHOLE_DEPS[@]}")
fi
install_dependent_packages DEPS[@]
updatePihole | tee ${tmpLog} updatePihole | tee ${tmpLog}
fi fi
@ -1193,25 +1273,33 @@ main() {
# Move the log file into /etc/pihole for storage # Move the log file into /etc/pihole for storage
mv ${tmpLog} ${instalLogLoc} mv ${tmpLog} ${instalLogLoc}
if [[ ${INSTALL_WEB} == true ]]; then
# Add password to web UI if there is none # Add password to web UI if there is none
pw="" pw=""
if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then if [[ $(grep 'WEBPASSWORD' -c /etc/pihole/setupVars.conf) == 0 ]] ; then
pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8) pw=$(tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
/usr/local/bin/pihole -a -p "${pw}" /usr/local/bin/pihole -a -p "${pw}"
fi fi
if [[ "${useUpdateVars}" == false ]]; then
displayFinalMessage "${pw}"
fi fi
echo "::: Restarting services..." echo "::: Restarting services..."
# Start services # Start services
start_service dnsmasq start_service dnsmasq
enable_service dnsmasq enable_service dnsmasq
if [[ ${INSTALL_WEB} == true ]]; then
start_service lighttpd start_service lighttpd
enable_service lighttpd enable_service lighttpd
fi
runGravity
echo "::: done." echo "::: done."
if [[ "${useUpdateVars}" == false ]]; then
displayFinalMessage "${pw}"
fi
echo ":::" echo ":::"
if [[ "${useUpdateVars}" == false ]]; then if [[ "${useUpdateVars}" == false ]]; then
echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
@ -1219,11 +1307,14 @@ main() {
echo "::: ${IPV6_ADDRESS}" echo "::: ${IPV6_ADDRESS}"
echo ":::" echo ":::"
echo "::: If you set a new IP address, you should restart the Pi." echo "::: If you set a new IP address, you should restart the Pi."
if [[ ${INSTALL_WEB} == true ]]; then
echo "::: View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin" echo "::: View the web interface at http://pi.hole/admin or http://${IPV4_ADDRESS%/*}/admin"
fi
else else
echo "::: Update complete!" echo "::: Update complete!"
fi fi
if [[ ${INSTALL_WEB} == true ]]; then
if (( ${#pw} > 0 )) ; then if (( ${#pw} > 0 )) ; then
echo ":::" echo ":::"
echo "::: Note: As security measure a password has been installed for your web interface" echo "::: Note: As security measure a password has been installed for your web interface"
@ -1233,6 +1324,7 @@ main() {
echo "::: You can always change it using" echo "::: You can always change it using"
echo "::: pihole -a -p new_password" echo "::: pihole -a -p new_password"
fi fi
fi
echo ":::" echo ":::"
echo "::: The install log is located at: /etc/pihole/install.log" echo "::: The install log is located at: /etc/pihole/install.log"