diff --git a/plinth/modules/wireguard/__init__.py b/plinth/modules/wireguard/__init__.py index 5b17cfbd2..554465379 100644 --- a/plinth/modules/wireguard/__init__.py +++ b/plinth/modules/wireguard/__init__.py @@ -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() diff --git a/plinth/modules/wireguard/utils.py b/plinth/modules/wireguard/utils.py index 2d7b56c79..ecb97581f 100644 --- a/plinth/modules/wireguard/utils.py +++ b/plinth/modules/wireguard/utils.py @@ -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())