diff --git a/core/cli.py b/core/cli.py index a6b416e..ef9a075 100644 --- a/core/cli.py +++ b/core/cli.py @@ -368,6 +368,56 @@ def masquerade(remove: bool, enable: str): except Exception as e: click.echo(f'{e}', err=True) +@cli.group('extra-config') +def extra_config(): + """Manage extra proxy configurations for subscription links.""" + pass + + +@extra_config.command('add') +@click.option('--name', required=True, help='A unique name for the configuration.') +@click.option('--uri', required=True, help='The proxy URI (vmess, vless, ss, trojan).') +def add_extra_config(name: str, uri: str): + """Add a new extra proxy configuration.""" + try: + output = cli_api.add_extra_config(name, uri) + click.echo(output) + except Exception as e: + click.echo(f'{e}', err=True) + + +@extra_config.command('delete') +@click.option('--name', required=True, help='The name of the configuration to delete.') +def delete_extra_config(name: str): + """Delete an extra proxy configuration.""" + try: + output = cli_api.delete_extra_config(name) + click.echo(output) + except Exception as e: + click.echo(f'{e}', err=True) + + +@extra_config.command('list') +def list_extra_configs(): + """List all extra proxy configurations.""" + try: + output = cli_api.list_extra_configs() + click.echo(output) + except Exception as e: + click.echo(f'{e}', err=True) + + +@extra_config.command('get') +@click.option('--name', required=True, help='The name of the configuration to retrieve.') +def get_extra_config(name: str): + """Get a specific extra proxy configuration.""" + try: + res = cli_api.get_extra_config(name) + if res: + pretty_print(res) + except Exception as e: + click.echo(f'{e}', err=True) + # endregion # region Advanced Menu diff --git a/core/cli_api.py b/core/cli_api.py index 3098060..c235dce 100644 --- a/core/cli_api.py +++ b/core/cli_api.py @@ -36,6 +36,7 @@ class Command(Enum): NODE_MANAGER = os.path.join(SCRIPT_DIR, 'hysteria2', 'node.py') MANAGE_OBFS = os.path.join(SCRIPT_DIR, 'hysteria2', 'manage_obfs.py') MASQUERADE_SCRIPT = os.path.join(SCRIPT_DIR, 'hysteria2', 'masquerade.py') + EXTRA_CONFIG_SCRIPT = os.path.join(SCRIPT_DIR, 'hysteria2', 'extra_config.py') TRAFFIC_STATUS = 'traffic.py' # won't be called directly (it's a python module) UPDATE_GEO = os.path.join(SCRIPT_DIR, 'hysteria2', 'update_geo.py') LIST_USERS = os.path.join(SCRIPT_DIR, 'hysteria2', 'list_users.sh') @@ -476,6 +477,25 @@ def update_geo(country: str): except Exception as e: raise HysteriaError(f'An unexpected error occurred: {e}') +def add_extra_config(name: str, uri: str) -> str: + """Adds an extra proxy configuration.""" + return run_cmd(['python3', Command.EXTRA_CONFIG_SCRIPT.value, 'add', '--name', name, '--uri', uri]) + + +def delete_extra_config(name: str) -> str: + """Deletes an extra proxy configuration.""" + return run_cmd(['python3', Command.EXTRA_CONFIG_SCRIPT.value, 'delete', '--name', name]) + + +def list_extra_configs() -> str: + """Lists all extra proxy configurations.""" + return run_cmd(['python3', Command.EXTRA_CONFIG_SCRIPT.value, 'list']) + + +def get_extra_config(name: str) -> dict[str, Any] | None: + """Gets a specific extra proxy configuration.""" + if res := run_cmd(['python3', Command.EXTRA_CONFIG_SCRIPT.value, 'get', '--name', name]): + return json.loads(res) # endregion