]> git.ipfire.org Git - dnsbl.git/commitdiff
dnsbl: Add a dummy "update" command
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Dec 2025 14:29:30 +0000 (14:29 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Dec 2025 14:29:30 +0000 (14:29 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/dnsbl/__init__.py
src/dnsbl/logger.py [new file with mode: 0644]
src/scripts/dnsbl.in

index d5482f9ae4f949e83fad7624acd16ff1b086adb8..7199aa2165049a4825ee7dd1af8fbe4c7dae9b81 100644 (file)
@@ -50,7 +50,8 @@ SED_PROCESS = \
 
 dist_pkgpython_PYTHON = \
        src/dnsbl/__init__.py \
-       src/dnsbl/i18n.py
+       src/dnsbl/i18n.py \
+       src/dnsbl/logger.py
 
 # ------------------------------------------------------------------------------
 
index 463cc6a7dcc3af4ca6f854ea20bc57c5cbe1f18a..5330288aeb6ea575e454ad0c96aee65b43afd49f 100644 (file)
 ###############################################################################
 
 import configparser
+import logging
+
+# Initialize logging as early as possible
+from . import logger
+
+# Setup logging
+log = logging.getLogger(__name__)
 
 class Backend(object):
        def __init__(self, config=None):
                # Parse the configuration file
                self.config = self.parse_config(config)
 
+               log.debug("DNS Blocklist Backend Initialized")
+
        def parse_config(self, config=None):
                """
                        Reads the configuration file
@@ -37,3 +46,9 @@ class Backend(object):
                        c.read_file(config)
 
                return c
+
+       def update_sources(self):
+               """
+                       Updates all sources
+               """
+               pass
diff --git a/src/dnsbl/logger.py b/src/dnsbl/logger.py
new file mode 100644 (file)
index 0000000..2c06426
--- /dev/null
@@ -0,0 +1,47 @@
+###############################################################################
+#                                                                             #
+# dnsbl - A DNS Blacklist Compositor For IPFire                               #
+# Copyright (C) 2025 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+import logging
+import logging.handlers
+
+# Initialise root logger
+log = logging.getLogger("dnsbl")
+log.setLevel(logging.INFO)
+
+# Log to console
+handler = logging.StreamHandler()
+handler.setLevel(logging.DEBUG)
+log.addHandler(handler)
+
+# Log to syslog
+handler = logging.handlers.SysLogHandler(address="/dev/log",
+       facility=logging.handlers.SysLogHandler.LOG_DAEMON)
+handler.setLevel(logging.INFO)
+log.addHandler(handler)
+
+# Format syslog messages
+formatter = logging.Formatter("%(message)s")
+handler.setFormatter(formatter)
+
+def set_level(level):
+       """
+               Sets the log level for the root logger
+       """
+       log.setLevel(level)
index 0c0023e9a569be8c574b34774a860ed36145d754..f1f7a6cd69fa22606bb50734fc4edfa090b1d8e7 100644 (file)
@@ -21,6 +21,7 @@
 
 import argparse
 import dnsbl
+import logging
 import sys
 
 # i18n
@@ -44,6 +45,10 @@ class CLI(object):
                # Show Version
                parser.add_argument("--version", action="version", version="%(prog)s @VERSION@")
 
+               # update
+               update = subparsers.add_parser("update", help=_("Update sources"))
+               update.set_defaults(func=self.__update)
+
                # Parse all arguments
                args = parser.parse_args()
 
@@ -52,16 +57,35 @@ class CLI(object):
                        parser.print_usage()
                        sys.exit(2)
 
+               return args
+
        def run(self):
                # Parse the command line
                args = self.parse_cli()
 
-               # XXX Configure logging
+               # Configure logging
+               if args.debug:
+                       dnsbl.logger.set_level(logging.DEBUG)
 
                # Initialize the backend
                backend = dnsbl.Backend(args.config)
 
-               # XXX TODO
+               # Call the handler function
+               ret = args.func(backend, args)
+
+               # Exit with the returned error code
+               if ret:
+                       sys.exit(ret)
+
+               # Otherwise just exit
+               sys.exit(0)
+
+       def __update(self, backend, args):
+               """
+                       Updates all sources
+               """
+               backend.update_sources()
+
 
 def main():
        c = CLI()