mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-22 07:56:18 -05:00
captive portal: let acknowledged clients finish so the OS offers "Done"
A phone's sign-in sheet only shows "Done" once the OS re-probes and gets the genuine success reply. The Controller now remembers each client (by hotspot IP) that has loaded the portal page and answers its later probes with the reply each OS expects (Apple "Success" HTML, Android 204, Windows "Microsoft Connect Test", ...). The set is cleared when the hotspot starts so a new session shows the page again. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
66151df6c6
commit
f182e64e17
7 changed files with 108 additions and 15 deletions
|
|
@ -9,15 +9,18 @@ import logging
|
|||
from pathlib import Path
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from fastapi.responses import RedirectResponse, Response
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from controller.lib.admin import get_hotspot_device, get_hotspot_ssid
|
||||
from controller.lib.captive_portal import (
|
||||
PORTAL_PATH,
|
||||
PROBE_PATHS,
|
||||
PROBE_SUCCESS_RESPONSES,
|
||||
acknowledge_client,
|
||||
get_hotspot_ip,
|
||||
is_captive_portal_enabled,
|
||||
is_client_acknowledged,
|
||||
)
|
||||
from controller.lib.config import is_docker_mode
|
||||
|
||||
|
|
@ -40,14 +43,22 @@ async def portal(request: Request):
|
|||
if not ip:
|
||||
# Hotspot is down; a page with the wrong address is worse than none.
|
||||
raise HTTPException(status_code=404)
|
||||
# The phone has seen the address; let its next probe succeed so it offers "Done".
|
||||
acknowledge_client(request.client.host if request.client else None)
|
||||
context = {"ip": ip, "ssid": get_hotspot_ssid()}
|
||||
return templates.TemplateResponse(request, "portal.html", context, headers=NO_STORE)
|
||||
|
||||
|
||||
async def probe():
|
||||
"""A connectivity probe. Anything but the expected reply makes the phone show the portal."""
|
||||
async def probe(request: Request):
|
||||
"""
|
||||
A connectivity probe. Anything but the expected reply makes the phone show the portal, so
|
||||
redirect until this client has loaded the portal page, then give the reply it expects.
|
||||
"""
|
||||
if not is_captive_portal_enabled():
|
||||
raise HTTPException(status_code=404)
|
||||
if is_client_acknowledged(request.client.host if request.client else None):
|
||||
status, media_type, body = PROBE_SUCCESS_RESPONSES[request.url.path]
|
||||
return Response(content=body, status_code=status, media_type=media_type, headers=NO_STORE)
|
||||
return RedirectResponse(url=PORTAL_PATH, status_code=302, headers=NO_STORE)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue