mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 06:09:57 -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
|
|
@ -470,7 +470,9 @@ def start_hotspot() -> dict:
|
|||
# must be in place first. The address is not known until then; NetworkManager almost
|
||||
# always picks the default, and the file is corrected below if it did not.
|
||||
captive_portal_lib.apply_dnsmasq_config(captive_portal_lib.dnsmasq_config_ip()
|
||||
or captive_portal_lib.DEFAULT_HOTSPOT_IP)
|
||||
or captive_portal_lib.DEFAULT_HOTSPOT_IP)
|
||||
# A new hotspot session: every client sees the portal page again.
|
||||
captive_portal_lib.reset_acknowledged_clients()
|
||||
|
||||
# Create hotspot using NetworkManager
|
||||
logger.info("Starting hotspot on %s with SSID %s", device, ssid)
|
||||
|
|
|
|||
|
|
@ -26,17 +26,22 @@ PROBE_HOSTS = (
|
|||
'nmcheck.gnome.org', # GNOME
|
||||
)
|
||||
|
||||
# Paths those probes request. The Controller redirects each of these to the portal.
|
||||
# Paths those probes request, and the reply each OS takes as "online". The Controller redirects a
|
||||
# probe to the portal until the client has loaded the portal page, then returns the expected
|
||||
# reply so the OS shows its "Done" button and keeps using the hotspot.
|
||||
# `/` is not listed: the dashboard already answers it with HTML, which a probe treats as a portal.
|
||||
PROBE_PATHS = (
|
||||
'/hotspot-detect.html', # Apple
|
||||
'/generate_204', # Android
|
||||
'/connecttest.txt', # Windows 10+
|
||||
'/ncsi.txt', # Windows 7/8
|
||||
'/success.txt', # Firefox
|
||||
'/canonical.html', # Firefox
|
||||
'/check_network_status.txt', # GNOME
|
||||
)
|
||||
PROBE_SUCCESS_RESPONSES = {
|
||||
'/hotspot-detect.html': (200, 'text/html', # Apple
|
||||
'<HTML><HEAD><TITLE>Success</TITLE></HEAD><BODY>Success</BODY></HTML>'),
|
||||
'/generate_204': (204, 'text/plain', ''), # Android
|
||||
'/connecttest.txt': (200, 'text/plain', 'Microsoft Connect Test'), # Windows 10+
|
||||
'/ncsi.txt': (200, 'text/plain', 'Microsoft NCSI'), # Windows 7/8
|
||||
'/success.txt': (200, 'text/plain', 'success\n'), # Firefox
|
||||
'/canonical.html': (200, 'text/html', # Firefox
|
||||
'<meta http-equiv="refresh" content="0;url=https://support.mozilla.org/kb/captive-portal"/>'),
|
||||
'/check_network_status.txt': (200, 'text/plain', 'NetworkManager is online\n'), # GNOME
|
||||
}
|
||||
PROBE_PATHS = tuple(PROBE_SUCCESS_RESPONSES)
|
||||
|
||||
# `http://wrolpi/` also reaches the WROLPi from a hotspot client.
|
||||
FRIENDLY_NAME = 'wrolpi'
|
||||
|
|
@ -128,3 +133,22 @@ def dnsmasq_config_ip() -> Optional[str]:
|
|||
except OSError:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
# Clients (by hotspot IP) which have loaded the portal page. Their later probes get the success
|
||||
# reply. Reset whenever the hotspot starts so a new session shows the page again.
|
||||
_acknowledged_clients: set[str] = set()
|
||||
|
||||
|
||||
def acknowledge_client(ip: str):
|
||||
"""The client at `ip` has seen the portal page; its probes now say "online"."""
|
||||
if ip:
|
||||
_acknowledged_clients.add(ip)
|
||||
|
||||
|
||||
def is_client_acknowledged(ip: str) -> bool:
|
||||
return ip in _acknowledged_clients
|
||||
|
||||
|
||||
def reset_acknowledged_clients():
|
||||
_acknowledged_clients.clear()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue