Skip to content

Commit abd0b29

Browse files
committed
config
1 parent 5191ccf commit abd0b29

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

image/service/phpldapadmin/container-start.sh

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,88 @@ if [ ! -e "$FIRST_START_DONE" ]; then
2222
a2ensite phpldapadmin
2323
fi
2424

25-
get_salt () {
25+
get_salt() {
2626
salt=$(</dev/urandom tr -dc '1324567890#<>,()*.^@$% =-_~;:|{}[]+!`azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN' | head -c64 | tr -d '\\')
2727
}
2828

2929
# phpLDAPadmin cookie secret
3030
get_salt
3131
sed -i "s/blowfish'] = '/blowfish'] = '${salt}/g" /osixia/phpldapadmin/config.php
3232

33+
print_by_php_type() {
34+
35+
if [ "$1" == "True" ]; then
36+
echo "true"
37+
elif [ "$1" == "False" ]; then
38+
echo "false"
39+
elif [[ "$1" == array\(\'* ]]; then
40+
echo "$1"
41+
else
42+
echo "'$1'"
43+
fi
44+
}
45+
46+
# phpLDAPadmin servers config
47+
host_infos() {
48+
49+
local to_print=$1
50+
local infos=(${!2})
51+
52+
for info in "${infos[@]}"
53+
do
54+
host_infos_value "$to_print" "$info"
55+
done
56+
}
57+
58+
host_infos_value(){
59+
60+
local to_print=$1
61+
local info_key_value=(${!2})
62+
63+
local key=${!info_key_value[0]}
64+
local value=(${!info_key_value[1]})
65+
66+
local value_of_value_table=(${!value})
67+
68+
# it's a table of values
69+
if [ "${#value[@]}" -gt "1" ]; then
70+
host_infos "$to_print'$key'," "${info_key_value[1]}"
71+
72+
# the value of value is a table
73+
elif [ "${#value_of_value_table[@]}" -gt "1" ]; then
74+
host_infos_value "$to_print'$key'," "$value"
75+
76+
# it's just a not empty value
77+
elif [ -n "$value" ]; then
78+
local php_value=$(print_by_php_type $value)
79+
echo "\$servers->setValue($to_print'$key',$php_value);" >> /osixia/phpldapadmin/config.php
80+
fi
81+
}
82+
83+
# phpLDAPadmin config
84+
LDAP_HOSTS=($LDAP_HOSTS)
85+
for host in "${LDAP_HOSTS[@]}"
86+
do
87+
88+
#host var contain a variable name, we access to the variable value and cast it to a table
89+
infos=(${!host})
90+
91+
echo "\$servers->newServer('ldap_pla');" >> /osixia/phpldapadmin/config.php
92+
93+
# it's a table of infos
94+
if [ "${#infos[@]}" -gt "1" ]; then
95+
echo "\$servers->setValue('server','name','${!infos[0]}');" >> /osixia/phpldapadmin/config.php
96+
echo "\$servers->setValue('server','host','${!infos[0]}');" >> /osixia/phpldapadmin/config.php
97+
host_infos "" ${infos[1]}
98+
99+
# it's just a host name
100+
else
101+
echo "\$servers->setValue('server','name','${!host}');" >> /osixia/phpldapadmin/config.php
102+
echo "\$servers->setValue('server','host','${!host}');" >> /osixia/phpldapadmin/config.php
103+
fi
104+
done
105+
106+
33107
# Fix file permission
34108
find /var/www/ -type d -exec chmod 755 {} \;
35109
find /var/www/ -type f -exec chmod 644 {} \;

0 commit comments

Comments
 (0)