]> git.ipfire.org Git - dbl.git/commitdiff
exporters: Use the tarball exporter to write Suricata rules
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Jan 2026 18:31:37 +0000 (18:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 5 Jan 2026 18:31:37 +0000 (18:31 +0000)
That way, we will always compress them as they are rather large to be
downloaded as plaintext.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/exporters.py

index 21b99bf9cb911fce24518d44e867234f40c344ab..5de5722ae937801ef4d13862201511c957526683 100644 (file)
@@ -415,7 +415,7 @@ class SquidGuardExporter(TarballExporter):
        }
 
 
-class SuricataExporter(TextExporter):
+class SuricataRulesExporter(TextExporter):
        """
                Export domains as a set of rules for Suricata
        """
@@ -486,7 +486,7 @@ class SuricataExporter(TextExporter):
                return h
 
 
-class SuricataDNSExporter(SuricataExporter):
+class SuricataDNSExporter(SuricataRulesExporter):
        """
                Exports the lists as a Suricata ruleset that filters DNS queries.
        """
@@ -505,7 +505,7 @@ class SuricataDNSExporter(SuricataExporter):
        )
 
 
-class SuricataHTTPExporter(SuricataExporter):
+class SuricataHTTPExporter(SuricataRulesExporter):
        """
                Exports the lists as a Suricata ruleset that filters HTTP requests.
        """
@@ -524,7 +524,7 @@ class SuricataHTTPExporter(SuricataExporter):
        )
 
 
-class SuricataTLSExporter(SuricataExporter):
+class SuricataTLSExporter(SuricataRulesExporter):
        """
                Exports the lists as a Suricata ruleset that filters TLS connections.
        """
@@ -543,7 +543,7 @@ class SuricataTLSExporter(SuricataExporter):
        )
 
 
-class SuricataQUICExporter(SuricataExporter):
+class SuricataQUICExporter(SuricataRulesExporter):
        """
                Exports the lists as a Suricata ruleset that filters QUIC connections.
        """
@@ -562,6 +562,18 @@ class SuricataQUICExporter(SuricataExporter):
        )
 
 
+class SuricataExporter(TarballExporter):
+       """
+               Export a list in the format that squidguard can process it
+       """
+       files = {
+               "%(list)s-dns.rules"  : SuricataDNSExporter,
+               "%(list)s-http.rules" : SuricataHTTPExporter,
+               "%(list)s-tls.rules"  : SuricataTLSExporter,
+               "%(list)s-quic.rules" : SuricataQUICExporter,
+       }
+
+
 class MultiExporter(abc.ABC):
        """
                This is a base class that can export multiple lists at the same time
@@ -614,9 +626,8 @@ class CombinedSuricataExporter(MultiExporter):
                # Create a tar file
                with tarfile.open(fileobj=f, mode="w|gz") as tarball:
                        for list in self.lists:
-                               for file, exporter in self.files.items():
-                                       e = exporter(self.backend, list)
-                                       e.export_to_tarball(tarball, file)
+                               exporter = SuricataExporter(self.backend, list)
+                               exporter(tarball)
 
 
 class DirectoryExporter(MultiExporter):