Merge pull request #26 from EV21/GH-25
GH-25 Getting the Domain-Record-ID via XML-RPC API
This commit is contained in:
commit
8beff3d7c5
40
README.md
40
README.md
@ -17,17 +17,41 @@ In order to run the script you need to have installed the following command line
|
|||||||
- _awk_
|
- _awk_
|
||||||
- _nslookup_ or _drill_
|
- _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
|
## Installation
|
||||||
|
|
||||||
Simply clone this project or download the `master.zip` and extract it, e.g., using `wget` and `7z x master.zip`.
|
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.
|
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
|
## Run nsupdate by cron
|
||||||
With `crontab -e` you can add the following line for running the script every 5 minutes:
|
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
|
## Changelog
|
||||||
|
|
||||||
|
**2020-07-03**
|
||||||
|
|
||||||
|
- Rearranged config.sample
|
||||||
|
- Updated Readme
|
||||||
|
- Getting the Domain-Record-ID via XML-RPC API
|
||||||
|
|
||||||
**2020-05-11**
|
**2020-05-11**
|
||||||
|
|
||||||
- Updated Readme with some hints
|
- Updated Readme with some hints
|
||||||
|
@ -2,37 +2,52 @@
|
|||||||
# The nsupdate.sh is processing all .config files by looping.
|
# 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.
|
# If you want to update an IPv4 and an IPv6 record you need two config files.
|
||||||
|
|
||||||
# Log file name.
|
# Login credentials for the inwx admin interface
|
||||||
LOG="$0.log"
|
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?
|
# From which site should we get your WAN IP?
|
||||||
# Note that for IPv4 or IPv6 the IP_CHECK_SITE should work
|
# 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
|
# e.g. for IPv4 use api.ipify.org and for IPv6 use api6.ipify.org
|
||||||
IP_CHECK_SITE="https://api.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
|
# TTL: Time to Live
|
||||||
# default TTL setting by inwx is 3600 (1 hour)
|
# default TTL setting by inwx is 3600 (1 hour)
|
||||||
# minimum TTL allowed by inwx is 300 (5 minutes) for regular nameserver record updates
|
# 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
|
# Log file name.
|
||||||
INWX_USER="USERNAME"
|
LOG="$0.log"
|
||||||
INWX_PASS="PASSWORD"
|
|
||||||
|
|
||||||
# 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
|
# Note: You can get the specific domain record ID while editing the given nameserver entry by
|
||||||
# inspecting the target URL of the save button.
|
# 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"
|
||||||
|
104
nsupdate.sh
104
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 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 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 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
|
LOG=$0.log
|
||||||
SILENT=NO
|
SILENT=NO
|
||||||
@ -37,15 +38,30 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
|
|||||||
# Loop through configs
|
# Loop through configs
|
||||||
for f in $(dirname $0)/nsupdate.d/*.config
|
for f in $(dirname $0)/nsupdate.d/*.config
|
||||||
do
|
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
|
source $f
|
||||||
|
|
||||||
if [[ "$SILENT" == "NO" ]]; then
|
if [[ "$SILENT" == "NO" ]]; then
|
||||||
echo "Starting nameserver update with config file $f ($LOG)"
|
echo "Starting nameserver update with config file $f ($LOG)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Set record type to IPv4
|
if [[ "$TYPE" == "A" ]]; then
|
||||||
TYPE=A
|
CONNECTION_TYPE=4
|
||||||
CONNECTION_TYPE=4
|
fi
|
||||||
|
|
||||||
## Set record type to MX
|
## Set record type to MX
|
||||||
if [[ "$MX" == "YES" ]]; then
|
if [[ "$MX" == "YES" ]]; then
|
||||||
@ -55,6 +71,9 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
|
|||||||
## Set record type to IPv6
|
## Set record type to IPv6
|
||||||
if [[ "$IPV6" == "YES" ]]; then
|
if [[ "$IPV6" == "YES" ]]; then
|
||||||
TYPE=AAAA
|
TYPE=AAAA
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$TYPE" == "AAAA" ]]; then
|
||||||
CONNECTION_TYPE=6
|
CONNECTION_TYPE=6
|
||||||
fi
|
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}| grep -Eo '\<[[:digit:]]{1,3}(\.[[:digit:]]{1,3}){3}\>'`
|
||||||
WAN_IP=$(curl -s -$CONNECTION_TYPE ${IP_CHECK_SITE})
|
WAN_IP=$(curl -s -$CONNECTION_TYPE ${IP_CHECK_SITE})
|
||||||
|
|
||||||
|
# This is relevant for getting the specific domain record id.
|
||||||
|
API_XML_INFO="<?xml version=\"1.0\"?>
|
||||||
|
<methodCall>
|
||||||
|
<methodName>nameserver.info</methodName>
|
||||||
|
<params>
|
||||||
|
<param>
|
||||||
|
<value>
|
||||||
|
<struct>
|
||||||
|
<member>
|
||||||
|
<name>user</name>
|
||||||
|
<value>
|
||||||
|
<string>$INWX_USER</string>
|
||||||
|
</value>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<name>lang</name>
|
||||||
|
<value>
|
||||||
|
<string>en</string>
|
||||||
|
</value>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<name>pass</name>
|
||||||
|
<value>
|
||||||
|
<string>$INWX_PASS</string>
|
||||||
|
</value>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<name>domain</name>
|
||||||
|
<value>
|
||||||
|
<string>$MAIN_DOMAIN</string>
|
||||||
|
</value>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<name>name</name>
|
||||||
|
<value>
|
||||||
|
<string>$DOMAIN</string>
|
||||||
|
</value>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<name>type</name>
|
||||||
|
<value>
|
||||||
|
<string>$TYPE</string>
|
||||||
|
</value>
|
||||||
|
</member>
|
||||||
|
</struct>
|
||||||
|
</value>
|
||||||
|
</param>
|
||||||
|
</params>
|
||||||
|
</methodCall>"
|
||||||
|
|
||||||
API_XML="<?xml version=\"1.0\"?>
|
# 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="<?xml version=\"1.0\"?>
|
||||||
<methodCall>
|
<methodCall>
|
||||||
<methodName>nameserver.updateRecord</methodName>
|
<methodName>nameserver.updateRecord</methodName>
|
||||||
<params>
|
<params>
|
||||||
@ -128,7 +214,10 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
|
|||||||
</methodCall>"
|
</methodCall>"
|
||||||
|
|
||||||
if [[ "$NSLOOKUP" != "$WAN_IP" ]]; 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
|
if [[ "$SILENT" == "NO" ]]; then
|
||||||
echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG
|
echo "$(date) - $DOMAIN updated. Old IP: "$NSLOOKUP "New IP: "$WAN_IP >> $LOG
|
||||||
fi
|
fi
|
||||||
@ -138,6 +227,8 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
unset TYPE
|
||||||
|
unset MAIN_DOMAIN
|
||||||
unset DOMAIN
|
unset DOMAIN
|
||||||
unset IPV6
|
unset IPV6
|
||||||
unset MX
|
unset MX
|
||||||
@ -147,7 +238,8 @@ if ls $(dirname $0)/nsupdate.d/*.config &> /dev/null; then
|
|||||||
unset INWX_PASS
|
unset INWX_PASS
|
||||||
unset INWX_USER
|
unset INWX_USER
|
||||||
unset INWX_DOMAIN_ID
|
unset INWX_DOMAIN_ID
|
||||||
unset API_XML
|
unset API_XML_UPDATE_RECORD
|
||||||
|
unset API_XML_INFO
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "There does not seem to be any config file available in $(dirname $0)/nsupdate.d/."
|
echo "There does not seem to be any config file available in $(dirname $0)/nsupdate.d/."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user