###############################################################################
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
c.read_file(config)
return c
+
+ def update_sources(self):
+ """
+ Updates all sources
+ """
+ pass
--- /dev/null
+###############################################################################
+# #
+# 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)
import argparse
import dnsbl
+import logging
import sys
# i18n
# 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()
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()