devproxy 0.1.0
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/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +1 -0
- data/bin/devproxy +10 -0
- data/devproxy.gemspec +22 -0
- data/lib/devproxy/cli.rb +55 -0
- data/lib/devproxy/connection.rb +80 -0
- data/lib/devproxy/net-ssh-patch.rb +23 -0
- data/lib/devproxy/options.rb +20 -0
- data/lib/devproxy/version.rb +3 -0
- data/lib/devproxy.rb +6 -0
- data/readme.md +54 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adam Bozanich
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/devproxy
ADDED
data/devproxy.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'devproxy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "devproxy"
|
8
|
+
gem.version = Devproxy::VERSION
|
9
|
+
gem.authors = ["Adam Bozanich"]
|
10
|
+
gem.email = ["adam.boz@gmail.com"]
|
11
|
+
gem.summary = %q{https://devproxy.io client gem}
|
12
|
+
gem.description = %q{https://devproxy.io client gem}
|
13
|
+
gem.homepage = "https://github.com/boz/devproxy"
|
14
|
+
|
15
|
+
gem.add_dependency "net-ssh", "~> 2.6.7"
|
16
|
+
gem.add_development_dependency "rspec"
|
17
|
+
|
18
|
+
gem.files = `git ls-files`.split($/)
|
19
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
20
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
21
|
+
gem.require_paths = ["lib"]
|
22
|
+
end
|
data/lib/devproxy/cli.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'devproxy/connection'
|
2
|
+
require 'devproxy/options'
|
3
|
+
require 'optparse'
|
4
|
+
module Devproxy
|
5
|
+
class CLI < Devproxy::Connection
|
6
|
+
def self.parse(argv)
|
7
|
+
options = Devproxy::Options::default
|
8
|
+
opts = OptionParser.new
|
9
|
+
opts.banner = "Usage: devproxy user [proxy] [options...]"
|
10
|
+
|
11
|
+
opts.separator ""
|
12
|
+
opts.separator " user: \tDevproxy username."
|
13
|
+
opts.separator " proxy:\tThe name of the proxy you want to connect to (without the domain)."
|
14
|
+
opts.separator " \tDefaults to `user`."
|
15
|
+
opts.separator " \texample: 'foo' for tunneling 'foo.devproxy.io'"
|
16
|
+
|
17
|
+
opts.separator ""
|
18
|
+
|
19
|
+
opts.on "-p PORT", "--port PORT", Integer,
|
20
|
+
"Local port accepting connections (default: #{options.port})" do |x|
|
21
|
+
options.port = x
|
22
|
+
end
|
23
|
+
|
24
|
+
if ENV['DEVPROXY_DEVELOPMENT']
|
25
|
+
opts.on "--host HOST", "remote hostname." do |x|
|
26
|
+
options.host = x
|
27
|
+
end
|
28
|
+
opts.on "--remote-port PORT",Integer,"remote SSH port" do |x|
|
29
|
+
options.remote_port = x
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on_tail "-h", "--help", "show this message" do
|
34
|
+
puts opts
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on_tail "--version", "Show version" do
|
39
|
+
puts Devproxy::VERSION.join('.')
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
opts.parse!(argv)
|
43
|
+
options.user = argv[0]
|
44
|
+
options.proxy = argv[1] || argv[0]
|
45
|
+
unless options.valid?
|
46
|
+
puts opts
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
options
|
50
|
+
end
|
51
|
+
def self.create(argv)
|
52
|
+
super(parse(argv))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'devproxy/net-ssh-patch'
|
3
|
+
|
4
|
+
module Devproxy
|
5
|
+
class Connection
|
6
|
+
class Error < StandardError; end
|
7
|
+
class Error::Authentication < Error ; end
|
8
|
+
|
9
|
+
attr_reader :options, :ssh
|
10
|
+
|
11
|
+
MAX_DOTS = 60
|
12
|
+
|
13
|
+
def initialize options, ssh
|
14
|
+
@options, @ssh, @halt = options, ssh, false
|
15
|
+
reset_dots!
|
16
|
+
end
|
17
|
+
|
18
|
+
def loop!
|
19
|
+
@ssh.loop { !halt? }
|
20
|
+
rescue Errno::ECONNREFUSED
|
21
|
+
on_stderr "CONNECTION REFUSED. Is there anything listening on port #{options.port}?"
|
22
|
+
retry
|
23
|
+
end
|
24
|
+
def stop!
|
25
|
+
@halt = true
|
26
|
+
end
|
27
|
+
def halt?
|
28
|
+
@halt
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_stdout data
|
32
|
+
$stdout.write data
|
33
|
+
if (@dotno += 1) % MAX_DOTS == 0
|
34
|
+
$stdout.write "\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_stderr data
|
39
|
+
$stderr.puts "\nError: #{data}"
|
40
|
+
reset_dots!
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_close
|
44
|
+
stop!
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
def reset_dots!
|
49
|
+
@dotno = 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.loop!(options)
|
53
|
+
create(options).loop!
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.create(options)
|
57
|
+
ssh = open_ssh(options)
|
58
|
+
connection = new(options,ssh)
|
59
|
+
ssh.forward.remote(options.port,"localhost",0,'0.0.0.0')
|
60
|
+
channel = ssh.exec(options.proxy) do |ch,stream,data|
|
61
|
+
if stream == :stdout
|
62
|
+
connection.on_stdout(data)
|
63
|
+
else
|
64
|
+
connection.on_stderr(data)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
channel.on_close do
|
68
|
+
connection.on_close
|
69
|
+
end
|
70
|
+
connection
|
71
|
+
rescue Net::SSH::AuthenticationFailed
|
72
|
+
raise Error::Authentication, "Authentication Failed: Invalid username or SSH key"
|
73
|
+
end
|
74
|
+
def self.open_ssh(options)
|
75
|
+
Net::SSH.start(options.host, options.username,{
|
76
|
+
:port => options.remote_port,
|
77
|
+
})
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "net/ssh"
|
2
|
+
|
3
|
+
#
|
4
|
+
# Read remote port from channel.
|
5
|
+
#
|
6
|
+
# https://github.com/net-ssh/net-ssh/pull/99
|
7
|
+
#
|
8
|
+
|
9
|
+
class Net::SSH::Service::Forward
|
10
|
+
def remote(port, host, remote_port, remote_host="127.0.0.1",&blk)
|
11
|
+
session.send_global_request("tcpip-forward", :string, remote_host, :long, remote_port) do |success, response|
|
12
|
+
if success
|
13
|
+
remote_port = response.read_long if remote_port.zero?
|
14
|
+
debug { "remote forward from remote #{remote_host}:#{remote_port} to #{host}:#{port} established" }
|
15
|
+
blk.call(remote_port) if blk
|
16
|
+
@remote_forwarded_ports[[remote_port, remote_host]] = Remote.new(host, port)
|
17
|
+
else
|
18
|
+
error { "remote forwarding request failed" }
|
19
|
+
raise Net::SSH::Exception, "remote forwarding request failed"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Devproxy
|
2
|
+
class Options < Struct.new(:user, :proxy, :port, :host, :remote_port)
|
3
|
+
def username
|
4
|
+
"devproxy-#{user}"
|
5
|
+
end
|
6
|
+
def valid?
|
7
|
+
!( user.nil? || user.empty? ||
|
8
|
+
proxy.nil? || proxy.empty? ||
|
9
|
+
port.nil? || remote_port.nil? ||
|
10
|
+
host.nil? || host.empty? )
|
11
|
+
end
|
12
|
+
def self.default
|
13
|
+
default = new
|
14
|
+
default.host = "ssh.devproxy.io"
|
15
|
+
default.remote_port = 2222
|
16
|
+
default.port = 3000
|
17
|
+
default
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/devproxy.rb
ADDED
data/readme.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Devproxy
|
2
|
+
|
3
|
+
[devproxy.io](https://devproxy.io) client used for tunneling
|
4
|
+
connections from a public domain (`https://example.devproxy.io`) to your
|
5
|
+
local machine.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'devproxy'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install devproxy --source https://github.com/boz/devproxy.git
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Create an account on [devproxy.io](https://devproxy.io) and upload
|
24
|
+
your ssh public key.
|
25
|
+
|
26
|
+
To tunnel connections for `example.devproxy.io` to port 3000 on your local machine, run:
|
27
|
+
|
28
|
+
$ devproxy example
|
29
|
+
|
30
|
+
You can specify the local port with `-p`:
|
31
|
+
|
32
|
+
$ devproxy example -p 3000
|
33
|
+
|
34
|
+
If the host that you want to tunnel is not the same as your [devproxy.io](https://devproxy.io)
|
35
|
+
username, specify the hostname as the second argument:
|
36
|
+
|
37
|
+
$ devproxy example test
|
38
|
+
|
39
|
+
### Rails
|
40
|
+
|
41
|
+
Start up your tunnel in a separate terminal or use a [foreman](https://github.com/ddollar/foreman) Procfile:
|
42
|
+
|
43
|
+
```
|
44
|
+
devproxy: bundle exec devproxy example -p 3000
|
45
|
+
web: bundle exec rails s -p 3000
|
46
|
+
```
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: devproxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Bozanich
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: net-ssh
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.6.7
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.6.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: https://devproxy.io client gem
|
47
|
+
email:
|
48
|
+
- adam.boz@gmail.com
|
49
|
+
executables:
|
50
|
+
- devproxy
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- Rakefile
|
58
|
+
- bin/devproxy
|
59
|
+
- devproxy.gemspec
|
60
|
+
- lib/devproxy.rb
|
61
|
+
- lib/devproxy/cli.rb
|
62
|
+
- lib/devproxy/connection.rb
|
63
|
+
- lib/devproxy/net-ssh-patch.rb
|
64
|
+
- lib/devproxy/options.rb
|
65
|
+
- lib/devproxy/version.rb
|
66
|
+
- readme.md
|
67
|
+
homepage: https://github.com/boz/devproxy
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.25
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: https://devproxy.io client gem
|
91
|
+
test_files: []
|