otcerts/letsencrypt/lets_authenticator.sh
2020-02-23 19:59:56 +01:00

42 sor
1,4 KiB
Bash
Executable file

LOG_FILE='/tmp/lets_auth.log'
DNS_DB_MYCNF="/usr/local/ortiche/otcerts/etc/dns_db.conf"
echo "Auth $CERTBOT_DOMAIN"
echo "" >> $LOG_FILE
date >> $LOG_FILE
RECORD_NAME='_acme-challenge'
RECORD_FQDN="$RECORD_NAME.$CERTBOT_DOMAIN"
DOMAIN_ID=`mysql --defaults-extra-file=$DNS_DB_MYCNF -s -N << END_QUERY
SELECT domains.id FROM domains WHERE domains.name='$CERTBOT_DOMAIN'
END_QUERY`
if [ -z "$DOMAIN_ID" ]; then
echo "ERROR: Nameservers are not managed for domain $CERTBOT_DOMAIN" >> $LOG_FILE
exit 255
fi
echo "Selected domain_id $DOMAIN_ID" >> $LOG_FILE
echo "Creating $RECORD_FQDN TXT entry with value $CERTBOT_VALIDATION" >> $LOG_FILE
QUERY_RES=`mysql --defaults-extra-file=$DNS_DB_MYCNF -s -N << END_QUERY
INSERT INTO records (domain_id, name, type, content, ttl, prio, label)
VALUES ($DOMAIN_ID, '$RECORD_FQDN', 'TXT', '"$CERTBOT_VALIDATION"', 5, 60, '"$CERTBOT_VALIDATION"')
END_QUERY`
# echo "Done updating" >> $LOG_FILE
RECORD_ID=`mysql --defaults-extra-file=$DNS_DB_MYCNF -s -N << END_QUERY
SELECT id FROM records WHERE (type='TXT' and name='$RECORD_FQDN')
END_QUERY`
echo "After update $RECORD_ID ." >> $LOG_FILE
echo "Done updating, sleeping 10 secs .. " >> $LOG_FILE
sleep 5
echo "Done sleeping." >> $LOG_FILE
# dig @172.19.0.102 $RECORD_FQDN TXT +short >> $LOG_FILE
# dig @dns.contaminati.net $RECORD_FQDN TXT +short >> $LOG_FILE
# dig @dns.ortiche.net $RECORD_FQDN TXT +short >> $LOG_FILE
exit 0