ProxmoxBackupClientPBSClien.../docker/scripts/dashboard.html
zaphod-black efba1948f6 Add web-based configuration interface to Docker dashboard
FEATURE: Settings page for configuring PBS backups via web UI

PROBLEM:
- Users had no way to configure PBS settings from the web dashboard
- Required manually setting environment variables or restarting containers
- Blank stats because no configuration existed

SOLUTION:
Added complete configuration management system:

API ENDPOINTS:
- GET /config - Retrieve current configuration
- POST /config - Save new configuration to /config/settings.json

DASHBOARD ENHANCEMENTS:
- New "⚙ Settings" button in Actions section
- Modal form with all configuration options:
  * PBS Repository (user@pam!token@host:port:datastore)
  * PBS Password/Token Secret
  * Backup Hostname
  * Backup Paths
  * Exclude Patterns (multi-line textarea)
  * Backup Schedule (cron expression)
  * Timezone
- Form validation and user-friendly placeholders
- Persistent storage to /config/settings.json
- Auto-refresh status after saving

DESIGN:
- Retro terminal aesthetic matching dashboard theme
- Blue/purple neon modal with dark background overlay
- Smooth fade-in animation
- Mobile-responsive form layout

TECHNICAL:
- Configuration persists across container restarts
- Environment variables can be overridden by config file
- JavaScript fetch API for async save/load
- Proper error handling and user feedback

Now users can configure everything from the web UI!

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

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

845 lines
28 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;
}
/* Modal styles */
.modal {
display: none;
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(10, 10, 20, 0.95);
animation: fadeIn 0.3s;
}
.modal.active {
display: flex;
align-items: center;
justify-content: center;
}
.modal-content {
background: #0f0f1a;
border: 3px solid #aa00ff;
padding: 30px;
max-width: 600px;
width: 90%;
max-height: 90vh;
overflow-y: auto;
box-shadow: 0 0 50px rgba(170, 0, 255, 0.5);
position: relative;
}
.modal-title {
color: #aa00ff;
font-size: 22px;
margin-bottom: 20px;
text-transform: uppercase;
letter-spacing: 3px;
}
.form-group {
margin-bottom: 20px;
}
.form-label {
display: block;
color: #00d4ff;
font-size: 14px;
margin-bottom: 8px;
text-transform: uppercase;
letter-spacing: 1px;
}
.form-input, .form-textarea {
width: 100%;
background: #05050a;
border: 2px solid #aa00ff;
color: #00d4ff;
padding: 12px;
font-family: 'JetBrains Mono', 'Courier New', monospace;
font-size: 15px;
box-sizing: border-box;
}
.form-input:focus, .form-textarea:focus {
outline: none;
border-color: #00d4ff;
box-shadow: 0 0 15px rgba(0, 212, 255, 0.3);
}
.form-textarea {
min-height: 80px;
resize: vertical;
}
.form-help {
color: #888;
font-size: 12px;
margin-top: 5px;
}
.modal-buttons {
display: flex;
gap: 15px;
margin-top: 25px;
}
.close-button {
position: absolute;
top: 15px;
right: 20px;
background: none;
border: none;
color: #ff3366;
font-size: 30px;
cursor: pointer;
line-height: 1;
}
.close-button:hover {
color: #ff6699;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.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="openSettings()">⚙ Settings</button>
<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>
<!-- Settings Modal -->
<div id="settings-modal" class="modal">
<div class="modal-content">
<button class="close-button" onclick="closeSettings()">&times;</button>
<div class="modal-title">⚙ Configuration</div>
<form id="config-form" onsubmit="saveSettings(event)">
<div class="form-group">
<label class="form-label">PBS Repository</label>
<input type="text" id="pbs_repository" class="form-input"
placeholder="user@pam!token@host:port:datastore" required>
<div class="form-help">Example: backup@pam!mytoken@192.168.1.100:8007:backups</div>
</div>
<div class="form-group">
<label class="form-label">PBS Password/Token Secret</label>
<input type="password" id="pbs_password" class="form-input"
placeholder="API token secret or password" required>
<div class="form-help">API token secret (recommended) or user password</div>
</div>
<div class="form-group">
<label class="form-label">Backup Hostname</label>
<input type="text" id="backup_hostname" class="form-input"
placeholder="my-server">
<div class="form-help">Hostname for backups (default: container hostname)</div>
</div>
<div class="form-group">
<label class="form-label">Backup Paths</label>
<input type="text" id="backup_paths" class="form-input"
placeholder="/host-data">
<div class="form-help">Space-separated paths to backup</div>
</div>
<div class="form-group">
<label class="form-label">Exclude Patterns</label>
<textarea id="exclude_patterns" class="form-textarea"
placeholder="/host-data/tmp&#10;/host-data/*.log"></textarea>
<div class="form-help">One pattern per line (optional)</div>
</div>
<div class="form-group">
<label class="form-label">Backup Schedule (Cron)</label>
<input type="text" id="backup_schedule" class="form-input"
placeholder="0 2 * * *">
<div class="form-help">Cron expression (e.g., "0 2 * * *" for 2 AM daily)</div>
</div>
<div class="form-group">
<label class="form-label">Timezone</label>
<input type="text" id="timezone" class="form-input"
placeholder="UTC">
<div class="form-help">e.g., America/New_York, Europe/London</div>
</div>
<div class="modal-buttons">
<button type="submit" class="button">💾 Save Configuration</button>
<button type="button" class="button" onclick="closeSettings()">✖ Cancel</button>
</div>
</form>
</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.');
}
// Settings modal functions
function openSettings() {
fetch('/config')
.then(r => r.json())
.then(config => {
document.getElementById('pbs_repository').value = config.pbs_repository || '';
document.getElementById('pbs_password').value = config.pbs_password || '';
document.getElementById('backup_hostname').value = config.backup_hostname || '';
document.getElementById('backup_paths').value = config.backup_paths || '/host-data';
document.getElementById('exclude_patterns').value = (config.exclude_patterns || '').replace(/ /g, '\n');
document.getElementById('backup_schedule').value = config.backup_schedule || '0 2 * * *';
document.getElementById('timezone').value = config.timezone || 'UTC';
document.getElementById('settings-modal').classList.add('active');
})
.catch(err => {
console.error('Failed to load config:', err);
alert('Failed to load configuration');
});
}
function closeSettings() {
document.getElementById('settings-modal').classList.remove('active');
}
function saveSettings(event) {
event.preventDefault();
const config = {
pbs_repository: document.getElementById('pbs_repository').value,
pbs_password: document.getElementById('pbs_password').value,
backup_hostname: document.getElementById('backup_hostname').value,
backup_paths: document.getElementById('backup_paths').value,
exclude_patterns: document.getElementById('exclude_patterns').value.split('\n').join(' ').trim(),
backup_schedule: document.getElementById('backup_schedule').value,
timezone: document.getElementById('timezone').value
};
fetch('/config', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config)
})
.then(r => r.json())
.then(result => {
if (result.status === 'success') {
alert('✓ Configuration saved successfully!\n\nNote: Restart container for cron schedule changes to take effect.');
closeSettings();
refreshStatus();
} else {
alert('Failed to save configuration: ' + (result.error || 'Unknown error'));
}
})
.catch(err => {
console.error('Failed to save config:', err);
alert('Failed to save configuration: ' + err.message);
});
}
// 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>