Add Colors
This commit is contained in:
53
modify.py
53
modify.py
@ -6,6 +6,13 @@ from datetime import datetime
|
|||||||
|
|
||||||
users_file_path = '/etc/hysteria/users/users.json'
|
users_file_path = '/etc/hysteria/users/users.json'
|
||||||
|
|
||||||
|
def colors():
|
||||||
|
green='\033[0;32m'
|
||||||
|
cyan='\033[0;36m'
|
||||||
|
red='\033[0;31m'
|
||||||
|
NC='\033[0m' # No Color
|
||||||
|
return green, cyan, red, NC
|
||||||
|
|
||||||
def load_users():
|
def load_users():
|
||||||
with open(users_file_path, 'r') as file:
|
with open(users_file_path, 'r') as file:
|
||||||
return json.load(file)
|
return json.load(file)
|
||||||
@ -19,41 +26,49 @@ def generate_password():
|
|||||||
return result.stdout.strip()
|
return result.stdout.strip()
|
||||||
|
|
||||||
def list_users(users):
|
def list_users(users):
|
||||||
|
green, cyan, red, NC = colors()
|
||||||
|
print(f"{green}List of Users{NC}\n")
|
||||||
for i, user in enumerate(users.keys(), start=1):
|
for i, user in enumerate(users.keys(), start=1):
|
||||||
print(f"{i}. {user}")
|
print(f"{cyan}{i}. {user}{NC}")
|
||||||
|
|
||||||
def edit_user(users):
|
def edit_user(users):
|
||||||
|
green, cyan, red, NC = colors()
|
||||||
list_users(users)
|
list_users(users)
|
||||||
try:
|
try:
|
||||||
choice = int(input("Enter the number of the user to edit: "))
|
choice = int(input(f"{green}Enter the number of the user to edit:{NC} "))
|
||||||
username = list(users.keys())[choice - 1]
|
username = list(users.keys())[choice - 1]
|
||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
print("Invalid choice.")
|
print(f"{green}Invalid choice.{NC}")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"Editing user: {username}")
|
print(f"{green}Editing user: {cyan}{username}{NC}")
|
||||||
|
|
||||||
change_password = input(f"Change password? (current: {users[username]['password']}) [y/N]: ").lower() == 'y'
|
change_password = input(f"Change password? (current: {users[username]['password']}) [y/N]: ").lower() == 'y'
|
||||||
if change_password:
|
if change_password:
|
||||||
new_password = generate_password()
|
new_password = generate_password()
|
||||||
users[username]['password'] = new_password
|
users[username]['password'] = new_password
|
||||||
print(f"New password: {new_password}")
|
print(f"{green}New password: {cyan}{new_password}{NC}")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
max_download_gb = input(f"Enter new max download bytes in GB (current: {users[username]['max_download_bytes'] // (1024 ** 3)} GB): ")
|
current_max_download_gb = users[username]['max_download_bytes'] // (1024 ** 3)
|
||||||
if max_download_gb.isdigit():
|
max_download_gb = input(f"Enter new max download bytes in GB (current: {current_max_download_gb} GB, press Enter to keep current): ")
|
||||||
|
if max_download_gb.strip() == '':
|
||||||
|
break
|
||||||
|
elif max_download_gb.isdigit():
|
||||||
users[username]['max_download_bytes'] = int(max_download_gb) * (1024 ** 3)
|
users[username]['max_download_bytes'] = int(max_download_gb) * (1024 ** 3)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Invalid input. Please enter a valid number.")
|
print(f"{red}Invalid input. Please enter a valid number or press Enter to keep current.{NC}")
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
expiration_days = input(f"Enter new expiration days (current: {users[username]['expiration_days']}): ")
|
expiration_days = input(f"Enter new expiration days (current: {users[username]['expiration_days']}, press Enter to keep current): ")
|
||||||
if expiration_days.isdigit():
|
if expiration_days.strip() == '':
|
||||||
|
break
|
||||||
|
elif expiration_days.isdigit():
|
||||||
users[username]['expiration_days'] = int(expiration_days)
|
users[username]['expiration_days'] = int(expiration_days)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Invalid input. Please enter a valid number.")
|
print(f"{red}Invalid input. Please enter a valid number or press Enter to keep current.{NC}")
|
||||||
|
|
||||||
blocked = input(f"Blocked? (current: {users[username]['blocked']}) [true/false]: ").lower()
|
blocked = input(f"Blocked? (current: {users[username]['blocked']}) [true/false]: ").lower()
|
||||||
if blocked:
|
if blocked:
|
||||||
@ -64,24 +79,28 @@ def edit_user(users):
|
|||||||
users[username]['account_creation_date'] = datetime.today().strftime('%Y-%m-%d')
|
users[username]['account_creation_date'] = datetime.today().strftime('%Y-%m-%d')
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
green, cyan, red, NC = colors()
|
||||||
|
|
||||||
if not os.path.exists(users_file_path):
|
if not os.path.exists(users_file_path):
|
||||||
print(f"File {users_file_path} does not exist.")
|
print(f"{red}File {users_file_path} does not exist.{NC}")
|
||||||
return
|
return
|
||||||
|
|
||||||
users = load_users()
|
users = load_users()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
print("1. Edit user")
|
print(f"{green}1. Edit user{NC}")
|
||||||
print("2. Exit")
|
print(f"{red}2. Exit{NC}")
|
||||||
choice = input("Enter your choice: ")
|
choice = input(f"{NC}Enter your choice: {NC}")
|
||||||
|
|
||||||
if choice == "1":
|
if choice == "1":
|
||||||
edit_user(users)
|
edit_user(users)
|
||||||
save_users(users)
|
save_users(users)
|
||||||
elif choice == "2":
|
elif choice == "2":
|
||||||
return
|
print(f"{red}Exiting...{NC}")
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
print("Invalid choice. Please try again.")
|
print(f"{NC}Invalid choice. Please try again.{NC}")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user