boxlet 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +0 -0
- data/README.md +5 -6
- data/Rakefile +0 -0
- data/boxlet.gemspec +0 -0
- data/config.yml +0 -0
- data/lib/boxlet.rb +33 -11
- data/lib/boxlet/app.rb +7 -5
- data/lib/boxlet/app/controller.rb +2 -3
- data/lib/boxlet/app/models.rb +1 -2
- data/lib/boxlet/app/router.rb +1 -3
- data/lib/boxlet/config.rb +1 -4
- data/lib/boxlet/db.rb +1 -3
- data/lib/boxlet/log.rb +0 -0
- data/lib/boxlet/runner.rb +1 -2
- data/lib/boxlet/util.rb +1 -5
- data/lib/boxlet/version.rb +1 -1
- data/lib/handlers/thin.rb +1 -1
- data/lib/rack/boxlet_url_builder.rb +6 -6
- data/lib/rack/boxlet_url_map.rb +0 -2
- data/lib/rack/file_upload.rb +77 -77
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 956d2071a94833442316b9e97b35eaaf40284976
|
4
|
+
data.tar.gz: a6997a8a7258f156543cddc80eff0b6527d740b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2162347f5df7546e58b33372afe319fca9360d46551a8bcdc1e549f47961be04fc207c0b4404f899d04e316415f7749e81d1f0902db5d939989c276f646b55f
|
7
|
+
data.tar.gz: a550939df3ccbd8588f7a9a62af995f36aa3d6a9fc941b2066a7c9491d03a9665ac81e58a41c598f2137011eadc52b0e522df553603baeb806c93b5455b9aeb0
|
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ From the mobile iOS app, you can specify any server:port where the Boxlet server
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
Run `boxlet` from any folder to stat the server with default settings.
|
25
|
+
Run `boxlet run` from any folder to stat the server with default settings.
|
26
26
|
|
27
27
|
See below for config and parameters.
|
28
28
|
|
@@ -104,8 +104,7 @@ Many config options are available as command-line parameters
|
|
104
104
|
|
105
105
|
## Contributing
|
106
106
|
|
107
|
-
1. Fork
|
108
|
-
2. Create
|
109
|
-
3.
|
110
|
-
4.
|
111
|
-
5. Create new Pull Request
|
107
|
+
1. Fork this repo
|
108
|
+
2. Create an [issue/feature request](https://github.com/arktisklada/boxlet/issues)
|
109
|
+
3. Create, commit, and push your feature branch (my-new-feature)
|
110
|
+
4. Create new Pull Request
|
data/Rakefile
CHANGED
File without changes
|
data/boxlet.gemspec
CHANGED
File without changes
|
data/config.yml
CHANGED
File without changes
|
data/lib/boxlet.rb
CHANGED
@@ -6,12 +6,9 @@ require 'boxlet/log'
|
|
6
6
|
require 'boxlet/config'
|
7
7
|
require 'boxlet/runner'
|
8
8
|
|
9
|
-
|
10
9
|
APP_ROOT = Dir.pwd
|
11
10
|
|
12
|
-
|
13
11
|
module Boxlet
|
14
|
-
|
15
12
|
extend self
|
16
13
|
extend Boxlet::Config
|
17
14
|
|
@@ -22,13 +19,24 @@ module Boxlet
|
|
22
19
|
@log = Boxlet::Log.new(@config[:log_file], (debug? ? Logger::DEBUG : Logger::INFO))
|
23
20
|
@app = Boxlet::App.new
|
24
21
|
|
22
|
+
command = command.to_s.to_sym
|
25
23
|
case command
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
24
|
+
when :run
|
25
|
+
Boxlet.log(:debug, @config)
|
26
|
+
@runner = Boxlet::Runner.new
|
27
|
+
@runner.start(@app.bind, &blk)
|
28
|
+
when :stop
|
29
|
+
if @config[:daemonize] == true
|
30
|
+
pid = File.read(@config[:pid_file]).to_i
|
31
|
+
puts "Killing #{pid}..."
|
32
|
+
Process.kill(Signal.list["TERM"], pid)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
if App::PUBLIC_COMMANDS.keys.include?(command)
|
31
36
|
@app.send(command, argv)
|
37
|
+
else
|
38
|
+
print_menu
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
42
|
@app
|
@@ -39,22 +47,36 @@ module Boxlet
|
|
39
47
|
@app
|
40
48
|
end
|
41
49
|
|
42
|
-
|
43
50
|
def debug?
|
44
51
|
@config[:debug] == true
|
45
52
|
end
|
53
|
+
|
46
54
|
def config
|
47
55
|
@config
|
48
56
|
end
|
57
|
+
|
49
58
|
def params
|
50
59
|
@params
|
51
60
|
end
|
61
|
+
|
52
62
|
def log(level, message)
|
53
63
|
@log.write(level, message)
|
54
64
|
end
|
55
65
|
|
56
|
-
|
66
|
+
private
|
57
67
|
|
68
|
+
def print_menu
|
69
|
+
puts "Usage: boxlet command [args]"
|
70
|
+
puts
|
71
|
+
puts "Available commands are as follows:"
|
72
|
+
commands_with_descriptions = App::PUBLIC_COMMANDS.merge run: "Run the Boxlet server"
|
73
|
+
commands = commands_with_descriptions.keys
|
74
|
+
max_chars = commands.sort { |a, b| a.length <=> b.length }.last.length
|
75
|
+
commands.sort.each do |command|
|
76
|
+
puts " #{command.to_s.ljust(max_chars)} #{commands_with_descriptions[command]}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
58
80
|
|
59
81
|
# Configure our temporary folder
|
60
82
|
class Dir
|
@@ -72,4 +94,4 @@ class Dir
|
|
72
94
|
File.expand_path(tmp)
|
73
95
|
end
|
74
96
|
end
|
75
|
-
end
|
97
|
+
end
|
data/lib/boxlet/app.rb
CHANGED
@@ -10,9 +10,14 @@ require 'boxlet/app/models'
|
|
10
10
|
|
11
11
|
module Boxlet
|
12
12
|
class App
|
13
|
-
|
14
13
|
include Sys
|
15
14
|
|
15
|
+
PUBLIC_COMMANDS = {
|
16
|
+
add_user: "Add a new user to the database",
|
17
|
+
change_password: "Change a user's password",
|
18
|
+
setup: "Initialize a directory as a Boxlet app (create folders, check space, etc.)."
|
19
|
+
}.freeze
|
20
|
+
|
16
21
|
def self.routes
|
17
22
|
routes = {
|
18
23
|
# ["/", :get] => :index,
|
@@ -47,7 +52,6 @@ module Boxlet
|
|
47
52
|
end.to_app
|
48
53
|
end
|
49
54
|
|
50
|
-
|
51
55
|
def setup(args)
|
52
56
|
begin
|
53
57
|
Boxlet.log(:debug, Boxlet.config)
|
@@ -88,7 +92,6 @@ module Boxlet
|
|
88
92
|
end
|
89
93
|
end
|
90
94
|
|
91
|
-
|
92
95
|
def add_user(args)
|
93
96
|
unless username = args['-u']
|
94
97
|
raise 'You must specify a username with -u'
|
@@ -135,6 +138,5 @@ module Boxlet
|
|
135
138
|
rescue Exception => e
|
136
139
|
Boxlet.log(:fatal, "ERROR: #{e}")
|
137
140
|
end
|
138
|
-
|
139
141
|
end
|
140
|
-
end
|
142
|
+
end
|
@@ -36,9 +36,7 @@ module Boxlet
|
|
36
36
|
{format: @format, content: action_response}
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
39
|
# actions
|
41
|
-
|
42
40
|
def index
|
43
41
|
'<html><body><form action="/push_files" method="post" enctype="multipart/form-data">UUID:<input type="text" name="uuid"><br><input type="file" name="file"><input type="submit"></form>'
|
44
42
|
end
|
@@ -103,6 +101,7 @@ module Boxlet
|
|
103
101
|
filename: new_filename,
|
104
102
|
size: file.size,
|
105
103
|
local_date: file.mtime.to_i,
|
104
|
+
orientation: @params[:orientation],
|
106
105
|
thumbnail: new_thumb_filename,
|
107
106
|
asset_path: @params[:asset_path],
|
108
107
|
asset_date: @params[:asset_date],
|
@@ -225,4 +224,4 @@ module Boxlet
|
|
225
224
|
end
|
226
225
|
end
|
227
226
|
end
|
228
|
-
end
|
227
|
+
end
|
data/lib/boxlet/app/models.rb
CHANGED
data/lib/boxlet/app/router.rb
CHANGED
data/lib/boxlet/config.rb
CHANGED
@@ -64,7 +64,6 @@ module Boxlet
|
|
64
64
|
}
|
65
65
|
}
|
66
66
|
|
67
|
-
|
68
67
|
def populate_params!(argv, path_to_config)
|
69
68
|
@raw_config = load_config_file(path_to_config)
|
70
69
|
@raw_params = parse_arguments(argv)
|
@@ -73,7 +72,6 @@ module Boxlet
|
|
73
72
|
@config[:debug] = @raw_config[:debug] || @raw_params[:debug]
|
74
73
|
end
|
75
74
|
|
76
|
-
|
77
75
|
def symbolize_keys(hash)
|
78
76
|
hash.inject({}){|result, (key, value)|
|
79
77
|
new_key = key.instance_of?(String) ? key.to_sym : key
|
@@ -84,7 +82,6 @@ module Boxlet
|
|
84
82
|
}
|
85
83
|
end
|
86
84
|
|
87
|
-
|
88
85
|
private
|
89
86
|
|
90
87
|
def parse_arguments(argv)
|
@@ -121,4 +118,4 @@ module Boxlet
|
|
121
118
|
end
|
122
119
|
end
|
123
120
|
end
|
124
|
-
end
|
121
|
+
end
|
data/lib/boxlet/db.rb
CHANGED
data/lib/boxlet/log.rb
CHANGED
File without changes
|
data/lib/boxlet/runner.rb
CHANGED
data/lib/boxlet/util.rb
CHANGED
@@ -5,13 +5,11 @@ module Boxlet
|
|
5
5
|
include Sys
|
6
6
|
|
7
7
|
# Auth methods
|
8
|
-
|
9
8
|
def self.encrypt(string)
|
10
9
|
(Digest::SHA256.new << string).to_s
|
11
10
|
end
|
12
11
|
|
13
12
|
# App disk space functions
|
14
|
-
|
15
13
|
def self.free_space
|
16
14
|
return -1 if Boxlet.config[:s3][:enabled]
|
17
15
|
Boxlet::Util.app_space_capacity - Boxlet::Util.app_space_usage
|
@@ -41,7 +39,6 @@ module Boxlet
|
|
41
39
|
end
|
42
40
|
|
43
41
|
# Drive disk space functions
|
44
|
-
|
45
42
|
def self.drive_free_space
|
46
43
|
stat = Filesystem.stat(Boxlet.config[:file_system_root])
|
47
44
|
(stat.block_size * stat.blocks_available).to_mb
|
@@ -51,6 +48,5 @@ module Boxlet
|
|
51
48
|
stat = Filesystem.stat(Boxlet.config[:file_system_root])
|
52
49
|
(stat.block_size * stat.blocks).to_mb
|
53
50
|
end
|
54
|
-
|
55
51
|
end
|
56
|
-
end
|
52
|
+
end
|
data/lib/boxlet/version.rb
CHANGED
data/lib/handlers/thin.rb
CHANGED
@@ -7,10 +7,10 @@ module Rack
|
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
def generate_map(default_app, mapping)
|
11
|
+
mapped = default_app ? {'/' => default_app} : {}
|
12
|
+
mapping.each { |r,b| mapped[r] = self.class.new(default_app, &b) }
|
13
|
+
BoxletUrlMap.new(mapped)
|
14
|
+
end
|
15
15
|
end
|
16
|
-
end
|
16
|
+
end
|
data/lib/rack/boxlet_url_map.rb
CHANGED
data/lib/rack/file_upload.rb
CHANGED
@@ -25,97 +25,97 @@ module Rack
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
28
|
private
|
30
29
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
30
|
+
def convert_and_pass_on(env)
|
31
|
+
if env['rack.input'].kind_of?(Tempfile)
|
32
|
+
env['rack.input'].extend(EqlFix)
|
33
|
+
tempfile = env['rack.input']
|
34
|
+
else
|
35
|
+
tempfile = Tempfile.new('raw-upload.', @tmpdir)
|
36
|
+
|
37
|
+
env['rack.input'].each do |chunk|
|
38
|
+
if chunk.respond_to?(:force_encoding)
|
39
|
+
tempfile << chunk.force_encoding('UTF-8')
|
40
|
+
else
|
41
|
+
tempfile << chunk
|
42
|
+
end
|
43
43
|
end
|
44
|
+
env['rack.input'].rewind
|
45
|
+
|
46
|
+
tempfile.flush
|
47
|
+
tempfile.rewind
|
44
48
|
end
|
45
|
-
env['rack.input'].rewind
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
env['
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
inject_query_params!(env, env['HTTP_X_PARAMS'])
|
50
|
+
fake_file = {
|
51
|
+
:filename => env['HTTP_X_FILE_NAME'],
|
52
|
+
:type => env['CONTENT_TYPE'],
|
53
|
+
:tempfile => tempfile,
|
54
|
+
}
|
55
|
+
env['rack.request.form_input'] = env['rack.input']
|
56
|
+
env['rack.request.form_hash'] ||= {}
|
57
|
+
env['rack.request.query_hash'] ||= {}
|
58
|
+
env['rack.request.form_hash']['file'] = fake_file
|
59
|
+
env['rack.request.query_hash']['file'] = fake_file
|
60
|
+
if env['HTTP_X_QUERY_PARAMS']
|
61
|
+
env['rack.errors'].puts("Warning! The header X-Query-Params is deprecated. Please use X-JSON-Params instead.")
|
62
|
+
inject_json_params!(env, env['HTTP_X_QUERY_PARAMS'])
|
63
|
+
end
|
64
|
+
if env['HTTP_X_JSON_PARAMS']
|
65
|
+
inject_json_params!(env, env['HTTP_X_JSON_PARAMS'])
|
66
|
+
end
|
67
|
+
if env['HTTP_X_PARAMS']
|
68
|
+
inject_query_params!(env, env['HTTP_X_PARAMS'])
|
69
|
+
end
|
70
|
+
@app.call(env)
|
69
71
|
end
|
70
|
-
@app.call(env)
|
71
|
-
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
def kick_in?(env)
|
74
|
+
env['HTTP_X_FILE_UPLOAD'] == 'true' ||
|
75
|
+
! @explicit && env['HTTP_X_FILE_UPLOAD'] != 'false' && raw_file_upload?(env) ||
|
76
|
+
env.has_key?('HTTP_X_FILE_UPLOAD') && env['HTTP_X_FILE_UPLOAD'] != 'false' && raw_file_upload?(env)
|
77
|
+
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
79
|
+
def raw_file_upload?(env)
|
80
|
+
upload_path?(env['PATH_INFO']) &&
|
81
|
+
%{POST PUT}.include?(env['REQUEST_METHOD']) &&
|
82
|
+
content_type_of_raw_file?(env['CONTENT_TYPE']) &&
|
83
|
+
env['CONTENT_LENGTH'].to_i > 0
|
84
|
+
end
|
85
85
|
|
86
|
-
|
87
|
-
|
88
|
-
|
86
|
+
def literal_path_match?(request_path, candidate)
|
87
|
+
candidate == request_path
|
88
|
+
end
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
90
|
+
def wildcard_path_match?(request_path, candidate)
|
91
|
+
return false unless candidate.include?('*')
|
92
|
+
regexp = '^' + candidate.gsub('.', '\.').gsub('*', '[^/]*') + '$'
|
93
|
+
!! (Regexp.new(regexp) =~ request_path)
|
94
|
+
end
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
def content_type_of_raw_file?(content_type)
|
97
|
+
case content_type
|
98
|
+
when %r{^application/x-www-form-urlencoded}, %r{^multipart/form-data}
|
99
|
+
false
|
100
|
+
else
|
101
|
+
true
|
102
|
+
end
|
102
103
|
end
|
103
|
-
end
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
def random_string
|
106
|
+
(0...8).map{65.+(rand(25)).chr}.join
|
107
|
+
end
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
109
|
+
def inject_json_params!(env, params)
|
110
|
+
json = MultiJson.load(params)
|
111
|
+
env['rack.request.form_hash'].merge!(json)
|
112
|
+
env['rack.request.query_hash'].merge!(json)
|
113
|
+
end
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
def inject_query_params!(env, params)
|
116
|
+
json = Rack::Utils.parse_query(params)
|
117
|
+
env['rack.request.form_hash'].merge!(json)
|
118
|
+
env['rack.request.query_hash'].merge!(json)
|
119
|
+
end
|
119
120
|
end
|
120
|
-
end
|
121
121
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxlet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arktisklada
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -237,8 +237,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
237
|
version: '0'
|
238
238
|
requirements: []
|
239
239
|
rubyforge_project:
|
240
|
-
rubygems_version: 2.
|
240
|
+
rubygems_version: 2.5.0
|
241
241
|
signing_key:
|
242
242
|
specification_version: 4
|
243
243
|
summary: Upload pics from your phone
|
244
244
|
test_files: []
|
245
|
+
has_rdoc:
|