diff --git a/core/models/system/SystemProfile.py b/core/models/system/SystemProfile.py index bd00de4..9a41672 100644 --- a/core/models/system/SystemProfile.py +++ b/core/models/system/SystemProfile.py @@ -14,7 +14,9 @@ class SystemProfile(BaseProfile): connection: Optional[SystemConnection] 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): @@ -48,10 +50,15 @@ class SystemProfile(BaseProfile): raise ProfileModificationError('The WireGuard configuration could not be attached.') 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): - 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): @@ -59,7 +66,6 @@ class SystemProfile(BaseProfile): self.__delete_wireguard_configuration() def delete(self): - try: self.__delete_wireguard_configuration() except ProfileModificationError: @@ -68,11 +74,13 @@ class SystemProfile(BaseProfile): if shutil.which('pkexec') is None: raise CommandNotFoundError('pkexec') - process = subprocess.Popen(('pkexec', 'rm', '-d', self.get_system_config_path())) - completed_successfully = not bool(os.waitpid(process.pid, 0)[1] >> 8) - - if not completed_successfully: - raise ProfileDeletionError('The profile could not be deleted.') + try: + 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: + raise ProfileDeletionError('The profile could not be deleted.') + except: + print("skipping the delete of the WG folder.") super().delete() @@ -83,12 +91,19 @@ class SystemProfile(BaseProfile): if shutil.which('pkexec') is None: raise CommandNotFoundError('pkexec') - process = subprocess.Popen(('pkexec', 'rm', '-d', self.get_wireguard_configuration_path())) - completed_successfully = not bool(os.waitpid(process.pid, 0)[1] >> 8) + try: + 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: raise ProfileModificationError('The WireGuard configuration could not be deleted.') @staticmethod 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