diff --git a/manager/templatetags/notifications.py b/manager/templatetags/notifications.py index 753c5f2..9e62410 100644 --- a/manager/templatetags/notifications.py +++ b/manager/templatetags/notifications.py @@ -7,5 +7,12 @@ register = template.Library() @register.inclusion_tag('manager/notifications.html', takes_context=True) def getNotifications(context, login=False): - return { 'notifications': [notification for notification in Notification.objects.filter(Q(expiry__gte = timezone.now()) | Q(expiry = None)) if (notification.on_login or (not login)) ] } - + notifications = [notification for notification in Notification.objects.filter(Q(expiry__gte = timezone.now()) | Q(expiry = None)) if (notification.on_login or (not login)) ] + if context.dicts[3]["exception"]: + exception = Notification() + exception.status = 2 + exception.text = context.dicts[3]["exception"].human + if context.dicts[3]["user"].is_superuser: + exception.text += "

" + str(context.dicts[3]["exception"]) + "" + notifications = [ exception ] + notifications + return { 'notifications': notifications } diff --git a/manager/views.py b/manager/views.py index d17b5c0..6524da2 100644 --- a/manager/views.py +++ b/manager/views.py @@ -135,8 +135,8 @@ def ping(request, device_id): return HttpResponse(ajax, content_type="application/json") @login_required -def devices(request): - return render(request, "manager/index.html", {"title": "Device Administration"}) +def devices(request, code=200, exception=None): + return render(request, "manager/index.html", {"title": "Device Administration", "exception": exception}, status=code) @login_required def editdevice(request, device_id): @@ -479,3 +479,26 @@ def saveUserStatus(sender, instance, **kwargs): except: UserStatus.objects.create(user=instance) +def errorhandler(request, code, exception): + if code == 403: + exception.human = "You have no permission to access the requested page." + elif code == 400: + exception.human = "Something seems to be wrong with the request you sent. Please try again." + elif code == 404: + exception.human = "Sorry, we were unable to find the page you requested. Please check the address and try again." + elif code == 500: + exception.human = "Sorry, something seems to be wrong on our end. Please try again later or contact support if the problem persists." + + return devices(request, code=code, exception=exception) + +def handler400(request, exception): + return errorhandler(request, 400, exception) + +def handler403(request, exception): + return errorhandler(request, 403, exception) + +def handler404(request, exception): + return errorhandler(request, 404, exception) + +def handler500(request): + return errorhandler(request, 500, Exception("Please check the server logs for additional information.")) diff --git a/templates/manager/index.html b/templates/manager/index.html index b866f8e..8debfee 100644 --- a/templates/manager/index.html +++ b/templates/manager/index.html @@ -15,8 +15,10 @@ ‐ Organizations {% endif %} - +

+{% autoescape off %} {% getNotifications %} +{% endautoescape %}

Devices

diff --git a/vpnmanager/settings.py b/vpnmanager/settings.py index b7ac358..aa048b0 100644 --- a/vpnmanager/settings.py +++ b/vpnmanager/settings.py @@ -7,7 +7,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = '=go8&h#^kh6ksr11e2z-@4qqd6t%63$x#-!s#l_yhw@oyanrys' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = ["admin360.kumi.host", "test360.kumi.host"] diff --git a/vpnmanager/urls.py b/vpnmanager/urls.py index 482517b..623c8a1 100644 --- a/vpnmanager/urls.py +++ b/vpnmanager/urls.py @@ -19,3 +19,8 @@ urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('django.contrib.auth.urls')) ] + +handler400 = "manager.views.handler400" +handler403 = "manager.views.handler403" +handler404 = "manager.views.handler404" +handler500 = "manager.views.handler500"