From: Michael Tremer Date: Tue, 30 Dec 2025 14:38:08 +0000 (+0000) Subject: dnsbl: Add a page to show any pending reports X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cce67fdb801f0781ad8634ba94614b45b090c46;p=ipfire.org.git dnsbl: Add a page to show any pending reports Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 20327fc4..68db2c29 100644 --- a/Makefile.am +++ b/Makefile.am @@ -190,6 +190,7 @@ templates_dnsbldir = $(templatesdir)/dnsbl templates_dnsbl_lists_DATA = \ src/templates/dnsbl/lists/index.html \ + src/templates/dnsbl/lists/reports.html \ src/templates/dnsbl/lists/show.html templates_dnsbl_listsdir = $(templates_dnsbldir)/lists diff --git a/src/backend/dnsbl.py b/src/backend/dnsbl.py index 018f5cf9..0a242231 100644 --- a/src/backend/dnsbl.py +++ b/src/backend/dnsbl.py @@ -17,15 +17,20 @@ from .decorators import * log = logging.getLogger(__name__) class DNSBL(Object): - async def _fetch(self, path, headers=None, body=None, **kwargs): + async def _fetch(self, path, headers=None, args=None, body=None, **kwargs): if headers is None: headers = {} + # Format the URL url = urllib.parse.urljoin( #"https://api.dnsbl.ipfire.org", "http://dnsbl01.haj.ipfire.org:8000", path, ) + # Append any query arguments to the URL + if args: + url = "%s?%s" % (url, urllib.parse.urlencode(args)) + # Authenticate headers |= { "X-API-Key" : self.backend.settings.get("dnsbl-api-key", ""), @@ -159,6 +164,21 @@ class List(Model): return [Source(self._backend, **data) for data in response] + # Reports + + async def get_reports(self, open=None, limit=None): + args = { + "open" : open, + "limit" : limit, + } + + # Send the request + response = await self._backend.dnsbl._fetch( + "/lists/%s/reports" % self.slug, args=args, + ) + + return [Report(self._backend, **data) for data in response] + # Report! async def report(self, name, reported_by, comment=None, block=True): """ diff --git a/src/templates/dnsbl/lists/reports.html b/src/templates/dnsbl/lists/reports.html new file mode 100644 index 00000000..988d4310 --- /dev/null +++ b/src/templates/dnsbl/lists/reports.html @@ -0,0 +1,111 @@ +{% extends "../../base.html" %} + +{% block head %} + {% module OpenGraph( + title=_("IPFire DNSBL - %s - Reports") % list, + description=list.description, + ) %} +{% end block %} + +{% block title %}{{ _("IPFire DNSBL") }} - {{ list }} - {{ _("Reports") }}{% end block %} + +{% block container %} +
+
+
+ + +

+ {{ _("Reports: %s") % list }} +

+
+
+
+ +
+
+

+ {{ _("Pending Reports") }} +

+ + {# Show any pending reports #} + {% if reports %} + {% for report in reports %} +
+
+
+
+

+ + {{ report }} + +

+ +

+ {{ _("Submitted %(when)s by %(who)s") % { + "when" : locale.format_date(report.reported_at), + "who" : report.reported_by, + } }} +

+
+ + {# Comment #} + {% if report.comment %} +
+
{{ report.comment }}
+
+ {% end %} +
+
+
+ {% end %} + + {# Show a note if we don't have any pending reports #} + {% else %} +
+ {{ _("There are currently no pending reports for this list") }} +
+ {% end %} +
+
+ +
+
+
+ {{ _("See Something? Say Something") }} +
+ +
+ Spot something that should be listed? Send it our way. +
+ + + {{ _("Submit a Report") }} + +
+
+{% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index f80678f7..0305ea1b 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -217,6 +217,7 @@ class Application(tornado.web.Application): (r"/dnsbl/?", StaticHandler, { "template" : "dnsbl/index.html" }), (r"/dnsbl/lists", dnsbl.ListsHandler), (r"/dnsbl/lists/(\w+)", dnsbl.ListHandler), + (r"/dnsbl/lists/(\w+)/reports", dnsbl.ListReportsHandler), (r"/dnsbl/report", dnsbl.SubmitReportHandler), (r"/dnsbl/reports/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})", dnsbl.ReportHandler), diff --git a/src/web/dnsbl.py b/src/web/dnsbl.py index 59e0d03b..a9821df2 100644 --- a/src/web/dnsbl.py +++ b/src/web/dnsbl.py @@ -31,8 +31,25 @@ class ListHandler(base.AnalyticsMixin, BaseHandler): # Fetch the sources sources = await list.get_sources() + # Fetch some recent reports + reports = await list.get_reports(limit=25) + + # Render the page + self.render("dnsbl/lists/show.html", list=list, sources=sources, reports=reports) + + +class ListReportsHandler(base.AnalyticsMixin, BaseHandler): + async def get(self, slug): + # Fetch the list + list = await self.backend.dnsbl.get_list(slug) + if not list: + raise tornado.web.HTTPError(404, "Could not find list '%s'" % slug) + + # Fetch some recent reports + reports = await list.get_reports(limit=25) + # Render the page - self.render("dnsbl/lists/show.html", list=list, sources=sources) + self.render("dnsbl/lists/reports.html", list=list, reports=reports) class SubmitReportHandler(base.AnalyticsMixin, BaseHandler):