leamas / ddupdate

Update DNS Data for Dynamic IP Addresses
MIT License
40 stars 28 forks source link

[plugin submit] freedns.afraid.org v2 api #70

Open atesin opened 1 year ago

atesin commented 1 year ago

hi.... as promised in #67 , i (tried to) wrote a new plugin for freedns afraid.org api v2 (random token)

random token is more secure (your accound data is not exposed) and shorter, and a single token can be associated with many domains... see https://freedns.afraid.org/dynamic/v2/ for details (needs login)

keep in mind is very basic because i don't have the tools (i wrote it just with plain vim) and i'm not so skilled in python, neither in git... i never sent a patch request so here it goes the plugin

freedns_v2.py

"""
"""
ddupdate plugin updating data on freedns.afraid.org api v2 random token.

See: ddupdate(8)
See: https://freedns.afraid.org
See: https://freedns.afraid.org/dynamic/v2/ (needs login)
"""

from ddupdate.ddplugin import ServicePlugin, ServiceError
from ddupdate.ddplugin import get_response

class FreednsV2Plugin(ServicePlugin):
    """
    Updates DNS data for host on freedns.afraid.org api v2.

    Freedns allows settings the IP address using an address plugin or
    just using the address as seen from the internet using the ip-disabled
    plugin. Ipv6 is supported. V2 api uses a random token which is simpler
    and more secure, your credentials are never exposed.

    Login to afraid.org and add some domain to v2 api. Take the token
    (last part of update url) and use it as 'hostname' in ddupdate.conf.
    """

    _name = 'sync.afraid.org'
    _oneliner = 'Updates on https://sync.afraid.org/'
    _url = 'https://{0}sync.afraid.org/u/{1}/'

    def register(self, log, hostname, ip, options):
        """
        Based on  https://freedns.afraid.org/dynamic/v2/, needs _url below
        to update.

        The {0} parameter is a randomized update token, generated specificly
        for each domain when enabled for api v2. The server detects source IP
        automatically, but optionally you can provide it
        """
        url = ''
        if ip and ip.v6:
            url = self._url.format('v6.', hostname) + '?address=' + str(ip.v6)
        else:
            url = self._url.format(''   , hostname)
            if ip and ip.v4:
                url += '?address=' + str(ip.v4)
        log.debug("Contacting freedns for update v2 on %s", url)
        get_response(log, url)

what it lacks:

maybe token fits best as password than hostname... but how can i do if i don't want to use a .netrc file?... i don't know/understand how to write it properly, but the code is open to enhancements

leamas commented 1 year ago

OK. "Just using vim" is nothing spectacular, this is what I use ;)

Anyway, without the netrc support it cannot be accepted since it will not work with ddupdate-config. This is a basic requirement for any plugin.

atesin commented 1 year ago

vim is a powerful text editor... but for developing apps it lacks many tools, like function names autocompletion, documentation tooltips, search in files debugging, refactoring, rename vars in all files, etc.... if you develop python or any language just with a text editor without the need of external tools, that means you know all the quirks of the language and you are a pro developer

i think this project urges a detailed (and well advertised) formal document on how to write plugins... requirements, submission, etc .... that might boost the growth and popularity of this plugin, and relieve your work

atesin commented 1 year ago

mh... i sent a pull request a week ago, but i cand find it :/

i manually edit a new file inside /plugins/ directory in devel branch and then the system offered me to sublit a pull request with the new file

atesin commented 1 year ago

nevermind... i sent a PR as it should be... by forking repo, modifying and sending a PR (i am still learning github)... please review when you can

74