wireguard: add 'Start Server' button with confirmation page

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 <fredericojfgomes@gmail.com>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
[jvalleroy: Change from TemplateView to View]
[jvalleroy: Remove redundant import]
Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Frederico Gomes 2026-01-04 20:41:29 +00:00 committed by James Valleroy
parent 8276ab64ea
commit 53f7c75d8e
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 37 additions and 7 deletions

View File

@ -56,14 +56,26 @@
</p>
<div class="btn-toolbar">
<a title="{% trans 'Add a new peer' %}"
role="button" class="btn btn-default btn-add-client"
href="{% url 'wireguard:add-client' %}">
<span class="fa fa-plus" aria-hidden="true"></span>
{% trans "Add Allowed Client" %}
</a>
{% if not server.public_key %}
<form method="post" action="{% url 'wireguard:enable-server' %}">
{% csrf_token %}
<button type="submit" class="btn btn-primary"
title="{% trans 'Start WireGuard Server' %}">
<span class="fa fa-rocket" aria-hidden="true"></span>
{% trans "Start WireGuard Server" %}
</button>
</form>
{% else %}
<a title="{% trans 'Add a new peer' %}"
role="button" class="btn btn-default btn-add-client"
href="{% url 'wireguard:add-client' %}">
<span class="fa fa-plus" aria-hidden="true"></span>
{% trans "Add Allowed Client" %}
</a>
{% endif %}
</div>
<h3>{% trans "As a Client" %}</h3>
<p>
{% blocktrans trimmed %}

View File

@ -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<public_key>[^/]+)/show/$',

View File

@ -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')