Custom Dynamic DNS using PUT instead of GET



  • My dynamic DNS update URL requires HTTP PUT instead of GET in the form:

    curl -X PUT --user {email}:{password} https://{fqdn}/admin/dns/custom[/qname[/rtype]]
    

    So I tried putting the correctly formatted curl command into the "Update URL" field for the "Custom" service type of "Dynamic DNS Client". Of course that didn't work because the update URL field expects a URL and not a curl command.

    I can specify the URL alone, but is there a way to specify PUT instead of GET?


  • Netgate Administrator

    I'm not aware of a way to do that with the pfSense config. I think you would need to use a custom script or patch the existing code.

    Steve


  • Rebel Alliance Developer Netgate

    That would need custom code/scripting to handle the different method. The whole setup at the moment is geared toward using GET. I could see POST and PUT being useful but the latter two would need more work. PUT especially would likely have to format the submitted data differently (e.g. JSON), depending on what the server expects.



  • The DDNS server I'm referring to is Mail-in-a-Box which has an elegant REST-style API for managing custom DNS records. For instance, the following command sets pfsense.mydomain.com to point to the IP address of the machine you are executing curl on:

    curl -X PUT https://box.mydomain.com/admin/dns/custom/pfsense.mydomain.com
    

    But pfSense will only permit a GET request and not a PUT request. In fact, many dynamic DNS APIs utilize GET for update functionality, and pfSense supports 40+ different DDNS services, so while I appreciate the popular view of GET for updating DDNS, it would be nice if the "Custom" DDNS option of pfSense optionally supported the elegant REST-style API of PUT or POST for DDNS update functionality.

    Perhaps the answer is to augment pfSense with a "cURL" DDNS option which would allow the specification of a minimal set of curl options including:

    -X, --request <command> - Specifies a custom request method to use when communicating with the HTTP server.
    -d, --data <data> Sends  the  specified data in a POST request.
    

    The benefit to this approach would be tremendous flexibility in calling various DDNS providers whose APIs are more REST-centric.


  • Netgate Administrator

    I could be misreading this but there do seem to be a number of clients (3) using PUT already. For example:
    https://github.com/pfsense/pfsense/blob/8800ee6f90d2ac91ca9c2886bd260bc1a4e12893/src/etc/inc/dyndns.class#L804

    Maybe you could just add your provider via a pull request?

    Steve


  • Rebel Alliance Developer Netgate

    Yes, it could be done that way as a new provider. Though having the option in custom could be handy for others using private servers or other providers they don't want to add the code for.



  • I think you're right! I spent so much time trying to get the Custom option to work, that I didn't realize some of the other providers require PUT.

    I'm not a PHP-programmer, but I'll study the code and try to make sense of it. I'm sure it would be a piece of cake for the programmer of this code to add support for MIAB.



  • I've spent some time looking over the code for DDNS, and I see at least three files that would need to be changed in order to add support for PUT to the "Custom" DNS provider.

    src/usr/local/www/services_dyndns_edit.php
    src/etc/inc/dyndns.class
    src/etc/inc/services.inc
    

    I'm thinking of adding a new flag 'curl_use_http_put' similar to the existing 'curl_ssl_verifypeer' flag so that the "Custom" provider UI will display a new checkbox to capture the option in "src/usr/local/www/services_dyndns_edit.php".

    The flag 'curl_use_http_put' would need to be passed to "src/etc/inc/dyndns.class" where the logic to act on the flag would evaluated.

    One thing I don't yet understand is how the configuration is persisted. Would someone provide an overview of how the DDNS service is initialized and settings persisted?


Log in to reply