feat: LAN detection via ping probe for Tailscale clients at home
Deploy Dashboard / deploy (push) Successful in 1m16s
Deploy Dashboard / deploy (push) Successful in 1m16s
This commit is contained in:
@@ -116,7 +116,20 @@ async def health():
|
|||||||
|
|
||||||
@app.get("/api/client-ip")
|
@app.get("/api/client-ip")
|
||||||
async def client_ip(request: Request):
|
async def client_ip(request: Request):
|
||||||
return {"ip": request.client.host}
|
ip = request.client.host
|
||||||
|
if ip.startswith("192.168.31."):
|
||||||
|
return {"ip": ip, "lan": True}
|
||||||
|
# Tailscale client — check if Mac is reachable on LAN
|
||||||
|
if ip.startswith("100."):
|
||||||
|
try:
|
||||||
|
proc = await asyncio.create_subprocess_exec(
|
||||||
|
"ping", "-c", "1", "-W", "1", "192.168.31.2",
|
||||||
|
stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
return {"ip": ip, "lan": await asyncio.wait_for(proc.wait(), 2) == 0}
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return {"ip": ip, "lan": False}
|
||||||
|
|
||||||
# Public auth endpoints
|
# Public auth endpoints
|
||||||
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
|
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
if (typeof window !== "undefined") {
|
if (typeof window !== "undefined") {
|
||||||
fetch("/api/client-ip").then(r => r.json()).then(d => {
|
fetch("/api/client-ip").then(r => r.json()).then(d => {
|
||||||
if (d.ip?.startsWith("192.168.31.")) lanReachable = true;
|
if (d.lan) lanReachable = true;
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user