From: Michael Tremer Date: Fri, 5 Dec 2025 14:29:30 +0000 (+0000) Subject: dnsbl: Add a dummy "update" command X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=815cd205c3e9422303025a208e29eae48d9cb6ab;p=dnsbl.git dnsbl: Add a dummy "update" command Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index d5482f9..7199aa2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 # ------------------------------------------------------------------------------ diff --git a/src/dnsbl/__init__.py b/src/dnsbl/__init__.py index 463cc6a..5330288 100644 --- a/src/dnsbl/__init__.py +++ b/src/dnsbl/__init__.py @@ -19,12 +19,21 @@ ############################################################################### 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 index 0000000..2c06426 --- /dev/null +++ b/src/dnsbl/logger.py @@ -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 . # +# # +############################################################################### + +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) diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in index 0c0023e..f1f7a6c 100644 --- a/src/scripts/dnsbl.in +++ b/src/scripts/dnsbl.in @@ -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()