From 53f7c75d8ef43ebe4accaf4a825e381ea5ad143f Mon Sep 17 00:00:00 2001 From: Frederico Gomes Date: Sun, 4 Jan 2026 20:41:29 +0000 Subject: [PATCH] wireguard: add 'Start Server' button with confirmation page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds explicit UI flow to generate server keypair and interface. - New EnableServerView - Conditional 'Start Server' button on main page when no wg0 - Button switches to 'Add Client' after server setup Solves circular dependency UX issue when connecting two FBs EDIT: Following review feedback, I removed the intermediate confirmation page. The “Start WireGuard Server” button now sends a POST directly from the main page. Signed-off-by: Frederico Gomes Reviewed-by: James Valleroy [jvalleroy: Change from TemplateView to View] [jvalleroy: Remove redundant import] Signed-off-by: James Valleroy --- .../wireguard/templates/wireguard.html | 24 ++++++++++++++----- plinth/modules/wireguard/urls.py | 2 ++ plinth/modules/wireguard/views.py | 18 +++++++++++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/plinth/modules/wireguard/templates/wireguard.html b/plinth/modules/wireguard/templates/wireguard.html index d670179fd..73e56bce6 100644 --- a/plinth/modules/wireguard/templates/wireguard.html +++ b/plinth/modules/wireguard/templates/wireguard.html @@ -56,14 +56,26 @@

- - - {% trans "Add Allowed Client" %} - + {% if not server.public_key %} +
+ {% csrf_token %} + +
+ {% else %} + + + {% trans "Add Allowed Client" %} + + {% endif %}
+

{% trans "As a Client" %}

{% blocktrans trimmed %} diff --git a/plinth/modules/wireguard/urls.py b/plinth/modules/wireguard/urls.py index d0dcc6bbe..1c44b551e 100644 --- a/plinth/modules/wireguard/urls.py +++ b/plinth/modules/wireguard/urls.py @@ -9,6 +9,8 @@ from plinth.modules.wireguard import views urlpatterns = [ re_path(r'^apps/wireguard/$', views.WireguardView.as_view(), name='index'), + re_path(r'^apps/wireguard/enable-server/$', + views.EnableServerView.as_view(), name='enable-server'), re_path(r'^apps/wireguard/client/add/$', views.AddClientView.as_view(), name='add-client'), re_path(r'^apps/wireguard/client/(?P[^/]+)/show/$', diff --git a/plinth/modules/wireguard/views.py b/plinth/modules/wireguard/views.py index 9259edf22..48fcc45f8 100644 --- a/plinth/modules/wireguard/views.py +++ b/plinth/modules/wireguard/views.py @@ -11,7 +11,7 @@ from django.http import Http404 from django.shortcuts import redirect from django.urls import reverse_lazy from django.utils.translation import gettext as _ -from django.views.generic import FormView, TemplateView +from django.views.generic import FormView, TemplateView, View from plinth import network from plinth.modules.names.components import DomainName @@ -252,3 +252,19 @@ class DeleteServerView(SuccessMessageMixin, TemplateView): network.delete_connection(connection.get_uuid()) messages.success(request, _('Server deleted.')) return redirect('wireguard:index') + + +class EnableServerView(SuccessMessageMixin, View): + """View to enable the WireGuard server.""" + + def post(self, request): + """Create server interface.""" + try: + utils.setup_server() + messages.success(request, + _('WireGuard server started successfully.')) + except Exception as error: + messages.error( + request, + _('Failed to start WireGuard server: {}').format(error)) + return redirect('wireguard:index')