em-wssh 0.3.0 → 0.4.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: 5594f5ba9ee7af40c50e16a6495afe8567c1ae8e
4
- data.tar.gz: 5d311ce91fcd6c547070ce9dfd805c44dbc8b204
3
+ metadata.gz: 60abc80ee170a46ba2b1b2e70166eeb4a5f5718e
4
+ data.tar.gz: be2a072ef48e86d235c1a88781f9855f482ee416
5
5
  SHA512:
6
- metadata.gz: bf4bc293ae6fda9f53b3183566fb9a644146e9e70022cbd11273ea76274a8fbda896a367ff0219b3a6ac8e338ef49e23474b1703965ee427897776c4aa2f3fd1
7
- data.tar.gz: cfd455480307b436d080bd803ac188dd90c615b7b270b04cfdfbe83bc07f6b8f8d501aeff8c45503fc7aa946bfe17a89d441f8ce19eb6227f7c31b6346c87acb
6
+ metadata.gz: eb11f5728fc982b93a87fb395e98eed141e45cac2993e37e0d080c250fbed1c84f211b47fe7bdcd2f267a0397c22c5d5ffc29cf0c4f12591882ab265a26d5888
7
+ data.tar.gz: d69126590e4af9e4337769032a31e8dc461ad019b9c84ef04ed3fcb3e8b1bdd514edb9f2aebc839fb8a837c3d5f796459254624a6dfb0474644df81eb09df40f
data/em-wssh.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["ukoloff@gmail.com"]
11
11
  spec.description = 'Proxy SSH connection through Websocket (nginx)'
12
12
  spec.summary = ''
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/ukoloff/em-wssh"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -2,13 +2,17 @@ require_relative '../wssh'
2
2
 
3
3
  module EventMachine::Wssh
4
4
  module Client
5
+
6
+ Title='Connect to WSSH server'
7
+
5
8
  Need=%w(faye/websocket)
6
9
 
7
10
  def self.help
11
+ require_relative 'exe'
8
12
  puts <<-EOT
9
13
  WSSH client
10
14
 
11
- Usage: ruby #{File.basename __FILE__} ws[s]://host[:port]/uri
15
+ Usage: #{Exe.biname} ws[s]://host[:port]/uri
12
16
  EOT
13
17
  exit 1
14
18
  end
@@ -4,6 +4,8 @@ module EventMachine::Wssh
4
4
  module Connect
5
5
  extend Service
6
6
 
7
+ Title='HTTP Connect proxy to WSSH server'
8
+
7
9
  Need=%w(faye/websocket)
8
10
 
9
11
  @options={
@@ -16,10 +18,11 @@ module Connect
16
18
  }
17
19
 
18
20
  def self.help
21
+ require_relative 'exe'
19
22
  puts <<-EOF
20
23
  Simple HTTP CONNECT proxy to WSSH daemon
21
24
 
22
- Usage: ruby #{File.basename __FILE__} [options...] ws[s]://host[:port]/uri
25
+ Usage: #{Exe.biname} [options...] ws[s]://host[:port]/uri
23
26
  EOF
24
27
  helptions
25
28
  end
@@ -157,7 +160,8 @@ Usage: ruby #{File.basename __FILE__} [options...] ws[s]://host[:port]/uri
157
160
  end
158
161
 
159
162
  def self.listen!
160
- EM.start_server options[:host], options[:port], Http
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]
161
165
  end
162
166
  end
163
167
  end
data/lib/em/wssh/exe.rb CHANGED
@@ -2,18 +2,35 @@ require_relative '../wssh'
2
2
 
3
3
  module EventMachine::Wssh
4
4
  module Exe
5
- def self.do!
6
- cmd = ARGV.shift
7
- help unless /\A\w+\Z/.match cmd
5
+ def self.command? cmd
6
+ return unless /\A\w+\Z/.match cmd
8
7
  cmd=cmd.downcase
9
8
  begin
10
9
  require_relative cmd
11
10
  rescue LoadError
12
- help
11
+ return
13
12
  end
14
- m=Module.nesting[1].const_get cmd.sub(/^./){|s|s.upcase}
15
- help unless Module===m and m.respond_to? :go!
16
- m.go!
13
+ m=Module.nesting[1].const_get cmd.sub(/^./){|s|s.upcase} rescue nil
14
+ return unless Module===m and m.respond_to? :go!
15
+ m
16
+ end
17
+
18
+ def self.commands
19
+ m=Module.nesting[1]
20
+ Hash[
21
+ m.constants
22
+ .map{|n|m.const_get n}
23
+ .grep(Module)
24
+ .select{|m| m.respond_to? :go!}
25
+ .map{|m| [m.name.split(/\W+/).last.downcase, m]}
26
+ .sort_by{|x| x[0]}
27
+ ]
28
+ end
29
+
30
+ def self.do!
31
+ mod = command? ARGV.shift
32
+ help unless mod
33
+ mod.go!
17
34
  end
18
35
 
19
36
  def self.help
@@ -21,5 +38,9 @@ module Exe
21
38
  Help.go!
22
39
  exit
23
40
  end
41
+
42
+ def self.biname
43
+ "wssh "+File.basename(caller_locations.first.path).sub(/[.][^.]*\Z/, '')
44
+ end
24
45
  end
25
46
  end
data/lib/em/wssh/help.rb CHANGED
@@ -1,19 +1,45 @@
1
- require_relative 'all'
1
+ require_relative 'exe'
2
2
 
3
3
  module EventMachine::Wssh
4
4
  module Help
5
+
6
+ Title='Show this help'
7
+
5
8
  def self.go!
6
- m=Module.nesting[1]
7
- list=m.constants
8
- .map{|n|m.const_get n}
9
- .grep(Module)
10
- .select{|m| m.respond_to? :go!}
11
- .map{|m| m.name.split(/\W+/).last.downcase}
12
- .sort
9
+ if mod = Exe.command?(ARGV.shift)
10
+ command mod
11
+ else
12
+ top
13
+ end
14
+ end
15
+
16
+ def self.top
17
+ require_relative 'all'
18
+
19
+ puts <<-EOT
20
+ WSSH suite v#{VERSION}
21
+
22
+ Usage: wssh command [parameters...]
23
+
24
+ Available commands:
25
+
26
+ EOT
27
+ Exe.commands.each{|cmd, mod| puts " wssh #{cmd}\t#{mod::Title rescue nil}"}
28
+ end
29
+
30
+ def self.command mod
31
+ if mod.respond_to? :help
32
+ mod.help
33
+ else
34
+ puts mod::Title
35
+ end
36
+ end
37
+
38
+ def self.help
13
39
  puts <<-EOT
14
- WSSH v#{VERSION}
40
+ Shows help for WSSH suite or individual commands
15
41
 
16
- Available commands: #{list*', '}
42
+ Usage: #{Exe.biname} [command]
17
43
  EOT
18
44
  end
19
45
  end
@@ -4,6 +4,8 @@ module EventMachine::Wssh
4
4
  module Server
5
5
  extend Service
6
6
 
7
+ Title='WSSH daemon redirects Websocket to sshd'
8
+
7
9
  Need=%w(yaml em-websocket)
8
10
 
9
11
  @options={
@@ -16,10 +18,11 @@ module Server
16
18
  }
17
19
 
18
20
  def self.help
21
+ require_relative 'exe'
19
22
  puts <<-EOF
20
23
  Proxy ssh connection through websocket
21
24
 
22
- Usage: ruby #{File.basename __FILE__} [options...]
25
+ Usage: #{Exe.biname} [options...]
23
26
  EOF
24
27
  helptions
25
28
  end
@@ -68,8 +71,7 @@ EOF
68
71
 
69
72
  @count=self.class.count
70
73
 
71
- port, ip=Socket.unpack_sockaddr_in ws.get_peername
72
- log "Connect from", ip
74
+ log "Connect from", Socket.unpack_sockaddr_in(ws.get_peername)[1]
73
75
 
74
76
  ws.onopen{|handshake| onopen handshake}
75
77
  ws.onbinary{|msg| ondata msg}
@@ -6,7 +6,7 @@ module Service
6
6
 
7
7
  def log *msg
8
8
  msg.unshift "[#{Time.now}]"
9
- puts msg*' '
9
+ (options[:logger]||=STDOUT).puts msg*' '
10
10
  end
11
11
 
12
12
  def helptions
@@ -0,0 +1,12 @@
1
+ require_relative '../wssh'
2
+
3
+ module EventMachine::Wssh
4
+ module Version
5
+
6
+ Title = 'Show WSSH version'
7
+
8
+ def self.go!
9
+ puts VERSION
10
+ end
11
+ end
12
+ end
data/lib/em/wssh.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  module Wssh
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
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.3.0
4
+ version: 0.4.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-03 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket
@@ -91,8 +91,9 @@ files:
91
91
  - lib/em/wssh/help.rb
92
92
  - lib/em/wssh/server.rb
93
93
  - lib/em/wssh/service.rb
94
+ - lib/em/wssh/version.rb
94
95
  - nginx/ssh
95
- homepage: ''
96
+ homepage: https://github.com/ukoloff/em-wssh
96
97
  licenses:
97
98
  - MIT
98
99
  metadata: {}