xlogin 0.4.10 → 0.4.12
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -0
- data/lib/xlogin/firmware.rb +1 -0
- data/lib/xlogin/session.rb +14 -0
- data/lib/xlogin/ssh.rb +12 -134
- data/lib/xlogin/telnet.rb +0 -14
- data/lib/xlogin/version.rb +1 -1
- data/lib/xlogin.rb +1 -2
- data/xlogin.gemspec +2 -0
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee6e8c428e1f71f7454b78db8c10a43212fb1819
|
4
|
+
data.tar.gz: c0e1b1f9a6fc303be6f13faff6ba696602b5fe28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abdaa6ea16194a13a77498dd17ceb15893a3147dfb93ab8f49a5bdc55f715bcee879b1c04cbe70ecea5c4994bc0722b8c208137c5f59b616ce846ba5dfe71545
|
7
|
+
data.tar.gz: a4695e113fe14bd9a9e7e7c908c96bd9b0b78aae448ea699d6cf9337f6b0ec58f75b6495f58136d76d84e16d94c7708ffd07df0095a7cdd667b036cfbddc5469
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
xlogin (0.4.12)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
net-ssh (4.1.0)
|
10
|
+
net-ssh-gateway (2.0.0)
|
11
|
+
net-ssh (>= 4.0.0)
|
12
|
+
net-ssh-telnet (0.2.0)
|
13
|
+
net-ssh (>= 2.0.1)
|
14
|
+
net-telnet (0.1.1)
|
15
|
+
rake (10.5.0)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
bundler (~> 1.13)
|
22
|
+
net-ssh-gateway
|
23
|
+
net-ssh-telnet
|
24
|
+
net-telnet
|
25
|
+
rake (~> 10.0)
|
26
|
+
xlogin!
|
27
|
+
|
28
|
+
BUNDLED WITH
|
29
|
+
1.15.3
|
data/lib/xlogin/firmware.rb
CHANGED
data/lib/xlogin/session.rb
CHANGED
@@ -25,6 +25,20 @@ module Xlogin
|
|
25
25
|
@mutex = Mutex.new
|
26
26
|
end
|
27
27
|
|
28
|
+
def waitfor(*expect)
|
29
|
+
if expect.compact.empty?
|
30
|
+
super(Regexp.union(*@prompts.map(&:first)), &@logger)
|
31
|
+
else
|
32
|
+
line = super(*expect, &@logger)
|
33
|
+
_, process = @prompts.find { |r, p| r =~ line && p }
|
34
|
+
if process
|
35
|
+
instance_eval(&process)
|
36
|
+
line += waitfor(*expect)
|
37
|
+
end
|
38
|
+
line
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
def lock(timeout: @timeout)
|
29
43
|
granted = false
|
30
44
|
|
data/lib/xlogin/ssh.rb
CHANGED
@@ -1,150 +1,28 @@
|
|
1
|
-
require 'net/ssh'
|
1
|
+
require 'net/ssh/telnet'
|
2
2
|
require 'xlogin/session'
|
3
3
|
|
4
4
|
module Xlogin
|
5
|
-
class Ssh
|
5
|
+
class Ssh < Net::SSH::Telnet
|
6
|
+
|
6
7
|
include Session
|
7
8
|
|
8
9
|
def initialize(**opts)
|
9
10
|
configure_session(opts.merge(port: opts[:port] || 22))
|
11
|
+
username, password = @userinfo
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
:password => password,
|
20
|
-
)
|
21
|
-
rescue TimeoutError
|
22
|
-
raise TimeoutError, 'timed out while opening a connection to the host'
|
23
|
-
rescue
|
24
|
-
raise
|
25
|
-
end
|
26
|
-
|
27
|
-
@buf = ''
|
28
|
-
@eof = false
|
29
|
-
@channel = nil
|
30
|
-
|
31
|
-
@ssh.open_channel do |channel|
|
32
|
-
channel.on_data { |ch, data| @buf << data }
|
33
|
-
channel.on_close { @eof = true }
|
34
|
-
|
35
|
-
channel.request_pty do |ch, success|
|
36
|
-
raise 'Failed to open ssh pty' unless success
|
37
|
-
end
|
38
|
-
|
39
|
-
channel.send_channel_request('shell') do |ch, success|
|
40
|
-
raise 'Failed to open ssh shell' unless success
|
41
|
-
|
42
|
-
@channel = ch
|
43
|
-
waitfor
|
44
|
-
return
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
@ssh.loop
|
49
|
-
end
|
50
|
-
|
51
|
-
def close
|
52
|
-
@channel.close if @channel
|
53
|
-
@ssh.close if @ssh
|
54
|
-
end
|
55
|
-
|
56
|
-
def waitfor(opts = nil)
|
57
|
-
time_out = @timeout
|
58
|
-
waittime = @timeout
|
59
|
-
|
60
|
-
case opts
|
61
|
-
when Hash
|
62
|
-
prompt = if opts.has_key?('Match')
|
63
|
-
opts['Match']
|
64
|
-
elsif opts.has_key?('Prompt')
|
65
|
-
opts['Prompt']
|
66
|
-
elsif opts.has_key?('String')
|
67
|
-
Regexp.new( Regexp.quote(opts['String']) )
|
68
|
-
end
|
69
|
-
time_out = opts['Timeout'] if opts.has_key?('Timeout')
|
70
|
-
waittime = opts['Waittime'] if opts.has_key?('Waittime')
|
71
|
-
else
|
72
|
-
prompt = opts || Regexp.union(*@prompts.map(&:first))
|
73
|
-
end
|
74
|
-
|
75
|
-
buf = ''
|
76
|
-
rest = ''
|
77
|
-
line = ''
|
78
|
-
sock = @ssh.transport.socket
|
79
|
-
|
80
|
-
until sock.available == 0 && @buf == "" && prompt != line && (@eof || (!sock.closed? && !IO::select([sock], nil, nil, waittime)))
|
81
|
-
if sock.available == 0 && @buf == "" && prompt !~ line && !IO::select([sock], nil, nil, time_out)
|
82
|
-
raise Net::ReadTimeout, 'timed out while waiting for more data'
|
83
|
-
end
|
84
|
-
|
85
|
-
process_connection
|
86
|
-
if @buf != ''
|
87
|
-
buf = rest + @buf
|
88
|
-
rest = ''
|
89
|
-
|
90
|
-
if pt = buf.rindex(/\r\z/no)
|
91
|
-
buf = buf[0...pt]
|
92
|
-
rest = buf[pt..-1]
|
93
|
-
end
|
94
|
-
|
95
|
-
@buf = ''
|
96
|
-
line += buf
|
97
|
-
@logger.call(buf)
|
98
|
-
elsif @eof
|
99
|
-
break
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
_, process = @prompts.find { |r, p| r =~ line && p }
|
104
|
-
if process
|
105
|
-
instance_eval(&process)
|
106
|
-
line += waitfor(opts)
|
107
|
-
end
|
108
|
-
line
|
109
|
-
end
|
110
|
-
|
111
|
-
def print(string)
|
112
|
-
@channel.send_data(string)
|
113
|
-
process_connection
|
114
|
-
end
|
115
|
-
|
116
|
-
def puts(string)
|
117
|
-
print(string + "\n")
|
118
|
-
end
|
119
|
-
|
120
|
-
def cmd(opts)
|
121
|
-
match = Regexp.union(*@prompts.map(&:first))
|
122
|
-
time_out = @timeout
|
123
|
-
|
124
|
-
if opts.kind_of?(Hash)
|
125
|
-
string = opts['String']
|
126
|
-
match = opts['Match'] if opts.has_key?('Match')
|
127
|
-
time_out = opts['Timeout'] if opts.has_key?('Timeout')
|
128
|
-
else
|
129
|
-
string = opts
|
130
|
-
end
|
131
|
-
|
132
|
-
puts(string)
|
133
|
-
waitfor('Prompt' => match, 'Timeout' => time_out)
|
13
|
+
super(
|
14
|
+
'Host' => @host,
|
15
|
+
'Port' => @port,
|
16
|
+
'Username' => username,
|
17
|
+
'Password' => password,
|
18
|
+
'Timeout' => @timeout,
|
19
|
+
'Prompt' => Regexp.union(*@prompts.map(&:first))
|
20
|
+
)
|
134
21
|
end
|
135
22
|
|
136
23
|
def interact!
|
137
24
|
raise 'Not implemented'
|
138
25
|
end
|
139
26
|
|
140
|
-
private
|
141
|
-
def process_connection
|
142
|
-
begin
|
143
|
-
@channel.connection.process(0)
|
144
|
-
rescue IOError
|
145
|
-
@eof = true
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
27
|
end
|
150
28
|
end
|
data/lib/xlogin/telnet.rb
CHANGED
@@ -20,20 +20,6 @@ module Xlogin
|
|
20
20
|
login(*@userinfo) if respond_to?(:login) && !@userinfo.empty?
|
21
21
|
end
|
22
22
|
|
23
|
-
def waitfor(*expect)
|
24
|
-
if expect.compact.empty?
|
25
|
-
super(Regexp.union(*@prompts.map(&:first)), &@logger)
|
26
|
-
else
|
27
|
-
line = super(*expect, &@logger)
|
28
|
-
_, process = @prompts.find { |r, p| r =~ line && p }
|
29
|
-
if process
|
30
|
-
instance_eval(&process)
|
31
|
-
line += waitfor(*expect)
|
32
|
-
end
|
33
|
-
line
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
23
|
def renew(opts = @opts)
|
38
24
|
self.class.new(opts).tap { |s| @sock = s.sock }
|
39
25
|
end
|
data/lib/xlogin/version.rb
CHANGED
data/lib/xlogin.rb
CHANGED
@@ -42,8 +42,7 @@ module Xlogin
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def get(hostname, args = {})
|
45
|
-
|
46
|
-
session = _factory.build_from_hostname(hostname, args)
|
45
|
+
session = factory.build_from_hostname(hostname, args)
|
47
46
|
|
48
47
|
if block_given?
|
49
48
|
begin yield session ensure session.close end
|
data/xlogin.gemspec
CHANGED
@@ -32,5 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 1.13"
|
34
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "net-telnet"
|
36
|
+
spec.add_development_dependency "net-ssh-telnet"
|
35
37
|
spec.add_development_dependency "net-ssh-gateway"
|
36
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlogin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- haccht
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: net-telnet
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: net-ssh-telnet
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: net-ssh-gateway
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +90,7 @@ files:
|
|
62
90
|
- ".gitignore"
|
63
91
|
- CODE_OF_CONDUCT.md
|
64
92
|
- Gemfile
|
93
|
+
- Gemfile.lock
|
65
94
|
- LICENSE.txt
|
66
95
|
- README.md
|
67
96
|
- Rakefile
|