]> git.ipfire.org Git - dbl.git/commitdiff
lists: Add a priority which is exported to Suricata
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Jan 2026 11:11:17 +0000 (11:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Jan 2026 11:11:17 +0000 (11:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.sql
src/dnsbl/exporters.py
src/dnsbl/lists.py
src/scripts/dnsbl.in

index be5db53bf303084b7cfb0b2382d6deaa5fb4fb81..88943f1eec97853fe3037efb32cbc234881159cf 100644 (file)
@@ -2,7 +2,7 @@
 -- PostgreSQL database dump
 --
 
-\restrict 0x0tldyHgIUyWxgnGUGi115yWYckW02ZTvAqVYxdprpqc4kMhzpMBPkpIKiHQLO
+\restrict 1diYTcUdWXmrci8nOPBU0L49Gy6AtiuIiTy0rir4PbAGglPIHU607lYZcp7rwvf
 
 -- Dumped from database version 17.6 (Debian 17.6-0+deb13u1)
 -- Dumped by pg_dump version 17.6 (Debian 17.6-0+deb13u1)
@@ -157,7 +157,8 @@ CREATE TABLE public.lists (
     updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
     description text,
     total_domains integer DEFAULT 0 NOT NULL,
-    pending_reports integer DEFAULT 0 NOT NULL
+    pending_reports integer DEFAULT 0 NOT NULL,
+    priority integer DEFAULT 0 NOT NULL
 );
 
 
@@ -587,5 +588,5 @@ ALTER TABLE ONLY public.sources
 -- PostgreSQL database dump complete
 --
 
-\unrestrict 0x0tldyHgIUyWxgnGUGi115yWYckW02ZTvAqVYxdprpqc4kMhzpMBPkpIKiHQLO
+\unrestrict 1diYTcUdWXmrci8nOPBU0L49Gy6AtiuIiTy0rir4PbAGglPIHU607lYZcp7rwvf
 
index 4970dcfebd2ace3feed5d7298b51acfd11a7cfcc..26fbe463e214c0c76249b863e51825793510048c 100644 (file)
@@ -423,13 +423,23 @@ class SuricataRulesExporter(TextExporter):
                # Write the header
                self.write_header(f)
 
-               # XXX Maybe we should look into having different priority for different lists.
-               # For example, blocking some advertising has a lower priority than accessing
-               # a malware/phishing domain.
-
                # Shift the ID of the list to the higher 16 bits and append the offset
                sid = self.list.id << 16
 
+               # Map the priority
+               # High Priority
+               if self.list.priority == 3:
+                       priority = 1
+               # Medium Priority
+               elif self.list.priority == 2:
+                       priority = 2
+               # Low Priority
+               elif self.list.priority == 1:
+                       priority = 3
+               # Informational
+               else:
+                       priority = 4
+
                rules = {
                        # DNS
                        "dns" : {
@@ -443,7 +453,7 @@ class SuricataRulesExporter(TextExporter):
                                        "load datasets/%s.txt" % self.list.slug,
                                ),
                                "classtype" : "policy-violation",
-                               "priority"  : "3",
+                               "priority"  : priority,
                                "sid"       : sid | 1,
                                "rev"       : "1",
                                "reference" : (
@@ -467,7 +477,7 @@ class SuricataRulesExporter(TextExporter):
                                        "load datasets/%s.txt" % self.list.slug,
                                ),
                                "classtype" : "policy-violation",
-                               "priority"  : "3",
+                               "priority"  : priority,
                                "sid"       : sid | 2,
                                "rev"       : "1",
                                "reference" : (
@@ -491,7 +501,7 @@ class SuricataRulesExporter(TextExporter):
                                        "load datasets/%s.txt" % self.list.slug,
                                ),
                                "classtype" : "policy-violation",
-                               "priority"  : "3",
+                               "priority"  : priority,
                                "sid"       : sid | 3,
                                "rev"       : "1",
                                "reference" : (
@@ -515,7 +525,7 @@ class SuricataRulesExporter(TextExporter):
                                        "load datasets/%s.txt" % self.list.slug,
                                ),
                                "classtype" : "policy-violation",
-                               "priority"  : "3",
+                               "priority"  : priority,
                                "sid"       : sid | 4,
                                "rev"       : "1",
                                "reference" : (
index f192edac904ead5dfe1af9cadcc18742fcc7cea1..5601840a640e652590442b17f8ef9ba106c695a7 100644 (file)
@@ -39,6 +39,13 @@ from .i18n import _
 # Setup logging
 log = logging.getLogger(__name__)
 
+PRIORITIES = {
+       "INFORMATIONAL" : 0,
+       "LOW"           : 1,
+       "MEDIUM"        : 2,
+       "HIGH"          : 3,
+}
+
 class Lists(object):
        def __init__(self, backend):
                self.backend = backend
@@ -90,12 +97,18 @@ class Lists(object):
 
                        return slug
 
-       def create(self, name, created_by, license, description=None):
+       def create(self, name, created_by, license, description=None, priority=None):
                """
                        Creates a new list
                """
                slug = self._make_slug(name)
 
+               # Map priority
+               try:
+                       priority = PRIORITIES[priority]
+               except KeyError as e:
+                       raise ValueError("Invalid priority: %s" % priority) from e
+
                # Create a new list
                return self.backend.db.insert(
                        List,
@@ -104,6 +117,7 @@ class Lists(object):
                        created_by  = created_by,
                        license     = license,
                        description = description,
+                       priority    = priority,
                )
 
 
@@ -155,6 +169,9 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
        # Description
        description : str
 
+       # Priority
+       priority: int = 0
+
        # Sources
        sources : typing.List["Source"] = sqlmodel.Relationship(
                back_populates="list",
index 94d9a660306ec2875dd814227085b439e6ba233a..5136103956786a20470e5c64f7143f484e5b0053 100644 (file)
@@ -78,6 +78,8 @@ class CLI(object):
                                help=_("The license of the list"))
                create.add_argument("--description",
                                help=_("The description of the list"))
+               create.add_argument("--priority", choices=dnsbl.lists.PRIORITIES,
+                               help=_("The priority of this list"), default="INFORMATIONAL")
                create.set_defaults(func=self.__create)
 
                # delete
@@ -290,6 +292,7 @@ class CLI(object):
                        created_by  = args.created_by,
                        license     = args.license,
                        description = args.description,
+                       priority    = args.priority,
                )
 
        def __delete(self, backend, args):