]> git.ipfire.org Git - ddns.git/blobdiff - src/ddns/__init__.py
chore: add provider and sample configuration for infomaniak.ch
[ddns.git] / src / ddns / __init__.py
index fbebc0ef0ad9a91aade2dfd208bc516000c333c0..ca232bf9ec4c571db60689b1b0cf74e00cf2f405 100644 (file)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 ###############################################################################
 #                                                                             #
 # ddns - A dynamic DNS client for IPFire                                      #
 
 import logging
 import logging.handlers
-import ConfigParser
+import configparser
 
-from i18n import _
+from .i18n import _
 
 logger = logging.getLogger("ddns.core")
 logger.propagate = 1
 
-import providers
+from . import database
+from . import providers
 
 from .errors import *
 from .system import DDNSSystem
@@ -76,16 +77,33 @@ class DDNSCore(object):
                # Add the system class.
                self.system = DDNSSystem(self)
 
+               # Open the database.
+               self.db = database.DDNSDatabase(self, "/var/lib/ddns.db")
+
        def get_provider_names(self):
                """
                        Returns a list of names of all registered providers.
                """
                return sorted(self.providers.keys())
 
+       def get_provider_with_token_support(self):
+               """
+                       Returns a list with names of all registered providers
+                       which support token based authtentication.
+               """
+
+               token_provider = []
+
+               for handle, provider in sorted(self.providers.items()):
+                       if provider.supports_token_auth is True:
+                               token_provider.append(handle)
+
+               return sorted(token_provider)
+
        def load_configuration(self, filename):
                logger.debug(_("Loading configuration file %s") % filename)
 
-               configs = ConfigParser.RawConfigParser()
+               configs = configparser.RawConfigParser()
                configs.read([filename,])
 
                # First apply all global configuration settings.
@@ -94,7 +112,7 @@ class DDNSCore(object):
                                self.settings[k] = v
 
                # Allow missing config section
-               except ConfigParser.NoSectionError:
+               except configparser.NoSectionError:
                        pass
 
                for entry in configs.sections():
@@ -120,6 +138,12 @@ class DDNSCore(object):
                                logger.warning("Could not find provider '%s' for entry '%s'." % (provider, entry))
                                continue
 
+                       # Check if the provider is actually supported and if there are
+                       # some dependencies missing on this system.
+                       if not provider.supported():
+                               logger.warning("Provider '%s' is known, but not supported on this machine" % provider.name)
+                               continue
+
                        # Create an instance of the provider object with settings from the
                        # configuration file.
                        entry = provider(self, **settings)
@@ -153,13 +177,13 @@ class DDNSCore(object):
                try:
                        entry(force=force)
 
-               except DDNSError, e:
-                       logger.error(_("Dynamic DNS update for %(hostname)s (%(provider)s) failed:") % \
-                               { "hostname" : entry.hostname, "provider" : entry.name })
+               except DDNSError as e:
+                       logger.error(_("Dynamic DNS update for %(hostname)s (%(provider)s) failed:") %
+                               {"hostname": entry.hostname, "provider": entry.name})
                        logger.error("  %s: %s" % (e.__class__.__name__, e.reason))
                        if e.message:
                                logger.error("  %s" % e.message)
 
-               except Exception, e:
-                       logger.error(_("Dynamic DNS update for %(hostname)s (%(provider)s) throwed an unhandled exception:") % \
-                               { "hostname" : entry.hostname, "provider" : entry.name }, exc_info=True)
+               except Exception:
+                       logger.error(_("Dynamic DNS update for %(hostname)s (%(provider)s) threw an unhandled exception:") %
+                                                {"hostname": entry.hostname, "provider": entry.name}, exc_info=True)