ProxmoxBackupClientPBSClien.../docker/scripts/dashboard.html
zaphod-black 0746428435 Fix Docker web dashboard with Python HTTP server + blue/purple neon theme
PROBLEM SOLVED:
The netcat-based HTTP server had a fundamental bidirectional pipe issue:
- `( read method path ) | nc -l` only connects stdout→stdin in one direction
- The `read` command couldn't receive HTTP request data from nc
- All requests returned "Not found" despite correct routing logic

SOLUTION:
- Created api-server.py: Proper Python HTTP server using http.server
- Handles dashboard (GET /), status, health, logs, and backup trigger (POST)
- Full request/response handling with proper HTTP headers
- Replaces broken netcat approach with robust solution

DASHBOARD ENHANCEMENTS:
- Changed from green terminal theme to blue/purple neon aesthetic
  - Primary: #00d4ff (cyan blue)
  - Accent: #aa00ff (purple)
  - Background: #0a0a14 (dark blue-black)
- Increased all font sizes 2-4px for better readability
- Enhanced button padding and spacing
- More visible, high-contrast interface

TECHNICAL DETAILS:
- Dockerfile: Replaced netcat-openbsd with python3 dependency
- api-server.sh: Now simple wrapper that exec's Python script
- api-server.py: Full-featured HTTP server with JSON/HTML responses
- dashboard.html: Updated color scheme and typography

TESTING:
 Dashboard loads at http://localhost:8080/
 /status endpoint returns JSON
 /health endpoint working
 /logs endpoint working
 Real-time backup monitoring ready

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-02 23:25:10 -06:00

614 lines
20 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PBS Backup Monitor</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #0a0a14;
color: #00d4ff;
font-family: 'JetBrains Mono', 'Courier New', monospace;
font-size: 16px;
line-height: 1.6;
padding: 20px;
overflow-x: hidden;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
color: #aa00ff;
text-shadow: 0 0 15px #aa00ff;
margin-bottom: 25px;
white-space: pre;
font-size: 11px;
line-height: 1;
}
.box {
border: 2px solid #aa00ff;
padding: 20px;
margin-bottom: 20px;
background: #0f0f1a;
box-shadow: 0 0 25px rgba(170, 0, 255, 0.2);
}
.box-title {
color: #00d4ff;
margin-bottom: 15px;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 3px;
font-size: 18px;
}
.status-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 10px;
margin-bottom: 10px;
}
.status-item {
padding: 12px;
background: #05050a;
border-left: 4px solid #aa00ff;
}
.status-label {
color: #888;
font-size: 13px;
text-transform: uppercase;
letter-spacing: 1px;
}
.status-value {
color: #00d4ff;
font-size: 20px;
font-weight: bold;
margin-top: 5px;
}
.status-value.error {
color: #ff3366;
text-shadow: 0 0 8px #ff3366;
}
.status-value.warning {
color: #ffaa00;
}
.status-value.success {
color: #00ff88;
text-shadow: 0 0 8px #00ff88;
}
.button {
background: #1a0033;
border: 2px solid #aa00ff;
color: #aa00ff;
padding: 14px 28px;
cursor: pointer;
font-family: inherit;
font-size: 15px;
text-transform: uppercase;
letter-spacing: 2px;
transition: all 0.3s;
margin-right: 12px;
margin-bottom: 12px;
font-weight: 600;
}
.button:hover {
background: #aa00ff;
color: #0a0a14;
box-shadow: 0 0 25px #aa00ff;
transform: translateY(-2px);
}
.button:active {
transform: scale(0.98);
}
.button:disabled {
opacity: 0.3;
cursor: not-allowed;
}
.log-viewer {
background: #000;
padding: 18px;
height: 350px;
overflow-y: auto;
font-size: 14px;
border: 2px solid #aa00ff;
margin-top: 12px;
line-height: 1.6;
}
.log-line {
margin-bottom: 4px;
color: #00d4ff;
}
.log-line.error {
color: #ff3366;
}
.log-line.warning {
color: #ffaa00;
}
.log-line.info {
color: #00aaff;
}
.backup-history {
max-height: 200px;
overflow-y: auto;
}
.backup-entry {
padding: 12px;
margin-bottom: 8px;
background: #05050a;
border-left: 4px solid #00d4ff;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 15px;
}
.backup-entry.failed {
border-left-color: #ff3366;
}
.backup-time {
color: #888;
font-size: 14px;
}
.backup-status {
font-weight: bold;
}
.backup-status.success {
color: #00ff88;
}
.backup-status.failed {
color: #ff3366;
}
.progress-bar {
width: 100%;
height: 26px;
background: #05050a;
border: 2px solid #aa00ff;
margin-top: 12px;
position: relative;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #1a0033, #aa00ff, #00d4ff);
width: 0%;
transition: width 0.5s;
box-shadow: 0 0 15px #aa00ff;
}
.progress-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #00d4ff;
font-size: 13px;
font-weight: bold;
text-shadow: 0 0 8px #000;
}
.blink {
animation: blink 1s infinite;
}
@keyframes blink {
0%, 50% { opacity: 1; }
51%, 100% { opacity: 0.3; }
}
.scanline {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: repeating-linear-gradient(
0deg,
rgba(0, 0, 0, 0.1),
rgba(0, 0, 0, 0.1) 1px,
transparent 1px,
transparent 2px
);
pointer-events: none;
z-index: 9999;
}
.ascii-border {
color: #aa00ff;
white-space: pre;
font-size: 11px;
line-height: 1;
margin: 12px 0;
}
::-webkit-scrollbar {
width: 12px;
}
::-webkit-scrollbar-track {
background: #0a0a14;
}
::-webkit-scrollbar-thumb {
background: #aa00ff;
border: 2px solid #0a0a14;
}
::-webkit-scrollbar-thumb:hover {
background: #00d4ff;
}
.metric {
display: inline-block;
padding: 10px 16px;
background: #05050a;
border: 2px solid #aa00ff;
margin-right: 12px;
margin-bottom: 10px;
}
.metric-label {
color: #888;
font-size: 12px;
}
.metric-value {
color: #00d4ff;
font-weight: bold;
font-size: 17px;
}
.timestamp {
color: #666;
font-size: 14px;
text-align: right;
margin-top: 25px;
}
@media (max-width: 768px) {
body {
font-size: 14px;
padding: 12px;
}
.status-grid {
grid-template-columns: 1fr;
}
.button {
font-size: 14px;
padding: 12px 20px;
}
}
</style>
</head>
<body>
<div class="scanline"></div>
<div class="container">
<div class="header">
╔═══════════════════════════════════════════════════════════════════════════╗
║ PROXMOX BACKUP CLIENT MONITOR v1.2.0 ║
║ [DOCKER CONTAINER MODE] ║
╚═══════════════════════════════════════════════════════════════════════════╝
</div>
<!-- System Status -->
<div class="box">
<div class="box-title">► SYSTEM STATUS</div>
<div class="status-grid">
<div class="status-item">
<div class="status-label">Container Health</div>
<div class="status-value" id="health-status">---</div>
</div>
<div class="status-item">
<div class="status-label">Last Backup</div>
<div class="status-value" id="last-backup">Never</div>
</div>
<div class="status-item">
<div class="status-label">Next Scheduled</div>
<div class="status-value" id="next-backup">---</div>
</div>
<div class="status-item">
<div class="status-label">Backup Status</div>
<div class="status-value" id="backup-status">Idle</div>
</div>
</div>
</div>
<!-- Configuration -->
<div class="box">
<div class="box-title">► CONFIGURATION</div>
<div class="metric">
<div class="metric-label">REPOSITORY</div>
<div class="metric-value" id="config-repo">---</div>
</div>
<div class="metric">
<div class="metric-label">HOSTNAME</div>
<div class="metric-value" id="config-host">---</div>
</div>
<div class="metric">
<div class="metric-label">SCHEDULE</div>
<div class="metric-value" id="config-schedule">---</div>
</div>
<div class="metric">
<div class="metric-label">PATHS</div>
<div class="metric-value" id="config-paths">---</div>
</div>
</div>
<!-- Actions -->
<div class="box">
<div class="box-title">► ACTIONS</div>
<button class="button" onclick="runBackup()">▶ Run Backup Now</button>
<button class="button" onclick="refreshStatus()">↻ Refresh Status</button>
<button class="button" onclick="downloadEncryptionKey()">🔑 Download Encryption Key</button>
<button class="button" onclick="toggleLogs()">📜 Toggle Logs</button>
<div id="backup-progress" style="display:none;">
<div class="progress-bar">
<div class="progress-fill" id="progress-fill"></div>
<div class="progress-text" id="progress-text">Running backup...</div>
</div>
</div>
</div>
<!-- Logs -->
<div class="box" id="logs-box" style="display:none;">
<div class="box-title">► SYSTEM LOGS</div>
<div class="log-viewer" id="log-viewer">
<div class="log-line">Waiting for logs...</div>
</div>
</div>
<!-- Backup History -->
<div class="box">
<div class="box-title">► BACKUP HISTORY</div>
<div class="backup-history" id="backup-history">
<div style="color: #888; text-align: center; padding: 20px;">Loading history...</div>
</div>
</div>
<div class="ascii-border">
═══════════════════════════════════════════════════════════════════════════
</div>
<div class="timestamp">
Last updated: <span id="last-update">---</span> | Auto-refresh: <span class="blink"></span> 30s
</div>
</div>
<script>
let backupRunning = false;
let logsVisible = false;
// Fetch status from API
async function fetchStatus() {
try {
const response = await fetch('/status');
const data = await response.json();
updateStatus(data);
} catch (error) {
console.error('Failed to fetch status:', error);
document.getElementById('health-status').className = 'status-value error';
document.getElementById('health-status').textContent = 'ERROR';
}
}
// Fetch health from API
async function fetchHealth() {
try {
const response = await fetch('/health');
const data = await response.json();
const healthEl = document.getElementById('health-status');
if (data.status === 'healthy') {
healthEl.className = 'status-value success';
healthEl.textContent = '✓ HEALTHY';
} else {
healthEl.className = 'status-value error';
healthEl.textContent = '✗ UNHEALTHY';
}
} catch (error) {
const healthEl = document.getElementById('health-status');
healthEl.className = 'status-value error';
healthEl.textContent = '✗ ERROR';
}
}
// Fetch logs from API
async function fetchLogs() {
if (!logsVisible) return;
try {
const response = await fetch('/logs');
const data = await response.json();
if (data.logs && Array.isArray(data.logs)) {
const logViewer = document.getElementById('log-viewer');
logViewer.innerHTML = data.logs.map(line => {
let className = 'log-line';
if (line.toLowerCase().includes('error')) className += ' error';
else if (line.toLowerCase().includes('warn')) className += ' warning';
else if (line.toLowerCase().includes('info')) className += ' info';
return `<div class="${className}">${escapeHtml(line)}</div>`;
}).join('');
// Auto-scroll to bottom
logViewer.scrollTop = logViewer.scrollHeight;
}
} catch (error) {
console.error('Failed to fetch logs:', error);
}
}
// Update status UI
function updateStatus(data) {
if (data.last_backup) {
const lastBackup = new Date(data.last_backup);
const now = new Date();
const diffMinutes = Math.floor((now - lastBackup) / 60000);
let timeAgo;
if (diffMinutes < 1) timeAgo = 'Just now';
else if (diffMinutes < 60) timeAgo = `${diffMinutes}m ago`;
else if (diffMinutes < 1440) timeAgo = `${Math.floor(diffMinutes/60)}h ago`;
else timeAgo = `${Math.floor(diffMinutes/1440)}d ago`;
document.getElementById('last-backup').textContent = timeAgo;
}
const statusEl = document.getElementById('backup-status');
if (data.success === true) {
statusEl.className = 'status-value success';
statusEl.textContent = '✓ Success';
} else if (data.success === false) {
statusEl.className = 'status-value error';
statusEl.textContent = '✗ Failed';
} else {
statusEl.className = 'status-value';
statusEl.textContent = 'Idle';
}
if (data.hostname) {
document.getElementById('config-host').textContent = data.hostname;
}
if (data.paths) {
document.getElementById('config-paths').textContent =
Array.isArray(data.paths) ? data.paths.join(', ') : data.paths;
}
// Update config from environment (mock data)
const repo = getEnvVar('PBS_REPOSITORY', 'Not configured');
const schedule = getEnvVar('BACKUP_SCHEDULE', '0 2 * * *');
document.getElementById('config-repo').textContent = maskSensitive(repo);
document.getElementById('config-schedule').textContent = schedule;
document.getElementById('last-update').textContent = new Date().toLocaleString();
}
// Run manual backup
async function runBackup() {
if (backupRunning) return;
backupRunning = true;
document.getElementById('backup-progress').style.display = 'block';
document.getElementById('progress-fill').style.width = '0%';
try {
const response = await fetch('/backup', { method: 'POST' });
const data = await response.json();
// Simulate progress
let progress = 0;
const interval = setInterval(() => {
progress += Math.random() * 15;
if (progress > 90) progress = 90;
document.getElementById('progress-fill').style.width = progress + '%';
document.getElementById('progress-text').textContent =
`Running backup... ${Math.floor(progress)}%`;
}, 1000);
// Check status every 5 seconds
const statusCheck = setInterval(async () => {
await fetchStatus();
}, 5000);
// Stop after 2 minutes max
setTimeout(() => {
clearInterval(interval);
clearInterval(statusCheck);
document.getElementById('progress-fill').style.width = '100%';
document.getElementById('progress-text').textContent = 'Backup started!';
setTimeout(() => {
document.getElementById('backup-progress').style.display = 'none';
backupRunning = false;
}, 3000);
}, 10000);
} catch (error) {
console.error('Failed to trigger backup:', error);
document.getElementById('progress-text').textContent = 'Error!';
setTimeout(() => {
document.getElementById('backup-progress').style.display = 'none';
backupRunning = false;
}, 3000);
}
}
// Toggle logs visibility
function toggleLogs() {
logsVisible = !logsVisible;
const logsBox = document.getElementById('logs-box');
logsBox.style.display = logsVisible ? 'block' : 'none';
if (logsVisible) fetchLogs();
}
// Refresh status
function refreshStatus() {
fetchStatus();
fetchHealth();
if (logsVisible) fetchLogs();
}
// Download encryption key
function downloadEncryptionKey() {
alert('To download encryption key:\n\ndocker cp pbs-backup-client:/config/encryption-key.json ./\n\nRun this command in your terminal.');
}
// Helper functions
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function maskSensitive(text) {
// Mask password/token parts
return text.replace(/:[^@:]+@/g, ':****@');
}
function getEnvVar(name, defaultValue) {
// In real implementation, these would come from API
// For now, return mock data
return defaultValue;
}
// Initialize
refreshStatus();
setInterval(refreshStatus, 30000); // Auto-refresh every 30 seconds
if (logsVisible) setInterval(fetchLogs, 5000); // Update logs every 5 seconds when visible
</script>
</body>
</html>