Add PWA support to the LifeTrac v25 base-station operator console#83
Add PWA support to the LifeTrac v25 base-station operator console#83Copilot wants to merge 5 commits into
Conversation
|
@copilot so we can create a self signed cert on the base station and achieve HTTPS on the local Ethernet network? We would like PWA to be used on cell phone browser to take advantage of the full screen mode. |
Yes, exactly. Here's the workflow for getting full-screen PWA on a phone over LAN Ethernet: 1. Generate a self-signed cert on the base station (one-time): openssl req -x509 -newkey rsa:2048 -nodes \
-keyout /etc/lifetrac/key.pem \
-out /etc/lifetrac/cert.pem \
-days 3650 \
-subj "/CN=lifetrac-base" \
-addext "subjectAltName=IP:192.168.1.42,DNS:lifetrac-base.local,DNS:localhost"Replace 2. Start uvicorn with TLS: uvicorn web_ui:app --host 0.0.0.0 --port 8443 \
--ssl-keyfile /etc/lifetrac/key.pem \
--ssl-certfile /etc/lifetrac/cert.pem3. Install
Once trusted, navigate to The service worker will also activate after HTTPS is in place, enabling offline fallback if the base station goes briefly unreachable. Full details are in the HTTPS / PWA setup section of BASE_STATION.md. |
|
@copilot could we add a method to download the cert from the HTTP website, then install the cert, then activate the HTTPS website? what other options are there to make the cert handling path easier for the end user? |
Added in commit What's new:
Two env vars control the page:
Other cert options added to
|
|
@copilot can we have the base station check if there is an existing cert on startup, and if there is no cert, create one? this would only need to happen on first boot after install? |
…LIDITY_DAYS constant, rename tmp variables
Done in commit On startup, Key details:
After auto-generation, the operator can point their phone to |
The base-station web UI lacked a web app manifest and service worker, making it impossible to install as a PWA or operate offline. Addresses the question of whether HTTPS is required and how to achieve it on a LAN device, including a guided cert-distribution flow for phone operators. The base station now auto-generates a self-signed TLS certificate on first boot so no manual
opensslcommand is needed.New files
web/manifest.json— Web App Manifest:display: standalone, landscape orientation, shortcuts to/mapand/diagnosticsweb/sw.js— Service worker with targeted caching strategy:loginpage + offline fallback on install/static/*)/api/*and/ws/*— never interceptedweb/offline.html— Fallback page shown on network failure; matches dark console themeweb/icons/icon.svg— Scalable tractor-silhouette icon (purpose: any maskable)web/setup.html— HTTPS bootstrap page (no login required): cert download button, per-OS install instructions (Android, iPhone/iPad, Windows, macOS, Linux), and a direct link to the HTTPS siteModified files
web/index.html—<link rel="manifest">,theme-color, Apple PWA metas, SW registration:web_ui.py— Four new root-level routes plus first-boot cert generation:GET /sw.js— served at/(not/static/) withService-Worker-Allowed: /andCache-Control: no-cacheso the SW controls all pagesGET /manifest.json—application/manifest+jsonGET /cert.pem— serves the public TLS certificate as a download so phones can install it directly from the base station over plain HTTP; the private key is never exposed; returns 404 with guidance when no cert existsGET /setup— servesweb/setup.htmlwith server-injected HTTPS port and cert-availability flag_ensure_self_signed_cert()— called on startup; invokesopensslto generate a self-signed cert+key under/etc/lifetrac/when neither file exists; sets the private key tochmod 600; no-ops if either file is already present so operator-supplied certs are never overwritten; logs a warning and continues ifopensslis not installedBASE_STATION.md— Expanded HTTPS / PWA setup section with four options: self-signed cert +/setuppage walkthrough,mkcertfor automatic OS-trusted certs, HTTPS reverse proxy (nginx/Caddy), andlocalhostaccess. Includes a plain-HTTP vs HTTPS feature table.Configuration
Three env vars control the cert bootstrap endpoints:
LIFETRAC_TLS_CERT/etc/lifetrac/cert.pem/cert.pemand generated on first bootLIFETRAC_TLS_KEY/etc/lifetrac/key.pemLIFETRAC_HTTPS_PORT8443/setuppage linkHTTPS requirement
Full PWA install and offline caching require HTTPS or
localhost. The operator console itself continues to work over plain HTTP; only Add-to-Home-Screen and the service worker are gated on a secure origin.Quickest phone onboarding path
Start the base station — a self-signed cert is auto-generated at
/etc/lifetrac/cert.pemand/etc/lifetrac/key.pemon first boot (requiresopensslto be installed).Start uvicorn with TLS:
http://<ip>:8080/setup, download the cert, follow the per-OS install steps, then tap Open HTTPS Site and use Add to Home Screen for full-screen landscape PWA mode.