From 9f71ff73324665008611e09d1398163705428d85 Mon Sep 17 00:00:00 2001 From: Sven Luethi Date: Tue, 11 Aug 2026 17:22:14 +0200 Subject: [PATCH] modified: netbox_dns_bridge/navigation.py new file: netbox_dns_bridge/templates/netbox_dns_bridge/catz_overview.html deleted: netbox_dns_bridge/templates/netbox_dns_bridge/info.html new file: netbox_dns_bridge/templates/netbox_dns_bridge/notify_overview.html modified: netbox_dns_bridge/urls.py modified: netbox_dns_bridge/views.py Extend views --- netbox_dns_bridge/navigation.py | 16 +++- .../netbox_dns_bridge/catz_overview.html | 68 ++++++++++++++ .../templates/netbox_dns_bridge/info.html | 89 ------------------- .../netbox_dns_bridge/notify_overview.html | 37 ++++++++ netbox_dns_bridge/urls.py | 5 +- netbox_dns_bridge/views.py | 54 +++++++---- 6 files changed, 157 insertions(+), 112 deletions(-) create mode 100644 netbox_dns_bridge/templates/netbox_dns_bridge/catz_overview.html delete mode 100644 netbox_dns_bridge/templates/netbox_dns_bridge/info.html create mode 100644 netbox_dns_bridge/templates/netbox_dns_bridge/notify_overview.html diff --git a/netbox_dns_bridge/navigation.py b/netbox_dns_bridge/navigation.py index 747a952..79a8ae4 100644 --- a/netbox_dns_bridge/navigation.py +++ b/netbox_dns_bridge/navigation.py @@ -1,16 +1,24 @@ from django.utils.translation import gettext_lazy as _ from netbox.plugins import PluginMenu, PluginMenuItem -info_menu_item = PluginMenuItem( - link="plugins:netbox_dns_bridge:info", - link_text=_("Info"), +information_menu_item = PluginMenuItem( + link="plugins:netbox_dns_bridge:catz", + link_text=_("Catalog Zones"), permissions=[], + staff_only=True, +) + +notify_menu_item = PluginMenuItem( + link="plugins:netbox_dns_bridge:notify", + link_text=_("Notify"), + permissions=[], + staff_only=True, ) menu = PluginMenu( label=_("DNS Bridge"), groups=( - (_("Information"), (info_menu_item,)), + (_("Information"), (information_menu_item, notify_menu_item)), ), icon_class="mdi mdi-bridge", ) diff --git a/netbox_dns_bridge/templates/netbox_dns_bridge/catz_overview.html b/netbox_dns_bridge/templates/netbox_dns_bridge/catz_overview.html new file mode 100644 index 0000000..fe2554b --- /dev/null +++ b/netbox_dns_bridge/templates/netbox_dns_bridge/catz_overview.html @@ -0,0 +1,68 @@ +{% extends 'base/layout.html' %} + +{% block title %}Catalog Zone Info{% endblock %} + +{% block content %} +
+
+ +
+
Catalog Zone SOA Serial Number
+
+ + + + + + + + {% if soa_serial is not None %} + + + + {% else %} + + {% endif %} + +
Value
{{ soa_serial }}
Not yet initialized.
+
+
+ + {% for view_name, rows in zones_grouped.items %} +
+
Zone Identifiers | {{ view_name }}
+
+ + + + + + + + + + {% for z in rows %} + + + + + + {% empty %} + + {% endfor %} + +
ZoneActiveCatalog Zone Identifier
{{ z.name }}{{ z.active|yesno:"Yes,No" }}{{ z.catz_identifier|default:"—" }}
No zones in this view.
+
+
+ {% empty %} +
+
Zone Identifiers
+
+

No zones found.

+
+
+ {% endfor %} + +
+
+{% endblock %} diff --git a/netbox_dns_bridge/templates/netbox_dns_bridge/info.html b/netbox_dns_bridge/templates/netbox_dns_bridge/info.html deleted file mode 100644 index 515d469..0000000 --- a/netbox_dns_bridge/templates/netbox_dns_bridge/info.html +++ /dev/null @@ -1,89 +0,0 @@ -{% extends 'base/layout.html' %} - -{% block title %}DNS Bridge Info{% endblock %} - -{% block content %} -
-
- -
-
Integer Key-Value Settings
-
- - - - - - - - - {% for s in settings_rows %} - - - - - {% empty %} - - {% endfor %} - -
KeyValue
{{ s.key }}{{ s.value }}
No settings found.
-
-
- -
-
Seen Transfer Clients
-
- - - - - - - - - - {% for c in seen_clients %} - - - - - - {% empty %} - - {% endfor %} - -
Source IPViewLast Seen
{{ c.source_ip }}{{ c.view.name }}{{ c.last_seen|date:"Y-m-d H:i:s" }}
No seen transfer clients.
-
-
- -
-
Zones & Catalog Zone Identifiers
-
- - - - - - - - - - - {% for z in zones %} - - - - - - - {% empty %} - - {% endfor %} - -
ZoneViewActiveCatalog Zone Identifier
{{ z.name }}{{ z.view|default:"—" }}{{ z.active|yesno:"Yes,No" }}{{ z.catz_identifier|default:"—" }}
No zones found.
-
-
- -
-
-{% endblock %} diff --git a/netbox_dns_bridge/templates/netbox_dns_bridge/notify_overview.html b/netbox_dns_bridge/templates/netbox_dns_bridge/notify_overview.html new file mode 100644 index 0000000..78c6a44 --- /dev/null +++ b/netbox_dns_bridge/templates/netbox_dns_bridge/notify_overview.html @@ -0,0 +1,37 @@ +{% extends 'base/layout.html' %} + +{% block title %}DNS Bridge Notify{% endblock %} + +{% block content %} +
+
+ +
+
Seen Transfer Clients
+
+ + + + + + + + + + {% for c in seen_clients %} + + + + + + {% empty %} + + {% endfor %} + +
Source IPViewLast Seen
{{ c.source_ip }}{{ c.view.name }}{{ c.last_seen|date:"Y-m-d H:i:s" }}
No seen transfer clients.
+
+
+ +
+
+{% endblock %} diff --git a/netbox_dns_bridge/urls.py b/netbox_dns_bridge/urls.py index 96b293c..207211c 100644 --- a/netbox_dns_bridge/urls.py +++ b/netbox_dns_bridge/urls.py @@ -1,7 +1,8 @@ from django.urls import path -from .views import InfoView +from .views import CatzOverviewView, NotifyOverviewView urlpatterns = [ - path("info/", InfoView.as_view(), name="info"), + path("catz/", CatzOverviewView.as_view(), name="catz"), + path("notify/", NotifyOverviewView.as_view(), name="notify"), ] diff --git a/netbox_dns_bridge/views.py b/netbox_dns_bridge/views.py index 830da2c..95834eb 100644 --- a/netbox_dns_bridge/views.py +++ b/netbox_dns_bridge/views.py @@ -1,43 +1,63 @@ -from django.views import View +from collections import OrderedDict + +from django.contrib.auth.decorators import user_passes_test from django.shortcuts import render +from django.utils.decorators import method_decorator +from django.views import View from .models import IntegerKeyValueSetting, SeenTransferClients -class InfoView(View): - template_name = "netbox_dns_bridge/info.html" +@method_decorator( + user_passes_test(lambda u: u.is_superuser), name="dispatch" +) +class CatzOverviewView(View): + template_name = "netbox_dns_bridge/catz_overview.html" def get(self, request): import netbox_dns.models - settings_rows = IntegerKeyValueSetting.objects.all().order_by("key") + soa_serial_obj = IntegerKeyValueSetting.objects.filter( + key="catalog-zone-soa-serial" + ).first() + soa_serial = soa_serial_obj.value if soa_serial_obj else None - seen_clients = ( - SeenTransferClients.objects.select_related("view") - .all() - .order_by("source_ip") - ) - - zones = [] + zones_grouped = OrderedDict() for z in netbox_dns.models.Zone.objects.select_related( "view", "catz_identifier" - ).order_by("name"): + ).order_by("view__name", "name"): + view_name = z.view.name if z.view else "" + view_display = view_name[0].upper() + view_name[1:] if view_name else "" try: catz_identifier = z.catz_identifier.name except netbox_dns.models.Zone.catz_identifier.RelatedObjectDoesNotExist: catz_identifier = None - zones.append( + zones_grouped.setdefault(view_display, []).append( { "name": z.name, - "view": z.view.name if z.view else None, "active": z.active, "catz_identifier": catz_identifier, } ) context = { - "settings_rows": settings_rows, - "seen_clients": seen_clients, - "zones": zones, + "soa_serial": soa_serial, + "zones_grouped": zones_grouped, } return render(request, self.template_name, context) + + +@method_decorator( + user_passes_test(lambda u: u.is_superuser), name="dispatch" +) +class NotifyOverviewView(View): + template_name = "netbox_dns_bridge/notify_overview.html" + + def get(self, request): + seen_clients = ( + SeenTransferClients.objects.select_related("view") + .all() + .order_by("source_ip") + ) + context = {"seen_clients": seen_clients} + return render(request, self.template_name, context)