feat(core): add status check for masquerade
This commit is contained in:
21
core/cli.py
21
core/cli.py
@ -401,20 +401,23 @@ def update_geo(country: str):
|
||||
@cli.command('masquerade')
|
||||
@click.option('--remove', '-r', is_flag=True, help="Remove 'masquerade' from config.json.")
|
||||
@click.option('--enable', '-e', is_flag=True, help="Enable 'masquerade' in config.json.")
|
||||
def masquerade(remove: bool, enable: bool):
|
||||
@click.option('--status', '-s', is_flag=True, help="Get 'masquerade' status.")
|
||||
def masquerade(remove: bool, enable: bool, status: bool):
|
||||
'''Manage 'masquerade' in Hysteria2 configuration.'''
|
||||
try:
|
||||
if not remove and not enable:
|
||||
raise click.UsageError('Error: You must use either --remove or --enable')
|
||||
if remove and enable:
|
||||
raise click.UsageError('Error: You cannot use both --remove and --enable at the same time')
|
||||
if sum([remove, enable, status]) != 1:
|
||||
raise click.UsageError('Error: You must use exactly one of --remove, --enable, or --status.')
|
||||
|
||||
if enable:
|
||||
cli_api.enable_hysteria2_masquerade()
|
||||
click.echo('Masquerade enabled successfully.')
|
||||
response = cli_api.enable_hysteria2_masquerade()
|
||||
click.echo(response)
|
||||
elif remove:
|
||||
cli_api.disable_hysteria2_masquerade()
|
||||
click.echo('Masquerade disabled successfully.')
|
||||
response = cli_api.disable_hysteria2_masquerade()
|
||||
click.echo(response)
|
||||
elif status:
|
||||
response = cli_api.get_hysteria2_masquerade_status()
|
||||
click.echo(response)
|
||||
|
||||
except Exception as e:
|
||||
click.echo(f'{e}', err=True)
|
||||
|
||||
|
||||
@ -231,11 +231,15 @@ def check_hysteria2_obfs():
|
||||
|
||||
def enable_hysteria2_masquerade():
|
||||
'''Enables masquerade for Hysteria2.'''
|
||||
run_cmd(['python3', Command.MASQUERADE_SCRIPT.value, '1'])
|
||||
return run_cmd(['python3', Command.MASQUERADE_SCRIPT.value, '1'])
|
||||
|
||||
def disable_hysteria2_masquerade():
|
||||
'''Disables masquerade for Hysteria2.'''
|
||||
run_cmd(['python3', Command.MASQUERADE_SCRIPT.value, '2'])
|
||||
return run_cmd(['python3', Command.MASQUERADE_SCRIPT.value, '2'])
|
||||
|
||||
def get_hysteria2_masquerade_status():
|
||||
'''Gets the current masquerade status for Hysteria2.'''
|
||||
return run_cmd(['python3', Command.MASQUERADE_SCRIPT.value, 'status'])
|
||||
|
||||
|
||||
def get_hysteria2_config_file() -> dict[str, Any]:
|
||||
|
||||
@ -10,10 +10,15 @@ def is_masquerade_enabled():
|
||||
with open(CONFIG_FILE, 'r') as f:
|
||||
config = json.load(f)
|
||||
return "masquerade" in config
|
||||
except Exception as e:
|
||||
print(f"Error reading config: {e}")
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def get_status():
|
||||
if is_masquerade_enabled():
|
||||
print("Enabled")
|
||||
else:
|
||||
print("Disabled")
|
||||
|
||||
def enable_masquerade():
|
||||
try:
|
||||
with open(CONFIG_FILE, 'r') as f:
|
||||
@ -72,9 +77,10 @@ def remove_masquerade():
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python3 masquerade.py {1|2}")
|
||||
print("Usage: python3 masquerade.py {1|2|status}")
|
||||
print("1: Enable Masquerade")
|
||||
print("2: Remove Masquerade")
|
||||
print("status: Get current status")
|
||||
sys.exit(1)
|
||||
|
||||
action = sys.argv[1]
|
||||
@ -85,9 +91,11 @@ def main():
|
||||
elif action == "2":
|
||||
print("Removing 'masquerade' from config.json...")
|
||||
remove_masquerade()
|
||||
elif action == "status":
|
||||
get_status()
|
||||
else:
|
||||
print("Invalid option. Use 1 to enable or 2 to disable masquerade.")
|
||||
print("Invalid option. Use 1, 2, or status.")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
Reference in New Issue
Block a user