Added IPv6 suppport and config files

This commit is contained in:
Christian Busch 2014-02-22 09:44:38 +01:00
parent 8fc04ac46b
commit da10330885
3 changed files with 89 additions and 59 deletions

View File

@ -1,16 +1,21 @@
# Nameserver update for inwx (nsupdate) # 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 ## 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_ - 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 - Renamed _$HOSTNAME_ to _$DOMAIN_ to work around potential conflicts with _$HOSTNAME_ that's set by the host itself

View File

@ -1,10 +1,11 @@
# nsupdate.config # nsupdate.config
# from which site should we get your wan ip? # 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 instead of nslookup for hostname lookup
USE_DRILL="NO" USE_DRILL="YES"
IPV6="NO"
# Login credentials for the inwx admin interface # Login credentials for the inwx admin interface
INWX_USER="USERNAME" 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 # 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. # 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" INWX_DOMAIN_ID="123456789"

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/local/bin/bash
# Update a nameserver entry at inwx with the current WAN IP (DynDNS) # Update a nameserver entry at inwx with the current WAN IP (DynDNS)
@ -24,20 +24,35 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
source $(dirname $0)/nsupdate.config
LOG=$0.log LOG=$0.log
if [[ "$USE_DRILL" == "YES" ]]; then # Loop through configs
NSLOOKUP=$(drill $DOMAIN @ns.inwx.de | head -7 | tail -1 | awk '{print $5}') for f in $(dirname $0)/nsupdate.d/*.config
else do
NSLOOKUP=$(nslookup -sil $DOMAIN - ns.inwx.de | tail -2 | head -1 | cut -d' ' -f2) echo "Starting nameserver update with config file $f"
fi ## 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="<?xml version=\"1.0\"?> ## Set record type to IPv6
<methodCall> if [[ "$IPV6" == "YES" ]]; then
TYPE=AAAA
CONNECTION_TYPE=6
fi
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="<?xml version=\"1.0\"?>
<methodCall>
<methodName>nameserver.updateRecord</methodName> <methodName>nameserver.updateRecord</methodName>
<params> <params>
<param> <param>
@ -71,11 +86,20 @@ API_XML="<?xml version=\"1.0\"?>
</value> </value>
</param> </param>
</params> </params>
</methodCall>" </methodCall>"
if [ ! "$NSLOOKUP" == "$WAN_IP" ]; then if [ ! "$NSLOOKUP" == "$WAN_IP" ]; then
curl -silent -v -XPOST -H"Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/ 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 echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG
else else
echo "$(date) - No update needed for $DOMAIN. Current IP: "$NSLOOKUP >> $LOG echo "$(date) - No update needed for $DOMAIN. Current IP: "$NSLOOKUP >> $LOG
fi fi
unset DOMAIN
unset IPV6
unset WAN_IP
unset NSLOOKUP
unset INWX_PASS
unset INWX_USER
unset INWX_DOMAIN_ID
done