passageway 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +7 -0
- data/bin/passageway +53 -0
- data/lib/passageway/client.rb +80 -0
- data/lib/passageway/net_ssh_gateway_patch.rb +39 -0
- data/lib/passageway/version.rb +3 -0
- data/lib/passageway.rb +5 -0
- data/passageway.gemspec +27 -0
- data/spec/client_spec.rb +6 -0
- data/spec/spec_helper.rb +2 -0
- metadata +149 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 R. Tyler Croy
|
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,29 @@
|
|
1
|
+
# Passageway
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'passageway'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install passageway
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/passageway
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright (c) 2010 Jeff Lindsay
|
3
|
+
# Copyright (c) 2013 R. Tyler Croy
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person
|
6
|
+
# obtaining a copy of this software and associated documentation
|
7
|
+
# files (the "Software"), to deal in the Software without
|
8
|
+
# restriction, including without limitation the rights to use,
|
9
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the
|
11
|
+
# Software is furnished to do so, subject to the following
|
12
|
+
# conditions:
|
13
|
+
#
|
14
|
+
# The above copyright notice and this permission notice shall be
|
15
|
+
# included in all copies or substantial portions of the Software.
|
16
|
+
#
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
19
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
21
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
22
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
23
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
24
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
|
26
|
+
require 'rubygems'
|
27
|
+
require 'optparse'
|
28
|
+
require 'passageway'
|
29
|
+
|
30
|
+
key = nil
|
31
|
+
options = OptionParser.new do |o|
|
32
|
+
o.banner =
|
33
|
+
"Usage: passageway [options] <localport>\n\n" +
|
34
|
+
"The file .localtunnel_callback, if it exists in the current working directory,\n"+
|
35
|
+
"will be executed with the tunnel endpoint as the first argument once the \n" +
|
36
|
+
"tunnel is started\n\n"
|
37
|
+
|
38
|
+
o.on("-k", "--key FILE", "upload a public key for authentication") do |k|
|
39
|
+
key = File.exist?(k.to_s) ? File.open(k).read : nil
|
40
|
+
end
|
41
|
+
o.on('-h', "--help", "show this help") { puts o; exit }
|
42
|
+
end
|
43
|
+
|
44
|
+
args = options.parse!
|
45
|
+
local_port = args[0]
|
46
|
+
unless local_port.to_i.between?(1, 65535)
|
47
|
+
puts options
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
t = Passageway::Client.new(local_port, key)
|
52
|
+
t.register_tunnel
|
53
|
+
t.start_tunnel
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'net/ssh/gateway'
|
4
|
+
require 'net/http'
|
5
|
+
require 'uri'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
require 'passageway/net_ssh_gateway_patch'
|
9
|
+
|
10
|
+
module Passageway
|
11
|
+
class Client
|
12
|
+
|
13
|
+
SHELL_HOOK_FILE = "./.localtunnel_callback"
|
14
|
+
|
15
|
+
attr_accessor :port, :key, :host
|
16
|
+
|
17
|
+
def initialize(port, key)
|
18
|
+
@port = port
|
19
|
+
@key = key
|
20
|
+
@host = ""
|
21
|
+
end
|
22
|
+
|
23
|
+
def register_tunnel(key=@key)
|
24
|
+
url = URI.parse("http://open.localtunnel.com/")
|
25
|
+
if key
|
26
|
+
resp = JSON.parse(Net::HTTP.post_form(url, {"key" => key}).body)
|
27
|
+
else
|
28
|
+
resp = JSON.parse(Net::HTTP.get(url))
|
29
|
+
end
|
30
|
+
if resp.has_key? 'error'
|
31
|
+
puts " [Error] #{resp['error']}"
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
@host = resp['host'].split(':').first
|
35
|
+
@tunnel = resp
|
36
|
+
return resp
|
37
|
+
rescue
|
38
|
+
puts " [Error] Unable to register tunnel. Perhaps service is down?"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
|
42
|
+
def start_tunnel
|
43
|
+
port = @port
|
44
|
+
tunnel = @tunnel
|
45
|
+
gateway = Net::SSH::Gateway.new(@host, tunnel['user'], :auth_methods => %w{ publickey })
|
46
|
+
gateway.open_remote(port.to_i, '127.0.0.1', tunnel['through_port'].to_i) do |rp,rh|
|
47
|
+
puts " " << tunnel['banner'] if tunnel.has_key? 'banner'
|
48
|
+
if File.exists?(File.expand_path(SHELL_HOOK_FILE))
|
49
|
+
system "#{File.expand_path(SHELL_HOOK_FILE)} ""#{tunnel['host']}"""
|
50
|
+
if !$?.success?
|
51
|
+
puts " An error occurred executing the callback hook #{SHELL_HOOK_FILE}"
|
52
|
+
puts " (Make sure it is executable)"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
puts " Port #{port} is now publicly accessible from http://#{tunnel['host']} ..."
|
56
|
+
begin
|
57
|
+
# If we're using Passageway from within Ruby
|
58
|
+
if block_given?
|
59
|
+
yield
|
60
|
+
else
|
61
|
+
# Otherwise, we're probably calling it on the command line, so
|
62
|
+
# let's just block forever
|
63
|
+
sleep 1 while true
|
64
|
+
end
|
65
|
+
rescue Interrupt
|
66
|
+
gateway.close_remote(rp, rh)
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
rescue Net::SSH::AuthenticationFailed
|
71
|
+
possible_key = Dir[File.expand_path('~/.ssh/*.pub')].first
|
72
|
+
puts " Failed to authenticate. If this is your first tunnel, you need to"
|
73
|
+
puts " upload a public key using the -k option. Try this:\n\n"
|
74
|
+
puts " localtunnel -k #{possible_key ? possible_key : '~/path/to/key.pub'} #{port}\n\n"
|
75
|
+
puts " Don't have a key? Check out http://bit.ly/createsshkey"
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/ssh'
|
3
|
+
require 'net/ssh/gateway'
|
4
|
+
|
5
|
+
# http://groups.google.com/group/capistrano/browse_thread/thread/455c0c8a6faa9cc8?pli=1
|
6
|
+
class Net::SSH::Gateway
|
7
|
+
# Opens a SSH tunnel from a port on a remote host to a given host and port
|
8
|
+
# on the local side
|
9
|
+
# (equivalent to openssh -R parameter)
|
10
|
+
def open_remote(port, host, remote_port, remote_host = "127.0.0.1")
|
11
|
+
ensure_open!
|
12
|
+
|
13
|
+
@session_mutex.synchronize do
|
14
|
+
@session.forward.remote(port, host, remote_port, remote_host)
|
15
|
+
end
|
16
|
+
|
17
|
+
if block_given?
|
18
|
+
begin
|
19
|
+
yield [remote_port, remote_host]
|
20
|
+
ensure
|
21
|
+
close_remote(remote_port, remote_host)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
return [remote_port, remote_host]
|
25
|
+
end
|
26
|
+
rescue Errno::EADDRINUSE
|
27
|
+
retry
|
28
|
+
end
|
29
|
+
|
30
|
+
# Cancels port-forwarding over an open port that was previously opened via
|
31
|
+
# #open_remote.
|
32
|
+
def close_remote(port, host = "127.0.0.1")
|
33
|
+
ensure_open!
|
34
|
+
|
35
|
+
@session_mutex.synchronize do
|
36
|
+
@session.forward.cancel_remote(port, host)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/passageway.rb
ADDED
data/passageway.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'passageway/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "passageway"
|
8
|
+
spec.version = Passageway::VERSION
|
9
|
+
spec.authors = ["R. Tyler Croy"]
|
10
|
+
spec.email = ["tyler@monkeypox.org"]
|
11
|
+
spec.description = "A Ruby-based client for localtunnel"
|
12
|
+
spec.summary = "This is a fork off the original localtunnel Ruby gem, which has since been deprecated"
|
13
|
+
spec.homepage = "https://github.com/rtyler/passageway"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency 'json'
|
25
|
+
spec.add_dependency 'net-ssh'
|
26
|
+
spec.add_dependency 'net-ssh-gateway'
|
27
|
+
end
|
data/spec/client_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: passageway
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- R. Tyler Croy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
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: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '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: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: net-ssh
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: net-ssh-gateway
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: A Ruby-based client for localtunnel
|
95
|
+
email:
|
96
|
+
- tyler@monkeypox.org
|
97
|
+
executables:
|
98
|
+
- passageway
|
99
|
+
extensions: []
|
100
|
+
extra_rdoc_files: []
|
101
|
+
files:
|
102
|
+
- .gitignore
|
103
|
+
- Gemfile
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- bin/passageway
|
108
|
+
- lib/passageway.rb
|
109
|
+
- lib/passageway/client.rb
|
110
|
+
- lib/passageway/net_ssh_gateway_patch.rb
|
111
|
+
- lib/passageway/version.rb
|
112
|
+
- passageway.gemspec
|
113
|
+
- spec/client_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
homepage: https://github.com/rtyler/passageway
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
segments:
|
129
|
+
- 0
|
130
|
+
hash: -4133823098665751409
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: -4133823098665751409
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 1.8.25
|
143
|
+
signing_key:
|
144
|
+
specification_version: 3
|
145
|
+
summary: This is a fork off the original localtunnel Ruby gem, which has since been
|
146
|
+
deprecated
|
147
|
+
test_files:
|
148
|
+
- spec/client_spec.rb
|
149
|
+
- spec/spec_helper.rb
|