net-ssh-telnet 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/History.txt +7 -0
- data/Manifest.txt +11 -0
- data/README.txt +54 -0
- data/Rakefile +14 -0
- data/Todo.txt +5 -0
- data/examples/detailed_debug.rb +28 -0
- data/examples/get_disk_info.rb +29 -0
- data/examples/get_hostname.rb +18 -0
- data/examples/non_standard_shell.rb +20 -0
- data/lib/net/ssh/telnet.rb +411 -0
- data/test/test_net-ssh-telnet.rb +0 -0
- metadata +100 -0
- metadata.gz.sig +1 -0
data.tar.gz.sig
ADDED
Binary file
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= net-ssh-telnet
|
2
|
+
|
3
|
+
* http://net-ssh-telnet.rubyforge.org
|
4
|
+
* mailto:matt@bravenet.com
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
A ruby module to provide a simple send/expect interface over SSH with an API
|
9
|
+
almost identical to Net::Telnet. Ideally it should be a drop in replacement.
|
10
|
+
|
11
|
+
Please see Net::Telnet for main documentation (included with ruby stdlib).
|
12
|
+
|
13
|
+
== FEATURES/PROBLEMS:
|
14
|
+
|
15
|
+
* FIX (list of features or problems)
|
16
|
+
|
17
|
+
== SYNOPSIS:
|
18
|
+
|
19
|
+
FIX (code sample of usage)
|
20
|
+
|
21
|
+
== REQUIREMENTS:
|
22
|
+
|
23
|
+
* net-ssh >= 2.0.1
|
24
|
+
|
25
|
+
== INSTALL:
|
26
|
+
|
27
|
+
* sudo gem install net-ssh-telnet
|
28
|
+
|
29
|
+
== LICENSE:
|
30
|
+
|
31
|
+
(The MIT License)
|
32
|
+
|
33
|
+
Based on code in net/telnet.rb by Wakou Aoyama <wakou@ruby-lang.org>
|
34
|
+
Modified to work with Net::SSH by Brian Candler <b.candler@pobox.com>
|
35
|
+
Additional Net::SSH v2 modifications by Matthew Kent <matt@bravenet.com>
|
36
|
+
|
37
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
38
|
+
a copy of this software and associated documentation files (the
|
39
|
+
'Software'), to deal in the Software without restriction, including
|
40
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
41
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
42
|
+
permit persons to whom the Software is furnished to do so, subject to
|
43
|
+
the following conditions:
|
44
|
+
|
45
|
+
The above copyright notice and this permission notice shall be
|
46
|
+
included in all copies or substantial portions of the Software.
|
47
|
+
|
48
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
49
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
50
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
51
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
52
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
53
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
54
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
6
|
+
require 'net/ssh/telnet'
|
7
|
+
|
8
|
+
Hoe.new('net-ssh-telnet', Net::SSH::Telnet::VERSION) do |p|
|
9
|
+
p.developer('Matthew Kent', 'matt@bravenet.com')
|
10
|
+
p.extra_deps << ['net-ssh', '>= 2.0.1']
|
11
|
+
p.remote_rdoc_dir = ''
|
12
|
+
end
|
13
|
+
|
14
|
+
# vim: syntax=Ruby
|
data/Todo.txt
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
4
|
+
|
5
|
+
require 'net/ssh/telnet'
|
6
|
+
|
7
|
+
# Example showing debugging possibilities
|
8
|
+
|
9
|
+
# Dump the ssh interaction to stdout..
|
10
|
+
ssh = Net::SSH.start(nil, nil,
|
11
|
+
:host_name => "127.0.0.1",
|
12
|
+
:user => "demo",
|
13
|
+
:password => "guy",
|
14
|
+
:verbose => :debug
|
15
|
+
)
|
16
|
+
|
17
|
+
# ..and output our 2 Net::Telnet style interaction logs.
|
18
|
+
s = Net::SSH::Telnet.new(
|
19
|
+
"Session" => ssh,
|
20
|
+
"Dump_log" => "dump.log",
|
21
|
+
"Output_log" => "output.log"
|
22
|
+
)
|
23
|
+
|
24
|
+
puts s.cmd("echo democommand1")
|
25
|
+
puts s.cmd("echo democommand2")
|
26
|
+
puts s.cmd("echo democommand3")
|
27
|
+
|
28
|
+
s.close
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
4
|
+
|
5
|
+
require 'net/ssh/telnet'
|
6
|
+
|
7
|
+
# Example using Waittime.
|
8
|
+
|
9
|
+
puts "Using Waittime"
|
10
|
+
s = Net::SSH::Telnet.new(
|
11
|
+
"Host" => "127.0.0.1",
|
12
|
+
"Username" => "demo",
|
13
|
+
"Password" => "guy",
|
14
|
+
# Seconds to wait for more data after seeing the prompt
|
15
|
+
"Waittime" => 3
|
16
|
+
)
|
17
|
+
puts "Logged in"
|
18
|
+
puts s.cmd("head -1 /proc/mounts\r\ndf\r\recho done")
|
19
|
+
s.close
|
20
|
+
|
21
|
+
puts "\nAgain, but with no wait time"
|
22
|
+
s = Net::SSH::Telnet.new(
|
23
|
+
"Host" => "127.0.0.1",
|
24
|
+
"Username" => "demo",
|
25
|
+
"Password" => "guy"
|
26
|
+
)
|
27
|
+
puts "Logged in"
|
28
|
+
puts s.cmd("head -1 /proc/mounts\r\ndf\r\recho done")
|
29
|
+
s.close
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
4
|
+
|
5
|
+
require 'net/ssh/telnet'
|
6
|
+
|
7
|
+
# Example showing a simple interaction, with debugging data to stdout.
|
8
|
+
|
9
|
+
s = Net::SSH::Telnet.new(
|
10
|
+
"Dump_log" => "/dev/stdout",
|
11
|
+
"Host" => "127.0.0.1",
|
12
|
+
"Username" => "demo",
|
13
|
+
"Password" => "guy"
|
14
|
+
)
|
15
|
+
puts "Logged in"
|
16
|
+
puts s.cmd("hostname")
|
17
|
+
|
18
|
+
s.close
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
$: << File.dirname(__FILE__) + "/../lib"
|
4
|
+
|
5
|
+
require 'net/ssh/telnet'
|
6
|
+
|
7
|
+
# Example showing interaction with a device that provides a custom shell via
|
8
|
+
# ssh.
|
9
|
+
|
10
|
+
s = Net::SSH::Telnet.new(
|
11
|
+
"Host" => "192.168.1.1",
|
12
|
+
"Username" => "demo",
|
13
|
+
"Password" => "guy",
|
14
|
+
"Prompt" => %r{^\S+>\s.*$},
|
15
|
+
"Terminator" => "\r"
|
16
|
+
)
|
17
|
+
|
18
|
+
puts s.cmd("show alerts")
|
19
|
+
|
20
|
+
s.close
|
@@ -0,0 +1,411 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/ssh'
|
3
|
+
|
4
|
+
module Net
|
5
|
+
module SSH
|
6
|
+
|
7
|
+
# == Net::SSH::Telnet
|
8
|
+
#
|
9
|
+
# Provides a simple send/expect interface with an API almost
|
10
|
+
# identical to Net::Telnet. Please see Net::Telnet for main documentation.
|
11
|
+
# Only the differences are documented here.
|
12
|
+
|
13
|
+
class Telnet
|
14
|
+
|
15
|
+
CR = "\015"
|
16
|
+
LF = "\012"
|
17
|
+
EOL = CR + LF
|
18
|
+
VERSION = '0.0.1'
|
19
|
+
|
20
|
+
# Wrapper to emulate the behaviour of Net::Telnet "Proxy" option, where
|
21
|
+
# the user passes in an already-open socket
|
22
|
+
|
23
|
+
class TinyFactory
|
24
|
+
def initialize(sock)
|
25
|
+
@sock = sock
|
26
|
+
end
|
27
|
+
def open(host, port)
|
28
|
+
s = @sock
|
29
|
+
@sock = nil
|
30
|
+
s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Creates a new Net::SSH::Telnet object.
|
35
|
+
#
|
36
|
+
# The API is similar to Net::Telnet, although you will need to pass in
|
37
|
+
# either an existing Net::SSH::Session object or a Username and Password,
|
38
|
+
# as shown below.
|
39
|
+
#
|
40
|
+
# Note that unlike Net::Telnet there is no preprocess method automatically
|
41
|
+
# setting up options related to proper character translations, so if your
|
42
|
+
# remote ptty is configured differently than the typical linux one you may
|
43
|
+
# need to pass in a different terminator or call 'stty' remotely to set it
|
44
|
+
# into an expected mode. This is better explained by the author of perl's
|
45
|
+
# Net::SSH::Expect here:
|
46
|
+
#
|
47
|
+
# http://search.cpan.org/~bnegrao/Net-SSH-Expect-1.04/lib/Net/SSH/Expect.pod
|
48
|
+
# #IMPORTANT_NOTES_ABOUT_DEALING_WITH_SSH_AND_PSEUDO-TERMINALS
|
49
|
+
#
|
50
|
+
# though for most installs the default LF should be fine. See example 5
|
51
|
+
# below.
|
52
|
+
#
|
53
|
+
# A new option is added to correct a misfeature of Net::Telnet. If you
|
54
|
+
# pass "FailEOF" => true, then if the remote end disconnects while you
|
55
|
+
# are still waiting for your match pattern then an EOFError is raised.
|
56
|
+
# Otherwise, it reverts to the same behaviour as Net::Telnet, which is
|
57
|
+
# just to return whatever data was sent so far, or nil if no data was
|
58
|
+
# returned so far. (This is a poor design because you can't tell whether
|
59
|
+
# the expected pattern was successfully matched or the remote end
|
60
|
+
# disconnected unexpectedly, unless you perform a second match on the
|
61
|
+
# return string). See
|
62
|
+
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/11373
|
63
|
+
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/11380
|
64
|
+
#
|
65
|
+
# Example 1 - pass existing Net::SSH::Session object
|
66
|
+
#
|
67
|
+
# ssh = Net::SSH.start("127.0.0.1",
|
68
|
+
# :username=>"test123",
|
69
|
+
# :password=>"pass456"
|
70
|
+
# )
|
71
|
+
# s = Net::SSH::Telnet.new(
|
72
|
+
# "Dump_log" => "/dev/stdout",
|
73
|
+
# "Session" => ssh
|
74
|
+
# )
|
75
|
+
# puts "Logged in"
|
76
|
+
# p s.cmd("echo hello")
|
77
|
+
#
|
78
|
+
# This is the most flexible way as it allows you to set up the SSH
|
79
|
+
# session using whatever authentication system you like. When done this
|
80
|
+
# way, calling Net::SSH::Telnet.new multiple times will create
|
81
|
+
# multiple channels, and #close will only close one channel.
|
82
|
+
#
|
83
|
+
# In all later examples, calling #close will close the entire
|
84
|
+
# Net::SSH::Session object (and therefore drop the TCP connection)
|
85
|
+
#
|
86
|
+
# Example 2 - pass host, username and password
|
87
|
+
#
|
88
|
+
# s = Net::SSH::Telnet.new(
|
89
|
+
# "Dump_log" => "/dev/stdout",
|
90
|
+
# "Host" => "127.0.0.1",
|
91
|
+
# "Username" => "test123",
|
92
|
+
# "Password" => "pass456"
|
93
|
+
# )
|
94
|
+
# puts "Logged in"
|
95
|
+
# puts s.cmd("echo hello")
|
96
|
+
#
|
97
|
+
# Example 3 - pass open IO object, username and password (this is really
|
98
|
+
# just for compatibility with Net::Telnet Proxy feature)
|
99
|
+
#
|
100
|
+
# require 'socket'
|
101
|
+
# sock = TCPSocket.open("127.0.0.1",22)
|
102
|
+
# s = Net::SSH::Telnet.new(
|
103
|
+
# "Dump_log" => "/dev/stdout",
|
104
|
+
# "Proxy" => sock,
|
105
|
+
# "Username" => "test123",
|
106
|
+
# "Password" => "pass456"
|
107
|
+
# )
|
108
|
+
# puts "Logged in"
|
109
|
+
# puts s.cmd("echo hello")
|
110
|
+
#
|
111
|
+
# Example 4 - pass a connection factory, host, username and password;
|
112
|
+
# Net::SSH will call #open(host,port) on this object. Included just
|
113
|
+
# because it was easy :-)
|
114
|
+
#
|
115
|
+
# require 'socket'
|
116
|
+
# s = Net::SSH::Telnet.new(
|
117
|
+
# "Dump_log" => "/dev/stdout",
|
118
|
+
# "Factory" => TCPSocket,
|
119
|
+
# "Host" => "127.0.0.1",
|
120
|
+
# "Username" => "test123",
|
121
|
+
# "Password" => "pass456"
|
122
|
+
# )
|
123
|
+
# puts "Logged in"
|
124
|
+
# puts s.cmd("echo hello")
|
125
|
+
#
|
126
|
+
# Example 5 - connection to a SAN device running a customized NetBSD with
|
127
|
+
# different ptty defaults, it doesn't convert LF -> CR+LF (see the man
|
128
|
+
# page for 'stty') and uses a custom prompt
|
129
|
+
#
|
130
|
+
# s = Net::SSH::Telnet.new(
|
131
|
+
# "Host" => "192.168.1.1",
|
132
|
+
# "Username" => "test123",
|
133
|
+
# "Password" => "pass456",
|
134
|
+
# "Prompt" => %r{^\S+>\s.*$},
|
135
|
+
# "Terminator" => "\r"
|
136
|
+
# )
|
137
|
+
# puts "Logged in"
|
138
|
+
# puts s.cmd("show alerts")
|
139
|
+
|
140
|
+
def initialize(options, &blk) # :yield: mesg
|
141
|
+
@options = options
|
142
|
+
@options["Host"] = "localhost" unless @options.has_key?("Host")
|
143
|
+
@options["Port"] = 22 unless @options.has_key?("Port")
|
144
|
+
@options["Prompt"] = /[$%#>] \z/n unless @options.has_key?("Prompt")
|
145
|
+
@options["Timeout"] = 10 unless @options.has_key?("Timeout")
|
146
|
+
@options["Waittime"] = 0 unless @options.has_key?("Waittime")
|
147
|
+
@options["Terminator"] = LF unless @options.has_key?("Terminator")
|
148
|
+
|
149
|
+
unless @options.has_key?("Binmode")
|
150
|
+
@options["Binmode"] = false
|
151
|
+
else
|
152
|
+
unless (true == @options["Binmode"] or false == @options["Binmode"])
|
153
|
+
raise ArgumentError, "Binmode option must be true or false"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
if @options.has_key?("Output_log")
|
158
|
+
@log = File.open(@options["Output_log"], 'a+')
|
159
|
+
@log.sync = true
|
160
|
+
@log.binmode
|
161
|
+
end
|
162
|
+
|
163
|
+
if @options.has_key?("Dump_log")
|
164
|
+
@dumplog = File.open(@options["Dump_log"], 'a+')
|
165
|
+
@dumplog.sync = true
|
166
|
+
@dumplog.binmode
|
167
|
+
def @dumplog.log_dump(dir, x) # :nodoc:
|
168
|
+
len = x.length
|
169
|
+
addr = 0
|
170
|
+
offset = 0
|
171
|
+
while 0 < len
|
172
|
+
if len < 16
|
173
|
+
line = x[offset, len]
|
174
|
+
else
|
175
|
+
line = x[offset, 16]
|
176
|
+
end
|
177
|
+
hexvals = line.unpack('H*')[0]
|
178
|
+
hexvals += ' ' * (32 - hexvals.length)
|
179
|
+
hexvals = format("%s %s %s %s " * 4, *hexvals.unpack('a2' * 16))
|
180
|
+
line = line.gsub(/[\000-\037\177-\377]/n, '.')
|
181
|
+
printf "%s 0x%5.5x: %s%s\n", dir, addr, hexvals, line
|
182
|
+
addr += 16
|
183
|
+
offset += 16
|
184
|
+
len -= 16
|
185
|
+
end
|
186
|
+
print "\n"
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
if @options.has_key?("Session")
|
191
|
+
@ssh = @options["Session"]
|
192
|
+
@close_all = false
|
193
|
+
elsif @options.has_key?("Proxy")
|
194
|
+
@ssh = Net::SSH.start(nil, nil,
|
195
|
+
:host_name => @options["Host"], # ignored
|
196
|
+
:port => @options["Port"], # ignored
|
197
|
+
:user => @options["Username"],
|
198
|
+
:password => @options["Password"],
|
199
|
+
:timeout => @options["Timeout"],
|
200
|
+
:proxy => TinyFactory.new(@options["Proxy"])
|
201
|
+
)
|
202
|
+
@close_all = true
|
203
|
+
else
|
204
|
+
message = "Trying " + @options["Host"] + "...\n"
|
205
|
+
yield(message) if block_given?
|
206
|
+
@log.write(message) if @options.has_key?("Output_log")
|
207
|
+
@dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
|
208
|
+
|
209
|
+
begin
|
210
|
+
@ssh = Net::SSH.start(nil, nil,
|
211
|
+
:host_name => @options["Host"],
|
212
|
+
:port => @options["Port"],
|
213
|
+
:user => @options["Username"],
|
214
|
+
:password => @options["Password"],
|
215
|
+
:timeout => @options["Timeout"],
|
216
|
+
:proxy => @options["Factory"]
|
217
|
+
)
|
218
|
+
@close_all = true
|
219
|
+
rescue TimeoutError
|
220
|
+
raise TimeoutError, "timed out while opening a connection to the host"
|
221
|
+
rescue
|
222
|
+
@log.write($ERROR_INFO.to_s + "\n") if @options.has_key?("Output_log")
|
223
|
+
@dumplog.log_dump('#', $ERROR_INFO.to_s + "\n") if @options.has_key?("Dump_log")
|
224
|
+
raise
|
225
|
+
end
|
226
|
+
|
227
|
+
message = "Connected to " + @options["Host"] + ".\n"
|
228
|
+
yield(message) if block_given?
|
229
|
+
@log.write(message) if @options.has_key?("Output_log")
|
230
|
+
@dumplog.log_dump('#', message) if @options.has_key?("Dump_log")
|
231
|
+
end
|
232
|
+
|
233
|
+
@buf = ""
|
234
|
+
@eof = false
|
235
|
+
@channel = nil
|
236
|
+
@ssh.open_channel do |channel|
|
237
|
+
channel.request_pty { |ch,success|
|
238
|
+
if success == false
|
239
|
+
raise "Failed to open ssh pty"
|
240
|
+
end
|
241
|
+
}
|
242
|
+
channel.send_channel_request("shell") { |ch, success|
|
243
|
+
if success
|
244
|
+
@channel = ch
|
245
|
+
waitfor(@options['Prompt'], &blk)
|
246
|
+
return
|
247
|
+
else
|
248
|
+
raise "Failed to open ssh shell"
|
249
|
+
end
|
250
|
+
}
|
251
|
+
channel.on_data { |ch,data| @buf << data }
|
252
|
+
channel.on_extended_data { |ch,type,data| @buf << data if type == 1 }
|
253
|
+
channel.on_close { @eof = true }
|
254
|
+
end
|
255
|
+
@ssh.loop
|
256
|
+
end # initialize
|
257
|
+
|
258
|
+
# Close the ssh channel, and also the entire ssh session if we
|
259
|
+
# opened it.
|
260
|
+
|
261
|
+
def close
|
262
|
+
@channel.close if @channel
|
263
|
+
@channel = nil
|
264
|
+
@ssh.close if @close_all and @ssh
|
265
|
+
end
|
266
|
+
|
267
|
+
# The ssh session and channel we are using.
|
268
|
+
attr_reader :ssh, :channel
|
269
|
+
|
270
|
+
# Turn newline conversion on (+mode+ == false) or off (+mode+ == true),
|
271
|
+
# or return the current value (+mode+ is not specified).
|
272
|
+
def binmode(mode = nil)
|
273
|
+
case mode
|
274
|
+
when nil
|
275
|
+
@options["Binmode"]
|
276
|
+
when true, false
|
277
|
+
@options["Binmode"] = mode
|
278
|
+
else
|
279
|
+
raise ArgumentError, "argument must be true or false"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# Turn newline conversion on (false) or off (true).
|
284
|
+
def binmode=(mode)
|
285
|
+
if (true == mode or false == mode)
|
286
|
+
@options["Binmode"] = mode
|
287
|
+
else
|
288
|
+
raise ArgumentError, "argument must be true or false"
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
# Read data from the host until a certain sequence is matched.
|
293
|
+
|
294
|
+
def waitfor(options) # :yield: recvdata
|
295
|
+
time_out = @options["Timeout"]
|
296
|
+
waittime = @options["Waittime"]
|
297
|
+
fail_eof = @options["FailEOF"]
|
298
|
+
|
299
|
+
if options.kind_of?(Hash)
|
300
|
+
prompt = if options.has_key?("Match")
|
301
|
+
options["Match"]
|
302
|
+
elsif options.has_key?("Prompt")
|
303
|
+
options["Prompt"]
|
304
|
+
elsif options.has_key?("String")
|
305
|
+
Regexp.new( Regexp.quote(options["String"]) )
|
306
|
+
end
|
307
|
+
time_out = options["Timeout"] if options.has_key?("Timeout")
|
308
|
+
waittime = options["Waittime"] if options.has_key?("Waittime")
|
309
|
+
fail_eof = options["FailEOF"] if options.has_key?("FailEOF")
|
310
|
+
else
|
311
|
+
prompt = options
|
312
|
+
end
|
313
|
+
|
314
|
+
if time_out == false
|
315
|
+
time_out = nil
|
316
|
+
end
|
317
|
+
|
318
|
+
line = ''
|
319
|
+
buf = ''
|
320
|
+
rest = ''
|
321
|
+
sock = @ssh.transport.socket
|
322
|
+
|
323
|
+
until prompt === line and ((@eof and @buf == "") or not IO::select([sock], nil, nil, waittime))
|
324
|
+
while @buf == "" and !@eof
|
325
|
+
# timeout is covered by net-ssh
|
326
|
+
@channel.connection.process(0.1)
|
327
|
+
end
|
328
|
+
if @buf != ""
|
329
|
+
c = @buf; @buf = ""
|
330
|
+
@dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
|
331
|
+
buf = c
|
332
|
+
buf.gsub!(/#{EOL}/no, "\n") unless @options["Binmode"]
|
333
|
+
rest = ''
|
334
|
+
@log.print(buf) if @options.has_key?("Output_log")
|
335
|
+
line += buf
|
336
|
+
yield buf if block_given?
|
337
|
+
elsif @eof # End of file reached
|
338
|
+
break if prompt === line
|
339
|
+
raise EOFError if fail_eof
|
340
|
+
if line == ''
|
341
|
+
line = nil
|
342
|
+
yield nil if block_given?
|
343
|
+
end
|
344
|
+
break
|
345
|
+
end
|
346
|
+
end
|
347
|
+
line
|
348
|
+
end
|
349
|
+
|
350
|
+
# Write +string+ to the host.
|
351
|
+
#
|
352
|
+
# Does not perform any conversions on +string+. Will log +string+ to the
|
353
|
+
# dumplog, if the Dump_log option is set.
|
354
|
+
def write(string)
|
355
|
+
@dumplog.log_dump('>', string) if @options.has_key?("Dump_log")
|
356
|
+
@channel.send_data string
|
357
|
+
end
|
358
|
+
|
359
|
+
# Sends a string to the host.
|
360
|
+
#
|
361
|
+
# This does _not_ automatically append a newline to the string. Embedded
|
362
|
+
# newlines may be converted depending upon the values of binmode or
|
363
|
+
# terminator.
|
364
|
+
def print(string)
|
365
|
+
terminator = @options["Terminator"]
|
366
|
+
|
367
|
+
if @options["Binmode"]
|
368
|
+
self.write(string)
|
369
|
+
else
|
370
|
+
self.write(string.gsub(/\n/n, terminator))
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
# Sends a string to the host.
|
375
|
+
#
|
376
|
+
# Same as #print(), but appends a newline to the string.
|
377
|
+
def puts(string)
|
378
|
+
self.print(string + "\n")
|
379
|
+
end
|
380
|
+
|
381
|
+
# Send a command to the host.
|
382
|
+
#
|
383
|
+
# More exactly, sends a string to the host, and reads in all received
|
384
|
+
# data until is sees the prompt or other matched sequence.
|
385
|
+
#
|
386
|
+
# The command or other string will have the newline sequence appended
|
387
|
+
# to it.
|
388
|
+
|
389
|
+
def cmd(options) # :yield: recvdata
|
390
|
+
match = @options["Prompt"]
|
391
|
+
time_out = @options["Timeout"]
|
392
|
+
|
393
|
+
if options.kind_of?(Hash)
|
394
|
+
string = options["String"]
|
395
|
+
match = options["Match"] if options.has_key?("Match")
|
396
|
+
time_out = options["Timeout"] if options.has_key?("Timeout")
|
397
|
+
else
|
398
|
+
string = options
|
399
|
+
end
|
400
|
+
|
401
|
+
self.puts(string)
|
402
|
+
if block_given?
|
403
|
+
waitfor({"Prompt" => match, "Timeout" => time_out}){|c| yield c }
|
404
|
+
else
|
405
|
+
waitfor({"Prompt" => match, "Timeout" => time_out})
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
end # class Telnet
|
410
|
+
end # module SSH
|
411
|
+
end # module Net
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: net-ssh-telnet
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2008-06-06 00:00:00 -07:00
|
8
|
+
summary: A ruby module to provide a simple send/expect interface over SSH with an API almost identical to Net::Telnet
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email:
|
12
|
+
- matt@bravenet.com
|
13
|
+
homepage: http://net-ssh-telnet.rubyforge.org
|
14
|
+
rubyforge_project: net-ssh-telnet
|
15
|
+
description: A ruby module to provide a simple send/expect interface over SSH with an API almost identical to Net::Telnet. Ideally it should be a drop in replacement. Please see Net::Telnet for main documentation (included with ruby stdlib).
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
- |
|
30
|
+
-----BEGIN CERTIFICATE-----
|
31
|
+
MIIDMDCCAhigAwIBAgIBADANBgkqhkiG9w0BAQUFADA+MQ0wCwYDVQQDDARtYXR0
|
32
|
+
MRgwFgYKCZImiZPyLGQBGRYIYnJhdmVuZXQxEzARBgoJkiaJk/IsZAEZFgNjb20w
|
33
|
+
HhcNMDgwNTI5MjM1MDUwWhcNMDkwNTI5MjM1MDUwWjA+MQ0wCwYDVQQDDARtYXR0
|
34
|
+
MRgwFgYKCZImiZPyLGQBGRYIYnJhdmVuZXQxEzARBgoJkiaJk/IsZAEZFgNjb20w
|
35
|
+
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDDGVrJnpk6/hCO5lg6T7As
|
36
|
+
unEksqdmCly6GkRpX0cVxusWG/wbjrZw4Ka5x9pSS2m3GfefEpu5CuWH9wnGB/q0
|
37
|
+
LwbWhrkpQb+uNVD6hEbQcngDEiQbiitaSWZKSvrIymbM5Tl92rIScmvx7Pd7l8tz
|
38
|
+
BLndL/DmrBHrHWQ47xLxOmBAA4NJy0gk7HdsdAFfJwrEoC14AAXqcI3X0qU3KGrr
|
39
|
+
9Fs0jVeIKktx3fthwGVPrpYrMIw3xgiUqOqn7M+V4soD013dopaN7orewmCm9dQL
|
40
|
+
4N06FMnGNjwFaS6+MV612nk8gkVpJwgcwTHE1GNt2NItR5zeK6j+AZ01DijYdjH9
|
41
|
+
AgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBQ6jcdN
|
42
|
+
QqNNsx2XxigfTWE0Owy0XzANBgkqhkiG9w0BAQUFAAOCAQEAvWBkYaD7eKP+KHxJ
|
43
|
+
dtQuaebQTZvBX4vjk/Omjn7hj7u8X8aTvmCKyopnmywiApFH1zgDa8NRc1KTsvZt
|
44
|
+
zhSRWIuI7fFB+JFZUatE7Nius56id9UchYO98569t6bNU284XwBtcj4MN5Andfcp
|
45
|
+
LKdUNuuT0yui1InJG4fD0uKnOS1qcXEm+mN2s1uqPGVltEHorG7L/bPNAw8xV+uq
|
46
|
+
NPc7hhQTkbi7HB2Uwxr9uK9IGHEE5tDVnsPWPnJJ4jSOc7Bd1eHZuSMkEPfyREDf
|
47
|
+
h9ljoX3AGXW8qYohFzGjflamaWZ4xYaKZSNqS2i0Kc+M76Sy+r9FldDRNn4FGUBE
|
48
|
+
JqYgHg==
|
49
|
+
-----END CERTIFICATE-----
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
authors:
|
53
|
+
- Matthew Kent
|
54
|
+
files:
|
55
|
+
- History.txt
|
56
|
+
- Manifest.txt
|
57
|
+
- README.txt
|
58
|
+
- Rakefile
|
59
|
+
- Todo.txt
|
60
|
+
- examples/detailed_debug.rb
|
61
|
+
- examples/get_disk_info.rb
|
62
|
+
- examples/get_hostname.rb
|
63
|
+
- examples/non_standard_shell.rb
|
64
|
+
- lib/net/ssh/telnet.rb
|
65
|
+
- test/test_net-ssh-telnet.rb
|
66
|
+
test_files:
|
67
|
+
- test/test_net-ssh-telnet.rb
|
68
|
+
rdoc_options:
|
69
|
+
- --main
|
70
|
+
- README.txt
|
71
|
+
extra_rdoc_files:
|
72
|
+
- History.txt
|
73
|
+
- Manifest.txt
|
74
|
+
- README.txt
|
75
|
+
- Todo.txt
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
dependencies:
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: net-ssh
|
85
|
+
version_requirement:
|
86
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.0.1
|
91
|
+
version:
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: hoe
|
94
|
+
version_requirement:
|
95
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.5.3
|
100
|
+
version:
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
����IW���y֪���yv�Q~�'�\��LL����?ݾ}
|