polyssh 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/{bin → exe}/polyssh +0 -0
- data/lib/polyssh/cli.rb +24 -7
- data/lib/polyssh/command_builder.rb +13 -10
- data/lib/polyssh/version.rb +1 -1
- data/polyssh.gemspec +3 -2
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e74e4493183db0966a98460a46f5654ac722084
|
4
|
+
data.tar.gz: ef43dc25ecaf23a33f1c12deb53c642fea05acc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb8c0d9a7762786acda31b101285b0a01912d4ddf99820bf8fe2a1e059666245f2e739d6c3c552ee43bbd7a7ad7e7cff5f4a76b1a790323edad5695b24503791
|
7
|
+
data.tar.gz: 69961a80e472e300605825ad51de1dbac776e5167782bcc0ee6fc9d31643fb6917ed13c40d295ecd78229176822ad1b9495fc2c310e00429bedcc303e754858d
|
data/README.md
CHANGED
@@ -36,16 +36,16 @@ We want to connect
|
|
36
36
|
|
37
37
|
* to a remote host called ``destination`` (as user ``charlie``, on default port)
|
38
38
|
* via a firewall (as user ``alice``, on non-default port 7222)
|
39
|
-
* then via a router (as user ``bob``, on default), with
|
39
|
+
* then via a router (as user ``bob``, on default), with verbosity)
|
40
40
|
|
41
41
|
Type the following command using polyssh :
|
42
42
|
|
43
|
-
$ polyssh alice@firewall:7222 -verbose
|
43
|
+
$ polyssh alice@firewall:7222 -verbose bob@router charlie@destination
|
44
44
|
|
45
45
|
|
46
46
|
## Credits
|
47
47
|
|
48
|
-
* Initial idea : [Bob Muller on Stack Overflow](http://superuser.com/a/377215)
|
48
|
+
* Initial idea & implementation : [Bob Muller on Stack Overflow](http://superuser.com/a/377215)
|
49
49
|
* Ruby rewrite & packaging : Glenn Y. Rolland
|
50
50
|
|
51
51
|
## Contributing
|
data/{bin → exe}/polyssh
RENAMED
File without changes
|
data/lib/polyssh/cli.rb
CHANGED
@@ -2,42 +2,52 @@
|
|
2
2
|
require 'net/ssh'
|
3
3
|
require 'net/scp'
|
4
4
|
require 'optparse'
|
5
|
+
require 'colorize'
|
5
6
|
|
6
7
|
module PolySSH
|
7
8
|
class Cli
|
8
|
-
attr_reader :chain
|
9
|
+
attr_reader :chain, :commands
|
9
10
|
|
10
11
|
def self.start args
|
11
12
|
app = self.new
|
12
13
|
app.parse_cmdline args
|
13
14
|
|
15
|
+
puts "Building SSH hops...".yellow
|
14
16
|
app.build_commands app.chain
|
17
|
+
#app.commands.each{|x| puts x }
|
15
18
|
|
16
|
-
|
17
|
-
|
19
|
+
puts "Running SSH hops...".yellow
|
20
|
+
app.run_commands app.commands
|
18
21
|
end
|
19
22
|
|
20
23
|
def initialize
|
21
24
|
@chain = NodeList.new
|
25
|
+
@commands = []
|
22
26
|
@options = {}
|
23
27
|
end
|
24
28
|
|
25
29
|
def parse_cmdline args
|
26
30
|
_parse_cmdline_options args
|
27
31
|
_parse_cmdline_hops args
|
28
|
-
|
29
32
|
end
|
30
33
|
|
34
|
+
def run_commands commands
|
35
|
+
@commands[0..-2].each do |baseport,cmd|
|
36
|
+
fork { exec cmd + " >/dev/null 2>&1 " }
|
37
|
+
_wait_active_port baseport
|
38
|
+
end
|
39
|
+
_baseport, cmd = @commands.last
|
40
|
+
system cmd
|
41
|
+
end
|
31
42
|
|
32
43
|
def build_commands chain
|
33
|
-
commands = chain.accept(CommandBuilder.new)
|
34
|
-
return commands
|
44
|
+
@commands = chain.accept(CommandBuilder.new)
|
45
|
+
return @commands
|
35
46
|
end
|
36
47
|
|
37
48
|
private
|
38
49
|
|
39
50
|
def _parse_cmdline_hops args
|
40
|
-
puts args
|
41
51
|
args_current = []
|
42
52
|
args.each do |arg|
|
43
53
|
case arg
|
@@ -60,6 +70,12 @@ module PolySSH
|
|
60
70
|
return @chain
|
61
71
|
end
|
62
72
|
|
73
|
+
def _wait_active_port port
|
74
|
+
while !system("nc -w0 localhost #{port}") do
|
75
|
+
sleep 1
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
63
79
|
def _parse_cmdline_options args
|
64
80
|
OptionParser.new do |opts|
|
65
81
|
opts.banner = "Usage: example.rb [options]"
|
@@ -77,6 +93,7 @@ module PolySSH
|
|
77
93
|
end
|
78
94
|
end.parse! args
|
79
95
|
rescue FinalOption
|
96
|
+
# nothing
|
80
97
|
ensure
|
81
98
|
return nil
|
82
99
|
end
|
@@ -14,19 +14,22 @@ module PolySSH
|
|
14
14
|
if node_list.count > 0 then
|
15
15
|
node_list.first.accept(self)
|
16
16
|
end
|
17
|
-
@commands.each do |cmd|
|
18
|
-
puts cmd
|
19
|
-
fork { exec cmd + " >/dev/null 2>&1 " }
|
20
|
-
sleep 2
|
21
|
-
end
|
22
|
-
puts @last_command
|
23
|
-
system @last_command
|
24
17
|
end
|
25
18
|
|
26
19
|
# Visit each node entry
|
27
20
|
def visit_polyssh_nodeentry node_entry
|
28
21
|
cmd=""
|
29
|
-
if node_entry.next.nil? then
|
22
|
+
if @commands.empty? and node_entry.next.nil? then
|
23
|
+
cmd = ("ssh " +
|
24
|
+
"-o ForwardAgent=yes " +
|
25
|
+
"-o UserKnownHostsFile=/dev/null " +
|
26
|
+
"-o StrictHostKeyChecking=no " +
|
27
|
+
"-p #{node_entry.port} " +
|
28
|
+
"-l #{node_entry.user} " +
|
29
|
+
"#{node_entry.host} "
|
30
|
+
)
|
31
|
+
@commands << [@baseport, cmd]
|
32
|
+
elsif node_entry.next.nil? then
|
30
33
|
cmd = ("ssh " +
|
31
34
|
"-o ForwardAgent=yes " +
|
32
35
|
"-o UserKnownHostsFile=/dev/null " +
|
@@ -35,7 +38,7 @@ module PolySSH
|
|
35
38
|
"-l #{node_entry.user} " +
|
36
39
|
"localhost "
|
37
40
|
)
|
38
|
-
@
|
41
|
+
@commands << [@baseport, cmd]
|
39
42
|
else
|
40
43
|
get_port
|
41
44
|
next_entry = node_entry.next
|
@@ -48,7 +51,7 @@ module PolySSH
|
|
48
51
|
"-L#{@baseport}:#{next_entry.host}:#{next_entry.port} " +
|
49
52
|
"-l #{node_entry.user} #{node_entry.host} "
|
50
53
|
)
|
51
|
-
@commands << cmd
|
54
|
+
@commands << [@baseport, cmd]
|
52
55
|
next_entry.accept(self)
|
53
56
|
end
|
54
57
|
end
|
data/lib/polyssh/version.rb
CHANGED
data/polyssh.gemspec
CHANGED
@@ -15,12 +15,13 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = "
|
19
|
-
spec.executables = spec.files.grep(%r{^
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "net-scp"
|
23
23
|
spec.add_runtime_dependency "net-ssh"
|
24
|
+
spec.add_runtime_dependency "colorize"
|
24
25
|
|
25
26
|
spec.add_development_dependency "bundler", "~> 1.10"
|
26
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glenn Y. Rolland
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-scp
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +109,7 @@ files:
|
|
95
109
|
- README.md
|
96
110
|
- Rakefile
|
97
111
|
- TODO.md
|
98
|
-
-
|
112
|
+
- exe/polyssh
|
99
113
|
- lib/polyssh.rb
|
100
114
|
- lib/polyssh/cli.rb
|
101
115
|
- lib/polyssh/command_builder.rb
|