proxylocal 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -2,7 +2,9 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('proxylocal', '0.0.4') do |p|
5
+ require 'lib/client'
6
+
7
+ Echoe.new('proxylocal', ProxyLocal::VERSION) do |p|
6
8
  p.description = 'http://proxylocal.com/'
7
9
  p.url = 'http://proxylocal.com/'
8
10
  p.author = 'Just Lest'
data/bin/proxylocal CHANGED
@@ -3,24 +3,44 @@
3
3
  require 'optparse'
4
4
  require File.expand_path('client', File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
 
6
- server_host = nil
7
- server_port = nil
6
+ options = {}
8
7
 
9
- options = OptionParser.new do |o|
10
- o.banner = "Usage: localtunnel [options] PORT"
11
- o.on('-s', '--server SERVER', 'default proxylocal.com') do |server|
12
- server_host, server_port = server.split(':')
8
+ cmd_args = OptionParser.new do |opts|
9
+ opts.banner = 'Usage: proxylocal [options] [PORT]'
10
+
11
+ opts.on('-s', '--server SERVER') do |s|
12
+ options[:server_host], options[:server_port] = s.split(':')
13
+ end
14
+
15
+ opts.on('--[no-]tls', 'Use TLS') do |tls|
16
+ options[:tls] = tls
17
+ end
18
+
19
+ opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
20
+ options[:verbose] = v
21
+ end
22
+
23
+ opts.on_tail('-h', '--help', 'Show this message') do
24
+ puts opts
25
+ exit
26
+ end
27
+
28
+ opts.on_tail("--version", "Show version") do
29
+ puts ProxyLocal::VERSION
30
+ exit
13
31
  end
14
- o.on('-h', "--help", "show this help") { puts o; exit }
15
- end
32
+ end.parse!
16
33
 
17
- args = options.parse!
34
+ options[:local_port] = cmd_args[0]
18
35
 
19
- server_host ||= 'proxylocal.com'
20
- server_port ||= '8282'
36
+ default_options = {
37
+ :server_host => 'proxylocal.com',
38
+ :server_port => '8282',
39
+ :local_port => '80',
40
+ :tls => true,
41
+ :verbose => false
42
+ }
21
43
 
22
- local_port = args[0] || 80
44
+ options = default_options.merge(options.reject { |k, v| v.nil? })
23
45
 
24
- ProxyLocal::Client.run(:server_host => server_host,
25
- :server_port => server_port,
26
- :local_port => local_port)
46
+ ProxyLocal::Client.run(options)
data/lib/client.rb CHANGED
@@ -1,8 +1,11 @@
1
+ require 'logger'
1
2
  require 'rubygems'
2
3
  require 'eventmachine'
3
4
  require 'bert'
4
5
 
5
6
  module ProxyLocal
7
+ VERSION = '0.0.5'
8
+
6
9
  module Serializer
7
10
  def self.dump(object)
8
11
  BERT.encode(object)
@@ -16,11 +19,12 @@ module ProxyLocal
16
19
  class Client < EventMachine::Connection
17
20
  include EventMachine::Protocols::ObjectProtocol
18
21
 
19
- def serializer
20
- Serializer
21
- end
22
-
23
22
  def self.run(options = {})
23
+ @@logger = Logger.new(STDOUT)
24
+ @@logger.level = options[:verbose] ? Logger::INFO : Logger::WARN
25
+
26
+ @@logger.info("Run with options #{options.inspect}")
27
+
24
28
  trap "SIGCLD", "IGNORE"
25
29
  trap "INT" do
26
30
  puts
@@ -29,27 +33,53 @@ module ProxyLocal
29
33
  end
30
34
 
31
35
  EventMachine.run do
32
- EventMachine::connect(options[:server_host], options[:server_port], self) do |c|
36
+ EventMachine.connect(options[:server_host], options[:server_port], self) do |c|
33
37
  c.instance_eval do
34
38
  @options = options
35
- send_object(BERT::Tuple[:options, @options])
39
+ if @options[:tls]
40
+ @@logger.info("Request TLS")
41
+ send_object(:start_tls)
42
+ else
43
+ send_options
44
+ end
36
45
  end
37
46
  end
38
47
  end
39
48
  end
40
49
 
50
+ def serializer
51
+ Serializer
52
+ end
53
+
54
+ def send_options
55
+ send_object(BERT::Tuple[:options, @options])
56
+ end
57
+
58
+ def ssl_handshake_completed
59
+ send_options
60
+ end
61
+
62
+ def first_line(data)
63
+ data.split(/\r?\n/, 2).first
64
+ end
65
+
41
66
  def receive_object(message)
42
67
  message = [message] unless message.is_a?(Array)
43
68
 
44
69
  case message[0]
70
+ when :start_tls
71
+ @@logger.info("Start TLS")
72
+ start_tls
45
73
  when :message
46
74
  puts message[1]
47
75
  when :halt
48
76
  EventMachine.stop_event_loop
49
77
  when :request
50
78
  _, uuid, request = message
51
- EventMachine::connect('127.0.0.1', @options[:local_port], ClientProxy) do |connection|
79
+ @@logger.info(first_line(request))
80
+ EventMachine.connect('127.0.0.1', @options[:local_port], ClientProxy) do |connection|
52
81
  connection.callback do |data|
82
+ @@logger.info("#{first_line(data)} - #{first_line(request)}")
53
83
  send_object(BERT::Tuple[:response, uuid, data])
54
84
  end
55
85
  connection.send_data(request)
data/proxylocal.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{proxylocal}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Just Lest"]
9
- s.date = %q{2010-11-12}
9
+ s.date = %q{2010-11-17}
10
10
  s.default_executable = %q{proxylocal}
11
11
  s.description = %q{http://proxylocal.com/}
12
12
  s.email = %q{just.lest@gmail.com}
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxylocal
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Just Lest
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-12 00:00:00 +02:00
18
+ date: 2010-11-17 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency