func ServeDOSTerm(channel ssh.Channel) { go ReadSSHIn(channel) MyID := randSeq(5) FBIN := make(chan []byte) FrameBufferSubscribers[MyID] = FBIN defer delete(FrameBufferSubscribers, MyID) // Unsubscribe when dead FB := make([]byte, 0) for { FB = <-FBIN if len(FB) != 4000 { continue } channel.Write([]byte("\x1B[0;0H")) // Reset the cursor to 0,0 outbound := "" ptr := 0 for ptr < len(FB) { outbound = outbound + VESAtoVT100(FB[ptr+1]) outbound = outbound + CorrectBadChars(FB[ptr]) ptr = ptr + 2 } _, err := channel.Write([]byte(outbound)) if err != nil { return } } }
func HandleSshRequests(channel ssh.Channel, in <-chan *ssh.Request, term *terminal.Terminal) { for req := range in { ok := false logfile.Println("[request " + req.Type + "]: " + string(req.Payload)) switch req.Type { case "shell": // hacky way to get around presenting the correct prompt channel.Write([]byte("root@web1:/root# ")) term.SetPrompt("root@web1:/root# ") case "exec": term.SetPrompt("") fmt.Println(req) channel.Write(RunCommand(string(req.Payload[4:]))) // close after executing their one off command channel.Close() } /* this condition set and reply is needed to allow a PTY */ ok = true req.Reply(ok, nil) } }