summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'server.go')
-rw-r--r--server.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/server.go b/server.go
new file mode 100644
index 0000000..47eb3e5
--- /dev/null
+++ b/server.go
@@ -0,0 +1,46 @@
1package main
2
3import (
4 "log"
5 "net"
6 "net/http"
7
8 "github.com/gorilla/websocket"
9)
10
11type ServerHandler struct {
12 ProxyToHost string
13 upgrader websocket.Upgrader
14}
15
16func NewServerHandler(proxyToHost string) *ServerHandler {
17 return &ServerHandler{
18 ProxyToHost: proxyToHost,
19 upgrader: websocket.Upgrader{
20 ReadBufferSize: 1024,
21 WriteBufferSize: 1024,
22 },
23 }
24}
25
26func (h *ServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
27 log.Println("Got new HTTP connection")
28
29 wsconn, err := h.upgrader.Upgrade(w, r, nil)
30 if err != nil {
31 log.Printf("error: ServeHTTP: %s", err)
32 return
33 }
34 defer wsconn.Close()
35
36 proxyconn, err := net.Dial("tcp", h.ProxyToHost)
37 if err != nil {
38 log.Printf("error: ServeHTTP: %s", err)
39 return
40 }
41 defer proxyconn.Close()
42
43 log.Println("Connected to SSH server")
44
45 serviceBoth(wsconn, proxyconn)
46}