-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint
142 lines (120 loc) · 6.49 KB
/
entrypoint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/sh
TZ=${TZ:-Europe/Moscow}
#mysql
MYSQL_HOST=${MYSQL_HOST:-localhost}
MYSQL_PORT=${MYSQL_PORT:-3306}
MYSQL_DATABASE=${MYSQL_DATABASE:-pdns}
MYSQL_USER=${MYSQL_USER:-pdns}
MYSQL_PASSWORD=${MYSQL_PASSWORD:-pdns}
#poweradmin
POWERADMIN_IFACE_LANG=${POWERADMIN_IFACE_LANG:-en_EN}
POWERADMIN_IFACE_STYLE=${POWERADMIN_IFACE_STYLE:-ignite}
POWERADMIN_IFACE_INDEX=${POWERADMIN_IFACE_INDEX:-cards}
POWERADMIN_HOSTMASTER=${POWERADMIN_HOSTMASTER:-}
POWERADMIN_NS1=${POWERADMIN_NS1:-}
POWERADMIN_NS2=${POWERADMIN_NS2:-}
POWERADMIN_SESSION_KEY=${POWER_ADMIN:-`pwgen 32 1`}
#pdns
PDNS_ALLOW_AXFR_IPS=${PDNS_ALLOW_AXFR_IPS:-127.0.0.1}
PDNS_LOCAL_ADDRESS=${PDNS_LOCAL_ADDRESS:-0.0.0.0, ::}
PDNS_MASTER=${PDNS_MASTER:-yes}
PDNS_SLAVE=${PDNS_SLAVE:-no}
PDNS_CACHE_TTL=${PDNS_CACHE_TTL:-20}
PDNS_DISTRIBUTOR_THREADS=${PDNS_DISTRIBUTOR_THREADS:-3}
PDNS_ALLOW_DNSUPDATE_FROM=${PDNS_ALLOW_DNSUPDATE_FROM:-127.0.0.1}
#pdns recursor
PDNS_RECURSIVE_CACHE_TTL=${PDNS_RECURSIVE_CACHE_TTL:-10}
PDNS_ALLOW_RECURSION=${PDNS_ALLOW_RECURSION:-127.0.0.1}
PDNS_RECURSOR=${PDNS_RECURSOR:-no}
#pdns webserver
PDNS_WEBSERVER_ENABLE=${PDNS_WEBSERVER_ENABLE:-no}
PDNS_WEBSERVER_IP=${PDNS_WEBSERVER_IP:-127.0.0.1}
PDNS_WEBSERVER_ALLOW_FROM=${PDNS_WEBSERVER_ALLOW_FROM:-127.0.0.1}
PDNS_WEBSERVER_PASSWORD=${PDNS_WEBSERVER_PASSWORD:-`pwgen 8 1`}
PDNS_WEBSERVER_PORT=${PDNS_WEBSERVER_PORT:-8081}
PDNS_WEBSERVER_API_ENABLE=${PDNS_WEBSERVER_API_ENABLE:-no}
PDNS_WEBSERVER_API_KEY=${PDNS_WEBSERVER_API_KEY:-`pwgen 32 1`}
cp /usr/share/zoneinfo/${TZ} /etc/localtime
LANG=${POWERADMIN_IFACE_LANG}.UTF-8
LANGUAGE=${POWERADMIN_IFACE_LANG}.UTF-8
LC_ALL=${POWERADMIN_IFACE_LANG}.UTF-8
MUSL_LOCPATH=/usr/share/i18n/locales/musl
export LANG
export LANGUAGE
export LC_ALL
export MUSL_LOCPATH
#pdns mysql
sed -i "s!MYSQL_HOST!${MYSQL_HOST}!" /etc/powerdns/conf.d/gmysql.conf
sed -i "s!MYSQL_PORT!${MYSQL_PORT}!" /etc/powerdns/conf.d/gmysql.conf
sed -i "s!MYSQL_DATABASE!${MYSQL_DATABASE}!" /etc/powerdns/conf.d/gmysql.conf
sed -i "s!MYSQL_USER!${MYSQL_USER}!" /etc/powerdns/conf.d/gmysql.conf
sed -i "s!MYSQL_PASSWORD!${MYSQL_PASSWORD}!" /etc/powerdns/conf.d/gmysql.conf
#pdns webserver
sed -i "s!PDNS_WEBSERVER_ENABLE!${PDNS_WEBSERVER_ENABLE}!" /etc/powerdns/conf.d/webserver.conf
sed -i "s!PDNS_WEBSERVER_IP!${PDNS_WEBSERVER_IP}!" /etc/powerdns/conf.d/webserver.conf
sed -i "s!PDNS_WEBSERVER_ALLOW_FROM!${PDNS_WEBSERVER_ALLOW_FROM}!" /etc/powerdns/conf.d/webserver.conf
sed -i "s!PDNS_WEBSERVER_PASSWORD!${PDNS_WEBSERVER_PASSWORD}!" /etc/powerdns/conf.d/webserver.conf
sed -i "s!PDNS_WEBSERVER_PORT!${PDNS_WEBSERVER_PORT}!" /etc/powerdns/conf.d/webserver.conf
sed -i "s!PDNS_WEBSERVER_API_ENABLE!${PDNS_WEBSERVER_API_ENABLE}!" /etc/powerdns/conf.d/webserver.conf
sed -i "s!PDNS_WEBSERVER_API_KEY!${PDNS_WEBSERVER_API_KEY}!" /etc/powerdns/conf.d/webserver.conf
#pdns
sed -i "s!PDNS_ALLOW_AXFR_IPS!${PDNS_ALLOW_AXFR_IPS}!" /etc/powerdns/conf.d/dns.conf
sed -i "s!PDNS_LOCAL_ADDRESS!${PDNS_LOCAL_ADDRESS}!" /etc/powerdns/conf.d/dns.conf
sed -i "s!PDNS_MASTER!${PDNS_MASTER}!" /etc/powerdns/conf.d/dns.conf
sed -i "s!PDNS_SLAVE!${PDNS_SLAVE}!" /etc/powerdns/conf.d/dns.conf
sed -i "s!PDNS_CACHE_TTL!${PDNS_CACHE_TTL}!" /etc/powerdns/conf.d/dns.conf
sed -i "s!PDNS_DISTRIBUTOR_THREADS!${PDNS_DISTRIBUTOR_THREADS}!" /etc/powerdns/conf.d/dns.conf
sed -i "s!PDNS_ALLOW_DNSUPDATE_FROM!${PDNS_ALLOW_DNSUPDATE_FROM}!" /etc/powerdns/conf.d/dns.conf
#poweradmin
sed -i "s!MYSQL_HOST!${MYSQL_HOST}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!MYSQL_PORT!${MYSQL_PORT}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!MYSQL_DATABASE!${MYSQL_DATABASE}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!MYSQL_USER!${MYSQL_USER}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!MYSQL_PASSWORD!${MYSQL_PASSWORD}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!POWERADMIN_SESSION_KEY!${POWERADMIN_SESSION_KEY}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!POWERADMIN_IFACE_LANG!${POWERADMIN_IFACE_LANG}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!POWERADMIN_IFACE_STYLE!${POWERADMIN_IFACE_STYLE}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!POWERADMIN_IFACE_INDEX!${POWERADMIN_IFACE_INDEX}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!POWERADMIN_HOSTMASTER!${POWERADMIN_HOSTMASTER}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!POWERADMIN_NS1!${POWERADMIN_NS1}!" /var/www/html/poweradmin/inc/config.inc.php
sed -i "s!POWERADMIN_NS2!${POWERADMIN_NS2}!" /var/www/html/poweradmin/inc/config.inc.php
#other
sed -i "s!TZ!${TZ}!" /var/www/html/poweradmin/inc/config.inc.php
until nc -z ${MYSQL_HOST} ${MYSQL_PORT}; do
echo "$(date) - waiting for a response from mysql"
sleep 1
done
if mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} "${MYSQL_DATABASE}" >/dev/null 2>&1 </dev/null
then
echo "Database ${MYSQL_DATABASE} already exists"
else
mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} -e "CREATE DATABASE ${MYSQL_DATABASE}"
mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < /sql/pdns_schema.sql
mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < /sql/poweradmin.sql
fi
echo "check powerdns database table"
CHECK_TABLE=`mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} -e "CHECK TABLE domains;" | grep "doesn't exist" | awk {'print $3'}`
if [ "${CHECK_TABLE}" == "Error" ]; then
echo "update tables powerdns schema"
mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < /sql/pdns_schema.sql
fi
echo "check poweradmin database table"
CHECK_TABLE=`mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} -e "CHECK TABLE users;" | grep "doesn't exist" | awk {'print $3'}`
if [ "${CHECK_TABLE}" == "Error" ]; then
echo "update tables poweradmin schema"
mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < /sql/poweradmin.sql
fi
#mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < /sql/cascade.sql
#rm -rf /sql
#
# bcrypt 12 (admin/admin)
#
# INSERT INTO users ( id, username, `password`, fullname, email, description, perm_templ, active, use_ldap )
# VALUES ( 1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'Administrator', '[email protected]', 'Administrator with full rights.', 1, 1, 0 );
# INSERT INTO perm_templ ( id, name, descr ) VALUES ( 1, 'Administrator', 'Administrator template with full rights.' );
#
echo "*****"
echo "POWERDNS WEBSERVER PASSWORD = "${PDNS_WEBSERVER_PASSWORD}
echo "POWERDNS WEBSERVER API KEY = "${PDNS_WEBSERVER_API_KEY}
echo "*****"
exec "$@"