wireguard: Create view to handle client config actions

Signed-off-by: Frederico Gomes <fredericojfgomes@gmail.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Frederico Gomes 2026-03-22 18:14:46 +00:00 committed by James Valleroy
parent 60a6ac2a0d
commit 8e9b2a0631
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -7,7 +7,7 @@ import urllib.parse
from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.http import Http404
from django.http import Http404, HttpResponse
from django.shortcuts import redirect
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
@ -112,6 +112,20 @@ class SessionClientDataMixin:
)
class ClientActionsView(SessionClientDataMixin, View):
action = None
def get(self, request):
if self.action == 'download':
config = self.get_client_config(request)
response = HttpResponse(config, content_type='text/plain')
response['Content-Disposition'] = \
'attachment; filename="wg-client.conf"'
return response
raise Http404("Invalid action")
class AutoAddClientView(SuccessMessageMixin, FormView):
"""View to add a client with keypair generation."""
form_class = forms.AutoAddClientForm