mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
wireguard: Write pre-shared key to tempfile
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
a0ea33d9b6
commit
28bc880dc5
@ -18,6 +18,7 @@
|
|||||||
Views for WireGuard application.
|
Views for WireGuard application.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import tempfile
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
@ -164,14 +165,19 @@ class AddServerView(SuccessMessageMixin, FormView):
|
|||||||
all_outgoing_traffic = form.cleaned_data.get('all_outgoing_traffic')
|
all_outgoing_traffic = form.cleaned_data.get('all_outgoing_traffic')
|
||||||
args = ['add-server', '--endpoint', endpoint, '--client-ip',
|
args = ['add-server', '--endpoint', endpoint, '--client-ip',
|
||||||
client_ip_address, '--public-key', public_key]
|
client_ip_address, '--public-key', public_key]
|
||||||
|
optional_psk_file = None
|
||||||
if pre_shared_key:
|
if pre_shared_key:
|
||||||
# TODO: pass pre-shared key through stdin
|
optional_psk_file = tempfile.NamedTemporaryFile()
|
||||||
args += ['--pre-shared-key', pre_shared_key]
|
optional_psk_file.write(pre_shared_key.encode())
|
||||||
|
args += ['--pre-shared-key', optional_psk_file.name]
|
||||||
|
|
||||||
if all_outgoing_traffic:
|
if all_outgoing_traffic:
|
||||||
args.append('--all-outgoing')
|
args.append('--all-outgoing')
|
||||||
|
|
||||||
actions.superuser_run('wireguard', args)
|
actions.superuser_run('wireguard', args)
|
||||||
|
if optional_psk_file:
|
||||||
|
optional_psk_file.close()
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
@ -236,14 +242,19 @@ class EditServerView(SuccessMessageMixin, FormView):
|
|||||||
all_outgoing_traffic = form.cleaned_data.get('all_outgoing_traffic')
|
all_outgoing_traffic = form.cleaned_data.get('all_outgoing_traffic')
|
||||||
args = ['modify-server', '--endpoint', endpoint, '--client-ip',
|
args = ['modify-server', '--endpoint', endpoint, '--client-ip',
|
||||||
client_ip_address, '--public-key', public_key]
|
client_ip_address, '--public-key', public_key]
|
||||||
|
optional_psk_file = None
|
||||||
if pre_shared_key:
|
if pre_shared_key:
|
||||||
# TODO: pass pre-shared key through stdin
|
optional_psk_file = tempfile.NamedTemporaryFile()
|
||||||
args += ['--pre-shared-key', pre_shared_key]
|
optional_psk_file.write(pre_shared_key.encode())
|
||||||
|
args += ['--pre-shared-key', optional_psk_file.name]
|
||||||
|
|
||||||
if all_outgoing_traffic:
|
if all_outgoing_traffic:
|
||||||
args.append('--all-outgoing')
|
args.append('--all-outgoing')
|
||||||
|
|
||||||
actions.superuser_run('wireguard', args)
|
actions.superuser_run('wireguard', args)
|
||||||
|
if optional_psk_file:
|
||||||
|
optional_psk_file.close()
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user