-
Notifications
You must be signed in to change notification settings - Fork 1
/
HostEuropeDynDns
executable file
·74 lines (60 loc) · 3.27 KB
/
HostEuropeDynDns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Script for automatically update a DNS-A entry for domains hosted by http://hosteurope.de
# The purpose of this script is to have a DNS update functionality similar to dyndns, no-ip, or afraid.org.
DOMAIN=$3 # Domain name
HOST=$4 # Host Name
#NEW_IP="3.2.1.2" # Desired IP address (if not set, external IP will be used)
HOSTEUROPE_kdnummer=$1 # Hosteurope "Kundennmmer"
HOSTEUROPE_passwd=$2 # Hosteurope password (must be urlencoded)
# uncomment first line if you have curl and second line if you have wget
#FETCH_BIN="curl -s --url"
FETCH_BIN="wget -qO-"
# Regular expression for valid IPv4 adresses
REGEX_IS_IP="(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"
# file to temporary store data
TMP_FILE="/tmp/hosteurope_update_DNS_A.tmp"
# URL-start (use variable since it occurs so often
URL_START="https://kis.hosteurope.de/administration/domainservices/index.php?menu=1&submode=edit&mode=autodns&domain=$DOMAIN&kdnummer=$HOSTEUROPE_kdnummer&passwd=$HOSTEUROPE_passwd"
while true; do
echo "start updating"
echo "get list of all DNS entries..."
# get list of all DNS entries (more information is stored on the webpage than it's visible). Purge unneeded stuff to save space (important on embedded devices)
$FETCH_BIN "$URL_START" | grep -e "$HOST.$DOMAIN" -e "hidden" -e "record" > $TMP_FILE
# fine line where information about $HOST starts
START_LINE=$(grep -n "$HOST.$DOMAIN" $TMP_FILE | cut -f1 -d:)
if [ -z $START_LINE ]; then
logger -s "DNS Update Hosteurope: can't find $HOST.$DOMAIN as vaild entry in https://kis.hosteurope.de/administration/domainservices/index.php?menu=1&mode=autodns&submode=edit&domain=$DOMAIN"
exit 1
fi
echo "START_LINE: $START_LINE"
# from $START_LINE search in the next 10 lines for a hostid and eliminate clutter like "value=". The limit of 10 lines is necessary to avoid fetching hostid of wrong host.
HOSTID=$(tail -n +$START_LINE $TMP_FILE | head -n 10 | grep hostid | awk '{ print $4 }' | sed -e 's/value="//' -e 's/"//')
if [ -z $HOSTID ]; then
logger -s "DNS Update Hosteurope: can't fetch HOSTID for host $HOST.$DOMAIN"
exit 1
fi
# same for getting old IP
OLD_IP=$(tail -n +$START_LINE $TMP_FILE | head -n 10 | grep -e "select name=\"record" | awk '{ print $19 }' | sed -e 's/value="//' -e 's/"><br//' | head -n 1 | grep -E "$REGEX_IS_IP" )
if [ -z $OLD_IP ]; then
logger -s "DNS Update Hosteurope: can't fetch OLD_IP for host $HOST.$DOMAIN"
exit 1
fi
# get IP if not already set by $NEW_IP
if [ -z $NEW_IP ]; then
NEW_IP=$($FETCH_BIN "http://ifconfig.me/ip" | grep -E "$REGEX_IS_IP" )
if [ -z $NEW_IP ]; then
logger -s "DNS Update Hosteurope: can't fetch CURRENT_IP from http://ifconfig.me/ip"
echo "DNS Update Hosteurope: can't fetch CURRENT_IP from http://ifconfig.me/ip"
exit 1
fi
fi
# update only if something had changed (hosteurope gets annoyed if you spam updates too frequently)
if [ $OLD_IP != $NEW_IP ]; then
$FETCH_BIN "$URL_START&record=0&pointer=$NEW_IP&submit=Update&truemode=host&hostid=$HOSTID" > /dev/null
echo "updated IP-Address: $NEW_IP"
fi
echo "finished"
sleep 55;
done
# delete temp file
rm $TMP_FILE