Files
rustguac/static/index.html
T
Dave Kempe 67101e27ce Initial public release
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 14:38:53 +11:00

140 lines
5.5 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>rustguac</title>
<style>
:root { --primary: #e94560; --primary-hover: #c73652; --accent: #5bc0be; --accent-hover: #4aa3a1; --bg: #1a1a2e; --surface: #16213e; --input: #0f3460; --text: #e0e0e0; --text-muted: #aaa; --border: #333; }
body { font-family: monospace; background: var(--bg); color: var(--text); padding: 2em; font-size: 18px; }
h1 { color: var(--primary); }
form {
background: var(--surface);
padding: 1.5em;
border-radius: 6px;
max-width: 360px;
margin: 2em 0;
}
label { display: block; margin-top: 0.8em; color: var(--text-muted); font-size: 0.9em; }
input {
display: block;
width: 100%;
padding: 0.4em;
margin-top: 0.2em;
background: var(--input);
border: 1px solid var(--border);
color: var(--text);
font-family: monospace;
font-size: 1em;
border-radius: 3px;
box-sizing: border-box;
}
input:focus { outline: none; border-color: var(--primary); }
button {
margin-top: 1.2em;
padding: 0.5em 1.5em;
background: var(--primary);
color: #fff;
border: none;
font-family: monospace;
font-size: 1em;
border-radius: 3px;
cursor: pointer;
}
button:hover { background: var(--primary-hover); }
button:disabled { background: #555; cursor: default; }
#error { color: var(--primary); margin-top: 0.8em; }
</style>
</head>
<body>
<img id="site-logo" src="/logo.svg" style="max-height:64px;margin-bottom:0.5em" alt="">
<h1>rustguac</h1>
<form id="login-form">
<strong>Login</strong>
<label>API Key
<input type="password" id="api-key" placeholder="Bearer API key" required>
</label>
<button type="submit" id="login-btn">Login</button>
<div id="error"></div>
</form>
<div id="sso-section" style="display:none; max-width: 360px; margin: 0;">
<div style="text-align: center; color: #666; margin: 1em 0;">— or —</div>
<button id="sso-btn" style="width:100%;padding:0.6em;background:var(--accent);color:var(--bg);border:none;font-family:monospace;font-size:1em;border-radius:3px;cursor:pointer;">Sign in with SSO</button>
</div>
<script>
// Show SSO error if redirected back from a failed callback
if (new URLSearchParams(window.location.search).get('sso_error')) {
document.getElementById('error').textContent = 'SSO login failed — please try again.';
history.replaceState(null, '', '/');
}
// If already logged in via API key, redirect
if (sessionStorage.getItem('rustguac_api_key')) {
window.location.href = '/addressbook.html';
}
// Check if already authenticated via cookie
fetch('/api/me', { credentials: 'same-origin' })
.then(function(res) {
if (res.ok) window.location.href = '/addressbook.html';
});
function applyTheme(theme) {
if (!theme) return;
var props = {primary_color:'--primary',primary_hover:'--primary-hover',accent_color:'--accent',accent_hover:'--accent-hover',bg_color:'--bg',surface_color:'--surface',input_color:'--input',text_color:'--text',text_muted:'--text-muted',border_color:'--border'};
var r = document.documentElement.style;
for (var k in props) { if (theme[k]) r.setProperty(props[k], theme[k]); }
if (theme.logo_url) { var logo = document.getElementById('site-logo'); if (logo) { logo.src = theme.logo_url; logo.style.display = ''; } }
}
// Check if OIDC is enabled
fetch('/api/auth/status')
.then(function(res) { return res.json(); })
.then(function(data) {
if (data.oidc_enabled) {
document.getElementById('sso-section').style.display = 'block';
}
if (data.site_title) {
document.title = data.site_title;
document.querySelector('h1').textContent = data.site_title;
}
applyTheme(data.theme);
});
document.getElementById('sso-btn').addEventListener('click', function() {
window.location.href = '/auth/login';
});
var form = document.getElementById('login-form');
var errorEl = document.getElementById('error');
var btn = document.getElementById('login-btn');
form.addEventListener('submit', function(e) {
e.preventDefault();
errorEl.textContent = '';
btn.disabled = true;
btn.textContent = 'Checking...';
var key = document.getElementById('api-key').value;
fetch('/api/sessions', {
headers: { 'Authorization': 'Bearer ' + key }
})
.then(function(res) {
if (!res.ok) throw new Error('Invalid API key');
sessionStorage.setItem('rustguac_api_key', key);
window.location.href = '/addressbook.html';
})
.catch(function(err) {
errorEl.textContent = err.message;
})
.finally(function() {
btn.disabled = false;
btn.textContent = 'Login';
});
});
</script>
</body>
</html>