From c99f35ad0e1f439638fe22804039481e9fe0754c Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 25 Aug 2026 22:12:06 -0700 Subject: [PATCH] wireguard: Fix auto-adding client when no domains are configured - When no domains are configured, and .local domain is filtered out, an exception is thrown by the auto-add client page. - Don't filter out .local domain. It is still a valid endpoint for peers to connect to. - Instead of showing just one domain, show all the domains as endpoints to connect to. - Don't store private key in the session. It is retained for longer than necessary and also sessions are stored on the disk. Tests: - Remove all configured domains from the system and click 'Add Client Automatically' button. It throws an exception. With the patch, it works. - The Add Client Automatically page shows all the domains as endpoints. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- .../templates/wireguard_auto_add_client.html | 23 +++++++++++----- freedombox/modules/wireguard/views.py | 26 ++++++------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/freedombox/modules/wireguard/templates/wireguard_auto_add_client.html b/freedombox/modules/wireguard/templates/wireguard_auto_add_client.html index 2baa8595d..7fb5ddad8 100644 --- a/freedombox/modules/wireguard/templates/wireguard_auto_add_client.html +++ b/freedombox/modules/wireguard/templates/wireguard_auto_add_client.html @@ -19,17 +19,28 @@ {% if client_privkey %}
- - - - - + + + + + + + + + + + + + + + +
{% trans "IP Address" %}{{ next_ip }}
{% trans "Endpoint" %}{{ endpoint }}
{% trans "Public Key" %}{{ client_pubkey }}
{% trans "Private Key" %}
{% trans "IP Address" %}{{ next_ip }}
{% trans "Endpoint(s)" %}
{% for endpoint in endpoints %}{{ endpoint }}
+{% endfor %}
{% trans "Public Key" %}{{ client_pubkey }}
{% trans "Private Key" %}
{% trans "Click to reveal" %} {{ client_privkey }}
-
diff --git a/freedombox/modules/wireguard/views.py b/freedombox/modules/wireguard/views.py index 6cf909ab7..0ff323bc0 100644 --- a/freedombox/modules/wireguard/views.py +++ b/freedombox/modules/wireguard/views.py @@ -152,11 +152,8 @@ class AutoAddClientView(SuccessMessageMixin, FormView): if server_info: domains = DomainName.list_names(filter_for_service='wireguard') - filtered_domains = [ - domain for domain in domains if not domain.endswith('.local') - ] port = server_info.get('listen_port', 51820) - endpoint = f"{filtered_domains[0]}:{port}" + endpoints = [f'{domain}:{port}' for domain in domains] try: client_privkey, client_pubkey = utils.generate_client_keypair() @@ -167,23 +164,16 @@ class AutoAddClientView(SuccessMessageMixin, FormView): settings = connection.get_setting_by_name(setting_name) next_ip = utils._get_next_available_ip_address(settings) - data = { - 'next_ip': next_ip, - 'client_privkey': client_privkey, - 'client_pubkey': client_pubkey, - 'endpoint': endpoint - } - # Add properties to template context - context['domains'] = filtered_domains - context.update(data) + context['client_pubkey'] = client_pubkey + context['client_privkey'] = client_privkey + context['next_ip'] = next_ip + context['endpoints'] = endpoints # Store info on instance for reuse - self.request.session.update(data) - - except Exception as e: - messages.warning(f"Client key generation failed: {e}") - pass + self.request.session['client_pubkey'] = client_pubkey + except Exception as exception: + messages.warning('Client key generation failed: %s', exception) return context