mirror of
https://github.com/wahyd4/home-docker.git
synced 2026-08-08 20:15:03 +10:00
fix(demo-service): correct is_internal_ip() logic bug + add login link to fallback error page
This commit is contained in:
@@ -4,7 +4,7 @@ _ep = _here / "error-page.html"
|
||||
if _ep.exists():
|
||||
AUTH_REQUIRED_HTML = _ep.read_text()
|
||||
else:
|
||||
AUTH_REQUIRED_HTML = """<!DOCTYPE html><html><body style=font-family:sans-serif;display:flex;align-items:center;justify-content:center;height:100vh;margin:0;background:#0b0f19;color:#8b949e><div style=text-align:center><h1>Page not available</h1><p>Try again later.</p></div></body></html>"""
|
||||
AUTH_REQUIRED_HTML = """<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>Unavailable</title></head><body style=font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Inter",sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#0b0f19;color:#8b949e><div style=text-align:center><h1 style=font-size:26px;font-weight:600;color:#c9d1d9;margin-bottom:8px>This page isn't available right now</h1><p style=font-size:14px;color:#6e7681>Try again later.</p><a style=margin-top:24px;display:inline-block;font-size:13px;color:#58a6ff;text-decoration:none;opacity:.7 href="#" onclick="location.href='https://pass.junv.cc/oauth2/start?rd='+encodeURIComponent(location.href);return false">Log in</a></div></body></html>"""
|
||||
|
||||
# Admin UI
|
||||
_ui = _here / "admin-ui.html"
|
||||
|
||||
@@ -27,7 +27,11 @@ import _db
|
||||
app = FastAPI(title="Demo Manager", version="2.0.0")
|
||||
|
||||
# ─── Internal network detection ───────────
|
||||
INTERNAL_NETS = [ipaddress.ip_network("192.168.1.0/24")]
|
||||
INTERNAL_NETS = [
|
||||
ipaddress.ip_network("192.168.1.0/24"),
|
||||
# Router's WAN IP — internal traffic via NAT appears from this IP
|
||||
ipaddress.ip_network("14.137.198.99/32"),
|
||||
]
|
||||
|
||||
|
||||
def is_internal_ip(request: Request) -> bool:
|
||||
@@ -38,10 +42,11 @@ def is_internal_ip(request: Request) -> bool:
|
||||
else:
|
||||
# Fallback: X-Real-IP (set by nginx ingress) or direct connection
|
||||
client_ip = request.headers.get("X-Real-IP", "")
|
||||
if not client_ip and request.client:
|
||||
client_ip = request.client.host
|
||||
else:
|
||||
return False
|
||||
if not client_ip:
|
||||
if request.client:
|
||||
client_ip = request.client.host
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
ip = ipaddress.ip_address(client_ip)
|
||||
return any(ip in net for net in INTERNAL_NETS)
|
||||
|
||||
Reference in New Issue
Block a user