]> git.ipfire.org Git - dbl.git/commitdiff
dnsbl: Implement forcing a list update
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Dec 2025 10:20:11 +0000 (10:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 22 Dec 2025 10:20:11 +0000 (10:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dnsbl/lists.py
src/dnsbl/sources.py
src/scripts/dnsbl.in

index 24001da13b708d25fe162e263742411c379fccba..595aa67817a954971edfcaa2397a9e2812ec81bf 100644 (file)
@@ -260,7 +260,7 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
        # Update!
 
-       def update(self):
+       def update(self, **kwargs):
                """
                        Updates the list
                """
@@ -269,7 +269,7 @@ class List(sqlmodel.SQLModel, database.BackendMixin, table=True):
 
                        # Update all sources
                        for source in self.sources:
-                               if source.update():
+                               if source.update(**kwargs):
                                        updated = True
 
                        # Update the timestamp if at least one source has actually fetched new data
index 7edef262f2d066124e4cf16ce4521a9976127b38..77f510211a9f40675b255879b41c9d84d85ac23e 100644 (file)
@@ -158,7 +158,7 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
                # Log action
                log.info(_("Source '%s' has been deleted from '%s'") % (self, self.list))
 
-       def update(self):
+       def update(self, force=False):
                """
                        Updates this source.
                """
@@ -173,7 +173,7 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
                with self.db.transaction():
                        with self.backend.client() as client:
                                # Compose some request headers
-                               headers = self._make_headers()
+                               headers = self._make_headers(force=force)
 
                                with client.stream("GET", self.url, headers=headers) as response:
                                        # Parse the response headers
@@ -242,20 +242,21 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
                # Signal that we have actually fetched new data
                return True
 
-       def _make_headers(self):
+       def _make_headers(self, force=False):
                """
                        Creates some headers we will send with the request.
                """
                headers = {}
 
-               # Send If-Modified-Since so that we won't re-import the same list
-               if self.last_modified_at:
-                       headers["If-Modified-Since"] = \
-                               self.last_modified_at.strftime("%a, %d %b %Y %H:%M:%S GMT")
+               if not force:
+                       # Send If-Modified-Since so that we won't re-import the same list
+                       if self.last_modified_at:
+                               headers["If-Modified-Since"] = \
+                                       self.last_modified_at.strftime("%a, %d %b %Y %H:%M:%S GMT")
 
-               # If we don't have the timestamp, we will send the ETag
-               elif self.etag:
-                       headers["If-None-Match"] = self.etag
+                       # If we don't have the timestamp, we will send the ETag
+                       elif self.etag:
+                               headers["If-None-Match"] = self.etag
 
                return headers
 
index e7ca4c6e490710dd972f4208832e2818695709ec..bcd4596f4cb156ee04c3ab2a99c79b2b53d91499 100644 (file)
@@ -93,6 +93,7 @@ class CLI(object):
                # update
                update = subparsers.add_parser("update", help=_("Updates a list"))
                update.add_argument("list", help=_("The name of the list"))
+               update.add_argument("--force", action="store_true", help=_("Force an update"))
                update.set_defaults(func=self.__update)
 
                # update-all
@@ -279,7 +280,7 @@ class CLI(object):
                list = backend.lists.get_by_slug(args.list)
 
                # Update!
-               list.update()
+               list.update(force=args.force)
 
        def __update_all(self, backend, args):
                """