feat: Add function to cli_api to get current NormalSub subpath

This commit is contained in:
Whispering Wind
2025-05-17 23:54:32 +03:30
committed by GitHub
parent d86087cf74
commit eaef80b80e

View File

@ -13,6 +13,8 @@ SCRIPT_DIR = '/etc/hysteria/core/scripts'
CONFIG_FILE = '/etc/hysteria/config.json' CONFIG_FILE = '/etc/hysteria/config.json'
CONFIG_ENV_FILE = '/etc/hysteria/.configs.env' CONFIG_ENV_FILE = '/etc/hysteria/.configs.env'
WEBPANEL_ENV_FILE = '/etc/hysteria/core/scripts/webpanel/.env' WEBPANEL_ENV_FILE = '/etc/hysteria/core/scripts/webpanel/.env'
NORMALSUB_ENV_FILE = '/etc/hysteria/core/scripts/normalsub/.env'
class Command(Enum): class Command(Enum):
'''Contains path to command's script''' '''Contains path to command's script'''
@ -519,6 +521,18 @@ def edit_normalsub_subpath(new_subpath: str):
run_cmd(['bash', Command.INSTALL_NORMALSUB.value, 'edit_subpath', new_subpath]) run_cmd(['bash', Command.INSTALL_NORMALSUB.value, 'edit_subpath', new_subpath])
def get_normalsub_subpath() -> str | None:
'''Retrieves the current SUBPATH for the NormalSub service from its .env file.'''
try:
if not os.path.exists(NORMALSUB_ENV_FILE):
return None
env_vars = dotenv_values(NORMALSUB_ENV_FILE)
return env_vars.get('SUBPATH')
except Exception as e:
print(f"Error reading NormalSub .env file: {e}")
return None
def stop_normalsub(): def stop_normalsub():
'''Stops NormalSub.''' '''Stops NormalSub.'''
run_cmd(['bash', Command.INSTALL_NORMALSUB.value, 'stop']) run_cmd(['bash', Command.INSTALL_NORMALSUB.value, 'stop'])