wireguard: Show list of added clients

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy committed 2020-01-18 13:52:40 -05:00
1 parent aa02f4d710
commit e00c28f36e
4 files changed
+58 -5

No files matched your search

+2
View File
@@ -21,6 +21,7 @@ FreedomBox app for wireguard.
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import app as app_module
from plinth import cfg, frontpage, menu
from plinth.modules.firewall.components import Firewall
@@ -95,4 +96,5 @@ def init():
def setup(helper, old_version=None):
"""Install and configure the module."""
helper.install(managed_packages)
helper.call('post', actions.superuser_run, 'wireguard', ['setup'])
helper.call('post', app.enable)
@@ -23,10 +23,24 @@
{% block configuration %}
<h3>{% trans "Server" %}</h3>
<p>{% trans "Peers allowed to connect to this server" %}</p>
<ul>{% trans "public key" %}</ul>
<ul>{% trans "last connected time" %}</ul>
<ul>{% trans "edit" %}</ul>
<table class="table table-bordered table-condensed table-striped"
id="server-clients-list">
<tr>
<th>{% trans "Public Key" %}</th>
<th>{% trans "Last Connected Time" %}</th>
<th>{% trans "Edit" %}</th>
</tr>
{% for client in server_clients %}
<tr>
<td>{{ client.public_key }}</td>
<td>{{ client.latest_handshake }}</td>
<td>Edit</td>
</tr>
{% endfor %}
</table>
<a title="{% trans 'Add a new peer' %}"
role="button" class="btn btn-default"
href="{% url 'wireguard:add-client' %}">
+13 -2
View File
@@ -18,8 +18,10 @@
Views for WireGuard application.
"""
from django.contrib import messages
import json
from django.contrib.messages.views import SuccessMessageMixin
from django.urls import reverse_lazy
from django.utils.translation import ugettext as _
from django.views.generic import FormView
@@ -41,11 +43,20 @@ class WireguardView(AppView):
template_name = 'wireguard.html'
port_forwarding_info = wireguard.port_forwarding_info
def get_context_data(self, **kwargs):
"""Return additional context for rendering the template."""
context = super().get_context_data(**kwargs)
clients_list = actions.superuser_run('wireguard', ['list-clients'])
context['server_clients'] = json.loads(clients_list)
return context
class AddClientView(SuccessMessageMixin, FormView):
"""View to add a client."""
form_class = forms.AddClientForm
template_name = 'wireguard_add_client.html'
success_url = reverse_lazy('wireguard:index')
success_message = _('Added new client.')
def get_context_data(self, **kwargs):
"""Return additional context for rendering the template."""
@@ -58,4 +69,4 @@ class AddClientView(SuccessMessageMixin, FormView):
public_key = form.cleaned_data.get('public_key')
actions.superuser_run(
'wireguard', ['add-client', public_key])
messages.success(self.request, _('Added new client.'))
return super().form_valid(form)