swistaczek-localtunnel 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,6 @@
1
+ Rakefile
2
+ lib/localtunnel.rb
3
+ lib/localtunnel/tunnel.rb
4
+ lib/localtunnel/net_ssh_gateway_patch.rb
5
+ bin/localtunnel
6
+ Manifest
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('swistaczek-localtunnel', '0.3.2') do |p|
6
+ p.description = "instant public tunnel to your local web server"
7
+ p.url = "http://github.com/swistaczek/localtunnel"
8
+ p.author = "Jeff Lindsay"
9
+ p.email = "jeff.lindsay@twilio.com"
10
+ p.rdoc_pattern = //
11
+ p.rdoc_options = []
12
+ p.ignore_pattern = ["tmp/*", "script/*"]
13
+ p.executable_pattern = ["bin/*"]
14
+ p.runtime_dependencies = ["json >=1.2.4", "net-ssh >=2.0.22", "net-ssh-gateway >=1.0.1"]
15
+ p.development_dependencies = []
16
+ end
data/bin/localtunnel ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2010 Jeff Lindsay
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation
6
+ # files (the "Software"), to deal in the Software without
7
+ # restriction, including without limitation the rights to use,
8
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the
10
+ # Software is furnished to do so, subject to the following
11
+ # 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
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ # OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require 'rubygems'
26
+ require 'optparse'
27
+ require 'localtunnel'
28
+
29
+ key = nil
30
+ options = OptionParser.new do |o|
31
+ o.banner =
32
+ "Usage: localtunnel [options] <localport>\n\n" +
33
+ "The file .localtunnel_callback, if it exists in the current working directory,\n"+
34
+ "will be executed with the tunnel endpoint as the first argument once the \n" +
35
+ "tunnel is started\n\n"
36
+
37
+ o.on("-k", "--key FILE", "upload a public key for authentication") do |k|
38
+ key = File.exist?(k.to_s) ? File.open(k).read : nil
39
+ end
40
+ o.on('-h', "--help", "show this help") { puts o; exit }
41
+ end
42
+
43
+ args = options.parse!
44
+ local_port = args[0]
45
+ unless local_port.to_i.between?(1, 65535)
46
+ puts options
47
+ exit
48
+ end
49
+
50
+ t = LocalTunnel::Tunnel.new(local_port, key)
51
+ t.register_tunnel
52
+ t.start_tunnel
@@ -0,0 +1,2 @@
1
+ $: << File.expand_path(File.dirname(__FILE__))
2
+ require 'localtunnel/tunnel'
@@ -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
@@ -0,0 +1,72 @@
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 'localtunnel/net_ssh_gateway_patch'
9
+
10
+ module LocalTunnel; end
11
+
12
+ class LocalTunnel::Tunnel
13
+
14
+ SHELL_HOOK_FILE = "./.localtunnel_callback"
15
+
16
+ attr_accessor :port, :key, :host
17
+
18
+ def initialize(port, key)
19
+ @port = port
20
+ @key = key
21
+ @host = ""
22
+ end
23
+
24
+ def register_tunnel(key=@key)
25
+ url = URI.parse("http://open.localtunnel.com/")
26
+ if key
27
+ resp = JSON.parse(Net::HTTP.post_form(url, {"key" => key}).body)
28
+ else
29
+ resp = JSON.parse(Net::HTTP.get(url))
30
+ end
31
+ if resp.has_key? 'error'
32
+ puts " [Error] #{resp['error']}"
33
+ exit
34
+ end
35
+ @host = resp['host'].split(':').first
36
+ @tunnel = resp
37
+ return resp
38
+ rescue
39
+ puts " [Error] Unable to register tunnel. Perhaps service is down?"
40
+ exit
41
+ end
42
+
43
+ def start_tunnel
44
+ port = @port
45
+ tunnel = @tunnel
46
+ gateway = Net::SSH::Gateway.new(@host, tunnel['user'], :auth_methods => %w{ publickey })
47
+ gateway.open_remote(port.to_i, '127.0.0.1', tunnel['through_port'].to_i) do |rp,rh|
48
+ puts " " << tunnel['banner'] if tunnel.has_key? 'banner'
49
+ if File.exists?(File.expand_path(SHELL_HOOK_FILE))
50
+ system "#{File.expand_path(SHELL_HOOK_FILE)} ""#{tunnel['host']}"""
51
+ if !$?.success?
52
+ puts " An error occurred executing the callback hook #{SHELL_HOOK_FILE}"
53
+ puts " (Make sure it is executable)"
54
+ end
55
+ end
56
+ puts " Port #{port} is now publicly accessible from http://#{tunnel['host']} ..."
57
+ begin
58
+ sleep 1 while true
59
+ rescue Interrupt
60
+ gateway.close_remote(rp, rh)
61
+ exit
62
+ end
63
+ end
64
+ rescue Net::SSH::AuthenticationFailed
65
+ possible_key = Dir[File.expand_path('~/.ssh/*.pub')].first
66
+ puts " Failed to authenticate. If this is your first tunnel, you need to"
67
+ puts " upload a public key using the -k option. Try this:\n\n"
68
+ puts " localtunnel -k #{possible_key ? possible_key : '~/path/to/key.pub'} #{port}\n\n"
69
+ puts " Don't have a key? Check out http://bit.ly/createsshkey"
70
+ exit
71
+ end
72
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "swistaczek-localtunnel"
5
+ s.version = "0.3.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jeff Lindsay"]
9
+ s.date = "2012-07-13"
10
+ s.description = "instant public tunnel to your local web server"
11
+ s.email = "jeff.lindsay@twilio.com"
12
+ s.executables = ["localtunnel"]
13
+ s.extra_rdoc_files = ["Rakefile", "lib/localtunnel.rb", "lib/localtunnel/tunnel.rb", "lib/localtunnel/net_ssh_gateway_patch.rb", "bin/localtunnel", "swistaczek-localtunnel.gemspec"]
14
+ s.files = ["Rakefile", "lib/localtunnel.rb", "lib/localtunnel/tunnel.rb", "lib/localtunnel/net_ssh_gateway_patch.rb", "bin/localtunnel", "Manifest", "swistaczek-localtunnel.gemspec"]
15
+ s.homepage = "http://github.com/swistaczek/localtunnel"
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = "swistaczek-localtunnel"
18
+ s.rubygems_version = "1.8.24"
19
+ s.summary = "instant public tunnel to your local web server"
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_runtime_dependency(%q<json>, [">= 1.2.4"])
26
+ s.add_runtime_dependency(%q<net-ssh>, [">= 2.0.22"])
27
+ s.add_runtime_dependency(%q<net-ssh-gateway>, [">= 1.0.1"])
28
+ else
29
+ s.add_dependency(%q<json>, [">= 1.2.4"])
30
+ s.add_dependency(%q<net-ssh>, [">= 2.0.22"])
31
+ s.add_dependency(%q<net-ssh-gateway>, [">= 1.0.1"])
32
+ end
33
+ else
34
+ s.add_dependency(%q<json>, [">= 1.2.4"])
35
+ s.add_dependency(%q<net-ssh>, [">= 2.0.22"])
36
+ s.add_dependency(%q<net-ssh-gateway>, [">= 1.0.1"])
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swistaczek-localtunnel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeff Lindsay
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.2.4
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: 1.2.4
30
+ - !ruby/object:Gem::Dependency
31
+ name: net-ssh
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.22
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.22
46
+ - !ruby/object:Gem::Dependency
47
+ name: net-ssh-gateway
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.1
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: 1.0.1
62
+ description: instant public tunnel to your local web server
63
+ email: jeff.lindsay@twilio.com
64
+ executables:
65
+ - localtunnel
66
+ extensions: []
67
+ extra_rdoc_files:
68
+ - Rakefile
69
+ - lib/localtunnel.rb
70
+ - lib/localtunnel/tunnel.rb
71
+ - lib/localtunnel/net_ssh_gateway_patch.rb
72
+ - bin/localtunnel
73
+ - swistaczek-localtunnel.gemspec
74
+ files:
75
+ - Rakefile
76
+ - lib/localtunnel.rb
77
+ - lib/localtunnel/tunnel.rb
78
+ - lib/localtunnel/net_ssh_gateway_patch.rb
79
+ - bin/localtunnel
80
+ - Manifest
81
+ - swistaczek-localtunnel.gemspec
82
+ homepage: http://github.com/swistaczek/localtunnel
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '1.2'
100
+ requirements: []
101
+ rubyforge_project: swistaczek-localtunnel
102
+ rubygems_version: 1.8.24
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: instant public tunnel to your local web server
106
+ test_files: []