当前位置: 首页>>代码示例>>Golang>>正文


Golang Terminal.ReadLine方法代码示例

本文整理汇总了Golang中code/google/com/p/go/crypto/ssh/terminal.Terminal.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:Golang Terminal.ReadLine方法的具体用法?Golang Terminal.ReadLine怎么用?Golang Terminal.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在code/google/com/p/go/crypto/ssh/terminal.Terminal的用法示例。


在下文中一共展示了Terminal.ReadLine方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]
			}
		}
	}
}
开发者ID:oiooj,项目名称:ssh-passwd-honeypot,代码行数:27,代码来源:sshd.go

示例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)
	}

}
开发者ID:oiooj,项目名称:ssh-passwd-honeypot,代码行数:30,代码来源:sshd.go

示例3: enroll

func enroll(config *Config, term *terminal.Terminal) bool {
	var err error
	warn(term, "Enrolling new config file")

	var domain string
	for {
		term.SetPrompt("Account (i.e. [email protected], enter to quit): ")
		if config.Account, err = term.ReadLine(); err != nil || len(config.Account) == 0 {
			return false
		}

		parts := strings.SplitN(config.Account, "@", 2)
		if len(parts) != 2 {
			alert(term, "invalid username (want [email protected]): "+config.Account)
			continue
		}
		domain = parts[1]
		break
	}

	term.SetPrompt("Enable debug logging to /tmp/xmpp-client-debug.log? ")
	if debugLog, err := term.ReadLine(); err != nil || debugLog != "yes" {
		info(term, "Not enabling debug logging...")
	} else {
		info(term, "Debug logging enabled...")
		config.RawLogFile = "/tmp/xmpp-client-debug.log"
	}

	term.SetPrompt("Use Tor?: ")
	if useTorQuery, err := term.ReadLine(); err != nil || useTorQuery != "yes" {
		info(term, "Not using Tor...")
		config.UseTor = false
	} else {
		info(term, "Using Tor...")
		config.UseTor = true
	}

	term.SetPrompt("File to import libotr private key from (enter to generate): ")

	var priv otr.PrivateKey
	for {
		importFile, err := term.ReadLine()
		if err != nil {
			return false
		}
		if len(importFile) > 0 {
			privKeyBytes, err := ioutil.ReadFile(importFile)
			if err != nil {
				alert(term, "Failed to open private key file: "+err.Error())
				continue
			}

			if !priv.Import(privKeyBytes) {
				alert(term, "Failed to parse libotr private key file (the parser is pretty simple I'm afraid)")
				continue
			}
			break
		} else {
			info(term, "Generating private key...")
			priv.Generate(rand.Reader)
			break
		}
	}
	config.PrivateKey = priv.Serialize(nil)

	config.OTRAutoAppendTag = true
	config.OTRAutoStartSession = true
	config.OTRAutoTearDown = false

	// If we find ourselves here - we want to autoconfigure everything quickly
	if domain == "jabber.ccc.de" && config.UseTor == true {
		const torProxyURL = "socks5://127.0.0.1:9050"
		info(term, "It appears that you are using a well known server and we will use its Tor hidden service to connect.")
		config.Server = "okj7xc6j2szr2y75.onion"
		config.Port = 5222
		config.Proxies = []string{torProxyURL}
		term.SetPrompt("> ")
		return true
	}

	if domain == "riseup.net" && config.UseTor == true {
		const torProxyURL = "socks5://127.0.0.1:9050"
		info(term, "It appears that you are using a well known server and we will use its Tor hidden service to connect.")
		config.Server = "ztmc4p37hvues222.onion"
		config.Port = 5222
		config.Proxies = []string{torProxyURL}
		term.SetPrompt("> ")
		return true
	}

	var proxyStr string
	term.SetPrompt("Proxy (i.e socks5://127.0.0.1:9050, enter for none): ")

	for {
		if proxyStr, err = term.ReadLine(); err != nil {
			return false
		}
		if len(proxyStr) == 0 {
			break
		}
//.........这里部分代码省略.........
开发者ID:ioerror,项目名称:xmpp-client,代码行数:101,代码来源:config.go

示例4: readLine

func readLine(shell *terminal.Terminal, t *testing.T) {
	if _, err := shell.ReadLine(); err != nil && err != io.EOF {
		t.Errorf("unable to read line: %v", err)
	}
}
开发者ID:Blystad,项目名称:deis,代码行数:5,代码来源:session_test.go


注:本文中的code/google/com/p/go/crypto/ssh/terminal.Terminal.ReadLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。