From b6372dcf17a49ebf1cf35f9bee742d739ba6bc2c Mon Sep 17 00:00:00 2001 From: Tuschl Date: Wed, 26 Jul 2017 09:06:56 +0200 Subject: [PATCH 1/3] Support changing ifm configuration via docker env vars --- .dockerignore | 2 +- Dockerfile | 22 ++++++++++++++--- apache2-foreground | 8 ------- docker-startup.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 12 deletions(-) delete mode 100755 apache2-foreground create mode 100755 docker-startup.sh diff --git a/.dockerignore b/.dockerignore index 7915c0c..d24cb44 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,3 @@ * !ifm.php -!apache2-foreground +!docker-startup.sh diff --git a/Dockerfile b/Dockerfile index c5e43aa..5392c09 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,22 @@ FROM alpine:3.5 ENV PHP_INI_DIR /etc/php5 +# general settings +ENV IFM_AUTH=0 \ + IFM_AUTH_SOURCE='inline;admin:$2y$10$0Bnm5L4wKFHRxJgNq.oZv.v7yXhkJZQvinJYR2p6X1zPvzyDRUVRC' \ + IFM_ROOT_DIR="" \ + IFM_TMP_DIR="" \ + IFM_DEFAULTTIMEZONE="Europe/Berlin" +# api controls +ENV IFM_API_AJAXREQUEST=1 IFM_API_CHMOD=1 IFM_API_COPYMOVE=1 \ + IFM_API_CREATEDIR=1 IFM_API_CREATEFILE=1 IFM_API_EDIT=1 \ + IFM_API_DELETE=1 IFM_API_DOWNLOAD=1 IFM_API_EXTRACT=1 \ + IFM_API_UPLOAD=1 IFM_API_REMOTEUPLOAD=1 IFM_API_RENAME=1 \ + IFM_API_ZIPNLOAD=1 +# gui controls +ENV IFM_GUI_SHOWLASTMODIFIED=0 IFM_GUI_SHOWFILESIZE=1 IFM_GUI_SHOWOWNER=1 \ + IFM_GUI_SHOWGROUP=1 IFM_GUI_SHOWPERMISSIONS=2 IFM_GUI_SHOWHTDOCS=1 \ + IFM_GUI_SHOWHIDDENFILES=1 IFM_GUI_SHOWPATH=0 # ensure apache user exists with the desired uid RUN set -x \ @@ -76,13 +92,13 @@ RUN { \ echo 'log_errors = On'; \ echo 'error_log = "/var/www/php.log"'; \ } > $PHP_INI_DIR/conf.d/ZZ_ifm.ini - -COPY apache2-foreground /usr/local/bin/ + +COPY docker-startup.sh /usr/local/bin/ COPY ifm.php /var/www/html/index.php WORKDIR /var/www EXPOSE 80 -CMD ["apache2-foreground"] +CMD ["docker-startup.sh"] diff --git a/apache2-foreground b/apache2-foreground deleted file mode 100755 index 819d8ea..0000000 --- a/apache2-foreground +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -set -e - -# Apache gets grumpy about PID files pre-existing -rm -f /usr/local/apache2/logs/httpd.pid - -exec httpd -DFOREGROUND - diff --git a/docker-startup.sh b/docker-startup.sh new file mode 100755 index 0000000..692edf7 --- /dev/null +++ b/docker-startup.sh @@ -0,0 +1,59 @@ +#!/bin/sh +set -e + +################################################################################ +# Adjust ifm configuration according to docker env vars. +# Defaults should match those in ifm.php. See Dockerfile for details. + +# see http://stackoverflow.com/a/2705678/433558 +sed_escape_lhs() { + echo "$@" | sed 's/[]\/$*.^|[]/\\&/g' +} +sed_escape_rhs() { + echo "$@" | sed 's/[\/&]/\\&/g' +} +set_config() { + key=$(sed_escape_lhs "$1") + value=$(sed_escape_rhs "$2" ) + sed -ri -e "s/\"$key\"[[:space:]]*=>.*$/\"$key\" => $value,/" /var/www/html/index.php +} + +# general settings +set_config "auth" "$IFM_AUTH" +set_config "auth_source" "'$IFM_AUTH_SOURCE'" +set_config "root_dir" "'$IFM_ROOT_DIR'" +set_config "tmp_dir" "'$IFM_TMP_DIR'" +set_config "defaulttimezone" "'$IFM_DEFAULTTIMEZONE'" +# api controls +set_config "ajaxrequest" "$IFM_API_AJAXREQUEST" +set_config "chmod" "$IFM_API_CHMOD" +set_config "copymove" "$IFM_API_COPYMOVE" +set_config "createdir" "$IFM_API_CREATEDIR" +set_config "createfile" "$IFM_API_CREATEFILE" +set_config "edit" "$IFM_API_EDIT" +set_config "delete" "$IFM_API_DELETE" +set_config "download" "$IFM_API_DOWNLOAD" +set_config "extract" "$IFM_API_EXTRACT" +set_config "upload" "$IFM_API_UPLOAD" +set_config "remoteupload" "$IFM_API_REMOTEUPLOAD" +set_config "rename" "$IFM_API_RENAME" +set_config "zipnload" "$IFM_API_ZIPNLOAD" +# gui controls +set_config "showlastmodified" "$IFM_GUI_SHOWLASTMODIFIED" +set_config "showfilesize" "$IFM_GUI_SHOWFILESIZE" +set_config "showowner" "$IFM_GUI_SHOWOWNER" +set_config "showgroup" "$IFM_GUI_SHOWGROUP" +set_config "showpermissions" "$IFM_GUI_SHOWPERMISSIONS" +set_config "showhtdocs" "$IFM_GUI_SHOWHTDOCS" +set_config "showhiddenfiles" "$IFM_GUI_SHOWHIDDENFILES" +set_config "showpath" "$IFM_GUI_SHOWPATH" + + +################################################################################ + +# Apache gets grumpy about PID files pre-existing +rm -f /usr/local/apache2/logs/httpd.pid + +# Start up apache +exec httpd -DFOREGROUND + From 6e645aaced1ad3e9ccdcd74ccaefd887c99218d8 Mon Sep 17 00:00:00 2001 From: Tuschl Date: Wed, 26 Jul 2017 09:09:56 +0200 Subject: [PATCH 2/3] Minor whitespace, format and naming adjustments --- Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5392c09..9fbcb6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,7 @@ RUN set -xe; \ xz RUN set -xe; \ - apk add --no-cache --virtual .wordpress-runtime-deps \ + apk add --no-cache --virtual .ifm-runtime-deps \ apache2 \ apache2-utils \ php5-apache2 \ @@ -84,11 +84,11 @@ RUN mkdir -p /run/apache2 \ RUN { \ echo 'date.timezone = "Europe/Berlin"'; \ echo 'zlib.output_compression = On'; \ - echo 'zlib.output_compression_level = 6'; \ - echo 'memory_limit = 256M'; \ - echo 'max_execution_time = 120'; \ - echo 'upload_max_filesize = 512M'; \ - echo 'post_max_size = 512M'; \ + echo 'zlib.output_compression_level = 6'; \ + echo 'memory_limit = 256M'; \ + echo 'max_execution_time = 120'; \ + echo 'upload_max_filesize = 512M'; \ + echo 'post_max_size = 512M'; \ echo 'log_errors = On'; \ echo 'error_log = "/var/www/php.log"'; \ } > $PHP_INI_DIR/conf.d/ZZ_ifm.ini From eb7130063a079bfcd68f471a1342aa90a20c7c60 Mon Sep 17 00:00:00 2001 From: Tuschl Date: Wed, 26 Jul 2017 10:52:41 +0200 Subject: [PATCH 3/3] Add documentation for docker env vars Also, move docker documentation further down to be less invasive --- README.md | 67 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7120e55..1a3ba9f 100644 --- a/README.md +++ b/README.md @@ -27,23 +27,6 @@ The IFM uses the following resources: ## installation Just copy the ifm.php to your webspace - thats all :) -## docker - -The docker image is based on alpine 3.5 for a small image footprint, with necessary apache, php and supporting packages installed and exposes port 80. - -### build image - -Run the following command from the top source dir: - -`docker build -t ifm .` - -### run image - -The script is installed inside the image at `/var/www/html/index.php`. Its default configuration is unchanged, thus it will display the contents of the document root (`/var/www/html`). - -Here is an example of how to start up a container with this image: -`docker run --rm -i -p "9090:80" -v "/data:/var/www/html/data" ifm` - ## key bindings * e - edit / extract current file * hjkl - vim-style navigation (alternative to arrow keys) @@ -76,6 +59,56 @@ The file should contain ONLY ONE LINE: ``` The password hash has to be a hash generated by PHPs `password_hash()` function. The default credentials are "admin:admin". +## docker + +The docker image is based on alpine 3.5 for a small image footprint, with necessary apache, php and supporting packages installed and exposes port 80 + +### build image + +Run the following command from the top source dir: + +`docker build -t ifm .` + +### run image + +The script is installed inside the image at `/var/www/html/index.php`. Its default configuration is unchanged, thus it will display the contents of the document root (`/var/www/html`) + +Here is an example of how to start up a container with this image: + +`docker run --rm -it -e IFM_AUTH=1 -p "9090:80" -v "/data:/var/www/html/data" ifm` + +The script's configuration can be changed by adjusting the corresponding docker environment variables +listed below: + +| PHP config value | Docker env var | +| ------------------ | -------------------------- | +| `auth` | `IFM_AUTH` | +| `auth_source` | `IFM_AUTH_SOURCE` | +| `root_dir` | `IFM_ROOT_DIR` | +| `tmp_dir` | `IFM_TMP_DIR` | +| `defaulttimezone` | `IFM_DEFAULTTIMEZONE` | +| `ajaxrequest` | `IFM_API_AJAXREQUEST` | +| `chmod` | `IFM_API_CHMOD` | +| `copymove` | `IFM_API_COPYMOVE` | +| `createdir` | `IFM_API_CREATEDIR` | +| `createfile` | `IFM_API_CREATEFILE` | +| `edit` | `IFM_API_EDIT` | +| `delete` | `IFM_API_DELETE` | +| `download` | `IFM_API_DOWNLOAD` | +| `extract` | `IFM_API_EXTRACT` | +| `upload` | `IFM_API_UPLOAD` | +| `remoteupload` | `IFM_API_REMOTEUPLOAD` | +| `rename` | `IFM_API_RENAME` | +| `zipnload` | `IFM_API_ZIPNLOAD` | +| `showlastmodified` | `IFM_GUI_SHOWLASTMODIFIED` | +| `showfilesize` | `IFM_GUI_SHOWFILESIZE` | +| `showowner` | `IFM_GUI_SHOWOWNER` | +| `showgroup` | `IFM_GUI_SHOWGROUP` | +| `showpermissions` | `IFM_GUI_SHOWPERMISSIONS` | +| `showhtdocs` | `IFM_GUI_SHOWHTDOCS` | +| `showhiddenfiles` | `IFM_GUI_SHOWHIDDENFILES` | +| `showpath` | `IFM_GUI_SHOWPATH` | + ## screenshots