webdav-exporter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +26 -0
- data/bin/webdav-exporter +197 -0
- data/webdav-exporter.rb +197 -0
- metadata +56 -0
data/README
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Public Description:
|
2
|
+
|
3
|
+
A WebDAV server for easy filesharing in hostile environments or for unwilling
|
4
|
+
sysads. Starts directly from the commandline and can do SSL/HTTPS. The
|
5
|
+
webdav-exporter uses the webrick-webdav gem which *fakes* a DAV2 protocol
|
6
|
+
implementation.
|
7
|
+
|
8
|
+
|
9
|
+
Description:
|
10
|
+
|
11
|
+
WebDAV server for easy filesharing in hostile environments or unwilling system
|
12
|
+
administrators. It starts a DAV server directly from commandline and shares
|
13
|
+
your files. Can use SSL with HTTPS for secure transfers. Authorization and
|
14
|
+
feature set is very limited at the moment. The webdav-exporter blends webrick
|
15
|
+
and the webrick-webdav into a comandline application and tries to fix the
|
16
|
+
missing parts with the DAV2 protocol.
|
17
|
+
|
18
|
+
|
19
|
+
Usage:
|
20
|
+
|
21
|
+
execute with no arguments an see usage output for examples. Next step is
|
22
|
+
reading the source and in case or further demand drop me a line per email to
|
23
|
+
dirk at sebrink dot de.
|
24
|
+
|
25
|
+
|
26
|
+
have fun
|
data/bin/webdav-exporter
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'app-ctx'
|
5
|
+
require 'webrick'
|
6
|
+
require 'webrick/httpstatus'
|
7
|
+
require 'webrick/https'
|
8
|
+
require 'webrick/httpservlet/webdavhandler'
|
9
|
+
|
10
|
+
# global variable for passing commandline/default values into the webdav servlet
|
11
|
+
$context = nil
|
12
|
+
|
13
|
+
# the 'DefaultSettings' can be overruled from the command line, e.g:
|
14
|
+
#
|
15
|
+
# webdav-exporter --port=1234 /path/to/exported/dir
|
16
|
+
#
|
17
|
+
# the SSL handling code liberally came from Gabriele Marrone at
|
18
|
+
# http://gmarrone.objectblues.net/cgi-bin/wiki/WebDAV_-_Linux_server%2c_Mac_OS_X_client
|
19
|
+
#
|
20
|
+
# and was discussed a bit at: http://www.ruby-forum.com/topic/86624#160859
|
21
|
+
#
|
22
|
+
DefaultSettings = {
|
23
|
+
:host => nil, # "0.0.0.0" or "::" or nil
|
24
|
+
:port => 443, # the default HTTPS port(needs root power)
|
25
|
+
#:docroot => Dir.pwd, # exports current working dir
|
26
|
+
# FileHandler = {
|
27
|
+
:NondisclosureName => [".ht*", "*~"],
|
28
|
+
:FancyIndexing => false,
|
29
|
+
:HandlerTable => {},
|
30
|
+
:HandlerCallback => nil,
|
31
|
+
:DirectoryCallback => nil,
|
32
|
+
:FileCallback => nil,
|
33
|
+
:UserDir => nil, # e.g. "public_html"
|
34
|
+
:AcceptableLanguages => [], # ["en", "ja", ... ]
|
35
|
+
:SSLEnable => true, # enable SSL for default HTTPS port 443
|
36
|
+
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
|
37
|
+
:SSLCertName => [["CN", WEBrick::Utils::getservername]],
|
38
|
+
:realm => "webdav-exporter: Yeah! Yeah! Yeah!",
|
39
|
+
:username => "guest",
|
40
|
+
:password => "%04d" % rand(10000),
|
41
|
+
# }
|
42
|
+
}
|
43
|
+
|
44
|
+
def usage
|
45
|
+
puts <<EOU
|
46
|
+
|
47
|
+
usage: #{$0} [options] <docroot>
|
48
|
+
|
49
|
+
default settings:
|
50
|
+
|
51
|
+
EOU
|
52
|
+
DefaultSettings.each do |k,v|
|
53
|
+
puts("\t%-25s: %s" % [k, v.inspect || "<nil>"])
|
54
|
+
end
|
55
|
+
puts <<EXAMPLES
|
56
|
+
|
57
|
+
Note: String and integer settings can be set on the command line!
|
58
|
+
|
59
|
+
usage examples:
|
60
|
+
|
61
|
+
# export your home directory(unix style :-)
|
62
|
+
$ #{$0} --port=12345 ~
|
63
|
+
|
64
|
+
# export to dedicated interface only
|
65
|
+
$ webdav-exporter --BindAddress=16.11.19.64 ~
|
66
|
+
# is equivalent to:
|
67
|
+
$ #{$0} --host=16.11.19.64 ~
|
68
|
+
|
69
|
+
# all features on
|
70
|
+
$ #{$0} --realm="go for it" --password=1234 --port=5500 /tmp
|
71
|
+
|
72
|
+
EXAMPLES
|
73
|
+
exit 0
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# WebDAVHandlerVersion2 fakes the DAV2 protocol and implementats certificate
|
78
|
+
# handling for SSL connections
|
79
|
+
class WebDAVHandlerVersion2 < WEBrick::HTTPServlet::WebDAVHandler
|
80
|
+
|
81
|
+
include WEBrick::HTTPStatus
|
82
|
+
|
83
|
+
def cfg
|
84
|
+
$context.values
|
85
|
+
end
|
86
|
+
|
87
|
+
def initialize(*args)
|
88
|
+
super(*args)
|
89
|
+
end
|
90
|
+
|
91
|
+
def service(req, res)
|
92
|
+
WEBrick::HTTPAuth.basic_auth(req, res, cfg.realm) do |user, pass|
|
93
|
+
# this block returns true if
|
94
|
+
# authentication token is valid
|
95
|
+
user == cfg.username && pass == cfg.password
|
96
|
+
true
|
97
|
+
end
|
98
|
+
super
|
99
|
+
end
|
100
|
+
|
101
|
+
def do_UNLOCK(req, res)
|
102
|
+
#@log << ">>>>> UNLOCK >>>>> #{req}"
|
103
|
+
res.body << ""
|
104
|
+
end
|
105
|
+
|
106
|
+
def do_LOCK(req, res)
|
107
|
+
#cfg.Logger << ">>>>> LOCK >>>>>\n #{req}"
|
108
|
+
|
109
|
+
# XXX I still don't now what to answer but this is an axmple request
|
110
|
+
#raise PreconditionFailed, "not implemented"
|
111
|
+
res.body << "<#{Time.now.to_s}>"
|
112
|
+
|
113
|
+
# this is a example form the WebDAV RFC(which are horrible!)
|
114
|
+
#
|
115
|
+
# LOCK /._x%20copy.rb HTTP/1.1
|
116
|
+
# User-Agent: WebDAVFS/1.4.1 (01418000) Darwin/8.8.1 (i386)
|
117
|
+
# Accept: */*
|
118
|
+
# Depth: 0
|
119
|
+
# Timeout: Second-600
|
120
|
+
# Content-Type: text/xml; charset="utf-8"
|
121
|
+
# Authorization: Basic bXl1c2VyOm15cGFzcw==
|
122
|
+
# Content-Length: 229
|
123
|
+
# Connection: keep-alive
|
124
|
+
# Host: localhost:1611
|
125
|
+
#
|
126
|
+
# <?xml version="1.0" encoding="utf-8"?>
|
127
|
+
# <D:lockinfo xmlns:D="DAV:">
|
128
|
+
# <D:lockscope><D:exclusive/></D:lockscope>
|
129
|
+
# <D:locktype><D:write/></D:locktype>
|
130
|
+
# <D:owner>
|
131
|
+
# <D:href>http://www.apple.com/webdav_fs/</D:href>
|
132
|
+
# </D:owner>
|
133
|
+
# </D:lockinfo>
|
134
|
+
end
|
135
|
+
|
136
|
+
def do_OPTIONS(req, res)
|
137
|
+
super
|
138
|
+
res["DAV"] = "1,2"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
App::run do |context|
|
143
|
+
|
144
|
+
usage if context.argv.empty?
|
145
|
+
|
146
|
+
context.set_default_values(DefaultSettings)
|
147
|
+
|
148
|
+
# some (convenience only)command line mappings which can be used
|
149
|
+
# interchangebly:
|
150
|
+
# --host instead --BindAddress ...
|
151
|
+
# --port instead --Port
|
152
|
+
context.values[:BindAddress] ||= context.values[:host]
|
153
|
+
context.values[:Port] ||= context.values[:port]
|
154
|
+
|
155
|
+
log = WEBrick::Log.new
|
156
|
+
log.level = WEBrick::Log::DEBUG if $DEBUG
|
157
|
+
context.values[:Logger] = log
|
158
|
+
server = WEBrick::HTTPServer.new(context.values)
|
159
|
+
|
160
|
+
context.values[:docroot] = context.argv.shift
|
161
|
+
# webdav-exporter --port=1234 --docroot="/foo/bar/ with blanks "
|
162
|
+
|
163
|
+
# make application context globally available before having instantiating
|
164
|
+
# the WebDAV server object which uses it
|
165
|
+
$context = context
|
166
|
+
# XXX move this code to app-ctx soon...
|
167
|
+
class << $context.values
|
168
|
+
def method_missing(m,*a)
|
169
|
+
if m.to_s =~ /=$/
|
170
|
+
self[$`.to_sym] = a[0]
|
171
|
+
elsif a.empty?
|
172
|
+
self[m]
|
173
|
+
else
|
174
|
+
raise NoMethodError, "#{m}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
server.mount "/", WebDAVHandlerVersion2, context.values[:docroot]
|
180
|
+
#server.mount "/", WEBrick::HTTPServlet::FileHandler, Dir.pwd, context.values
|
181
|
+
|
182
|
+
puts <<INFO
|
183
|
+
|
184
|
+
You can now log in to the
|
185
|
+
|
186
|
+
#{$context.values.realm}
|
187
|
+
|
188
|
+
Realm with the following username/password:
|
189
|
+
|
190
|
+
username: #{$context.values.username}
|
191
|
+
password: #{$context.values.password}
|
192
|
+
|
193
|
+
INFO
|
194
|
+
|
195
|
+
trap("INT") { server.shutdown }
|
196
|
+
server.start
|
197
|
+
end
|
data/webdav-exporter.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'app-ctx'
|
5
|
+
require 'webrick'
|
6
|
+
require 'webrick/httpstatus'
|
7
|
+
require 'webrick/https'
|
8
|
+
require 'webrick/httpservlet/webdavhandler'
|
9
|
+
|
10
|
+
# global variable for passing commandline/default values into the webdav servlet
|
11
|
+
$context = nil
|
12
|
+
|
13
|
+
# the 'DefaultSettings' can be overruled from the command line, e.g:
|
14
|
+
#
|
15
|
+
# webdav-exporter --port=1234 /path/to/exported/dir
|
16
|
+
#
|
17
|
+
# the SSL handling code liberally came from Gabriele Marrone at
|
18
|
+
# http://gmarrone.objectblues.net/cgi-bin/wiki/WebDAV_-_Linux_server%2c_Mac_OS_X_client
|
19
|
+
#
|
20
|
+
# and was discussed a bit at: http://www.ruby-forum.com/topic/86624#160859
|
21
|
+
#
|
22
|
+
DefaultSettings = {
|
23
|
+
:host => nil, # "0.0.0.0" or "::" or nil
|
24
|
+
:port => 443, # the default HTTPS port(needs root power)
|
25
|
+
#:docroot => Dir.pwd, # exports current working dir
|
26
|
+
# FileHandler = {
|
27
|
+
:NondisclosureName => [".ht*", "*~"],
|
28
|
+
:FancyIndexing => false,
|
29
|
+
:HandlerTable => {},
|
30
|
+
:HandlerCallback => nil,
|
31
|
+
:DirectoryCallback => nil,
|
32
|
+
:FileCallback => nil,
|
33
|
+
:UserDir => nil, # e.g. "public_html"
|
34
|
+
:AcceptableLanguages => [], # ["en", "ja", ... ]
|
35
|
+
:SSLEnable => true, # enable SSL for default HTTPS port 443
|
36
|
+
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
|
37
|
+
:SSLCertName => [["CN", WEBrick::Utils::getservername]],
|
38
|
+
:realm => "webdav-exporter: Yeah! Yeah! Yeah!",
|
39
|
+
:username => "guest",
|
40
|
+
:password => "%04d" % rand(10000),
|
41
|
+
# }
|
42
|
+
}
|
43
|
+
|
44
|
+
def usage
|
45
|
+
puts <<EOU
|
46
|
+
|
47
|
+
usage: #{$0} [options] <docroot>
|
48
|
+
|
49
|
+
default settings:
|
50
|
+
|
51
|
+
EOU
|
52
|
+
DefaultSettings.each do |k,v|
|
53
|
+
puts("\t%-25s: %s" % [k, v.inspect || "<nil>"])
|
54
|
+
end
|
55
|
+
puts <<EXAMPLES
|
56
|
+
|
57
|
+
Note: String and integer settings can be set on the command line!
|
58
|
+
|
59
|
+
usage examples:
|
60
|
+
|
61
|
+
# export your home directory(unix style :-)
|
62
|
+
$ #{$0} --port=12345 ~
|
63
|
+
|
64
|
+
# export to dedicated interface only
|
65
|
+
$ webdav-exporter --BindAddress=16.11.19.64 ~
|
66
|
+
# is equivalent to:
|
67
|
+
$ #{$0} --host=16.11.19.64 ~
|
68
|
+
|
69
|
+
# all features on
|
70
|
+
$ #{$0} --realm="go for it" --password=1234 --port=5500 /tmp
|
71
|
+
|
72
|
+
EXAMPLES
|
73
|
+
exit 0
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# WebDAVHandlerVersion2 fakes the DAV2 protocol and implementats certificate
|
78
|
+
# handling for SSL connections
|
79
|
+
class WebDAVHandlerVersion2 < WEBrick::HTTPServlet::WebDAVHandler
|
80
|
+
|
81
|
+
include WEBrick::HTTPStatus
|
82
|
+
|
83
|
+
def cfg
|
84
|
+
$context.values
|
85
|
+
end
|
86
|
+
|
87
|
+
def initialize(*args)
|
88
|
+
super(*args)
|
89
|
+
end
|
90
|
+
|
91
|
+
def service(req, res)
|
92
|
+
WEBrick::HTTPAuth.basic_auth(req, res, cfg.realm) do |user, pass|
|
93
|
+
# this block returns true if
|
94
|
+
# authentication token is valid
|
95
|
+
user == cfg.username && pass == cfg.password
|
96
|
+
true
|
97
|
+
end
|
98
|
+
super
|
99
|
+
end
|
100
|
+
|
101
|
+
def do_UNLOCK(req, res)
|
102
|
+
#@log << ">>>>> UNLOCK >>>>> #{req}"
|
103
|
+
res.body << ""
|
104
|
+
end
|
105
|
+
|
106
|
+
def do_LOCK(req, res)
|
107
|
+
#cfg.Logger << ">>>>> LOCK >>>>>\n #{req}"
|
108
|
+
|
109
|
+
# XXX I still don't now what to answer but this is an axmple request
|
110
|
+
#raise PreconditionFailed, "not implemented"
|
111
|
+
res.body << "<#{Time.now.to_s}>"
|
112
|
+
|
113
|
+
# this is a example form the WebDAV RFC(which are horrible!)
|
114
|
+
#
|
115
|
+
# LOCK /._x%20copy.rb HTTP/1.1
|
116
|
+
# User-Agent: WebDAVFS/1.4.1 (01418000) Darwin/8.8.1 (i386)
|
117
|
+
# Accept: */*
|
118
|
+
# Depth: 0
|
119
|
+
# Timeout: Second-600
|
120
|
+
# Content-Type: text/xml; charset="utf-8"
|
121
|
+
# Authorization: Basic bXl1c2VyOm15cGFzcw==
|
122
|
+
# Content-Length: 229
|
123
|
+
# Connection: keep-alive
|
124
|
+
# Host: localhost:1611
|
125
|
+
#
|
126
|
+
# <?xml version="1.0" encoding="utf-8"?>
|
127
|
+
# <D:lockinfo xmlns:D="DAV:">
|
128
|
+
# <D:lockscope><D:exclusive/></D:lockscope>
|
129
|
+
# <D:locktype><D:write/></D:locktype>
|
130
|
+
# <D:owner>
|
131
|
+
# <D:href>http://www.apple.com/webdav_fs/</D:href>
|
132
|
+
# </D:owner>
|
133
|
+
# </D:lockinfo>
|
134
|
+
end
|
135
|
+
|
136
|
+
def do_OPTIONS(req, res)
|
137
|
+
super
|
138
|
+
res["DAV"] = "1,2"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
App::run do |context|
|
143
|
+
|
144
|
+
usage if context.argv.empty?
|
145
|
+
|
146
|
+
context.set_default_values(DefaultSettings)
|
147
|
+
|
148
|
+
# some (convenience only)command line mappings which can be used
|
149
|
+
# interchangebly:
|
150
|
+
# --host instead --BindAddress ...
|
151
|
+
# --port instead --Port
|
152
|
+
context.values[:BindAddress] ||= context.values[:host]
|
153
|
+
context.values[:Port] ||= context.values[:port]
|
154
|
+
|
155
|
+
log = WEBrick::Log.new
|
156
|
+
log.level = WEBrick::Log::DEBUG if $DEBUG
|
157
|
+
context.values[:Logger] = log
|
158
|
+
server = WEBrick::HTTPServer.new(context.values)
|
159
|
+
|
160
|
+
context.values[:docroot] = context.argv.shift
|
161
|
+
# webdav-exporter --port=1234 --docroot="/foo/bar/ with blanks "
|
162
|
+
|
163
|
+
# make application context globally available before having instantiating
|
164
|
+
# the WebDAV server object which uses it
|
165
|
+
$context = context
|
166
|
+
# XXX move this code to app-ctx soon...
|
167
|
+
class << $context.values
|
168
|
+
def method_missing(m,*a)
|
169
|
+
if m.to_s =~ /=$/
|
170
|
+
self[$`.to_sym] = a[0]
|
171
|
+
elsif a.empty?
|
172
|
+
self[m]
|
173
|
+
else
|
174
|
+
raise NoMethodError, "#{m}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
server.mount "/", WebDAVHandlerVersion2, context.values[:docroot]
|
180
|
+
#server.mount "/", WEBrick::HTTPServlet::FileHandler, Dir.pwd, context.values
|
181
|
+
|
182
|
+
puts <<INFO
|
183
|
+
|
184
|
+
You can now log in to the
|
185
|
+
|
186
|
+
#{$context.values.realm}
|
187
|
+
|
188
|
+
Realm with the following username/password:
|
189
|
+
|
190
|
+
username: #{$context.values.username}
|
191
|
+
password: #{$context.values.password}
|
192
|
+
|
193
|
+
INFO
|
194
|
+
|
195
|
+
trap("INT") { server.shutdown }
|
196
|
+
server.start
|
197
|
+
end
|
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: webdav-exporter
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2006-12-31 00:00:00 +01:00
|
8
|
+
summary: one-stop WebDAV file export directly from your commandline
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: dirk@sebrink.de, dluesebrink@idmedia.com
|
12
|
+
homepage: http://www.sofasportler.de/dirk.blog/category/coding/ruby/
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Dirk Luesebrink
|
30
|
+
files:
|
31
|
+
- webdav-exporter.rb
|
32
|
+
- README
|
33
|
+
- bin/webdav-exporter
|
34
|
+
test_files: []
|
35
|
+
|
36
|
+
rdoc_options:
|
37
|
+
- --main
|
38
|
+
- README
|
39
|
+
extra_rdoc_files:
|
40
|
+
- README
|
41
|
+
executables:
|
42
|
+
- webdav-exporter
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
requirements: []
|
46
|
+
|
47
|
+
dependencies:
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: app-ctx
|
50
|
+
version_requirement:
|
51
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.1.4
|
56
|
+
version:
|