diff --git a/AppImage/components/lxc-terminal-modal.tsx b/AppImage/components/lxc-terminal-modal.tsx index fa718f17..cc5d33e2 100644 --- a/AppImage/components/lxc-terminal-modal.tsx +++ b/AppImage/components/lxc-terminal-modal.tsx @@ -24,9 +24,9 @@ interface LxcTerminalModalProps { vmName: string } -function getWebSocketUrl(): string { +function getWebSocketUrl(vmid: number): string { if (typeof window === "undefined") { - return "ws://localhost:8008/ws/terminal" + return `ws://localhost:8008/ws/terminal/lxc/${vmid}` } const { protocol, hostname, port } = window.location @@ -34,9 +34,9 @@ function getWebSocketUrl(): string { const wsProtocol = protocol === "https:" ? "wss:" : "ws:" if (isStandardPort) { - return `${wsProtocol}//${hostname}/ws/terminal` + return `${wsProtocol}//${hostname}/ws/terminal/lxc/${vmid}` } else { - return `${wsProtocol}//${hostname}:${API_PORT}/ws/terminal` + return `${wsProtocol}//${hostname}:${API_PORT}/ws/terminal/lxc/${vmid}` } } @@ -98,15 +98,11 @@ export function LxcTerminalModal({ // Small delay to ensure Dialog content is rendered const initTimeout = setTimeout(() => { - if (!terminalContainerRef.current) { - console.log("[v0] Terminal container not ready") - return - } + if (!terminalContainerRef.current) return initTerminal() }, 100) const initTerminal = async () => { - console.log("[v0] Initializing LXC terminal for vmid:", vmid) const [TerminalClass, FitAddonClass] = await Promise.all([ import("xterm").then((mod) => mod.Terminal), import("xterm-addon-fit").then((mod) => mod.FitAddon), @@ -160,14 +156,12 @@ export function LxcTerminalModal({ termRef.current = term fitAddonRef.current = fitAddon - // Connect WebSocket - const wsUrl = getWebSocketUrl() - console.log("[v0] LXC Terminal connecting to:", wsUrl) + // Connect WebSocket - direct connection to LXC container + const wsUrl = getWebSocketUrl(vmid) const ws = new WebSocket(wsUrl) wsRef.current = ws ws.onopen = () => { - console.log("[v0] LXC Terminal WebSocket connected") setConnectionStatus("online") // Start heartbeat ping @@ -181,22 +175,13 @@ export function LxcTerminalModal({ } }, 25000) - // Sync terminal size first + // Sync terminal size fitAddon.fit() ws.send(JSON.stringify({ type: "resize", cols: term.cols, rows: term.rows, })) - - // Auto-execute pct enter command after terminal is ready - // Wait for shell prompt to appear before sending command - setTimeout(() => { - if (ws.readyState === WebSocket.OPEN) { - // Send the command as plain text like user would type - ws.send(`pct enter ${vmid}\r`) - } - }, 800) } ws.onmessage = (event) => { @@ -207,14 +192,12 @@ export function LxcTerminalModal({ term.write(event.data) } - ws.onerror = (error) => { - console.log("[v0] LXC Terminal WebSocket error:", error) + ws.onerror = () => { setConnectionStatus("offline") term.writeln("\r\n\x1b[31m[ERROR] WebSocket connection error\x1b[0m") } - ws.onclose = (event) => { - console.log("[v0] LXC Terminal WebSocket closed:", event.code, event.reason) + ws.onclose = () => { setConnectionStatus("offline") if (pingIntervalRef.current) { clearInterval(pingIntervalRef.current) @@ -397,13 +380,13 @@ export function LxcTerminalModal({ {/* Mobile/Tablet control buttons */} {showMobileControls && ( -