mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
wireguard: Remove NM connections when app is uninstalled
Tests: - Install WireGuard and start the server. Uninstall the app and re-install. Without the patch, the connection remain after uninstall. With the patch, the connections are removed after uninstall and return to pristine state after re-install. - Functional tests succeed. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
b0a841c63a
commit
f4b1eb23ac
@ -96,3 +96,8 @@ class WireguardApp(app_module.App):
|
||||
super().setup(old_version)
|
||||
if not old_version:
|
||||
self.enable()
|
||||
|
||||
def uninstall(self):
|
||||
"""De-configure and uninstall the app."""
|
||||
utils.delete_connections()
|
||||
super().uninstall()
|
||||
|
||||
@ -127,6 +127,17 @@ def enable_connections(enable):
|
||||
pass # Connection is already inactive
|
||||
|
||||
|
||||
def delete_connections():
|
||||
"""Remove all WireGuard connections."""
|
||||
setting_name = nm.SETTING_WIREGUARD_SETTING_NAME
|
||||
client = network.get_nm_client()
|
||||
for connection in client.get_connections():
|
||||
if connection.get_connection_type() != setting_name:
|
||||
continue
|
||||
|
||||
connection.delete()
|
||||
|
||||
|
||||
def _get_public_key_from_private_key(private_key):
|
||||
process = subprocess.run(['wg', 'pubkey'], check=True, capture_output=True,
|
||||
input=private_key.encode())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user