Ticket #12500: 20141002-ddns_cloudflare.update

File 20141002-ddns_cloudflare.update, 2.6 KB (added by chris5560, 3 years ago)
Line 
1# update_script to update ddns service of cloudflare.com
2#
3# This script is parsed by dynamic_dns_functions.sh inside send_update() function
4#
5# using following options from /etc/config/ddns
6# option username - your cloudflare e-mail
7# option password - cloudflare api key, you can get it from cloudflare.com/my-account/
8# option domain   - your full hostname to update, in cloudflare its subdomain.domain
9#                       i.e. myhost.example.com where myhost is the subdomain and example.com is your domain
10#
11# addtional needed option inside /etc/config/ddns
12# option cloudflare_rec_id -
13
14# Attention !!! script will only work if there is only one subdomain-level at your domain
15# subdomain2.subdomain1.domain i.e. mail.host.example.com will not work
16#
17# variable __IP already defined with the ip-address to use for update
18#
19local __URL=""
20local __SUBDOMAIN=$(echo $domain | awk -F "." '{print $1}')
21local __DOMAIN=$(echo $domain | awk -F "${__SUBDOMAIN}." '{print $2}')
22
23# temporary code for testing only ********************************************************
24local __IDURL="https://www.cloudflare.com/api_json.html?a=rec_load_all&email=${username}&tkn=${password}&z=${__DOMAIN}"
25[ $use_https -ne 0 ] && __IDURL=$(echo $__IDURL | sed -e 's#^http:#https:#')    # set secure http
26__do_transfer __ANSWER "$__IDURL"
27echo "$__ANSWER" > /tmp/log/cloudflare.readid
28# temporary code for testing only ********************************************************
29
30# build url according to cloudflare client api at https://www.cloudflare.com/docs/client-api.html
31
32__URL="http://www.cloudflare.com/api_json.html"         # curl https://www.cloudflare.com/api_json.html
33__URL="${__URL}?a=rec_edit"                             #  -d 'a=rec_edit'
34__URL="${__URL}&tkn=$password"                          #  -d 'tkn=8afbe6dea02407989af4dd4c97bb6e25'
35__URL="${__URL}&id=$cloudflare_rec_id"                  #  -d 'id=9001'
36__URL="${__URL}&email=$password"                        #  -d 'email=sample@example.com'
37__URL="${__URL}&z=$__DOMAIN"                            #  -d 'z=example.com'
38
39[ $use_ipv6 -eq 0 ] && __URL="${__URL}&type=A"          #  -d 'type=A'
40[ $use_ipv6 -eq 1 ] && __URL="${__URL}&type=AAAA"
41
42__URL="${__URL}&name=$__SUBDOMAIN"                      #  -d 'name=sub'
43__URL="${__URL}&content=$__IP"                          #  -d 'content=1.2.3.4'
44__URL="${__URL}&service_mode=1"                         #  -d 'service_mode=1'
45__URL="${__URL}&ttl=1"                                  #  -d 'ttl=1'
46
47[ $use_https -ne 0 ] && __URL=$(echo $__URL | sed -e 's#^http:#https:#')        # set secure http
48
49# lets do the update
50__do_transfer __ANSWER "$__URL"
51__ERR=$?
52[ $__ERR -gt 0 ] && {
53        verbose_echo "\n!!!!!!!!! ERROR =: Error sending update to cloudflare.com\n"
54        return 1
55}
56verbose_echo "   update send =: cloudflare.com answered\n$__ANSWER"
57return 0