From 228e01f6e98c1c4c4b9e96726b1e5e9c3d66edfb Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Mon, 2 Jun 2025 00:16:41 +0330 Subject: [PATCH] feat: Add --check flag to manage_obfs CLI command Integrates the OBFS status check functionality into the main CLI. Users can now use `cli.py manage_obfs --check` to see if OBFS is active. --- core/cli.py | 20 +++++++++++++------- core/cli_api.py | 4 ++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/cli.py b/core/cli.py index ab0c9f7..32873f1 100644 --- a/core/cli.py +++ b/core/cli.py @@ -250,19 +250,25 @@ def server_info(): @cli.command('manage_obfs') @click.option('--remove', '-r', is_flag=True, help="Remove 'obfs' from config.json.") @click.option('--generate', '-g', is_flag=True, help="Generate new 'obfs' in config.json.") -def manage_obfs(remove: bool, generate: bool): +@click.option('--check', '-c', is_flag=True, help="Check 'obfs' status in config.json.") +def manage_obfs(remove: bool, generate: bool, check: bool): try: - if not remove and not generate: - raise click.UsageError('Error: You must use either --remove or --generate') - if remove and generate: - raise click.UsageError('Error: You cannot use both --remove and --generate at the same time') + options_selected = sum([remove, generate, check]) + if options_selected == 0: + raise click.UsageError('Error: You must use either --remove, --generate, or --check.') + if options_selected > 1: + raise click.UsageError('Error: You can only use one of --remove, --generate, or --check at a time.') if generate: cli_api.enable_hysteria2_obfs() - click.echo('Obfs enabled successfully.') + click.echo('OBFS enabled successfully.') elif remove: cli_api.disable_hysteria2_obfs() - click.echo('Obfs disabled successfully.') + click.echo('OBFS disabled successfully.') + elif check: + status_output = cli_api.check_hysteria2_obfs() + click.echo(status_output) + except Exception as e: click.echo(f'{e}', err=True) diff --git a/core/cli_api.py b/core/cli_api.py index 834da6c..c131c53 100644 --- a/core/cli_api.py +++ b/core/cli_api.py @@ -218,6 +218,10 @@ def disable_hysteria2_obfs(): '''Removes 'obfs' from Hysteria2 configuration.''' run_cmd(['python3', Command.MANAGE_OBFS.value, '--remove']) +def check_hysteria2_obfs(): + '''Removes 'obfs' from Hysteria2 configuration.''' + result = subprocess.run(["python3", Command.MANAGE_OBFS.value, "--check"], check=True, capture_output=True, text=True) + return result.stdout.strip() def enable_hysteria2_masquerade(domain: str): '''Enables masquerade for Hysteria2.'''