diff --git a/api/views.py b/api/views.py index 767a7af..fa44e1d 100644 --- a/api/views.py +++ b/api/views.py @@ -1,6 +1,8 @@ +from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.contrib import auth -from django.http import JsonResponse +from django.core.exceptions import PermissionDenied +from django.http import JsonResponse, Http404 from django.shortcuts import get_object_or_404, redirect from django.views.decorators.http import require_http_methods from django.http import HttpResponseForbidden @@ -10,7 +12,7 @@ from django.utils import timezone from user_manager.models import UserAcl, AuthenticationToken from wireguard.models import WebadminSettings, Peer, PeerStatus, WireGuardInstance -from wgwadmlibrary.tools import user_allowed_peers +from wgwadmlibrary.tools import user_allowed_peers, user_has_access_to_peer import requests import subprocess import datetime @@ -112,6 +114,22 @@ def routerfleet_get_user_token(request): return JsonResponse(data) +@login_required +def peer_info(request): + peer = get_object_or_404(Peer, uuid=request.GET.get('uuid')) + user_acl = get_object_or_404(UserAcl, user=request.user) + + if not user_has_access_to_peer(user_acl, peer): + raise PermissionDenied + + data = { + 'name': str(peer), + 'public_key': str(peer.public_key), + 'uuid': str(peer.uuid), + } + return JsonResponse(data) + + @require_http_methods(["GET"]) def wireguard_status(request): user_acl = None diff --git a/templates/wireguard/wireguard_peer_list.html b/templates/wireguard/wireguard_peer_list.html index 9e7b4bc..20a1dfa 100644 --- a/templates/wireguard/wireguard_peer_list.html +++ b/templates/wireguard/wireguard_peer_list.html @@ -3,18 +3,16 @@ {% block content %} {% if wireguard_instances %}
Transfer:
- Latest Handshake:
+ Latest Handshake:
+
Endpoints:
- Allowed IPs:
+ Allowed IPs:
+
{% for address in peer.peerallowedip_set.all %}
- {% if address.priority == 0 and address.config_file == 'server' %}{{ address }}{% endif %}
+ {% if address.priority == 0 and address.config_file == 'server' %}
+ {{ address }}
+ {% endif %}
{% endfor %}
{% for address in peer.peerallowedip_set.all %}
- {% if address.priority >= 1 and address.config_file == 'server' %}{{ address }}{% endif %}
+ {% if address.priority >= 1 and address.config_file == 'server' %}
+ {{ address }}
+ {% endif %}
{% endfor %}
There are no WireGuard instances configured. You can add a new instance by clicking the button below.
@@ -98,14 +118,44 @@ Add WireGuard Instance {% endif %} - - - {% endblock %} {% block custom_page_scripts %} + +