Auto-sign autodiscover and autoconfig for all domains found in mailcow - only if A records exists and matches
parent
655aa9594e
commit
0fd0cff8ac
|
@ -7,7 +7,8 @@ RUN apk add --update --no-cache \
|
||||||
acme-client \
|
acme-client \
|
||||||
curl \
|
curl \
|
||||||
openssl \
|
openssl \
|
||||||
bind-tools
|
bind-tools \
|
||||||
|
mariadb-client
|
||||||
|
|
||||||
COPY docker-entrypoint.sh /srv/docker-entrypoint.sh
|
COPY docker-entrypoint.sh /srv/docker-entrypoint.sh
|
||||||
|
|
||||||
|
|
|
@ -13,28 +13,50 @@ restart_containers(){
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|
||||||
AUTODISCOVER=
|
# Autodiscover and Autoconfig (Thunderbird)
|
||||||
AUTODISCOVER_A=$(dig a autodiscover.${MAILCOW_HOSTNAME#*} +short @208.67.220.222)
|
declare -a SQL_DOMAIN_ARR
|
||||||
if [[ ! -z ${AUTODISCOVER_A} ]]; then
|
declare -a DOMAIN_ARR
|
||||||
if [[ $(curl -4s https://mailcow.email/ip.php) == ${AUTODISCOVER_A} ]]; then
|
declare -a DOMAIN_ARR
|
||||||
AUTODISCOVER="autodiscover.${MAILCOW_HOSTNAME#*}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
AUTOCONFIG=
|
while read line; do
|
||||||
AUTOCONFIG_A=$(dig a autoconfig.${MAILCOW_HOSTNAME#*} +short @208.67.220.222)
|
SQL_DOMAIN_ARR+=("${line}")
|
||||||
if [[ ! -z ${AUTOCONFIG_A} ]]; then
|
done < <(mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT domain FROM domain" -Bs)
|
||||||
if [[ $(curl -4s https://mailcow.email/ip.php) == ${AUTOCONFIG_A} ]]; then
|
|
||||||
AUTOCONFIG="autoconfig.${MAILCOW_HOSTNAME#*}"
|
for SQL_DOMAIN in "${SQL_DOMAIN_ARR[@]}"; do
|
||||||
|
IPV4=$(curl -4s https://mailcow.email/ip.php)
|
||||||
|
A_CONFIG=$(dig A autoconfig.${SQL_DOMAIN} +short @208.67.220.222)
|
||||||
|
if [[ ! -z ${A_CONFIG} ]]; then
|
||||||
|
echo "Found A record for autoconfig.${SQL_DOMAIN}: ${A_CONFIG}"
|
||||||
|
if [[ ${IPV4} == ${A_CONFIG} ]]; then
|
||||||
|
echo "Confirmed A record autoconfig.${SQL_DOMAIN}"
|
||||||
|
CONFIG_DOMAINS+=("autoconfig.${SQL_DOMAIN}")
|
||||||
|
else
|
||||||
|
echo "Cannot match Your IP against hostname autoconfig.${SQL_DOMAIN}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "No A record for autoconfig.${SQL_DOMAIN} found"
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
A_DISCOVER=$(dig A autodiscover.${SQL_DOMAIN} +short @208.67.220.222)
|
||||||
|
if [[ ! -z ${A_DISCOVER} ]]; then
|
||||||
|
echo "Found A record for autodiscover.${SQL_DOMAIN}: ${A_CONFIG}"
|
||||||
|
if [[ ${IPV4} == ${A_DISCOVER} ]]; then
|
||||||
|
echo "Confirmed A record autodiscover.${SQL_DOMAIN}"
|
||||||
|
CONFIG_DOMAINS+=("autodiscover.${SQL_DOMAIN}")
|
||||||
|
else
|
||||||
|
echo "Cannot match Your IP against hostname autodiscover.${SQL_DOMAIN}"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "No A record for autodiscover.${SQL_DOMAIN} found"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
acme-client \
|
acme-client \
|
||||||
-v -b -N -n \
|
-v -e -b -N -n \
|
||||||
-f ${ACME_BASE}/acme/private/account.key \
|
-f ${ACME_BASE}/acme/private/account.key \
|
||||||
-k ${ACME_BASE}/acme/private/privkey.pem \
|
-k ${ACME_BASE}/acme/private/privkey.pem \
|
||||||
-c ${ACME_BASE}/acme \
|
-c ${ACME_BASE}/acme \
|
||||||
${MAILCOW_HOSTNAME} ${AUTOCONFIG} ${AUTODISCOVER} ${ADDITIONAL_SAN}
|
${MAILCOW_HOSTNAME} ${CONFIG_DOMAINS[*]} ${ADDITIONAL_SAN}
|
||||||
|
|
||||||
case "$?" in
|
case "$?" in
|
||||||
0) # new certs
|
0) # new certs
|
||||||
|
|
Loading…
Reference in New Issue