From 9b9d87bc63102bb705ac717f76c6bf9f349b0a9f Mon Sep 17 00:00:00 2001
From: ikmaak
{% blocktrans trimmed %}
- Note: only specially created directories will be shared on selected disks,
+ Note: Only specially created directories will be shared on selected disks,
not the whole disk.
{% endblocktrans %}
{% trans "Shares" %}
{% trans "Users who need to re-enter their password on the password change page to access group and home shares" %}: +
{% trans "Users needing to re-enter their password on the password change page to access group and home shares" %}: {{ users.password_re_enter_needed|join:", " }}.
{% endif %} From 3a202af843b420dd3743ff547e1aaaeeb72b0e38 Mon Sep 17 00:00:00 2001 From: Veiko Aasa{% trans "Peers allowed to connect to this server" %}
+{% trans "Peer servers that FreedomBox will connect to" %}
+{% trans "No connections to remove servers are configured yet." %}
+{% trans "Peer servers that FreedomBox will connect to" %}
diff --git a/plinth/modules/wireguard/templates/wireguard_add_client.html b/plinth/modules/wireguard/templates/wireguard_add_client.html new file mode 100644 index 000000000..3aa891a17 --- /dev/null +++ b/plinth/modules/wireguard/templates/wireguard_add_client.html @@ -0,0 +1,37 @@ +{% extends "base.html" %} +{% comment %} +# +# This file is part of FreedomBox. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see{% trans "Peers allowed to connect to this server" %}
-| {% trans "Public Key" %} | +{% trans "Last Connected Time" %} | +{% trans "Edit" %} | +
|---|---|---|
| {{ client.public_key }} | +{{ client.latest_handshake }} | +Edit | +
+ {% trans "Are you sure that you want to delete this client?" %} +
++ {{ public_key }} +
+ + + +{% endblock %} diff --git a/plinth/modules/wireguard/urls.py b/plinth/modules/wireguard/urls.py index 96b2f5de0..d7b72da6a 100644 --- a/plinth/modules/wireguard/urls.py +++ b/plinth/modules/wireguard/urls.py @@ -25,5 +25,7 @@ from plinth.modules.wireguard import views urlpatterns = [ url(r'^apps/wireguard/$', views.WireguardView.as_view(), name='index'), url(r'^apps/wireguard/client/add/$', views.AddClientView.as_view(), - name='add-client') + name='add-client'), + url(r'^apps/wireguard/client/(?P{% trans "Peers allowed to connect to this server" %}
| {% trans "Public Key" %} | {% trans "Last Connected Time" %} | {% trans "Delete" %} | |
|---|---|---|---|
| + + {{ client.public_key }} + + | +{{ client.latest_handshake }} | ++ + | +|
| {{ client.public_key }} | -{{ client.latest_handshake }} | -- + | + {% blocktrans trimmed %} + No peers configured to connect to this {{ box_name }} yet. + {% endblocktrans %} |
{% trans "IP address to use:" %}
+{% trans "Server endpoints:" %}
+{% trans "Server's public key:" %} {{ server.public_key }}
+{% trans "Pre-shared key:" %}
+ +{% trans "Client Public Key:" %} {{ client.public_key }}
+{% trans "Data transmitted:" %} {{ client.transfer_tx }}
+{% trans "Data received:" %} {{ client.transfer_rx }}
+{% trans "Latest handshake:" %} {{ client.latest_handshake }}
+ +{% endblock %} diff --git a/plinth/modules/wireguard/urls.py b/plinth/modules/wireguard/urls.py index d7b72da6a..a454dbd4e 100644 --- a/plinth/modules/wireguard/urls.py +++ b/plinth/modules/wireguard/urls.py @@ -26,6 +26,8 @@ urlpatterns = [ url(r'^apps/wireguard/$', views.WireguardView.as_view(), name='index'), url(r'^apps/wireguard/client/add/$', views.AddClientView.as_view(), name='add-client'), + url(r'^apps/wireguard/client/(?P{% trans "No connections to remove servers are configured yet." %}
-{% trans "Peers allowed to connect to this server" %}
| {% trans "Public Key" %} | {% trans "Last Connected Time" %} | {% trans "Delete" %} | |
|---|---|---|---|
| - - {{ client.public_key }} - - | -{{ client.latest_handshake }} | + + {{ peer.public_key }} + + +{{ peer.latest_handshake }} | + href="{% url 'wireguard:delete-client' peer.public_key %}"> | -
| + | {% blocktrans trimmed %} No peers configured to connect to this {{ box_name }} yet. {% endblocktrans %} - | +
{% trans "Peer servers that FreedomBox will connect to" %}
-{% trans "No connections to remove servers are configured yet." %}
+| {% trans "Endpoint" %} | +{% trans "Public Key" %} | +{% trans "Last Connected Time" %} | +{% trans "Edit" %} | +
|---|---|---|---|
| {{ peer.endpoint }} | +{{ peer.public_key }} | +{{ peer.latest_handshake }} | +Edit | +
| + {% blocktrans trimmed %} + No connections to remote servers are configured yet. + {% endblocktrans %} + | +
{% trans "IP address to use:" %}
{% trans "Server endpoints:" %}
-{% trans "Server's public key:" %} {{ server.public_key }}
+{% trans "Server's public key:" %} {{ my_server.public_key }}
{% trans "Pre-shared key:" %}
{% trans "Peer servers that FreedomBox will connect to" %}
| {% trans "Endpoint" %} | {% trans "Public Key" %} | @@ -79,21 +79,25 @@|||
|---|---|---|---|---|
| {{ peer.endpoint }} | -{{ peer.public_key }} | -{{ peer.latest_handshake }} | -Edit | -|
| {{ peer.endpoint }} | ++ + {{ peer.public_key }} + + | +{{ peer.latest_handshake }} | +Edit | +|
| + | {% blocktrans trimmed %} No connections to remote servers are configured yet. {% endblocktrans %} - | +|||
{% trans "Endpoint:" %} {{ server.endpoint }}
+{% trans "Public Key:" %} {{ server.public_key }}
+{% trans "Pre-shared key:" %} {{ server.preshared_key }}
+{% trans "Data transmitted:" %} {{ server.transfer_tx }}
+{% trans "Data received:" %} {{ server.transfer_rx }}
+{% trans "Latest handshake:" %} {{ server.latest_handshake }}
+ +{% endblock %} diff --git a/plinth/modules/wireguard/urls.py b/plinth/modules/wireguard/urls.py index 2135867bc..fa2a1f159 100644 --- a/plinth/modules/wireguard/urls.py +++ b/plinth/modules/wireguard/urls.py @@ -32,4 +32,6 @@ urlpatterns = [ views.DeleteClientView.as_view(), name='delete-client'), url(r'^apps/wireguard/server/add/$', views.AddServerView.as_view(), name='add-server'), + url(r'^apps/wireguard/server/(?P{% trans "Peers allowed to connect to this server" %}
++ {% blocktrans %} + Public key for this {{ box_name }}: + {% endblocktrans %} +
{{ server.public_key }}
+
+
@@ -72,15 +83,19 @@
- {% blocktrans %} - Public key for this {{ box_name }}: - {% endblocktrans %} - -
{{ public_key }}
-
-
{{ block.super }}
{% endblock %}
diff --git a/plinth/modules/wireguard/templates/wireguard_show_client.html b/plinth/modules/wireguard/templates/wireguard_show_client.html
index 416a87c6c..51fc9edd7 100644
--- a/plinth/modules/wireguard/templates/wireguard_show_client.html
+++ b/plinth/modules/wireguard/templates/wireguard_show_client.html
@@ -22,23 +22,58 @@
{% block content %}
- | {% trans "Client public key:" %} | +{{ client.public_key }} | +
|---|---|
| {% trans "IP address to use:" %} | +{{ client.allowed_ips|join:", " }} | +
| {% trans "Pre-shared key:" %} | +{{ client.preshared_key }} | +
| {% trans "Server endpoints:" %} | +
+ {% for endpoint in endpoints %}
+ {{ endpoint }}
+ {% endfor %}
+ |
+
| {% trans "Server's public key:" %} | +{{ server.public_key }} | +
{% trans "IP address to use:" %}
-{% trans "Server endpoints:" %}
-{% trans "Server's public key:" %} {{ my_server.public_key }}
-{% trans "Pre-shared key:" %}
- -{% trans "Client Public Key:" %} {{ client.public_key }}
-{% trans "Data transmitted:" %} {{ client.transfer_tx|filesizeformat }}
-{% trans "Data received:" %} {{ client.transfer_rx|filesizeformat }}
-{% trans "Latest handshake:" %} {{ client.latest_handshake }}
+| {% trans "Data transmitted:" %} | +{{ client.status.transfer_tx|filesizeformat }} | +
|---|---|
| {% trans "Data received:" %} | +{{ client.status.transfer_rx|filesizeformat }} | +
| {% trans "Latest handshake:" %} | +{{ client.status.latest_handshake|default:'' }} | +
+
{% trans "Edit Client" %}
- {% trans "Peers allowed to connect to this server" %} {% trans "Peers allowed to connect to this server:" %} {% trans "Peer servers that FreedomBox will connect to" %}
+ {% blocktrans trimmed %}
+ Servers that {{ box_name }} will connect to:
+ {% endblocktrans %}
+
+ {% blocktrans trimmed %}
+ {{ box_name }} will allow this client to connect to it. Ensure that the
+ client is configured with the following information.
+ {% endblocktrans %}
+
+ {% blocktrans trimmed %}
+ {{ box_name }} will attempt to reach a WireGuard server with the
+ following information. Ensure that the server is configured to allow
+ {{ box_name }}'s public key and IP address.
+ {% endblocktrans %}
+
- {% trans "Edit Server" %}
+ {% trans "Edit" %}
- {% trans "Delete Server" %}
+ {% trans "Delete" %}
{% trans "Not configured yet." %} Most routers provide a '
+ 'configuration setting called DMZ. This will allow the '
+ 'router to forward all incoming traffic from the '
+ 'internet to a single IP address such as the '
+ '{box_name}\'s address. First remember to configure a '
+ 'static local IP address for your {box_name} in your '
+ 'router\'s configuration. You may alternatively choose to '
+ 'forward only specific traffic to your {box_name}. '
+ 'This is ideal if you have other servers like '
+ '{box_name} in your network or if your router does not '
+ 'support DMZ feature. All applications that provide a '
+ 'web interface need you to forward traffic from ports '
+ '80 and 443 to work. Each of the other applications '
+ 'will suggest you which port(s) need to be forwarded '
+ 'for that application to work. Choose this if you have not '
+ 'configured or are unable to configure the router '
+ 'currently and wish to be reminded later. Some of '
+ 'the other configuration steps may fail.
+ {% blocktrans trimmed %}
+ Your Freedombox gets its internet connection from your router via Wi-Fi or Ethernet cable.
+ This is a typical home setup.
+ {% endblocktrans %}
+
+ {% blocktrans trimmed %}
+ With this setup, any device on the internet trying to reach your Freedombox will have to
+ go through your router. The router will need to be configured to forward all traffic
+ it receives so that Freedombox provides the services.
+ {% endblocktrans %}
+
+ {% blocktrans trimmed %}
+ If you don't have control over your router, choose not to configure it. To see options,
+ to overcome this limitation, choose 'no public address' option in Internet connection
+ type selection.
+ {% endblocktrans %}
+
+ {% blocktrans trimmed %}
+ You will need to login to your router's administration
+ console provided by the router. This may look like
+ http://192.168.168.0.1.
+ The username and password is configured by you
+ when you first setup the router. For many routers, this
+ information is printed at the back of the router. If you
+ don't remember the credentials or the IP address of the
+ router, you may decide to reset it and set it up freshly.
+ Lookup your router model number and search online for the
+ router's manual. This will provide full instructions on
+ how to perform this task.
+ {% endblocktrans %}
+
+ {% blocktrans trimmed %}
+ The following best describes how your Freedombox is connected in your
+ network. This information is used only to suggest you necessary configuration
+ actions.
+ {% endblocktrans %}
+
+ {% blocktrans trimmed %}
+ Your Freedombox gets its internet from your Router via WiFi or Ethernet
+ cable. This is a typical home setup.
+ {% endblocktrans %}
+
{% blocktrans trimmed %}
@@ -61,15 +59,3 @@
how to perform this task.
{% endblocktrans %}
- {% blocktrans trimmed %}
- The following best describes how your Freedombox is connected in your
- network. This information is used only to suggest you necessary configuration
- actions.
- {% endblocktrans %}
-
- {% blocktrans trimmed %}
- Your Freedombox gets its internet from your Router via WiFi or Ethernet
- cable. This is a typical home setup.
- {% endblocktrans %}
-
-
- {% trans "Endpoint:" %}
- {{ server.peers.0.endpoint }}
-
-
- {% trans "Public Key:" %}
- {{ server.peers.0.public_key }}
-
-
- {% trans "Pre-shared key:" %}
- {{ server.peers.0.preshared_key }}
-
-
- {% trans "Data transmitted:" %}
- {{ server.peers.0.status.transfer_tx|filesizeformat }}
-
-
- {% trans "Data received:" %}
- {{ server.peers.0.status.transfer_rx|filesizeformat }}
-
-
+ {% for peer in server.peers.values %}
+ {% if forloop.first %}
+ {% trans "Latest handshake:" %}
- {{ server.peers.0.status.latest_handshake }}
-
+
+ {% trans "Endpoint:" %}
+ {{ peer.endpoint }}
+
+
+ {% trans "Public Key:" %}
+ {{ peer.public_key }}
+
+
+ {% trans "Pre-shared key:" %}
+ {{ peer.preshared_key }}
+
+
+ {% trans "Data transmitted:" %}
+ {{ peer.status.transfer_tx|filesizeformat }}
+
+
+ {% trans "Data received:" %}
+ {{ peer.status.transfer_rx|filesizeformat }}
+
+
+ {% endif %}
+ {% endfor %}
diff --git a/plinth/modules/wireguard/utils.py b/plinth/modules/wireguard/utils.py
index d41ba042e..86c404001 100644
--- a/plinth/modules/wireguard/utils.py
+++ b/plinth/modules/wireguard/utils.py
@@ -18,9 +18,100 @@
Utilities for managing WireGuard.
"""
+import datetime
+import json
import subprocess
+import time
-from plinth import network
+from plinth import actions, network
+from plinth.utils import import_from_gi
+
+nm = import_from_gi('NM', '1.0')
+
+IP_TEMPLATE = '10.84.0.{}'
+WIREGUARD_SETTING = nm.SETTING_WIREGUARD_SETTING_NAME
+
+
+def get_nm_info():
+ """Get information from network manager."""
+ client = network.get_nm_client()
+
+ connections = {}
+ for connection in client.get_connections():
+ if connection.get_connection_type() != WIREGUARD_SETTING:
+ continue
+
+ settings = connection.get_setting_by_name(WIREGUARD_SETTING)
+ secrets = connection.get_secrets(WIREGUARD_SETTING)
+ connection.update_secrets(WIREGUARD_SETTING, secrets)
+
+ info = {}
+ info['interface'] = connection.get_interface_name()
+ info['private_key'] = settings.get_private_key()
+ info['public_key'] = None
+ info['listen_port'] = settings.get_listen_port()
+ info['fwmark'] = settings.get_fwmark()
+ info['mtu'] = settings.get_mtu()
+ info['default_route'] = settings.get_ip4_auto_default_route()
+ info['peers'] = {}
+ for peer_index in range(settings.get_peers_len()):
+ peer = settings.get_peer(peer_index)
+ peer_info = {
+ 'endpoint': peer.get_endpoint(),
+ 'public_key': peer.get_public_key(),
+ 'preshared_key': peer.get_preshared_key(),
+ 'persistent_keepalive': peer.get_persistent_keepalive(),
+ 'allowed_ips': []
+ }
+ for index in range(peer.get_allowed_ips_len()):
+ allowed_ip = peer.get_allowed_ip(index, None)
+ peer_info['allowed_ips'].append(allowed_ip)
+
+ info['peers'][peer_info['public_key']] = peer_info
+
+ settings_ipv4 = connection.get_setting_ip4_config()
+ if settings_ipv4 and settings_ipv4.get_num_addresses():
+ info['ip_address'] = settings_ipv4.get_address(0).get_address()
+
+ connections[info['interface']] = info
+
+ return connections
+
+
+def get_info():
+ """Return server and clients info."""
+ output = actions.superuser_run('wireguard', ['get-info'])
+ status = json.loads(output)
+
+ nm_info = get_nm_info()
+
+ my_server_info = None
+ my_client_servers = {}
+ for interface, info in nm_info.items():
+ if interface == 'wg0':
+ my_server_info = info
+ else:
+ my_client_servers[interface] = info
+
+ if interface not in status:
+ continue
+
+ info['public_key'] = status[interface]['public_key']
+ for status_peer in status[interface]['peers']:
+ if status_peer['latest_handshake']:
+ status_peer['latest_handshake'] = \
+ datetime.datetime.fromtimestamp(
+ status_peer['latest_handshake'])
+ public_key = status_peer['public_key']
+ info_peer = info['peers'].setdefault(public_key, {})
+ info_peer['status'] = status_peer
+
+ return {
+ 'my_server': my_server_info,
+ 'my_client': {
+ 'servers': my_client_servers,
+ },
+ }
def find_next_interface():
@@ -38,8 +129,106 @@ def find_next_interface():
def add_server(settings):
- """Add a server."""
+ """Add information for connecting to a server."""
interface_name = find_next_interface()
- settings['common']['name'] = 'WireGuard-' + interface_name
+ settings['common']['name'] = 'WireGuard-Client-' + interface_name
settings['common']['interface'] = interface_name
network.add_connection(settings)
+
+
+def setup_server():
+ """Setup a server connection that clients can connect to."""
+ process = subprocess.run(['wg', 'genkey'], check=True, capture_output=True)
+ private_key = process.stdout.decode().strip()
+ settings = {
+ 'common': {
+ 'name': 'WireGuard-Server-wg0',
+ 'type': WIREGUARD_SETTING,
+ 'zone': 'internal',
+ 'interface': 'wg0'
+ },
+ 'ipv4': {
+ 'method': 'manual',
+ 'address': IP_TEMPLATE.format(1),
+ 'netmask': '255.255.255.0',
+ 'gateway': '',
+ 'dns': '',
+ 'second_dns': '',
+ },
+ 'wireguard': {
+ 'private_key': private_key,
+ 'listen_port': 51820,
+ }
+ }
+ network.add_connection(settings)
+
+
+def _get_next_available_ip_address(settings):
+ """Get the next available IP address to allocate to a client."""
+ allocated_ips = set()
+ for peer_index in range(settings.get_peers_len()):
+ peer = settings.get_peer(peer_index)
+ for ip_index in range(peer.get_allowed_ips_len()):
+ allowed_ip = peer.get_allowed_ip(ip_index)
+ # We assume these are simple IP addresses but they can be subnets.
+ allocated_ips.add(allowed_ip)
+
+ for index in range(2, 254):
+ ip_address = IP_TEMPLATE.format(index)
+ if ip_address not in allocated_ips:
+ return ip_address
+
+ raise IndexError('Reached client limit')
+
+
+def _server_connection():
+ """Return a server connection. Create one if necessary."""
+ connection = network.get_connection_by_interface_name('wg0')
+ if not connection:
+ setup_server()
+
+ for _ in range(10):
+ # XXX: Improve this waiting by doing a synchronous D-Bus operation to
+ # add network manager connection instead.
+ time.sleep(1)
+ connection = network.get_connection_by_interface_name('wg0')
+ if connection:
+ break
+
+ if not connection:
+ raise RuntimeError('Unable to create a server connection.')
+
+ # Retrieve secrets so that when the connection is changed, secrets are
+ # preserved properly.
+ secrets = connection.get_secrets(WIREGUARD_SETTING)
+ connection.update_secrets(WIREGUARD_SETTING, secrets)
+
+ return connection
+
+
+def add_client(public_key):
+ """Add a permission for a client to connect our server."""
+ connection = _server_connection()
+ settings = connection.get_setting_by_name(WIREGUARD_SETTING)
+ peer, _ = settings.get_peer_by_public_key(public_key)
+ if peer:
+ raise ValueError('Peer with public key already exists')
+
+ peer = nm.WireGuardPeer.new()
+ peer.set_public_key(public_key, False)
+ peer.set_persistent_keepalive(25) # To keep NAT 'connections' alive
+ peer.append_allowed_ip(_get_next_available_ip_address(settings), False)
+ settings.append_peer(peer)
+ connection.commit_changes(True)
+
+
+def remove_client(public_key):
+ """Remove permission for a client to connect our server."""
+ connection = _server_connection()
+ settings = connection.get_setting_by_name(WIREGUARD_SETTING)
+ peer, peer_index = settings.get_peer_by_public_key(public_key)
+ if not peer:
+ raise KeyError('Client not found')
+
+ settings.remove_peer(peer_index)
+ connection.commit_changes(True)
diff --git a/plinth/modules/wireguard/views.py b/plinth/modules/wireguard/views.py
index 1e1f72141..1558646a0 100644
--- a/plinth/modules/wireguard/views.py
+++ b/plinth/modules/wireguard/views.py
@@ -29,7 +29,8 @@ from django.utils.translation import ugettext as _
from django.views.generic import FormView, TemplateView
import plinth.modules.wireguard as wireguard
-from plinth import actions, network
+from plinth import network
+from plinth.modules.names.components import DomainName
from plinth.views import AppView
from . import forms, utils
@@ -49,9 +50,8 @@ 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']
+ info = utils.get_info()
+ context['server'] = info['my_server']
context['client_peers'] = info['my_client']['servers']
return context
@@ -72,7 +72,13 @@ class AddClientView(SuccessMessageMixin, FormView):
def form_valid(self, form):
"""Add the client."""
public_key = form.cleaned_data.get('public_key')
- actions.superuser_run('wireguard', ['add-client', public_key])
+ try:
+ utils.add_client(public_key)
+ except ValueError:
+ messages.warning(self.request,
+ _('Client with public key already exists'))
+ return redirect('wireguard:index')
+
return super().form_valid(form)
@@ -86,12 +92,17 @@ class ShowClientView(SuccessMessageMixin, TemplateView):
context['title'] = _('Show Client')
public_key = urllib.parse.unquote(self.kwargs['public_key'])
- info = wireguard.get_info()
- context.update(info)
- for client in info['my_server']['clients']:
- if client['public_key'] == public_key:
- context['client'] = client
+ server_info = utils.get_info()['my_server']
+ if not server_info or public_key not in server_info['peers']:
+ raise Http404
+ domains = DomainName.list_names(filter_for_service='wireguard')
+ context['server'] = server_info
+ context['client'] = server_info['peers'][public_key]
+ context['endpoints'] = [
+ domain + ':' + str(server_info['listen_port'])
+ for domain in domains
+ ]
return context
@@ -117,10 +128,17 @@ class EditClientView(SuccessMessageMixin, FormView):
def form_valid(self, form):
"""Update the client."""
old_public_key = form.initial['public_key']
- actions.superuser_run('wireguard', ['remove-client', old_public_key])
-
public_key = form.cleaned_data.get('public_key')
- actions.superuser_run('wireguard', ['add-client', public_key])
+
+ if old_public_key != public_key:
+ try:
+ utils.add_client(public_key)
+ except ValueError:
+ messages.warning(self.request,
+ _('Client with public key already exists'))
+
+ utils.remove_client(old_public_key)
+
return super().form_valid(form)
@@ -138,8 +156,12 @@ class DeleteClientView(SuccessMessageMixin, TemplateView):
def post(self, request, public_key):
"""Delete the client."""
public_key = urllib.parse.unquote(public_key)
- actions.superuser_run('wireguard', ['remove-client', public_key])
- messages.success(request, _('Client deleted.'))
+ try:
+ utils.remove_client(public_key)
+ messages.success(request, _('Client deleted.'))
+ except KeyError:
+ messages.error(request, _('Client not found'))
+
return redirect('wireguard:index')
@@ -172,7 +194,7 @@ class ShowServerView(SuccessMessageMixin, TemplateView):
context['title'] = _('Server Information')
interface = self.kwargs['interface']
- info = wireguard.get_info()
+ info = utils.get_info()
server = info['my_client']['servers'].get(interface)
if not server:
raise Http404
@@ -199,14 +221,14 @@ class EditServerView(SuccessMessageMixin, FormView):
"""Get initial form data."""
initial = super().get_initial()
interface = self.kwargs['interface']
- info = wireguard.get_nm_info()
+ info = utils.get_nm_info()
server = info.get(interface)
if not server:
raise Http404
initial['ip_address'] = server.get('ip_address')
if server['peers']:
- peer = server['peers'][0]
+ peer = next(peer for peer in server['peers'].values())
initial['peer_endpoint'] = peer['endpoint']
initial['peer_public_key'] = peer['public_key']
initial['private_key'] = server['private_key']
@@ -220,7 +242,7 @@ class EditServerView(SuccessMessageMixin, FormView):
settings = form.get_settings()
interface = self.kwargs['interface']
settings['common']['interface'] = interface
- settings['common']['name'] = 'WireGuard-' + interface
+ settings['common']['name'] = 'WireGuard-Client-' + interface
connection = network.get_connection_by_interface_name(interface)
network.edit_connection(connection, settings)
return super().form_valid(form)
@@ -236,14 +258,14 @@ class DeleteServerView(SuccessMessageMixin, TemplateView):
context['title'] = _('Delete Server')
interface = self.kwargs['interface']
- info = wireguard.get_nm_info()
+ info = utils.get_nm_info()
server = info.get(interface)
if not server:
raise Http404
context['interface'] = interface
if server['peers']:
- peer = server['peers'][0]
+ peer = next(peer for peer in server['peers'].values())
context['peer_endpoint'] = peer['endpoint']
context['peer_public_key'] = peer['public_key']
diff --git a/plinth/network.py b/plinth/network.py
index d491e3083..7d3add55c 100644
--- a/plinth/network.py
+++ b/plinth/network.py
@@ -477,19 +477,27 @@ def _update_wireguard_settings(connection, wireguard):
settings.set_property(nm.SETTING_WIREGUARD_PRIVATE_KEY,
wireguard['private_key'])
- peer = nm.WireGuardPeer.new()
- peer.set_endpoint(wireguard['peer_endpoint'], False)
- peer.set_public_key(wireguard['peer_public_key'], False)
- if wireguard['preshared_key']:
- # Flag NONE means that NM should store and retain the secret.
- # Default seems to be NOT_REQUIRED in this case.
- peer.set_preshared_key_flags(nm.SettingSecretFlags.NONE)
- peer.set_preshared_key(wireguard['preshared_key'], False)
+ if 'listen_port' in wireguard:
+ settings.set_property(nm.SETTING_WIREGUARD_LISTEN_PORT,
+ wireguard['listen_port'])
- peer.append_allowed_ip('0.0.0.0/0', False)
- peer.append_allowed_ip('::/0', False)
- settings.clear_peers()
- settings.append_peer(peer)
+ if 'peer_public_key' in wireguard:
+ peer = nm.WireGuardPeer.new()
+ peer.set_public_key(wireguard['peer_public_key'], False)
+
+ if 'peer_endpoint' in wireguard:
+ peer.set_endpoint(wireguard['peer_endpoint'], False)
+
+ if wireguard['preshared_key']:
+ # Flag NONE means that NM should store and retain the secret.
+ # Default seems to be NOT_REQUIRED in this case.
+ peer.set_preshared_key_flags(nm.SettingSecretFlags.NONE)
+ peer.set_preshared_key(wireguard['preshared_key'], False)
+
+ peer.append_allowed_ip('0.0.0.0/0', False)
+ peer.append_allowed_ip('::/0', False)
+ settings.clear_peers()
+ settings.append_peer(peer)
def _update_settings(connection, connection_uuid, settings):
From 2b9d278a9535f7ee31f25e99f60792576f45b010 Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa {% trans "Latest handshake:" %}
+ {{ peer.status.latest_handshake|default:'' }}
+ {% trans "Server" %}
+ {% trans "As a Server" %}
-
@@ -69,11 +69,15 @@
role="button" class="btn btn-default"
href="{% url 'wireguard:add-client' %}">
- {% trans "Add Client" %}
+ {% trans "Add Allowed Client" %}
-
{% trans "Client" %}
- {% trans "As a Client" %}
+
@@ -112,7 +116,7 @@
role="button" class="btn btn-default"
href="{% url 'wireguard:add-server' %}">
- {% trans "Add Server" %}
+ {% trans "Add Connection to Server" %}
{{ block.super }}
diff --git a/plinth/modules/wireguard/templates/wireguard_add_server.html b/plinth/modules/wireguard/templates/wireguard_add_server.html
index dc508b99c..39df9f286 100644
--- a/plinth/modules/wireguard/templates/wireguard_add_server.html
+++ b/plinth/modules/wireguard/templates/wireguard_add_server.html
@@ -31,7 +31,7 @@
{{ form|bootstrap }}
+ value="{% trans "Add Connection" %}"/>
{% endblock %}
diff --git a/plinth/modules/wireguard/templates/wireguard_delete_client.html b/plinth/modules/wireguard/templates/wireguard_delete_client.html
index b69efd23b..b50c5a8fa 100644
--- a/plinth/modules/wireguard/templates/wireguard_delete_client.html
+++ b/plinth/modules/wireguard/templates/wireguard_delete_client.html
@@ -36,7 +36,7 @@
{% csrf_token %}
+ value="{% trans "Delete" %}"/>
{% endblock %}
diff --git a/plinth/modules/wireguard/templates/wireguard_delete_server.html b/plinth/modules/wireguard/templates/wireguard_delete_server.html
index b36cdf205..635a395cc 100644
--- a/plinth/modules/wireguard/templates/wireguard_delete_server.html
+++ b/plinth/modules/wireguard/templates/wireguard_delete_server.html
@@ -45,7 +45,7 @@
{% csrf_token %}
+ value="{% trans "Delete" %}"/>
{% endblock %}
diff --git a/plinth/modules/wireguard/templates/wireguard_edit_server.html b/plinth/modules/wireguard/templates/wireguard_edit_server.html
index b2f1a6e6c..42722b4e8 100644
--- a/plinth/modules/wireguard/templates/wireguard_edit_server.html
+++ b/plinth/modules/wireguard/templates/wireguard_edit_server.html
@@ -31,7 +31,7 @@
{{ form|bootstrap }}
+ value="{% trans "Update Connection" %}"/>
{% endblock %}
diff --git a/plinth/modules/wireguard/templates/wireguard_show_client.html b/plinth/modules/wireguard/templates/wireguard_show_client.html
index 51fc9edd7..aafd39138 100644
--- a/plinth/modules/wireguard/templates/wireguard_show_client.html
+++ b/plinth/modules/wireguard/templates/wireguard_show_client.html
@@ -22,7 +22,13 @@
{% block content %}
- {% trans "Connection Information" %}
+ {{ title }}
+
@@ -30,7 +36,7 @@
{{ client.public_key }}
-
{% trans "IP address to use:" %}
+ {% trans "IP address to use for client:" %}
{{ client.allowed_ips|join:", " }}
@@ -46,7 +52,7 @@
-
@@ -74,12 +80,12 @@
- {% trans "Edit Client" %}
+ {% trans "Edit" %}
- {% trans "Delete Client" %}
+ {% trans "Delete" %}
diff --git a/plinth/modules/wireguard/templates/wireguard_show_server.html b/plinth/modules/wireguard/templates/wireguard_show_server.html
index 150baab67..4a6764fe4 100644
--- a/plinth/modules/wireguard/templates/wireguard_show_server.html
+++ b/plinth/modules/wireguard/templates/wireguard_show_server.html
@@ -22,24 +22,44 @@
{% block content %}
- {% trans "Server's public key:" %}
+ {% trans "Server public key:" %}
{{ server.public_key }}
{{ title }}
-
-
-
- {% for peer in server.peers.values %}
- {% if forloop.first %}
+ {% for peer in server.peers.values %}
+ {% if forloop.first %}
+
+ {% endif %}
+ {% endfor %}
{{ title }}
+
+
+
+
-
{% trans "Endpoint:" %}
+ {% trans "Server endpoint:" %}
{{ peer.endpoint }}
-
{% trans "Public Key:" %}
+ {% trans "Server public key:" %}
{{ peer.public_key }}
+ {% trans "Pre-shared key:" %}
{{ peer.preshared_key }}
+
+ {% trans "Public key of this machine:" %}
+ {{ server.public_key }}
+
+
+
+ {% trans "IP address of this machine:" %}
+ {{ server.ip_address }}
+ {% trans "Status" %}
+
+
+
+
- {% endif %}
- {% endfor %}
-
- {% trans "Data transmitted:" %}
{{ peer.status.transfer_tx|filesizeformat }}
@@ -52,21 +72,21 @@
{% trans "Latest handshake:" %}
{{ peer.status.latest_handshake|default:'' }}
{{ server.public_key }}
+ {% if server.public_key %}
+ {{ server.public_key }}
+ {% else %}
+ {% trans "Setup FreedomBox Behind a Router" %}
+ {% trans "Choose How You Wish to Configure Your Router" %}
+ {% trans "Freedombox Internet Connectivity" %}
+ {% trans "Connections" %}
From e771ca3b8ec186de79bd35dc71ac4cdb37645a60 Mon Sep 17 00:00:00 2001
From: Nektarios Katakis {% trans "Setup FreedomBox Behind a Router" %}
{% trans "Freedombox Internet Connectivity" %}
- {% trans "Connections" %}