mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
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:
parent
8276ab64ea
commit
53f7c75d8e
@ -56,14 +56,26 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="btn-toolbar">
|
<div class="btn-toolbar">
|
||||||
<a title="{% trans 'Add a new peer' %}"
|
{% if not server.public_key %}
|
||||||
role="button" class="btn btn-default btn-add-client"
|
<form method="post" action="{% url 'wireguard:enable-server' %}">
|
||||||
href="{% url 'wireguard:add-client' %}">
|
{% csrf_token %}
|
||||||
<span class="fa fa-plus" aria-hidden="true"></span>
|
<button type="submit" class="btn btn-primary"
|
||||||
{% trans "Add Allowed Client" %}
|
title="{% trans 'Start WireGuard Server' %}">
|
||||||
</a>
|
<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>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<h3>{% trans "As a Client" %}</h3>
|
<h3>{% trans "As a Client" %}</h3>
|
||||||
<p>
|
<p>
|
||||||
{% blocktrans trimmed %}
|
{% blocktrans trimmed %}
|
||||||
|
|||||||
@ -9,6 +9,8 @@ from plinth.modules.wireguard import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
re_path(r'^apps/wireguard/$', views.WireguardView.as_view(), name='index'),
|
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(),
|
re_path(r'^apps/wireguard/client/add/$', views.AddClientView.as_view(),
|
||||||
name='add-client'),
|
name='add-client'),
|
||||||
re_path(r'^apps/wireguard/client/(?P<public_key>[^/]+)/show/$',
|
re_path(r'^apps/wireguard/client/(?P<public_key>[^/]+)/show/$',
|
||||||
|
|||||||
@ -11,7 +11,7 @@ from django.http import Http404
|
|||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.translation import gettext as _
|
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 import network
|
||||||
from plinth.modules.names.components import DomainName
|
from plinth.modules.names.components import DomainName
|
||||||
@ -252,3 +252,19 @@ class DeleteServerView(SuccessMessageMixin, TemplateView):
|
|||||||
network.delete_connection(connection.get_uuid())
|
network.delete_connection(connection.get_uuid())
|
||||||
messages.success(request, _('Server deleted.'))
|
messages.success(request, _('Server deleted.'))
|
||||||
return redirect('wireguard:index')
|
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')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user