wireguard: List peers in client section

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:48 -05:00
1 parent 901f89f393
commit 36fdedb9a7
5 files changed
+96 -55

No files matched your search

+17 -3
View File
@@ -59,6 +59,8 @@ port_forwarding_info = [('UDP', 51820)]
app = None
SERVER_INTERFACE = 'wg0'
class WireguardApp(app_module.App):
"""FreedomBox app for wireguard."""
@@ -103,6 +105,18 @@ def setup(helper, old_version=None):
def get_info():
"""Get server and clients info."""
info = actions.superuser_run('wireguard', ['get-info'])
return json.loads(info)
"""Return server and clients info."""
output = actions.superuser_run('wireguard', ['get-info'])
info = json.loads(output)
my_server_info = info.pop(SERVER_INTERFACE)
my_client_servers = [interface['peers'][0] or {}
for interface in info.values()]
return {
'my_server': {
'public_key': my_server_info['public_key'],
'clients': my_server_info['peers'],
},
'my_client': {
'servers': my_client_servers,
},
}
@@ -26,36 +26,36 @@
<p>{% trans "Peers allowed to connect to this server" %}</p>
<table class="table table-bordered table-condensed table-striped"
id="server-clients-list">
id="server-peers-list">
<tr>
<th>{% trans "Public Key" %}</th>
<th>{% trans "Last Connected Time" %}</th>
<th>{% trans "Delete" %}</th>
</tr>
{% if server_clients %}
{% for client in server_clients %}
<tr>
{% if server_peers %}
{% for peer in server_peers %}
<tr>
<td>
<a href="{% url 'wireguard:show-client' client.public_key %}">
{{ client.public_key }}
</a>
</td>
<td>{{ client.latest_handshake }}</td>
<a href="{% url 'wireguard:show-client' peer.public_key %}">
{{ peer.public_key }}
</a>
</td>
<td>{{ peer.latest_handshake }}</td>
<td><a class="btn btn-sm btn-default"
href="{% url 'wireguard:delete-client' client.public_key %}">
href="{% url 'wireguard:delete-client' peer.public_key %}">
<span class="fa fa-trash-o" aria-hidden="true">
</span>
</td>
</tr>
</tr>
{% endfor %}
{% else %}
<tr>
<td>
<td>
{% blocktrans trimmed %}
No peers configured to connect to this {{ box_name }} yet.
{% endblocktrans %}
</td>
</td>
</tr>
{% endif %}
</table>
@@ -69,11 +69,35 @@
<h3>{% trans "Client" %}</h3>
<p>{% trans "Peer servers that FreedomBox will connect to" %}</p>
<ul>{% trans "endpoint" %}</ul>
<ul>{% trans "public key" %}</ul>
<ul>{% trans "last connected time" %}</ul>
<ul>{% trans "edit" %}</ul>
<p>{% trans "No connections to remove servers are configured yet." %}</p>
<table class="table table-bordered table-condensed table-striped"
id="client-peers-list">
<tr>
<th>{% trans "Endpoint" %}</th>
<th>{% trans "Public Key" %}</th>
<th>{% trans "Last Connected Time" %}</th>
<th>{% trans "Edit" %}</th>
</tr>
{% if client_peers %}
{% for peer in client_peers %}
<tr>
<td>{{ peer.endpoint }}</td>
<td>{{ peer.public_key }}</td>
<td>{{ peer.latest_handshake }}</td>
<td>Edit</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td>
{% blocktrans trimmed %}
No connections to remote servers are configured yet.
{% endblocktrans %}
</td>
</tr>
{% endif %}
</table>
<a title="{% trans 'Add a new server' %}"
role="button" class="btn btn-default"
href="{% url 'wireguard:add-server' %}">
@@ -27,7 +27,7 @@
<h4>{% trans "Connection Information" %}</h4>
<p>{% trans "IP address to use:" %}</p>
<p>{% trans "Server endpoints:" %}</p>
<p>{% trans "Server's public key:" %} {{ server.public_key }}</p>
<p>{% trans "Server's public key:" %} {{ my_server.public_key }}</p>
<p>{% trans "Pre-shared key:" %}</p>
<h4>{% trans "Status" %}</h4>
+6 -3
View File
@@ -47,7 +47,8 @@ class WireguardView(AppView):
"""Return additional context for rendering the template."""
context = super().get_context_data(**kwargs)
info = wireguard.get_info()
context['server_clients'] = info['clients']
context['server_peers'] = info['my_server']['clients']
context['client_peers'] = info['my_client']['servers']
return context
@@ -79,12 +80,14 @@ class ShowClientView(SuccessMessageMixin, TemplateView):
"""Return additional context data for rendering the template."""
context = super().get_context_data(**kwargs)
context['title'] = _('Show Client')
public_key = self.kwargs['public_key']
info = wireguard.get_info()
context['server'] = info['server']
for client in info['clients']:
context.update(info)
for client in info['my_server']['clients']:
if client['public_key'] == public_key:
context['client'] = client
return context