tunnel_vision 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +66 -0
- data/Rakefile +2 -0
- data/bin/tunnelvision +6 -0
- data/lib/tunnel_vision/runner.rb +105 -0
- data/lib/tunnel_vision/version.rb +3 -0
- data/lib/tunnel_vision.rb +38 -0
- data/tunnel_vision.gemspec +21 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# TunnelVission!
|
2
|
+
|
3
|
+
## What is it?
|
4
|
+
|
5
|
+
Simple tool which lets you create definitions of ssh tunnels your project will need.
|
6
|
+
|
7
|
+
Then you by issuing one command you can open all of them and carry on with your work.
|
8
|
+
|
9
|
+
### Scratching an itch:
|
10
|
+
|
11
|
+
I find myself working remotely and/or changing machines more often than I could imagine.
|
12
|
+
|
13
|
+
Because at my day job I'm working only on a part of a big system I need to maintain connectivity of my development environment with other services by using SSH tunnels.
|
14
|
+
|
15
|
+
At worst I need 4 tunnels for my dev setup to be usable. *sigh*
|
16
|
+
|
17
|
+
So far I've been maintaining a set of different shell scripts which helped me establish SSH tunnels to different servers and such.
|
18
|
+
|
19
|
+
TunnelVision solves that problem.
|
20
|
+
|
21
|
+
|
22
|
+
### Inspired by
|
23
|
+
|
24
|
+
- [takeup by Maxim Chernyak](https://github.com/maxim/takeup)
|
25
|
+
- [foreman by David Dollar](https://github.com/ddollar/foreman)
|
26
|
+
|
27
|
+
|
28
|
+
# Installation
|
29
|
+
|
30
|
+
`gem install tunnel_vision`
|
31
|
+
|
32
|
+
# Usage
|
33
|
+
|
34
|
+
- `tunnelvision` - shows simple help
|
35
|
+
- `tunnelvision generate` - generates example `tunnels.yaml` file
|
36
|
+
- `tunnelvision start` - opens all tunnels defined in `tunnels.yaml`
|
37
|
+
- `tunnelvision status` - shows information about opened tunnels
|
38
|
+
- `tunnelvision stop` - closes all opened tunnels defined by `tunnels.yaml`
|
39
|
+
|
40
|
+
### Requirements
|
41
|
+
|
42
|
+
- `ruby 1.8.7` (probably works with 1.9.2)
|
43
|
+
- OpenSSL support enabled in Ruby (OSX comes with that, Linux needs ruby-openssl package)
|
44
|
+
- `net-ssh` gem (gets installed with TunnelVission)
|
45
|
+
|
46
|
+
## Important!
|
47
|
+
|
48
|
+
You need to set up ssh-key based authentication before using TunnelVision. While it's possible to use passwords straight from `tunnels.yaml` it's horribly insecure!
|
49
|
+
|
50
|
+
You should always use ssh keys anyway.
|
51
|
+
|
52
|
+
### Bugs?
|
53
|
+
|
54
|
+
Yeah, plenty.
|
55
|
+
|
56
|
+
This gem was created in few hours, so it has few things which can explode. I will hunt them down.
|
57
|
+
|
58
|
+
## Todo
|
59
|
+
|
60
|
+
- colors
|
61
|
+
|
62
|
+
# Licence
|
63
|
+
|
64
|
+
TunnelVision is a product of Łukasz Korecki (lukasz@coffeesounds.com)
|
65
|
+
|
66
|
+
Licenced under MIT Licence
|
data/Rakefile
ADDED
data/bin/tunnelvision
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module TunnelVision
|
5
|
+
class Runner
|
6
|
+
def initialize args
|
7
|
+
if args.empty?
|
8
|
+
puts "Command me!"
|
9
|
+
puts help
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
@tunnel = TunnelVision::Tunnel.new
|
14
|
+
|
15
|
+
case args.first
|
16
|
+
when 'generate'
|
17
|
+
generate
|
18
|
+
when 'start'
|
19
|
+
start
|
20
|
+
when 'status'
|
21
|
+
status
|
22
|
+
when 'stop'
|
23
|
+
stop
|
24
|
+
else
|
25
|
+
puts "Unrecognized command"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def start
|
30
|
+
begin
|
31
|
+
tunnels = YAML::load_file 'tunnels.yaml'
|
32
|
+
rescue
|
33
|
+
puts "No tunnels file!"
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
current = {}
|
38
|
+
tunnels.each do |tunnel_def|
|
39
|
+
puts "Starting:\n\t#{tunnel_def['description']}"
|
40
|
+
pid = @tunnel.add tunnel_def['tunnel'], tunnel_def['user'], tunnel_def['host']
|
41
|
+
current[pid] = tunnel_def['description']
|
42
|
+
end
|
43
|
+
|
44
|
+
File.open('.opened_tunnels','w') do |file|
|
45
|
+
YAML::dump(current, file)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def status
|
50
|
+
begin
|
51
|
+
current = YAML::load_file '.opened_tunnels'
|
52
|
+
rescue
|
53
|
+
puts "No tunnels or .opened_tunnels files is locked/deleted"
|
54
|
+
exit 0
|
55
|
+
end
|
56
|
+
|
57
|
+
puts "Current tunnels"
|
58
|
+
current.each do |id, description|
|
59
|
+
puts "\t#{description} (#{id})"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def stop
|
64
|
+
@tunnel.pids = YAML::load_file('.opened_tunnels').keys
|
65
|
+
@tunnel.close_all!
|
66
|
+
FileUtils.rm '.opened_tunnels'
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def help
|
71
|
+
<<-HELP
|
72
|
+
tunnelvision generate - generate example tunnels file
|
73
|
+
tunnelvision start - start all ssh tunnels defined in tunnels.yaml
|
74
|
+
tunnelvision stop - stop all opened ssh tunnels
|
75
|
+
HELP
|
76
|
+
end
|
77
|
+
|
78
|
+
def generate
|
79
|
+
puts "Generating tunnels.yaml"
|
80
|
+
example = [
|
81
|
+
{
|
82
|
+
'description' => 'irc on staging server',
|
83
|
+
"user" => 'bob',
|
84
|
+
'host' => 'example.com',
|
85
|
+
'tunnel' => '123:123.0.0.1:80'
|
86
|
+
},
|
87
|
+
{
|
88
|
+
'description' => 'db from database server',
|
89
|
+
'user' => 'clyde',
|
90
|
+
'host' => 'bar.foo.com',
|
91
|
+
'tunnel' => '7777:bar.foo.com:8080'
|
92
|
+
}
|
93
|
+
]
|
94
|
+
|
95
|
+
begin
|
96
|
+
File.open('tunnels.yaml', 'w') do |file|
|
97
|
+
YAML::dump(example, file)
|
98
|
+
end
|
99
|
+
|
100
|
+
rescue "Error when creating tunnels.yaml"
|
101
|
+
end
|
102
|
+
puts "Created!"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/ssh'
|
3
|
+
module TunnelVision
|
4
|
+
class Tunnel
|
5
|
+
attr_accessor :pids
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@pids = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add tunnel, user, server
|
12
|
+
from, host, to = tunnel.split(':')
|
13
|
+
pid = fork do
|
14
|
+
puts "Connecting #{user}@#{server}"
|
15
|
+
begin
|
16
|
+
getaway = Net::SSH.start server, user do |ssh|
|
17
|
+
puts "setting forwarding (#{from} -> #{to} on #{host})"
|
18
|
+
ssh.forward.local from, host, to
|
19
|
+
ssh.loop { true }
|
20
|
+
end
|
21
|
+
rescue
|
22
|
+
puts ">>> AUTH ERROR <<"
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@pids << pid
|
27
|
+
pid
|
28
|
+
end
|
29
|
+
|
30
|
+
def close_all!
|
31
|
+
@pids.each do |pid|
|
32
|
+
puts "Closing #{pid}"
|
33
|
+
`kill -9 #{pid}`
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tunnel_vision/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tunnel_vision"
|
7
|
+
s.version = TunnelVision::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Łukasz Korecki"]
|
10
|
+
s.email = ["lukasz@coffeesounds.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{SSH tunnel manager}
|
13
|
+
s.description = %q{Easily open and close ssh tunnels required by your project}
|
14
|
+
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.add_dependency "net-ssh", ">= 2.1.4"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tunnel_vision
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "\xC5\x81ukasz Korecki"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-03 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: net-ssh
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 1
|
33
|
+
- 4
|
34
|
+
version: 2.1.4
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Easily open and close ssh tunnels required by your project
|
38
|
+
email:
|
39
|
+
- lukasz@coffeesounds.com
|
40
|
+
executables:
|
41
|
+
- tunnelvision
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- bin/tunnelvision
|
52
|
+
- lib/tunnel_vision.rb
|
53
|
+
- lib/tunnel_vision/runner.rb
|
54
|
+
- lib/tunnel_vision/version.rb
|
55
|
+
- tunnel_vision.gemspec
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: ""
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.5.0
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: SSH tunnel manager
|
90
|
+
test_files: []
|
91
|
+
|