92bed208e0
ARCHITECTURE ============ Backend: FastAPI + uvicorn (port 8000) - JWT authentication with PAM system users - ZFS CLI wrapper with caching (30-60s TTL) - WebSocket pool status broadcaster (30s interval) - Services: auth, zfs_runner, file_manager, shares, identities, system_info - Routers: pools, datasets, snapshots, shares, identities, navigator, system Frontend: Next.js 15 + TypeScript (static export) - Incremental Static Regeneration (ISR) for weak hardware - Type-safe API client (lib/api.ts) - Dark mode + custom Tailwind theme - Pages: Dashboard, Login, Snapshots, Datasets, Shares, etc. DEPLOYMENT ========== Test Target: 192.168.1.179:8090 (Debian LXC) Production: 10.66.120.3:9090 (Raspberry Pi 4GB ARM64) Updater: Automated Gitea-based deployment (update-test.sh, update-pi.sh) FEATURES COMPLETED ================== Phase 3a: Dashboard Quick Stats (System, CPU, Memory, Storage) - Real-time stats with color-coded progress bars - Responsive grid layout (mobile: 1, tablet: 2, desktop: 4 columns) - ISR-optimized for fast loads on weak hardware REBRANDING ========== Renamed throughout: - Project: 'ZFS Manager' → 'ZMB Webui' - Services: 'zfs-manager' → 'zmb-webui' - Systemd units: zfs-manager-backend → zmb-webui-backend - Configuration files and documentation Co-Authored-By: Patrick <patrick@perlbach24.de>
130 lines
3.5 KiB
Python
Executable File
130 lines
3.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
User management CLI tool for ZMB Webui
|
|
Usage:
|
|
python manage_users.py add <username> [password]
|
|
python manage_users.py list
|
|
python manage_users.py delete <username>
|
|
python manage_users.py change-password <username> [password]
|
|
"""
|
|
|
|
import sys
|
|
import getpass
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
|
|
from services.auth import auth_service
|
|
|
|
|
|
def add_user(username: str, password: str = None):
|
|
"""Add new user"""
|
|
if not password:
|
|
password = getpass.getpass(f"Enter password for {username}: ")
|
|
confirm = getpass.getpass("Confirm password: ")
|
|
if password != confirm:
|
|
print("ERROR: Passwords don't match")
|
|
return False
|
|
|
|
try:
|
|
auth_service.add_user(username, password)
|
|
print(f"✓ User '{username}' created successfully")
|
|
return True
|
|
except Exception as e:
|
|
print(f"ERROR: {e}")
|
|
return False
|
|
|
|
|
|
def list_users():
|
|
"""List all users"""
|
|
if not auth_service.users:
|
|
print("No users found")
|
|
return True
|
|
|
|
print("Users:")
|
|
print("-" * 40)
|
|
for username, user_data in auth_service.users.items():
|
|
disabled = " (disabled)" if user_data.get("disabled") else ""
|
|
print(f" {username}{disabled}")
|
|
print("-" * 40)
|
|
return True
|
|
|
|
|
|
def delete_user(username: str):
|
|
"""Delete user"""
|
|
if username not in auth_service.users:
|
|
print(f"ERROR: User '{username}' not found")
|
|
return False
|
|
|
|
confirm = input(f"Are you sure you want to delete '{username}'? (y/N): ")
|
|
if confirm.lower() != 'y':
|
|
print("Cancelled")
|
|
return False
|
|
|
|
del auth_service.users[username]
|
|
auth_service._save_users()
|
|
print(f"✓ User '{username}' deleted")
|
|
return True
|
|
|
|
|
|
def change_password(username: str, password: str = None):
|
|
"""Change user password"""
|
|
if username not in auth_service.users:
|
|
print(f"ERROR: User '{username}' not found")
|
|
return False
|
|
|
|
if not password:
|
|
password = getpass.getpass(f"Enter new password for {username}: ")
|
|
confirm = getpass.getpass("Confirm password: ")
|
|
if password != confirm:
|
|
print("ERROR: Passwords don't match")
|
|
return False
|
|
|
|
auth_service.users[username]["hashed_password"] = auth_service.get_password_hash(password)
|
|
auth_service._save_users()
|
|
print(f"✓ Password changed for '{username}'")
|
|
return True
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
print(__doc__)
|
|
return 1
|
|
|
|
command = sys.argv[1]
|
|
|
|
if command == "add":
|
|
if len(sys.argv) < 3:
|
|
print("Usage: manage_users.py add <username> [password]")
|
|
return 1
|
|
username = sys.argv[2]
|
|
password = sys.argv[3] if len(sys.argv) > 3 else None
|
|
return 0 if add_user(username, password) else 1
|
|
|
|
elif command == "list":
|
|
return 0 if list_users() else 1
|
|
|
|
elif command == "delete":
|
|
if len(sys.argv) < 3:
|
|
print("Usage: manage_users.py delete <username>")
|
|
return 1
|
|
username = sys.argv[2]
|
|
return 0 if delete_user(username) else 1
|
|
|
|
elif command == "change-password":
|
|
if len(sys.argv) < 3:
|
|
print("Usage: manage_users.py change-password <username> [password]")
|
|
return 1
|
|
username = sys.argv[2]
|
|
password = sys.argv[3] if len(sys.argv) > 3 else None
|
|
return 0 if change_password(username, password) else 1
|
|
|
|
else:
|
|
print(f"ERROR: Unknown command '{command}'")
|
|
print(__doc__)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|