mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
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 <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
5c2fe7a3d1
commit
c99f35ad0e
@ -19,17 +19,28 @@
|
||||
{% if client_privkey %}
|
||||
<div class="form-group">
|
||||
<table class="table table-sm">
|
||||
<tr><td>{% trans "IP Address" %}</td><td>{{ next_ip }}</td></tr>
|
||||
<tr><td>{% trans "Endpoint" %}</td><td>{{ endpoint }}</td></tr>
|
||||
<tr><td>{% trans "Public Key" %}</td>
|
||||
<td class="pubkey-val">{{ client_pubkey }}</td></tr>
|
||||
<tr><td>{% trans "Private Key" %}</td>
|
||||
<tr>
|
||||
<td>{% trans "IP Address" %}</td>
|
||||
<td>{{ next_ip }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{% trans "Endpoint(s)" %}</td>
|
||||
<td><pre>{% for endpoint in endpoints %}{{ endpoint }}
|
||||
{% endfor %}</pre></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{% trans "Public Key" %}</td>
|
||||
<td class="pubkey-val">{{ client_pubkey }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{% trans "Private Key" %}</td>
|
||||
<td>
|
||||
<details class="privkey-val">
|
||||
<summary>{% trans "Click to reveal" %}</summary>
|
||||
{{ client_privkey }}
|
||||
</details>
|
||||
</td></tr>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user