mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
wireguard: Allow deleting a client
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
5 files changed
+89
-7
No files matched your search
@@ -30,13 +30,17 @@
|
||||
<tr>
|
||||
<th>{% trans "Public Key" %}</th>
|
||||
<th>{% trans "Last Connected Time" %}</th>
|
||||
<th>{% trans "Edit" %}</th>
|
||||
<th>{% trans "Delete" %}</th>
|
||||
</tr>
|
||||
{% for client in server_clients %}
|
||||
<tr>
|
||||
<td>{{ client.public_key }}</td>
|
||||
<td>{{ client.latest_handshake }}</td>
|
||||
<td>Edit</td>
|
||||
<td><a class="btn btn-sm btn-default"
|
||||
href="{% url 'wireguard:delete-client' client.public_key %}">
|
||||
<span class="fa fa-trash-o" aria-hidden="true">
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
{% extends "base.html" %}
|
||||
{% comment %}
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
{% endcomment %}
|
||||
|
||||
{% load bootstrap %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>{{ title }}</h3>
|
||||
|
||||
<p>
|
||||
{% trans "Are you sure that you want to delete this client?" %}
|
||||
</p>
|
||||
<p>
|
||||
<b>{{ public_key }}</b>
|
||||
</p>
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<input type="submit" class="btn btn-danger"
|
||||
value="{% trans "Delete Client" %}"/>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
@@ -25,5 +25,7 @@ from plinth.modules.wireguard import views
|
||||
urlpatterns = [
|
||||
url(r'^apps/wireguard/$', views.WireguardView.as_view(), name='index'),
|
||||
url(r'^apps/wireguard/client/add/$', views.AddClientView.as_view(),
|
||||
name='add-client')
|
||||
name='add-client'),
|
||||
url(r'^apps/wireguard/client/(?P<public_key>[^/]+)/delete/$',
|
||||
views.DeleteClientView.as_view(), name='delete-client'),
|
||||
]
|
||||
@@ -20,10 +20,12 @@ Views for WireGuard application.
|
||||
|
||||
import json
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import FormView
|
||||
from django.views.generic import FormView, TemplateView
|
||||
|
||||
import plinth.modules.wireguard as wireguard
|
||||
from plinth import actions
|
||||
@@ -67,6 +69,23 @@ class AddClientView(SuccessMessageMixin, FormView):
|
||||
def form_valid(self, form):
|
||||
"""Add the client."""
|
||||
public_key = form.cleaned_data.get('public_key')
|
||||
actions.superuser_run(
|
||||
'wireguard', ['add-client', public_key])
|
||||
actions.superuser_run('wireguard', ['add-client', public_key])
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class DeleteClientView(SuccessMessageMixin, TemplateView):
|
||||
"""View to delete a client."""
|
||||
template_name = 'wireguard_delete_client.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Return additional context data for rendering the template."""
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['title'] = _('Delete Client')
|
||||
context['public_key'] = self.kwargs['public_key']
|
||||
return context
|
||||
|
||||
def post(self, request, public_key):
|
||||
"""Delete the client."""
|
||||
actions.superuser_run('wireguard', ['remove-client', public_key])
|
||||
messages.success(request, _('Client deleted.'))
|
||||
return redirect('wireguard:index')
|
||||
Reference in new issue
Block a user