feat: add show-user-uri-json command

This commit is contained in:
Whispering Wind
2025-04-19 13:12:33 +03:30
committed by GitHub
parent e79123364f
commit 325c130fd0
3 changed files with 94 additions and 1 deletions

View File

@ -28,6 +28,7 @@ class Command(Enum):
RESET_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'reset_user.sh')
REMOVE_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'remove_user.sh')
SHOW_USER_URI = os.path.join(SCRIPT_DIR, 'hysteria2', 'show_user_uri.py')
WRAPPER_URI = os.path.join(SCRIPT_DIR, 'hysteria2', 'wrapper_uri.py')
IP_ADD = os.path.join(SCRIPT_DIR, 'hysteria2', 'ip.sh')
MANAGE_OBFS = os.path.join(SCRIPT_DIR, 'hysteria2', 'manage_obfs.sh')
MASQUERADE_SCRIPT = os.path.join(SCRIPT_DIR, 'hysteria2', 'masquerade.sh')
@ -334,6 +335,25 @@ def show_user_uri(username: str, qrcode: bool, ipv: int, all: bool, singbox: boo
command_args.append('-n')
return run_cmd(command_args)
def show_user_uri_json(usernames: list[str]) -> list[dict[str, Any]] | None:
'''
Displays the URI for a list of users in JSON format.
'''
script_path = Command.WRAPPER_URI.value
if not os.path.exists(script_path):
raise ScriptNotFoundError(f"Wrapper URI script not found at: {script_path}")
try:
process = subprocess.run(['python3', script_path, *usernames], capture_output=True, text=True, check=True)
return json.loads(process.stdout)
except subprocess.CalledProcessError as e:
raise CommandExecutionError(f"Failed to execute wrapper URI script: {e}\nError: {e.stderr}")
except FileNotFoundError:
raise ScriptNotFoundError(f'Script not found: {script_path}')
except json.JSONDecodeError:
raise CommandExecutionError(f"Failed to decode JSON output from script: {script_path}\nOutput: {process.stdout if 'process' in locals() else 'No output'}") # Add process check
except Exception as e:
raise HysteriaError(f'An unexpected error occurred: {e}')
# endregion
# region Server