wireguard: Create network manager connection

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 12:29:19 -04:00
parent aed82eca1b
commit 64165c5fbd
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -159,6 +159,28 @@ def subcommand_add_server(arguments):
['ip', 'link', 'add', 'dev', new_interface_name, 'type', 'wireguard'],
check=True)
connection_name = 'WireGuard-' + new_interface_name
subprocess.run(['nmcli', 'con', 'add',
'con-name', connection_name,
'ifname', new_interface_name,
'type', 'wireguard'], check=True)
subprocess.run(['nmcli', 'con', 'modify', connection_name,
'connection.autoconnect', 'TRUE'], check=True)
subprocess.run(['nmcli', 'con', 'modify', connection_name,
'connection.zone', 'internal'], check=True)
subprocess.run(['nmcli', 'con', 'modify', connection_name,
'ipv4.method', 'manual',
'ipv4.addresses', arguments.client_ip + '/24'], check=True)
with open('/var/lib/freedombox/wireguard/privatekey') as private_key_file:
private_key = private_key_file.read().strip()
subprocess.run(['nmcli', 'con', 'modify', connection_name,
'wireguard.private-key', private_key], check=True)
args = ['wg', 'set', new_interface_name, 'peer', arguments.public_key]
if arguments.pre_shared_key:
args += ['preshared-key', arguments.pre_shared_key]