Hotspot captive portal: welcome page with the WROLPi's address

Devices that join the hotspot probe a fixed plain-HTTP URL to check for
Internet access.  NetworkManager's shared-mode dnsmasq now resolves those
probe hostnames (and `wrolpi`) to the hotspot address via an include the
Controller writes when the hotspot starts, the probes land on the Controller
(port 80), and are redirected to /portal: "This is your WROLPi, its address is
10.42.0.1, open WROLPi / open the Controller".

Only the probe hostnames are hijacked so the hotspot keeps forwarding
everything else when the WROLPi has an uplink.  The include is corrected and
the connection re-activated once if NetworkManager picked a non-default
subnet.  Writing the include is best-effort; the hotspot starts regardless.

`hotspot.captive_portal` (controller.yaml, default true) toggles the probe
redirects and the include; like the other hotspot settings it applies on the
next hotspot start, so saving while the hotspot is up reports
restart_required and both Controller UIs say so.  The status endpoint gains
the hotspot address and portal URL, shown in both UIs.  repair.sh only
creates the include directory so a disabled setting survives upgrades.
Native only: Docker has no hotspot.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-09-13 19:09:12 -06:00
parent 91f92683ba
commit 6bea09600e
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
17 changed files with 772 additions and 15 deletions

View file

@ -977,6 +977,7 @@
<button id="desktop-btn" class="btn" onclick="toggleSubsystem('desktop')" disabled>Loading...</button>
<button id="vnc-btn" class="btn" onclick="toggleSubsystem('vnc')" disabled>Loading...</button>
</div>
<p id="hotspot-address" style="margin: -0.5rem 0 1rem; color: #aaa; font-size: 0.9rem;" hidden></p>
<details style="margin-bottom: 1rem;">
<summary style="cursor: pointer;">Hotspot Settings</summary>
<div class="modal-form" style="max-width: 24rem; margin-top: 0.5rem;">
@ -996,6 +997,10 @@
style="width: 100%; padding: 0.5rem; margin-bottom: 1rem; background: #1a1a2e; border: 1px solid #333; border-radius: 4px; color: #fff; font-size: 1rem;">
</select>
</label>
<label style="display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem;">
<input type="checkbox" id="hotspot-captive-portal">
Captive portal: show a welcome page (with this WROLPi's address) to devices that join
</label>
<button class="btn btn-primary" onclick="saveHotspotSettings()">Save Hotspot Settings</button>
</div>
</details>
@ -1392,6 +1397,7 @@
id: 'hotspot-btn', label: 'Hotspot',
statusUrl: 'api/hotspot/status', startUrl: 'api/hotspot/start', stopUrl: 'api/hotspot/stop',
isOn: data => data.enabled,
onStatus: showHotspotAddress,
},
bluetooth: {
id: 'bluetooth-btn', label: 'Bluetooth',
@ -1429,6 +1435,7 @@
try {
const data = await apiCall(config.statusUrl);
toggleStates[name] = config.isOn(data);
if (config.onStatus) config.onStatus(data);
btn.title = '';
if (!data.available) {
btn.textContent = `${config.label} Unavailable`;
@ -1481,6 +1488,19 @@
}
}
// Hotspot clients need the address to reach this WROLPi; the portal page tells them.
function showHotspotAddress(data) {
const el = document.getElementById('hotspot-address');
if (!el) return;
if (data.enabled && data.ip) {
el.textContent = `Hotspot address: ${data.ip}`
+ (data.portal_url ? ` · Welcome page: ${data.portal_url}` : ' · Captive portal off');
el.hidden = false;
} else {
el.hidden = true;
}
}
async function loadHotspotSettings() {
const ssidInput = document.getElementById('hotspot-ssid');
if (!ssidInput) return;
@ -1491,6 +1511,7 @@
]);
ssidInput.value = settings.ssid;
document.getElementById('hotspot-password').value = settings.password;
document.getElementById('hotspot-captive-portal').checked = settings.captive_portal !== false;
const select = document.getElementById('hotspot-device');
select.innerHTML = '';
// Keep the saved device selectable even if it is not currently present.
@ -1543,13 +1564,17 @@
const btn = event.target;
btn.disabled = true;
try {
await apiCall('api/hotspot/settings', 'POST', {
const saved = await apiCall('api/hotspot/settings', 'POST', {
ssid: document.getElementById('hotspot-ssid').value,
password: document.getElementById('hotspot-password').value,
device: document.getElementById('hotspot-device').value,
protocol: document.getElementById('hotspot-protocol').value || null,
captive_portal: document.getElementById('hotspot-captive-portal').checked,
});
await updateToggleButton('hotspot');
if (saved.restart_required) {
alert('Saved. Restart the hotspot to apply the new settings.');
}
} catch (e) {
alert(`Failed to save hotspot settings: ${e.message}`);
}

View file

@ -0,0 +1,69 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to WROLPi</title>
<style>
/* Self-contained: shown inside phone sign-in sheets which load nothing external. */
body {
margin: 0;
padding: 2rem 1.25rem;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
background: #1a1a2e;
color: #f0f0f0;
text-align: center;
}
h1 { font-size: 1.6rem; margin: 0 0 0.5rem; }
p { margin: 0.5rem 0; line-height: 1.4; }
.muted { color: #b0b0c0; font-size: 0.95rem; }
.address {
font-family: ui-monospace, Menlo, Consolas, monospace;
font-size: 2.4rem;
font-weight: 700;
margin: 1.25rem 0;
word-break: break-all;
user-select: all;
-webkit-user-select: all;
}
.btn {
display: block;
box-sizing: border-box;
width: 100%;
max-width: 22rem;
margin: 0.75rem auto;
padding: 0.9rem 1rem;
border-radius: 8px;
font-size: 1.1rem;
font-weight: 600;
text-decoration: none;
color: #fff;
background: #6c4fbb;
}
.btn.secondary { background: #2f2f4a; }
.note {
margin-top: 2rem;
padding-top: 1rem;
border-top: 1px solid #333;
}
</style>
</head>
<body>
<h1>This is your WROLPi</h1>
<p class="muted">You are connected to the <strong>{{ ssid }}</strong> hotspot.</p>
<p>The address of this WROLPi is</p>
<div class="address">{{ ip }}</div>
<a class="btn" href="https://{{ ip }}/">Open WROLPi</a>
<a class="btn secondary" href="https://{{ ip }}/controller/">Open the Controller</a>
<div class="note muted">
<p>If these buttons do nothing, close this window and open your browser to
<strong>https://{{ ip }}</strong>.</p>
<p>Your browser will warn about the certificate the first time. That is expected for an
offline WROLPi; continue to the site.</p>
<p>This hotspot does not provide Internet access.</p>
</div>
</body>
</html>