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
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", ""),
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):
"""
--- /dev/null
+{% 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 %}
+ <section class="hero is-dark">
+ <div class="hero-body">
+ <div class="container">
+ <nav class="breadcrumb" aria-label="breadcrumbs">
+ <ul>
+ <li>
+ <a href="/dnsbl">
+ {{ _("IPFire DNSBL") }}
+ </a>
+ </li>
+
+ <li>
+ <a href="/dnsbl/lists">
+ {{ _("Lists") }}
+ </a>
+ </li>
+
+ <li>
+ <a href="/dnsbl/lists/{{ list.slug }}">
+ {{ list }}
+ </a>
+ </li>
+
+ <li class="is-active">
+ <a href="#" aria-current="page">{{ _("Reports") }}</a>
+ </li>
+ </ul>
+ </nav>
+
+ <h1 class="title">
+ {{ _("Reports: %s") % list }}
+ </h1>
+ </div>
+ </div>
+ </section>
+
+ <section class="section">
+ <div class="container">
+ <h3 class="title is-3">
+ {{ _("Pending Reports") }}
+ </h3>
+
+ {# Show any pending reports #}
+ {% if reports %}
+ {% for report in reports %}
+ <div class="card">
+ <div class="card-content">
+ <div class="columns">
+ <div class="column">
+ <p class="title is-5">
+ <a href="/dnsbl/reports/{{ report.id }}">
+ {{ report }}
+ </a>
+ </p>
+
+ <p class="subtitle is-6">
+ {{ _("Submitted %(when)s by %(who)s") % {
+ "when" : locale.format_date(report.reported_at),
+ "who" : report.reported_by,
+ } }}
+ </p>
+ </div>
+
+ {# Comment #}
+ {% if report.comment %}
+ <div class="column">
+ <pre>{{ report.comment }}</pre>
+ </div>
+ {% end %}
+ </div>
+ </div>
+ </div>
+ {% end %}
+
+ {# Show a note if we don't have any pending reports #}
+ {% else %}
+ <div class="notification has-text-centered">
+ {{ _("There are currently no pending reports for this list") }}
+ </div>
+ {% end %}
+ </div>
+ </section>
+
+ <section class="section">
+ <div class="container">
+ <h5 class="title is-5">
+ {{ _("See Something? Say Something") }}
+ </h5>
+
+ <div class="content">
+ Spot something that should be listed? Send it our way.
+ </div>
+
+ <a class="button is-primary" href="/dnsbl/report">
+ {{ _("Submit a Report") }}
+ </a>
+ </div>
+ </section>
+{% end block %}
(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),
# 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):