This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
324 additions
and
218 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
/pkg | ||
pkg/* | ||
*.gem | ||
.bundle | ||
.rvmrc |
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,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in proxylocal.gemspec | ||
gemspec |
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,21 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
proxylocal (0.3.0) | ||
bert (>= 1.1.2) | ||
eventmachine (>= 0.12.10) | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
bert (1.1.2) | ||
eventmachine (0.12.10) | ||
rake (0.8.7) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (>= 1.0.10) | ||
proxylocal! | ||
rake (>= 0.8.7) |
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 |
---|---|---|
@@ -1,15 +1,2 @@ | ||
require 'rubygems' | ||
require 'rake' | ||
require 'echoe' | ||
|
||
require 'lib/client' | ||
|
||
Echoe.new('proxylocal', ProxyLocal::VERSION) do |p| | ||
p.summary = 'Proxy your local web-server and make it publicly available over the internet' | ||
p.url = 'http://proxylocal.com/' | ||
p.author = 'Just Lest' | ||
p.email = 'just.lest@gmail.com' | ||
p.runtime_dependencies = ['eventmachine >=0.12.10', 'bert >=1.1.2'] | ||
p.require_signed = true | ||
p.project = nil | ||
end | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
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 |
---|---|---|
@@ -1,71 +1,10 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'optparse' | ||
require 'yaml' | ||
require File.expand_path('client', File.join(File.dirname(__FILE__), '..', 'lib')) | ||
|
||
rc_path = File.expand_path(File.join('~', '.proxylocalrc')) | ||
rc = YAML.load_file(rc_path) rescue {} | ||
|
||
options = rc.dup | ||
|
||
begin | ||
cmd_args = OptionParser.new do |opts| | ||
opts.banner = 'Usage: proxylocal [options] [PORT]' | ||
|
||
opts.on('--token TOKEN', 'Save token to .proxylocalrc') do |token| | ||
rc[:token] = token | ||
File.open(rc_path, 'w') { |f| f.write(YAML.dump(rc)) } | ||
File.chmod(0600, rc_path) | ||
exit | ||
end | ||
|
||
opts.on('--host HOST', 'Bind to host') do |host| | ||
options[:hosts] ||= [] | ||
options[:hosts] << host | ||
end | ||
|
||
opts.on('--[no-]tls', 'Use TLS') do |tls| | ||
options[:tls] = tls | ||
end | ||
|
||
opts.on('-s', '--server SERVER', 'Specify proxylocal server') do |s| | ||
options[:server_host], options[:server_port] = s.split(':') | ||
end | ||
|
||
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v| | ||
options[:verbose] = v | ||
end | ||
|
||
opts.on_tail("--version", "Show version") do | ||
puts ProxyLocal::VERSION | ||
exit | ||
end | ||
|
||
opts.on_tail('-h', '--help', 'Show this message') do | ||
puts opts | ||
exit | ||
end | ||
end.parse! | ||
rescue OptionParser::MissingArgument => e | ||
puts e | ||
exit | ||
rescue OptionParser::InvalidOption => e | ||
puts e | ||
exit | ||
require 'proxylocal/command' | ||
rescue LoadError | ||
proxylocal_path = File.expand_path('../../lib', __FILE__) | ||
$:.unshift(proxylocal_path) if File.directory?(proxylocal_path) && !$:.include?(proxylocal_path) | ||
require 'proxylocal/command' | ||
end | ||
|
||
options[:local_port] = cmd_args[0] | ||
|
||
default_options = { | ||
:server_host => 'proxylocal.com', | ||
:server_port => '8282', | ||
:local_port => '80', | ||
:tls => false, | ||
:verbose => false, | ||
:version => ProxyLocal::VERSION | ||
} | ||
|
||
options = default_options.merge(options.reject { |k, v| v.nil? }) | ||
|
||
ProxyLocal::Client.run(options) |
This file was deleted.
Oops, something went wrong.
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,19 @@ | ||
require 'proxylocal/version' | ||
|
||
module ProxyLocal | ||
autoload :Client, 'proxylocal/client' | ||
autoload :Protocol, 'proxylocal/protocol' | ||
autoload :ClientProxy, 'proxylocal/client_proxy' | ||
autoload :Serializer, 'proxylocal/serializer' | ||
autoload :Command, 'proxylocal/command' | ||
|
||
class << self | ||
def logger | ||
@@logger ||= nil | ||
end | ||
|
||
def logger=(logger) | ||
@@logger = logger | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
require 'logger' | ||
require 'eventmachine' | ||
|
||
module ProxyLocal | ||
class Client < EventMachine::Connection | ||
include Protocol | ||
|
||
def self.run(options = {}) | ||
@@logger = Logger.new(STDOUT) | ||
@@logger.level = options[:verbose] ? Logger::INFO : Logger::WARN | ||
|
||
@@logger.info("Run with options #{options.inspect}") | ||
|
||
begin | ||
trap 'SIGCLD', 'IGNORE' | ||
trap 'INT' do | ||
puts | ||
EventMachine.stop | ||
exit | ||
end | ||
rescue ArgumentError | ||
end | ||
|
||
EventMachine.run do | ||
EventMachine.connect(options[:server_host], options[:server_port], self, options) | ||
end | ||
end | ||
|
||
def initialize(options) | ||
@options = options | ||
end | ||
|
||
def send_options | ||
send_object(:options, @options) | ||
end | ||
|
||
def post_init | ||
@connections = {} | ||
|
||
if @options[:tls] | ||
@@logger.info('Request TLS') | ||
send_object(:start_tls) | ||
else | ||
send_options | ||
end | ||
end | ||
|
||
def ssl_handshake_completed | ||
send_options | ||
end | ||
|
||
def unbind | ||
EventMachine.stop_event_loop | ||
puts 'A connection has been terminated' | ||
end | ||
|
||
def receive_unknown(object) | ||
@@logger.info("Received #{object.inspect}") | ||
end | ||
|
||
def receive_start_tls | ||
@@logger.info('Start TLS') | ||
start_tls | ||
end | ||
|
||
def receive_message(message) | ||
puts message | ||
end | ||
|
||
def receive_halt | ||
EventMachine.stop_event_loop | ||
end | ||
|
||
def receive_connection(id) | ||
@@logger.info('New connection') | ||
connection = EventMachine.connect('127.0.0.1', @options[:local_port], ClientProxy) | ||
connection.on_data do |data| | ||
send_object(:stream, id, data) | ||
end | ||
connection.on_unbind do | ||
@@logger.info('Connection closed') | ||
@connections.delete(id) | ||
send_object(:close, id) | ||
end | ||
@connections[id] = connection | ||
end | ||
|
||
def receive_stream(id, data) | ||
@connections[id].send_data(data) if @connections[id] | ||
end | ||
|
||
def receive_close(id) | ||
connection = @connections.delete(id) | ||
connection.close_connection_after_writing if connection | ||
end | ||
end | ||
end |
Oops, something went wrong.