diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/net/telnet.rb | 12 |
2 files changed, 13 insertions, 4 deletions
@@ -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 diff --git a/lib/net/telnet.rb b/lib/net/telnet.rb index afdfc33df8..05691de0f7 100644 --- a/lib/net/telnet.rb +++ b/lib/net/telnet.rb @@ -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) |