wireguard: Encode public keys for use in URLs

Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
James Valleroy 2019-09-15 20:07:36 -04:00
parent 64165c5fbd
commit 6b39aa8075
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 9 additions and 6 deletions

View File

@ -37,13 +37,13 @@
{% for peer in server_peers %}
<tr>
<td>
<a href="{% url 'wireguard:show-client' peer.public_key %}">
<a href="{% url 'wireguard:show-client' peer.public_key|urlencode:'' %}">
{{ peer.public_key }}
</a>
</td>
<td>{{ peer.latest_handshake }}</td>
<td><a class="btn btn-sm btn-default"
href="{% url 'wireguard:delete-client' peer.public_key %}">
href="{% url 'wireguard:delete-client' peer.public_key|urlencode:'' %}">
<span class="fa fa-trash-o" aria-hidden="true">
</span>
</td>
@ -83,7 +83,7 @@
<tr>
<td>{{ peer.endpoint }}</td>
<td>
<a href="{% url 'wireguard:show-server' peer.public_key %}">
<a href="{% url 'wireguard:show-server' peer.public_key|urlencode:'' %}">
{{ peer.public_key }}
</a>
</td>

View File

@ -18,6 +18,8 @@
Views for WireGuard application.
"""
import urllib.parse
from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.shortcuts import redirect
@ -82,7 +84,7 @@ class ShowClientView(SuccessMessageMixin, TemplateView):
context = super().get_context_data(**kwargs)
context['title'] = _('Show Client')
public_key = self.kwargs['public_key']
public_key = urllib.parse.unquote(self.kwargs['public_key'])
info = wireguard.get_info()
context.update(info)
for client in info['my_server']['clients']:
@ -100,11 +102,12 @@ class DeleteClientView(SuccessMessageMixin, TemplateView):
"""Return additional context data for rendering the template."""
context = super().get_context_data(**kwargs)
context['title'] = _('Delete Client')
context['public_key'] = self.kwargs['public_key']
context['public_key'] = urllib.parse.unquote(self.kwargs['public_key'])
return context
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.'))
return redirect('wireguard:index')
@ -152,7 +155,7 @@ class ShowServerView(SuccessMessageMixin, TemplateView):
context = super().get_context_data(**kwargs)
context['title'] = _('Show Server')
public_key = self.kwargs['public_key']
public_key = urllib.parse.unquote(self.kwargs['public_key'])
info = wireguard.get_info()
context.update(info)
for server in info['my_client']['servers']: