I modified the NOIP script to make it work with Gandi LiveDNS. it work well, but only with a single domain. To make that use multiple domain, I have to convert the following curl/jq line to "/tool fetch", but I can't. This line is used to change the gandi zones UUID
Code: Select all
curl -s -H "X-Api-Key: $apikey" https://dns.api.gandi.net/api/v5/domains/$domain | jq -r '.zone_records_href'
I convert the first part that use curl but I don't know how to convert the last part that use jq.
Code: Select all
/tool fetch mode=https http-method=get http-header-field="Content-Type:application/json,X-Api-Key:$apikey" url=https://dns.api.gandi.net/api/v5/domains/$domain
Please give me some advice or suggestions to convert the jq code, if it is possible.
Code: Select all
# Gandi.net LiveDNS automatic Dynamic DNS update written by Massimo Ciani
#
# Credits:
# - This script was designed using the NO-IP script written by riverron https://wiki.mikrotik.com/wiki/Dynamic_DNS_Update_Script_for_No-IP_DNS
#
#--------------- Change Values in this section to match your setup ------------------
# LiveDNS API key
:local apikey "your api key"
# Set the domain and subdomain of zone to be updated.
# Hostnames with spaces are unsupported. Replace the value in the quotations below with your domain and subdomain.
# To specify multiple domain, separate them with commas.(not working right now. Only one domain)
:local domain "example.com"
:local subdomain "subdomain name"
# catch this by using this command on your computer (change the $apikey and $domain): curl -s -H "X-Api-Key: $apikey" https://dns.api.gandi.net/api/v5/domains/$domain | jq -r '.zone_records_href'
:local zonehref "https://dns.api.gandi.net/api/v5/zones/<UUID>/records"
# Change to the name of interface that gets the dynamic IP address
:local inetinterface "pppoe-out1"
#------------------------------------------------------------------------------------
# No more changes need
:global previousIP [:resolve "$subdomain.$domain"]
:if ([/interface get $inetinterface value-name=running]) do={
# Get the current IP on the interface
:local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address]
# Strip the net mask off the IP address
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i]
}
}
:if ($currentIP != $previousIP) do={
:log info "LiveDNS: Current IP $currentIP is not equal to previous IP, update needed"
:local noiphostarray
:set noiphostarray [:toarray $domain]
:foreach host in=$noiphostarray do={
# Next line must be converted from curl to "/tool fetch" to have multidomain work
# :local zonehref [curl -s -H "X-Api-Key: $apikey" https://dns.api.gandi.net/api/v5/domains/$domain | jq -r '.zone_records_href']
:log info "LiveDNS: Sending update for $subdomain.$host"
/tool fetch mode=https http-method=put http-header-field="Content-Type:application/json,X-Api-Key:$apikey" http-data="{\"rrset_name\": \"$subdomain\",\"rrset_type\": \"A\",\"rrset_ttl\": 300,\"rrset_values\": [\"$currentIP\"]}" url="$zonehref/$subdomain/A" dst-path="" output=none
:log info "LiveDNS: Host $subdomain.$host updated on Gandi with IP $currentIP"
}
} else={
:log info "LiveDNS: Previous IP $previousIP is equal to current IP, no update needed"
}
} else={
:log info "LiveDNS: $inetinterface is not currently running, so therefore will not update."
}
I'm not a programmer and maybe there are some error in the script. If there are please report to me.
Thanks