]> git.ipfire.org Git - dbl.git/commitdiff
dnsbl: Create a basic Backend module and CLI util
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Dec 2025 14:16:14 +0000 (14:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Dec 2025 14:16:14 +0000 (14:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
configure.ac
src/dnsbl/__init__.py [new file with mode: 0644]
src/dnsbl/i18n.py [new file with mode: 0644]
src/scripts/dnsbl.in [new file with mode: 0644]

index 31b2476d1b1cc01f5979acb70fc791d3f87424b0..1db8edd62e6a75291265fa5fee3d814dd886ba4b 100644 (file)
@@ -1,6 +1,7 @@
 /Makefile
 /build-aux
 /missing
+/src/scripts/dnsbl
 /tmp
 /*.tar.bz2
 /*.tar.gz
index 0fb9389cd47e29b954d25bac6ea5a1cf72d671b4..d5482f9ae4f949e83fad7624acd16ff1b086adb8 100644 (file)
@@ -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
index 540c87849a70b21faf49e9d4d9ee8b7636301ff2..4593a60d6ba279f06452e7a27a05b818dd6d6c7d 100644 (file)
@@ -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 (file)
index 0000000..463cc6a
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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 (file)
index 0000000..a9a7ba5
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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 (file)
index 0000000..0c0023e
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+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()