diff --git a/README.md b/README.md index a388e91..d00aaaa 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,21 @@ # Nameserver update for inwx (nsupdate) -Update a nameserver entry at inwx with the current WAN IP (DynDNS) +Update nameserver entrys at inwx with the current WAN IP (DynDNS) -nsbackup is a bash script that uses curl and the inwx API to update a given nameserver entry with the current WAN IP. +nsbackup is a bash script that uses curl and the inwx API to update nameserver entrys at inwx with the current WAN IP. It supports IPv4 and IPv6. -You have to configurue it in the file nsupdate.config. +Place your config files in the _nsupdate.d_ folder. ## Changelog -**2014-01-2-02** +**2014-02-21** -- Changed default IP check site to ifconfig.me +- Added support for IPv6 +- Added support for config files + +**2014-01-02** + +- Changed default IP check site to ip.dblx.io - Added a switch to use _drill_ instead of _nslookup_ because FreeBSD 10 switched from _bind_ to _unbound_ - Renamed _$HOSTNAME_ to _$DOMAIN_ to work around potential conflicts with _$HOSTNAME_ that's set by the host itself diff --git a/nsupdate.config.sample b/nsupdate.d/sample.config.dist old mode 100644 new mode 100755 similarity index 82% rename from nsupdate.config.sample rename to nsupdate.d/sample.config.dist index e626028..6861db9 --- a/nsupdate.config.sample +++ b/nsupdate.d/sample.config.dist @@ -1,10 +1,11 @@ # nsupdate.config # from which site should we get your wan ip? -IP_CHECK_SITE="http://ifconfig.me/ip" +IP_CHECK_SITE="http://ip.dblx.io" # use drill instead of nslookup for hostname lookup -USE_DRILL="NO" +USE_DRILL="YES" +IPV6="NO" # Login credentials for the inwx admin interface INWX_USER="USERNAME" @@ -12,5 +13,5 @@ INWX_PASS="PASSWORD" # The hostname that you want to update and it's ID from the inwx interface # You get the ID when you edit the given nameserver entry and hover the save button. -DOMAIN="subdomain.example.com" +DOMAIN="DOMAIN" INWX_DOMAIN_ID="123456789" \ No newline at end of file diff --git a/nsupdate.sh b/nsupdate.sh index 24de756..f9f9e3b 100755 --- a/nsupdate.sh +++ b/nsupdate.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/local/bin/bash # Update a nameserver entry at inwx with the current WAN IP (DynDNS) @@ -24,58 +24,82 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -source $(dirname $0)/nsupdate.config - LOG=$0.log -if [[ "$USE_DRILL" == "YES" ]]; then - NSLOOKUP=$(drill $DOMAIN @ns.inwx.de | head -7 | tail -1 | awk '{print $5}') -else - NSLOOKUP=$(nslookup -sil $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f2) -fi +# Loop through configs +for f in $(dirname $0)/nsupdate.d/*.config +do + echo "Starting nameserver update with config file $f" + ## Set record type to IPv4 + TYPE=A + CONNECTION_TYPE=4 -WAN_IP=`curl -s ${IP_CHECK_SITE}| grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'` + source $f -API_XML=" - - nameserver.updateRecord - - - - - - user - - $INWX_USER - - - - pass - - $INWX_PASS - - - - id - - $INWX_DOMAIN_ID - - - - content - - $WAN_IP - - - - - - -" + ## Set record type to IPv6 + if [[ "$IPV6" == "YES" ]]; then + TYPE=AAAA + CONNECTION_TYPE=6 + fi -if [ ! "$NSLOOKUP" == "$WAN_IP" ]; then - curl -silent -v -XPOST -H"Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/ - echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG -else - echo "$(date) - No update needed for $DOMAIN. Current IP: "$NSLOOKUP >> $LOG -fi \ No newline at end of file + if [[ "$USE_DRILL" == "YES" ]]; then + NSLOOKUP=$(drill $DOMAIN @ns.inwx.de $TYPE | head -7 | tail -1 | awk '{print $5}') + else + NSLOOKUP=$(nslookup -sil -type=$TYPE $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f2) + fi + + # WAN_IP=`curl -s -$CONNECTION_TYPE ${IP_CHECK_SITE}| grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'` + WAN_IP=`curl -s -$CONNECTION_TYPE ${IP_CHECK_SITE}` + + API_XML=" + + nameserver.updateRecord + + + + + + user + + $INWX_USER + + + + pass + + $INWX_PASS + + + + id + + $INWX_DOMAIN_ID + + + + content + + $WAN_IP + + + + + + + " + + if [ ! "$NSLOOKUP" == "$WAN_IP" ]; then + curl -silent -v -XPOST -H"Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/ + echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG + else + echo "$(date) - No update needed for $DOMAIN. Current IP: "$NSLOOKUP >> $LOG + fi + + unset DOMAIN + unset IPV6 + unset WAN_IP + unset NSLOOKUP + unset INWX_PASS + unset INWX_USER + unset INWX_DOMAIN_ID +done \ No newline at end of file