daps 0.0.1.a.3 → 0.0.1.a.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/daps/application.rb +1 -3
- data/lib/daps/client.rb +2 -1
- data/lib/daps/server.rb +18 -14
- data/lib/daps/version.rb +1 -1
- metadata +3 -3
data/lib/daps/application.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
class Daps::Application < Thor
|
2
2
|
|
3
3
|
desc "server DIR [TOKEN]", "Start the daps server"
|
4
|
-
method_option :port, :type => :numeric, :default =>
|
4
|
+
method_option :port, :type => :numeric, :default => 0
|
5
5
|
def server(dir, token=nil)
|
6
|
-
token ||= Digest::SHA1.hexdigest([Time.now, rand(1<<100)].join('--'))
|
7
|
-
puts "Token: #{token}"
|
8
6
|
server = Daps::Server.new(dir, token, options.port)
|
9
7
|
server.start!
|
10
8
|
end
|
data/lib/daps/client.rb
CHANGED
@@ -6,8 +6,9 @@ class Daps::Client
|
|
6
6
|
|
7
7
|
def start!
|
8
8
|
system(%{
|
9
|
-
wget -O /tmp/daps-#{@token}-client.tar.gz http://#{@remote}:#{@port}/#{@token} &&
|
9
|
+
wget -T 300 -O /tmp/daps-#{@token}-client.tar.gz http://#{@remote}:#{@port}/#{@token} &&
|
10
10
|
tar --directory=#{@dir} -xzf /tmp/daps-#{@token}-client.tar.gz ;
|
11
|
+
wget -q -O /dev/null http://#{@remote}:#{@port}/#{@token}/close ;
|
11
12
|
rm -f /tmp/daps-#{@token}-client.tar.gz
|
12
13
|
})
|
13
14
|
end
|
data/lib/daps/server.rb
CHANGED
@@ -2,11 +2,17 @@ class Daps::Server
|
|
2
2
|
|
3
3
|
def initialize(dir, token, port)
|
4
4
|
@dir, @token, @port = File.expand_path(dir), token, port.to_i
|
5
|
-
Dir.chdir(@dir)
|
6
5
|
end
|
7
6
|
|
8
7
|
def start!
|
9
|
-
|
8
|
+
Dir.chdir(@dir)
|
9
|
+
|
10
|
+
@port = rand(5000) + 5000 if @port == 0
|
11
|
+
@token ||= Digest::SHA1.hexdigest([Time.now, rand(1<<100)].join('--'))
|
12
|
+
|
13
|
+
puts "URI: daps://#{`hostname`.strip}:#{@port}/#{@token}"
|
14
|
+
|
15
|
+
Rack::Handler::Thin.run(self, :Port => @port) { |s| s.silent = true }
|
10
16
|
end
|
11
17
|
|
12
18
|
def call(env)
|
@@ -17,6 +23,16 @@ class Daps::Server
|
|
17
23
|
|
18
24
|
class Http < Sinatra::Base
|
19
25
|
|
26
|
+
get '/:token/close' do
|
27
|
+
token = params[:token]
|
28
|
+
if @env['daps.token'] != token
|
29
|
+
halt(403, {'Content-type' => 'text/plain'}, 'back off!')
|
30
|
+
end
|
31
|
+
|
32
|
+
File.unlink("/tmp/daps-#{token}-server.tar.gz")
|
33
|
+
EM.stop_event_loop
|
34
|
+
end
|
35
|
+
|
20
36
|
get '/:token' do
|
21
37
|
token = params[:token]
|
22
38
|
if @env['daps.token'] != token
|
@@ -35,16 +51,4 @@ class Daps::Server
|
|
35
51
|
|
36
52
|
end
|
37
53
|
|
38
|
-
end
|
39
|
-
|
40
|
-
class Sinatra::Helpers::StaticFile < ::File
|
41
|
-
alias_method :other_each, :each
|
42
|
-
def each(&block)
|
43
|
-
other_each(&block)
|
44
|
-
ensure
|
45
|
-
EM.next_tick do
|
46
|
-
File.unlink(self.path)
|
47
|
-
EM.stop_event_loop
|
48
|
-
end
|
49
|
-
end
|
50
54
|
end
|
data/lib/daps/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: daps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 117
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 1
|
10
10
|
- a
|
11
|
-
-
|
12
|
-
version: 0.0.1.a.
|
11
|
+
- 4
|
12
|
+
version: 0.0.1.a.4
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Simon Menke
|