emptyd 0.0.6 → 0.0.7

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: 54c1986a43737d5677bd3be8f54c70297d115ba5
4
- data.tar.gz: 703dc34c62c07005a9e3e4d8e491b0d1e1d2d8a1
3
+ metadata.gz: 3a6c2238de6a8ddfad2f05d18c568fc1d333c458
4
+ data.tar.gz: 521686c0e7a3c8242870ec331d86eab857bcb62d
5
5
  SHA512:
6
- metadata.gz: 157e1c2f2674399157fa02ab38fdc6d584df852241b85b0b024636345bd5301275d4f8ab61bc07acaf24294a7cdccff205841fa6fc69454be2e1eb193c73d33d
7
- data.tar.gz: c89ef07273792b1b5594501f0d29032dbbf100c19e092c2ce5d5c1b0584226b2049e17edad5223271760dbd2cb0f187d88cc4f41343311aa91c6282e0e355ee8
6
+ metadata.gz: 966fdfbe3f9ed0e4e6a3b2628d15c2ef7c6556620f9fa66bebf5d686d3e25b12a30d41f63e5601d4da916473b6ab87980e46edb68094941800fe80d83b9f4fcf
7
+ data.tar.gz: eb6db97c46fdcce7be4b09ebda7fdfa03fd05d26a979391382213c2fb975bf836f053e02b9bbce2d7adf97e539d73aec0038e165753cf9a8853a2f9670a3356b
data/README.md CHANGED
@@ -1,20 +1,17 @@
1
1
  # Emptyd
2
2
 
3
- TODO: Write a gem description
3
+ Server counterpart of [emptyc](https://github.com/kmeaw/emptyc), which
4
+ keeps track of SSH connections, pushes I/O over the wire, providing
5
+ an HTTP-interface for emptyc.
4
6
 
5
7
  ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ $ sudo gem install emptyd
8
10
 
9
- gem 'emptyd'
11
+ For Mac OS X Mavericks users: if you have problems compiling native
12
+ extensions for eventmachine-le, try setting up ARCHFLAGS:
10
13
 
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install emptyd
14
+ $ sudo env ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install emptyd
18
15
 
19
16
  ## Usage
20
17
 
data/bin/emptyd CHANGED
@@ -9,12 +9,14 @@ end
9
9
 
10
10
  require "emptyd"
11
11
  require 'evma_httpserver'
12
+ require 'getoptlong'
12
13
 
13
14
  class MyHttpServer < EM::Connection
14
15
  include EM::HttpServer
15
16
 
16
- def initialize(logger)
17
- @logger = logger
17
+ def initialize(options)
18
+ @logger = options[:logger]
19
+ @cookie = options[:cookie]
18
20
  end
19
21
 
20
22
  def post_init
@@ -27,11 +29,21 @@ class MyHttpServer < EM::Connection
27
29
  port, ip = Socket.unpack_sockaddr_in(get_peername)
28
30
  @logger.info "#{ip}:#{port} #{@http_request_method} #{@http_path_info} #{@http_post_content.inspect}"
29
31
 
32
+ headers = Hash[@http_headers.split("\x00").map{|x| x.split(":",2)}.map{|x,y| [x.strip.downcase,y.lstrip]}]
33
+
30
34
  response = EM::DelegatedHttpResponse.new(self)
31
35
  response.status = 200
32
36
  response.content_type 'application/json'
33
37
  response.content = JSON.dump({ :okay => true })
34
38
 
39
+ if @cookie and headers['authorization'] != "Cookie: #{@cookie}"
40
+ @logger.warn "Bad cookie: #{headers['authorization']}"
41
+ response.status = 403
42
+ response.content = JSON.dump({ :cookie => :bad })
43
+ response.send_response
44
+ return
45
+ end
46
+
35
47
  begin
36
48
  case @http_path_info
37
49
  when %r{/ping}
@@ -102,10 +114,44 @@ end
102
114
  # XXX: We need a shared environment for Session and Connection
103
115
  $PASSWORD = CONFIG[:password]
104
116
 
117
+ opts = GetoptLong.new(
118
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
119
+ [ '--cookie', '-C', GetoptLong::REQUIRED_ARGUMENT ],
120
+ )
121
+
122
+ logger = Logger.new(STDOUT)
123
+ options = { :logger => logger }
124
+ options[:cookie] = CONFIG[:cookie]
125
+ options[:port] = CONFIG[:port]
126
+
127
+ opts.each do |opt, arg|
128
+ case opt
129
+ when '--help'
130
+ print <<-EOF
131
+ #{$0} [OPTION]
132
+
133
+ -h, --help:
134
+ show help
135
+
136
+ -C x, --cookie x:
137
+ protect server with a cookie value
138
+
139
+ -p x, --port x:
140
+ set port number
141
+
142
+ EOF
143
+ exit
144
+ when '--cookie'
145
+ options[:cookie] = arg
146
+ when '--port'
147
+ options[:port] = arg.to_i
148
+ end
149
+ end
150
+
105
151
  EM.run do
106
152
  $0 = "emptyd"
107
- logger = Logger.new(STDOUT)
108
- EM.start_server CONFIG[:server], CONFIG[:server_port], MyHttpServer, logger
109
- logger.info "Server started on #{CONFIG[:server]}, port #{CONFIG[:server_port]}."
153
+
154
+ EM.start_server CONFIG[:server], options[:port], MyHttpServer, options
155
+ logger.info "Server started on #{CONFIG[:server]}, port #{options[:port]}."
110
156
  end
111
157
 
@@ -1,3 +1,3 @@
1
1
  module Emptyd
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/emptyd.rb CHANGED
@@ -371,15 +371,14 @@ module Emptyd
371
371
  end
372
372
 
373
373
  def terminate key
374
- chan = @running[key]
375
- conn = @connections[key]
374
+ return if @terminated[key]
375
+ chan = @running.delete key
376
+ conn = @connections.delete key
376
377
  chan.close if chan.respond_to? :close
377
378
  if conn
378
379
  callback conn, :close, "user"
379
380
  conn.unbind self
380
381
  end
381
- @running.delete key
382
- @connections.delete key
383
382
  @terminated[key] = true
384
383
  end
385
384
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emptyd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - kmeaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler