pairkit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rdoc", "~> 3.12"
10
+ gem "bundler", "~> 1.1.0"
11
+ gem "jeweler", "~> 1.8.4"
12
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.7.3)
11
+ rake (0.9.2.2)
12
+ rdoc (3.12)
13
+ json (~> 1.4)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.1.0)
20
+ jeweler (~> 1.8.4)
21
+ rdoc (~> 3.12)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Gabe Hollombe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = pairkit
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to pairkit
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Gabe Hollombe. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "pairkit"
18
+ gem.homepage = "http://pairkit.com"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Share local ports over the Internet, even through NAT.}
21
+ gem.description = %Q{PairKit lets you temporarily expose any ports, on your local computer, to someone else on the Internet. This makes it great for sharing your local web server with a friend, or letting a buddy ssh into your box to pair with you on some code. PairKit uses SSH to set up reverse tunnels (one per exposed port) to your computer through a public server.}
22
+ gem.email = "gabe@avantbard.com"
23
+ gem.authors = ["Gabe Hollombe"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "pairkit #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/pairkit ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+ Bundler.require(:default)
6
+
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require 'lib/ssh_keys'
9
+
10
+ J = MultiJson
11
+
12
+ SERVER_HOST = "pairkit.com"
13
+ SERVER_WEB = "http://#{SERVER_HOST}:80"
14
+ SERVER_SSH_USERNAME = 'pairkit'
15
+
16
+
17
+ class Pair < Thor
18
+ desc "claim_invite_code", "claim an invite code"
19
+ method_option :invite_code, :aliases => "-c", :desc => "Your invite code", :type => :string
20
+ def claim_invite_code
21
+ public_key = get_or_generate_ssh_key()
22
+ claim_response = RestClient.get(SERVER_WEB + "/claim_invite_code", :params => {:invite_code => options[:invite_code], :public_key => public_key})
23
+ puts claim_response
24
+ end
25
+
26
+ desc 'share [PORTS]', 'share some ports'
27
+ def share(*ports)
28
+ public_key = get_or_generate_ssh_key()
29
+
30
+ # Register with the server
31
+ response = RestClient.post(SERVER_WEB + "/share",
32
+ :public_key => public_key,
33
+ :ports => ports)
34
+
35
+ share_result = J.load(response, :symbolize_keys => true)
36
+ puts "Share result: #{share_result}"
37
+
38
+ # Collect all the remote:local port forward pairs
39
+ reverse_tunnel_args = share_result[:remote_port_forwards].collect{ |remote_port, local_port| "-R #{remote_port}:localhost:#{local_port}" }
40
+
41
+ # Setup our reverse tunnel so the server forwards its remote ports to our local ports
42
+ setup_reverse_tunnel_cmd = "ssh -N #{reverse_tunnel_args.join(' ')} #{share_result[:ssh_user_name]}@#{share_result[:ssh_host]}"
43
+ puts "Running: #{setup_reverse_tunnel_cmd}"
44
+
45
+ pids = []
46
+ pids << Kernel.fork { `#{setup_reverse_tunnel_cmd}` }
47
+
48
+ # Let them know we're good to go
49
+ puts "OK! We're forwarding ports as long as you keep this process running."
50
+ puts "When you're ready to kill the port forwards, type Control+C."
51
+
52
+ # Wait for a Control+C to quit
53
+ trap("SIGINT") do
54
+ # Cleanup our ssh forwards before we quit
55
+ pids.each {|pid| Process.kill("HUP", pid) }
56
+ puts "Thank you, come again! =-)"
57
+ exit!
58
+ end
59
+ cmd = nil
60
+ while cmd != "quit" do
61
+ cmd = STDIN.gets
62
+ end
63
+ end
64
+ end
65
+
66
+ Pair.start
data/lib/pairkit.rb ADDED
@@ -0,0 +1 @@
1
+ #TODO encapsulate client executable code better and move most of it in here. And tests? =-)
data/lib/ssh_keys.rb ADDED
@@ -0,0 +1,63 @@
1
+ # ----------------------------------------
2
+ #
3
+ # Thank you, Heroku gem, for nearly all of this!
4
+ #
5
+ # ----------------------------------------
6
+
7
+ def get_or_generate_ssh_key
8
+ public_keys = Dir.glob("#{home_directory}/.ssh/*.pub").sort
9
+
10
+ case public_keys.length
11
+ when 0 then
12
+ puts "Could not find an existing public key."
13
+ puts "Let's generate one..."
14
+ puts "Generating new SSH public key."
15
+ generate_ssh_key("id_rsa")
16
+ get_key("#{home_directory}/.ssh/id_rsa.pub")
17
+ when 1 then
18
+ puts "Using existing public key: #{public_keys.first}"
19
+ get_key(public_keys.first)
20
+ else
21
+ puts "Found the following SSH public keys:"
22
+ public_keys.each_with_index do |key, index|
23
+ puts "#{index+1}) #{File.basename(key)}"
24
+ end
25
+ puts "Which would you like to use? (Enter number) "
26
+ choice = ask.to_i - 1
27
+ chosen = public_keys[choice]
28
+ if choice == -1 || chosen.nil?
29
+ error("Invalid choice.")
30
+ end
31
+ get_key(chosen)
32
+ end
33
+ end
34
+
35
+ def generate_ssh_key(keyfile)
36
+ ssh_dir = File.join(home_directory, ".ssh")
37
+ unless File.exists?(ssh_dir)
38
+ FileUtils.mkdir_p ssh_dir
39
+ File.chmod(0700, ssh_dir)
40
+ end
41
+ `ssh-keygen -t rsa -N "" -f \"#{home_directory}}/.ssh/#{keyfile}\" 2>&1`
42
+ end
43
+
44
+ def get_key(key)
45
+ File.read(key).chomp #strip trailing newline if present
46
+ end
47
+
48
+ def ask
49
+ $stdin.gets.to_s.strip
50
+ end
51
+
52
+ def error(message)
53
+ $stderr.puts(message)
54
+ exit(1)
55
+ end
56
+
57
+ def home_directory
58
+ running_on_windows? ? ENV['USERPROFILE'].gsub("\\","/") : ENV['HOME']
59
+ end
60
+
61
+ def running_on_windows?
62
+ RUBY_PLATFORM =~ /mswin32|mingw32/
63
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'pairkit'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPairkit < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pairkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gabe Hollombe
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.12'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.12'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeweler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.4
62
+ description: PairKit lets you temporarily expose any ports, on your local computer,
63
+ to someone else on the Internet. This makes it great for sharing your local web
64
+ server with a friend, or letting a buddy ssh into your box to pair with you on some
65
+ code. PairKit uses SSH to set up reverse tunnels (one per exposed port) to your
66
+ computer through a public server.
67
+ email: gabe@avantbard.com
68
+ executables:
69
+ - pairkit
70
+ extensions: []
71
+ extra_rdoc_files:
72
+ - LICENSE.txt
73
+ - README.rdoc
74
+ files:
75
+ - .document
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - LICENSE.txt
79
+ - README.rdoc
80
+ - Rakefile
81
+ - VERSION
82
+ - bin/pairkit
83
+ - lib/pairkit.rb
84
+ - lib/ssh_keys.rb
85
+ - test/helper.rb
86
+ - test/test_pairkit.rb
87
+ homepage: http://pairkit.com
88
+ licenses:
89
+ - MIT
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ segments:
101
+ - 0
102
+ hash: -2069664640876726119
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 1.8.22
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Share local ports over the Internet, even through NAT.
115
+ test_files: []