proxylocal 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in proxylocal.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ proxylocal (0.3.0)
5
+ bert (>= 1.1.2)
6
+ eventmachine (>= 0.12.10)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ bert (1.1.2)
12
+ eventmachine (0.12.10)
13
+ rake (0.8.7)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (>= 1.0.10)
20
+ proxylocal!
21
+ rake (>= 0.8.7)
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # ProxyLocal
2
+
3
+ ProxyLocal could proxy your local web-server and make it publicly
4
+ available over the internet.
5
+
6
+ This software is splited into client and server parts. Server part is
7
+ running on [proxylocal.com] server and usage of its resources is free.
8
+ Client is written in ruby and distributed as gem, its source code is
9
+ open and available on [github].
10
+
11
+ ## Installation
12
+
13
+ ProxyLocal is a tool that runs on the command line.
14
+
15
+ On any system with [ruby] and [rubygems] installed, open your terminal
16
+ and type:
17
+
18
+ $ gem install proxylocal
19
+
20
+ ## Usage
21
+
22
+ Assume you are running your local web-server on port 3000. To make it
23
+ publicly available run:
24
+
25
+ $ proxylocal 3000
26
+ Local server on port 3000 is now publicly available via:
27
+ http://fp9k.t.proxylocal.com/
28
+
29
+ Now you can open this link in your favorite browser and request will
30
+ be proxied to your local web-server.
31
+
32
+ Also you can specify preferred host you want to use, e.g.:
33
+
34
+ $ proxylocal 3000 --host testhost
35
+ Local server on port 3000 is now publicly available via:
36
+ http://testhost.t.proxylocal.com/
37
+
38
+ [proxylocal.com]: http://proxylocal.com/
39
+ [ruby]: http://www.ruby-lang.org/en/downloads/
40
+ [rubygems]: https://rubygems.org/pages/download
41
+ [github]: https://github.com/proxylocal/proxylocal-gem
data/Rakefile CHANGED
@@ -1,15 +1,2 @@
1
- require 'rubygems'
2
- require 'rake'
3
- require 'echoe'
4
-
5
- require 'lib/client'
6
-
7
- Echoe.new('proxylocal', ProxyLocal::VERSION) do |p|
8
- p.summary = 'Proxy your local web-server and make it publicly available over the internet'
9
- p.url = 'http://proxylocal.com/'
10
- p.author = 'Just Lest'
11
- p.email = 'just.lest@gmail.com'
12
- p.runtime_dependencies = ['eventmachine >=0.12.10', 'bert >=1.1.2']
13
- p.require_signed = true
14
- p.project = nil
15
- end
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/proxylocal CHANGED
@@ -1,71 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'optparse'
4
- require 'yaml'
5
- require File.expand_path('client', File.join(File.dirname(__FILE__), '..', 'lib'))
6
-
7
- rc_path = File.expand_path(File.join('~', '.proxylocalrc'))
8
- rc = YAML.load_file(rc_path) rescue {}
9
-
10
- options = rc.dup
11
-
12
3
  begin
13
- cmd_args = OptionParser.new do |opts|
14
- opts.banner = 'Usage: proxylocal [options] [PORT]'
15
-
16
- opts.on('--token TOKEN', 'Save token to .proxylocalrc') do |token|
17
- rc[:token] = token
18
- File.open(rc_path, 'w') { |f| f.write(YAML.dump(rc)) }
19
- File.chmod(0600, rc_path)
20
- exit
21
- end
22
-
23
- opts.on('--host HOST', 'Bind to host') do |host|
24
- options[:hosts] ||= []
25
- options[:hosts] << host
26
- end
27
-
28
- opts.on('--[no-]tls', 'Use TLS') do |tls|
29
- options[:tls] = tls
30
- end
31
-
32
- opts.on('-s', '--server SERVER', 'Specify proxylocal server') do |s|
33
- options[:server_host], options[:server_port] = s.split(':')
34
- end
35
-
36
- opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
37
- options[:verbose] = v
38
- end
39
-
40
- opts.on_tail("--version", "Show version") do
41
- puts ProxyLocal::VERSION
42
- exit
43
- end
44
-
45
- opts.on_tail('-h', '--help', 'Show this message') do
46
- puts opts
47
- exit
48
- end
49
- end.parse!
50
- rescue OptionParser::MissingArgument => e
51
- puts e
52
- exit
53
- rescue OptionParser::InvalidOption => e
54
- puts e
55
- exit
4
+ require 'proxylocal/command'
5
+ rescue LoadError
6
+ proxylocal_path = File.expand_path('../../lib', __FILE__)
7
+ $:.unshift(proxylocal_path) if File.directory?(proxylocal_path) && !$:.include?(proxylocal_path)
8
+ require 'proxylocal/command'
56
9
  end
57
10
 
58
- options[:local_port] = cmd_args[0]
59
-
60
- default_options = {
61
- :server_host => 'proxylocal.com',
62
- :server_port => '8282',
63
- :local_port => '80',
64
- :tls => false,
65
- :verbose => false,
66
- :version => ProxyLocal::VERSION
67
- }
68
-
69
- options = default_options.merge(options.reject { |k, v| v.nil? })
70
-
71
- ProxyLocal::Client.run(options)
@@ -0,0 +1,109 @@
1
+ require 'logger'
2
+ require 'eventmachine'
3
+
4
+ module ProxyLocal
5
+ class Client < EventMachine::Connection
6
+ include Protocol
7
+
8
+ def self.run(options = {})
9
+ @@logger = Logger.new(STDOUT)
10
+ @@logger.level = options[:verbose] ? Logger::INFO : Logger::WARN
11
+
12
+ @@logger.info("Run with options #{options.inspect}")
13
+
14
+ begin
15
+ trap 'SIGCLD', 'IGNORE'
16
+ trap 'INT' do
17
+ puts
18
+ EventMachine.stop
19
+ exit
20
+ end
21
+ rescue ArgumentError
22
+ end
23
+
24
+ EventMachine.run { connect(options) }
25
+ end
26
+
27
+ def self.connect(options)
28
+ EventMachine.connect(options[:server_host], options[:server_port], self, options)
29
+ end
30
+
31
+ def initialize(options)
32
+ @options = options
33
+
34
+ @reconnect = options[:hosts].any?
35
+ end
36
+
37
+ def send_options
38
+ send_object(:options, @options)
39
+ end
40
+
41
+ def post_init
42
+ @connections = {}
43
+
44
+ if @options[:tls]
45
+ @@logger.info('Request TLS')
46
+ send_object(:start_tls)
47
+ else
48
+ send_options
49
+ end
50
+ end
51
+
52
+ def ssl_handshake_completed
53
+ send_options
54
+ end
55
+
56
+ def unbind
57
+ if @reconnect
58
+ puts "Connection has been terminated. Trying to reconnect..."
59
+ EventMachine.add_timer 5 do
60
+ self.class.connect(@options)
61
+ end
62
+ else
63
+ EventMachine.stop_event_loop
64
+ puts "Connection has been terminated"
65
+ end
66
+ end
67
+
68
+ def receive_unknown(object)
69
+ @@logger.info("Received #{object.inspect}")
70
+ end
71
+
72
+ def receive_start_tls
73
+ @@logger.info('Start TLS')
74
+ start_tls
75
+ end
76
+
77
+ def receive_message(message)
78
+ puts message
79
+ end
80
+
81
+ def receive_halt
82
+ @reconnect = false
83
+ EventMachine.stop_event_loop
84
+ end
85
+
86
+ def receive_connection(id)
87
+ @@logger.info('New connection')
88
+ connection = EventMachine.connect('127.0.0.1', @options[:local_port], ClientProxy)
89
+ connection.on_data do |data|
90
+ send_object(:stream, id, data)
91
+ end
92
+ connection.on_unbind do
93
+ @@logger.info('Connection closed')
94
+ @connections.delete(id)
95
+ send_object(:close, id)
96
+ end
97
+ @connections[id] = connection
98
+ end
99
+
100
+ def receive_stream(id, data)
101
+ @connections[id].send_data(data) if @connections[id]
102
+ end
103
+
104
+ def receive_close(id)
105
+ connection = @connections.delete(id)
106
+ connection.close_connection_after_writing if connection
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,25 @@
1
+ require 'eventmachine'
2
+
3
+ module ProxyLocal
4
+ class ClientProxy < EventMachine::Connection
5
+ def post_init
6
+ @callbacks = {}
7
+ end
8
+
9
+ def receive_data(data)
10
+ @callbacks[:on_data].call(data) if @callbacks.has_key?(:on_data)
11
+ end
12
+
13
+ def unbind
14
+ @callbacks[:on_unbind].call if @callbacks.has_key?(:on_unbind)
15
+ end
16
+
17
+ def on_data(&block)
18
+ @callbacks[:on_data] = block
19
+ end
20
+
21
+ def on_unbind(&block)
22
+ @callbacks[:on_unbind] = block
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,74 @@
1
+ require 'rubygems'
2
+ require 'optparse'
3
+ require 'yaml'
4
+
5
+ proxylocal_path = File.expand_path('../../lib', __FILE__)
6
+ $:.unshift(proxylocal_path) if File.directory?(proxylocal_path) && !$:.include?(proxylocal_path)
7
+
8
+ require 'proxylocal'
9
+
10
+ rc_path = File.expand_path(File.join('~', '.proxylocalrc'))
11
+ rc = YAML.load_file(rc_path) rescue {}
12
+
13
+ options = rc.dup
14
+
15
+ begin
16
+ cmd_args = OptionParser.new do |opts|
17
+ opts.banner = 'Usage: proxylocal [options] [PORT]'
18
+
19
+ opts.on('--token TOKEN', 'Save token to .proxylocalrc') do |token|
20
+ rc[:token] = token
21
+ File.open(rc_path, 'w') { |f| f.write(YAML.dump(rc)) }
22
+ File.chmod(0600, rc_path)
23
+ puts 'Token was successfully saved'
24
+ exit
25
+ end
26
+
27
+ opts.on('--host HOST', 'Bind to host') do |host|
28
+ options[:hosts] ||= []
29
+ options[:hosts] << host
30
+ end
31
+
32
+ opts.on('--[no-]tls', 'Use TLS') do |tls|
33
+ options[:tls] = tls
34
+ end
35
+
36
+ opts.on('-s', '--server SERVER', 'Specify proxylocal server') do |s|
37
+ options[:server_host], options[:server_port] = s.split(':')
38
+ end
39
+
40
+ opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
41
+ options[:verbose] = v
42
+ end
43
+
44
+ opts.on_tail("--version", "Show version") do
45
+ puts ProxyLocal::VERSION
46
+ exit
47
+ end
48
+
49
+ opts.on_tail('-h', '--help', 'Show this message') do
50
+ puts opts
51
+ exit
52
+ end
53
+ end.parse!
54
+ rescue OptionParser::MissingArgument => e
55
+ puts e
56
+ exit
57
+ rescue OptionParser::InvalidOption => e
58
+ puts e
59
+ exit
60
+ end
61
+
62
+ options[:local_port] = cmd_args[0]
63
+ options[:version] = ProxyLocal::VERSION
64
+ options.delete_if { |k, v| v.nil? }
65
+
66
+ default_options = {
67
+ :server_host => 'proxylocal.com',
68
+ :server_port => '8282',
69
+ :local_port => '80',
70
+ :tls => false,
71
+ :verbose => false
72
+ }
73
+
74
+ ProxyLocal::Client.run(default_options.merge(options))
@@ -0,0 +1,35 @@
1
+ require 'bert'
2
+ require 'eventmachine'
3
+
4
+ module ProxyLocal
5
+ module Protocol
6
+ include EventMachine::Protocols::ObjectProtocol
7
+
8
+ def serializer
9
+ Serializer
10
+ end
11
+
12
+ def receive_object(object)
13
+ object = [object] unless object.is_a?(Array)
14
+
15
+ command, *args = object
16
+
17
+ method_name = "receive_#{command}"
18
+
19
+ if respond_to?(method_name) && [-1, args.size].include?(method(method_name).arity)
20
+ send(method_name, *args)
21
+ else
22
+ receive_unknown(object)
23
+ end
24
+ end
25
+
26
+ def send_object(*args)
27
+ object = if args.size > 1
28
+ BERT::Tuple[*args]
29
+ else
30
+ args.first
31
+ end
32
+ super(object)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ require 'bert'
2
+
3
+ module ProxyLocal
4
+ module Serializer
5
+ def self.dump(object)
6
+ BERT.encode(object)
7
+ end
8
+
9
+ def self.load(data)
10
+ BERT.decode(data)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module ProxyLocal
2
+ VERSION = '0.3.0'
3
+ end
data/lib/proxylocal.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'proxylocal/version'
2
+
3
+ module ProxyLocal
4
+ autoload :Client, 'proxylocal/client'
5
+ autoload :Protocol, 'proxylocal/protocol'
6
+ autoload :ClientProxy, 'proxylocal/client_proxy'
7
+ autoload :Serializer, 'proxylocal/serializer'
8
+ autoload :Command, 'proxylocal/command'
9
+
10
+ class << self
11
+ def logger
12
+ @@logger ||= nil
13
+ end
14
+
15
+ def logger=(logger)
16
+ @@logger = logger
17
+ end
18
+ end
19
+ end
data/proxylocal.gemspec CHANGED
@@ -1,39 +1,22 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.unshift(File.expand_path('../lib', __FILE__))
3
+ require 'proxylocal/version'
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = %q{proxylocal}
5
- s.version = "0.2.4"
6
+ s.name = 'proxylocal'
7
+ s.version = ProxyLocal::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Sergey Nartimov']
10
+ s.email = ['just.lest@gmail.com']
11
+ s.homepage = 'http://proxylocal.com/'
12
+ s.summary = 'Proxy your local web-server and make it publicly available over the internet'
6
13
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Just Lest"]
9
- s.cert_chain = ["/Users/lest/.gem/gem-public_cert.pem"]
10
- s.date = %q{2010-12-17}
11
- s.default_executable = %q{proxylocal}
12
- s.description = %q{Proxy your local web-server and make it publicly available over the internet}
13
- s.email = %q{just.lest@gmail.com}
14
- s.executables = ["proxylocal"]
15
- s.extra_rdoc_files = ["bin/proxylocal", "lib/client.rb"]
16
- s.files = ["Manifest", "Rakefile", "bin/proxylocal", "lib/client.rb", "proxylocal.gemspec"]
17
- s.homepage = %q{http://proxylocal.com/}
18
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Proxylocal"]
19
- s.require_paths = ["lib"]
20
- s.rubygems_version = %q{1.3.7}
21
- s.signing_key = %q{/Users/lest/.gem/gem-private_key.pem}
22
- s.summary = %q{Proxy your local web-server and make it publicly available over the internet}
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
23
17
 
24
- if s.respond_to? :specification_version then
25
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
- s.specification_version = 3
27
-
28
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
29
- s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
30
- s.add_runtime_dependency(%q<bert>, [">= 1.1.2"])
31
- else
32
- s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
33
- s.add_dependency(%q<bert>, [">= 1.1.2"])
34
- end
35
- else
36
- s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
37
- s.add_dependency(%q<bert>, [">= 1.1.2"])
38
- end
18
+ s.add_dependency('eventmachine', '>= 0.12.10')
19
+ s.add_dependency('bert', '>= 1.1.2')
20
+ s.add_development_dependency('bundler', '>= 1.0.10')
21
+ s.add_development_dependency('rake', '>= 0.8.7')
39
22
  end
metadata CHANGED
@@ -1,128 +1,111 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: proxylocal
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - Just Lest
7
+ authors:
8
+ - Sergey Nartimov
14
9
  autorequire:
15
10
  bindir: bin
16
- cert_chain:
17
- - |
18
- -----BEGIN CERTIFICATE-----
19
- MIIDNDCCAhygAwIBAgIBADANBgkqhkiG9w0BAQUFADBAMRIwEAYDVQQDDAlqdXN0
20
- Lmxlc3QxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
21
- bTAeFw0xMDExMjMxMzQ1MDZaFw0xMTExMjMxMzQ1MDZaMEAxEjAQBgNVBAMMCWp1
22
- c3QubGVzdDEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYD
23
- Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuUnh7oCJRr+SzsE5
24
- opUADHIBpMkn6T3DMuT7sV0wZAUfvbTYwH7291A/3nzdyVbWGhNKnAYx3ZB8fWcz
25
- duG+Dyu4KqQ+n6wY3q/PEtC7fP4/ork+Np90WzM3TCqHP2ykRkbqmvr1TI7pJd9Q
26
- Cl51BCd+JaqzExBeR7D4BBC/LuJB6NOW4vpO0niVRFc3dbnrptMCfJEzjvXHmigo
27
- 4jd6ASiqVK1TIm6mNdu0uG22JY0jnEwIdrZzHpH85b53vcMavDWQyn4LzNO84mOi
28
- 55XolYTHdKYFZBa0OHbxnCG/dlsX99mkcw0F2DchTJ6hFePQqFsj3g41U2Fsncu4
29
- 1e2dRwIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU
30
- ALBQFVVADB4PNXk2/VUVTJhVdEwwDQYJKoZIhvcNAQEFBQADggEBAA9v7xhcTa/h
31
- SpxEjknr/TbTkN4rE9bSWUG5s2/8ifEoAxCwqIV59rGTb/gYsV/dvw/6MRsq6Rjc
32
- s4Tj1SWD282ENFpzrGrAAbPUyBO7bEo6qDWHGJFAvxlVLHIO66m6Tst439Pj11k6
33
- q6fAPwYVlbRJ9xi6JJXC27T+Rx1p+GA9MccLxia+0plPIe5HsJhpcUGmCOffqpKy
34
- qmCDeoQiExRVlE2cEMQ3FyMJYLb1EPCso9+kCvFr2M+zQ67tyGH8dkdoOtLcDKD2
35
- HRZT7lH/kWyJY9jLD8pBtbuDpLWcWRLK8kvAaGmQZEVyGAoPfl/6oORBzxoBaKG3
36
- 9HkV98wF6vQ=
37
- -----END CERTIFICATE-----
38
-
39
- date: 2010-12-17 00:00:00 +02:00
40
- default_executable:
41
- dependencies:
42
- - !ruby/object:Gem::Dependency
11
+ cert_chain: []
12
+ date: 2012-01-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
43
15
  name: eventmachine
44
- prerelease: false
45
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2153350440 !ruby/object:Gem::Requirement
46
17
  none: false
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- hash: 59
51
- segments:
52
- - 0
53
- - 12
54
- - 10
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
55
21
  version: 0.12.10
56
22
  type: :runtime
57
- version_requirements: *id001
58
- - !ruby/object:Gem::Dependency
59
- name: bert
60
23
  prerelease: false
61
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2153350440
25
+ - !ruby/object:Gem::Dependency
26
+ name: bert
27
+ requirement: &2153349440 !ruby/object:Gem::Requirement
62
28
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- hash: 23
67
- segments:
68
- - 1
69
- - 1
70
- - 2
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
71
32
  version: 1.1.2
72
33
  type: :runtime
73
- version_requirements: *id002
74
- description: Proxy your local web-server and make it publicly available over the internet
75
- email: just.lest@gmail.com
76
- executables:
34
+ prerelease: false
35
+ version_requirements: *2153349440
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &2153348020 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.10
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2153348020
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &2153360060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.7
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *2153360060
58
+ description:
59
+ email:
60
+ - just.lest@gmail.com
61
+ executables:
77
62
  - proxylocal
78
63
  extensions: []
79
-
80
- extra_rdoc_files:
81
- - bin/proxylocal
82
- - lib/client.rb
83
- files:
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - Gemfile.lock
84
69
  - Manifest
70
+ - README.md
85
71
  - Rakefile
86
72
  - bin/proxylocal
87
- - lib/client.rb
73
+ - lib/proxylocal.rb
74
+ - lib/proxylocal/client.rb
75
+ - lib/proxylocal/client_proxy.rb
76
+ - lib/proxylocal/command.rb
77
+ - lib/proxylocal/protocol.rb
78
+ - lib/proxylocal/serializer.rb
79
+ - lib/proxylocal/version.rb
88
80
  - proxylocal.gemspec
89
- has_rdoc: true
90
81
  homepage: http://proxylocal.com/
91
82
  licenses: []
92
-
93
83
  post_install_message:
94
- rdoc_options:
95
- - --line-numbers
96
- - --inline-source
97
- - --title
98
- - Proxylocal
99
- require_paths:
84
+ rdoc_options: []
85
+ require_paths:
100
86
  - lib
101
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
102
88
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
108
94
  - 0
109
- version: "0"
110
- required_rubygems_version: !ruby/object:Gem::Requirement
95
+ hash: -3646587277700671729
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
97
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 11
116
- segments:
117
- - 1
118
- - 2
119
- version: "1.2"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ segments:
103
+ - 0
104
+ hash: -3646587277700671729
120
105
  requirements: []
121
-
122
106
  rubyforge_project:
123
- rubygems_version: 1.3.7
107
+ rubygems_version: 1.8.11
124
108
  signing_key:
125
109
  specification_version: 3
126
110
  summary: Proxy your local web-server and make it publicly available over the internet
127
111
  test_files: []
128
-
data/lib/client.rb DELETED
@@ -1,136 +0,0 @@
1
- require 'logger'
2
- require 'rubygems'
3
- require 'eventmachine'
4
- require 'bert'
5
-
6
- module ProxyLocal
7
- VERSION = '0.2.4'
8
-
9
- module Serializer
10
- def self.dump(object)
11
- BERT.encode(object)
12
- end
13
-
14
- def self.load(data)
15
- BERT.decode(data)
16
- end
17
- end
18
-
19
- class Client < EventMachine::Connection
20
- include EventMachine::Protocols::ObjectProtocol
21
-
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
-
28
- begin
29
- trap "SIGCLD", "IGNORE"
30
- trap "INT" do
31
- puts
32
- EventMachine.run
33
- exit
34
- end
35
- rescue ArgumentError
36
- end
37
-
38
- EventMachine.run do
39
- EventMachine.connect(options[:server_host], options[:server_port], self) do |c|
40
- c.instance_eval do
41
- @options = options
42
- if @options[:tls]
43
- @@logger.info("Request TLS")
44
- send_object(:start_tls)
45
- else
46
- send_options
47
- end
48
- end
49
- end
50
- end
51
- end
52
-
53
- def serializer
54
- Serializer
55
- end
56
-
57
- def send_options
58
- send_object(BERT::Tuple[:options, @options])
59
- end
60
-
61
- def post_init
62
- @connections = {}
63
- end
64
-
65
- def ssl_handshake_completed
66
- send_options
67
- end
68
-
69
- def first_line(data)
70
- data.split(/\r?\n/, 2).first
71
- end
72
-
73
- def receive_object(message)
74
- message = [message] unless message.is_a?(Array)
75
-
76
- case message[0]
77
- when :start_tls
78
- @@logger.info("Start TLS")
79
- start_tls
80
- when :message
81
- puts message[1]
82
- when :halt
83
- EventMachine.stop_event_loop
84
- when :connection
85
- _, id = message
86
- @@logger.info("New connection")
87
- connection = EventMachine.connect('127.0.0.1', @options[:local_port], ClientProxy)
88
- connection.on_data do |data|
89
- send_object(BERT::Tuple[:stream, id, data])
90
- end
91
- connection.on_unbind do
92
- @@logger.info("Connection closed")
93
- @connections.delete(id)
94
- send_object(BERT::Tuple[:close, id])
95
- end
96
- @connections[id] = connection
97
- when :stream
98
- _, id, data = message
99
- @connections[id].send_data(data) if @connections[id]
100
- when :close
101
- _, id = message
102
- connection = @connections.delete(id)
103
- connection.close_connection_after_writing if connection
104
- else
105
- @@logger.info("Received #{message.inspect}")
106
- end
107
- end
108
-
109
- def unbind
110
- EventMachine.stop_event_loop
111
- puts "A connection has been terminated"
112
- end
113
- end
114
-
115
- class ClientProxy < EventMachine::Connection
116
- def post_init
117
- @callbacks = {}
118
- end
119
-
120
- def receive_data(data)
121
- @callbacks[:on_data].call(data) if @callbacks.has_key?(:on_data)
122
- end
123
-
124
- def unbind
125
- @callbacks[:on_unbind].call if @callbacks.has_key?(:on_unbind)
126
- end
127
-
128
- def on_data(&block)
129
- @callbacks[:on_data] = block
130
- end
131
-
132
- def on_unbind(&block)
133
- @callbacks[:on_unbind] = block
134
- end
135
- end
136
- end
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- �H��Qp0�v���K*��;�fo�r���?�w���$��݁N�6�KHZ�I�9�ܼ?Fҙj�-M[K� Vn����TѪ��ߧ18uM����%Υ!#����t�f���À�v����EM���,�z�.տ��.�{�IrK�=[��9�T"������,:#�p�Kbη�f؜���
metadata.gz.sig DELETED
Binary file