Log improvements - fixup in the other one

pull/25/head
Vasile Popescu 4 years ago committed by Elis Popescu
parent 2100e4ab90
commit 6c0171e9d9

@ -2,7 +2,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"net/http" "net/http"
"net/url" "net/url"
@ -36,7 +35,7 @@ func (w *wsTextWriter) Write(data []byte) (n int, err error) {
} }
func (c *ttyShareClient) Run() (err error) { func (c *ttyShareClient) Run() (err error) {
log.Debugf("Starting tty-share client on %s", c.url) log.Debugf("Connecting as a client to %s ..", c.url)
resp, err := http.Get(c.url) resp, err := http.Get(c.url)
@ -58,11 +57,11 @@ func (c *ttyShareClient) Run() (err error) {
} }
wsURL := wsScheme + "://" + httpURL.Host + wsPath wsURL := wsScheme + "://" + httpURL.Host + wsPath
log.Debugf("Connecting to WS URL: %s", wsURL) log.Debugf("Built the WS URL from the headers: %s", wsURL)
conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil) conn, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
if err != nil { if err != nil {
log.Fatal("Cannot create the websocket connection:", err) return
} }
state, err := terminal.MakeRaw(0) state, err := terminal.MakeRaw(0)
@ -74,7 +73,7 @@ func (c *ttyShareClient) Run() (err error) {
var msg ttyServer.MsgAll var msg ttyServer.MsgAll
_, r, err := conn.NextReader() _, r, err := conn.NextReader()
if err != nil { if err != nil {
fmt.Printf("Connection closed\n") log.Debugf("Connection closed\n")
return return
} }
err = json.NewDecoder(r).Decode(&msg) err = json.NewDecoder(r).Decode(&msg)
@ -93,7 +92,7 @@ func (c *ttyShareClient) Run() (err error) {
os.Stdout.Write(msgWrite.Data) os.Stdout.Write(msgWrite.Data)
case ttyServer.MsgIDWinSize: case ttyServer.MsgIDWinSize:
log.Debugf("Remote window changed its size") log.Infof("Remote window changed its size")
// We ignore the window size changes - can't do much about that for // We ignore the window size changes - can't do much about that for
// now. // now.
@ -108,11 +107,10 @@ func (c *ttyShareClient) Run() (err error) {
ww := &wsTextWriter{ ww := &wsTextWriter{
conn: conn, conn: conn,
} }
_, err := io.Copy(ttyServer.NewTTYProtocolWriter(ww), os.Stdin) _, err := io.Copy(ttyServer.NewTTYProtocolWriter(ww), os.Stdin)
if err != nil { if err != nil {
fmt.Printf("Connection closed.\n") log.Debugf("Connection closed.\n")
return return
} }
} }

@ -16,7 +16,6 @@ import (
var version string = "0.0.0" var version string = "0.0.0"
func createServer(frontListenAddress string, frontendPath string, tty io.Writer, sessionID string) *server.TTYServer { func createServer(frontListenAddress string, frontendPath string, tty io.Writer, sessionID string) *server.TTYServer {
config := ttyServer.TTYServerConfig{ config := ttyServer.TTYServerConfig{
FrontListenAddress: frontListenAddress, FrontListenAddress: frontListenAddress,
@ -51,7 +50,7 @@ Examples:
Join a remote session by providing the URL created another tty-share command: Join a remote session by providing the URL created another tty-share command:
tty-share http://localhost:8000/local/ tty-share http://localhost:8000/s/local/
Flags: Flags:
` `
@ -64,16 +63,16 @@ Flags:
listenAddress := flag.String("listen", "localhost:8000", "tty-server address") listenAddress := flag.String("listen", "localhost:8000", "tty-server address")
versionFlag := flag.Bool("version", false, "Print the tty-share version") versionFlag := flag.Bool("version", false, "Print the tty-share version")
frontendPath := flag.String("frontend-path", "", "The path to the frontend resources. By default, these resources are included in the server binary, so you only need this path if you don't want to use the bundled ones.") frontendPath := flag.String("frontend-path", "", "The path to the frontend resources. By default, these resources are included in the server binary, so you only need this path if you don't want to use the bundled ones.")
proxyServerAddress := flag.String("tty-proxy", "localhost:9000", "Address of the proxy for public facing connections") proxyServerAddress := flag.String("tty-proxy", "on.tty-share.com:4567", "Address of the proxy for public facing connections")
readOnly := flag.Bool("readonly", false, "Start a read only session") readOnly := flag.Bool("readonly", false, "Start a read only session")
publicSession := flag.Bool("public", false, "Create a public session") publicSession := flag.Bool("public", false, "Create a public session")
noTLS := flag.Bool("no-tls", false, "Don't use TLS to connect to the tty-proxy server. Useful for local debugging") noTLS := flag.Bool("no-tls", false, "Don't use TLS to connect to the tty-proxy server. Useful for local debugging")
verbose := flag.Bool("verbose", false, "Verbose logging")
flag.Usage = func() { flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "%s", usageString) fmt.Fprintf(flag.CommandLine.Output(), "%s", usageString)
flag.PrintDefaults() flag.PrintDefaults()
fmt.Fprintf(flag.CommandLine.Output(), "\n") fmt.Fprintf(flag.CommandLine.Output(), "\n")
} }
flag.Parse() flag.Parse()
if *versionFlag { if *versionFlag {
@ -81,6 +80,20 @@ Flags:
return return
} }
// Log setup
log.SetLevel(log.WarnLevel)
if *verbose {
log.SetLevel(log.DebugLevel)
}
if *logFileName != "-" {
logFile, err := os.Create(*logFileName)
if err != nil {
fmt.Printf("Can't open %s for writing logs\n", *logFileName)
}
log.SetOutput(logFile)
}
// tty-share can work in two modes: either starting a command to be shared by acting as a // tty-share can work in two modes: either starting a command to be shared by acting as a
// server, or by acting as a client for the remote side If we have an argument, that is not // server, or by acting as a client for the remote side If we have an argument, that is not
// a flag, passed to tty-share, we expect that to be the URl to connect to, as a // a flag, passed to tty-share, we expect that to be the URl to connect to, as a
@ -92,22 +105,12 @@ Flags:
err := client.Run() err := client.Run()
if err != nil { if err != nil {
fmt.Printf("Cannot connect to the remote session: %s\n", err.Error()) log.Errorf("Cannot connect to the remote session. Make sure the URL points to a valid tty-share session.", err.Error())
} }
return return
} }
log.SetLevel(log.InfoLevel) // tty-share works as a server, from here on
if *logFileName != "-" {
fmt.Printf("Writing logs to: %s\n", *logFileName)
logFile, err := os.Create(*logFileName)
if err != nil {
fmt.Printf("Can't open %s for writing logs\n", *logFileName)
}
log.SetLevel(log.DebugLevel)
log.SetOutput(logFile)
}
if !isStdinTerminal() { if !isStdinTerminal() {
fmt.Printf("Input not a tty\n") fmt.Printf("Input not a tty\n")
os.Exit(1) os.Exit(1)
@ -117,7 +120,7 @@ Flags:
if *publicSession { if *publicSession {
proxy, err := proxy.NewProxyConnection(*listenAddress, *proxyServerAddress, *noTLS) proxy, err := proxy.NewProxyConnection(*listenAddress, *proxyServerAddress, *noTLS)
if err != nil { if err != nil {
fmt.Printf("Can't connect to the proxy: %s\n", err.Error()) log.Errorf("Can't connect to the proxy: %s\n", err.Error())
return return
} }
@ -129,7 +132,7 @@ Flags:
// Display the session information to the user, before showing any output from the command. // Display the session information to the user, before showing any output from the command.
// Wait until the user presses Enter // Wait until the user presses Enter
fmt.Printf("local session: http://%s/local/\n", *listenAddress) fmt.Printf("local session: http://%s/s/local/\n", *listenAddress)
fmt.Printf("Press Enter to continue!\n") fmt.Printf("Press Enter to continue!\n")
bufio.NewReader(os.Stdin).ReadString('\n') bufio.NewReader(os.Stdin).ReadString('\n')
@ -158,7 +161,7 @@ Flags:
ptyMaster.Refresh() ptyMaster.Refresh()
}) })
if err != nil { if err != nil {
log.Error(err.Error()) log.Debugf("Server done: %s", err.Error())
} }
}() }()
@ -175,7 +178,6 @@ Flags:
}() }()
ptyMaster.Wait() ptyMaster.Wait()
fmt.Printf("tty-share finished.\n\r") fmt.Printf("tty-share finished\n\n")
server.Stop() server.Stop()
} }

@ -51,8 +51,9 @@ func NewProxyConnection(backConnAddrr, proxyAddr string, noTLS bool) (*proxyConn
} }
// C -> S: HelloCLient // C -> S: HelloCLient
// S -> C: HelloServer (sesionID) // S -> C: HelloServer {sesionID}
je := json.NewEncoder(conn) je := json.NewEncoder(conn)
// TODO: extract these strings constants somewhere at some point
helloC := HelloClient{ helloC := HelloClient{
Version: "1", Version: "1",
Data: "-", Data: "-",
@ -69,7 +70,7 @@ func NewProxyConnection(backConnAddrr, proxyAddr string, noTLS bool) (*proxyConn
return nil, err return nil, err
} }
log.Debugf("Got from the ReverseProxy: version=%s, sessionID=%s", helloS.Version, helloS.SessionID) log.Debugf("Connected to %s tty-proxy: version=%s, sessionID=%s", helloS.PublicURL, helloS.Version, helloS.SessionID)
session, err := yamux.Server(conn, nil) session, err := yamux.Server(conn, nil)
return &proxyConnection{ return &proxyConnection{
@ -82,21 +83,23 @@ func NewProxyConnection(backConnAddrr, proxyAddr string, noTLS bool) (*proxyConn
func (p *proxyConnection) RunProxy() { func (p *proxyConnection) RunProxy() {
for { for {
conn, err := p.muxSession.Accept() frontConn, err := p.muxSession.Accept()
if err != nil { if err != nil {
log.Errorf("tty-proxy connection closed.\n") log.Debugf("tty-proxy connection closed: %s", err.Error())
return return
} }
defer frontConn.Close()
go func() { go func() {
dst, err := net.Dial("tcp", p.backConnAddress) backConn, err := net.Dial("tcp", p.backConnAddress)
defer dst.Close()
defer conn.Close()
if err != nil { if err != nil {
log.Errorf("Client: Can't connect to the target HTTP server: %s\n", err.Error()) log.Errorf("Cannot proxy the connection to the target HTTP server: %s", err.Error())
return
} }
glueConnAndWait(dst, conn) defer backConn.Close()
pipeConnectionsAndWait(backConn, frontConn)
}() }()
} }
} }
@ -112,25 +115,36 @@ func errToString(err error) string {
return "nil" return "nil"
} }
func glueConnAndWait(conn1, conn2 net.Conn) error { func pipeConnectionsAndWait(backConn, frontConn net.Conn) error {
errChan := make(chan error, 2) errChan := make(chan error, 2)
log.Debugf("Starting the glue of the two conn %s %s", conn1.LocalAddr().String(), conn2.LocalAddr().String()) backConnAddr := backConn.RemoteAddr().String()
frontConnAddr := frontConn.RemoteAddr().String()
log.Debugf("Piping the two conn %s <-> %s ..", backConnAddr, frontConnAddr)
copyAndNotify := func(dst, src net.Conn) { copyAndNotify := func(dst, src net.Conn, info string) {
n, err := io.Copy(dst, src) n, err := io.Copy(dst, src)
log.Debugf("Wrote %d bytes, %s -> %s\n", n, src.LocalAddr().String(), dst.LocalAddr().String()) log.Debugf("%s: piping done with %d bytes, and err %s", info, n, errToString(err))
if err != nil {
log.Debugf(" -- ended with error: %s\n", err.Error())
}
errChan <- err errChan <- err
// Close both connections when done with copying. Yeah, both will beclosed two
// times, but it doesn't matter. By closing them both, we unblock the other copy
// call which would block indefinitely otherwise
dst.Close()
src.Close()
} }
go copyAndNotify(conn1, conn2) go copyAndNotify(backConn, frontConn, "front->back")
go copyAndNotify(conn2, conn1) go copyAndNotify(frontConn, backConn, "back->front")
err1 := <-errChan err1 := <-errChan
err2 := <-errChan err2 := <-errChan
log.Debugf("Finished the glued connections with: %s and %s", errToString(err1), errToString(err2)) log.Debugf("Piping finished for %s <-> %s .", backConnAddr, frontConnAddr)
return err1
// Return one of the two error that is not nil
if err1 != nil {
return err1
}
return err2
} }

@ -8,8 +8,8 @@ import (
"time" "time"
ptyDevice "github.com/elisescu/pty" ptyDevice "github.com/elisescu/pty"
"golang.org/x/crypto/ssh/terminal"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh/terminal"
) )
type onWindowChangedCB func(int, int) type onWindowChangedCB func(int, int)

@ -16,10 +16,10 @@ func newReadWriter(r io.Reader, w io.Writer) io.ReadWriter {
} }
} }
func (c *combiner)Read(p []byte) (n int, err error) { func (c *combiner) Read(p []byte) (n int, err error) {
return c.r.Read(p) return c.r.Read(p)
} }
func (c *combiner)Write(p []byte) (n int, err error) { func (c *combiner) Write(p []byte) (n int, err error) {
return c.w.Write(p) return c.w.Write(p)
} }

@ -1,26 +1,16 @@
TTY_SERVER=./tty-server
TTY_SERVER_ASSETS=$(wildcard frontend/public/*) frontend/public/index.html TTY_SERVER_ASSETS=$(wildcard frontend/public/*) frontend/public/index.html
TTY_SERVER_SRC=$(wildcard *.go) assets_bundle.go
.PHONY: all frontend clean cleanfront rebuild .PHONY: all frontend clean cleanfront rebuild
all: $(TTY_SERVER) all: assets_bundle.go
@echo "Done" @echo "Done"
rebuild: clean all rebuild: clean all
# Building the server and tty-share
$(TTY_SERVER): $(TTY_SERVER_SRC)
go build -o $@
assets_bundle.go: $(TTY_SERVER_ASSETS) assets_bundle.go: $(TTY_SERVER_ASSETS)
go get github.com/go-bindata/go-bindata/... go get github.com/go-bindata/go-bindata/...
go-bindata --prefix frontend/public/ -pkg server -o $@ frontend/public/* go-bindata --prefix frontend/public/ -pkg server -o $@ frontend/public/*
%.zip: %
zip $@ $^
frontend: cleanfront frontend/public/index.html assets_bundle.go frontend: cleanfront frontend/public/index.html assets_bundle.go
frontend/public/index.html: frontend/public/index.html:
@ -30,16 +20,5 @@ cleanfront:
rm -fr frontend/public rm -fr frontend/public
clean: cleanfront clean: cleanfront
rm -fr tty-server assets_bundle.go rm -fr assets_bundle.go
@echo "Cleaned" @echo "Cleaned"
## Development helper targets
### Runs the server, without TLS/HTTPS (no need for localhost testing)
runs: $(TTY_SERVER)
$(TTY_SERVER) --url http://localhost:9090 --web_address :9090 --sender_address :7654 -frontend_path ./frontend/public
### Runs the sender, without TLS (no need for localhost testing)
runc:
tty-share --useTLS=false --server localhost:7654
test:
@go test github.com/elisescu/tty-share/testing -v

@ -1,7 +1,6 @@
// Code generated for package server by go-bindata DO NOT EDIT. (@generated) // Code generated for package server by go-bindata DO NOT EDIT. (@generated)
// sources: // sources:
// frontend/public/404.css // frontend/public/404.css
// frontend/public/404.html
// frontend/public/404.in.html // frontend/public/404.in.html
// frontend/public/bootstrap.min.css // frontend/public/bootstrap.min.css
// frontend/public/tty-share.in.html // frontend/public/tty-share.in.html
@ -97,27 +96,7 @@ func _404Css() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "404.css", size: 3393, mode: os.FileMode(420), modTime: time.Unix(1601583738, 0)} info := bindataFileInfo{name: "404.css", size: 3393, mode: os.FileMode(420), modTime: time.Unix(1601755149, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var __404Html = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x91\xbd\x8e\xeb\x20\x10\x85\x7b\x3f\xc5\x84\xe6\x56\x84\x14\xae\x22\x4c\x73\xef\xad\x37\xd2\xa6\xd9\x12\xe3\xb1\x8d\x82\x01\x31\xb3\xc9\xe6\xed\x57\xb6\x53\xe4\xa7\xd8\xad\x90\xbe\xf9\x74\x74\xc4\xd1\x1b\x29\xe1\x38\x7a\x02\x4f\xc0\xf6\x84\x11\xfa\x92\xa6\x3d\x8c\xcc\x99\xf6\x4a\xb9\x14\x52\x09\xbe\xdd\xba\x34\xa9\x4b\x56\x7d\x41\x94\xf5\xae\x96\x58\x4a\x2a\x32\xdb\x01\x25\xe3\x94\x83\x65\x24\x05\x52\x9a\x4a\x6f\xfe\xbd\xfd\x3d\x7e\x1c\xfe\xc3\xc8\x53\x30\x55\xa5\xe7\x17\x82\x8d\x43\x23\x30\x0a\x53\xe9\x11\x6d\x67\x2a\x00\x00\x1d\x7c\x3c\x41\xc1\xd0\x08\xe2\x6b\x40\x1a\x11\x59\x00\x5f\x33\x36\x82\xf1\x8b\x95\x23\x12\x30\x16\xec\x1b\xa1\x88\x2d\x7b\xa7\xea\x5d\xbd\x9d\xb1\xa9\xb4\x5a\xa3\x74\x9b\xba\xeb\x2d\x91\xd0\xb1\x4f\x11\x7c\xd7\x88\x98\x58\xf6\xe9\x33\x76\x62\x3d\x2e\x42\xe7\xcf\xcb\x91\x3d\x07\x14\xe6\x3d\x4d\xc8\xa3\x8f\xc3\x1f\x82\x4b\x49\x71\xd0\xaa\xf3\xe7\x27\xdf\x05\x4b\xd4\x08\xe7\x8b\x0b\x48\x77\x69\x8b\x91\x4d\xbd\xab\x1f\xd0\x82\xdb\x62\x5e\x21\x4d\x36\x04\x73\xb0\x03\x42\x4c\x0c\x4b\x3b\xad\x56\xfa\x98\xaa\xf2\x13\xa0\x6c\xe3\x63\x13\x68\xfd\x20\x8c\x56\xf3\xe5\x67\x79\xc2\xee\xf7\xf2\xd2\xe8\x55\xbf\xfb\x1c\xad\x6e\x5f\x3d\xef\xb0\x0e\x30\x0f\xb2\x8c\xfe\x1d\x00\x00\xff\xff\xd2\xed\xfa\x10\x59\x02\x00\x00")
func _404HtmlBytes() ([]byte, error) {
return bindataRead(
__404Html,
"404.html",
)
}
func _404Html() (*asset, error) {
bytes, err := _404HtmlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "404.html", size: 601, mode: os.FileMode(420), modTime: time.Unix(1601583738, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -137,7 +116,7 @@ func _404InHtml() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "404.in.html", size: 616, mode: os.FileMode(420), modTime: time.Unix(1601583738, 0)} info := bindataFileInfo{name: "404.in.html", size: 616, mode: os.FileMode(420), modTime: time.Unix(1601755149, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -157,12 +136,12 @@ func bootstrapMinCss() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "bootstrap.min.css", size: 140930, mode: os.FileMode(420), modTime: time.Unix(1601583738, 0)} info := bindataFileInfo{name: "bootstrap.min.css", size: 140930, mode: os.FileMode(420), modTime: time.Unix(1601755149, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
var _ttyShareInHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\x92\xcf\xaf\xdb\x20\x0c\xc7\xef\xef\xaf\xf0\xe3\x4e\xd0\x6e\xd3\x44\x7a\x9a\x26\xed\x56\x69\x9d\x76\x76\x82\x37\x5c\x25\x10\x81\x97\x34\x8a\xf2\xbf\x4f\x09\x52\x9b\xaa\x7b\x5c\xc0\xe6\xeb\x8f\x7f\x80\x7d\x77\xb1\x95\x79\x20\xf0\xd2\x77\xa7\x37\x5b\x36\x00\x00\xeb\x09\x5d\x39\xee\x66\x4f\x82\xd0\x7a\x4c\x99\xa4\x56\x3f\x2f\xdf\xf4\x67\x75\xb8\x16\x96\x8e\x4e\x22\xb3\xce\x1e\x13\x59\x53\x1c\x05\x65\x1e\x2c\xdb\x44\x37\x1f\xe2\xde\xb5\x86\x8b\xe7\x0c\x8e\x47\x40\x91\xc4\xcd\x5f\xa1\x0c\x13\x77\x1d\x34\x04\x89\xd0\x41\x33\x83\x78\x82\x3b\x1d\xda\xd8\xf7\x18\x1c\x4c\x9e\x02\x24\x0c\x10\xc3\xae\x48\xd4\x47\x21\xc8\xec\x08\xb4\x3e\xa4\xd9\xe8\xec\x6a\x75\x47\xe8\xad\x1f\x05\x43\x8a\x12\xf5\x48\x29\x73\x0c\xb5\xfa\xa4\x60\xca\x7a\x40\xf1\xb5\x5a\x96\xea\xd7\x8f\x33\x8a\x5f\x57\x75\xb2\xc6\xf1\xf8\x3f\x1e\xa5\x9e\x03\x76\x1f\x2b\x32\x89\x70\xf8\x93\x5f\x15\xb9\x4d\x3c\x08\x6c\xe3\xdf\x40\x37\x31\x57\x1c\xb1\x78\x0f\xa3\xdd\xd6\xc4\xc1\xc5\xa9\x12\x99\xbf\x07\x16\xc6\xee\x2b\x0a\x42\x0d\xcb\x93\x6a\x57\xe6\xad\xe4\x2f\x70\xa8\xfe\x49\xf3\xb0\xac\x29\xa9\x5e\x2b\xca\xa9\xad\x95\x59\x96\x6a\x8b\x3f\x27\xfa\xcd\xb7\x75\x35\x59\x50\xb8\x35\xf7\x09\x56\xd7\xbd\xa7\x23\xc4\x9a\xf2\xba\xd6\x94\x7f\xf4\xf6\x2f\x00\x00\xff\xff\x73\xbb\x5a\x79\x60\x02\x00\x00") var _ttyShareInHtml = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x6c\x91\x4d\x6b\xc3\x30\x0c\x86\xef\xfd\x15\x5a\xee\x8d\xaf\x63\x38\x39\x8d\xc1\x6e\x85\x6d\xec\xac\xd9\xde\xac\x92\x8f\x62\xbf\xa4\x0d\x26\xff\x7d\x38\x86\x35\xa5\xf3\xc5\x92\xfc\xe8\xb5\x3e\xf4\x83\x1d\x0d\xe6\x93\x23\x8f\xbe\x6b\x77\xba\x5c\x44\x44\xda\x3b\xb6\xc5\x5c\xdd\xde\x81\xc9\x78\x0e\xd1\xa1\xa9\x3e\xde\x5f\xf6\x8f\xd5\xe6\x19\x82\xce\xb5\xc0\xbc\x8f\x9e\x83\xd3\xaa\x04\x8a\x94\xba\x6a\xe9\xaf\xd1\xce\x9b\x3c\x2b\x13\x89\x6d\x2a\xb8\xd0\xcb\xc0\x5d\xd5\x6a\x65\x65\xfa\x87\x88\x0e\x90\xe1\x27\xde\x13\xd1\x04\x39\x81\x72\x1f\x59\xe8\x02\x75\xe4\x89\x4b\x74\x53\x63\x3e\x67\x19\xec\x78\xae\x81\xf9\x75\x10\x08\x77\xcf\x0c\xa6\x86\xd2\x0d\xb5\x92\xf1\xc0\xf0\x4f\x94\x52\xfd\xf9\x96\xcd\x65\xb9\x61\xae\x9e\x56\xe5\xab\xfb\x8a\x62\x30\x4d\x95\x52\x9d\xd3\x0f\xc1\x7d\xcb\x65\x59\x54\x04\x43\x8c\xfa\x1b\x55\x7d\x5c\x5b\xda\x6a\x68\x55\xa6\xa4\x55\xd9\xc7\xee\x37\x00\x00\xff\xff\xe1\xc2\xa8\xce\xa8\x01\x00\x00")
func ttyShareInHtmlBytes() ([]byte, error) { func ttyShareInHtmlBytes() ([]byte, error) {
return bindataRead( return bindataRead(
@ -177,7 +156,7 @@ func ttyShareInHtml() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "tty-share.in.html", size: 608, mode: os.FileMode(420), modTime: time.Unix(1601583738, 0)} info := bindataFileInfo{name: "tty-share.in.html", size: 424, mode: os.FileMode(420), modTime: time.Unix(1601755149, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -197,7 +176,7 @@ func ttyShareJs() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "tty-share.js", size: 404641, mode: os.FileMode(420), modTime: time.Unix(1601583738, 0)} info := bindataFileInfo{name: "tty-share.js", size: 404641, mode: os.FileMode(420), modTime: time.Unix(1601755149, 0)}
a := &asset{bytes: bytes, info: info} a := &asset{bytes: bytes, info: info}
return a, nil return a, nil
} }
@ -255,7 +234,6 @@ func AssetNames() []string {
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() (*asset, error){
"404.css": _404Css, "404.css": _404Css,
"404.html": _404Html,
"404.in.html": _404InHtml, "404.in.html": _404InHtml,
"bootstrap.min.css": bootstrapMinCss, "bootstrap.min.css": bootstrapMinCss,
"tty-share.in.html": ttyShareInHtml, "tty-share.in.html": ttyShareInHtml,
@ -304,7 +282,6 @@ type bintree struct {
var _bintree = &bintree{nil, map[string]*bintree{ var _bintree = &bintree{nil, map[string]*bintree{
"404.css": &bintree{_404Css, map[string]*bintree{}}, "404.css": &bintree{_404Css, map[string]*bintree{}},
"404.html": &bintree{_404Html, map[string]*bintree{}},
"404.in.html": &bintree{_404InHtml, map[string]*bintree{}}, "404.in.html": &bintree{_404InHtml, map[string]*bintree{}},
"bootstrap.min.css": &bintree{bootstrapMinCss, map[string]*bintree{}}, "bootstrap.min.css": &bintree{bootstrapMinCss, map[string]*bintree{}},
"tty-share.in.html": &bintree{ttyShareInHtml, map[string]*bintree{}}, "tty-share.in.html": &bintree{ttyShareInHtml, map[string]*bintree{}},

@ -1,23 +0,0 @@
<!-- This is taken from: https://colorlib.com/wp/free-404-error-page-templates/ -->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="/static/404.css">
</head>
<body>
<section id="not-found">
<div id="title">Something's wrong</div>
<div class="circles">
<p>404
<br>
<small>Page not found</small>
</p>
<span class="circle big"></span>
<span class="circle med"></span>
<span class="circle small"></span>
</div>
</section>
</body>
</html>

@ -12,7 +12,7 @@
wsPath: {{.WSPath}} wsPath: {{.WSPath}}
} }
</script> </script>
<script src="/{{.PathPrefix}}/static/tty-share.js"></script> <script src="{{.PathPrefix}}/static/tty-share.js"></script>
</body> </body>
</html> </html>

@ -88,25 +88,28 @@ func NewTTYServer(config TTYServerConfig) (server *TTYServer) {
routesHandler := mux.NewRouter() routesHandler := mux.NewRouter()
installHandlers := func(session string) { installHandlers := func(session string) {
path := fmt.Sprintf("/%s/static/", session) path := fmt.Sprintf("/s/%s/static/", session)
routesHandler.PathPrefix(path).Handler(http.StripPrefix(path, routesHandler.PathPrefix(path).Handler(http.StripPrefix(path,
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server.serveContent(w, r, r.URL.Path) server.serveContent(w, r, r.URL.Path)
}))) })))
routesHandler.HandleFunc(fmt.Sprintf("/%s/", session), func(w http.ResponseWriter, r *http.Request) { routesHandler.HandleFunc(fmt.Sprintf("/s/%s/", session), func(w http.ResponseWriter, r *http.Request) {
wsPath := "/" + session + "/ws" wsPath := "/s/" + session + "/ws"
pathPrefix := "/s/" + session
// Check the frontend/templates/tty-share.in.html file to see where the template applies
templateModel := struct { templateModel := struct {
PathPrefix string PathPrefix string
WSPath string WSPath string
}{session, wsPath} }{pathPrefix, wsPath}
// Extract these in constants
// TODO Extract these in constants
w.Header().Add("TTYSHARE-VERSION", "1") w.Header().Add("TTYSHARE-VERSION", "1")
w.Header().Add("TTYSHARE-WSPATH", wsPath) w.Header().Add("TTYSHARE-WSPATH", wsPath)
server.handleWithTemplateHtml(w, r, "tty-share.in.html", templateModel) server.handleWithTemplateHtml(w, r, "tty-share.in.html", templateModel)
}) })
routesHandler.HandleFunc(fmt.Sprintf("/%s/ws", session), func(w http.ResponseWriter, r *http.Request) { routesHandler.HandleFunc(fmt.Sprintf("/s/%s/ws", session), func(w http.ResponseWriter, r *http.Request) {
server.handleWebsocket(w, r) server.handleWebsocket(w, r)
}) })
routesHandler.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { routesHandler.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

@ -126,7 +126,7 @@ func (session *ttyShareSession) HandleWSConnection(wsConn *WSConnection) {
lastWindowSizeData, _ := MarshalMsg(session.lastWindowSizeMsg) lastWindowSizeData, _ := MarshalMsg(session.lastWindowSizeMsg)
session.mainRWLock.Unlock() session.mainRWLock.Unlock()
log.Debugf("Got new TTYReceiver connection (%s). Serving it..", wsConn.Address()) log.Debugf("New WS connection (%s). Serving ..", wsConn.Address())
// Sending the initial size of the window, if we have one // Sending the initial size of the window, if we have one
rcvWriter.WriteRawData(lastWindowSizeData) rcvWriter.WriteRawData(lastWindowSizeData)
@ -135,13 +135,13 @@ func (session *ttyShareSession) HandleWSConnection(wsConn *WSConnection) {
for { for {
msg, err := rcvReader.ReadMessage() msg, err := rcvReader.ReadMessage()
if err != nil { if err != nil {
log.Warnf("Finishing handling the TTYReceiver loop because: %s", err.Error()) log.Debugf("Finished the WS reading loop: %s", err.Error())
break break
} }
// We only support MsgTTYWrite from the web terminal for now // We only support MsgTTYWrite from the web terminal for now
if msg.Type != MsgIDWrite { if msg.Type != MsgIDWrite {
log.Warnf("TTYReceiver sent unknown message type %s", msg.Type) log.Warnf("Unknown message over the WS connection: type %s", msg.Type)
break break
} }

Loading…
Cancel
Save