forked from progrium/localtunnel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:progrium/localtunnel
- Loading branch information
Showing
7 changed files
with
177 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
.idea/* | ||
.idea/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
= localtunnel -- instant public tunnel for local web servers | ||
|
||
Dependencies: | ||
- Ruby (with libopenssl) and Rubygems. | ||
- A public key. | ||
|
||
To get the dependencies, type: | ||
|
||
sudo apt-get install ruby ruby1.8-dev rubygems1.8 libopenssl-ruby | ||
|
||
If you have never made a public key, then run: | ||
|
||
ssh-keygen | ||
|
||
== Install | ||
|
||
sudo gem install localtunnel | ||
|
||
or to get the source: | ||
|
||
git clone http://github.com/progrium/localtunnel.git | ||
|
||
|
||
== Usage | ||
|
||
localtunnel [options] <localport> | ||
-k, --key FILE upload a public key for authentication | ||
|
||
Localtunnel is a client to a free and open source reverse tunneling | ||
service made specifically for web traffic. It's intended to be used to | ||
temporarily expose local web servers to the greater Internet for | ||
debugging, unit tests, demos, etc. | ||
|
||
This is how you make your local port 8080 public: | ||
|
||
$ localtunnel 8080 | ||
|
||
Port 8080 is now publicly accessible from http://8bv2.localtunnel.com ... | ||
|
||
Using localtunnel is comparable to using SSH reverse/remote port | ||
forwarding on a remote host that has GatewayPorts enabled, but without | ||
all the configuration or the need of a host. The localtunnel command | ||
works with a server component that is running on localtunnel.com, | ||
which is provided as a free service. | ||
|
||
If have never run localtunnel before, you'll need to upload a public | ||
key to authenticate. You do this once: | ||
|
||
$ localtunnel -k ~/.ssh/id_rsa.pub 8080 | ||
|
||
After that, you shouldn't have to use -k again. | ||
|
||
Localtunnel can be started before or after the local web server. It | ||
tunnels through to the url given in that status message "publicly | ||
accessible from..." for as long as the command is running. The tunnel | ||
is closed if the command exits. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'rubygems' | ||
require 'net/ssh' | ||
require 'net/ssh/gateway' | ||
require 'net/http' | ||
require 'uri' | ||
require 'optparse' | ||
require 'json' | ||
|
||
class LocalTunnel | ||
|
||
attr_accessor :port, :key, :host | ||
|
||
def initialize(port, key) | ||
@port = port | ||
@key = key | ||
@host = "" | ||
end | ||
|
||
def register_tunnel(key=@key) | ||
url = URI.parse("http://open.localtunnel.com/") | ||
if key | ||
resp = JSON.parse(Net::HTTP.post_form(url, {"key" => key}).body) | ||
else | ||
resp = JSON.parse(Net::HTTP.get(url)) | ||
end | ||
if resp.has_key? 'error' | ||
puts " [Error] #{resp['error']}" | ||
exit | ||
end | ||
@host = resp['host'] | ||
@tunnel = resp | ||
return resp | ||
rescue | ||
puts " [Error] Unable to register tunnel. Perhaps service is down?" | ||
exit | ||
end | ||
|
||
def start_tunnel | ||
port = @port | ||
tunnel = @tunnel | ||
gateway = Net::SSH::Gateway.new(tunnel['host'], tunnel['user']) | ||
gateway.open_remote(port.to_i, '127.0.0.1', tunnel['through_port'].to_i) do |rp,rh| | ||
puts " " << tunnel['banner'] if tunnel.has_key? 'banner' | ||
puts " Port #{port} is now publicly accessible from http://#{tunnel['host']} ..." | ||
begin | ||
sleep 1 while true | ||
rescue Interrupt | ||
gateway.close_remote(rp, rh) | ||
exit | ||
end | ||
end | ||
rescue Net::SSH::AuthenticationFailed | ||
possible_key = Dir[File.expand_path('~/.ssh/*.pub')].first | ||
puts " Failed to authenticate. If this is your first tunnel, you need to" | ||
puts " upload a public key using the -k option. Try this:\n\n" | ||
puts " localtunnel -k #{possible_key ? possible_key : '~/path/to/key'} #{port}" | ||
exit | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'rubygems' | ||
require 'net/ssh' | ||
require 'net/ssh/gateway' | ||
require 'net/http' | ||
require 'uri' | ||
require 'optparse' | ||
require 'json' | ||
|
||
# http://groups.google.com/group/capistrano/browse_thread/thread/455c0c8a6faa9cc8?pli=1 | ||
class Net::SSH::Gateway | ||
# Opens a SSH tunnel from a port on a remote host to a given host and port | ||
# on the local side | ||
# (equivalent to openssh -R parameter) | ||
def open_remote(port, host, remote_port, remote_host = "127.0.0.1") | ||
ensure_open! | ||
|
||
@session_mutex.synchronize do | ||
@session.forward.remote(port, host, remote_port, remote_host) | ||
end | ||
|
||
if block_given? | ||
begin | ||
yield [remote_port, remote_host] | ||
ensure | ||
close_remote(remote_port, remote_host) | ||
end | ||
else | ||
return [remote_port, remote_host] | ||
end | ||
rescue Errno::EADDRINUSE | ||
retry | ||
end | ||
|
||
# Cancels port-forwarding over an open port that was previously opened via | ||
# #open_remote. | ||
def close_remote(port, host = "127.0.0.1") | ||
ensure_open! | ||
|
||
@session_mutex.synchronize do | ||
@session.forward.cancel_remote(port, host) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters