agent is now setting up ws connection to server.

Next: adding multiplexing and listening on a socket.
This commit is contained in:
Erik Brakkee 2024-07-20 10:56:14 +02:00
parent f3cbd9012a
commit 6c8e0adccf
2 changed files with 20 additions and 3 deletions

View File

@ -1,7 +1,9 @@
package main
import (
"cidebug/pkg/iowrappers"
"fmt"
"github.com/gorilla/websocket"
"io"
"log"
"net"
@ -27,7 +29,7 @@ func SftpHandler(sess ssh.Session) {
if err != nil {
log.Printf("sftp tcpserver init error: %s\n", err)
return
}F
}
if err := server.Serve(); err == io.EOF {
server.Close()
fmt.Println("sftp client exited session.")
@ -46,7 +48,7 @@ func setWinsize(f *os.File, w, h int) {
uintptr(unsafe.Pointer(&struct{ h, w, x, y uint16 }{uint16(h), uint16(w), 0, 0})))
}
func main() {
func mainSsh() {
ssh.Handle(func(s ssh.Session) {
cmd := exec.Command("bash")
ptyReq, winCh, isPty := s.Pty()
@ -100,3 +102,18 @@ func main() {
//log.Fatal(server.ListenAndServe())
}
func main() {
wsURL := os.Args[1]
conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
if err != nil {
log.Println("WebSocket connection error:", err)
return
}
wsConn := iowrappers.NewWebSocketConn(conn)
defer wsConn.Close()
// echo server
iowrappers.SynchronizeStreams(wsConn, wsConn)
}

View File

@ -219,7 +219,7 @@ func main() {
},
}
http.HandleFunc("/register/", registrationService.handle)
http.HandleFunc("/agent/", registrationService.handle)
http.HandleFunc("/client/", clientService.handle)
// Start HTTP server