Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made it support having templates externally #87

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ but setting your own config.php is possible. 2 options:

- Add your config file by extending or cloning this image, please refer to the [Advanced User Guide](#advanced-user-guide)

### Use your own templates directory

2 options:

- Link your templates directory at run time to /container/service/phpldapadmin/assets/templates

docker run --volume /data/phpldapadmin/assets/templates:/container/service/phpldapadmin/assets/templates --detach osixia/phpldapadmin:0.9.0

- Add your templates file by extending or cloning this image, please refer to the [Advanced User Guide](#advanced-user-guide)

### HTTPS

#### Use autogenerated certificate
Expand Down Expand Up @@ -185,6 +195,8 @@ See how to [set your own environment variables](#set-your-own-environment-variab
Apache :
- **PHPLDAPADMIN_SERVER_ADMIN**: Server admin email. Defaults to `[email protected]`
- **PHPLDAPADMIN_SERVER_PATH**: Server path (usefull if behind a reverse proxy). Defaults to `/phpldapadmin`
- **PHPLDAPADMIN_WWW_DATA_UID**: runtime docker user uid to run container as
- **PHPLDAPADMIN_WWW_DATA_GID**: runtime docker user gid to run container as

HTTPS :
- **PHPLDAPADMIN_HTTPS**: Use apache ssl config. Defaults to `true`
Expand Down
70 changes: 69 additions & 1 deletion image/service/phpldapadmin/startup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
#!/bin/bash -e



# ensure_uid $servicename $intended_uid $intended_gid $filename(s)
# Taken from OpenLDAP image; should be moved to the shared image at some point, then used by this script and OpenLDAP both
function ensure_uid() {
local servicename=$1
local intended_uid=${2:-33}
local intended_gid=${3:-33}
# Because there are 3 positional params
shift 3

log-helper info "$servicename user and group adjustments"

log-helper info "get current $servicename uid/gid info inside container"
CUR_USER_GID=`id -g $servicename || true`
CUR_USER_UID=`id -u $servicename || true`

SERVICE_UIDGID_CHANGED=false
if [ "$intended_uid" != "$CUR_USER_UID" ]; then
log-helper info "CUR_USER_UID (${CUR_USER_UID}) does't match intended_uid (${intended_uid}), adjusting..."
usermod -o -u "$intended_uid" $servicename
SERVICE_UIDGID_CHANGED=true
fi
if [ "$intended_gid" != "$CUR_USER_GID" ]; then
log-helper info "CUR_USER_GID (${CUR_USER_GID}) does't match intended_gid (${intended_gid}), adjusting..."
groupmod -o -g "$intended_gid" $servicename
SERVICE_UIDGID_CHANGED=true
fi

log-helper info '-------------------------------------'
log-helper info '$servicename GID/UID'
log-helper info '-------------------------------------'
log-helper info "User uid: $(id -u $servicename)"
log-helper info "User gid: $(id -g $servicename)"
log-helper info "uid/gid changed: ${SERVICE_UIDGID_CHANGED}"
log-helper info "-------------------------------------"

# fix file permissions
if [ "${DISABLE_CHOWN,,}" == "false" ]; then
log-helper info "updating file uid/gid ownership"
if [ ! -z "$*" ]; then
for file in $*; do
chown -R $servicename:$servicename $file
done
fi
fi
}

# set -x (bash debug) if log level is trace
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/log-helper
log-helper level eq trace && set -x
Expand Down Expand Up @@ -141,12 +189,32 @@ if [ ! -e "/var/www/phpldapadmin/config/config.php" ]; then

fi

PHPLDAPADMIN_WWW_DATA_UID=${PHPLDAPADMIN_WWW_DATA_UID:-33}
PHPLDAPADMIN_WWW_DATA_GID=${PHPLDAPADMIN_WWW_DATA_GID:-33}
ensure_uid www-data $PHPLDAPADMIN_WWW_DATA_UID $PHPLDAPADMIN_WWW_DATA_GID /var/www

##### For each template...
templatedir=${CONTAINER_SERVICE_DIR}/phpldapadmin/assets/templates
echo "Finding templates"
find ${CONTAINER_SERVICE_DIR}/phpldapadmin/assets/
shopt -s nullglob
for action in creation modification; do
for template in ${templatedir}/${action}/*.xml; do
basename=`basename $template`
log-helper info "Linking $action template for $template"
target=/var/www/phpldapadmin/templates/$action/$basename
ln -sf $template $target
chown $PHPLDAPADMIN_WWW_DATA_UID:$PHPLDAPADMIN_WWW_DATA_GID $target
done
done
shopt -u nullglob

# fix file permission
find /var/www/ -type d -exec chmod 755 {} \;
find /var/www/ -type f -exec chmod 644 {} \;
chown www-data:www-data -R /var/www

# symlinks special (chown -R don't follow symlinks)
# Should be redone because of ensure_uid above
chown www-data:www-data /var/www/phpldapadmin/config/config.php
chmod 400 /var/www/phpldapadmin/config/config.php

Expand Down