OpenWrt Forum Archive

Topic: DDNS for NameSilo

The content of this topic has been archived on 28 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello....

I'm trying to setup DDNS for NameSilo to update DNS records for my domains and subdomains.  I used "github.com/pztop/namesilo_ddns" as a guide to create a little script to make it run at startup, but I seem to stuck on extracting the record_id from the the xml file as there's no xmllint command in OpenWrt's libxml2 package.

So instead of using the xmllint to extract the record_id's (bb74e10cc00faa6b9e99b2cd108e1184 and a1cd001a0d9906f48cce82755e1dbcba) from the xml file, is there any other command I can use to extract the record_id's from the mydomain.xml file into place holders for use in the next operation to update the DNS records with NameSilo?  Thanks in advance for any assistance.

<?xml version="1.0"?>
<namesilo><request><operation>dnsListRecords</operation><ip>176.103.133.13</ip></request><reply><code>300</code><detail>success</detail><resource_record><record_id>bb74e10cc00faa6b9e99b2cd108e1184</record_id><type>A</type><host>subdomain</host><value>176.103.133.13</value><ttl>3600</ttl><distance>0</distance></resource_record><resource_record><record_id>a1cd001a0d9906f48cce82755e1dbcba</record_id><type>CNAME</type><host>mydomain</host><value>namesilo</value><ttl>3603</ttl><distance>0</distance></resource_record></reply></namesilo>

Google for "Bash XML extract". You will find a lot of ideas that could help you.
i.e. grep -oP "(?<=<record_id>)[^<]+" test.xml
Later on, you need to check if the version of "grep", "sed" or "awk" installed on LEDE/OpenWrt support all options.

here's an old code I wrote, hope it helps

I had to obfuscate all the URLs because of the silly spammers.
I trust you can restore them.

#!/bin/bash

IP=$(ifstatus wan | jsonfilter -e '@["ipv4-address"][0].address')

#update an A record hosted by namesilo.com to point to my public IP
REC=${1:-${HOSTNAME}.ddns}
DOMAIN=example.com
TTL=3600

KEY=jhnfsjkaohj123u24001
ttps\\zzz.namesilo.com\account_api.php


ZONE=$(curl --silent --connect-timeout 3 --insecure "ttps\\zzz.namesilo.com\api\dnsListRecords?version=1&type=xml&key=${KEY}&domain=${DOMAIN}")
IP=$(echo "$ZONE" | sed -n -e 's/.*<ip>\([0-9\.]*\)<\/ip>.*/\1/p')
RECID=$(echo "$ZONE" | sed -n -e "s/.*<record_id>\([0-9a-z]*\)<\/record_id><type>A<\/type><host>${REC}.${DOMAIN}<\/host>.*/\1/p")

[ -n "$IP" ] && [ -n "$RECID" ] &&
echo "I:$0: ${REC}.${DOMAIN}    $TTL    IN      A       $IP" >&2 &&
curl --silent --insecure "ttps\\zzz.namesilo.com\api\dnsUpdateRecord?version=1&type=xml&key=${KEY}&domain=${DOMAIN}&rrid=${RECID}&rrhost=${REC}&rrvalue=${IP}&rrttl=${TTL}"

The discussion might have continued from here.