opnsense / plugins

OPNsense plugin collection
https://opnsense.org/
BSD 2-Clause "Simplified" License
810 stars 593 forks source link

ddclient: allow hostname starting with dot for porkbun provider #3965

Open danieleg1 opened 1 month ago

danieleg1 commented 1 month ago

Important notices Before you add a new report, we ask you kindly to acknowledge the following:

Is your feature request related to a problem? Please describe. Right now with porkbun as provider and ddclient as backend, you can only update subdomain (aaa.example.com, bbb.example.com), if you put the root domain example.com the update fails.

Describe the solution you'd like Putting as hostname .example.com the update of the dns record works, but you can't do that in the ui because the validation return the error "Please specify a valid IP address or hostname". I'd like to allow that hostname.

Additional context After a bit of trial and error with plain ddclient I found that this configuration works as expected (notice the starting dot in the domain):

protocol=porkbun \
apikey=pk1_xxx \
secretapikey=sk1_xxx \
root-domain=example.com
.example.com

In OPNsense I had to manually edit the file /usr/local/etc/ddclient.json changing the "hostnames" key, after a restart of the plugin the DNS record was correctly updated, but obviously this is not a permanent fix becasue the manual edit is lost every time you apply the configuration from the WebUI.

Without this fix the update fails because ddclient call this API to check the if the domain exists:

https://porkbun.com/api/json/v3/dns/retrieveByNameType/[HOSTNAME]/A/[SUBDOMAIN]

With a hostname aaa.example.com the actual url called is:

https://porkbun.com/api/json/v3/dns/retrieveByNameType/example.com/A/aaa

The SUBDOMAIN is optional to allow update of the root domain, but right now if you put example.com as hostname the url look like this:

https://porkbun.com/api/json/v3/dns/retrieveByNameType/com/A/example

and this calls fails because com is not a valid domain name. With a dot at the start, the domain is correctly parsed and the url is:

https://porkbun.com/api/json/v3/dns/retrieveByNameType/example.com/A/

Porkbun API documentation: https://porkbun.com/api/json/v3/documentation