本文整理匯總了Golang中code/google/com/p/go/crypto/ssh.Channel.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Channel.Close方法的具體用法?Golang Channel.Close怎麽用?Golang Channel.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/go/crypto/ssh.Channel
的用法示例。
在下文中一共展示了Channel.Close方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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)
}
}
示例2: 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]
}
}
}
}
示例3: 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.")
}
示例4: 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)
}
}
示例5: 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)
}
}
}
示例6: 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)
}
}
示例7: 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()
}