Added IPv6 suppport and config files
This commit is contained in:
parent
8fc04ac46b
commit
da10330885
15
README.md
15
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
|
||||
|
||||
|
7
nsupdate.config.sample → nsupdate.d/sample.config.dist
Normal file → Executable file
7
nsupdate.config.sample → nsupdate.d/sample.config.dist
Normal file → Executable file
@ -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"
|
126
nsupdate.sh
126
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="<?xml version=\"1.0\"?>
|
||||
<methodCall>
|
||||
<methodName>nameserver.updateRecord</methodName>
|
||||
<params>
|
||||
<param>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>user</name>
|
||||
<value>
|
||||
<string>$INWX_USER</string>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>pass</name>
|
||||
<value>
|
||||
<string>$INWX_PASS</string>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>id</name>
|
||||
<value>
|
||||
<int>$INWX_DOMAIN_ID</int>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>content</name>
|
||||
<value>
|
||||
<string>$WAN_IP</string>
|
||||
</value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodCall>"
|
||||
## 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
|
||||
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>
|
||||
<params>
|
||||
<param>
|
||||
<value>
|
||||
<struct>
|
||||
<member>
|
||||
<name>user</name>
|
||||
<value>
|
||||
<string>$INWX_USER</string>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>pass</name>
|
||||
<value>
|
||||
<string>$INWX_PASS</string>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>id</name>
|
||||
<value>
|
||||
<int>$INWX_DOMAIN_ID</int>
|
||||
</value>
|
||||
</member>
|
||||
<member>
|
||||
<name>content</name>
|
||||
<value>
|
||||
<string>$WAN_IP</string>
|
||||
</value>
|
||||
</member>
|
||||
</struct>
|
||||
</value>
|
||||
</param>
|
||||
</params>
|
||||
</methodCall>"
|
||||
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user