Adopt revised naming conventions
This commit is contained in:
parent
9e9d825bb8
commit
6b09780eac
13 changed files with 42 additions and 41 deletions
|
@ -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.
|
||||||
|
|
|
@ -6,6 +6,8 @@ import os
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class Constants:
|
class Constants:
|
||||||
|
|
||||||
|
SP_API_BASE_URL: Final[str] = 'https://api.simplifiedprivacy.is/api/v1'
|
||||||
|
|
||||||
HOME: Final[str] = os.path.expanduser('~')
|
HOME: Final[str] = os.path.expanduser('~')
|
||||||
|
|
||||||
SYSTEM_CONFIG_PATH: Final[str] = '/etc'
|
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')
|
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')
|
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'
|
HV_CONFIG_HOME: Final[str] = f'{CONFIG_HOME}/hydra-veil'
|
||||||
SP_DATA_HOME: Final[str] = f'{DATA_HOME}/simplified-privacy'
|
HV_DATA_HOME: Final[str] = f'{DATA_HOME}/hydra-veil'
|
||||||
SP_STATE_HOME: Final[str] = f'{STATE_HOME}/simplified-privacy'
|
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'
|
HV_PROFILE_CONFIG_HOME: Final[str] = f'{HV_CONFIG_HOME}/profiles'
|
||||||
SP_PROFILE_DATA_HOME: Final[str] = f'{SP_DATA_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'
|
HV_STORAGE_DATABASE_PATH: Final[str] = f'{HV_DATA_HOME}/storage.db'
|
||||||
|
|
||||||
SP_API_BASE_URL: Final[str] = 'https://api.simplifiedprivacy.is/api/v1'
|
|
||||||
|
|
|
@ -39,8 +39,8 @@ class ApplicationController:
|
||||||
|
|
||||||
display = ApplicationController.__find_unused_display()
|
display = ApplicationController.__find_unused_display()
|
||||||
|
|
||||||
base_initialization_file_template = open(f'/{Constants.SP_DATA_HOME}/.init.ptpl', 'r').read()
|
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, sp_data_home=Constants.SP_DATA_HOME)
|
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_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)
|
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
|
@staticmethod
|
||||||
def __run_process(initialization_file_path, profile, display, session_state):
|
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()
|
start_time = time.time()
|
||||||
timeout = float(10)
|
timeout = float(10)
|
||||||
|
|
|
@ -112,7 +112,7 @@ class ConnectionController:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def establish_session_connection(profile: SessionProfile, force: Optional[bool] = False, connection_observer: Optional[ConnectionObserver] = None):
|
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)
|
session_state = SessionStateController.get_or_new(profile.id)
|
||||||
|
|
||||||
port_number = None
|
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.write(f'WGConfig = {profile.get_wireguard_configuration_path()}\n\n[Socks5]\nBindAddress = 127.0.0.1:{str(port_number)}\n')
|
||||||
wireproxy_configuration_file.close()
|
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
|
@staticmethod
|
||||||
def establish_proxy_session_connection(profile: SessionProfile, session_directory: str, port_number: int, proxy_port_number: int):
|
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 = 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_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:
|
with open(proxychains_template_file_path, 'r') as proxychains_template_file:
|
||||||
|
|
||||||
|
@ -376,7 +376,7 @@ class ConnectionController:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __with_tor_connection(*args, task: callable, connection_observer: Optional[ConnectionObserver] = None, **kwargs):
|
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()
|
port_number = ConnectionController.get_random_available_port_number()
|
||||||
process = ConnectionController.establish_tor_session_connection(session_directory, port_number)
|
process = ConnectionController.establish_tor_session_connection(session_directory, port_number)
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class BaseProfile:
|
||||||
|
|
||||||
profiles = {}
|
profiles = {}
|
||||||
|
|
||||||
for directory_entry in os.listdir(Constants.SP_PROFILE_CONFIG_HOME):
|
for directory_entry in os.listdir(Constants.HV_PROFILE_CONFIG_HOME):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
id = int(directory_entry)
|
id = int(directory_entry)
|
||||||
|
@ -143,8 +143,8 @@ class BaseProfile:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_config_path(id: int):
|
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
|
@staticmethod
|
||||||
def __get_data_path(id: int):
|
def __get_data_path(id: int):
|
||||||
return f'{Constants.SP_PROFILE_DATA_HOME}/{str(id)}'
|
return f'{Constants.HV_PROFILE_DATA_HOME}/{str(id)}'
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Configuration:
|
||||||
def get():
|
def get():
|
||||||
|
|
||||||
try:
|
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:
|
except FileNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -61,9 +61,9 @@ class Configuration:
|
||||||
def save(configuration):
|
def save(configuration):
|
||||||
|
|
||||||
config_file_contents = f'{configuration.to_json(indent=4)}\n'
|
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:
|
with open(config_file_path, 'w') as config_file:
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Model:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _create_table_if_not_exists(table_name: str, table_definition: str, drop_existing: bool = False):
|
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()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
if drop_existing:
|
if drop_existing:
|
||||||
|
@ -24,7 +24,7 @@ class Model:
|
||||||
if parameters is None:
|
if parameters is None:
|
||||||
parameters = []
|
parameters = []
|
||||||
|
|
||||||
connection = sqlite3.connect(Constants.SP_STORAGE_DATABASE_PATH)
|
connection = sqlite3.connect(Constants.HV_STORAGE_DATABASE_PATH)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
cursor.row_factory = row_factory
|
cursor.row_factory = row_factory
|
||||||
|
@ -37,7 +37,7 @@ class Model:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _query_exists(query: str, parameters):
|
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()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
response = cursor.execute(f'SELECT EXISTS({query})', parameters).fetchone()
|
response = cursor.execute(f'SELECT EXISTS({query})', parameters).fetchone()
|
||||||
|
@ -51,7 +51,7 @@ class Model:
|
||||||
if parameters is None:
|
if parameters is None:
|
||||||
parameters = []
|
parameters = []
|
||||||
|
|
||||||
connection = sqlite3.connect(Constants.SP_STORAGE_DATABASE_PATH)
|
connection = sqlite3.connect(Constants.HV_STORAGE_DATABASE_PATH)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
cursor.row_factory = row_factory
|
cursor.row_factory = row_factory
|
||||||
|
@ -64,7 +64,7 @@ class Model:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _insert_many(query: str, tuple_factory, items):
|
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 = connection.cursor()
|
||||||
|
|
||||||
cursor.executemany(query, map(tuple_factory, items))
|
cursor.executemany(query, map(tuple_factory, items))
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ApplicationVersion(Model):
|
||||||
self.supported = self.is_supported()
|
self.supported = self.is_supported()
|
||||||
|
|
||||||
def get_installation_path(self):
|
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):
|
def is_installed(self):
|
||||||
return os.path.isdir(self.get_installation_path()) and len(os.listdir(self.get_installation_path())) > 0
|
return os.path.isdir(self.get_installation_path()) and len(os.listdir(self.get_installation_path())) > 0
|
||||||
|
|
|
@ -19,7 +19,7 @@ class SessionProfile(BaseProfile):
|
||||||
def attach_proxy_configuration(self, proxy_configuration):
|
def attach_proxy_configuration(self, proxy_configuration):
|
||||||
|
|
||||||
proxy_configuration_file_contents = f'{proxy_configuration.to_json(indent=4)}\n'
|
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()
|
proxy_configuration_file_path = self.get_proxy_configuration_path()
|
||||||
|
|
||||||
|
|
|
@ -101,4 +101,4 @@ class SessionState:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_state_path(id: int):
|
def __get_state_path(id: int):
|
||||||
return f'{Constants.SP_SESSION_STATE_HOME}/{str(id)}'
|
return f'{Constants.HV_SESSION_STATE_HOME}/{str(id)}'
|
||||||
|
|
|
@ -64,4 +64,4 @@ class SystemProfile(BaseProfile):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_system_config_path(id: int):
|
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)}'
|
||||||
|
|
|
@ -58,4 +58,4 @@ class SystemState:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_state_path():
|
def __get_state_path():
|
||||||
return Constants.SP_STATE_HOME
|
return Constants.HV_STATE_HOME
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
[project]
|
[project]
|
||||||
name = "sp-client-core"
|
name = "hydra-veil-core"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Simplified Privacy" },
|
{ 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"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
classifiers = [
|
classifiers = [
|
||||||
|
@ -22,8 +22,8 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Homepage = "https://git.simplifiedprivacy.is/codeking/sp-client-core"
|
Homepage = "https://git.simplifiedprivacy.is/codeking/hydra-veil-core"
|
||||||
Issues = "https://git.simplifiedprivacy.is/codeking/sp-client-core/issues"
|
Issues = "https://git.simplifiedprivacy.is/codeking/hydra-veil-core/issues"
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["hatchling"]
|
requires = ["hatchling"]
|
||||||
|
|
Loading…
Reference in a new issue