tunnel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tunnel.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tunnel (0.0.1)
5
+ highline (~> 1.6)
6
+ thor (= 0.14.3)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ highline (1.6.1)
12
+ thor (0.14.3)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ highline (~> 1.6)
19
+ thor (= 0.14.3)
20
+ tunnel!
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # Tunnel
2
+
3
+ A ruby cli wrapper to make ssh tunneling a no brainer. Manages multiple
4
+ tunnel configs
5
+
6
+ ## Usage
7
+
8
+ tunnel add # Add a new tunnel config
9
+ tunnel list # List your tunnel configs
10
+ tunnel start # Start a tunnel (based on one of your configs)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/tunnel ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require "tunnel"
3
+ Tunnel::CLI.start
data/lib/tunnel/cli.rb ADDED
@@ -0,0 +1,47 @@
1
+ require "thor"
2
+
3
+ module Tunnel
4
+ class CLI < Thor
5
+
6
+ desc "start", "Start a tunnel"
7
+ def start
8
+ highline = HighLine.new
9
+ highline.choose do |menu|
10
+ menu.choices(*configs) do |choice|
11
+ Tunnel.start(choice)
12
+ end
13
+ end
14
+ end
15
+
16
+ desc "list", "List your tunnel configs"
17
+ def list
18
+ configs.each_with_index do |c, i|
19
+ puts "#{i+1}. #{c}"
20
+ end
21
+ end
22
+
23
+ desc "add", "Add a new tunnel config"
24
+ def add
25
+ highline = HighLine.new
26
+ puts "Adding a new tunnel config"
27
+
28
+ conf = Config.new
29
+ conf.name = highline.ask("Name: ")
30
+ conf.ssh_port = highline.ask("SSH port: ") { |q| q.default = "22" }
31
+ conf.local_port = highline.ask("Local port: ") { |q| q.default = "3000" }
32
+ conf.remote_user = highline.ask("Remote user: ") { |q| q.default = ENV['USER'] }
33
+ conf.remote_host = highline.ask("Remote host: ")
34
+ conf.remote_port = highline.ask("Remote port: ")
35
+
36
+ Configfile.add(conf)
37
+ end
38
+
39
+ protected
40
+ def configs
41
+ @configs ||= begin
42
+ c = Configfile.configs
43
+ c.empty? ? abort("Please add a new config with `tunnel add`") : c
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,20 @@
1
+ require "ostruct"
2
+
3
+ module Tunnel
4
+ class Config < OpenStruct
5
+
6
+ def to_yaml(opts={})
7
+ @table.to_yaml(opts)
8
+ end
9
+
10
+ def to_s
11
+ "[ %s ] %s:%s -> 0.0.0.0:%s" %
12
+ [ name, remote_host, remote_port, local_port ]
13
+ end
14
+
15
+ def ssh_command
16
+ "ssh -v -p %s -nNT -g -R *:%s:0.0.0.0:%s %s@%s" %
17
+ [ ssh_port, remote_port, local_port, remote_user, remote_host ]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,39 @@
1
+ module Tunnel
2
+ class Configfile
3
+ class << self
4
+
5
+ def configs
6
+ @configs ||= ( load_from_file || [] )
7
+ end
8
+
9
+ def load_from_file
10
+ return false unless config_exists?
11
+
12
+ if result = YAML.load_file(configfile)
13
+ result.map { |c| Config.new(c) }
14
+ else
15
+ puts "Your tunnel config (~/.tunnel) is not valid yaml"
16
+ end
17
+ end
18
+
19
+ def add(config)
20
+ configs.push(config)
21
+ save
22
+ end
23
+
24
+ def save
25
+ File.open(configfile, "w+") do |f|
26
+ f.puts YAML.dump( configs.sort_by { |c| c.name } )
27
+ end
28
+ end
29
+
30
+ def config_exists?
31
+ File.exist?(configfile)
32
+ end
33
+
34
+ def configfile
35
+ File.expand_path("~/.tunnel")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Tunnel
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tunnel.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "highline"
2
+ require "yaml"
3
+
4
+ module Tunnel
5
+ autoload :CLI, "tunnel/cli"
6
+ autoload :Configfile, "tunnel/configfile"
7
+ autoload :Config, "tunnel/config"
8
+
9
+ def self.start(conf)
10
+ puts "Starting #{conf}"
11
+ puts "--> #{conf.ssh_command}"
12
+ system conf.ssh_command
13
+ end
14
+ end
data/tunnel.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tunnel/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tunnel"
7
+ s.version = Tunnel::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ben Marini"]
10
+ s.email = ["bmarini@gmail.com"]
11
+ s.homepage = "http://github.com/bmarini/tunnel"
12
+ s.summary = %q{A ruby cli wrapper to make ssh tunneling a no brainer}
13
+ s.description = %q{A ruby cli wrapper to make ssh tunneling a no brainer}
14
+
15
+ s.rubyforge_project = "tunnel"
16
+ s.add_dependency "thor", "0.14.3"
17
+ s.add_dependency "highline", "~> 1.6"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tunnel
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ben Marini
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-14 00:00:00 -08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thor
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 33
30
+ segments:
31
+ - 0
32
+ - 14
33
+ - 3
34
+ version: 0.14.3
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: highline
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 1
48
+ - 6
49
+ version: "1.6"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: A ruby cli wrapper to make ssh tunneling a no brainer
53
+ email:
54
+ - bmarini@gmail.com
55
+ executables:
56
+ - tunnel
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - bin/tunnel
68
+ - lib/tunnel.rb
69
+ - lib/tunnel/cli.rb
70
+ - lib/tunnel/config.rb
71
+ - lib/tunnel/configfile.rb
72
+ - lib/tunnel/version.rb
73
+ - tunnel.gemspec
74
+ has_rdoc: true
75
+ homepage: http://github.com/bmarini/tunnel
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options: []
80
+
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ hash: 3
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project: tunnel
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: A ruby cli wrapper to make ssh tunneling a no brainer
108
+ test_files: []
109
+