diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 59746cacd..000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,49 +0,0 @@ - -### Issue type -[ ] Feature request -[ ] Bug report -[ ] Documentation -[ ] Housekeeping - - -### Environment -* Python version: -* NetBox version: - - -### Description diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 000000000..4bf6fb9c6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: 🐛 Bug Report +about: Report a reproducible bug in the current release of NetBox + +--- + + +### Environment +* Python version: +* NetBox version: + + +### Steps to Reproduce + + + +### Expected Behavior + + + +### Observed Behavior diff --git a/.github/ISSUE_TEMPLATE/documentation_change.md b/.github/ISSUE_TEMPLATE/documentation_change.md new file mode 100644 index 000000000..408beef44 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation_change.md @@ -0,0 +1,18 @@ +--- +name: 📖 Documentation Change +about: Suggest an addition or modification to the NetBox documentation + +--- + + +### Change Type +[ ] Addition +[ ] Correction +[ ] Deprecation +[ ] Cleanup (formatting, typos, etc.) + + +### Proposed Changes diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 000000000..ebe19d811 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,54 @@ +--- +name: ✨ Feature Request +about: Propose a new NetBox feature or enhancement + +--- + + +### Environment +* Python version: +* NetBox version: + + +### Proposed Functionality + + + +### Use Case + + + +### Database Changes + + + +### External Dependencies diff --git a/.github/ISSUE_TEMPLATE/housekeeping.md b/.github/ISSUE_TEMPLATE/housekeeping.md new file mode 100644 index 000000000..e03ae63a2 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/housekeeping.md @@ -0,0 +1,17 @@ +--- +name: 🏡 Housekeeping +about: A change pertaining to the codebase itself + +--- + + +### Proposed Changes + + + +### Justification diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index 2d6ec11a4..948622548 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -203,17 +203,35 @@ class RIRTable(BaseTable): class RIRDetailTable(RIRTable): - stats_total = tables.Column(accessor='stats.total', verbose_name='Total', - footer=lambda table: sum(r.stats['total'] for r in table.data)) - stats_active = tables.Column(accessor='stats.active', verbose_name='Active', - footer=lambda table: sum(r.stats['active'] for r in table.data)) - stats_reserved = tables.Column(accessor='stats.reserved', verbose_name='Reserved', - footer=lambda table: sum(r.stats['reserved'] for r in table.data)) - stats_deprecated = tables.Column(accessor='stats.deprecated', verbose_name='Deprecated', - footer=lambda table: sum(r.stats['deprecated'] for r in table.data)) - stats_available = tables.Column(accessor='stats.available', verbose_name='Available', - footer=lambda table: sum(r.stats['available'] for r in table.data)) - utilization = tables.TemplateColumn(template_code=RIR_UTILIZATION, verbose_name='Utilization') + stats_total = tables.Column( + accessor='stats.total', + verbose_name='Total', + footer=lambda table: sum(r.stats['total'] for r in table.data) + ) + stats_active = tables.Column( + accessor='stats.active', + verbose_name='Active', + footer=lambda table: sum(r.stats['active'] for r in table.data) + ) + stats_reserved = tables.Column( + accessor='stats.reserved', + verbose_name='Reserved', + footer=lambda table: sum(r.stats['reserved'] for r in table.data) + ) + stats_deprecated = tables.Column( + accessor='stats.deprecated', + verbose_name='Deprecated', + footer=lambda table: sum(r.stats['deprecated'] for r in table.data) + ) + stats_available = tables.Column( + accessor='stats.available', + verbose_name='Available', + footer=lambda table: sum(r.stats['available'] for r in table.data) + ) + utilization = tables.TemplateColumn( + template_code=RIR_UTILIZATION, + verbose_name='Utilization' + ) class Meta(RIRTable.Meta): fields = ( diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index e861db1f2..681dbfef7 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -189,9 +189,15 @@ class RIRListView(ObjectListView): queryset = Prefix.objects.filter(prefix__net_contained_or_equal=str(aggregate.prefix)) # Find all consumed space for each prefix status (we ignore containers for this purpose). - active_prefixes = netaddr.cidr_merge([p.prefix for p in queryset.filter(status=PREFIX_STATUS_ACTIVE)]) - reserved_prefixes = netaddr.cidr_merge([p.prefix for p in queryset.filter(status=PREFIX_STATUS_RESERVED)]) - deprecated_prefixes = netaddr.cidr_merge([p.prefix for p in queryset.filter(status=PREFIX_STATUS_DEPRECATED)]) + active_prefixes = netaddr.cidr_merge( + [p.prefix for p in queryset.filter(status=PREFIX_STATUS_ACTIVE)] + ) + reserved_prefixes = netaddr.cidr_merge( + [p.prefix for p in queryset.filter(status=PREFIX_STATUS_RESERVED)] + ) + deprecated_prefixes = netaddr.cidr_merge( + [p.prefix for p in queryset.filter(status=PREFIX_STATUS_DEPRECATED)] + ) # Find all available prefixes by subtracting each of the existing prefix sets from the aggregate prefix. available_prefixes = ( @@ -202,11 +208,11 @@ class RIRListView(ObjectListView): ) # Add the size of each metric to the RIR total. - stats['total'] += aggregate.prefix.size / denominator - stats['active'] += netaddr.IPSet(active_prefixes).size / denominator - stats['reserved'] += netaddr.IPSet(reserved_prefixes).size / denominator - stats['deprecated'] += netaddr.IPSet(deprecated_prefixes).size / denominator - stats['available'] += available_prefixes.size / denominator + stats['total'] += int(aggregate.prefix.size / denominator) + stats['active'] += int(netaddr.IPSet(active_prefixes).size / denominator) + stats['reserved'] += int(netaddr.IPSet(reserved_prefixes).size / denominator) + stats['deprecated'] += int(netaddr.IPSet(deprecated_prefixes).size / denominator) + stats['available'] += int(available_prefixes.size / denominator) # Calculate the percentage of total space for each prefix status. total = float(stats['total']) @@ -226,20 +232,6 @@ class RIRListView(ObjectListView): return rirs - def extra_context(self): - - totals = { - 'total': sum([rir.stats['total'] for rir in self.queryset]), - 'active': sum([rir.stats['active'] for rir in self.queryset]), - 'reserved': sum([rir.stats['reserved'] for rir in self.queryset]), - 'deprecated': sum([rir.stats['deprecated'] for rir in self.queryset]), - 'available': sum([rir.stats['available'] for rir in self.queryset]), - } - - return { - 'totals': totals, - } - class RIRCreateView(PermissionRequiredMixin, ObjectEditView): permission_required = 'ipam.add_rir' diff --git a/netbox/netbox/urls.py b/netbox/netbox/urls.py index 970c8a728..d23e2d64e 100644 --- a/netbox/netbox/urls.py +++ b/netbox/netbox/urls.py @@ -80,3 +80,5 @@ if settings.DEBUG: urlpatterns = [ url(r'^{}'.format(settings.BASE_PATH), include(_patterns)) ] + +handler500 = 'utilities.views.server_error' diff --git a/netbox/project-static/css/base.css b/netbox/project-static/css/base.css index 52656a505..6222a477d 100644 --- a/netbox/project-static/css/base.css +++ b/netbox/project-static/css/base.css @@ -376,12 +376,19 @@ table.reports td.method { font-family: monospace; padding-left: 30px; } -table.reports td.stats label { +td.report-stats label { display: inline-block; line-height: 14px; margin-bottom: 0; min-width: 40px; } +table.report th { + position: relative; +} +table.report th a { + position: absolute; + top: -51px; +} /* AJAX loader */ .loading { diff --git a/netbox/templates/extras/report.html b/netbox/templates/extras/report.html index 050d6e445..92753e23b 100644 --- a/netbox/templates/extras/report.html +++ b/netbox/templates/extras/report.html @@ -29,63 +29,73 @@

{{ report.description }}

{% endif %} {% if report.result %} -

Last run: {{ report.result.created }}

- {% else %} -

Last run: Never

+

Last run: {{ report.result.created }}

{% endif %} - -
{% if report.result %} - - - - - - - - - - {% for method, data in report.result.data.items %} - - - - {% for time, level, obj, url, message in data.log %} - - -
TimeLevelObjectMessage
{{ method }}
{{ time }} - +
+
+ Report Methods +
+ + {% for method, data in report.result.data.items %} + + + - - {% endfor %} - {% endfor %} -
{{ method }} + + + + - {% if obj and url %} - {{ obj }} - {% elif obj %} - {{ obj }} - {% endif %} - {{ message }}
+
+
+
+
+ Report Results +
+ + + + + + + + + + + {% for method, data in report.result.data.items %} + + + + {% for time, level, obj, url, message in data.log %} + + + + + + + {% endfor %} + {% endfor %} + +
TimeLevelObjectMessage
+ {{ method }} +
{{ time }} + + + {% if obj and url %} + {{ obj }} + {% elif obj %} + {{ obj }} + {% endif %} + {{ message }}
+
{% else %}
No results are available for this report. Please run the report first.
{% endif %}
{% if report.result %} -
-
- Methods -
- -
{% endif %}
diff --git a/netbox/templates/extras/report_list.html b/netbox/templates/extras/report_list.html index 1d6fbb72e..7d2f8a2e2 100644 --- a/netbox/templates/extras/report_list.html +++ b/netbox/templates/extras/report_list.html @@ -38,7 +38,7 @@ {{ method }} - + @@ -69,7 +69,7 @@ {{ report.name }}
- {% include 'extras/inc/report_label.html' %} + {% include 'extras/inc/report_label.html' with result=report.result %}
{% endfor %} diff --git a/netbox/utilities/middleware.py b/netbox/utilities/middleware.py index 47fa48c90..dafafde24 100644 --- a/netbox/utilities/middleware.py +++ b/netbox/utilities/middleware.py @@ -5,9 +5,10 @@ import sys from django.conf import settings from django.db import ProgrammingError from django.http import Http404, HttpResponseRedirect -from django.shortcuts import render from django.urls import reverse +from .views import server_error + BASE_PATH = getattr(settings, 'BASE_PATH', False) LOGIN_REQUIRED = getattr(settings, 'LOGIN_REQUIRED', False) @@ -65,23 +66,19 @@ class ExceptionHandlingMiddleware(object): if isinstance(exception, Http404): return - # Determine the type of exception + # Determine the type of exception. If it's a common issue, return a custom error page with instructions. + custom_template = None if isinstance(exception, ProgrammingError): - template_name = 'exceptions/programming_error.html' + custom_template = 'exceptions/programming_error.html' elif isinstance(exception, ImportError): - template_name = 'exceptions/import_error.html' + custom_template = 'exceptions/import_error.html' elif ( sys.version_info[0] >= 3 and isinstance(exception, PermissionError) ) or ( isinstance(exception, OSError) and exception.errno == 13 ): - template_name = 'exceptions/permission_error.html' - else: - template_name = '500.html' + custom_template = 'exceptions/permission_error.html' - # Return an error message - type_, error, traceback = sys.exc_info() - return render(request, template_name, { - 'exception': str(type_), - 'error': error, - }, status=500) + # Return a custom error message, or fall back to Django's default 500 error handling + if custom_template: + return server_error(request, template_name=custom_template) diff --git a/netbox/utilities/views.py b/netbox/utilities/views.py index f27838bdd..ee01b5ef9 100644 --- a/netbox/utilities/views.py +++ b/netbox/utilities/views.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from collections import OrderedDict from copy import deepcopy +import sys from django.conf import settings from django.contrib import messages @@ -10,12 +11,16 @@ from django.core.exceptions import ValidationError from django.db import transaction, IntegrityError from django.db.models import Count, ProtectedError from django.forms import CharField, Form, ModelMultipleChoiceField, MultipleHiddenInput, Textarea +from django.http import HttpResponseServerError from django.shortcuts import get_object_or_404, redirect, render -from django.template.exceptions import TemplateSyntaxError +from django.template import loader +from django.template.exceptions import TemplateDoesNotExist, TemplateSyntaxError from django.urls import reverse from django.utils.html import escape from django.utils.http import is_safe_url from django.utils.safestring import mark_safe +from django.views.decorators.csrf import requires_csrf_token +from django.views.defaults import ERROR_500_TEMPLATE_NAME from django.views.generic import View from django_tables2 import RequestConfig @@ -844,3 +849,20 @@ class BulkComponentCreateView(GetReturnURLMixin, View): 'table': table, 'return_url': self.get_return_url(request), }) + + +@requires_csrf_token +def server_error(request, template_name=ERROR_500_TEMPLATE_NAME): + """ + Custom 500 handler to provide additional context when rendering 500.html. + """ + try: + template = loader.get_template(template_name) + except TemplateDoesNotExist: + return HttpResponseServerError('

Server Error (500)

', content_type='text/html') + type_, error, traceback = sys.exc_info() + + return HttpResponseServerError(template.render({ + 'exception': str(type_), + 'error': error, + }))