feat(cli): Integrate unlimited IP option for user creation
This commit is contained in:
@ -130,9 +130,10 @@ def get_user(username: str):
|
|||||||
@click.option('--expiration-days', '-e', required=True, help='Expiration days for the new user', type=int)
|
@click.option('--expiration-days', '-e', required=True, help='Expiration days for the new user', type=int)
|
||||||
@click.option('--password', '-p', required=False, help='Password for the user', type=str)
|
@click.option('--password', '-p', required=False, help='Password for the user', type=str)
|
||||||
@click.option('--creation-date', '-c', required=False, help='Creation date for the user (YYYY-MM-DD)', type=str)
|
@click.option('--creation-date', '-c', required=False, help='Creation date for the user (YYYY-MM-DD)', type=str)
|
||||||
def add_user(username: str, traffic_limit: int, expiration_days: int, password: str, creation_date: str):
|
@click.option('--unlimited', is_flag=True, default=True, help='Exempt user from IP limit checks.')
|
||||||
|
def add_user(username: str, traffic_limit: int, expiration_days: int, password: str, creation_date: str, unlimited: bool):
|
||||||
try:
|
try:
|
||||||
cli_api.add_user(username, traffic_limit, expiration_days, password, creation_date)
|
cli_api.add_user(username, traffic_limit, expiration_days, password, creation_date, unlimited)
|
||||||
click.echo(f"User '{username}' added successfully.")
|
click.echo(f"User '{username}' added successfully.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
click.echo(f'{e}', err=True)
|
click.echo(f'{e}', err=True)
|
||||||
|
|||||||
@ -266,15 +266,23 @@ def get_user(username: str) -> dict[str, Any] | None:
|
|||||||
return json.loads(res)
|
return json.loads(res)
|
||||||
|
|
||||||
|
|
||||||
def add_user(username: str, traffic_limit: int, expiration_days: int, password: str | None, creation_date: str | None):
|
def add_user(username: str, traffic_limit: int, expiration_days: int, password: str | None, creation_date: str | None, unlimited: bool):
|
||||||
'''
|
'''
|
||||||
Adds a new user with the given parameters.
|
Adds a new user with the given parameters, respecting positional argument requirements.
|
||||||
'''
|
'''
|
||||||
if not password:
|
command = ['python3', Command.ADD_USER.value, username, str(traffic_limit), str(expiration_days)]
|
||||||
password = generate_password()
|
|
||||||
if not creation_date:
|
if unlimited:
|
||||||
creation_date = datetime.now().strftime('%Y-%m-%d')
|
final_password = password if password else generate_password()
|
||||||
run_cmd(['python3', Command.ADD_USER.value, username, str(traffic_limit), str(expiration_days), password, creation_date])
|
final_creation_date = creation_date if creation_date else datetime.now().strftime('%Y-%m-%d')
|
||||||
|
command.extend([final_password, final_creation_date, 'true'])
|
||||||
|
elif creation_date:
|
||||||
|
final_password = password if password else generate_password()
|
||||||
|
command.extend([final_password, creation_date])
|
||||||
|
elif password:
|
||||||
|
command.append(password)
|
||||||
|
|
||||||
|
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):
|
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):
|
||||||
|
|||||||
@ -9,7 +9,7 @@ from datetime import datetime
|
|||||||
from init_paths import *
|
from init_paths import *
|
||||||
from paths import *
|
from paths import *
|
||||||
|
|
||||||
def add_user(username, traffic_gb, expiration_days, password=None, creation_date=None, unlimited_user=False):
|
def add_user(username, traffic_gb, expiration_days, password=None, creation_date=None, unlimited_user=True):
|
||||||
"""
|
"""
|
||||||
Adds a new user to the USERS_FILE.
|
Adds a new user to the USERS_FILE.
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ def add_user(username, traffic_gb, expiration_days, password=None, creation_date
|
|||||||
expiration_days (str): The number of days until the account expires.
|
expiration_days (str): The number of days until the account expires.
|
||||||
password (str, optional): The user's password. If None, a random one is generated.
|
password (str, optional): The user's password. If None, a random one is generated.
|
||||||
creation_date (str, optional): The account creation date in YYYY-MM-DD format. If None, the current date is used.
|
creation_date (str, optional): The account creation date in YYYY-MM-DD format. If None, the current date is used.
|
||||||
unlimited_user (bool, optional): If True, user is exempt from IP limits. Defaults to False.
|
unlimited_user (bool, optional): If True, user is exempt from IP limits. Defaults to True.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: 0 on success, 1 on failure.
|
int: 0 on success, 1 on failure.
|
||||||
|
|||||||
Reference in New Issue
Block a user