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 committed 2020-01-18 13:52:54 -05:00
1 parent 87a58f1491
commit aed82eca1b
3 files changed
+25

No files matched your search

+13
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'])
@@ -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 %}
+1
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']