diff --git a/README.md b/README.md
index db9ca37..a72fe19 100644
--- a/README.md
+++ b/README.md
@@ -17,17 +17,41 @@ In order to run the script you need to have installed the following command line
- _awk_
- _nslookup_ or _drill_
+recommendation
+
+- _xmllint_ (libxml2-utils)
+If _xmllint_ is not on your system you have to set the domain record id in your config files.
+
+Note: 2-Factor-Authentification method (2FA) is not implemented.
+
## Installation
Simply clone this project or download the `master.zip` and extract it, e.g., using `wget` and `7z x master.zip`.
-Place your config files in the `nsupdate.d` folder. A `dist.config.sample` is provided. At least one config file needs to exist, ending with `.config.
+Place your config files in the `nsupdate.d` folder. A `dist.config.sample` file with all possible options is provided. At least one config file needs to exist, ending with `.config.
All .config files (one for each dns-record) will be processed by looping them.
-Simply copy the provided dist.config.sample and adjust your config to your needs.
-For home.example.com you may create:
-home.example.com-ipv4.config and/or
-home.example.com-ipv6.config
+For home.example.com you may create:
+A-Record Update configuration e.g.
+`myV4.config`
+```
+INWX_USER="USERNAME"
+INWX_PASS="PASSWORD"
+MAIN_DOMAIN="example.de"
+DOMAIN="home.example.de"
+TYPE="A"
+IP_CHECK_SITE="https://api.ipify.org"
+```
+AAAA-Record Update configuration e.g.
+`myV6.config`
+```
+INWX_USER="USERNAME"
+INWX_PASS="PASSWORD"
+MAIN_DOMAIN="example.de"
+DOMAIN="home.example.de"
+TYPE="AAAA"
+IP_CHECK_SITE="https://api6.ipify.org"
+```
## Run nsupdate by cron
With `crontab -e` you can add the following line for running the script every 5 minutes:
@@ -35,6 +59,12 @@ With `crontab -e` you can add the following line for running the script every 5
## Changelog
+**2020-07-03**
+
+ - Rearranged config.sample
+ - Updated Readme
+ - Getting the Domain-Record-ID via XML-RPC API
+
**2020-05-11**
- Updated Readme with some hints
diff --git a/nsupdate.d/dist.config.sample b/nsupdate.d/dist.config.sample
index cde0fe3..aad54e9 100755
--- a/nsupdate.d/dist.config.sample
+++ b/nsupdate.d/dist.config.sample
@@ -2,37 +2,52 @@
# The nsupdate.sh is processing all .config files by looping.
# If you want to update an IPv4 and an IPv6 record you need two config files.
-# Log file name.
-LOG="$0.log"
+# Login credentials for the inwx admin interface
+INWX_USER="USERNAME"
+INWX_PASS="PASSWORD"
+
+# The domain that you want to update AND its main/zone domain
+# The MAIN_DOMAIN is needed for the API-Request to get the record ID
+MAIN_DOMAIN="example.com"
+DOMAIN="home.example.com"
+# If it is the same domain:
+#DOMAIN="example.com"
+
+# Set the record type to either A, AAAA or MX
+# For MX you would normaly just set a domain and not an ip, so this is just a option.
+TYPE="A"
# From which site should we get your WAN IP?
# Note that for IPv4 or IPv6 the IP_CHECK_SITE should work
# e.g. for IPv4 use api.ipify.org and for IPv6 use api6.ipify.org
IP_CHECK_SITE="https://api.ipify.org/"
-# Use drill instead of nslookup for hostname lookup.
-USE_DRILL="NO"
-
-# Use IPv6 connection.
-IPV6="NO"
-
-# Update an MX record.
-MX="NO"
-
-# Suppress all messages and deactivates logging.
-SILENT="NO"
-
# TTL: Time to Live
# default TTL setting by inwx is 3600 (1 hour)
# minimum TTL allowed by inwx is 300 (5 minutes) for regular nameserver record updates
-TTL=300
+# In this script the defaul setting is 300.
+#TTL=300
-# Login credentials for the inwx admin interface
-INWX_USER="USERNAME"
-INWX_PASS="PASSWORD"
+# Log file name.
+LOG="$0.log"
-# The hostname that you want to update and it's ID from the inwx interface.
+# Suppress all messages and deactivates logging.
+# default is SILENT="NO"
+#SILENT="YES"
+
+# Use drill instead of nslookup for hostname lookup.
+#USE_DRILL="YES"
+
+# The domain-Record-ID from the inwx interface.
+# If the command-line-tool "xmllint" is working you dont need to set this option.
# Note: You can get the specific domain record ID while editing the given nameserver entry by
# inspecting the target URL of the save button.
-DOMAIN="DOMAIN"
-INWX_DOMAIN_ID="123456789"
+#INWX_DOMAIN_ID="123456789"
+
+# Use IPv6 connection.
+# deprecated option for backward compatibility, use TYPE instead
+#IPV6="NO"
+
+# Update an MX record.
+# deprecated option for backward compatibility, use TYPE instead
+#MX="NO"
diff --git a/nsupdate.sh b/nsupdate.sh
index 745db13..a9a39f4 100755
--- a/nsupdate.sh
+++ b/nsupdate.sh
@@ -28,6 +28,7 @@
command -v curl &> /dev/null || { echo >&2 "I require curl but it's not installed. Note: all needed items are listed in the README.md file."; exit 1; }
command -v awk &> /dev/null || { echo >&2 "I require awk but it's not installed. Note: all needed items are listed in the README.md file."; exit 1; }
command -v drill &> /dev/null || command -v nslookup &> /dev/null || { echo >&2 "I need drill or nslookup installed. Note: all needed items are listed in the README.md file."; exit 1; }
+command -v xmllint &> /dev/null || { echo >&2 "I recommend xmllint but it's not installed. Note: all needed items are listed in the README.md file."; NO_XMLLINT="true";}
LOG=$0.log
SILENT=NO
@@ -37,15 +38,30 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
# Loop through configs
for f in $(dirname $0)/nsupdate.d/*.config
do
+ # Config files could be much cleaner by containing only relevant settings.
+ # If your User and Password is always the same just set it here once and delete it in the config files.
+ #INWX_USER="Username"
+ #INWX_PASS="Password"
+ # Resets previous set variables to catch wrong or not configured settings and set defaults.
+ MAIN_DOMAIN=
+ DOMAIN=
+ INWX_DOMAIN_ID="unset"
+ TTL=300
+ TYPE=A
+ CONNECTION_TYPE=4
+ # For backward compatability the following options remain in this script
+ IPV6="NO"
+ MX="NO"
+
source $f
if [[ "$SILENT" == "NO" ]]; then
echo "Starting nameserver update with config file $f ($LOG)"
fi
- ## Set record type to IPv4
- TYPE=A
- CONNECTION_TYPE=4
+ if [[ "$TYPE" == "A" ]]; then
+ CONNECTION_TYPE=4
+ fi
## Set record type to MX
if [[ "$MX" == "YES" ]]; then
@@ -55,6 +71,9 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
## Set record type to IPv6
if [[ "$IPV6" == "YES" ]]; then
TYPE=AAAA
+ fi
+
+ if [[ "$TYPE" == "AAAA" ]]; then
CONNECTION_TYPE=6
fi
@@ -77,8 +96,75 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
# 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})
+ # This is relevant for getting the specific domain record id.
+ API_XML_INFO="
+
+ nameserver.info
+
+
+
+
+
+ user
+
+ $INWX_USER
+
+
+
+ lang
+
+ en
+
+
+
+ pass
+
+ $INWX_PASS
+
+
+
+ domain
+
+ $MAIN_DOMAIN
+
+
+
+ name
+
+ $DOMAIN
+
+
+
+ type
+
+ $TYPE
+
+
+
+
+
+
+ "
- API_XML="
+ # The full xpath is
+ # XPATH='string(/methodResponse/params/param/value/struct/member[name="resData"]/value/struct/member[name="record"]/value/array/data/value/struct/member[name="id"]/value/int)'
+ # A short version of the xpath
+ XPATH='string(//member[name="id"]/value/int/text())'
+ if [[ "$NO_XMLLINT" != "true" ]]; then
+ if [[ "$NSLOOKUP" != "$WAN_IP" ]]; then
+ if [[ "$INWX_DOMAIN_ID" == "unset" ]]; then
+ INWX_DOMAIN_ID=$(curl -s -X POST https://api.domrobot.com/xmlrpc/ \
+ -H "Content-Type: application/xml" \
+ -d "$API_XML_INFO" \
+ | xmllint --xpath $XPATH -)
+ if [[ "$SILENT" == "NO" ]]; then
+ echo $(printf "%s - The %s-Type Record-ID of %s is: %s" "$(date)" "$TYPE" "$DOMAIN" "$INWX_DOMAIN_ID")>>$LOG
+ fi
+ fi
+ fi
+ fi
+
+ API_XML_UPDATE_RECORD="
nameserver.updateRecord
@@ -128,7 +214,10 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
"
if [[ "$NSLOOKUP" != "$WAN_IP" ]]; then
- curl -s -XPOST -H "Content-Type: application/xml" -d "$API_XML" https://api.domrobot.com/xmlrpc/
+ curl -s -X POST https://api.domrobot.com/xmlrpc/ \
+ -H "Content-Type: application/xml" \
+ -d "$API_XML_UPDATE_RECORD"
+
if [[ "$SILENT" == "NO" ]]; then
echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG
fi
@@ -138,6 +227,8 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
fi
fi
+ unset TYPE
+ unset MAIN_DOMAIN
unset DOMAIN
unset IPV6
unset MX
@@ -147,7 +238,8 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
unset INWX_PASS
unset INWX_USER
unset INWX_DOMAIN_ID
- unset API_XML
+ unset API_XML_UPDATE_RECORD
+ unset API_XML_INFO
done
else
echo "There does not seem to be any config file available in $(dirname $0)/nsupdate.d/."