62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"converge/pkg/iowrappers"
|
|
"converge/pkg/websocketutil"
|
|
"fmt"
|
|
"github.com/gorilla/websocket"
|
|
"log"
|
|
"net"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func closeConnection(conn net.Conn) {
|
|
if tcpConn, ok := conn.(*net.TCPConn); ok {
|
|
tcpConn.SetLinger(0)
|
|
}
|
|
_ = conn.Close()
|
|
}
|
|
|
|
type Stdio struct{}
|
|
|
|
func (stdio Stdio) Read(b []byte) (n int, err error) {
|
|
return os.Stdin.Read(b)
|
|
}
|
|
func (stdio Stdio) Write(b []byte) (n int, err error) {
|
|
return os.Stdout.Write(b)
|
|
}
|
|
|
|
func main() {
|
|
if len(os.Args) != 2 {
|
|
fmt.Fprintln(os.Stderr, "Usage: tcptows ws[s]://<host>[:port]/client/<ID>")
|
|
fmt.Fprintln(os.Stderr)
|
|
fmt.Fprintln(os.Stderr, "Here <ID> is the rendez-vous id of a continuous integratio job")
|
|
fmt.Fprintln(os.Stderr, "Use this in an ssh command like this; ")
|
|
fmt.Fprintln(os.Stderr)
|
|
fmt.Fprintln(os.Stderr, " ssh -oProxyCommand='wsproxy ws[s]://<host>[:port]/client/<ID>' abc@localhost")
|
|
fmt.Fprintln(os.Stderr)
|
|
fmt.Fprintln(os.Stderr, "This lets ssh connect through wsproxy to the remote websocket on")
|
|
fmt.Fprintln(os.Stderr, "Converge server.")
|
|
fmt.Fprintln(os.Stderr)
|
|
os.Exit(1)
|
|
}
|
|
|
|
wsURL := os.Args[1]
|
|
|
|
_wsConn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
_wsConn.SetReadDeadline(time.Time{})
|
|
_wsConn.SetWriteDeadline(time.Time{})
|
|
if err != nil {
|
|
log.Println("WebSocket connection error:", err)
|
|
panic(err)
|
|
}
|
|
wsConn := websocketutil.NewWebSocketConn(_wsConn)
|
|
defer wsConn.Close()
|
|
|
|
iowrappers.SynchronizeStreams(wsConn, Stdio{})
|
|
}
|