apiVersion: v1
data:
  sunrise.css: |
    :root {
      color-scheme: dark;
    }

    html,
    body {
      width: 100%;
      height: 100%;
      margin: 0;
      padding: 0;
      overflow: hidden;
      background: #000;
      color: #fff;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      font-size: 11px;
    }

    #status {
      position: fixed;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #000;
      color: rgb(255 255 255 / 60%);
      font-weight: 500;
      letter-spacing: 0;
      pointer-events: none;
      transition: opacity 200ms ease;
    }

    #status.hidden {
      opacity: 0;
    }

    #screen {
      width: 100%;
      height: 100%;
      background: #000;
    }

    /* noVNC sets an inline cursor on every frame. Keep a local cursor visible. */
    #screen,
    #screen canvas {
      cursor: default !important;
    }

    #noVNC_control_bar_anchor,
    #noVNC_control_bar {
      display: none !important;
    }
  sunrise.html: |
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="utf-8" />
      <title>Sunrise Console</title>
      <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
      <link rel="stylesheet" href="./sunrise.css" />
    </head>
    <body>
      <div id="status">Connecting…</div>
      <div id="screen"></div>
      <script type="module" src="./sunrise.js"></script>
    </body>
    </html>
  sunrise.js: |
    import RFB from "./core/rfb.js";

    const params = new URLSearchParams(window.location.search);
    const path = params.get("path") || "";
    const parentOriginParam = params.get("parentOrigin");

    function trustedParentOrigin(value) {
      if (!value) return null;
      try {
        const parsed = new URL(value);
        return parsed.protocol === "http:" || parsed.protocol === "https:"
          ? parsed.origin
          : null;
      } catch {
        return null;
      }
    }

    const parentOrigin = trustedParentOrigin(parentOriginParam);
    const protocol = window.location.protocol === "https:" ? "wss" : "ws";
    const port = window.location.port ? `:${window.location.port}` : "";
    const webSocketUrl = `${protocol}://${window.location.hostname}${port}/${path}`;
    const status = document.getElementById("status");

    function setStatus(message, hidden = false) {
      status.textContent = message;
      status.classList.toggle("hidden", hidden);
    }

    let rfb;
    try {
      rfb = new RFB(document.getElementById("screen"), webSocketUrl);
      rfb.viewOnly = false;
      rfb.scaleViewport = true;
      rfb.resizeSession = true;
      rfb.background = "#000";
      rfb.showDotCursor = true;
    } catch (error) {
      setStatus(`Failed to initialize: ${error.message}`);
      throw error;
    }

    rfb.addEventListener("connect", () => setStatus("Connected", true));
    rfb.addEventListener("disconnect", (event) =>
      setStatus(event.detail.clean ? "Disconnected" : "Connection lost"),
    );
    rfb.addEventListener("credentialsrequired", () => setStatus("Credentials required"));
    rfb.addEventListener("securityfailure", (event) =>
      setStatus(`Authentication failed: ${event.detail.reason || ""}`),
    );

    window.addEventListener("message", (event) => {
      if (!parentOrigin || event.origin !== parentOrigin || event.source !== window.parent) {
        return;
      }

      const { type, payload } = event.data || {};
      if (!rfb || typeof type !== "string") return;

      switch (type) {
        case "sunrise:ctrlAltDel":
          rfb.sendCtrlAltDel();
          break;
        case "sunrise:sendKey":
          rfb.sendKey(payload?.keysym, payload?.code, payload?.down);
          break;
        case "sunrise:disconnect":
          rfb.disconnect();
          break;
        case "sunrise:focus":
          rfb.focus();
          break;
        case "sunrise:ping":
          event.source?.postMessage({ type: "sunrise:pong" }, parentOrigin);
          break;
      }
    });

    if (parentOrigin && window.parent !== window) {
      window.parent.postMessage({ type: "sunrise:ready" }, parentOrigin);
    }
kind: ConfigMap
metadata:
  annotations:
    meta.helm.sh/release-name: nova
    meta.helm.sh/release-namespace: openstack
  creationTimestamp: "2026-11-06T22:01:17Z"
  labels:
    app.kubernetes.io/managed-by: Helm
  name: sunrise-novnc
  namespace: openstack
  resourceVersion: "16369"
  uid: d0912cd5-8d25-427e-a3ec-e556c192b080
