ProxmoxBackupClientPBSClien.../docker/scripts/api-server.sh
zaphod-black ab1bc800af Add retro ASCII web dashboard (WIP - routing issue)
New Features:
- Beautiful retro terminal-style web dashboard
- Dark mode with green-on-black terminal aesthetics
- ASCII art header and box-drawing characters
- Real-time status monitoring
- Manual backup trigger button
- Log viewer with syntax highlighting
- Backup history display
- Responsive design with scanline effects
- Auto-refresh every 30 seconds

Files Added:
- docker/scripts/dashboard.html - Complete retro web UI
- docker/test-dashboard.sh - Testing script

Files Modified:
- docker/Dockerfile - Added netcat-openbsd and dashboard.html
- docker/scripts/api-server.sh - Added dashboard serving (has routing bug)

Known Issue:
The nc-based HTTP server has a path routing bug where all requests
hit the default case. The dashboard HTML is complete and beautiful,
but needs either:
1. Fix to the nc-based routing logic, OR
2. Replace with Python HTTP server for more reliable routing

Dashboard features work when routing is fixed:
- GET / - Serves retro dashboard
- GET /status - Backup status JSON
- GET /health - Health check JSON
- POST /backup - Trigger manual backup
- GET /logs - Recent backup logs

The HTML/CSS/JS is production-ready, just needs working HTTP routing.

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

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

87 lines
2.6 KiB
Bash
Executable file

#!/bin/bash
# Simple API server for PBS Client container management
# Provides REST endpoints for status, manual backup, etc.
PORT=${API_PORT:-8080}
log() {
echo "[API] [$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# Simple HTTP server using nc
log "Starting API server on port $PORT"
while true; do
(
read -r method path protocol
# Strip carriage returns and whitespace from path
path=$(echo "$path" | tr -d '\r' | xargs)
# Debug logging
log "REQUEST: method=[$method] path=[$path] len=${#path}"
# Read headers (discard)
while read -r line; do
[ -z "$line" ] || [ "$line" = $'\r' ] && break
done
# Handle request directly (avoid subshell variable issues)
case "$path" in
/|/dashboard.html)
MIME_TYPE="text/html"
BODY=$(cat /usr/local/share/dashboard.html)
;;
/status)
MIME_TYPE="application/json"
if [ -f /logs/status.json ]; then
BODY=$(cat /logs/status.json)
else
BODY='{"error":"No backup status available"}'
fi
;;
/health)
MIME_TYPE="application/json"
if /usr/local/bin/healthcheck >/dev/null 2>&1; then
BODY='{"status":"healthy"}'
else
BODY='{"status":"unhealthy"}'
fi
;;
/backup)
MIME_TYPE="application/json"
if [ "$method" = "POST" ]; then
BODY='{"status":"starting","message":"Backup triggered"}'
/usr/local/bin/pbs-backup &
else
BODY='{"error":"Use POST method to trigger backup"}'
fi
;;
/logs)
MIME_TYPE="application/json"
if [ -f /logs/last-backup.log ]; then
BODY=$(tail -n 50 /logs/last-backup.log | jq -R -s -c 'split("\n") | {logs: .}')
else
BODY='{"logs":[]}'
fi
;;
*)
MIME_TYPE="application/json"
BODY='{"error":"Not found","available_endpoints":["/","/status","/health","/backup","/logs"]}'
;;
esac
CONTENT_LENGTH=${#BODY}
# Send HTTP response
cat << EOF
HTTP/1.1 200 OK
Content-Type: $MIME_TYPE
Content-Length: $CONTENT_LENGTH
Access-Control-Allow-Origin: *
Connection: close
$BODY
EOF
) | nc -l -p $PORT -q 1
done