mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-04-18 10:02:16 +00:00
Update terminal panel
This commit is contained in:
@@ -32,7 +32,7 @@ import { DialogHeader, DialogDescription } from "@/components/ui/dialog"
|
|||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Dialog as SearchDialog, DialogContent as SearchDialogContent, DialogTitle as SearchDialogTitle } from "@/components/ui/dialog"
|
import { Dialog as SearchDialog, DialogContent as SearchDialogContent, DialogTitle as SearchDialogTitle } from "@/components/ui/dialog"
|
||||||
import "@xterm/xterm/css/xterm.css"
|
import "@xterm/xterm/css/xterm.css"
|
||||||
import { fetchApi, getWebSocketUrl } from "@/lib/api-config"
|
import { API_PORT, fetchApi } from "@/lib/api-config"
|
||||||
|
|
||||||
interface LxcTerminalModalProps {
|
interface LxcTerminalModalProps {
|
||||||
open: boolean
|
open: boolean
|
||||||
@@ -75,7 +75,21 @@ const proxmoxCommands = [
|
|||||||
{ cmd: "clear", desc: "Clear terminal screen" },
|
{ cmd: "clear", desc: "Clear terminal screen" },
|
||||||
]
|
]
|
||||||
|
|
||||||
// Use centralized getWebSocketUrl from api-config
|
function getWebSocketUrl(): string {
|
||||||
|
if (typeof window === "undefined") {
|
||||||
|
return "ws://localhost:8008/ws/terminal"
|
||||||
|
}
|
||||||
|
|
||||||
|
const { protocol, hostname, port } = window.location
|
||||||
|
const isStandardPort = port === "" || port === "80" || port === "443"
|
||||||
|
const wsProtocol = protocol === "https:" ? "wss:" : "ws:"
|
||||||
|
|
||||||
|
if (isStandardPort) {
|
||||||
|
return `${wsProtocol}//${hostname}/ws/terminal`
|
||||||
|
} else {
|
||||||
|
return `${wsProtocol}//${hostname}:${API_PORT}/ws/terminal`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function LxcTerminalModal({
|
export function LxcTerminalModal({
|
||||||
open: isOpen,
|
open: isOpen,
|
||||||
@@ -208,7 +222,7 @@ export function LxcTerminalModal({
|
|||||||
fitAddonRef.current = fitAddon
|
fitAddonRef.current = fitAddon
|
||||||
|
|
||||||
// Connect WebSocket to host terminal
|
// Connect WebSocket to host terminal
|
||||||
const wsUrl = getWebSocketUrl("/ws/terminal")
|
const wsUrl = getWebSocketUrl()
|
||||||
const ws = new WebSocket(wsUrl)
|
const ws = new WebSocket(wsUrl)
|
||||||
wsRef.current = ws
|
wsRef.current = ws
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import {
|
|||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu"
|
||||||
import "@xterm/xterm/css/xterm.css"
|
import "@xterm/xterm/css/xterm.css"
|
||||||
import { getWebSocketUrl } from "@/lib/api-config"
|
import { API_PORT } from "@/lib/api-config"
|
||||||
|
|
||||||
interface WebInteraction {
|
interface WebInteraction {
|
||||||
type: "yesno" | "menu" | "msgbox" | "input" | "inputbox"
|
type: "yesno" | "menu" | "msgbox" | "input" | "inputbox"
|
||||||
@@ -96,7 +96,7 @@ export function ScriptTerminalModal({
|
|||||||
wsRef.current.close()
|
wsRef.current.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
const wsUrl = getScriptWebSocketUrlLocal(sessionIdRef.current)
|
const wsUrl = getScriptWebSocketUrl(sessionIdRef.current)
|
||||||
const ws = new WebSocket(wsUrl)
|
const ws = new WebSocket(wsUrl)
|
||||||
wsRef.current = ws
|
wsRef.current = ws
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ export function ScriptTerminalModal({
|
|||||||
}
|
}
|
||||||
}, 100)
|
}, 100)
|
||||||
|
|
||||||
const wsUrl = getScriptWebSocketUrlLocal(sessionIdRef.current)
|
const wsUrl = getScriptWebSocketUrl(sessionIdRef.current)
|
||||||
const ws = new WebSocket(wsUrl)
|
const ws = new WebSocket(wsUrl)
|
||||||
wsRef.current = ws
|
wsRef.current = ws
|
||||||
|
|
||||||
@@ -493,9 +493,20 @@ export function ScriptTerminalModal({
|
|||||||
}
|
}
|
||||||
}, [isOpen, isComplete, attemptReconnect])
|
}, [isOpen, isComplete, attemptReconnect])
|
||||||
|
|
||||||
// Use centralized getWebSocketUrl from api-config
|
const getScriptWebSocketUrl = (sid: string): string => {
|
||||||
const getScriptWebSocketUrlLocal = (sid: string): string => {
|
if (typeof window === "undefined") {
|
||||||
return getWebSocketUrl(`/ws/script/${sid}`)
|
return `ws://localhost:${API_PORT}/ws/script/${sid}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const { protocol, hostname, port } = window.location
|
||||||
|
const isStandardPort = port === "" || port === "80" || port === "443"
|
||||||
|
const wsProtocol = protocol === "https:" ? "wss:" : "ws:"
|
||||||
|
|
||||||
|
if (isStandardPort) {
|
||||||
|
return `${wsProtocol}//${hostname}/ws/script/${sid}`
|
||||||
|
} else {
|
||||||
|
return `${wsProtocol}//${hostname}:${API_PORT}/ws/script/${sid}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleInteractionResponse = (value: string) => {
|
const handleInteractionResponse = (value: string) => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import type React from "react"
|
import type React from "react"
|
||||||
import { useEffect, useRef, useState } from "react"
|
import { useEffect, useRef, useState } from "react"
|
||||||
import { API_PORT, fetchApi, getWebSocketUrl as getWebSocketUrlFromConfig, getApiUrl as getApiUrlFromConfig } from "@/lib/api-config"
|
import { API_PORT, fetchApi } from "@/lib/api-config" // Unificando importaciones de api-config en una sola línea con alias @/
|
||||||
import {
|
import {
|
||||||
Activity,
|
Activity,
|
||||||
Trash2,
|
Trash2,
|
||||||
@@ -46,13 +46,31 @@ interface TerminalInstance {
|
|||||||
pingInterval?: ReturnType<typeof setInterval> | null // Heartbeat interval to keep connection alive
|
pingInterval?: ReturnType<typeof setInterval> | null // Heartbeat interval to keep connection alive
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use centralized functions from api-config.ts for SSL/proxy support
|
|
||||||
function getWebSocketUrl(): string {
|
function getWebSocketUrl(): string {
|
||||||
return getWebSocketUrlFromConfig("/ws/terminal")
|
if (typeof window === "undefined") {
|
||||||
|
return "ws://localhost:8008/ws/terminal"
|
||||||
|
}
|
||||||
|
|
||||||
|
const { protocol, hostname, port } = window.location
|
||||||
|
const isStandardPort = port === "" || port === "80" || port === "443"
|
||||||
|
|
||||||
|
const wsProtocol = protocol === "https:" ? "wss:" : "ws:"
|
||||||
|
|
||||||
|
if (isStandardPort) {
|
||||||
|
return `${wsProtocol}//${hostname}/ws/terminal`
|
||||||
|
} else {
|
||||||
|
return `${wsProtocol}//${hostname}:${API_PORT}/ws/terminal`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getApiUrl(endpoint?: string): string {
|
function getApiUrl(endpoint?: string): string {
|
||||||
return getApiUrlFromConfig(endpoint || "")
|
if (typeof window === "undefined") {
|
||||||
|
return "http://localhost:8008"
|
||||||
|
}
|
||||||
|
|
||||||
|
const { protocol, hostname } = window.location
|
||||||
|
const apiProtocol = protocol === "https:" ? "https:" : "http:"
|
||||||
|
return `${apiProtocol}//${hostname}:${API_PORT}${endpoint || ""}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const proxmoxCommands = [
|
const proxmoxCommands = [
|
||||||
|
|||||||
@@ -50,41 +50,6 @@ export function getApiUrl(endpoint: string): string {
|
|||||||
return `${baseUrl}${normalizedEndpoint}`
|
return `${baseUrl}${normalizedEndpoint}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the base URL for WebSocket connections
|
|
||||||
* Automatically handles ws:// vs wss:// based on page protocol (SSL support)
|
|
||||||
*
|
|
||||||
* @param path - WebSocket endpoint path (e.g., '/ws/terminal')
|
|
||||||
* @returns Full WebSocket URL
|
|
||||||
*/
|
|
||||||
export function getWebSocketUrl(path: string): string {
|
|
||||||
if (typeof window === "undefined") {
|
|
||||||
return `ws://localhost:${API_PORT}${path}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const { protocol, hostname, port } = window.location
|
|
||||||
const isStandardPort = port === "" || port === "80" || port === "443"
|
|
||||||
|
|
||||||
// Use wss:// when page is served over https://
|
|
||||||
const wsProtocol = protocol === "https:" ? "wss:" : "ws:"
|
|
||||||
|
|
||||||
// Ensure path starts with /
|
|
||||||
const normalizedPath = path.startsWith("/") ? path : `/${path}`
|
|
||||||
|
|
||||||
let wsUrl: string
|
|
||||||
if (isStandardPort) {
|
|
||||||
// Behind a proxy - WebSocket goes through same host
|
|
||||||
wsUrl = `${wsProtocol}//${hostname}${normalizedPath}`
|
|
||||||
} else {
|
|
||||||
// Direct access - use API port
|
|
||||||
wsUrl = `${wsProtocol}//${hostname}:${API_PORT}${normalizedPath}`
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`[v0] getWebSocketUrl: protocol=${protocol}, hostname=${hostname}, port=${port}, isStandardPort=${isStandardPort}, wsUrl=${wsUrl}`)
|
|
||||||
|
|
||||||
return wsUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the JWT token from localStorage
|
* Gets the JWT token from localStorage
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user