From d7ff34fd74f1bbaf001dd1c565a20a83273959a9 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 23 Jan 2023 23:20:30 +0000 Subject: [PATCH] Instead of including a static config file for redirecting it - dynamically create this file on container start. This gets rid of what was probably a hack to have the VIRTUAL_HOST declared as an empty string in the Dockerfile (lighttpd would not start if env.VIRTUAL_HOST was not set Signed-off-by: Adam Warner --- src/Dockerfile | 1 - .../15-pihole-admin-redirect-docker.conf | 8 -------- .../usr/local/bin/bash_functions.sh | 19 ++++++++++++++----- 3 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 src/s6/debian-root/etc/lighttpd/conf-enabled/15-pihole-admin-redirect-docker.conf diff --git a/src/Dockerfile b/src/Dockerfile index 9cc923f..28e7514 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -31,7 +31,6 @@ ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2 ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME 0 ENV FTLCONF_LOCAL_IPV4 0.0.0.0 -ENV VIRTUAL_HOST "" ENV FTL_CMD no-daemon ENV DNSMASQ_USER pihole diff --git a/src/s6/debian-root/etc/lighttpd/conf-enabled/15-pihole-admin-redirect-docker.conf b/src/s6/debian-root/etc/lighttpd/conf-enabled/15-pihole-admin-redirect-docker.conf deleted file mode 100644 index b179ce8..0000000 --- a/src/s6/debian-root/etc/lighttpd/conf-enabled/15-pihole-admin-redirect-docker.conf +++ /dev/null @@ -1,8 +0,0 @@ -$HTTP["url"] == "/" { - $HTTP["host"] == env.VIRTUAL_HOST { - url.redirect = ("" => "/admin/") - } - $HTTP["host"] == env.FTLCONF_LOCAL_IPV4 { - url.redirect = ("" => "/admin/") - } -} \ No newline at end of file diff --git a/src/s6/debian-root/usr/local/bin/bash_functions.sh b/src/s6/debian-root/usr/local/bin/bash_functions.sh index 611ca8c..14c766a 100644 --- a/src/s6/debian-root/usr/local/bin/bash_functions.sh +++ b/src/s6/debian-root/usr/local/bin/bash_functions.sh @@ -117,8 +117,6 @@ ensure_basic_configuration() { if [ ! -f /etc/dnsmasq.d/01-pihole.conf ] ; then cp /etc/.pihole/advanced/01-pihole.conf /etc/dnsmasq.d/ fi; - - # setup_or_skip_gravity } validate_env() { @@ -364,9 +362,7 @@ setup_web_php_env() { local config_file config_file="/etc/lighttpd/conf-available/15-pihole-admin.conf" # if the environment variable VIRTUAL_HOST is not set, or is empty, then set it to the hostname of the container - if [ -z "${VIRTUAL_HOST}" ] || [ "${VIRTUAL_HOST}" == "" ]; then - VIRTUAL_HOST="${HOSTNAME}" - fi + VIRTUAL_HOST="${VIRTUAL_HOST:-$HOSTNAME}" for config_var in "VIRTUAL_HOST" "CORS_HOSTS" "PHP_ERROR_LOG" "PIHOLE_DOCKER_TAG" "TZ"; do local beginning_of_line=" \"${config_var}\" => " @@ -381,6 +377,19 @@ setup_web_php_env() { echo " [i] Added ENV to php:" grep -E '(VIRTUAL_HOST|CORS_HOSTS|PHP_ERROR_LOG|PIHOLE_DOCKER_TAG|TZ)' "$config_file" + + # Create an additional file in the lighttpd config directory to redirect the root to the admin page + # if the host matches either VIRTUAL_HOST (Or HOSTNAME if it is not set) or FTLCONF_LOCAL_IPV4 + cat < /etc/lighttpd/conf-enabled/15-pihole-admin-redirect-docker.conf + \$HTTP["url"] == "/" { + \$HTTP["host"] == "${VIRTUAL_HOST}" { + url.redirect = ("" => "/admin/") + } + \$HTTP["host"] == "${FTLCONF_LOCAL_IPV4}" { + url.redirect = ("" => "/admin/") + } + } +END } setup_web_port() {