Got http to update DDNS but can't figure scrip to do this.

This is the http command. Need to get it into script form. Would it be possible? Any ideas would be appreciated.

https://www.cloudflare.com/api.html?a=DIUP&hosts=test.co.za&u=support@mymail.co.za&tkn=17610427ab5b783000d3102dd955&ip=196.219.31.181

The wiki has lots and lots of example scripts for updating DynDNS.org and changeip.com - you should be able to use those as building blocks for your provider.

Thanks. Actually using lots and lots of those scripts. :slight_smile: Working great, just cant seem to get the hang of this one though. Biggest problem is the that all those scrips make use of the dns-update tool, which does not support all the needed settings. Will give it a breather and then try again. :sunglasses:

# Define User Variables
:global CFusername "support@mymail.co.za";
:global CFpassword "17610427ab5b783000d3102dd955";
:global CFhost "test.co.za";

# Define Global Variables
:global CFip;
:global CFlastip;
:if ([ :typeof $CFlastip ] = nil ) do={ :global CFlastip "0" };

:global CFinterface;

# Define Local Variables
:local int;

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:foreach int in=[/ip route find dst-address=0.0.0.0/0 active=yes ] do={
  :if ([:typeof [/ip route get $int routing-mark ]] != str ) do={
     :global CFinterface [/ip route get $int interface];
  }
}

# Grab the current IP address on that interface.
:global CFip [ /ip address get [/ip address find interface=$CFinterface ] address ];

# Did we get an IP address to compare?
:if ([ :typeof $CFip ] = nil ) do={
   :log info ("CloudFlare: No ip address present on " . $CFinterface . ", please check.");
} else={
  :if ($CFip != $CFlastip) do={
    :log info "CloudFlare: Sending UPDATE!"
    /tool fetch address=www.cloudflare.com src-path="/api.html?a=DIUP&hosts=$CFhost&u=$CFusername&tkn=$CFpassword&ip=$CFip" mode=http dst-path=("/CFhost.".$CFhost);
    :delay 1
    /file remove [/file find name="CFhost.$CFhost"];
    :set CFlastip $CFip
  }

Untested, of course. Heavily, heavily, heavily based on a blatant rip off from http://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_dynDNS
Should work, though.

Thanks a lot. Will give it a bash tomorrow. However tkn=17610427ab5b783000d3102dd955 is a security token and not the password used to log in, but might work in this scenario and also this part “a=DIUP” tell the site to update, i guise the a record. Will have a look. Again, appreciate the input.

Well possible. Never heard of that provider. But if you figure it out and get it working make a wiki page for it!

Will do.

https://www.cloudflare.com/api.html?a=DIUP&hosts=test.co.za&u=support@mymail.co.za&tkn=17610427ab5b783000d3102dd955&ip=196.219.31.181

The problem appears to be the ? What would replace this in script?

The “?” is not an issue. It’s a normal character in URLs that indicates “that was the resource before me, after me are GET parameters”. The fetch tool handles that just fine.

Ok, have been trying to get it up and running in terminal window and found that it chucks the ? when i paste the line, probably because it is a help command.

In the CLI typing it directly you’ll have to escape it with a backslash.

?

I always put the url inside quotes and escape the ‘?’ i.e. ‘?’ even in scripts.

Your real problem will be that fetch doesn’t support https, afaik. http, ftp and tftp only.

 > /tool fetch url=https://www.yahoo.com           
failure: invalid URL protocol

It’s a major feature hole.

One way to get around this is to do the https wget on a server using php or cgi. Then make an http url on the server that the MT can fetch. When the MT fetchs, php does the https get.
It’s messy, but gets the job done. I did something like this to get OpenDNS to update a public IP.

Thanks for the info, appreciate. Did notice this, but was next hurdle. :slight_smile: Would try and keep it on the RB. Have got few domains i would like to update to different PPPoE ips and much easier if on RB. Looks like i would need a brandy top-up, :sunglasses: this is going to be a bit more time than anticipated. Have got every thing working on change ip, but like these guise more, much more, will still give it a bit of a bash.

Latest ROS now supports https fetch.
Does somebody get working script for CloudFare?

I’ve finally get working script for DDNS on CloudFlare
It’s messy, but works :slight_smile:
Just put your token, id, domain

/system script
add name=CloudFlareDDNS policy=\
    ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
    source="#:log info (\"CloudFlare: 0\");\r\
    \n\r\
    \n# Define User Variables\r\
    \n:global CFusername \"yourmail@gmail.com\";\r\
    \n:global CFpassword \"cloudflaretoken\";\r\
    \n:global CFhost \"subdomain\";\r\
    \n:global CFhostid \"subdomainID\";\r\
    \n:global CFzone \"domain.com\";\r\
    \n#:log info (\"CloudFlare: 1\");\r\
    \n\r\
    \n# Define Global Variables\r\
    \n:global CFip;\r\
    \n:global CFlastip;\r\
    \n:if ([ :typeof \$CFlastip ] = nil ) do={ :global CFlastip \"0\" };\r\
    \n#:log info (\"CloudFlare: 2\");\r\
    \n\r\
    \n# Get the current IP\r\
    \n#   :log info \"CF: Performing remote IP detection.\"\r\
    \n   /tool fetch address=\"ip.changeip.com\" host=\"ip.changeip.com\" src-\
    path=(\"/\?\" . [/int eth get 0 mac-address ]) dst-path=\"ip.txt\" mode=ht\
    tp port=80\r\
    \n# Parse the IP address received from fetch script.\r\
    \n:delay 5s;\r\
    \n\t:local html [/file get \"ip.txt\" contents]\r\
    \n\t:local CFip [:pick \$html ([:find \$html \"<!--IPADDR=\"] + 11) [:find\
    \_\$html \"-->\"] ]\r\
    \n#   :log info \"CF: \$CFip\"\r\
    \n\r\
    \n# Is it a valid IP and is it different than the last one\?\r\
    \n\t:if ([:typeof [:toip \$CFip]] = \"ip\" AND \$CFip != \$CFlastip ) do={\
    \r\
    \n\t\t:log info \"CF: Sending UPDATE with \$CFip\"\r\
    \n#\t\t:log info (\"api_json.html\\\?tkn=\".\$CFpassword.\"&email=\".\$CFu\
    sername.\"&a=rec_edit&id=\".\$CFhostid.\"&z=\".\$CFzone.\"&type=A&name=\".\
    \$CFhost.\"&service_mode=0&ttl=120&content=\".\$CFip)\t\r\
    \n/tool fetch mode=https address=\"www.cloudflare.com\" src-path=(\"api_js\
    on.html\\\?tkn=\".\$CFpassword.\"&email=\".\$CFusername.\"&a=rec_edit&id=\
    \".\$CFhostid.\"&z=\".\$CFzone.\"&type=A&name=\".\$CFhost.\"&service_mode=\
    0&ttl=120&content=\".\$CFip) check-certificate=no dst-path=\"result.htm\" \
    host=www.cloudflare.com\r\
    \n\r\
    \n\t\t:global CFlastip \$CFip\r\
    \n\t} else={\r\
    \n#\t\t:log info \"CF: No update required.\"\r\
    \n\t}\r\
    \n"

to get id of subdomain you can use

https://www.cloudflare.com/api_json.html?a=rec_load_all&tkn=yourtoken&email=yourmail@gmail.com&z=domain.com