Browse Source

Added dns_add_pdns-mysql and dns_del_pdns-mysql, to support dns updates using a local powerdns + mysql/mariadb setup

pull/61/head
Tod Huff 10 years ago
parent
commit
cef0b24787
2 changed files with 52 additions and 0 deletions
  1. +34
    -0
      dns_scripts/dns_add_pdns-mysql
  2. +18
    -0
      dns_scripts/dns_del_pdns-mysql

+ 34
- 0
dns_scripts/dns_add_pdns-mysql View File

@ -0,0 +1,34 @@
#!/bin/bash
# You must either have a suitable ~/.my.cnf containing a user / pass
# for your mysql / mariadb database, OR you must uncomment the next line
# (which is a security risk; don't do it!) and adjust accordingly.
#CREDENTIALS="-uUSERNAME -pPASSWORD"
FQDN=$1
TOKEN=$2
# If your database name is not powerdns, change it here.
DB="powerdns"
DOMAIN=${FQDN}
# Iterate over the database, checking for a match. Keep stripping
# subdomains off 1 by 1 until we find one, or exit with an error.
while [ -z ${DOMAIN_ID} ]; do
DOMAIN_ID=`mysql -ss ${CREDENTIALS} -e "SELECT id FROM ${DB}.domains WHERE name='${DOMAIN}'"`
if [ -z ${DOMAIN_ID} ]; then
DOMAIN=`echo ${DOMAIN}|cut -d. -f1 --complement`
fi
if [[ ${DOMAIN} != *"."* ]]; then
echo "Cannot find matching domain record! ABORT!"
exit 1
fi
done
echo "Domain ID: ${DOMAIN_ID} | FQDN: ${FQDN} | Domain: ${DOMAIN}"
mysql -ss ${CREDENTIALS} -e "INSERT INTO ${DB}.records \
(domain_id, name, content, type,ttl,prio) VALUES \
(${DOMAIN_ID},'_acme-challenge.${FQDN}','${TOKEN}','TXT',120,NULL);"

+ 18
- 0
dns_scripts/dns_del_pdns-mysql View File

@ -0,0 +1,18 @@
#!/bin/bash
# You must either have a suitable ~/.my.cnf containing a user / pass
# for your mysql / mariadb database, OR you must uncomment the next line
# (which is a security risk; don't do it!) and adjust accordingly.
#CREDENTIALS="-uUSERNAME -pPASSWORD"
FQDN=$1
TOKEN=$2
# If your database name is not powerdns, change it here.
DB="powerdns"
mysql -ss ${CREDENTIALS} -e "DELETE FROM ${DB}.records WHERE \
name = '${FQDN}' AND content = '${TOKEN}';"
echo "DELETE FROM ${DB}.records WHERE name = '${FQDN}' AND content = '${TOKEN}';"

Loading…
Cancel
Save