feat(web): optional web login and API tokens, off by default (stacked on #674) (#683)

Optional web login, off by default: a device that sets no password behaves
exactly as before. Set under General > Security; then every page and API
route needs a session login or an API token (Authorization: Bearer).
Loopback, the Wi-Fi setup flow in AP mode, static files, captive-portal
probes and a reduced /api/v3/health stay open. Secrets live in the web_auth
section of config_secrets.json and no API returns them.
scripts/reset_web_password.py turns login off. Stacked on #674.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chuck
2026-09-30 09:09:40 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent ba38a83c2c
commit e3c85cece6
23 changed files with 2310 additions and 26 deletions
+62
View File
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log in - LED Matrix Control Panel</title>
<meta name="theme-color" content="#111827">
<link rel="icon" type="image/png" sizes="192x192" href="{{ url_for('static', filename='v3/icons/icon-192.png') }}">
<script>
// Same theme choice as the main interface (base.html), before CSS loads.
(function() {
var theme = null;
try { theme = localStorage.getItem('theme'); } catch (e) { /* private mode */ }
if (!theme) {
try {
theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
} catch (e) { theme = 'light'; }
}
document.documentElement.setAttribute('data-theme', theme);
})();
</script>
<link rel="stylesheet" href="{{ url_for('static', filename='v3/vendor/fontawesome/css/all.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='v3/app.css') }}">
<style>
.login-wrap { max-width: 24rem; margin: 0 auto; padding: 4rem 1rem; }
.login-error { border: 1px solid #fecaca; border-radius: 0.375rem; padding: 0.75rem; }
.login-help { margin-top: 1.5rem; }
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<main class="login-wrap">
<div class="bg-white rounded-lg shadow p-6">
<h1 class="text-lg font-semibold text-gray-900 mb-2">
<i class="fas fa-tv text-blue-600 mr-2" aria-hidden="true"></i>LED Matrix Control
</h1>
<p class="text-sm text-gray-600 mb-6">This display's settings are protected by a password.</p>
{% if error %}
<div class="login-error bg-red-50 text-red-600 text-sm mb-4" role="alert">{{ error }}</div>
{% endif %}
<form method="post" action="{{ url_for('ledmatrix_auth.login') }}" class="space-y-4">
<input type="hidden" name="next" value="{{ next_path }}">
<div class="form-group">
<label for="password" class="block text-sm font-medium text-gray-700">Password</label>
<input type="password" id="password" name="password" required autofocus
autocomplete="current-password" class="form-control mt-1 w-full">
</div>
<button type="submit" class="btn bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-md w-full">
<i class="fas fa-sign-in-alt mr-2" aria-hidden="true"></i>Log in
</button>
</form>
<p class="login-help text-sm text-gray-600">
Forgot it? On the Pi, run
<code class="bg-gray-100 font-mono">sudo python3 ~/LEDMatrix/scripts/reset_web_password.py</code>
(use the folder LEDMatrix is installed in), or open the interface from the Pi itself.
</p>
</div>
</main>
</body>
</html>