em-wssh 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 60abc80ee170a46ba2b1b2e70166eeb4a5f5718e
4
- data.tar.gz: be2a072ef48e86d235c1a88781f9855f482ee416
3
+ metadata.gz: 1db6dba2f0f3dff81eed7b595806938e0bd8f064
4
+ data.tar.gz: 473cd9aaa813c0f21a5f178e03a90cf52acde42c
5
5
  SHA512:
6
- metadata.gz: eb11f5728fc982b93a87fb395e98eed141e45cac2993e37e0d080c250fbed1c84f211b47fe7bdcd2f267a0397c22c5d5ffc29cf0c4f12591882ab265a26d5888
7
- data.tar.gz: d69126590e4af9e4337769032a31e8dc461ad019b9c84ef04ed3fcb3e8b1bdd514edb9f2aebc839fb8a837c3d5f796459254624a6dfb0474644df81eb09df40f
6
+ metadata.gz: c01b25a7cf340ddb7f9ad0aadc5feaee60afc1f6acbb1660122eb3724011d8e2062abf02db60144052b23be6113584cd848cd02338806108894058820d78542b
7
+ data.tar.gz: 52d414591dfaf37c7c65c3a4610974f0ad491bb8c9d7b1d0bdfbfec3da832328b2189230638f0f72676476f5e4b2262c03908a2e4456806c19cfb359494fd20f
data/README.md CHANGED
@@ -11,24 +11,128 @@ Ruby version of ssh thru websocket proxying.
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'em-wssh' if Gem.win_platform?
14
+ gem 'em-wssh' if Gem.win_platform?
15
15
  ```
16
16
 
17
17
  And then execute:
18
18
 
19
19
  ```sh
20
- $ bundle
20
+ $ bundle
21
21
  ```
22
22
 
23
23
  Or install it yourself as:
24
24
 
25
25
  ```sh
26
- $ gem install em-wssh
26
+ $ gem install em-wssh
27
27
  ```
28
28
 
29
29
  ## Usage
30
30
 
31
- ...
31
+ Single command `wssh` is exported. Sometimes it should be `bundle exec wssh`.
32
+
33
+ ### WSSH Server
34
+
35
+ To run WSSH server say `wssh server`.
36
+
37
+ ### nginx
38
+
39
+ Directly exposing WSSH server to Internet is not a good idea.
40
+ One should better install nginx (with TLS) and [force it to redirect](nginx/ssh)
41
+ WSSH connections to WSSH server.
42
+
43
+ ### WSSH Client
44
+
45
+ Client is started with `wssh client URI`, eg `wssh client ws://localhost:4567`.
46
+
47
+ Running client from terminal is not very useful. It should be called by ssh client:
48
+
49
+ ```sh
50
+ ssh -o ProxyCommand='wssh client wss://server.host.com/ssh/%h' sshd.local
51
+ ```
52
+
53
+ By default WSSH server has 60 seconds timeout. To prevent idle connection to drop,
54
+ one can use `ServerAliveInterval` parameter:
55
+
56
+ ```sh
57
+ ssh -o ProxyCommand='wssh client wss://server.host.com/ssh/%h' -o ServerAliveInterval=50 sshd.local
58
+ ```
59
+
60
+ ### WSSH Proxy
61
+
62
+ WSSH client is in fact unusable on Windows.
63
+ It can be impractical when we create a lot of SSH connections (eg with Capistrano mass deploy).
64
+
65
+ In these cases run `wssh connect URI`, it will listen to TCP port (3122 by default) and will work
66
+ as normal HTTP proxy, so proxy-capable clients (PuTTY/Plink and Net::SSH) can use it to connect to SSH servers.
67
+
68
+ ```ruby
69
+ #!/usr/bin/env ruby
70
+
71
+ require 'net/ssh'
72
+ require 'net/ssh/proxy/http'
73
+
74
+ x=Net::SSH.start 'sshd.local', 'root',
75
+ proxy: Net::SSH::Proxy::HTTP.new('localhost', 3122)
76
+
77
+ puts x.exec! 'hostname'
78
+ ```
79
+
80
+ ## API
81
+
82
+ WSSH server, client or proxy can be start programmaticaly:
83
+
84
+ ```ruby
85
+ require 'em/wssh/server'
86
+
87
+ s=EventMachine::Wssh::Server
88
+ s.options.merge! base: '.'
89
+ s.loop!
90
+ ```
91
+
92
+ ```ruby
93
+ require 'em/wssh/client'
94
+
95
+ s=EventMachine::Wssh::Client
96
+ s.options[:uri]='wss://server.host.com/ssh/sshd.local'
97
+ s.loop!
98
+ ```
99
+
100
+ ```ruby
101
+ require 'em/wssh/connect'
102
+
103
+ s=EventMachine::Wssh::Connect
104
+ s.options.merge! base: '.', all: true, uri: 'wss://server.host.com/ssh/sshd.local'
105
+ s.loop!
106
+ ```
107
+
108
+ Some options are not accesible to `wssh` command and can be used only programmaticaly.
109
+
110
+ Eg, EventMachine::Wssh::Connect has option `onlisten` that allows listening to random port:
111
+
112
+ ```ruby
113
+ #!/usr/bin/env ruby
114
+
115
+ require 'net/ssh'
116
+ require 'net/ssh/proxy/http'
117
+ require 'em/wssh/connect'
118
+
119
+ q=Queue.new
120
+ c=EventMachine::Wssh::Connect
121
+ c.options.merge!(
122
+ port: 0,
123
+ uri: 'wss://server.host.com/ssh',
124
+ onlisten: Proc.new{|port| q.push port},
125
+ )
126
+
127
+ Thread.new{c.loop!}
128
+
129
+ puts "Port=#{port=q.pop}"
130
+
131
+ x=Net::SSH.start 'sshd.local', 'root',
132
+ proxy: Net::SSH::Proxy::HTTP.new('localhost', port)
133
+
134
+ puts x.exec! 'hostname'
135
+ ```
32
136
 
33
137
  ## Data flow
34
138
 
@@ -40,8 +144,8 @@ Normal SSH session is very simple:
40
144
 
41
145
  WSSH session is:
42
146
 
43
- * SSH Client with -o ProxyCommand='ruby client.rb WSSH-URI'
44
- * client.rb listening to its stdin
147
+ * SSH Client with -o ProxyCommand='wssh client WSSH-URI'
148
+ * WSSH client listening to its stdin
45
149
  * Websocket (HTTP/HTTPS) connection to nginx
46
150
  * nginx [configured](nginx/ssh) to redirect connection to WSSH server
47
151
  * Another Websocket connection from nginx to WSSH server
@@ -53,9 +157,9 @@ And nginx stage can be omited in development/testing scenarios.
53
157
 
54
158
  In some scenarios this path can be even longer:
55
159
 
56
- * SSH Client, capable to connect via HTTP proxy (eg PuTTY/PLink)
160
+ * SSH Client, capable to connect via HTTP proxy (eg PuTTY/PLink or Net::SSH)
57
161
  * TCP connection to local proxy
58
- * connect.rb listening to dedicated port (3122 by default)
162
+ * `wssh connect` listening to dedicated port (3122 by default)
59
163
  * Websocket (HTTP/HTTPS) connection to nginx
60
164
  * nginx [configured](nginx/ssh) to redirect connection to WSSH server
61
165
  * Another Websocket connection from nginx to WSSH server
@@ -74,7 +178,7 @@ Windows installation of EventMachine has a few bugs:
74
178
  So, this package is in fact almost unusable on MS Windows.
75
179
 
76
180
  The only exception: if you connect to Non-TLS WSSH server
77
- (ws: or http:, not wss: or https:), you **can** start connect.rb
181
+ (ws: or http:, not wss: or https:), you **can** start `wssh connect`
78
182
  and then use SSH client, capable to connect via HTTP proxy.
79
183
 
80
184
  To connect to TLS WSSH server, you should use Node.js version.
data/lib/em/wssh.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  module Wssh
3
- VERSION = "0.4.0"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
@@ -161,7 +161,7 @@ Usage: #{Exe.biname} [options...] ws[s]://host[:port]/uri
161
161
 
162
162
  def self.listen!
163
163
  conn=EM.start_server options[:host], options[:port], Http
164
- options[:onport].call Socket.unpack_sockaddr_in(EM.get_sockname conn)[0] if options[:onport]
164
+ options[:onlisten].call Socket.unpack_sockaddr_in(EM.get_sockname conn)[0] if options[:onlisten]
165
165
  end
166
166
  end
167
167
  end
@@ -6,7 +6,7 @@ module Service
6
6
 
7
7
  def log *msg
8
8
  msg.unshift "[#{Time.now}]"
9
- (options[:logger]||=STDOUT).puts msg*' '
9
+ puts msg*' '
10
10
  end
11
11
 
12
12
  def helptions
@@ -78,7 +78,6 @@ EOF
78
78
  log "Going on in background..."
79
79
 
80
80
  f = File.open mkdir(:log), 'a'
81
- f.sync=true
82
81
 
83
82
  STDIN.reopen '/dev/null'
84
83
  STDOUT.reopen f
@@ -101,6 +100,7 @@ EOF
101
100
 
102
101
  def loop!
103
102
  self::Need.each{|f| require f}
103
+ STDOUT.sync=true
104
104
  EM.run{ listen! }
105
105
  end
106
106
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-wssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stas Ukolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket