From a4a4227d87eb4f964526d3d8897ff6dc789ef4c0 Mon Sep 17 00:00:00 2001 From: renaud gaudin Date: Mon, 8 Jan 2024 14:04:26 +0000 Subject: [PATCH] Rewriting values in PHP to avoid escaping hell --- file-manager/Dockerfile | 9 ++++--- file-manager/conf-rewrite.php | 21 ++++++++++++++++ file-manager/entrypoint | 46 ++++++++++++----------------------- 3 files changed, 42 insertions(+), 34 deletions(-) create mode 100644 file-manager/conf-rewrite.php diff --git a/file-manager/Dockerfile b/file-manager/Dockerfile index d4fb23c..4314812 100644 --- a/file-manager/Dockerfile +++ b/file-manager/Dockerfile @@ -53,10 +53,11 @@ if (is_readable(\$config_file)) {\n\ }\n" > index.php \ && tail -n +$lnum tinyfilemanager.php >> index.php +COPY config.php $WEBDIR/ +COPY listing_auth.php $WEBDIR/ +COPY manager_auth.php $WEBDIR/ +COPY conf-rewrite.php $WEBDIR/ COPY lighttpd.conf /etc/lighttpd/lighttpd.conf -COPY config.php /var/www/html -COPY listing_auth.php /var/www/html -COPY manager_auth.php /var/www/html COPY entrypoint /usr/local/bin/ # there are three modes: @@ -71,7 +72,7 @@ ENV ADMIN_PASSWORD "admin@123" # timezone to use for date/time (assuming host has date) # /!\ must be escaped! (slash) -ENV UI_TIMEZONE "Etc\/UTC" +ENV UI_TIMEZONE "Etc/UTC" ENV UI_LANG "en" diff --git a/file-manager/conf-rewrite.php b/file-manager/conf-rewrite.php new file mode 100644 index 0000000..6add92d --- /dev/null +++ b/file-manager/conf-rewrite.php @@ -0,0 +1,21 @@ + diff --git a/file-manager/entrypoint b/file-manager/entrypoint index ca7c0b2..94e97a1 100755 --- a/file-manager/entrypoint +++ b/file-manager/entrypoint @@ -1,21 +1,26 @@ #!/bin/sh set -e -echo "set credentials" -sed -i "s/ADMIN_USERNAME/${ADMIN_USERNAME}/g" manager_auth.php -sed -i "s/ADMIN_PASSWORD/${ADMIN_PASSWORD}/g" manager_auth.php - -# mixed mode cannot set APP_URL as there are two apps if [[ "$ACCESS_MODE" = "mixed" ]] then - unset APP_URL + mkdir -p admin + cd admin + cp ../index.php index.php + cp ../config.php config.php + cp ../manager_auth.php manager_auth.php + ln -s manager_auth.php auth.php + # rewrite conf in /admin/ faking + if [[ "$APP_URL" != "" ]] + then + ADMIN_APP_URL="${APP_URL}/admin" + fi + APP_URL="$ADMIN_APP_URL" ACCESS_MODE=manager php83 ../conf-rewrite.php + cd .. + ln -s listing_auth.php auth.php fi -# static replacement for envs (so we can keep clear_env=yes) -echo "set statics" -sed -i "s/UI_TIMEZONE/${UI_TIMEZONE}/g" config.php -sed -i "s/UI_LANG/${UI_LANG}/g" config.php -sed -i "s/APP_URL/${APP_URL}/g" config.php +# rewrite config for single-app mode +php83 ./conf-rewrite.php echo "configuring for ${ACCESS_MODE}" if [[ "$ACCESS_MODE" = "listing" ]] @@ -24,28 +29,9 @@ then elif [[ "$ACCESS_MODE" = "manager" ]] then - ln -s manager_auth.php auth.php - -elif [[ "$ACCESS_MODE" = "mixed" ]] -then - mkdir -p admin - cd admin - cp ../index.php index.php - cp ../config.php config.php - cp ../manager_auth.php auth.php - cd .. - ln -s listing_auth.php auth.php -else - echo "Unsupported mode: ${ACCESS_MODE}" - exit 1 fi -ls -l -cat config.php -cat auth.php -cat manager_auth.php - php-fpm83 -D exec "$@"