From aed82eca1b3fdf48aea2551098b9f71af18353e7 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Thu, 12 Sep 2019 19:39:15 -0400 Subject: [PATCH] wireguard: Show this box's public key Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- plinth/modules/wireguard/__init__.py | 13 +++++++++++++ plinth/modules/wireguard/templates/wireguard.html | 11 +++++++++++ plinth/modules/wireguard/views.py | 1 + 3 files changed, 25 insertions(+) diff --git a/plinth/modules/wireguard/__init__.py b/plinth/modules/wireguard/__init__.py index 88ff30995..9f830e77c 100644 --- a/plinth/modules/wireguard/__init__.py +++ b/plinth/modules/wireguard/__init__.py @@ -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']) diff --git a/plinth/modules/wireguard/templates/wireguard.html b/plinth/modules/wireguard/templates/wireguard.html index 48ca39aa5..2cc397113 100644 --- a/plinth/modules/wireguard/templates/wireguard.html +++ b/plinth/modules/wireguard/templates/wireguard.html @@ -25,6 +25,7 @@

{% trans "Server" %}

{% trans "Peers allowed to connect to this server" %}

+ @@ -109,6 +110,16 @@ {% trans "Add Server" %} +

{% trans "Connection Information" %}

+ +

+ {% blocktrans %} + Public key for this {{ box_name }}: + {% endblocktrans %} + +

{{ public_key }}
+

+ {{ block.super }} {% endblock %} diff --git a/plinth/modules/wireguard/views.py b/plinth/modules/wireguard/views.py index dc8076206..0b31789e2 100644 --- a/plinth/modules/wireguard/views.py +++ b/plinth/modules/wireguard/views.py @@ -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']