wireguard: Show this box's public key

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2019-09-12 19:39:15 -04:00
parent 87a58f1491
commit aed82eca1b
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
3 changed files with 25 additions and 0 deletions

View File

@ -104,6 +104,19 @@ def setup(helper, old_version=None):
helper.call('post', app.enable)
def get_public_key():
"""Return this box's public key."""
public_key_path = '/var/lib/freedombox/wireguard/publickey'
try:
with open(public_key_path) as public_key_file:
public_key = public_key_file.read().strip()
except FileNotFoundError:
public_key = None
return public_key
def get_info():
"""Return server and clients info."""
output = actions.superuser_run('wireguard', ['get-info'])

View File

@ -25,6 +25,7 @@
<h3>{% trans "Server" %}</h3>
<p>{% trans "Peers allowed to connect to this server" %}</p>
<table class="table table-bordered table-condensed table-striped"
id="server-peers-list">
<tr>
@ -109,6 +110,16 @@
{% trans "Add Server" %}
</a>
<h3>{% trans "Connection Information" %}</h3>
<p>
{% blocktrans %}
Public key for this {{ box_name }}:
{% endblocktrans %}
<pre>{{ public_key }}</pre>
</p>
{{ block.super }}
{% endblock %}

View File

@ -46,6 +46,7 @@ class WireguardView(AppView):
def get_context_data(self, **kwargs):
"""Return additional context for rendering the template."""
context = super().get_context_data(**kwargs)
context['public_key'] = wireguard.get_public_key()
info = wireguard.get_info()
context['server_peers'] = info['my_server']['clients']
context['client_peers'] = info['my_client']['servers']