shaft 0.5.0

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shaft.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sagie Maoz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Shaft - right on.
2
+
3
+ <pre>
4
+ $$$$$$\ $$\ $$\ $$$$$$\ $$$$$$$$\ $$$$$$$$\
5
+ $$ __$$\ $$ | $$ |$$ __$$\ $$ _____|\__$$ __|
6
+ $$ / \__|$$ | $$ |$$ / $$ |$$ | $$ |
7
+ \$$$$$$\ $$$$$$$$ |$$$$$$$$ |$$$$$\ $$ |
8
+ \____$$\ $$ __$$ |$$ __$$ |$$ __| $$ |
9
+ $$\ $$ |$$ | $$ |$$ | $$ |$$ | $$ |
10
+ \$$$$$$ |$$ | $$ |$$ | $$ |$$ | $$ |
11
+ \______/ \__| \__|\__| \__|\__| \__|
12
+ </pre>
13
+
14
+ An SSH tunnel assistant for the command line.
15
+
16
+
17
+ ## Installation
18
+
19
+ As easy as:
20
+
21
+ $ gem install shaft
22
+
23
+ ## Usage
24
+
25
+ Your tunnel configurations need to be stored as
26
+ [YAML](http://www.yaml.org) files on your `~/.shaft/` dir.
27
+
28
+ See 'Configuration' for instructions on how to format these
29
+ files.
30
+
31
+ * Use `shaft all` to get a list of all available tunnels.
32
+ * Use `shaft list` to see which tunnels are currently active.
33
+ - You could use the `--short` option to get only the names
34
+ of those lines (this could be useful to insert into your
35
+ shell prompt. Just saying).
36
+ * `shaft start [NAME]` would start the tunnel of the same name.
37
+ * `shaft stop [NAME]` would stop the tunnel of the given name.
38
+
39
+ ## Configuration
40
+
41
+ Each SSH tunnel you want to have configured needs to be defined
42
+ in YAML format and stored in `~/.shaft/name.yml`, where `name`
43
+ is the tunnel name that would be used for `shaft`.
44
+
45
+ An example configuration would be:
46
+
47
+ port: 22
48
+ username: user
49
+ host: remote-host
50
+ bind:
51
+ client-port: 9999
52
+ host: host
53
+ host-port: 8888
54
+
55
+
56
+ Starting the tunnel defined in this example would be equivalent
57
+ to running:
58
+
59
+ $ ssh -N -p 22 user@remote-host -L 9999:host:8888
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ 1. Write tests.
2
+ 2. Verify killing of ssh process after 'stop' task.
data/bin/shaft ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ SHAFT_DIR = File.join(Dir.home, ".shaft")
4
+
5
+ require 'rubygems'
6
+ require 'thor'
7
+ require 'yaml'
8
+
9
+ class ShaftCLI < Thor
10
+ include Thor::Actions
11
+
12
+ map "-h" => :help
13
+ map "-l" => :list
14
+
15
+ desc "list", "Lists active tunnels"
16
+ method_options %w( short -s ) => :boolean
17
+ def list
18
+ active = get_active
19
+ unless active.empty?
20
+ if options[:short]
21
+ say active.keys.join(",")
22
+ else
23
+ say "Listing currently active tunnels:"
24
+ print_table active
25
+ end
26
+ else
27
+ say "No tunnels are currently active." unless options[:short]
28
+ end
29
+ end
30
+
31
+ desc "all", "Lists all available tunnels"
32
+ def all
33
+ say "Listing all available tunnels:"
34
+ tunnels = Dir["#{SHAFT_DIR}/*.yml"].map { |f| File.basename(f, ".yml") }
35
+ print_in_columns tunnels
36
+ end
37
+
38
+ desc "start [NAME]", "Starts a tunnel"
39
+ method_options :name => :string
40
+ def start(name)
41
+ active = get_active
42
+ if active.has_key? name
43
+ say "Error: tunnel '#{name}' already active!"
44
+ else
45
+ c = read_yaml("#{name}.yml")
46
+ unless c.nil?
47
+ begin
48
+ port = c['port']
49
+ bind = "#{c['bind']['client-port']}:#{c['bind']['host']}:#{c['bind']['host-port']}"
50
+ host = "#{c['username']}@#{c['host']}"
51
+ rescue NoMethodError
52
+ error "Tunnel file for '#{name}' appears to be invalid!"
53
+ return
54
+ end
55
+
56
+ say "Starting tunnel '#{name}'..."
57
+ pid = Process.spawn("ssh -N -p #{port} #{host} -L #{bind}")
58
+ Process.detach pid
59
+ say "Started with pid #{pid}."
60
+
61
+ active[name] = pid
62
+ set_active(active)
63
+ else
64
+ error "Tunnel '#{name}' file not found!"
65
+ end
66
+ end
67
+ end
68
+
69
+ desc "stop [NAME]", "Stops a tunnel"
70
+ method_options :name => :string
71
+ def stop(name)
72
+ active = get_active
73
+ if active.has_key? name
74
+ say "Stopping tunnel '#{name}' at pid #{active[name]}..."
75
+ Process.kill "INT", active[name]
76
+ say "Stopped."
77
+
78
+ #TODO verify killing?
79
+
80
+ active.delete(name)
81
+ set_active(active)
82
+ else
83
+ error "Tunnel '#{name}' does not seem to be active!"
84
+ end
85
+ end
86
+
87
+ private
88
+ def read_yaml(filename)
89
+ path = File.join(SHAFT_DIR, filename)
90
+ YAML::load(File.open(path)) if File.exist?(path)
91
+ end
92
+
93
+ def get_active
94
+ active = read_yaml(".active")
95
+ if active.nil?
96
+ active = {}
97
+ set_active(active)
98
+ end
99
+ active
100
+ end
101
+
102
+ def set_active(active)
103
+ unless File.exist?(SHAFT_DIR) and File.directory?(SHAFT_DIR)
104
+ Dir.mkdir(SHAFT_DIR)
105
+ end
106
+
107
+ File.open(File.join(SHAFT_DIR, '.active'), 'w') { |f|
108
+ f.write(active.to_yaml)
109
+ }
110
+ end
111
+
112
+ end
113
+
114
+ ShaftCLI.start
@@ -0,0 +1,3 @@
1
+ module Shaft
2
+ VERSION = "0.5.0"
3
+ end
data/lib/shaft.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "shaft/version"
2
+
3
+ module Shaft
4
+ # Your code goes here...
5
+ end
data/shaft.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/shaft/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sagie Maoz"]
6
+ gem.email = ["sagie2maoz.info"]
7
+ gem.description = %q{SSH tunnels manager}
8
+ gem.summary = %q{An SSH tunnel assistant for the command line.}
9
+ gem.homepage = "http://github.com/n0nick/shaft"
10
+
11
+ gem.add_dependency "thor"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "shaft"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = Shaft::VERSION
19
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shaft
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sagie Maoz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: SSH tunnels manager
31
+ email:
32
+ - sagie2maoz.info
33
+ executables:
34
+ - shaft
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - TODO
44
+ - bin/shaft
45
+ - lib/shaft.rb
46
+ - lib/shaft/version.rb
47
+ - shaft.gemspec
48
+ homepage: http://github.com/n0nick/shaft
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: An SSH tunnel assistant for the command line.
72
+ test_files: []