GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — host-api/console/console.go at main · PastureStack/host-api Expand file tree/ Copy pathconsole.goMore file actions 106 lines (93 loc) · 2.31 KB / Copy pathconsole.goFile metadata and controls106 lines (93 loc) · 2.31 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 package console import ( "encoding/base64" "io" "net" "net/url" "path/filepath" "regexp" "time" log "github.com/sirupsen/logrus" "github.com/PastureStack/host-api/auth" "github.com/PastureStack/websocket-proxy/backend" "github.com/PastureStack/websocket-proxy/common" ) const vmSocketRoot = "/var/lib/rancher/vm" var safeContainerID = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$`) type Handler struct { } func (s *Handler) Handle(key string, initialMessage string, incomingMessages <-chan string, response chan<- common.Message) { defer backend.SignalHandlerClosed(key, response) requestUrl, err := url.Parse(initialMessage) if err != nil { log.Error("Could not parse console request URL.") return } tokenString := requestUrl.Query().Get("token") token, valid := auth.GetAndCheckToken(tokenString) if !valid { return } console, ok := auth.GetClaimMap(token, "console") if !ok { log.Error("Token missing console claim.") return } container, ok := auth.GetMapString(console, "container") if !ok || !safeContainerID.MatchString(container) { log.Error("Token contains an invalid console container claim.") return } socketLoc := filepath.Join(vmSocketRoot, container, "vnc") conn, err := net.DialTimeout("unix", socketLoc, 10*time.Second) if err != nil { log.WithFields(log.Fields{"error": err}).Errorf("Couldn't dial VM socket [%v].", socketLoc) return } defer conn.Close() done := make(chan struct{}) go func() { defer func() { close(done) conn.Close() }() for { msg, ok := <-incomingMessages if !ok { return } data, err := base64.StdEncoding.DecodeString(msg) if err != nil { log.WithFields(log.Fields{"error": err}).Error("Error decoding message.") return } if _, err := conn.Write(data); err != nil { log.WithFields(log.Fields{"error": err}).Error("Error write message.") return } } }() for { buff := make([]byte, 1024) n, err := conn.Read(buff) if n > 0 { text := base64.StdEncoding.EncodeToString(buff[:n]) message := common.Message{ Key: key, Type: common.Body, Body: text, } response <- message } if err != nil { if err != io.EOF { select { case <-done: default: log.WithFields(log.Fields{"error": err}).Error("Error reading console response.") } } return } } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |