fix: web-based first-run setup — removes terminal input(), works under systemd
This commit is contained in:
@@ -54,6 +54,34 @@ async def logout(authorization: Optional[str] = Header(None)):
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/setup")
|
||||
async def setup_page():
|
||||
from fastapi.responses import FileResponse
|
||||
from auth import has_users
|
||||
from pathlib import Path
|
||||
if has_users():
|
||||
from fastapi.responses import RedirectResponse
|
||||
return RedirectResponse("/")
|
||||
return FileResponse(str(Path(__file__).parent.parent / "frontend" / "setup.html"))
|
||||
|
||||
|
||||
@router.post("/setup")
|
||||
async def setup_post(body: dict):
|
||||
from auth import has_users, create_user
|
||||
from config import load as load_config
|
||||
if has_users():
|
||||
raise HTTPException(status_code=403, detail="Bereits eingerichtet")
|
||||
username = body.get("username", "").strip()
|
||||
password = body.get("password", "")
|
||||
if not username or len(password) < 6:
|
||||
raise HTTPException(status_code=400, detail="Ungültige Eingabe")
|
||||
cfg = load_config()
|
||||
default_dir = cfg["output"]["path"]
|
||||
output_dir = body.get("output_dir") or default_dir
|
||||
create_user(username, password, output_dir, is_admin=True)
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Protected endpoints
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>tüit Transkriptor — Ersteinrichtung</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Overpass:wght@300;400;600;700&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--red: #DA251C;
|
||||
--yellow: #FFD802;
|
||||
--bg: #111;
|
||||
--surface: #1a1a1a;
|
||||
--text: #e8e8e8;
|
||||
--muted: #888;
|
||||
--border: #2e2e2e;
|
||||
}
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
body {
|
||||
font-family: 'Overpass', system-ui, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 12px;
|
||||
padding: 40px;
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
}
|
||||
.logo { display: flex; align-items: center; gap: 10px; }
|
||||
.logo-dot { width: 12px; height: 12px; background: var(--red); border-radius: 50%; flex-shrink: 0; }
|
||||
.logo h1 { font-size: 1.1rem; font-weight: 600; }
|
||||
.logo h1 span { color: var(--red); }
|
||||
.subtitle { font-size: 0.85rem; color: var(--muted); }
|
||||
.field { display: flex; flex-direction: column; gap: 6px; }
|
||||
label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
|
||||
input {
|
||||
background: #111;
|
||||
border: 1px solid var(--border);
|
||||
color: var(--text);
|
||||
border-radius: 6px;
|
||||
padding: 10px 12px;
|
||||
font-family: inherit;
|
||||
font-size: 0.9rem;
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
input:focus { border-color: var(--yellow); }
|
||||
button {
|
||||
background: var(--red);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
padding: 12px;
|
||||
font-family: inherit;
|
||||
font-size: 0.9rem;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.15s;
|
||||
}
|
||||
button:hover { opacity: 0.88; }
|
||||
.error {
|
||||
background: rgba(218,37,28,0.12);
|
||||
border: 1px solid rgba(218,37,28,0.3);
|
||||
border-radius: 6px;
|
||||
padding: 10px 12px;
|
||||
font-size: 0.85rem;
|
||||
color: #f87171;
|
||||
display: none;
|
||||
}
|
||||
.error.visible { display: block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="card">
|
||||
<div class="logo">
|
||||
<div class="logo-dot"></div>
|
||||
<h1>tüit <span>Transkriptor</span></h1>
|
||||
</div>
|
||||
<p class="subtitle">Ersteinrichtung — lege den Administrator-Account an.</p>
|
||||
|
||||
<div class="error" id="error"></div>
|
||||
|
||||
<div class="field">
|
||||
<label for="username">Benutzername</label>
|
||||
<input type="text" id="username" autocomplete="username" autofocus>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="password">Passwort</label>
|
||||
<input type="password" id="password" autocomplete="new-password">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="confirm">Passwort bestätigen</label>
|
||||
<input type="password" id="confirm" autocomplete="new-password">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="output_dir">Transkripte speichern unter</label>
|
||||
<input type="text" id="output_dir" placeholder="~/cloud.shron.de/Hetzner Storagebox/work">
|
||||
</div>
|
||||
|
||||
<button id="submit-btn">Einrichtung abschließen</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.getElementById('submit-btn').addEventListener('click', async () => {
|
||||
const username = document.getElementById('username').value.trim();
|
||||
const password = document.getElementById('password').value;
|
||||
const confirm = document.getElementById('confirm').value;
|
||||
const output_dir = document.getElementById('output_dir').value.trim();
|
||||
const errorEl = document.getElementById('error');
|
||||
|
||||
errorEl.classList.remove('visible');
|
||||
|
||||
if (!username) return showError('Benutzername darf nicht leer sein.');
|
||||
if (password.length < 6) return showError('Passwort muss mindestens 6 Zeichen lang sein.');
|
||||
if (password !== confirm) return showError('Passwörter stimmen nicht überein.');
|
||||
|
||||
const r = await fetch('/setup', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password, output_dir: output_dir || null }),
|
||||
});
|
||||
const data = await r.json();
|
||||
if (data.ok) {
|
||||
window.location.href = '/';
|
||||
} else {
|
||||
showError(data.error || 'Fehler bei der Einrichtung.');
|
||||
}
|
||||
|
||||
function showError(msg) {
|
||||
errorEl.textContent = msg;
|
||||
errorEl.classList.add('visible');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -129,10 +129,6 @@ def run_server(config: uvicorn.Config):
|
||||
# ── Entrypoint ─────────────────────────────────────────────────────────────────
|
||||
|
||||
if __name__ == "__main__":
|
||||
from auth import setup_wizard, has_users
|
||||
if not has_users():
|
||||
setup_wizard()
|
||||
|
||||
cfg = load_config()
|
||||
port = cfg["server"]["port"]
|
||||
host = cfg.get("network", {}).get("host", "127.0.0.1")
|
||||
@@ -152,7 +148,9 @@ if __name__ == "__main__":
|
||||
break
|
||||
time.sleep(0.1)
|
||||
|
||||
webbrowser.open(f"http://localhost:{port}")
|
||||
from auth import has_users
|
||||
start_path = "/setup" if not has_users() else "/"
|
||||
webbrowser.open(f"http://localhost:{port}{start_path}")
|
||||
|
||||
try:
|
||||
run_tray(port)
|
||||
|
||||
Reference in New Issue
Block a user