本文整理匯總了Golang中code/google/com/p/go/crypto/ssh.Channel類的典型用法代碼示例。如果您正苦於以下問題:Golang Channel類的具體用法?Golang Channel怎麽用?Golang Channel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Channel類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleTcpReading
func HandleTcpReading(channel ssh.Channel, term *terminal.Terminal, http map[string]string) {
defer channel.Close()
for {
line, err := term.ReadLine()
if err != nil {
break
}
logfile.Println(line)
if line == "" {
channel.Close()
return
}
if strings.Contains(line, ":") {
kv := strings.SplitAfterN(line, ":", 2)
http[kv[0]] = strings.TrimSpace(kv[1])
} else {
kv := strings.Fields(line)
if kv[0] == "POST" || kv[0] == "GET" {
http["Method"] = kv[0]
http["URI"] = kv[1]
} else {
http[kv[0]] = kv[1]
}
}
}
}
示例2: HandleTerminalReading
func HandleTerminalReading(channel ssh.Channel, term *terminal.Terminal) {
defer channel.Close()
for {
line, err := term.ReadLine()
if err != nil {
break
}
cmd_log := Command{Cmd: string(line)}
if strings.Contains(string(line), "exit") {
logfile.Println("[exit requested]")
channel.Close()
}
if line == "passwd" {
line, _ := term.ReadPassword("Enter new UNIX password: ")
logfile.Println("[password changed]: " + line)
line, _ = term.ReadPassword("Retype new UNIX password: ")
logfile.Println("[password changed confirmation]: " + line)
term.Write([]byte("passwd: password updated successfully\r\n"))
cmd_log.Cmd += " " + line
} else {
term.Write(RunCommand(line))
}
cmd_log.Save()
logfile.Println(line)
}
}
示例3: ServeDOSTerm
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
}
}
}
示例4: serveReqs
func (ci *ChanInfo) serveReqs(ch ssh.Channel, reqs <-chan *ssh.Request) {
defer ch.Close()
log.Debug("chan reqs begin.")
for req := range reqs {
log.Debug("new chan req: %s(reply: %t, payload: %d).",
req.Type, req.WantReply, len(req.Payload))
err := ci.serveReq(ch, req)
if err != nil {
log.Error("%s", err.Error())
}
}
log.Debug("chan reqs end.")
}
示例5: ReadSSHIn
func ReadSSHIn(channel ssh.Channel) {
buffer := make([]byte, 2)
for {
_, err := channel.Read(buffer)
if err != nil {
return
}
Keyin <- string(buffer[0])
time.Sleep(time.Millisecond * 10)
UpdateScreenNow <- true
time.Sleep(time.Millisecond * 200)
}
}
示例6: handleChannel
func handleChannel(ch ssh.Channel) {
term := terminal.NewTerminal(ch, "> ")
serverTerm := &ssh.ServerTerminal{
Term: term,
Channel: ch,
}
ch.Accept()
defer ch.Close()
for {
line, err := serverTerm.ReadLine()
if err == io.EOF {
return
}
if err != nil {
log.Println("handleChannel readLine err:", err)
continue
}
fmt.Println(line)
}
}
示例7: HandleChannelRequest
func (s *Session) HandleChannelRequest(channel ssh.Channel, in <-chan *ssh.Request) {
for req := range in {
switch req.Type {
case "shell":
if len(req.Payload) == 0 {
if err := req.Reply(true, nil); err != nil {
log.Printf("Unable to reply to channel request (%s)", err)
continue
}
go s.HandleNewTerminal(channel)
}
case "pty-req":
termLen := req.Payload[3]
w, h := ParseTerminalDims(req.Payload[termLen+4:])
s.WinH = uint16(h)
s.WinW = uint16(w)
if err := req.Reply(true, nil); err != nil {
log.Printf("Unable to reply to channel request (%s)", err)
}
case "window-change":
w := &win.Winsize{
Height: uint16(binary.BigEndian.Uint32(req.Payload[4:])),
Width: uint16(binary.BigEndian.Uint32(req.Payload)),
}
if err := win.SetWinsize(s.pty.Fd(), w); err != nil {
log.Printf("Unable to set window-change (%s)", err)
}
case "close":
if err := channel.Close(); err != nil {
log.Printf("Unable to close channel (%s)", err)
}
case "default":
log.Printf("Invalid Request Type (%s)", req.Type)
}
}
}
示例8: forwardUnixSocket
func forwardUnixSocket(channel ssh.Channel, addr string) {
conn, err := net.Dial("unix", addr)
if err != nil {
return
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
io.Copy(conn, channel)
conn.(*net.UnixConn).CloseWrite()
wg.Done()
}()
go func() {
io.Copy(channel, conn)
channel.CloseWrite()
wg.Done()
}()
wg.Wait()
conn.Close()
channel.Close()
}
示例9: serveReq
func (chi *ChanInfo) serveReq(ch ssh.Channel, req *ssh.Request) (err error) {
err = chi.onReq(req)
if err != nil {
log.Error("%s", err.Error())
req.Reply(false, nil)
return
}
r, err := ch.SendRequest(req.Type, req.WantReply, req.Payload)
if err != nil {
log.Error("%s", err.Error())
req.Reply(false, nil)
return
}
log.Debug("send chan req ok: %s(result: %t)", req.Type, r)
err = req.Reply(r, nil)
if err != nil {
return
}
log.Debug("reply chan req ok: %s(result: %t)", req.Type, r)
return
}
示例10: HandleSshRequests
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("[email protected]:/root# "))
term.SetPrompt("[email protected]:/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)
}
}