forked from neocities/neocities
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ru
More file actions
98 lines (78 loc) · 2.52 KB
/
config.ru
File metadata and controls
98 lines (78 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'rubygems'
require './app.rb'
require 'sidekiq/web'
require 'airbrake/sidekiq'
use Airbrake::Rack::Middleware
map('/') do
use(Rack::Cache,
verbose: false,
metastore: 'file:/tmp/neocitiesrackcache/meta',
entitystore: 'file:/tmp/neocitiesrackcache/body'
)
run Sinatra::Application
end
map '/webdav' do
use Rack::Auth::Basic do |username, password|
@site = Site.get_site_from_login username, password
@site ? true : false
end
run lambda {|env|
if env['REQUEST_METHOD'] == 'PUT'
path = env['PATH_INFO']
tmpfile = Tempfile.new 'davfile', encoding: 'binary'
tmpfile.write env['rack.input'].read
tmpfile.close
if @site.file_size_too_large? tmpfile.size
return [507, {}, ['']]
end
# if Site.valid_file_type?(filename: path, tempfile: tmpfile)
if @site.okay_to_upload? filename: path, tempfile: tmpfile
@site.store_files [{filename: path, tempfile: tmpfile}]
return [201, {}, ['']]
else
return [415, {}, ['']]
end
end
if env['REQUEST_METHOD'] == 'MKCOL'
@site.create_directory env['PATH_INFO']
return [201, {}, ['']]
end
if env['REQUEST_METHOD'] == 'MOVE'
destination = env['HTTP_DESTINATION'].match(/^.+\/webdav(.+)$/i).captures.first
env['PATH_INFO'] = env['PATH_INFO'][1..env['PATH_INFO'].length] if env['PATH_INFO'][0] == '/'
site_file = @site.site_files.select {|s| s.path == env['PATH_INFO']}.first
return [404, {}, ['']] if site_file.nil?
res = site_file.rename destination
return [201, {}, ['']]
end
if env['REQUEST_METHOD'] == 'COPY'
return [501, {}, ['']]
end
if env['REQUEST_METHOD'] == 'LOCK'
return [501, {}, ['']]
end
if env['REQUEST_METHOD'] == 'UNLOCK'
return [501, {}, ['']]
end
if env['REQUEST_METHOD'] == 'PROPPATCH'
return [501, {}, ['']]
end
if env['REQUEST_METHOD'] == 'DELETE'
@site.delete_file env['PATH_INFO']
return [201, {}, ['']]
end
res = DAV4Rack::Handler.new(
root: @site.files_path,
root_uri_path: '/webdav'
).call(env)
}
end
map '/sidekiq' do
use Rack::Auth::Basic, "Protected Area" do |username, password|
raise 'missing sidekiq auth' unless $config['sidekiq_user'] && $config['sidekiq_pass']
username == $config['sidekiq_user'] && password == $config['sidekiq_pass']
end
use Rack::Session::Cookie, key: 'sidekiq.session', secret: $config['session_secret']
use Rack::Protection::AuthenticityToken
run Sidekiq::Web
end