- Added @login_required decorator to all 38 unprotected API endpoints - Initialized Flask-WTF CSRFProtect in app factory - Added CSRF token meta tag to base.html - Added JavaScript fetch interceptor to attach X-CSRFToken header to all non-GET requests - Closes critical security vulnerability where any unauthenticated user could perform administrative actions
138 lines
6.6 KiB
HTML
138 lines
6.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
<title>{% block title %}Dune Awakening Server Dashboard{% endblock %}</title>
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
|
</head>
|
|
<body>
|
|
<div id="update-banner" class="update-banner" style="display:none;">
|
|
<span>🔄 Update available for Dune Dashboard</span>
|
|
<div class="update-actions">
|
|
<button onclick="applyUpdate()" class="update-btn primary">Update Now</button>
|
|
<button onclick="dismissUpdate()" class="update-btn">Later</button>
|
|
</div>
|
|
</div>
|
|
<nav>
|
|
<div class="brand">DUNE DASHBOARD</div>
|
|
{% for href, label in nav_pages %}
|
|
<a href="{{ href }}" class="{% if current_path == href %}active{% endif %}">{{ label }}</a>
|
|
{% endfor %}
|
|
<div class="spacer"></div>
|
|
<span style="font-size:12px;color:var(--nav-text);display:flex;align-items:center;">
|
|
<span class="conn-dot {% if conn_ok %}online{% else %}offline{% endif %}"></span>
|
|
{{ 'Connected' if conn_ok else 'Disconnected' }}
|
|
</span>
|
|
<button id="check-update-btn" onclick="manualCheckUpdate()" style="font-size:12px;color:var(--nav-text);background:none;border:none;cursor:pointer;padding:4px 8px;" title="Check for updates">🔄 Check Updates</button>
|
|
{% if current_user and current_user.is_authenticated %}
|
|
<a href="/logout" style="font-size:12px;color:var(--nav-text);">Logout</a>
|
|
{% endif %}
|
|
</nav>
|
|
<main class="container">
|
|
{% block content %}{% endblock %}
|
|
</main>
|
|
<div id="update-progress" class="update-progress" style="display:none;">
|
|
<div class="update-progress-inner">
|
|
<h3>Updating Dashboard...</h3>
|
|
<p id="update-status-text">Checking for updates...</p>
|
|
<div class="update-spinner"></div>
|
|
</div>
|
|
</div>
|
|
{% block scripts %}{% endblock %}
|
|
<script>
|
|
let updateDismissed = false;
|
|
async function checkForUpdate() {
|
|
if (updateDismissed) return;
|
|
try {
|
|
const resp = await fetch('/api/update/status');
|
|
const data = await resp.json();
|
|
if (data.available) {
|
|
document.getElementById('update-banner').style.display = 'flex';
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
async function manualCheckUpdate() {
|
|
const btn = document.getElementById('check-update-btn');
|
|
btn.textContent = 'Checking...';
|
|
btn.disabled = true;
|
|
try {
|
|
const resp = await fetch('/api/update/check', { method: 'POST' });
|
|
const data = await resp.json();
|
|
if (data.available) {
|
|
document.getElementById('update-banner').style.display = 'flex';
|
|
btn.textContent = 'Update Available!';
|
|
} else {
|
|
btn.textContent = 'Up to Date ✓';
|
|
setTimeout(() => { btn.textContent = '🔄 Check Updates'; }, 3000);
|
|
}
|
|
} catch (e) {
|
|
btn.textContent = 'Check Failed';
|
|
setTimeout(() => { btn.textContent = '🔄 Check Updates'; }, 3000);
|
|
}
|
|
btn.disabled = false;
|
|
}
|
|
function dismissUpdate() {
|
|
updateDismissed = true;
|
|
document.getElementById('update-banner').style.display = 'none';
|
|
}
|
|
async function applyUpdate() {
|
|
const banner = document.getElementById('update-banner');
|
|
const progress = document.getElementById('update-progress');
|
|
const statusText = document.getElementById('update-status-text');
|
|
banner.style.display = 'none';
|
|
progress.style.display = 'flex';
|
|
try {
|
|
const resp = await fetch('/api/update/apply', { method: 'POST' });
|
|
const data = await resp.json();
|
|
statusText.textContent = data.message || 'Applying update...';
|
|
if (data.success) {
|
|
statusText.textContent = 'Update complete! Restarting...';
|
|
setTimeout(() => { location.reload(); }, 5000);
|
|
} else {
|
|
statusText.textContent = 'Update failed: ' + (data.message || 'Unknown error');
|
|
setTimeout(() => { progress.style.display = 'none'; }, 5000);
|
|
}
|
|
} catch (e) {
|
|
statusText.textContent = 'Update failed: ' + e.message;
|
|
setTimeout(() => { progress.style.display = 'none'; }, 5000);
|
|
}
|
|
}
|
|
setInterval(checkForUpdate, 60000);
|
|
checkForUpdate();
|
|
|
|
// CSRF: Attach token to all non-GET fetch requests
|
|
(function() {
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.content;
|
|
if (!csrfToken) return;
|
|
const origFetch = window.fetch;
|
|
window.fetch = function() {
|
|
let [resource, config] = arguments;
|
|
if (!config) config = {};
|
|
if (!config.headers) config.headers = {};
|
|
const method = (config.method || 'GET').toUpperCase();
|
|
if (method !== 'GET' && method !== 'HEAD' && method !== 'OPTIONS') {
|
|
if (typeof config.headers === 'object') {
|
|
config.headers['X-CSRFToken'] = csrfToken;
|
|
}
|
|
}
|
|
return origFetch(resource, config);
|
|
};
|
|
})();
|
|
</script>
|
|
<style>
|
|
.update-banner { background: var(--bg-hover); border-bottom: 2px solid var(--accent); padding: 10px 20px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text); }
|
|
.update-actions { display: flex; gap: 8px; }
|
|
.update-btn { padding: 4px 12px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-card); color: var(--text); cursor: pointer; font-size: 12px; }
|
|
.update-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
|
|
.update-progress { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 9999; }
|
|
.update-progress-inner { background: var(--bg-card); padding: 30px 40px; border-radius: 8px; text-align: center; color: var(--text); max-width: 400px; }
|
|
.update-progress-inner h3 { margin: 0 0 10px; }
|
|
.update-progress-inner p { margin: 0 0 15px; color: var(--text-muted); font-size: 13px; }
|
|
.update-spinner { width: 30px; height: 30px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto; }
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
</style>
|
|
</body>
|
|
</html>
|