enable to use custom config file, and multiple domains to update at once
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
config.cfg
|
config.cfg
|
||||||
old.ip
|
old*.ip
|
||||||
tor-ips.txt
|
tor-ips.txt
|
||||||
update.log
|
update*.log
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
# Snap DynDNS server (ending with update.php)
|
# Snap DynDNS server (ending with update.php)
|
||||||
SERVER=https://yourdyndnsservice.net
|
SERVER=https://yourdyndnsservice.net/update.php
|
||||||
|
|
||||||
# Your personal DynDNS domain which has been registered to your
|
# Snap DynDNS domain, username and password
|
||||||
# Snap DynDNS Server provider
|
DOMAIN[0]=user1.example.com
|
||||||
DOMAIN=user1.example.com
|
USER[0]=myuser
|
||||||
|
PASS[0]=mypass
|
||||||
|
|
||||||
# Easy DynDNS username and password
|
# You can other domains to be updated. Just increase the counter
|
||||||
USER=myuser
|
#DOMAIN[1]=subdomain.user1.example.com
|
||||||
PASS=mypassword
|
#USER[1]=myuser
|
||||||
|
#PASS[1]=mypass
|
||||||
|
|
||||||
# Service which shows own IP in plain text (notice that if you use IPv4
|
# Service which shows own IP in plain text (notice that if you use IPv4
|
||||||
# and IPv6 parallely you will get an IPv6 address in many cases in
|
# and IPv6 parallely you will get an IPv6 address in many cases in
|
||||||
|
|||||||
114
dnsupdate.sh
114
dnsupdate.sh
@@ -26,9 +26,25 @@
|
|||||||
|
|
||||||
cd "$(dirname "$(readlink -f "$0")")"
|
cd "$(dirname "$(readlink -f "$0")")"
|
||||||
|
|
||||||
|
print_usage() {
|
||||||
|
echo "dnsupdate.sh [-c configfile]"
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts c:h OPT; do
|
||||||
|
case $OPT in
|
||||||
|
c) CONFIG=$OPTARG;; # type: normal or docker
|
||||||
|
h) print_usage; exit 0;;
|
||||||
|
*) echo "Unknown option: -$OPTARG"; print_usage; exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z $CONFIG ]; then
|
||||||
|
CONFIG="config.cfg"
|
||||||
|
fi
|
||||||
|
|
||||||
# Test if config.cfg exists and set needed variables
|
# Test if config.cfg exists and set needed variables
|
||||||
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
|
if [ ! -e "$CONFIG" ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
|
||||||
source config.cfg
|
source "$CONFIG"
|
||||||
|
|
||||||
# Test whether necessary applications are installed
|
# Test whether necessary applications are installed
|
||||||
function testinst {
|
function testinst {
|
||||||
@@ -41,54 +57,60 @@ function testinst {
|
|||||||
testinst curl
|
testinst curl
|
||||||
testinst wget
|
testinst wget
|
||||||
|
|
||||||
# Does the old.ip file exist? If not, fill it with unrealistic input
|
# Loop over all hosts. $i will be key
|
||||||
if [ ! -e old.ip ]; then
|
for i in "${!USER[@]}"; do
|
||||||
echo "0.0.0.0" > old.ip
|
oldip="old-$i.ip"
|
||||||
fi
|
logfile="update-$i.log"
|
||||||
|
|
||||||
# Read old IP, gather new IP via IP return service
|
# Does the old.ip file exist? If not, fill it with unrealistic input
|
||||||
OLDIP=$(cat old.ip)
|
if [ ! -e "$oldip" ]; then
|
||||||
NEWIP=$(wget -T $TIMEOUT -q -O - $IPSERV)
|
echo "0.0.0.0" > "$oldip"
|
||||||
|
|
||||||
# Post current timestamp in logfile
|
|
||||||
echo "[$(date "+%Y-%m-%d %H:%M:%S")]" > update.log
|
|
||||||
|
|
||||||
# check whether the IP has changed since the last update
|
|
||||||
if [ "$OLDIP" == "$NEWIP" ]; then
|
|
||||||
echo "IP ($OLDIP) did not change. Aborting." >> update.log
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check whether IP is on ignore list
|
|
||||||
if [ $(echo "$IGNOREIP" | grep "$NEWIP") ]; then
|
|
||||||
echo "Current IP ($NEWIP) is ignored. Aborting without DNS update." >> update.log
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check whether user is using a Tor exit node IP
|
|
||||||
if [ "$CHECKTOR" = true ]; then
|
|
||||||
# Only download list of exit nodes if tor-ips.txt file isn't existing yet, or if it is older than 7 days
|
|
||||||
if [ ! -e tor-ips.txt ] || [ $[ $(date +%s) - $(stat -L -c %Y tor-ips.txt) ] -gt "604800" ]; then
|
|
||||||
# download list, extract plain IPs, move back to file
|
|
||||||
echo "download list"
|
|
||||||
wget -O tor-ips.txt $EXITNODES
|
|
||||||
TORIPS=$(grep "^ExitAddress" tor-ips.txt | cut -d" " -f2)
|
|
||||||
echo $TORIPS | sed 's/ /\n/g' > tor-ips.txt
|
|
||||||
fi
|
fi
|
||||||
# Grep current IP in list of exit node IPs
|
|
||||||
if [ $(grep "^$NEWIP$" tor-ips.txt) ]; then
|
# Read old IP, gather new IP via IP return service
|
||||||
echo "Current IP ($NEWIP) is ignored because it is a Tor exit IP. Aborting without DNS update." >> update.log
|
OLDIP=$(cat "$oldip")
|
||||||
exit 0
|
NEWIP=$(wget -T $TIMEOUT -q -O - $IPSERV)
|
||||||
|
|
||||||
|
# Post current timestamp in logfile
|
||||||
|
echo "[$(date "+%Y-%m-%d %H:%M:%S")]" > "$logfile"
|
||||||
|
|
||||||
|
# check whether the IP has changed since the last update
|
||||||
|
if [ "$OLDIP" == "$NEWIP" ]; then
|
||||||
|
echo "IP ($OLDIP) did not change. Aborting." >> "$logfile"
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Run update if old IP and current IP are not equal
|
# Check whether IP is on ignore list
|
||||||
if [ ! "$OLDIP" == "$NEWIP" ]; then
|
if [ $(echo "$IGNOREIP" | grep "$NEWIP") ]; then
|
||||||
echo $NEWIP > old.ip
|
echo "Current IP ($NEWIP) is ignored. Aborting without DNS update." >> "$logfile"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
curl -X POST -d "domain=$DOMAIN&user=$USER&pass=$PASS&ip=$NEWIP" "$SERVER" >> update.log
|
# Check whether user is using a Tor exit node IP
|
||||||
|
if [ "$CHECKTOR" = true ]; then
|
||||||
|
# Only download list of exit nodes if tor-ips.txt file isn't existing yet, or if it is older than 7 days
|
||||||
|
if [ ! -e tor-ips.txt ] || [ $[ $(date +%s) - $(stat -L -c %Y tor-ips.txt) ] -gt "604800" ]; then
|
||||||
|
# download list, extract plain IPs, move back to file
|
||||||
|
echo "download list"
|
||||||
|
wget -O tor-ips.txt $EXITNODES
|
||||||
|
TORIPS=$(grep "^ExitAddress" tor-ips.txt | cut -d" " -f2)
|
||||||
|
echo $TORIPS | sed 's/ /\n/g' > tor-ips.txt
|
||||||
|
fi
|
||||||
|
# Grep current IP in list of exit node IPs
|
||||||
|
if [ $(grep "^$NEWIP$" tor-ips.txt) ]; then
|
||||||
|
echo "Current IP ($NEWIP) is ignored because it is a Tor exit IP. Aborting without DNS update." >> "$logfile"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
echo "" >> update.log
|
# Run update if old IP and current IP are not equal
|
||||||
echo "Updated IP address from $OLDIP to $NEWIP." >> update.log
|
if [ ! "$OLDIP" == "$NEWIP" ]; then
|
||||||
fi
|
echo $NEWIP > "$oldip"
|
||||||
|
|
||||||
|
curl -X POST -d "domain=${DOMAIN[$i]}&user=${USER[$i]}&pass=${PASS[$i]}&ip=$NEWIP" "$SERVER" >> "$logfile"
|
||||||
|
|
||||||
|
echo "" >> "$logfile"
|
||||||
|
echo "Updated IP address from $OLDIP to $NEWIP." >> "$logfile"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user