-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudflare_dyndns.sh
executable file
·61 lines (54 loc) · 1.2 KB
/
cloudflare_dyndns.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
#!/bin/bash
set -e
baseUrl='https://api.cloudflare.com/client/v4'
token=$CLOUDFLARE_TOKEN
zoneId=$CLOUDFLARE_ZONE_ID
recordId=$CLOUDFLARE_RECORD_ID
myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
#!/bin/bash
function getUrl(){
path=$1
curl -sX GET \
"${baseUrl}/${path}" \
-H "Authorization: Bearer ${token}" \
-H "Content-Type:application/json" \
| jq -r .
}
function postUrl(){
path=$1
data=$2
curl -sX POST \
"${baseUrl}/${path}" \
-H "Authorization: Bearer ${token}" \
-H "Content-Type:application/json" \
--data "${data}" \
| jq -r .
}
function putUrl(){
path=$1
data=$2
curl -sX PUT \
"${baseUrl}/${path}" \
-H "Authorization: Bearer ${token}" \
-H "Content-Type:application/json" \
--data "${data}" \
| jq -r .
}
generate_post_data()
{
cat <<EOF
{
"type": "A",
"name": "bcn.crypto-pool.net",
"content": "$myip",
"ttl": 120,
"priority": 10,
"proxied": false
}
EOF
}
#getUrl 'user/token/verify'
#getUrl 'zones'
#getUrl "zones/${zoneId}/dns_records"
#postUrl "zones/${zoneId}/dns_records" "$(generate_post_data)"
putUrl "zones/${zoneId}/dns_records/${recordId}" "$(generate_post_data)"