#!/bin/sh # SPDX-License-Identifier: MIT # SecuBox Landing Page Generator - Multi-Theme Support # Copyright (C) 2025 CyberMind.fr . /lib/functions.sh UCI_CONFIG="service-registry" OUTPUT_PATH="/www/secubox-services.html" THEME="mirrorbox" # Get config values config_load "$UCI_CONFIG" config_get OUTPUT_PATH main landing_path "$OUTPUT_PATH" config_get THEME main landing_theme "mirrorbox" # Get services JSON SERVICES_JSON=$(ubus call luci.service-registry list_services 2>/dev/null) if [ -z "$SERVICES_JSON" ]; then echo "Error: Could not fetch services" exit 1 fi # Get hostname HOSTNAME=$(uci -q get system.@system[0].hostname || echo "SecuBox") # Theme CSS variables get_theme_css() { case "$1" in mirrorbox) cat <<'CSS' --primary: #00d4ff; --primary-rgb: 0, 212, 255; --secondary: #7c3aed; --secondary-rgb: 124, 58, 237; --accent: #f472b6; --accent-rgb: 244, 114, 182; --bg-start: #0a0a1a; --bg-mid: #0f0f2a; --bg-end: #1a0a2e; --glass-bg: rgba(255, 255, 255, 0.03); --glass-border: rgba(255, 255, 255, 0.08); --glass-hover: rgba(255, 255, 255, 0.06); --text: #f0f0f5; --text-dim: #8b8b9e; --text-muted: #5a5a6e; CSS ;; cyberpunk) cat <<'CSS' --primary: #ff00ff; --primary-rgb: 255, 0, 255; --secondary: #00ffff; --secondary-rgb: 0, 255, 255; --accent: #ffff00; --accent-rgb: 255, 255, 0; --bg-start: #0d0221; --bg-mid: #150734; --bg-end: #0a0612; --glass-bg: rgba(255, 0, 255, 0.05); --glass-border: rgba(255, 0, 255, 0.2); --glass-hover: rgba(0, 255, 255, 0.1); --text: #ffffff; --text-dim: #b0b0ff; --text-muted: #7070aa; CSS ;; minimal) cat <<'CSS' --primary: #6366f1; --primary-rgb: 99, 102, 241; --secondary: #8b5cf6; --secondary-rgb: 139, 92, 246; --accent: #ec4899; --accent-rgb: 236, 72, 153; --bg-start: #111827; --bg-mid: #1f2937; --bg-end: #111827; --glass-bg: rgba(255, 255, 255, 0.02); --glass-border: rgba(255, 255, 255, 0.05); --glass-hover: rgba(255, 255, 255, 0.04); --text: #f9fafb; --text-dim: #9ca3af; --text-muted: #6b7280; CSS ;; terminal) cat <<'CSS' --primary: #00ff00; --primary-rgb: 0, 255, 0; --secondary: #00cc00; --secondary-rgb: 0, 204, 0; --accent: #00ff00; --accent-rgb: 0, 255, 0; --bg-start: #000000; --bg-mid: #001100; --bg-end: #000000; --glass-bg: rgba(0, 255, 0, 0.03); --glass-border: rgba(0, 255, 0, 0.15); --glass-hover: rgba(0, 255, 0, 0.08); --text: #00ff00; --text-dim: #00cc00; --text-muted: #008800; CSS ;; light) cat <<'CSS' --primary: #3b82f6; --primary-rgb: 59, 130, 246; --secondary: #8b5cf6; --secondary-rgb: 139, 92, 246; --accent: #ec4899; --accent-rgb: 236, 72, 153; --bg-start: #ffffff; --bg-mid: #f8fafc; --bg-end: #f1f5f9; --glass-bg: rgba(0, 0, 0, 0.02); --glass-border: rgba(0, 0, 0, 0.08); --glass-hover: rgba(0, 0, 0, 0.04); --text: #1e293b; --text-dim: #64748b; --text-muted: #94a3b8; CSS ;; esac } THEME_CSS=$(get_theme_css "$THEME") # Generate HTML (quoted heredoc to preserve JS variables) cat > "$OUTPUT_PATH" <<'HTMLHEAD' SecuBox Services

SecuBox Services

Your secure gateway to published endpoints

HTMLHEAD # Replace placeholders TMP_OUTPUT="${OUTPUT_PATH}.tmp" # Replace theme name sed -i "s/THEME_NAME_PLACEHOLDER/$THEME/g" "$OUTPUT_PATH" # Replace theme CSS (multi-line, use a temp file approach) # First, escape special characters in THEME_CSS for sed THEME_CSS_ESCAPED=$(printf '%s\n' "$THEME_CSS" | sed 's/[&/\]/\\&/g') # Create a temp file with the CSS echo "$THEME_CSS" > "${TMP_OUTPUT}.css" # Use awk for multi-line replacement awk -v cssfile="${TMP_OUTPUT}.css" ' /THEME_CSS_PLACEHOLDER/ { while ((getline line < cssfile) > 0) print line next } {print} ' "$OUTPUT_PATH" > "$TMP_OUTPUT" mv "$TMP_OUTPUT" "$OUTPUT_PATH" rm -f "${TMP_OUTPUT}.css" # Replace JSON placeholder awk -v json="$SERVICES_JSON" '{gsub(/SERVICES_JSON_PLACEHOLDER/, json); print}' "$OUTPUT_PATH" > "$TMP_OUTPUT" mv "$TMP_OUTPUT" "$OUTPUT_PATH" # Ensure web server can read the file chmod 644 "$OUTPUT_PATH" echo "Landing page generated: $OUTPUT_PATH (theme: $THEME)"