devproxy 0.2.0 → 0.3.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/lib/devproxy/connection.rb +11 -46
- data/lib/devproxy/session.rb +52 -0
- data/lib/devproxy/version.rb +1 -1
- data/readme.md +9 -5
- metadata +5 -4
data/lib/devproxy/connection.rb
CHANGED
@@ -1,32 +1,25 @@
|
|
1
|
-
require '
|
2
|
-
require 'devproxy/net-ssh-patch'
|
1
|
+
require 'devproxy/session'
|
3
2
|
|
4
3
|
module Devproxy
|
5
|
-
class Connection
|
6
|
-
|
7
|
-
class Error::Authentication < Error ; end
|
8
|
-
HEARTBEAT = "HEARTBEAT"
|
4
|
+
class Connection < Struct.new(:options)
|
5
|
+
MAX_DOTS = 60
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
MAX_DOTS = 60
|
13
|
-
|
14
|
-
def initialize options, ssh
|
15
|
-
@options, @ssh, @halt = options, ssh, false
|
7
|
+
def initialize options
|
8
|
+
super
|
16
9
|
reset_dots!
|
17
10
|
end
|
18
11
|
|
19
12
|
def loop!
|
20
|
-
@
|
13
|
+
@session.shutdown! if @session
|
14
|
+
@session = Session.create(options,self)
|
15
|
+
@session.loop!
|
21
16
|
rescue Errno::ECONNREFUSED
|
22
17
|
on_stderr "CONNECTION REFUSED. Is there anything listening on port #{options.port}?"
|
23
18
|
retry
|
24
19
|
end
|
20
|
+
|
25
21
|
def stop!
|
26
|
-
@
|
27
|
-
end
|
28
|
-
def halt?
|
29
|
-
@halt
|
22
|
+
@session.stop! if @session
|
30
23
|
end
|
31
24
|
|
32
25
|
def on_connected
|
@@ -61,39 +54,11 @@ module Devproxy
|
|
61
54
|
def reset_dots!
|
62
55
|
@dotno = 0
|
63
56
|
end
|
64
|
-
|
65
57
|
def self.loop!(options)
|
66
58
|
create(options).loop!
|
67
59
|
end
|
68
|
-
|
69
60
|
def self.create(options)
|
70
|
-
|
71
|
-
connection = new(options,ssh)
|
72
|
-
ssh.forward.remote(options.port,options.listen,0,'0.0.0.0')
|
73
|
-
channel = ssh.exec(options.proxy) do |ch,stream,data|
|
74
|
-
if stream == :stdout
|
75
|
-
if data.start_with?(HEARTBEAT)
|
76
|
-
connection.on_heartbeat(data)
|
77
|
-
else
|
78
|
-
connection.on_stdout(data)
|
79
|
-
end
|
80
|
-
else
|
81
|
-
connection.on_stderr(data)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
channel.on_close do
|
85
|
-
connection.on_close
|
86
|
-
end
|
87
|
-
connection.on_connected
|
88
|
-
connection
|
89
|
-
rescue Net::SSH::AuthenticationFailed
|
90
|
-
raise Error::Authentication, "Authentication Failed: Invalid username or SSH key"
|
91
|
-
end
|
92
|
-
def self.open_ssh(options)
|
93
|
-
Net::SSH.start(options.host, options.username,{
|
94
|
-
:port => options.remote_port,
|
95
|
-
:user_known_hosts_file => "/dev/null",
|
96
|
-
})
|
61
|
+
new(options)
|
97
62
|
end
|
98
63
|
end
|
99
64
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'devproxy/net-ssh-patch'
|
3
|
+
|
4
|
+
module Devproxy
|
5
|
+
class Session < Struct.new(:ssh)
|
6
|
+
class Error < StandardError; end
|
7
|
+
class Error::Authentication < Error ; end
|
8
|
+
|
9
|
+
HEARTBEAT = "HEARTBEAT"
|
10
|
+
|
11
|
+
def shutdown!
|
12
|
+
ssh.shutdown!
|
13
|
+
end
|
14
|
+
|
15
|
+
def loop!
|
16
|
+
ssh.loop { !@halt }
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop!
|
20
|
+
@halt = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create(options,connection)
|
24
|
+
ssh = open_ssh(options)
|
25
|
+
ssh.forward.remote(options.port,options.listen,0,'0.0.0.0')
|
26
|
+
channel = ssh.exec(options.proxy) do |ch,stream,data|
|
27
|
+
if stream == :stdout
|
28
|
+
if data.start_with?(HEARTBEAT)
|
29
|
+
connection.on_heartbeat(data)
|
30
|
+
else
|
31
|
+
connection.on_stdout(data)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
connection.on_stderr(data)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
channel.on_close do
|
38
|
+
connection.on_close
|
39
|
+
end
|
40
|
+
connection.on_connected
|
41
|
+
new(ssh)
|
42
|
+
rescue Net::SSH::AuthenticationFailed
|
43
|
+
raise Error::Authentication, "Authentication Failed: Invalid username or SSH key"
|
44
|
+
end
|
45
|
+
def self.open_ssh(options)
|
46
|
+
Net::SSH.start(options.host, options.username,{
|
47
|
+
:port => options.remote_port,
|
48
|
+
:user_known_hosts_file => "/dev/null",
|
49
|
+
})
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/devproxy/version.rb
CHANGED
data/readme.md
CHANGED
@@ -16,25 +16,29 @@ And then execute:
|
|
16
16
|
|
17
17
|
Or install it yourself as:
|
18
18
|
|
19
|
-
$ gem install devproxy
|
19
|
+
$ gem install devproxy -v '~> 0.2.0'
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
Create an account on [devproxy.io](https://devproxy.io) and upload
|
24
24
|
your ssh public key.
|
25
25
|
|
26
|
-
To tunnel connections for `
|
26
|
+
To tunnel connections for `username.devproxy.io` to port 3000 on your local machine, run:
|
27
27
|
|
28
|
-
$ devproxy
|
28
|
+
$ devproxy username
|
29
29
|
|
30
30
|
You can specify the local port with `-p`:
|
31
31
|
|
32
|
-
$ devproxy
|
32
|
+
$ devproxy username -p 5000
|
33
33
|
|
34
34
|
If the host that you want to tunnel is not the same as your [devproxy.io](https://devproxy.io)
|
35
35
|
username, specify the hostname as the second argument:
|
36
36
|
|
37
|
-
$ devproxy
|
37
|
+
$ devproxy username proxyname
|
38
|
+
|
39
|
+
`devproxy` comes with a server for testing. enable it with the `--test-server` flag:
|
40
|
+
|
41
|
+
$ devproxy username proxyname -p 5000 --test-server
|
38
42
|
|
39
43
|
### Rails
|
40
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devproxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/devproxy/connection.rb
|
66
66
|
- lib/devproxy/net-ssh-patch.rb
|
67
67
|
- lib/devproxy/options.rb
|
68
|
+
- lib/devproxy/session.rb
|
68
69
|
- lib/devproxy/version.rb
|
69
70
|
- readme.md
|
70
71
|
- spec/cli_spec.rb
|
@@ -85,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
86
|
version: '0'
|
86
87
|
segments:
|
87
88
|
- 0
|
88
|
-
hash:
|
89
|
+
hash: 1889482144132428415
|
89
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
91
|
none: false
|
91
92
|
requirements:
|
@@ -94,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
version: '0'
|
95
96
|
segments:
|
96
97
|
- 0
|
97
|
-
hash:
|
98
|
+
hash: 1889482144132428415
|
98
99
|
requirements: []
|
99
100
|
rubyforge_project:
|
100
101
|
rubygems_version: 1.8.25
|