Skip to content

Commit

Permalink
make sure htadmin/nginx auth files get created with correct ownership (
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Apr 13, 2023
1 parent 1390d78 commit e32b802
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
3 changes: 1 addition & 2 deletions Dockerfiles/nginx.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ RUN set -x ; \
make -j$(getconf _NPROCESSORS_ONLN) ; \
make install ; \
rm -rf /etc/nginx/html/ ; \
mkdir -p /etc/nginx/conf.d/ ; \
mkdir -p /usr/share/nginx/html/ ; \
mkdir -p /etc/nginx/conf.d/ /etc/nginx/auth/ /usr/share/nginx/html/ ; \
install -m644 html/index.html /usr/share/nginx/html/ ; \
install -m644 html/50x.html /usr/share/nginx/html/ ; \
install -m755 objs/nginx-debug /usr/sbin/nginx-debug ; \
Expand Down
36 changes: 13 additions & 23 deletions htadmin/htadmin.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
#!/usr/bin/env bash

HTADMIN_ENABLED=${NGINX_BASIC_AUTH:-"true"}
if [[ "${NGINX_BASIC_AUTH:-true}" == "true" ]]; then

if [[ ! -f /var/www/htadmin/config/config.ini ]] && [[ -f /var/www/htadmin/default/config.ini ]]; then
mkdir -p /var/www/htadmin/config/
cp /var/www/htadmin/default/config.ini /var/www/htadmin/config/config.ini
fi
if [[ ! -f /var/www/htadmin/config/config.ini ]] && [[ -f /var/www/htadmin/default/config.ini ]]; then
cp /var/www/htadmin/default/config.ini /var/www/htadmin/config/config.ini
[[ -n ${PUID} ]] && chown -f ${PUID} /var/www/htadmin/config/config.ini
[[ -n ${PGID} ]] && chown -f :${PGID} /var/www/htadmin/config/config.ini
fi

if [[ ! -f /var/www/htadmin/config/metadata ]] && [[ -f /var/www/htadmin/default/metadata ]]; then
mkdir -p /var/www/htadmin/config/
cp /var/www/htadmin/default/metadata /var/www/htadmin/config/metadata
fi
if [[ ! -f /var/www/htadmin/config/metadata ]] && [[ -f /var/www/htadmin/default/metadata ]]; then
cp /var/www/htadmin/default/metadata /var/www/htadmin/config/metadata
[[ -n ${PUID} ]] && chown -f ${PUID} /var/www/htadmin/config/metadata
[[ -n ${PGID} ]] && chown -f :${PGID} /var/www/htadmin/config/metadata
fi

if [[ "$HTADMIN_ENABLED" == "true" ]]; then
sleep 10
nginx -g "daemon off;"

else
mkdir -p /tmp/htadmin_disabled
pushd /tmp/htadmin_disabled >/dev/null 2>&1 && \
cat << EOF > index.html
<html>
<header><title>Basic Authentication Disabled</title></header>
<body>
<h1>Basic HTTP authentication has been disabled.</h1>
<p>Refer to the <a href="/readme#AuthLDAP" onclick="javascript:event.target.port=443">Malcolm documentation</a> for details on LDAP authentication.</p>
</body>
</html>
EOF
python3 -m http.server 80
popd >/dev/null 2>&1
/usr/local/bin/service_check_passthrough.sh -d -s htadmin -p 80 -f http
fi
5 changes: 3 additions & 2 deletions nginx/scripts/docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ EOF
fi # basic vs. ldap

if [[ ! -f /etc/nginx/auth/htpasswd ]] && [[ -f /tmp/auth/default/htpasswd ]]; then
mkdir -p /etc/nginx/auth/
cp /tmp/auth/default/htpasswd /etc/nginx/auth/
cp /tmp/auth/default/htpasswd /etc/nginx/auth/htpasswd
[[ -n ${PUID} ]] && chown -f ${PUID} /etc/nginx/auth/htpasswd
[[ -n ${PGID} ]] && chown -f :${PGID} /etc/nginx/auth/htpasswd
rm -rf /tmp/auth/* || true
fi

Expand Down
2 changes: 1 addition & 1 deletion shared/bin/service_check_passthrough.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ while getopts 'vds:p:f:' OPTION; do
;;

?)
echo "script usage: $(basename $0) [-v] [-i input]" >&2
echo "script usage: $(basename $0) [-v (verbose)] [-d (disabled)] [-s <service>] [-p <port>] [-f <format>]" >&2
exit 1
;;
esac
Expand Down

0 comments on commit e32b802

Please sign in to comment.