Migrate storage from JSON to SQLite with enhanced MVC architecture

- Replace JSON file storage with SQLite database for improved concurrency and data integrity
- Implement repository pattern with dedicated model layer (admin_model, file_model, chunk_model)
- Add database.py with automatic migration from existing JSON files
- Enable WAL mode for thread-safe concurrent access across Gunicorn workers
- Store database files in dedicated db/ folder
- Update controllers to use model layer instead of direct JSON access
- Add admin authentication system with TOTP 2FA support
This commit is contained in:
2025-12-27 14:00:39 -05:00
parent 8eac7b90c6
commit 872ae74668
14 changed files with 2442 additions and 175 deletions

View File

@@ -0,0 +1,312 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - Simple File Server</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: #2d3748;
padding: 2rem 1rem;
}
.container {
background: rgba(255, 255, 255, 0.95);
padding: 2.5rem;
border-radius: 1rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 90%;
max-width: 600px;
backdrop-filter: blur(10px);
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 2rem;
padding-bottom: 1.5rem;
border-bottom: 2px solid #e2e8f0;
}
.header-left {
display: flex;
align-items: center;
gap: 1rem;
}
.icon {
color: #667eea;
font-size: 2.5rem;
}
.header-text h1 {
color: #2d3748;
font-size: 1.75rem;
font-weight: 600;
margin-bottom: 0.25rem;
}
.header-text .username {
color: #718096;
font-size: 0.9rem;
}
.logout-btn {
background: transparent;
color: #718096;
padding: 0.5rem 1rem;
border: 2px solid #e2e8f0;
border-radius: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
gap: 0.5rem;
}
.logout-btn:hover {
border-color: #e53e3e;
color: #e53e3e;
background: #fff5f5;
}
.card {
background: #f7fafc;
padding: 1.5rem;
border-radius: 0.75rem;
margin-bottom: 1.5rem;
border-left: 4px solid #667eea;
}
.card-title {
display: flex;
align-items: center;
gap: 0.5rem;
font-weight: 600;
color: #2d3748;
margin-bottom: 1rem;
font-size: 1.1rem;
}
.card-title .material-icons {
color: #667eea;
font-size: 1.5rem;
}
.key-container {
background: white;
padding: 1rem;
border-radius: 0.5rem;
border: 2px solid #e2e8f0;
position: relative;
}
.key-display {
font-family: 'Courier New', monospace;
font-size: 0.95rem;
word-break: break-all;
color: #2d3748;
padding-right: 3rem;
line-height: 1.6;
}
.copy-btn {
position: absolute;
top: 0.75rem;
right: 0.75rem;
background: #667eea;
color: white;
border: none;
border-radius: 0.375rem;
padding: 0.5rem;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
}
.copy-btn:hover {
background: #5a67d8;
transform: scale(1.05);
}
.copy-btn:active {
transform: scale(0.95);
}
.copy-btn .material-icons {
font-size: 1.25rem;
}
.info-box {
background: #ebf8ff;
color: #2c5282;
padding: 1rem;
border-radius: 0.5rem;
border-left: 4px solid #4299e1;
font-size: 0.85rem;
line-height: 1.6;
display: flex;
gap: 0.75rem;
}
.info-box .material-icons {
color: #4299e1;
font-size: 1.5rem;
flex-shrink: 0;
}
.success-message {
background: #f0fff4;
color: #2f855a;
padding: 0.75rem 1rem;
border-radius: 0.5rem;
margin-bottom: 1rem;
display: none;
align-items: center;
gap: 0.5rem;
animation: slideIn 0.3s ease;
}
.success-message .material-icons {
color: #48bb78;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.actions {
display: flex;
gap: 1rem;
margin-top: 1.5rem;
}
.btn {
flex: 1;
padding: 0.75rem;
border: none;
border-radius: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
text-decoration: none;
}
.btn-primary {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
.btn-secondary {
background: white;
color: #667eea;
border: 2px solid #667eea;
}
.btn-secondary:hover {
background: #f7fafc;
}
</style>
<script>
function copyToClipboard() {
const keyText = document.querySelector('.key-display').textContent;
navigator.clipboard.writeText(keyText).then(() => {
const successMsg = document.querySelector('.success-message');
successMsg.style.display = 'flex';
setTimeout(() => {
successMsg.style.display = 'none';
}, 3000);
});
}
</script>
</head>
<body>
<div class="container">
<div class="header">
<div class="header-left">
<span class="material-icons icon">dashboard</span>
<div class="header-text">
<h1>Admin Dashboard</h1>
<div class="username">Logged in as {{ username }}</div>
</div>
</div>
<a href="/admin/logout" class="logout-btn">
<span class="material-icons" style="font-size: 1.25rem;">logout</span>
Logout
</a>
</div>
<div class="success-message">
<span class="material-icons">check_circle</span>
Client key copied to clipboard!
</div>
<div class="card">
<div class="card-title">
<span class="material-icons">vpn_key</span>
Client Key
</div>
<div class="key-container">
<div class="key-display">{{ client_key }}</div>
<button class="copy-btn" onclick="copyToClipboard()" title="Copy to clipboard">
<span class="material-icons">content_copy</span>
</button>
</div>
</div>
<div class="info-box">
<span class="material-icons">info</span>
<div>
<strong>What is the Client Key?</strong><br>
This key is used by clients to authenticate API requests to the file server.
It should be included in the <code>X-Client-Key</code> header for all upload operations.
Keep this key secure and don't share it publicly.
</div>
</div>
<div class="actions">
<a href="/" class="btn btn-secondary">
<span class="material-icons">home</span>
Home
</a>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,242 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login - Simple File Server</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: #2d3748;
}
.container {
background: rgba(255, 255, 255, 0.95);
padding: 2.5rem;
border-radius: 1rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 90%;
max-width: 450px;
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 2rem;
}
.icon {
color: #667eea;
font-size: 3rem;
margin-bottom: 1rem;
}
h1 {
color: #2d3748;
font-size: 1.75rem;
margin-bottom: 0.5rem;
font-weight: 600;
}
.subtitle {
color: #718096;
font-size: 0.9rem;
}
.form-group {
margin-bottom: 1.5rem;
}
label {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
color: #4a5568;
margin-bottom: 0.5rem;
}
label .material-icons {
font-size: 1.2rem;
color: #667eea;
}
input {
width: 100%;
padding: 0.75rem;
border: 2px solid #e2e8f0;
border-radius: 0.5rem;
font-size: 1rem;
transition: all 0.2s;
background: white;
}
input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.totp-input {
text-align: center;
font-size: 1.5rem;
letter-spacing: 0.5rem;
font-family: 'Courier New', monospace;
}
button {
width: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 0.875rem;
border: none;
border-radius: 0.5rem;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
button:active {
transform: translateY(0);
}
.error {
background-color: #fff5f5;
color: #c53030;
padding: 0.75rem;
border-radius: 0.5rem;
margin-bottom: 1rem;
border: 1px solid #feb2b2;
font-size: 0.9rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.error .material-icons {
color: #c53030;
}
.totp-hint {
font-size: 0.8rem;
color: #718096;
margin-top: 0.25rem;
text-align: center;
}
.back-link {
text-align: center;
margin-top: 1rem;
}
.back-link a {
color: #667eea;
text-decoration: none;
font-size: 0.9rem;
display: inline-flex;
align-items: center;
gap: 0.25rem;
}
.back-link a:hover {
text-decoration: underline;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
const totpInput = document.querySelector('.totp-input');
// Auto-submit on 6 digits
totpInput.addEventListener('input', (e) => {
e.target.value = e.target.value.replace(/\D/g, '');
if (e.target.value.length === 6) {
// Optional: auto-submit
// document.querySelector('form').submit();
}
});
});
</script>
</head>
<body>
<div class="container">
<div class="header">
<span class="material-icons icon">security</span>
<h1>Admin Login</h1>
<p class="subtitle">Enter your credentials</p>
</div>
{% if error %}
<div class="error">
<span class="material-icons">error</span>
<span>{{ error }}</span>
</div>
{% endif %}
<form method="POST">
<div class="form-group">
<label>
<span class="material-icons">person</span>
Username
</label>
<input type="text" name="username" required autocomplete="username" autofocus>
</div>
<div class="form-group">
<label>
<span class="material-icons">lock</span>
Password
</label>
<input type="password" name="password" required autocomplete="current-password">
</div>
<div class="form-group">
<label>
<span class="material-icons">pin</span>
Two-Factor Code
</label>
<input type="text" name="totp_code" class="totp-input" required
maxlength="6" pattern="[0-9]{6}" inputmode="numeric"
autocomplete="one-time-code" placeholder="000000">
<div class="totp-hint">Enter the 6-digit code from your authenticator app</div>
</div>
<button type="submit">
<span class="material-icons">login</span>
Login
</button>
</form>
<div class="back-link">
<a href="/">
<span class="material-icons" style="font-size: 1rem;">home</span>
Back to Home
</a>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,198 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Setup - Simple File Server</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: #2d3748;
}
.container {
background: rgba(255, 255, 255, 0.95);
padding: 2.5rem;
border-radius: 1rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 90%;
max-width: 450px;
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 2rem;
}
.icon {
color: #667eea;
font-size: 3rem;
margin-bottom: 1rem;
}
h1 {
color: #2d3748;
font-size: 1.75rem;
margin-bottom: 0.5rem;
font-weight: 600;
}
.subtitle {
color: #718096;
font-size: 0.9rem;
}
.form-group {
margin-bottom: 1.5rem;
}
label {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
color: #4a5568;
margin-bottom: 0.5rem;
}
label .material-icons {
font-size: 1.2rem;
color: #667eea;
}
input {
width: 100%;
padding: 0.75rem;
border: 2px solid #e2e8f0;
border-radius: 0.5rem;
font-size: 1rem;
transition: all 0.2s;
background: white;
}
input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
button {
width: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 0.875rem;
border: none;
border-radius: 0.5rem;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
button:active {
transform: translateY(0);
}
.error {
background-color: #fff5f5;
color: #c53030;
padding: 0.75rem;
border-radius: 0.5rem;
margin-bottom: 1rem;
border: 1px solid #feb2b2;
font-size: 0.9rem;
}
.info-box {
background-color: #ebf4ff;
color: #2c5282;
padding: 1rem;
border-radius: 0.5rem;
margin-bottom: 1.5rem;
border-left: 4px solid #4299e1;
font-size: 0.85rem;
line-height: 1.5;
}
.password-hint {
font-size: 0.8rem;
color: #718096;
margin-top: 0.25rem;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<span class="material-icons icon">admin_panel_settings</span>
<h1>Admin Setup</h1>
<p class="subtitle">Create your administrator account</p>
</div>
<div class="info-box">
Step 1 of 2: Create your admin credentials. You'll configure two-factor authentication on the next step.
</div>
{% if error %}
<div class="error">{{ error }}</div>
{% endif %}
<form method="POST">
<div class="form-group">
<label>
<span class="material-icons">person</span>
Username
</label>
<input type="text" name="username" required autocomplete="username" autofocus>
</div>
<div class="form-group">
<label>
<span class="material-icons">lock</span>
Password
</label>
<input type="password" name="password" required autocomplete="new-password" minlength="8">
<div class="password-hint">Minimum 8 characters</div>
</div>
<div class="form-group">
<label>
<span class="material-icons">lock</span>
Confirm Password
</label>
<input type="password" name="confirm_password" required autocomplete="new-password" minlength="8">
</div>
<button type="submit">
<span class="material-icons">arrow_forward</span>
Continue to Two-Factor Setup
</button>
</form>
</div>
</body>
</html>

View File

@@ -0,0 +1,199 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup Complete - Simple File Server</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: #2d3748;
}
.container {
background: rgba(255, 255, 255, 0.95);
padding: 2.5rem;
border-radius: 1rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 90%;
max-width: 500px;
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 2rem;
}
.icon {
color: #48bb78;
font-size: 3.5rem;
margin-bottom: 1rem;
}
h1 {
color: #2d3748;
font-size: 1.75rem;
margin-bottom: 0.5rem;
font-weight: 600;
}
.subtitle {
color: #718096;
font-size: 0.9rem;
}
.step {
background: #f7fafc;
padding: 1.5rem;
border-radius: 0.75rem;
margin-bottom: 1.5rem;
border-left: 4px solid #667eea;
}
.step-title {
display: flex;
align-items: center;
gap: 0.5rem;
font-weight: 600;
color: #2d3748;
margin-bottom: 1rem;
font-size: 1.1rem;
}
.step-title .material-icons {
color: #667eea;
font-size: 1.5rem;
}
.qr-container {
text-align: center;
margin: 1rem 0;
background: white;
padding: 1rem;
border-radius: 0.5rem;
}
.qr-code {
max-width: 200px;
height: auto;
}
.secret-code {
background: white;
padding: 1rem;
border-radius: 0.5rem;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
word-break: break-all;
border: 2px dashed #cbd5e0;
margin: 0.5rem 0;
text-align: center;
font-weight: bold;
color: #2d3748;
}
.warning {
background-color: #fffaf0;
color: #744210;
padding: 1rem;
border-radius: 0.5rem;
margin-bottom: 1.5rem;
border-left: 4px solid #ed8936;
font-size: 0.85rem;
display: flex;
align-items: start;
gap: 0.75rem;
}
.warning .material-icons {
color: #ed8936;
font-size: 1.5rem;
}
button {
width: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 0.875rem;
border: none;
border-radius: 0.5rem;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
.step-content {
color: #4a5568;
line-height: 1.6;
}
ol {
margin-left: 1.25rem;
margin-top: 0.5rem;
}
li {
margin-bottom: 0.5rem;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<span class="material-icons icon">check_circle</span>
<h1>Setup Complete!</h1>
<p class="subtitle">Your admin account has been created</p>
</div>
<div class="step">
<div class="step-content" style="text-align: center;">
<p style="font-size: 1.1rem; color: #2d3748; margin-bottom: 1rem;">
Welcome, <strong>{{ username }}</strong>!
</p>
<p style="color: #4a5568; line-height: 1.6;">
Your administrator account has been successfully created and your authenticator app is configured.
You can now login to access the admin dashboard.
</p>
</div>
</div>
<div class="warning">
<span class="material-icons">info</span>
<div>
<strong>Important:</strong> Make sure you've saved your authenticator app configuration.
You'll need it every time you log in to the admin panel.
</div>
</div>
<button onclick="window.location.href='/admin/login'">
<span class="material-icons">login</span>
Continue to Login
</button>
</div>
</body>
</html>

View File

@@ -0,0 +1,342 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup Two-Factor Authentication - Simple File Server</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
color: #2d3748;
padding: 2rem 1rem;
}
.container {
background: rgba(255, 255, 255, 0.95);
padding: 2.5rem;
border-radius: 1rem;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
width: 90%;
max-width: 550px;
backdrop-filter: blur(10px);
}
.header {
text-align: center;
margin-bottom: 2rem;
}
.icon {
color: #667eea;
font-size: 3rem;
margin-bottom: 1rem;
}
h1 {
color: #2d3748;
font-size: 1.75rem;
margin-bottom: 0.5rem;
font-weight: 600;
}
.subtitle {
color: #718096;
font-size: 0.9rem;
}
.step-indicator {
background: #ebf4ff;
color: #2c5282;
padding: 0.75rem 1rem;
border-radius: 0.5rem;
margin-bottom: 1.5rem;
border-left: 4px solid #4299e1;
font-size: 0.85rem;
font-weight: 500;
}
.info-box {
background-color: #fffaf0;
color: #744210;
padding: 1rem;
border-radius: 0.5rem;
margin-bottom: 1.5rem;
border-left: 4px solid #ed8936;
font-size: 0.85rem;
line-height: 1.6;
display: flex;
align-items: start;
gap: 0.75rem;
}
.info-box .material-icons {
color: #ed8936;
font-size: 1.5rem;
flex-shrink: 0;
}
.error {
background-color: #fff5f5;
color: #c53030;
padding: 0.75rem;
border-radius: 0.5rem;
margin-bottom: 1rem;
border: 1px solid #feb2b2;
font-size: 0.9rem;
display: flex;
align-items: center;
gap: 0.5rem;
}
.error .material-icons {
color: #c53030;
}
.totp-setup-section {
background: #f7fafc;
padding: 1.5rem;
border-radius: 0.75rem;
margin-bottom: 1.5rem;
border: 2px solid #e2e8f0;
}
.section-title {
font-size: 1.1rem;
margin-bottom: 1rem;
color: #2d3748;
display: flex;
align-items: center;
gap: 0.5rem;
font-weight: 600;
}
.section-title .material-icons {
color: #667eea;
}
.qr-container {
text-align: center;
margin: 1rem 0;
background: white;
padding: 1.5rem;
border-radius: 0.5rem;
}
.qr-code {
max-width: 220px;
height: auto;
border: 2px solid #e2e8f0;
border-radius: 0.5rem;
padding: 0.5rem;
}
.secret-display {
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 2px dashed #e2e8f0;
}
.secret-label {
font-size: 0.85rem;
color: #4a5568;
margin-bottom: 0.5rem;
font-weight: 500;
}
.secret-code {
background: white;
padding: 0.875rem;
border-radius: 0.5rem;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
word-break: break-all;
border: 2px dashed #cbd5e0;
text-align: center;
font-weight: bold;
color: #2d3748;
margin-bottom: 0.5rem;
}
.account-info {
font-size: 0.8rem;
color: #718096;
text-align: center;
}
.form-group {
margin-bottom: 1.5rem;
}
label {
display: flex;
align-items: center;
gap: 0.5rem;
font-size: 0.9rem;
font-weight: 500;
color: #4a5568;
margin-bottom: 0.5rem;
}
label .material-icons {
font-size: 1.2rem;
color: #667eea;
}
.totp-input {
width: 100%;
padding: 0.75rem;
border: 2px solid #e2e8f0;
border-radius: 0.5rem;
font-size: 1.5rem;
transition: all 0.2s;
background: white;
text-align: center;
letter-spacing: 0.5rem;
font-family: 'Courier New', monospace;
}
.totp-input:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.totp-hint {
font-size: 0.8rem;
color: #718096;
margin-top: 0.25rem;
text-align: center;
}
button {
width: 100%;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 0.875rem;
border: none;
border-radius: 0.5rem;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
display: flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}
button:active {
transform: translateY(0);
}
.steps-list {
list-style: none;
padding: 0;
margin: 0;
}
.steps-list li {
padding: 0.5rem 0;
color: #4a5568;
font-size: 0.9rem;
line-height: 1.5;
}
.steps-list li:before {
content: "→";
color: #667eea;
font-weight: bold;
margin-right: 0.5rem;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<span class="material-icons icon">security</span>
<h1>Two-Factor Authentication</h1>
<p class="subtitle">Secure your admin account</p>
</div>
<div class="step-indicator">
Step 2 of 2: Configure your authenticator app
</div>
<div class="info-box">
<span class="material-icons">info</span>
<div>
<strong>Required:</strong> You need an authenticator app to continue.
Download Google Authenticator, Authy, or any TOTP-compatible app before proceeding.
</div>
</div>
{% if error %}
<div class="error">
<span class="material-icons">error</span>
<span>{{ error }}</span>
</div>
{% endif %}
<div class="totp-setup-section">
<div class="section-title">
<span class="material-icons">qr_code_scanner</span>
Scan QR Code
</div>
<div class="qr-container">
<img class="qr-code" src="data:image/png;base64,{{ qr_code }}" alt="TOTP QR Code">
</div>
<div class="secret-display">
<div class="section-title" style="font-size: 1rem; margin-bottom: 0.75rem;">
<span class="material-icons" style="font-size: 1.25rem;">vpn_key</span>
Or Enter Manually
</div>
<div class="secret-label">Secret Key:</div>
<div class="secret-code">{{ totp_secret }}</div>
<div class="account-info">
Account: {{ username }}<br>
Issuer: Simple File Server
</div>
</div>
</div>
<form method="POST">
<div class="form-group">
<label>
<span class="material-icons">verified_user</span>
Verify Authentication Code
</label>
<input type="text" name="totp_code" class="totp-input" required
maxlength="6" pattern="[0-9]{6}" inputmode="numeric"
autocomplete="off" placeholder="000000" autofocus>
<div class="totp-hint">Enter the 6-digit code from your authenticator app</div>
</div>
<button type="submit">
<span class="material-icons">check_circle</span>
Complete Setup
</button>
</form>
</div>
</body>
</html>