Is there a programmatic way to update DNS TXT record?
Posted: Fri Nov 08, 2019 7:05 pm
For letsencrypt wildcard certs for HTTPS, one step is to update the TXT record. Can I do it programmatically?
Sonic.net Forums
https://forums.sonic.net/
Code: Select all
# log in
curl -Lv -c cookies.txt -d login=login -d user=your_username -d 'pw=your password' https://members.sonic.net/
# update DNS
curl -Lv -b cookies.txt -c cookies.txt -d a=UpdateDNS -d dom_id=yourdomain.net -d update_id=your_record_id -d recordName= -d recordTTL=900 -d 'recordContent="your txt record content"' https://members.sonic.net/websites/nameservers/host_records/
Code: Select all
# log in
curl -Lv -c cookies.txt -d login=login -d user=your_username -d 'pw=your password' https://members.sonic.net/ > /tmp/sonic.txt
grep 'You are logged in as' /tmp/sonic.txt
if [ $? != 0 ] ; then
echo "Failed to log in!"
exit 1
fi
# add similar check for the record update here :)
Code: Select all
#!/bin/zsh
#
# Update the _acme-challenge TXT record
#
content=$1
[b]user=XXXX
pw=YYY
dom_id=ZZZ.com
update_id=nnnnnnnnnn
[/b]ttl=100
# log in
welcomed=`curl -L -c cookies.txt -d login=login -d user=$user -d pw=$pw https://members.sonic.net/ 2>/dev/null|grep "Welcome to the Sonic Member Tools"`
#
if [[ -z "${welcomed// }" ]]
then
echo "We have a login problem"
else
updated=`curl -L -b cookies.txt -c cookies.txt -d a=UpdateDNS -d dom_id=$dom_id -d update_id=$update_id -d recordName=_acme-challenge -d recordTTL=$ttl -d recordContent=\"$content\" https://members.sonic.net/websites/nameservers/host_records/ 2>/dev/null|grep ${content}`
if [[ -z "${updated// }" ]]
then
echo "We have a update problem"
else
echo "updated _acme-challenge!"
fi
fi
rm cookies.txt