feat(cli): add bulk user creation command

This commit is contained in:
Whispering Wind
2025-08-20 23:22:29 +03:30
committed by GitHub
parent c1a60cbf32
commit 8341f23611
2 changed files with 33 additions and 0 deletions

View File

@ -138,6 +138,20 @@ def add_user(username: str, traffic_limit: int, expiration_days: int, password:
except Exception as e:
click.echo(f'{e}', err=True)
@cli.command('bulk-user-add')
@click.option('--traffic-gb', '-t', required=True, help='Traffic limit for each user in GB.', type=float)
@click.option('--expiration-days', '-e', required=True, help='Expiration duration for each user in days.', type=int)
@click.option('--count', '-c', required=True, help='Number of users to create.', type=int)
@click.option('--prefix', '-p', required=True, help='Prefix for usernames.', type=str)
@click.option('--start-number', '-s', default=1, help='Starting number for username suffix.', type=int)
@click.option('--unlimited', is_flag=True, default=False, help='Flag to mark users as unlimited (exempt from IP limits).')
def bulk_user_add(traffic_gb: float, expiration_days: int, count: int, prefix: str, start_number: int, unlimited: bool):
"""Adds multiple users in bulk."""
try:
cli_api.bulk_user_add(traffic_gb, expiration_days, count, prefix, start_number, unlimited)
click.echo(f"Successfully initiated the creation of {count} users with prefix '{prefix}'.")
except Exception as e:
click.echo(f'Error during bulk user addition: {e}', err=True)
@cli.command('edit-user')
@click.option('--username', '-u', required=True, help='Username for the user to edit', type=str)

View File

@ -27,6 +27,7 @@ class Command(Enum):
CHANGE_SNI_HYSTERIA2 = os.path.join(SCRIPT_DIR, 'hysteria2', 'change_sni.py')
GET_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'get_user.py')
ADD_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'add_user.py')
BULK_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'bulk_users.py')
EDIT_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'edit_user.sh')
RESET_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'reset_user.py')
REMOVE_USER = os.path.join(SCRIPT_DIR, 'hysteria2', 'remove_user.py')
@ -285,6 +286,24 @@ def add_user(username: str, traffic_limit: int, expiration_days: int, password:
run_cmd(command)
def bulk_user_add(traffic_gb: float, expiration_days: int, count: int, prefix: str, start_number: int, unlimited: bool):
"""
Executes the bulk user creation script with specified parameters.
"""
command = [
'python3',
Command.BULK_USER.value,
'--traffic-gb', str(traffic_gb),
'--expiration-days', str(expiration_days),
'--count', str(count),
'--prefix', prefix,
'--start-number', str(start_number)
]
if unlimited:
command.append('--unlimited')
run_cmd(command)
def edit_user(username: str, new_username: str | None, new_traffic_limit: int | None, new_expiration_days: int | None, renew_password: bool, renew_creation_date: bool, blocked: bool | None, unlimited_ip: bool | None):
'''