expect4r 0.0.5.dev → 0.0.6.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/expect/io.rb +20 -3
- data/lib/misc/passwd.rb +10 -8
- data/lib/router/cisco/ios/modes.rb +3 -3
- data/lib/router/cisco/iox/modes.rb +3 -3
- data/lib/router/juniper/junos/junos.rb +4 -0
- data/lib/router/juniper/junos/modes.rb +15 -5
- data/test/misc/passwd_test.rb +2 -0
- metadata +3 -3
data/lib/expect/io.rb
CHANGED
@@ -255,7 +255,20 @@ module Expect4r
|
|
255
255
|
exp_puts 'yes'
|
256
256
|
when /(Login incorrect|denied, please try again)/
|
257
257
|
spawnee_reset
|
258
|
-
|
258
|
+
else
|
259
|
+
# For objects that include Expect4r but do not subclass base Login class.
|
260
|
+
@matches ||= []
|
261
|
+
@matches.each { |match, _send|
|
262
|
+
if read_pipe._io_string =~ match
|
263
|
+
read_pipe._io_save no_echo, "match #{match}"
|
264
|
+
if _send.is_a?(Proc)
|
265
|
+
exp_puts _send.call
|
266
|
+
else
|
267
|
+
exp_puts _send
|
268
|
+
end
|
269
|
+
end
|
270
|
+
}
|
271
|
+
end
|
259
272
|
end
|
260
273
|
end
|
261
274
|
case ev
|
@@ -320,7 +333,11 @@ module Expect4r
|
|
320
333
|
@matches.each { |match, _send|
|
321
334
|
if r._io_string =~ match
|
322
335
|
r._io_save no_echo, "match #{match}"
|
323
|
-
|
336
|
+
if _send.is_a?(Proc)
|
337
|
+
exp_puts _send.call
|
338
|
+
else
|
339
|
+
exp_puts _send
|
340
|
+
end
|
324
341
|
end
|
325
342
|
}
|
326
343
|
end
|
@@ -512,7 +529,7 @@ module Expect4r
|
|
512
529
|
@ps1 = /(.*)(>|#|\$)\s*$/
|
513
530
|
@more = / --More-- /
|
514
531
|
@matches=Set.new
|
515
|
-
|
532
|
+
Base.add(self)
|
516
533
|
self
|
517
534
|
end
|
518
535
|
|
data/lib/misc/passwd.rb
CHANGED
@@ -24,13 +24,15 @@ begin
|
|
24
24
|
|
25
25
|
rescue LoadError => e
|
26
26
|
|
27
|
-
module Expect4r
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
27
|
+
# module Expect4r
|
28
|
+
# def self.cipher(arg, pwd='')
|
29
|
+
# arg
|
30
|
+
# end
|
31
|
+
# def self.decipher(arg,pwd='')
|
32
|
+
# arg
|
33
|
+
# end
|
34
|
+
# end
|
35
|
+
|
36
|
+
raise
|
35
37
|
|
36
38
|
end
|
@@ -83,7 +83,7 @@ module Modes
|
|
83
83
|
return :config if config?
|
84
84
|
to_exec
|
85
85
|
putline 'configure terminal' if exec?
|
86
|
-
raise RuntimeError, "unable to
|
86
|
+
raise RuntimeError, "unable to get to config mode" unless config?
|
87
87
|
:config
|
88
88
|
end
|
89
89
|
|
@@ -92,14 +92,14 @@ module Modes
|
|
92
92
|
if config?
|
93
93
|
1.upto(config_lvl?) { putline 'exit'}
|
94
94
|
end
|
95
|
-
raise RuntimeError, "unable to
|
95
|
+
raise RuntimeError, "unable to get to exec mode" unless exec?
|
96
96
|
:exec
|
97
97
|
end
|
98
98
|
|
99
99
|
def to_user
|
100
100
|
return if user?
|
101
101
|
putline "exit"
|
102
|
-
raise RuntimeError, "unable to
|
102
|
+
raise RuntimeError, "unable to get to user mode" unless exec?
|
103
103
|
:user
|
104
104
|
end
|
105
105
|
|
@@ -90,7 +90,7 @@ module Modes
|
|
90
90
|
return :config if config?
|
91
91
|
to_exec
|
92
92
|
putline 'configure'
|
93
|
-
raise RuntimeError, "unable to
|
93
|
+
raise RuntimeError, "unable to get to config mode" unless config?
|
94
94
|
:config
|
95
95
|
end
|
96
96
|
|
@@ -98,7 +98,7 @@ module Modes
|
|
98
98
|
return :shell if shell?
|
99
99
|
to_exec
|
100
100
|
putline 'run'
|
101
|
-
raise RuntimeError, "unable to
|
101
|
+
raise RuntimeError, "unable to get to shell mode" unless shell?
|
102
102
|
:shell
|
103
103
|
end
|
104
104
|
|
@@ -106,7 +106,7 @@ module Modes
|
|
106
106
|
return :exec if exec?
|
107
107
|
putline "exit" if shell?
|
108
108
|
putline "abort" if config?
|
109
|
-
raise RuntimeError, "unable to
|
109
|
+
raise RuntimeError, "unable to get to exec mode" unless exec?
|
110
110
|
:exec
|
111
111
|
end
|
112
112
|
|
@@ -86,7 +86,13 @@ end
|
|
86
86
|
# returns *true* if router is in <tt>:shell</tt> mode, *false* otherwise.
|
87
87
|
#
|
88
88
|
def shell?
|
89
|
-
@lp == '% '
|
89
|
+
if @lp == '% '
|
90
|
+
true
|
91
|
+
elsif logged_as_root? and @lp =~ /root@.+% $/
|
92
|
+
true
|
93
|
+
else
|
94
|
+
false
|
95
|
+
end
|
90
96
|
end
|
91
97
|
|
92
98
|
def set_cli_logical_router(logical_router)
|
@@ -111,7 +117,7 @@ def to_config
|
|
111
117
|
return :config if config?
|
112
118
|
to_exec
|
113
119
|
putline 'edit', :debug=>1
|
114
|
-
raise RuntimeError, "unable to
|
120
|
+
raise RuntimeError, "unable to get to config mode" unless config?
|
115
121
|
:config
|
116
122
|
end
|
117
123
|
|
@@ -120,15 +126,19 @@ def to_shell
|
|
120
126
|
return :shell if shell?
|
121
127
|
to_exec
|
122
128
|
putline 'start shell'
|
123
|
-
raise RuntimeError, "unable to
|
129
|
+
raise RuntimeError, "unable to get to shell mode" unless shell?
|
124
130
|
:shell
|
125
131
|
end
|
126
132
|
|
133
|
+
def logged_as_root?
|
134
|
+
@_is_root_ ||= @lp =~ /root@/
|
135
|
+
end
|
136
|
+
|
127
137
|
def to_exec
|
128
138
|
return :exec if exec?
|
129
139
|
top if config?
|
130
|
-
exit
|
131
|
-
raise RuntimeError, "unable to
|
140
|
+
logged_as_root? ? cli : exit
|
141
|
+
raise RuntimeError, "unable to get to exec mode" unless exec?
|
132
142
|
:exec
|
133
143
|
end
|
134
144
|
|
data/test/misc/passwd_test.rb
CHANGED
@@ -5,5 +5,7 @@ class TestMiscPasswd < Test::Unit::TestCase
|
|
5
5
|
def test_cipher
|
6
6
|
assert_not_equal 'my password', Expect4r.cipher('my password')
|
7
7
|
assert_equal 'my password', Expect4r.decipher(Expect4r.cipher('my password'))
|
8
|
+
assert_not_equal 'my password', Expect4r.cipher('my password', 'abcdef')
|
9
|
+
assert_equal 'my password', Expect4r.decipher(Expect4r.cipher('my password'))
|
8
10
|
end
|
9
11
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- dev
|
10
|
-
version: 0.0.
|
10
|
+
version: 0.0.6.dev
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jean-Michel Esnault
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-29 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|