-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcf-domain-update
22 lines (22 loc) · 969 Bytes
/
cf-domain-update
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
:global domain "home.example.com"
:global theinterface "internet-interface"
:global ipremote [:resolve $domain]
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] != nil ) do={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}
:if ($ipremote != $ipfresh) do={
:local cfmail "[email protected]"
:local cfapikey "MY_CF_API_KEY"
:local cfzoneid "MY_CF_ZONE_ID"
:local cfdomainid "MY_CF_DOMAIN_ID"
/tool fetch mode=https http-method=put \
http-header-field="content-type:application/json,X-Auth-Email:$cfmail,X-Auth-Key:$cfapikey" \
url="https://api.cloudflare.com/client/v4/zones/$cfzoneid/dns_records/$cfdomainid" \
http-data="{\"type\":\"A\",\"name\":\"$domain\",\"content\":\"$ipfresh\",\"ttl\":1,\"proxied\":false}"
:local ipremote $ipfresh
}
}