mydnshost / mydnshost-api

API Backend for mydnshost
Other
2 stars 1 forks source link

Feature Request: DDNS-Friendly API to update records #45

Closed ShaneMcC closed 5 years ago

ShaneMcC commented 5 years ago

Something like https://api.mydnshost.co.uk/1.0/something{domain}/{domainkey}/record/{rrname}/{rrtype}?value=

Removes all the {rrname}.{domain} records of {rrtype} and replaces them with <foo>. Optionally some special value for "whatever IP requests the page". Should accept POST or GET for the value. (POST because things should be POST if they change things. GET to make it nicer for generic things to poke it).

Currently using the API it would need to be something like:

curl -s -d '{"data": {"content": "1.1.1.1"}}' -H "Content-Type: application/json" -H "X-Domain: example.org" -H "X-Domain-Key: SOME-DOMAIN-KEY-HERE" "https://api.mydnshost.co.uk/1.0/domains/example.org/records/$(curl -s -H "X-Domain: example.org" -H "X-Domain-Key: SOME-DOMAIN-KEY-HERE" "https://api.mydnshost.co.uk/1.0/domains/example.org/record/record/A" | jq -r .response.records[0].id)"

Or a bit nicer:

export DOMAIN="example.org"
export DOMAIN_KEY="SOME-DOMAIN-KEY-HERE"
export RECORD="record"
export RR="A"
export NEW_VALUE="1.1.1.1"
export RECORD_ID=`curl -s -H "X-Domain: ${DOMAIN}" -H "X-Domain-Key: ${DOMAIN_KEY}" "https://api.mydnshost.co.uk/1.0/domains/${DOMAIN}/record/${RECORD}/${RR}" | jq -r .response.records[0].id`
curl -s -d '{"data": {"content": "'${NEW_VALUE}'"}}' -H "Content-Type: application/json" -H "X-Domain: ${DOMAIN}" -H "X-Domain-Key: ${DOMAIN_KEY}" "https://api.mydnshost.co.uk/1.0/domains/${DOMAIN}/records/${RECORD_ID}"
ShaneMcC commented 5 years ago

I've added this to the experimental API, and you should now be able to do something like:

https://ddns.experimental.api.mydnshost.co.uk/setrecord/example.org/SOME-DOMAIN-KEY-HERE/record/A?content=1.1.1.1

or if you want dynamic stuff:

https://ddns.experimental.api4.mydnshost.co.uk/setrecord/example.org/SOME-DOMAIN-KEY-HERE/record/A?dynamiccontent=myip4

https://ddns.experimental.api6.mydnshost.co.uk/setrecord/example.org/SOME-DOMAIN-KEY-HERE/record/AAAA?dynamiccontent=myip6

Docs at: https://ddns.experimental.api.mydnshost.co.uk/experimental/ddns/docs/

ShaneMcC commented 5 years ago

Gonna leave this under experimental for now, may or may not get promoted.