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