1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/net/telnet.rb (Net::Telnet::login): "options" can specify

regexps for login prompt and/or password prompt.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akira 2004-05-13 07:02:18 +00:00
parent 25aa9e6969
commit 793b2e8795
2 changed files with 13 additions and 4 deletions

View file

@ -1,3 +1,8 @@
Thu May 13 15:47:30 2004 akira yamada <akira@ruby-lang.org>
* lib/net/telnet.rb (Net::Telnet::login): "options" can specify
regexps for login prompt and/or password prompt.
Thu May 13 14:17:57 2004 why the lucky stiff <why@ruby-lang.org>
* ext/syck/rubyext.c (yaml_org_handler): some empty strings were

View file

@ -704,27 +704,31 @@ module Net
# the host should not echo). If a block is passed in, this received
# data is also yielded to the block as it is received.
def login(options, password = nil) # :yield: recvdata
login_prompt = /[Ll]ogin[: ]*\z/n
password_prompt = /Password[: ]*\z/n
if options.kind_of?(Hash)
username = options["Name"]
password = options["Password"]
login_prompt = options["LoginPrompt"] if options["LoginPrompt"]
password_prompt = options["PasswordPrompt"] if options["PasswordPrompt"]
else
username = options
end
if block_given?
line = waitfor(/[Ll]ogin[: ]*\z/n){|c| yield c }
line = waitfor(login_prompt){|c| yield c }
if password
line += cmd({"String" => username,
"Match" => /Password[: ]*\z/n}){|c| yield c }
"Match" => password_prompt}){|c| yield c }
line += cmd(password){|c| yield c }
else
line += cmd(username){|c| yield c }
end
else
line = waitfor(/[Ll]ogin[: ]*\z/n)
line = waitfor(login_prompt)
if password
line += cmd({"String" => username,
"Match" => /Password[: ]*\z/n})
"Match" => password_prompt})
line += cmd(password)
else
line += cmd(username)