proxylocal 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Manifest +5 -0
  2. data/Rakefile +12 -0
  3. data/bin/proxylocal +26 -0
  4. data/lib/client.rb +72 -0
  5. data/proxylocal.gemspec +35 -0
  6. metadata +91 -0
data/Manifest ADDED
@@ -0,0 +1,5 @@
1
+ Manifest
2
+ Rakefile
3
+ bin/proxylocal
4
+ lib/client.rb
5
+ proxylocal.gemspec
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('proxylocal', '0.0.2') do |p|
6
+ p.description = 'http://proxylocal.com/'
7
+ p.url = 'http://proxylocal.com/'
8
+ p.author = 'Just Lest'
9
+ p.email = 'just.lest@gmail.com'
10
+ p.runtime_dependencies = ['eventmachine >=0.12.10']
11
+ p.development_dependencies = []
12
+ end
data/bin/proxylocal ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require File.expand_path('client', File.join(File.dirname(__FILE__), '..', 'lib'))
5
+
6
+ server_host = nil
7
+ server_port = nil
8
+
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(':')
13
+ end
14
+ o.on('-h', "--help", "show this help") { puts o; exit }
15
+ end
16
+
17
+ args = options.parse!
18
+
19
+ server_host ||= 'proxylocal.com'
20
+ server_port ||= '8282'
21
+
22
+ local_port = args[0] || 80
23
+
24
+ ProxyLocal::Client.run(:server_host => server_host,
25
+ :server_port => server_port,
26
+ :local_port => local_port)
data/lib/client.rb ADDED
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+ require 'eventmachine'
3
+
4
+ module ProxyLocal
5
+
6
+ class Client < EventMachine::Connection
7
+
8
+ include EventMachine::Protocols::ObjectProtocol
9
+
10
+ def self.run(options = {})
11
+ trap "SIGCLD", "IGNORE"
12
+ trap "INT" do
13
+ puts
14
+ EventMachine.run
15
+ exit
16
+ end
17
+
18
+ EventMachine.run do
19
+ EventMachine::connect(options[:server_host], options[:server_port], self) do |c|
20
+ c.instance_eval do
21
+ @options = options
22
+ send_object(:options => @options)
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ def receive_object(obj)
29
+ if obj.has_key?(:message)
30
+ puts obj[:message]
31
+ end
32
+
33
+ EventMachine.stop_event_loop if obj[:halt]
34
+
35
+ if obj.has_key?(:uuid)
36
+ EventMachine::connect('127.0.0.1', @options[:local_port], ClientProxy) do |connection|
37
+ connection.callback do |data|
38
+ send_object(:uuid => obj[:uuid], :response => data)
39
+ end
40
+ connection.send_data(obj[:request])
41
+ end
42
+ end
43
+ end
44
+
45
+ def unbind
46
+ EventMachine.stop_event_loop
47
+ puts "A connection has been terminated"
48
+ end
49
+
50
+ end
51
+
52
+ class ClientProxy < EventMachine::Connection
53
+
54
+ def post_init
55
+ @data = ''
56
+ end
57
+
58
+ def receive_data(data)
59
+ @data << data
60
+ end
61
+
62
+ def unbind
63
+ @callback.call(@data) if @callback
64
+ end
65
+
66
+ def callback(&block)
67
+ @callback = block
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{proxylocal}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Just Lest"]
9
+ s.date = %q{2010-10-26}
10
+ s.default_executable = %q{proxylocal}
11
+ s.description = %q{http://proxylocal.com/}
12
+ s.email = %q{just.lest@gmail.com}
13
+ s.executables = ["proxylocal"]
14
+ s.extra_rdoc_files = ["bin/proxylocal", "lib/client.rb"]
15
+ s.files = ["Manifest", "Rakefile", "bin/proxylocal", "lib/client.rb", "proxylocal.gemspec"]
16
+ s.homepage = %q{http://proxylocal.com/}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Proxylocal"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{proxylocal}
20
+ s.rubygems_version = %q{1.3.7}
21
+ s.summary = %q{http://proxylocal.com/}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
29
+ else
30
+ s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<eventmachine>, [">= 0.12.10"])
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proxylocal
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Just Lest
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-26 00:00:00 +03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: eventmachine
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 12
33
+ - 10
34
+ version: 0.12.10
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: http://proxylocal.com/
38
+ email: just.lest@gmail.com
39
+ executables:
40
+ - proxylocal
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - bin/proxylocal
45
+ - lib/client.rb
46
+ files:
47
+ - Manifest
48
+ - Rakefile
49
+ - bin/proxylocal
50
+ - lib/client.rb
51
+ - proxylocal.gemspec
52
+ has_rdoc: true
53
+ homepage: http://proxylocal.com/
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options:
58
+ - --line-numbers
59
+ - --inline-source
60
+ - --title
61
+ - Proxylocal
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 11
79
+ segments:
80
+ - 1
81
+ - 2
82
+ version: "1.2"
83
+ requirements: []
84
+
85
+ rubyforge_project: proxylocal
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: http://proxylocal.com/
90
+ test_files: []
91
+