This script will allow Synology NAS to automatically update Cloudflare.
Specifically if using Cloudflare Zero Trust Gateway DNS Endpoint with firewall rules (using free Cloudflare to provide DNS protection, filtering).
This setup is with a Synology NAS (DSM 7.2), Google handling DDNS, Cloudflare handling WAN DNS, and pulling current IP Address with ifconfig.me.
Honestly, can't remember why it was needed or what issues it caused, because setup a long time ago and just found my notes... and it's late .... but, I'm sure I needed it in place for some reason.
Zone ID
UUID
API Key
All items can be found in your Cloudflare Account (see link at bottom of page for more instructions).
Run this script on any PC on network. It calls Cloudflare's API and returns some of the info needed associated with DNS Gateway. Replace items in RED with your info:
curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/ZONE_ID/gateway/locations/UUID" -H "X-Auth-Email:EMAIL" -H "X-Auth-Key:API_KEY" -H "Content-Type:application/json"
Now, be sure to reference link below if re-using this. link
In Synology "Task Scheduler", setup to run the below script on a schedule. I couldn't get variables to work with the Synology script so just input them in manually. But this works AS-IS.
#!/bin/bash
URL="https://api.cloudflare.com/client/v4/accounts"
ZONE_ID="423xxxxxxxxxxx"
UUID="b7xxxxxxxxxxx"
EMAIL="John@Jones.com"
API_KEY="a0xxxxxxxxxxxx"
# get actual record information
REC=$(curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/423xxxxxxxxxxx/gateway/locations/b7xxxxxxxxxxx" -H "X-Auth-Email:John@Jones.com" -H "X-Auth-Key:a0xxxxxxxxxxxx" -H "Content-Type:application/json")
# actual registered ip
registered=$(echo ${REC} | jq '.result.networks[0] .network')
# current real external ip
cur="$(curl -s ifconfig.me)"
rent="/32"
current=\"$cur$rent\"
# function to update record ip (other values remain the same)
change_record() {
curl -s -X PUT "https://api.cloudflare.com/client/v4/accounts/423xxxxxxxxxxx/gateway/locations/b7xxxxxxxxxxx" -H "X-Auth-Email: John@Jones.com" -H "X-Auth-Key: a0xxxxxxxxxxxx" -H "Content-Type:application/json" --data '{"name":"Home","networks":[{"network": '"${current}"'}],"client_default":true}'
}
[ "$current" != "$registered" ] && {
change_record
}
(advert|adserv|adsystem|doubleclick|2mdn|truecaller|uberads|206ads|360in|360yield|3lift|a2z|aarki|ad2iction|adcolony|addthis|adform|adhaven|adlooxtracking|admicro|adnxs|adpushup|adroll|adsafeprotected|adsbynimbus|adspruce|adsrvr|adswizz|adtelligent|adventori|adzerk|aerserv|amplitude|aniview|anzuinfra|apester|aralego|atdmt|atwola|bannersnack|batmobi|bluecava|blueconic|carambo|casalemediacriteo|crittercismriteo|crittercism|revcontent|ijinshan|imrworldwide|inmobi|marketo|moatads|moatpixel|mookie|perfectaudience|permutive|pubmatic|pushwoosh|rayjump|revcontent|revjet|rfihub|richrelevance|rqmob|rubiconproject|onetag|samba|scopely|scorecardresearch|shareaholic|sharethis|sharethrough|smaato|snapads|speedshiftmedia|supersonicads|swrve|taboola|tremorhub|unity3d|vertamedia|videohub|vungle|wzrkt|xiaomi|yieldlove|yieldmo|yieldoptimizer|baidu|chinanet|yandex|googlesyndication)
The built in nginx error page is located here: /usr/syno/share/nginx/error.html
Create an Error Page and save to Synology just like you would anything (best to put in root of a folder so it's easier to find).
Now, SSH into Synology and copy new Error Page to the /nginx/error.html, replacing it:
cp error.html /usr/syno/share/nginx/error.html