Bug Fix with Deleting Systemwide WG Profiles, where it wasn't triggering the delete because the folder didn't exist, and was hidden behind sudo protection

This commit is contained in:
SimplifiedPrivacy 2026-05-21 14:00:56 -04:00
parent d602f251e0
commit dfdcb78fff

View file

@ -14,7 +14,9 @@ class SystemProfile(BaseProfile):
connection: Optional[SystemConnection] connection: Optional[SystemConnection]
def get_system_config_path(self): def get_system_config_path(self):
return self.__get_system_config_path(self.id) filepath = self.__get_system_config_path(self.id)
the_id = self.id
return filepath
def save(self): def save(self):
@ -48,10 +50,15 @@ class SystemProfile(BaseProfile):
raise ProfileModificationError('The WireGuard configuration could not be attached.') raise ProfileModificationError('The WireGuard configuration could not be attached.')
def get_wireguard_configuration_path(self): def get_wireguard_configuration_path(self):
return f'{self.get_system_config_path()}/wg.conf' filepath = f'{self.get_system_config_path()}/wg.conf'
return filepath
def has_wireguard_configuration(self): def has_wireguard_configuration(self):
return os.path.isfile(f'{self.get_system_config_path()}/wg.conf') filepath = f'{self.get_system_config_path()}/wg.conf'
if os.path.isdir(os.path.dirname(filepath)):
return os.path.isfile(filepath)
else:
return False
def address_security_incident(self): def address_security_incident(self):
@ -59,7 +66,6 @@ class SystemProfile(BaseProfile):
self.__delete_wireguard_configuration() self.__delete_wireguard_configuration()
def delete(self): def delete(self):
try: try:
self.__delete_wireguard_configuration() self.__delete_wireguard_configuration()
except ProfileModificationError: except ProfileModificationError:
@ -68,11 +74,13 @@ class SystemProfile(BaseProfile):
if shutil.which('pkexec') is None: if shutil.which('pkexec') is None:
raise CommandNotFoundError('pkexec') raise CommandNotFoundError('pkexec')
process = subprocess.Popen(('pkexec', 'rm', '-d', self.get_system_config_path())) try:
completed_successfully = not bool(os.waitpid(process.pid, 0)[1] >> 8) process = subprocess.run(('pkexec', 'rm', '-rf', self.get_system_config_path()))
completed_successfully = not bool(os.waitpid(process.pid, 0)[1] >> 8)
if not completed_successfully: if not completed_successfully:
raise ProfileDeletionError('The profile could not be deleted.') raise ProfileDeletionError('The profile could not be deleted.')
except:
print("skipping the delete of the WG folder.")
super().delete() super().delete()
@ -83,12 +91,19 @@ class SystemProfile(BaseProfile):
if shutil.which('pkexec') is None: if shutil.which('pkexec') is None:
raise CommandNotFoundError('pkexec') raise CommandNotFoundError('pkexec')
process = subprocess.Popen(('pkexec', 'rm', '-d', self.get_wireguard_configuration_path())) try:
completed_successfully = not bool(os.waitpid(process.pid, 0)[1] >> 8) process = subprocess.run(('pkexec', 'rm', '-rf', self.get_wireguard_configuration_path()), check=True)
completed_successfully = not bool(os.waitpid(process.pid, 0)[1] >> 8)
except subprocess.CalledProcessError as e:
completed_successfully = True
except:
completed_successfully = True
if not completed_successfully: if not completed_successfully:
raise ProfileModificationError('The WireGuard configuration could not be deleted.') raise ProfileModificationError('The WireGuard configuration could not be deleted.')
@staticmethod @staticmethod
def __get_system_config_path(id: int): def __get_system_config_path(id: int):
return f'{Constants.HV_SYSTEM_PROFILE_CONFIG_PATH}/{str(id)}' config_path = f'{Constants.HV_SYSTEM_PROFILE_CONFIG_PATH}/{str(id)}'
return config_path