expect4r 0.0.4.dev → 0.0.5.dev
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/expect/io.rb +36 -19
- data/lib/misc/passwd.rb +33 -16
- data/lib/misc/shell.rb +2 -4
- metadata +3 -3
data/lib/expect/io.rb
CHANGED
@@ -314,15 +314,16 @@ module Expect4r
|
|
314
314
|
when @more
|
315
315
|
r._io_save no_echo, "matching MORE"
|
316
316
|
putc ' '
|
317
|
+
else
|
318
|
+
# For objects that include Expect4r but do not subclass base Login class.
|
319
|
+
@matches ||= []
|
320
|
+
@matches.each { |match, _send|
|
321
|
+
if r._io_string =~ match
|
322
|
+
r._io_save no_echo, "match #{match}"
|
323
|
+
exp_puts _send
|
324
|
+
end
|
325
|
+
}
|
317
326
|
end
|
318
|
-
|
319
|
-
@matches.each { |match, _send|
|
320
|
-
if r._io_string =~ match
|
321
|
-
r._io_save no_echo, "match #{match}"
|
322
|
-
exp_puts _send
|
323
|
-
end
|
324
|
-
}
|
325
|
-
|
326
327
|
end
|
327
328
|
end
|
328
329
|
case rc
|
@@ -431,7 +432,23 @@ module Kernel
|
|
431
432
|
end
|
432
433
|
|
433
434
|
module Expect4r
|
434
|
-
class
|
435
|
+
class Base
|
436
|
+
include Expect4r
|
437
|
+
class << self
|
438
|
+
attr_reader :routers
|
439
|
+
def add(r)
|
440
|
+
@routers ||=[]
|
441
|
+
@routers << r
|
442
|
+
end
|
443
|
+
end
|
444
|
+
def initialize(*args)
|
445
|
+
@matches = Set.new
|
446
|
+
Base.add(self)
|
447
|
+
self
|
448
|
+
end
|
449
|
+
end
|
450
|
+
|
451
|
+
class BaseLoginObject < Base
|
435
452
|
class << self
|
436
453
|
# Examples:
|
437
454
|
# my_mac = RShell.new_telnet '1.1.1.1', 'me', 'secret'
|
@@ -544,8 +561,8 @@ end
|
|
544
561
|
if __FILE__ != $0
|
545
562
|
|
546
563
|
at_exit {
|
547
|
-
if Expect4r::
|
548
|
-
Expect4r::
|
564
|
+
if Expect4r::Base.routers
|
565
|
+
Expect4r::Base.routers.each { |r| r.logout if r.respond_to? :logout }
|
549
566
|
end
|
550
567
|
}
|
551
568
|
|
@@ -553,21 +570,21 @@ else
|
|
553
570
|
|
554
571
|
require "test/unit"
|
555
572
|
|
556
|
-
class Expect4r::
|
573
|
+
class Expect4r::Base
|
557
574
|
def initialize
|
558
|
-
Expect4r::
|
575
|
+
Expect4r::Base.add(self)
|
559
576
|
end
|
560
577
|
end
|
561
578
|
|
562
|
-
class
|
579
|
+
class Base < Test::Unit::TestCase
|
563
580
|
include Expect4r
|
564
581
|
|
565
582
|
def test_add
|
566
|
-
assert [],
|
567
|
-
|
568
|
-
assert 1,
|
569
|
-
|
570
|
-
assert_equal 2,
|
583
|
+
assert [], Base.routers
|
584
|
+
Base.new
|
585
|
+
assert 1, Base.routers.size
|
586
|
+
Base.new
|
587
|
+
assert_equal 2, Base.routers.size
|
571
588
|
end
|
572
589
|
end
|
573
590
|
|
data/lib/misc/passwd.rb
CHANGED
@@ -1,19 +1,36 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
|
3
|
+
begin
|
4
|
+
|
5
|
+
require 'openssl'
|
6
|
+
require 'digest/sha1'
|
7
|
+
|
8
|
+
module Expect4r
|
9
|
+
def self.cipher(this, pwd='expect4r')
|
10
|
+
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
11
|
+
c.encrypt
|
12
|
+
c.key = key = Digest::SHA1.hexdigest(pwd)
|
13
|
+
e = c.update(this)
|
14
|
+
e << c.final
|
15
|
+
end
|
16
|
+
def self.decipher(cipher,pwd='expect4r')
|
17
|
+
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
18
|
+
c.decrypt
|
19
|
+
c.key = key = Digest::SHA1.hexdigest(pwd)
|
20
|
+
d = c.update(cipher)
|
21
|
+
d << c.final
|
22
|
+
end
|
11
23
|
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
24
|
+
|
25
|
+
rescue LoadError => e
|
26
|
+
|
27
|
+
module Expect4r
|
28
|
+
def self.cipher(arg, pwd='')
|
29
|
+
arg
|
30
|
+
end
|
31
|
+
def self.decipher(arg,pwd='')
|
32
|
+
arg
|
33
|
+
end
|
18
34
|
end
|
19
|
-
|
35
|
+
|
36
|
+
end
|
data/lib/misc/shell.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Expect4r
|
2
|
-
class Shell
|
3
|
-
include Expect4r
|
2
|
+
class Shell < Expect4r::Base
|
4
3
|
def initialize()
|
4
|
+
super
|
5
5
|
ENV['PROMPT_COMMAND']="date +%k:%m:%S"
|
6
6
|
ENV['PS1']="shell>"
|
7
7
|
@ps1 = /shell>$/
|
@@ -13,8 +13,6 @@ module Expect4r
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
class RShell < ::Expect4r::BaseLoginObject
|
16
|
-
include Expect4r
|
17
|
-
|
18
16
|
def initialize(*args)
|
19
17
|
super
|
20
18
|
default_ps1
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 5
|
9
9
|
- dev
|
10
|
-
version: 0.0.
|
10
|
+
version: 0.0.5.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-
|
18
|
+
date: 2010-11-13 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|