feat: Web Terminal (xterm.js + PTY over WebSocket) + SSH-Copy-Karte im Tunnel-Tab
This commit is contained in:
+42
-2
@@ -29,6 +29,10 @@ type Hub struct {
|
||||
|
||||
// Event-Callback fuer DB-Events bei Connect/Disconnect
|
||||
eventCallback func(agentID, eventType, message string)
|
||||
|
||||
// PTY-Sessions: session_id -> channel fuer Ausgabe an Browser
|
||||
ptySessions map[string]chan []byte
|
||||
ptySessionsMux sync.RWMutex
|
||||
}
|
||||
|
||||
func NewHub() *Hub {
|
||||
@@ -41,6 +45,7 @@ func NewHub() *Hub {
|
||||
}
|
||||
|
||||
hub.tunnelManager = NewTunnelManager(hub)
|
||||
hub.ptySessions = make(map[string]chan []byte)
|
||||
return hub
|
||||
}
|
||||
|
||||
@@ -281,8 +286,28 @@ func (h *Hub) ProcessAgentMessage(agentID string, messageType int, data []byte)
|
||||
agent.LastSeen = time.Now()
|
||||
}
|
||||
|
||||
// Binary Messages sind normalerweise Tunnel-Daten
|
||||
// Binary Messages: PTY oder Tunnel
|
||||
if messageType == 2 { // websocket.BinaryMessage
|
||||
// PTY-Session erkennen: session_id beginnt mit "pty-"
|
||||
if len(data) > 1 {
|
||||
idLen := int(data[0])
|
||||
if 1+idLen <= len(data) {
|
||||
sessionID := string(data[1 : 1+idLen])
|
||||
payload := data[1+idLen:]
|
||||
if len(sessionID) >= 4 && sessionID[:4] == "pty-" {
|
||||
h.ptySessionsMux.RLock()
|
||||
ch, ok := h.ptySessions[sessionID]
|
||||
h.ptySessionsMux.RUnlock()
|
||||
if ok {
|
||||
select {
|
||||
case ch <- payload:
|
||||
default:
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return h.tunnelManager.ProcessBinaryMessage(agentID, data)
|
||||
}
|
||||
|
||||
@@ -333,4 +358,19 @@ func (h *Hub) ProcessAgentMessage(agentID string, messageType int, data []byte)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
// RegisterPTYSession registriert einen Output-Channel fuer eine PTY-Session
|
||||
func (h *Hub) RegisterPTYSession(sessionID string) chan []byte {
|
||||
ch := make(chan []byte, 256)
|
||||
h.ptySessionsMux.Lock()
|
||||
h.ptySessions[sessionID] = ch
|
||||
h.ptySessionsMux.Unlock()
|
||||
return ch
|
||||
}
|
||||
|
||||
// UnregisterPTYSession entfernt eine PTY-Session
|
||||
func (h *Hub) UnregisterPTYSession(sessionID string) {
|
||||
h.ptySessionsMux.Lock()
|
||||
delete(h.ptySessions, sessionID)
|
||||
h.ptySessionsMux.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user