diff --git a/README.md b/README.md index 53c5ac6..9a71e41 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# sp-client-core +# hydra-veil-core -The `sp-client-core` library exposes core client logic to higher-level components. +The `hydra-veil-core` library exposes core logic to higher-level components. diff --git a/core/Constants.py b/core/Constants.py index 65da807..3625724 100644 --- a/core/Constants.py +++ b/core/Constants.py @@ -6,6 +6,8 @@ import os @dataclass(frozen=True) class Constants: + SP_API_BASE_URL: Final[str] = 'https://api.simplifiedprivacy.is/api/v1' + HOME: Final[str] = os.path.expanduser('~') SYSTEM_CONFIG_PATH: Final[str] = '/etc' @@ -14,21 +16,20 @@ class Constants: DATA_HOME: Final[str] = os.environ.get('XDG_DATA_HOME') or os.path.join(HOME, '.local/share') STATE_HOME: Final[str] = os.environ.get('XDG_STATE_HOME') or os.path.join(HOME, '.local/state') - SP_SYSTEM_CONFIG_PATH: Final[str] = f'{SYSTEM_CONFIG_PATH}/simplified-privacy' + HV_SYSTEM_CONFIG_PATH: Final[str] = f'{SYSTEM_CONFIG_PATH}/hydra-veil' - SP_CONFIG_HOME: Final[str] = f'{CONFIG_HOME}/simplified-privacy' - SP_DATA_HOME: Final[str] = f'{DATA_HOME}/simplified-privacy' - SP_STATE_HOME: Final[str] = f'{STATE_HOME}/simplified-privacy' + HV_CONFIG_HOME: Final[str] = f'{CONFIG_HOME}/hydra-veil' + HV_DATA_HOME: Final[str] = f'{DATA_HOME}/hydra-veil' + HV_STATE_HOME: Final[str] = f'{STATE_HOME}/hydra-veil' - SP_SYSTEM_PROFILE_CONFIG_PATH: Final[str] = f'{SP_SYSTEM_CONFIG_PATH}/profiles' + HV_SYSTEM_PROFILE_CONFIG_PATH: Final[str] = f'{HV_SYSTEM_CONFIG_PATH}/profiles' - SP_PROFILE_CONFIG_HOME: Final[str] = f'{SP_CONFIG_HOME}/profiles' - SP_PROFILE_DATA_HOME: Final[str] = f'{SP_DATA_HOME}/profiles' + HV_PROFILE_CONFIG_HOME: Final[str] = f'{HV_CONFIG_HOME}/profiles' + HV_PROFILE_DATA_HOME: Final[str] = f'{HV_DATA_HOME}/profiles' - SP_APPLICATION_DATA_HOME: Final[str] = f'{SP_DATA_HOME}/applications' + HV_APPLICATION_DATA_HOME: Final[str] = f'{HV_DATA_HOME}/applications' + HV_RUNTIME_DATA_HOME: Final[str] = f'{HV_DATA_HOME}/runtime' - SP_SESSION_STATE_HOME: Final[str] = f'{SP_STATE_HOME}/sessions' + HV_SESSION_STATE_HOME: Final[str] = f'{HV_STATE_HOME}/sessions' - SP_STORAGE_DATABASE_PATH: Final[str] = f'{SP_DATA_HOME}/storage.db' - - SP_API_BASE_URL: Final[str] = 'https://api.simplifiedprivacy.is/api/v1' + HV_STORAGE_DATABASE_PATH: Final[str] = f'{HV_DATA_HOME}/storage.db' diff --git a/core/controllers/ApplicationController.py b/core/controllers/ApplicationController.py index d72dbc4..340a03a 100644 --- a/core/controllers/ApplicationController.py +++ b/core/controllers/ApplicationController.py @@ -39,8 +39,8 @@ class ApplicationController: display = ApplicationController.__find_unused_display() - base_initialization_file_template = open(f'/{Constants.SP_DATA_HOME}/.init.ptpl', 'r').read() - base_initialization_file_contents = base_initialization_file_template.format(display=display, time_zone=profile.location.time_zone, sp_data_home=Constants.SP_DATA_HOME) + base_initialization_file_template = open(f'/{Constants.HV_RUNTIME_DATA_HOME}/.init.ptpl', 'r').read() + base_initialization_file_contents = base_initialization_file_template.format(display=display, time_zone=profile.location.time_zone, hv_data_home=Constants.HV_DATA_HOME) application_initialization_file_template = open(f'/{version.get_installation_path()}/.init.ptpl', 'r').read() application_initialization_file_contents = application_initialization_file_template.format(application_version_home=version.get_installation_path(), port_number=port_number or -1, home=Constants.HOME, profile_data_path=profile.get_data_path(), config_home=Constants.CONFIG_HOME, application_version_number=version.version_number) @@ -111,7 +111,7 @@ class ApplicationController: @staticmethod def __run_process(initialization_file_path, profile, display, session_state): - virtual_display_process = subprocess.Popen(('/usr/bin/Xephyr', '-ac', '-br', '-title', f'Simplified Privacy - {profile.name or "Unnamed Profile"}', '-screen', profile.resolution, '-no-host-grab', display), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + virtual_display_process = subprocess.Popen(('/usr/bin/Xephyr', '-ac', '-br', '-title', f'Hydra Veil - {profile.name or "Unnamed Profile"}', '-screen', profile.resolution, '-no-host-grab', display), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) start_time = time.time() timeout = float(10) diff --git a/core/controllers/ConnectionController.py b/core/controllers/ConnectionController.py index 2a7766f..5f08f9c 100644 --- a/core/controllers/ConnectionController.py +++ b/core/controllers/ConnectionController.py @@ -112,7 +112,7 @@ class ConnectionController: @staticmethod def establish_session_connection(profile: SessionProfile, force: Optional[bool] = False, connection_observer: Optional[ConnectionObserver] = None): - session_directory = tempfile.mkdtemp(prefix='sp-') + session_directory = tempfile.mkdtemp(prefix='hv-') session_state = SessionStateController.get_or_new(profile.id) port_number = None @@ -231,7 +231,7 @@ class ConnectionController: wireproxy_configuration_file.write(f'WGConfig = {profile.get_wireguard_configuration_path()}\n\n[Socks5]\nBindAddress = 127.0.0.1:{str(port_number)}\n') wireproxy_configuration_file.close() - return subprocess.Popen((f'{Constants.SP_DATA_HOME}/wireproxy/wireproxy', '-c', wireproxy_configuration_file_path), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + return subprocess.Popen((f'{Constants.HV_RUNTIME_DATA_HOME}/wireproxy/wireproxy', '-c', wireproxy_configuration_file_path), stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) @staticmethod def establish_proxy_session_connection(profile: SessionProfile, session_directory: str, port_number: int, proxy_port_number: int): @@ -256,7 +256,7 @@ class ConnectionController: proxychains_proxy_list = f'socks5 127.0.0.1 {port_number}\n' proxychains_proxy_list = proxychains_proxy_list + f'socks5 {proxy_configuration.ip_address} {proxy_configuration.port_number} {proxy_configuration.username} {proxy_configuration.password}' - proxychains_template_file_path = f'{Constants.SP_DATA_HOME}/proxychains.ptpl' + proxychains_template_file_path = f'{Constants.HV_RUNTIME_DATA_HOME}/proxychains.ptpl' with open(proxychains_template_file_path, 'r') as proxychains_template_file: @@ -376,7 +376,7 @@ class ConnectionController: @staticmethod def __with_tor_connection(*args, task: callable, connection_observer: Optional[ConnectionObserver] = None, **kwargs): - session_directory = tempfile.mkdtemp(prefix='sp-') + session_directory = tempfile.mkdtemp(prefix='hv-') port_number = ConnectionController.get_random_available_port_number() process = ConnectionController.establish_tor_session_connection(session_directory, port_number) diff --git a/core/models/BaseProfile.py b/core/models/BaseProfile.py index b64dc4c..0b358d1 100644 --- a/core/models/BaseProfile.py +++ b/core/models/BaseProfile.py @@ -103,7 +103,7 @@ class BaseProfile: profiles = {} - for directory_entry in os.listdir(Constants.SP_PROFILE_CONFIG_HOME): + for directory_entry in os.listdir(Constants.HV_PROFILE_CONFIG_HOME): try: id = int(directory_entry) @@ -143,8 +143,8 @@ class BaseProfile: @staticmethod def __get_config_path(id: int): - return f'{Constants.SP_PROFILE_CONFIG_HOME}/{str(id)}' + return f'{Constants.HV_PROFILE_CONFIG_HOME}/{str(id)}' @staticmethod def __get_data_path(id: int): - return f'{Constants.SP_PROFILE_DATA_HOME}/{str(id)}' + return f'{Constants.HV_PROFILE_DATA_HOME}/{str(id)}' diff --git a/core/models/Configuration.py b/core/models/Configuration.py index 00e1de4..4870923 100644 --- a/core/models/Configuration.py +++ b/core/models/Configuration.py @@ -43,7 +43,7 @@ class Configuration: def get(): try: - config_file_contents = open(f'{Constants.SP_CONFIG_HOME}/config.json', 'r').read() + config_file_contents = open(f'{Constants.HV_CONFIG_HOME}/config.json', 'r').read() except FileNotFoundError: return None @@ -61,9 +61,9 @@ class Configuration: def save(configuration): config_file_contents = f'{configuration.to_json(indent=4)}\n' - os.makedirs(Constants.SP_CONFIG_HOME, exist_ok=True) + os.makedirs(Constants.HV_CONFIG_HOME, exist_ok=True) - config_file_path = f'{Constants.SP_CONFIG_HOME}/config.json' + config_file_path = f'{Constants.HV_CONFIG_HOME}/config.json' with open(config_file_path, 'w') as config_file: diff --git a/core/models/Model.py b/core/models/Model.py index 31c45d4..c5b24db 100644 --- a/core/models/Model.py +++ b/core/models/Model.py @@ -7,7 +7,7 @@ class Model: @staticmethod def _create_table_if_not_exists(table_name: str, table_definition: str, drop_existing: bool = False): - connection = sqlite3.connect(Constants.SP_STORAGE_DATABASE_PATH) + connection = sqlite3.connect(Constants.HV_STORAGE_DATABASE_PATH) cursor = connection.cursor() if drop_existing: @@ -24,7 +24,7 @@ class Model: if parameters is None: parameters = [] - connection = sqlite3.connect(Constants.SP_STORAGE_DATABASE_PATH) + connection = sqlite3.connect(Constants.HV_STORAGE_DATABASE_PATH) cursor = connection.cursor() cursor.row_factory = row_factory @@ -37,7 +37,7 @@ class Model: @staticmethod def _query_exists(query: str, parameters): - connection = sqlite3.connect(Constants.SP_STORAGE_DATABASE_PATH) + connection = sqlite3.connect(Constants.HV_STORAGE_DATABASE_PATH) cursor = connection.cursor() response = cursor.execute(f'SELECT EXISTS({query})', parameters).fetchone() @@ -51,7 +51,7 @@ class Model: if parameters is None: parameters = [] - connection = sqlite3.connect(Constants.SP_STORAGE_DATABASE_PATH) + connection = sqlite3.connect(Constants.HV_STORAGE_DATABASE_PATH) cursor = connection.cursor() cursor.row_factory = row_factory @@ -64,7 +64,7 @@ class Model: @staticmethod def _insert_many(query: str, tuple_factory, items): - connection = sqlite3.connect(Constants.SP_STORAGE_DATABASE_PATH) + connection = sqlite3.connect(Constants.HV_STORAGE_DATABASE_PATH) cursor = connection.cursor() cursor.executemany(query, map(tuple_factory, items)) diff --git a/core/models/session/ApplicationVersion.py b/core/models/session/ApplicationVersion.py index 7fb59c1..3bb2257 100644 --- a/core/models/session/ApplicationVersion.py +++ b/core/models/session/ApplicationVersion.py @@ -66,7 +66,7 @@ class ApplicationVersion(Model): self.supported = self.is_supported() def get_installation_path(self): - return f'{Constants.SP_APPLICATION_DATA_HOME}/{self.application_code}/{self.version_number}' + return f'{Constants.HV_APPLICATION_DATA_HOME}/{self.application_code}/{self.version_number}' def is_installed(self): return os.path.isdir(self.get_installation_path()) and len(os.listdir(self.get_installation_path())) > 0 diff --git a/core/models/session/SessionProfile.py b/core/models/session/SessionProfile.py index af60d20..ce2a6de 100644 --- a/core/models/session/SessionProfile.py +++ b/core/models/session/SessionProfile.py @@ -19,7 +19,7 @@ class SessionProfile(BaseProfile): def attach_proxy_configuration(self, proxy_configuration): proxy_configuration_file_contents = f'{proxy_configuration.to_json(indent=4)}\n' - os.makedirs(Constants.SP_CONFIG_HOME, exist_ok=True) + os.makedirs(Constants.HV_CONFIG_HOME, exist_ok=True) proxy_configuration_file_path = self.get_proxy_configuration_path() diff --git a/core/models/session/SessionState.py b/core/models/session/SessionState.py index 6e12f8c..b63fd1f 100644 --- a/core/models/session/SessionState.py +++ b/core/models/session/SessionState.py @@ -101,4 +101,4 @@ class SessionState: @staticmethod def __get_state_path(id: int): - return f'{Constants.SP_SESSION_STATE_HOME}/{str(id)}' + return f'{Constants.HV_SESSION_STATE_HOME}/{str(id)}' diff --git a/core/models/system/SystemProfile.py b/core/models/system/SystemProfile.py index 105e9fb..68081a9 100644 --- a/core/models/system/SystemProfile.py +++ b/core/models/system/SystemProfile.py @@ -64,4 +64,4 @@ class SystemProfile(BaseProfile): @staticmethod def __get_system_config_path(id: int): - return f'{Constants.SP_SYSTEM_PROFILE_CONFIG_PATH}/{str(id)}' + return f'{Constants.HV_SYSTEM_PROFILE_CONFIG_PATH}/{str(id)}' diff --git a/core/models/system/SystemState.py b/core/models/system/SystemState.py index 6fc9ce4..0b24f30 100644 --- a/core/models/system/SystemState.py +++ b/core/models/system/SystemState.py @@ -58,4 +58,4 @@ class SystemState: @staticmethod def __get_state_path(): - return Constants.SP_STATE_HOME + return Constants.HV_STATE_HOME diff --git a/pyproject.toml b/pyproject.toml index 2f00283..2e375d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] -name = "sp-client-core" +name = "hydra-veil-core" version = "0.0.1" authors = [ { name = "Simplified Privacy" }, ] -description = "A library that exposes core client logic to higher-level components." +description = "A library that exposes core logic to higher-level components." readme = "README.md" requires-python = ">=3.12" classifiers = [ @@ -22,8 +22,8 @@ dependencies = [ ] [project.urls] -Homepage = "https://git.simplifiedprivacy.is/codeking/sp-client-core" -Issues = "https://git.simplifiedprivacy.is/codeking/sp-client-core/issues" +Homepage = "https://git.simplifiedprivacy.is/codeking/hydra-veil-core" +Issues = "https://git.simplifiedprivacy.is/codeking/hydra-veil-core/issues" [build-system] requires = ["hatchling"]