-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-v6-cloudflare
executable file
·82 lines (66 loc) · 2.9 KB
/
update-v6-cloudflare
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
#!/bin/bash
#based on https://github.com/billkit/cloudflare-DDNS/blob/bc67f68f09abcecb56ef1cbbb087bd993a7244d9/cloudflare-v6.sh but modified. Tested on ubuntu 18.04 & 20.04
auth_email="user@mail.com"
auth_key="xxxxxxxxxxx"
## your cloudflare account key above
zone_name="domain.com"
record_name="record.domain.com"
rec_type=AAAA
interface=eth0
## calls the ipv6_addr.sh script to return an external IPv6 on defined interface above
content=$(/sbin/ifconfig $eth0 | /bin/grep "inet6" | /usr/bin/awk -F " " '{print $2}' | /usr/bin/awk '{print $1}'|/bin/grep -v fe80)
echo $(date)
echo "Checking $rec_type for $record_name"
zone_id=`curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "content-Type: application/json" | \
grep -Eo '"id":"[^"]*' | head -1|sed -n 's/"id":"*//p'`
echo "Zone ID: " $zone_id
record_id=`curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=$rec_type&name=$record_name" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "content-Type: application/json" | \
grep -Eo '"id":"[^"]*' | head -1 | sed -n 's/"id":"*//p'`
echo "Record ID: " $record_id
current_content=`curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "content-Type: application/json" | \
grep -Eo '"content":"[^"]*' | head -1 | sed -n 's/"content":"*//p'`
echo "Current Content: " $current_content
echo "New Content: " $content
if [[ $current_content == $content ]]; then
echo "Content not changed. Exiting."
exit 0
else
echo "Content Changed. Update Cloudflare."
fi
#time to delete and get it agian
echo "will delete and run agian as of bug"
delete_first=`curl -X DELETE "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "Content-Type: application/json"`
echo "Zone ID: " $zone_id
record_id=`curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=$rec_type&name=$record_name" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "content-Type: application/json" | \
grep -Eo '"id":"[^"]*' | head -1 | sed -n 's/"id":"*//p'`
echo "Record ID: " $record_id
update=`curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "content-Type: application/json" \
-d "{\"id\":\"$zone_id\",\"type\":\"$rec_type\",\"name\":\"$record_name\",\"content\":\"$content\"}"`
if [[ $update == *"\"success\":false"* ]]; then
echo "test"
#message = "API UPDATE FAILED. DUMPING RESULTS:\n$update"
#echo "$message"
echo "API UPDATE FAILED. DUMPING RESULTS:\n$update"
exit 1
else
message="$record_type changed to: $content"
echo "$message"
fi