From: Michael Tremer Date: Fri, 5 Dec 2025 14:16:14 +0000 (+0000) Subject: dnsbl: Create a basic Backend module and CLI util X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f00b09f9f1ff567cb446a2322252cb0a3bc5f93;p=dbl.git dnsbl: Create a basic Backend module and CLI util Signed-off-by: Michael Tremer --- diff --git a/.gitignore b/.gitignore index 31b2476..1db8edd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /Makefile /build-aux /missing +/src/scripts/dnsbl /tmp /*.tar.bz2 /*.tar.gz diff --git a/Makefile.am b/Makefile.am index 0fb9389..d5482f9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,3 +27,38 @@ AUTOMAKE_OPTIONS = color-tests # keep itermediate files .SECONDARY: + +CLEANFILES = +EXTRA_DIST = + +# ------------------------------------------------------------------------------ + +SED_PROCESS = \ + $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \ + -e 's,@PYTHON\@,$(PYTHON),g' \ + -e 's,@VERSION\@,$(VERSION),g' \ + -e 's,@prefix\@,$(prefix),g' \ + -e 's,@exec_prefix\@,$(exec_prefix),g' \ + -e 's,@bindir\@,$(bindir),g' \ + -e 's,@libdir\@,$(libdir),g' \ + < $< > $@ + +%: %.in Makefile + $(SED_PROCESS) + +# ------------------------------------------------------------------------------ + +dist_pkgpython_PYTHON = \ + src/dnsbl/__init__.py \ + src/dnsbl/i18n.py + +# ------------------------------------------------------------------------------ + +CLEANFILES += \ + src/scripts/dnsbl + +EXTRA_DIST += \ + src/scripts/dnsbl.in + +bin_SCRIPTS = \ + src/scripts/dnsbl diff --git a/configure.ac b/configure.ac index 540c878..4593a60 100644 --- a/configure.ac +++ b/configure.ac @@ -44,6 +44,11 @@ AM_SILENT_RULES([yes]) # ------------------------------------------------------------------------------ +AC_PROG_SED +AC_PROG_MKDIR_P + +# ------------------------------------------------------------------------------ + # Python AM_PATH_PYTHON([3.13]) diff --git a/src/dnsbl/__init__.py b/src/dnsbl/__init__.py new file mode 100644 index 0000000..463cc6a --- /dev/null +++ b/src/dnsbl/__init__.py @@ -0,0 +1,39 @@ +############################################################################### +# # +# 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 configparser + +class Backend(object): + def __init__(self, config=None): + # Parse the configuration file + self.config = self.parse_config(config) + + def parse_config(self, config=None): + """ + Reads the configuration file + """ + # Create a new configuration object + c = configparser.ConfigParser(interpolation=None) + + # Parse the file + if config: + c.read_file(config) + + return c diff --git a/src/dnsbl/i18n.py b/src/dnsbl/i18n.py new file mode 100644 index 0000000..a9a7ba5 --- /dev/null +++ b/src/dnsbl/i18n.py @@ -0,0 +1,27 @@ +############################################################################### +# # +# 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 gettext + +def _(singular, plural=None, n=None): + if plural: + return gettext.dngettext("dnsbl", singular, plural, n) + + return gettext.dgettext("dnsbl", singular) diff --git a/src/scripts/dnsbl.in b/src/scripts/dnsbl.in new file mode 100644 index 0000000..0c0023e --- /dev/null +++ b/src/scripts/dnsbl.in @@ -0,0 +1,71 @@ +#!@PYTHON@ +############################################################################### +# # +# 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 argparse +import dnsbl +import sys + +# i18n +from dnsbl.i18n import _ + +class CLI(object): + def parse_cli(self): + """ + Main Function. + """ + parser = argparse.ArgumentParser( + description=_("DNS Blocklist Command Line Interface"), + ) + subparsers = parser.add_subparsers() + + # Global Configuration Flags + parser.add_argument("--debug", action="store_true", help=_("Enable debug output")) + parser.add_argument("--config", + type=argparse.FileType("r"), help=_("Configuration File")) + + # Show Version + parser.add_argument("--version", action="version", version="%(prog)s @VERSION@") + + # Parse all arguments + args = parser.parse_args() + + # Print usage if no action was given + if not "func" in args: + parser.print_usage() + sys.exit(2) + + def run(self): + # Parse the command line + args = self.parse_cli() + + # XXX Configure logging + + # Initialize the backend + backend = dnsbl.Backend(args.config) + + # XXX TODO + +def main(): + c = CLI() + c.run() + +if __name__ == "__main__": + main()