mike6715b / Mikrotik_CF_DDNS

Script for automatic DNS updates on Cloudflare
64 stars 25 forks source link

unable to change cloudflare dns entry #1

Closed carmineyiu closed 3 years ago

carmineyiu commented 3 years ago

I copy you script to mikrotik and set read, write, ftp. I use the following script to get the record id and other cloudflare info, then copy to your script. https://gist.github.com/Tras2/cba88201b17d765ec065ccbedfb16d9a

Data need input: WanInterface CFdomain CFtk CFzoneid CFid

I modify the cloudflare DNS record, it cannot detect there is a change in CloudFlare DNS. I saw previousIP is local variable, do not know where it keep the value. reboot mikrotik, to clear previousIP, from log, No previous ip address file found, createing.. CF: Updating CF, setting = my wan IP.

Check with Cloudflare DNS, there is no change, run the cloudflare-ddns-update.sh, effective immediate, cloudflare DNS updated.

from the log, CFdomain is the website name. from debug log, currentIP has no value.

From log, the value seems correct.
1st line CF: CFurl = https://api.cloudflare.com/client/v4/zones/myzone_id/dns_records/my_record_id&content=mywan_ip 2nd line My_Global_API_KEY; output=none http-data="{"type":"A","name":"my_website","ttl":120,"content":"mywan_ip"}"

I have not idea what is wrong. pls help

mike6715b commented 3 years ago

The previous IP is stored on local storage. Click "Files" in winbox and open ddns.tmp.txt to see your previous IP. Double check that you have your correct variables set: CFtkn is your private key or API token you get on cloudflare : https://dash.cloudflare.com/profile/api-tokens CFzoneid you get from the overview page of your domain (https://dash.cloudflare.com/ACC_ID/example.com) by scrolling down a bit and on the right side you will se it as Zone ID. Only CFid is a bit tricky... I call the cloudflare API to get all of my domains and just copied the ID of the one I want. If you'd like you can install postman and set all required paramaters from my json script.

OR step by step: After installing postman crate a new GET request. As link paste: https://api.cloudflare.com/client/v4/zones/ZONE_ID/dns_records?name=DOMAIN_NAME Replace ZODE_ID with your Zone ID from Cloudflare overview page. Under Authorization type select Bearer Token and paste in your API key. Under params change the value of the name paramater from DOMAIN_NAME to your domain eg. example.com and run the request. The first lane with id: YOUR_DOMAIN_ID copy the DOMAIN_ID and add it to the script.

The script works fine for me... Has worked since the day i uploaded the script and some time before.

carmineyiu commented 3 years ago

Is the following variable is good enough? running another mikrotik script, it can update cloudflare DNS correctly. so cross check and find they need login email id. :global WANInterface "wan" :local CFdomain "YOUR_DOMAIN" :local CFtkn "YOUR_API_TOKEN" :local CFzoneid "ZONE_ID" :local CFid "RECORD_ID"

I use the following method to test, input to winbox - terminal , and all record id is return. i.e my zone_id, apk token, email are correct. global cfg do={\ /tool fetch mode=https\ http-method=get\ url="https://api.cloudflare.com/client/v4/zones/$cfi/dns_records"\ http-header-field="content-type:application/json,X-Auth-Email:$cfe,X-Auth-Key:$cfk"\ } $cfg cfi="ZONE_ID" cfe="where is the email address" cfk="YOUR_API_TOKEN"

Input the record id and use script with following, also return can update cloudflare dns, sorry i am not an expert in cloudflare API, the only different I know the script below use email address, while your script do not need. /tool fetch mode=https\ http-method=put\ url="https://api.cloudflare.com/client/v4/zones/$cfi/dns_records/$cfr"\ http-header-field="content-type:application/json,X-Auth-Email:$cfe,X-Auth-Key:$cfk"\ http-data="{\"type\":\"A\",\"name\":\"$cfd\",\"content\":\"$cfa\",\"proxied\":$cfp}"\ output=none\ }

mike6715b commented 3 years ago

I found that you don't need an email in your headers just that you need to place "Authorization: Bearer $Cftkn" and the json as content type. When I was testing the old didn't work because of the way the token was passed because you needed the "Authorization: Bearer" line for it to work. Without your full script including all required parameters I can't say for certain what's wrong but the cloudflare parameters are also something that should be kept private. I recommend to experiment more with Postman since that's how I was able to get my script to work, Try inputting your API key as a parameter and then in the Authorization field. I found that mine didn't work as a parameter only in Authorization. Also maybe check if your API key has access to your domain. Other than that I don't know how else to help you without seeing your complete script including parameters :/ Try referencing the docs of Cloudflare API: https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record for correct formatting. While they also say to use Email AND key, in postman I get "Error 1000, Authentication error" and when using Authorization: Bearer $tkn it works fine. Email & Token : https://imgur.com/UvgelVK Authorization: Bearer $tkn : https://imgur.com/AZsCSdG

carmineyiu commented 3 years ago

working with different cloudflare update program. Found that for global API token need email address, if zone API token do not need email address. Will test the script again later to see if my zone API is not set correctly.

mike6715b commented 3 years ago

Closing due to inactivity