Complete Python/NiceGUI rewrite of the Wirezone (Elixir/Phoenix) VPN management platform. All 10 implementation phases delivered. Core stack: - NiceGUI reactive UI with SQLModel ORM on PostgreSQL (asyncpg) - Alembic migrations, Valkey/Redis cache, pydantic-settings config - WireGuard management via subprocess (wg/ip/nft CLIs) - 164 tests passing, 35% code coverage Features: - User/device/rule CRUD with admin and unprivileged roles - Full device config form with per-device WG overrides - WireGuard client config generation with QR codes - REST API (v0) with Bearer token auth for all resources - TOTP MFA with QR registration and challenge flow - OIDC SSO with authlib (provider registry, auto-create users) - Magic link passwordless sign-in via email - SAML SP-initiated SSO with IdP metadata parsing - WebAuthn/FIDO2 security key registration - nftables firewall with per-user chains and masquerade - Background tasks: WG stats polling, VPN session expiry, OIDC token refresh, WAN connectivity checks - Startup reconciliation (DB ↔ WireGuard state sync) - In-memory notification system with header badge - Admin UI: users, devices, rules, settings (3 tabs), diagnostics - Loguru logging with optional timestamped file output Deployment: - Multi-stage Dockerfile (python:3.13-slim) - Docker Compose prod stack (bridge networking, NET_ADMIN, nftables) - Forgejo CI: tests → semantic versioning → Docker registry push - Health endpoint at /api/health
28 lines
943 B
Python
28 lines
943 B
Python
"""Loguru configuration for WireGUI."""
|
|
|
|
import sys
|
|
from datetime import datetime
|
|
|
|
from loguru import logger
|
|
|
|
|
|
def setup_logging(log_to_file: bool = False) -> None:
|
|
"""Configure loguru sinks. Call once at startup."""
|
|
# Remove default stderr sink and re-add with our format
|
|
logger.remove()
|
|
logger.add(
|
|
sys.stderr,
|
|
format="<green>{time:HH:mm:ss}</green> | <level>{level:<7}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan> - <level>{message}</level>",
|
|
level="DEBUG",
|
|
)
|
|
|
|
if log_to_file:
|
|
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
logger.add(
|
|
f"logs/wiregui_{timestamp}.log",
|
|
format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level:<7} | {name}:{function}:{line} - {message}",
|
|
level="DEBUG",
|
|
rotation="10 MB",
|
|
retention="7 days",
|
|
)
|
|
logger.info("File logging enabled: logs/wiregui_{}.log", timestamp)
|