-
Notifications
You must be signed in to change notification settings - Fork 0
/
dyndns_dootal.sh
101 lines (87 loc) · 3.13 KB
/
dyndns_dootal.sh
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
if [[ $# -ne 1 ]] ; then
echo './dns.sh NEW-IP'
exit 0
fi
# Update the following variables:
USERNAME=xxxxxx
PASSWORD=xxxxxx
TLD=eu
SLD=vault13
# Change nothing below this point
DOMAIN=$SLD.$TLD
NEWIP=$1
echo "<x:Envelope xmlns:x=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:syncer\">
<x:Header/>
<x:Body>
<urn:ListDnsRecords>
<urn:sld>$SLD</urn:sld>
<urn:tld>$TLD</urn:tld>
<urn:login_handle>$USERNAME</urn:login_handle>
<urn:login_password>$PASSWORD</urn:login_password>
</urn:ListDnsRecords>
</x:Body>
</x:Envelope>" > list.xml
xml=$(curl --silent --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:syncer#ListDnsRecords" --data @list.xml http://api.syncer.com/index.php)
SUBDOMAINS=$(printf '%s\n' "$xml" | xmlstarlet sel -t -m "//item[type='A']" -v "name" -o " ")
array=( $SUBDOMAINS )
OLDIP=$(printf '%s\n' "$xml" | xmlstarlet sel -t -m "//item[1][type='A']" -v "data")
if [ "$OLDIP" == "$NEWIP" ] ; then
echo 'IP Address not changed, aborting!'
exit 0
fi
# update every subdomain (A-Record)
for i in "${array[@]}"
do
echo Calling: xmlstarlet sel -t -m "//item[name='$i']" -v "data"
IP=$(printf '%s\n' "$xml" | xmlstarlet sel -t -m "//item[name='$i']" -v "data")
echo Replacing $OLDIP with $NEWIP for $i, which currently has IP $IP
if ! [ "$OLDIP" == "$IP" ] ; then
echo 'Custom IP Address $IP, aborting!'
continue
fi
echo deleting $i
echo "<x:Envelope xmlns:x=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:syncer\">
<x:Header/>
<x:Body>
<urn:DeleteDnsRecord>
<urn:domain>$DOMAIN</urn:domain>
<urn:name>$i</urn:name>
<urn:type>A</urn:type>
<urn:data>$OLDIP</urn:data>
<urn:login_handle>$USERNAME</urn:login_handle>
<urn:login_password>$PASSWORD</urn:login_password>
</urn:DeleteDnsRecord>
</x:Body>
</x:Envelope>" > delete.xml
#echo Press any key to continue && read -n 1 -s
curl --silent --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:syncer#DeleteDnsRecord" --data @delete.xml http://api.syncer.com/index.php >/dev/null 2>&1
rm delete.xml
echo creating $i
echo "<x:Envelope xmlns:x=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:syncer\">
<x:Header/>
<x:Body>
<urn:AddDnsRecord>
<urn:domain>$DOMAIN</urn:domain>
<urn:name>$i</urn:name>
<urn:dnstype>A</urn:dnstype>
<urn:data>$NEWIP</urn:data>
<urn:options>array(\"overwrite:yes\");</urn:options>
<urn:login_handle>$USERNAME</urn:login_handle>
<urn:login_password>$PASSWORD</urn:login_password>
</urn:AddDnsRecord>
</x:Body>
</x:Envelope>" > request.xml
#echo Press any key to continue && read -n 1 -s
curl --silent --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction:urn:syncer#AddDnsRecord" --data @request.xml http://api.syncer.com/index.php >/dev/null 2>&1
rm request.xml
done
rm list.xml
if [ $? -eq 0 ];
then
# /sbin/ddns_custom_updated 1
echo 1
else
# /sbin/ddns_custom_updated 0
echo 0
fi