Browse Source

Host SSH server

master
Trevor Slocum 2 years ago
parent
commit
9fb58ec777
  1. 4
      client.go
  2. 7
      go.mod
  3. 30
      go.sum
  4. 33
      main.go
  5. 10
      server.go
  6. 17
      ssh.go
  7. 5
      ssh_windows.go

4
client.go

@ -104,13 +104,13 @@ func (c *Client) read(message string) { @@ -104,13 +104,13 @@ func (c *Client) read(message string) {
func (c *Client) handleRead() {
if c.ConnType == ClientWebsocket {
for {
_, message, err := c.ConnWebsocket.ReadMessage()
messageType, message, err := c.ConnWebsocket.ReadMessage()
if err != nil {
log.Println("WebSocket read error:", err)
break
}
log.Println("WebSocket read:", string(message))
log.Printf("WebSocket read %d: %s", messageType, string(message))
c.readbuffer <- string(message)
}
} else {

7
go.mod

@ -1,9 +1,12 @@ @@ -1,9 +1,12 @@
module gitlab.com/tslocum/jack
go 1.14
go 1.15
require (
github.com/gorilla/websocket v1.4.2
gitlab.com/tslocum/joker v0.1.3
gitlab.com/tslocum/joker-cribbage v0.1.2-0.20200206160759-4543b916d838
gitlab.com/tslocum/joker-cribbage v0.1.1
gitlab.com/tslocum/sshtargate v0.1.4
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d // indirect
)

30
go.sum

@ -1,8 +1,30 @@ @@ -1,8 +1,30 @@
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/gliderlabs/ssh v0.3.0 h1:7GcKy4erEljCE/QeQ2jTVpu+3f3zkpZOxOJjFYkMqYU=
github.com/gliderlabs/ssh v0.3.0/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
gitlab.com/tslocum/joker v0.1.2 h1:7ujvgkGNUJbrvpXvNHSvKWFDYIKTCWbvFcWL1IbRVWA=
gitlab.com/tslocum/joker v0.1.2/go.mod h1:bxTQ0FFmBP465r9z76zcm97S4Ld9eCLa3q20TyVM82A=
gitlab.com/tslocum/joker v0.1.2-0.20200123002530-2570d6c23aff/go.mod h1:bxTQ0FFmBP465r9z76zcm97S4Ld9eCLa3q20TyVM82A=
gitlab.com/tslocum/joker v0.1.3 h1:6AVQuc0Rt7LczppZKaAXfr5B5Yg/4sQky2SFaWaF9E4=
gitlab.com/tslocum/joker v0.1.3/go.mod h1:bxTQ0FFmBP465r9z76zcm97S4Ld9eCLa3q20TyVM82A=
gitlab.com/tslocum/joker-cribbage v0.1.2-0.20200206160759-4543b916d838 h1:Z3Sv+ArlCL2NezHmv6U6HA2GOY40Ed8+eCu4WrIZvdk=
gitlab.com/tslocum/joker-cribbage v0.1.2-0.20200206160759-4543b916d838/go.mod h1:/fD4xxguXPg+N9s5+Q6t6tib1xfvh7zZ6AQ6TZXViDA=
gitlab.com/tslocum/joker-cribbage v0.1.1 h1:oiCKebyppYsl4x1ZJNHQZcSCcHSBHUCMqSFTGDGv1fY=
gitlab.com/tslocum/joker-cribbage v0.1.1/go.mod h1:KyNZDgGv6fFmYGpHD9txZCBFuVDgKwCq4mJ4ZAgQ0hw=
gitlab.com/tslocum/sshtargate v0.1.4 h1:Vgk/hO36YGkgXWPO7spf5XFgRs3ZlXcCHyAoPHPGr5g=
gitlab.com/tslocum/sshtargate v0.1.4/go.mod h1:e/Kck7HkWfEy9n4rae/F4ZTkPNBayMCDHodrxiECpTY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de h1:ikNHVSjEfnvz6sxdSPCaPt572qowuyMDMJLLm3Db3ig=
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 h1:ogLJMz+qpzav7lGMh10LMvAkM/fAoGlaiiHYiFYdm80=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d h1:QQrM/CCYEzTs91GZylDCQjGHudbPTxF/1fvXdVh5lMo=
golang.org/x/sys v0.0.0-20200812155832-6a926be9bd1d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

33
main.go

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package main
import (
"flag"
"log"
"math/rand"
"net/http"
@ -8,21 +9,49 @@ import ( @@ -8,21 +9,49 @@ import (
)
func main() {
var (
cribPath string
serverAddress string
serverPath string
telnetAddress string
sshAddress string
)
flag.StringVar(&cribPath, "crib", "", "path to crib application (terminal-based client)")
flag.StringVar(&serverAddress, "server", "", "host websocket server on provided address")
flag.StringVar(&serverPath, "path", "/crib", "host websocket server on provided path")
flag.StringVar(&telnetAddress, "telnet", "", "host telnet server on provided address")
flag.StringVar(&sshAddress, "ssh", "", "host SSH server on provided address")
flag.Parse()
if serverAddress == "" {
log.Fatal("failed to start: server listen +address must be specified with --server")
}
rand.Seed(time.Now().UTC().UnixNano())
// TODO debug
go func() {
log.Fatal(http.ListenAndServe(":8880", nil))
}()
if sshAddress != "" {
if cribPath == "" {
cribPath = "crib"
}
listenSSH(sshAddress, cribPath, serverAddress, serverPath)
}
log.Println("CribServer initialized")
cs := CribServer{}
cs.clientqueuealert = make(chan bool)
go cs.matchPlayers()
go cs.listenWebSocket()
cs.listenTelnet()
go cs.listenWebSocket(serverAddress, serverPath)
if telnetAddress != "" {
go cs.listenTelnet(telnetAddress)
}
// TODO
select {}

10
server.go

@ -39,9 +39,9 @@ func (cs *CribServer) handleReadWebSocket(w http.ResponseWriter, r *http.Request @@ -39,9 +39,9 @@ func (cs *CribServer) handleReadWebSocket(w http.ResponseWriter, r *http.Request
cs.addClient(client)
}
func (cs *CribServer) listenWebSocket() {
http.HandleFunc("/crib", cs.handleReadWebSocket)
http.ListenAndServe(":8884", nil)
func (cs *CribServer) listenWebSocket(address string, path string) {
http.HandleFunc(path, cs.handleReadWebSocket)
http.ListenAndServe(address, nil)
}
func (cs *CribServer) addClient(client *Client) {
@ -55,8 +55,8 @@ func (cs *CribServer) addClient(client *Client) { @@ -55,8 +55,8 @@ func (cs *CribServer) addClient(client *Client) {
client.handleRead()
}
func (cs *CribServer) listenTelnet() {
ln, err := net.Listen("tcp", ":8888")
func (cs *CribServer) listenTelnet(address string) {
ln, err := net.Listen("tcp", address)
if err != nil {
log.Println(err)
return

17
ssh.go

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
//+build !windows
package main
import (
"fmt"
"log"
"gitlab.com/tslocum/sshtargate/portal"
)
func listenSSH(sshAddress string, cribPath, jackAddress string, serverPath string) {
_, err := portal.New("jack", sshAddress, []string{cribPath, "--server", fmt.Sprintf("ws://%s%s", jackAddress, serverPath)})
if err != nil {
log.Fatalf("failed to start SSH server: %s", err)
}
}

5
ssh_windows.go

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
//+build windows
package main
func listenSSH(sshAddress string, jackAddress string) {}
Loading…
Cancel
Save