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.
This commit is contained in:
Whispering Wind
2025-06-02 00:16:41 +03:30
committed by GitHub
parent 3ddb981077
commit 228e01f6e9
2 changed files with 17 additions and 7 deletions

View File

@ -250,19 +250,25 @@ def server_info():
@cli.command('manage_obfs') @cli.command('manage_obfs')
@click.option('--remove', '-r', is_flag=True, help="Remove 'obfs' from config.json.") @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.") @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: try:
if not remove and not generate: options_selected = sum([remove, generate, check])
raise click.UsageError('Error: You must use either --remove or --generate') if options_selected == 0:
if remove and generate: raise click.UsageError('Error: You must use either --remove, --generate, or --check.')
raise click.UsageError('Error: You cannot use both --remove and --generate at the same time') if options_selected > 1:
raise click.UsageError('Error: You can only use one of --remove, --generate, or --check at a time.')
if generate: if generate:
cli_api.enable_hysteria2_obfs() cli_api.enable_hysteria2_obfs()
click.echo('Obfs enabled successfully.') click.echo('OBFS enabled successfully.')
elif remove: elif remove:
cli_api.disable_hysteria2_obfs() 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: except Exception as e:
click.echo(f'{e}', err=True) click.echo(f'{e}', err=True)

View File

@ -218,6 +218,10 @@ def disable_hysteria2_obfs():
'''Removes 'obfs' from Hysteria2 configuration.''' '''Removes 'obfs' from Hysteria2 configuration.'''
run_cmd(['python3', Command.MANAGE_OBFS.value, '--remove']) 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): def enable_hysteria2_masquerade(domain: str):
'''Enables masquerade for Hysteria2.''' '''Enables masquerade for Hysteria2.'''