How cherryshine/project-wifi-autologin works
Project type and purpose
• This is a lightweight, macOS-only Hammerspoon automation script (init.lua) that auto-logs into a captive-portal Wi-Fi (KBU_PUBLIC).
• Purpose: Detect when macOS connects to KBU_PUBLIC, extract dynamic tokens from the portal page, submit credentials, verify internet connectivity, and display status via menu-bar alerts.
File structure
• Top-level files only:
• README.md – project description, setup, usage, logs
• init.lua – the entire automation logic
• No subdirectories, no build scripts, no external services inside the repo.
Key insights from README
• Relies on Hammerspoon’s Lua API (hs.wifi, hs.http, hs.timer, hs.alert).
• Workflow: Wi-Fi state change → captive-portal detection → HTTP GET/POST → token parsing → login confirmation → user alert.
• Dependencies: macOS, Hammerspoon, plain text credentials.
Main components
a. Hammerspoon host (macOS runtime)
b. Network subsystem (macOS Wi-Fi driver / Captive Portal)
c. Script modules inside init.lua:
• Wi-Fi Watcher (hs.wifi callback)
• HTTP Client (hs.http.request)
• Token Extractor (pattern matching in HTML)
• Login Manager (POST credentials + token)
• Connectivity Checker (simple GET to known site)
• Notifier (hs.alert for menu-bar notifications)
d. External systems:
• Captive Portal Web Server (login page endpoint)
• Internet (target site for connectivity test)
Architectural patterns and principles
• Event-driven: trigger on network state changes
• Modular separation: each logical concern (watching, HTTP, parsing, notifications) lives in its own function or block
• Single-process, single-threaded automation
• Resilience: retry logic on failure, idempotent login attempts
Technologies, frameworks, libraries
• Hammerspoon’s Lua environment
• hs.wifi, hs.http, hs.timer, hs.alert modules
• Standard Lua string matching for token extraction