fire1ce / DDNS-Cloudflare-Bash

Cloudflare DDNS bash Script for most Linux distributions and MacOS. Choose any source IP address to update external or internal (WAN/LAN). Cloudflare's options proxy and TTL configurable via the parameters.
https://3os.org
261 stars 61 forks source link

Script updates only first domain, not second #25

Closed aybab2 closed 5 months ago

aybab2 commented 5 months ago

cloudflare User API Token:

All zones - DNS:Edit

update-coudflare-dns.conf:

what_ip="external"
dns_record="url-1.com,url-2.com"
zoneid="zoneID-of-url-1"
cloudflare_zone_api_token="user-api-token"
proxied="false"

CONDITION NORMAL (all DNS records have correct IP): update-cloudflare-dns-log:

==> 2024-05-06 09:00:01
==> External IP is: 1.1.1.1
==> DNS record IP of url-1.com is 1.1.1.1, no changes needed.
==> DNS record IP of url-2.com is 1.1.1.1, no changes needed.

CONDITION IP CHANGED: update-cloudflare-dns-log:

==> 2024-05-06 09:01:01
==> External IP is: 1.1.1.2
==> DNS record of url-1.com is: 1.1.1.1. Trying to update...
==> Success!
==> url-1.com DNS Record updated to: 1.1.1.2, ttl: 1, proxied: false
==> DNS record of url-2.com is: 1.1.1.1. Trying to update...
{"success":false,"errors":[{"code":10000,"message":"PUT method not allowed for the api_token authentication scheme"}]}
Error! Update failed

STEPS TAKEN: Tried adding zoneID-of-url-2 as follows:

what_ip="external"
dns_record="url-1.com,url-2.com"
zoneid="zoneID-of-url-1,zoneID-of-url-2"
cloudflare_zone_api_token="user-api-token"
proxied="false"

RESULTS:

==> 2024-05-06 09:02:01
==> External IP is: 1.1.1.2
==> DNS record IP of url-1.com is 1.1.1.2, no changes needed.
==> DNS record of url-2.com is: 1.1.1.1. Trying to update...
{"success":false,"errors":[{"code":7003,"message":"Could not route to \/zones\/zoneID-of-url-1,zoneID-of-url-2\/dns_records, perhaps your object identifier is invalid?"},{"code":7000,"message":"No route for that URI"}],"messages":[],"result":null}
Error! Can't get url-2.com record information from Cloudflare API


I'm assuming only one zoneid should be entered in the conf.

Or perhaps both zoneid's need to be listed.

Or perhaps the domains need to be in same zone.

Any tips?

fire1ce commented 5 months ago

debug your API tokens. not a script issue

aybab2 commented 5 months ago

Appreciate your script, and the response. However the problem does lie within the script. Cloudflare assigns a unique Zone-ID to each individual domain. This script only allows one Zone-ID to be passed for ALL domains, and that is why cloudflare is not allowing this script to update more than one domain. In addition, the README says to create a zone-specific API token, this by design would not allow the API to update more than one zone. A little tweaking and we can get this script to update multiple zone's. It will need another function to accept a comma separated list of zone-ID's that need to be ordered corresponding to the list of domains. This will allow the PUT methods in your curl command to edit the correct zoneID for each domain. We could also then create only 1 zone-API-token which has permission across all zones. This is the most efficient path forward. Will tinker in spare time and then fork once completed. Thank you, cheers!