From 4cd5f5dc6bf734eade2c604ea300b443283358b5 Mon Sep 17 00:00:00 2001 From: ofreax Date: Fri, 21 Aug 2015 10:52:58 +0200 Subject: [PATCH] Better way to add custom config --- CHANGELOG.md | 3 + Makefile | 2 +- README.md | 10 ++-- image/Dockerfile | 2 +- image/service/phpldapadmin/assets/README.md | 1 + image/service/phpldapadmin/assets/config.php | 5 +- image/service/phpldapadmin/container-start.sh | 56 +++++++++++-------- image/service/phpldapadmin/install.sh | 3 - 8 files changed, 47 insertions(+), 35 deletions(-) create mode 100644 image/service/phpldapadmin/assets/README.md diff --git a/CHANGELOG.md b/CHANGELOG.md index deeffdc..8dd1732 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.6.2 + - Better way to add custom config + ## 0.6.1 - Upgrade baseimage: osixia/web-baseimage:0.1.1 - Rename environment variables diff --git a/Makefile b/Makefile index da82662..1c82414 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ NAME = osixia/phpldapadmin -VERSION = 0.6.1 +VERSION = 0.6.2 .PHONY: all build test tag_latest release diff --git a/README.md b/README.md index 2ddb6f6..63f0df8 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Example script: LDAP_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $LDAP_CID) # Run phpLDAPadmin and set ldap host to ldap ip - PHPLDAP_CID=$(docker run -h phpldapadmin.example.org -e PHPLDAPADMIN_LDAP_HOSTS=$LDAP_IP -d osixia/phpldapadmin:0.6.1) + PHPLDAP_CID=$(docker run -h phpldapadmin.example.org -e PHPLDAPADMIN_LDAP_HOSTS=$LDAP_IP -d osixia/phpldapadmin:0.6.2) # We get phpLDAPadmin container ip PHPLDAP_IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $PHPLDAP_CID) @@ -99,16 +99,16 @@ Environement variables defaults are set in **image/env.yaml**. You can modify en To convert yaml to python online : http://yaml-online-parser.appspot.com/ -Apache config : +Apache : - **PHPLDAPADMIN_SERVER_ADMIN**: Server admin email. Defaults to `webmaster@example.org` -PHPLDAPADMIN_HTTPS options : +HTTPS : - **PHPLDAPADMIN_HTTPS**: Use apache ssl config. Defaults to `true` - **PHPLDAPADMIN_HTTPS_CRT_FILENAME**: Apache ssl certificate filename. Defaults to `phpldapadmin.crt` - **PHPLDAPADMIN_HTTPS_KEY_FILENAME**: Apache ssl certificate private key filename. Defaults to `phpldapadmin.key` - **PHPLDAPADMIN_HTTPS_CA_CRT_FILENAME**: Apache ssl CA certificate filename. Defaults to `ca.crt` -Ldap client TLS/LDAPS options : +Ldap client TLS/LDAPS : - **PHPLDAPADMIN_LDAP_CLIENT_TLS**: Enable ldap client tls config, ldap serveur certificate check and set client certificate. Defaults to `true` - **PHPLDAPADMIN_LDAP_CLIENT_TLS_REQCERT**: Set ldap.conf TLS_REQCERT. Defaults to `demand` @@ -140,7 +140,7 @@ Clone this project : Adapt Makefile, set your image NAME and VERSION, for example : NAME = osixia/phpldapadmin - VERSION = 0.6.0 + VERSION = 0.6.2 becomes : NAME = billy-the-king/phpldapadmin diff --git a/image/Dockerfile b/image/Dockerfile index a0975f3..5961e3f 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -1,4 +1,4 @@ -FROM osixia/web-baseimage:0.1.1 +FROM osixia/web-baseimage:0.1.2 MAINTAINER Bertrand Gouny # phpLDAPadmin version diff --git a/image/service/phpldapadmin/assets/README.md b/image/service/phpldapadmin/assets/README.md new file mode 100644 index 0000000..f7b77d6 --- /dev/null +++ b/image/service/phpldapadmin/assets/README.md @@ -0,0 +1 @@ +Add your custom config.php file here or mount one at docker run to /container/service/phpldapadmin/assets/config.php diff --git a/image/service/phpldapadmin/assets/config.php b/image/service/phpldapadmin/assets/config.php index 550ba97..83f9095 100644 --- a/image/service/phpldapadmin/assets/config.php +++ b/image/service/phpldapadmin/assets/config.php @@ -28,7 +28,7 @@ /* * Autogenerated value will be automatically added by phpldapadmin/container-start.sh */ - $config->custom->session['blowfish'] = '{{ PHPMYADMIN_CONFIG_BLOWFISH }}'; + $config->custom->session['blowfish'] = '{{ PHPLDAPADMIN_CONFIG_BLOWFISH }}'; /********************************************* @@ -63,5 +63,6 @@ $servers = new Datastore(); /* - * Autogenerated servers will come here + * Autogenerated servers variables will come here */ +{{ PHPLDAPADMIN_SERVERS }} diff --git a/image/service/phpldapadmin/container-start.sh b/image/service/phpldapadmin/container-start.sh index 0647bf9..b70bfd9 100755 --- a/image/service/phpldapadmin/container-start.sh +++ b/image/service/phpldapadmin/container-start.sh @@ -27,13 +27,21 @@ if [ ! -e "$FIRST_START_DONE" ]; then cp -R /var/www/phpldapadmin_bootstrap/* /var/www/phpldapadmin rm -rf /var/www/phpldapadmin_bootstrap + echo "link /container/service/phpldapadmin/assets/config.php to /var/www/phpldapadmin/config/config.php" + ln -s /container/service/phpldapadmin/assets/config.php /var/www/phpldapadmin/config/config.php + get_salt() { salt=$(,()*.^@$% =-_~;:/{}[]+!`azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN' | head -c64 | tr -d '\\') } # phpLDAPadmin cookie secret get_salt - sed -i "s|{{ PHPMYADMIN_CONFIG_BLOWFISH }}|${salt}|g" /var/www/phpldapadmin/config/config.php + sed -i "s|{{ PHPLDAPADMIN_CONFIG_BLOWFISH }}|${salt}|g" /var/www/phpldapadmin/config/config.php + + append_to_servers() { + TO_APPEND=$1 + sed -i "s|{{ PHPLDAPADMIN_SERVERS }}|${TO_APPEND}\n{{ PHPLDAPADMIN_SERVERS }}|g" /var/www/phpldapadmin/config/config.php + } print_by_php_type() { @@ -81,12 +89,12 @@ if [ ! -e "$FIRST_START_DONE" ]; then # the value contain a not empty variable elif [ -n "${!value}" ]; then local php_value=$(print_by_php_type ${!value}) - echo "\$servers->setValue($to_print'$key',$php_value);" >> /var/www/phpldapadmin/config/config.php + append_to_servers "\$servers->setValue($to_print'$key',$php_value);" # it's just a not empty value elif [ -n "$value" ]; then local php_value=$(print_by_php_type $value) - echo "\$servers->setValue($to_print'$key',$php_value);" >> /var/www/phpldapadmin/config/config.php + append_to_servers "\$servers->setValue($to_print'$key',$php_value);" fi } @@ -98,46 +106,48 @@ if [ ! -e "$FIRST_START_DONE" ]; then # host var contain a variable name, we access to the variable value and cast it to a table infos=(${!host}) - echo "\$servers->newServer('ldap_pla');" >> /var/www/phpldapadmin/config/config.php + append_to_servers "\$servers->newServer('ldap_pla');" # it's a table of infos if [ "${#infos[@]}" -gt "1" ]; then - echo "\$servers->setValue('server','name','${!infos[0]}');" >> /var/www/phpldapadmin/config/config.php - echo "\$servers->setValue('server','host','${!infos[0]}');" >> /var/www/phpldapadmin/config/config.php + append_to_servers "\$servers->setValue('server','name','${!infos[0]}');" + append_to_servers "\$servers->setValue('server','host','${!infos[0]}');" host_infos "" ${infos[1]} # it's just a host name # stored in a variable elif [ -n "${!host}" ]; then - echo "\$servers->setValue('server','name','${!host}');" >> /var/www/phpldapadmin/config/config.php - echo "\$servers->setValue('server','host','${!host}');" >> /var/www/phpldapadmin/config/config.php + append_to_servers "\$servers->setValue('server','name','${!host}');" + append_to_servers "\$servers->setValue('server','host','${!host}');" # directly else - echo "\$servers->setValue('server','name','${host}');" >> /var/www/phpldapadmin/config/config.php - echo "\$servers->setValue('server','host','${host}');" >> /var/www/phpldapadmin/config/config.php + append_to_servers "\$servers->setValue('server','name','${host}');" + append_to_servers "\$servers->setValue('server','host','${host}');" fi done - if [ "${PHPLDAPADMIN_LDAP_CLIENT_TLS,,}" == "true" ]; then + sed -i "/{{ PHPLDAPADMIN_SERVERS }}/d" /var/www/phpldapadmin/config/config.php - # check certificat and key or create it - /sbin/ssl-helper "/container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CRT_FILENAME}" "/container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_KEY_FILENAME}" --ca-crt=/container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CA_CRT_FILENAME} --gnutls + fi - # ldap client config - sed -i "s,TLS_CACERT.*,TLS_CACERT /container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CA_CRT_FILENAME},g" /etc/ldap/ldap.conf - echo "TLS_REQCERT $PHPLDAPADMIN_LDAP_CLIENT_TLS_REQCERT" >> /etc/ldap/ldap.conf + if [ "${PHPLDAPADMIN_LDAP_CLIENT_TLS,,}" == "true" ]; then - www_data_homedir=$( getent passwd "www-data" | cut -d: -f6 ) + # check certificat and key or create it + /sbin/ssl-helper "/container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CRT_FILENAME}" "/container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_KEY_FILENAME}" --ca-crt=/container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CA_CRT_FILENAME} --gnutls - [[ -f "$www_data_homedir/.ldaprc" ]] && rm -f $www_data_homedir/.ldaprc - touch $www_data_homedir/.ldaprc - echo "TLS_CERT /container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CRT_FILENAME}" >> $www_data_homedir/.ldaprc - echo "TLS_KEY /container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_KEY_FILENAME}" >> $www_data_homedir/.ldaprc + # ldap client config + sed -i "s,TLS_CACERT.*,TLS_CACERT /container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CA_CRT_FILENAME},g" /etc/ldap/ldap.conf + echo "TLS_REQCERT $PHPLDAPADMIN_LDAP_CLIENT_TLS_REQCERT" >> /etc/ldap/ldap.conf - chown www-data:www-data -R /container/service/phpldapadmin/assets/ldap-client/certs/ - fi + www_data_homedir=$( getent passwd "www-data" | cut -d: -f6 ) + + [[ -f "$www_data_homedir/.ldaprc" ]] && rm -f $www_data_homedir/.ldaprc + touch $www_data_homedir/.ldaprc + echo "TLS_CERT /container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_CRT_FILENAME}" >> $www_data_homedir/.ldaprc + echo "TLS_KEY /container/service/phpldapadmin/assets/ldap-client/certs/${PHPLDAPADMIN_LDAP_CLIENT_TLS_KEY_FILENAME}" >> $www_data_homedir/.ldaprc + chown www-data:www-data -R /container/service/phpldapadmin/assets/ldap-client/certs/ fi # fix file permission diff --git a/image/service/phpldapadmin/install.sh b/image/service/phpldapadmin/install.sh index 21fd8f0..1c080ca 100755 --- a/image/service/phpldapadmin/install.sh +++ b/image/service/phpldapadmin/install.sh @@ -5,9 +5,6 @@ ln -s /container/service/phpldapadmin/assets/apache2/phpldapadmin.conf /etc/apache2/sites-available/phpldapadmin.conf ln -s /container/service/phpldapadmin/assets/apache2/phpldapadmin-ssl.conf /etc/apache2/sites-available/phpldapadmin-ssl.conf -cp /container/service/phpldapadmin/assets/config.php /var/www/phpldapadmin_bootstrap/config/config.php -rm /container/service/phpldapadmin/assets/config.php - cat /container/service/phpldapadmin/assets/php5-fpm/pool.conf >> /etc/php5/fpm/pool.d/www.conf rm /container/service/phpldapadmin/assets/php5-fpm/pool.conf