Using OPNsense API to update a DNS entry via cPanel
Although free DynDNS services such as dynu or dynv6 are fine, it is a missed opportunity to use them when you own your own TLD domain, which is obviously my case here.
My hosting service (ex2.com) provides a cPanel management dashboard. I could not get satisfying results trying to integrate the built-in DynDNS feature of cPanel with OPNsense. My main issue is that I could not get the same FQDN to get both an A and a AAAA record.
After a bit of snooping around, I ended up on this GitHub repo that uses the cPanel JSON API to update a DNS record based on either a command-line argument or the ipify API.
Eurêka !
A fork and a few hours of Python coding later, I have extended the functions of this script, including the ability to get the IPv4 and IPv6 addresses for the records from the OPNsense API.
The updated script can be found here. The original repository did not have a license set, so I took the liberty to add a MIT license.
To whomever might stumble upon this and have the same use case, enjoy and don’t hesistate to propose enhancements !