mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-02-20 11:36:18 +00:00
Add WireGuard status API endpoint: implement api_v2_wireguard_status function
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views_api import api_v2_manage_peer, api_v2_peer_list, api_v2_peer_detail
|
from .views_api import api_v2_manage_peer, api_v2_peer_list, api_v2_peer_detail, api_v2_wireguard_status
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('manage_peer/', api_v2_manage_peer, name='api_v2_manage_peer'),
|
path('manage_peer/', api_v2_manage_peer, name='api_v2_manage_peer'),
|
||||||
path('peer_list/', api_v2_peer_list, name='api_v2_peer_list'),
|
path('peer_list/', api_v2_peer_list, name='api_v2_peer_list'),
|
||||||
path('peer_detail/', api_v2_peer_detail, name='api_v2_peer_detail'),
|
path('peer_detail/', api_v2_peer_detail, name='api_v2_peer_detail'),
|
||||||
|
path('wireguard_status/', api_v2_wireguard_status, name='api_v2_wireguard_status'),
|
||||||
]
|
]
|
||||||
@@ -7,6 +7,7 @@ from django.db import transaction
|
|||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
|
from api.views import func_get_wireguard_status
|
||||||
from routing_templates.models import RoutingTemplate
|
from routing_templates.models import RoutingTemplate
|
||||||
from wireguard.models import Peer, PeerAllowedIP, WireGuardInstance
|
from wireguard.models import Peer, PeerAllowedIP, WireGuardInstance
|
||||||
from wireguard_peer.functions import func_create_new_peer
|
from wireguard_peer.functions import func_create_new_peer
|
||||||
@@ -618,3 +619,32 @@ def api_v2_peer_detail(request):
|
|||||||
|
|
||||||
return JsonResponse({"status": "success", "peer": peer_data}, status=200)
|
return JsonResponse({"status": "success", "peer": peer_data}, status=200)
|
||||||
|
|
||||||
|
|
||||||
|
@csrf_exempt
|
||||||
|
@api_doc(
|
||||||
|
summary="Get WireGuard status (dump) for all interfaces/peers",
|
||||||
|
auth="Header token: <ApiKey.token>",
|
||||||
|
methods=["POST", "GET"],
|
||||||
|
params=[],
|
||||||
|
returns=[
|
||||||
|
{"status": 200, "body": {"status": "success", "message": "...", "wg0": { "...": "..." }, "cache_information": { "..." }}},
|
||||||
|
{"status": 403, "body": {"status": "error", "error_message": "Invalid API key."}},
|
||||||
|
{"status": 405, "body": {"status": "error", "error_message": "Method not allowed."}},
|
||||||
|
],
|
||||||
|
examples={
|
||||||
|
"get_latest_status": {
|
||||||
|
"method": "GET",
|
||||||
|
"json": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
def api_v2_wireguard_status(request):
|
||||||
|
if request.method not in ("POST", "GET"):
|
||||||
|
return JsonResponse({"status": "error", "error_message": "Method not allowed."}, status=405)
|
||||||
|
|
||||||
|
api_key, api_error = validate_api_key(request)
|
||||||
|
if not api_key:
|
||||||
|
return JsonResponse({"status": "error", "error_message": api_error}, status=403)
|
||||||
|
|
||||||
|
data = func_get_wireguard_status()
|
||||||
|
return JsonResponse(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user