servedir 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +59 -0
- data/UNLICENSE +24 -0
- data/bin/servedir +65 -0
- metadata +68 -0
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
servedir: serve a directory over HTTP from behind NAT
|
2
|
+
=====================================================
|
3
|
+
|
4
|
+
`servedir` is a tiny Ruby program used to serve a directory over HTTP from
|
5
|
+
boxes that are behind a NAT (most ADSL users).
|
6
|
+
|
7
|
+
`servedir` does not require any additional library and is compatible with
|
8
|
+
Ruby 1.8.7, Ruby 1.9.3 and JRuby.
|
9
|
+
|
10
|
+
This program will not try to open ports on the NAT gateway: it expects ports
|
11
|
+
to be already configured in the proper way.
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
On the box behind NAT:
|
17
|
+
|
18
|
+
$ servedir ~/Public 13428
|
19
|
+
|
20
|
+
Server starting... (CTRL-C to terminate)
|
21
|
+
local address: <http://localhost:13428/>
|
22
|
+
public address: <http://84.136.123.62:13428/>
|
23
|
+
|
24
|
+
[2012-02-11 13:24:01] INFO WEBrick 1.3.1
|
25
|
+
[2012-02-11 13:24:01] INFO ruby 1.8.7 (2010-01-10) [x86_64-linux]
|
26
|
+
[2012-02-11 13:24:01] INFO WEBrick::HTTPServer#start: pid=8207 port=13428
|
27
|
+
|
28
|
+
From another computer:
|
29
|
+
|
30
|
+
$ w3m -dump http://84.136.123.62:13428/
|
31
|
+
Index of /
|
32
|
+
|
33
|
+
Name Last modified Size
|
34
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
35
|
+
|
36
|
+
Parent Directory 2012/02/11 13:28 -
|
37
|
+
bus timetable.pdf 2011/10/09 11:04 136856
|
38
|
+
facesofprotest.pdf 2011/04/09 15:15 5531985
|
39
|
+
Country pictures 2010/ 2011/04/12 22:41 -
|
40
|
+
fav_webradios.xml 2009/10/28 17:20 854
|
41
|
+
|
42
|
+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
43
|
+
|
44
|
+
WEBrick/1.3.1 (Ruby/1.8.7/2010-01-10)
|
45
|
+
at localhost:13428
|
46
|
+
|
47
|
+
|
48
|
+
Authors
|
49
|
+
-------
|
50
|
+
|
51
|
+
* Gioele Barabucci <http://svario.it/gioele>
|
52
|
+
|
53
|
+
|
54
|
+
License
|
55
|
+
-------
|
56
|
+
|
57
|
+
This is free and unencumbered software released into the public domain.
|
58
|
+
See the `UNLICENSE` file or <http://unlicense.org/> for more details.
|
59
|
+
|
data/UNLICENSE
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
data/bin/servedir
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This is free and unencumbered software released into the public domain.
|
4
|
+
# See the `UNLICENSE` file or <http://unlicense.org/> for more details.
|
5
|
+
|
6
|
+
require 'open-uri'
|
7
|
+
require 'webrick'
|
8
|
+
|
9
|
+
IP_DISCO_SERVICE = 'http://automation.whatismyip.com/n09230945.asp'
|
10
|
+
MAX_PORT = 2**16
|
11
|
+
|
12
|
+
def check_args(dir, port)
|
13
|
+
if !File.directory?(File.expand_path(dir))
|
14
|
+
puts "WARNING: '#{dir}' is not a directory"
|
15
|
+
end
|
16
|
+
|
17
|
+
if port > MAX_PORT
|
18
|
+
puts "ERROR: port numer too high, #{port} is > #{MAX_PORT}"
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_addresses(dir, port)
|
24
|
+
begin
|
25
|
+
ip = open(IP_DISCO_SERVICE).read
|
26
|
+
rescue Errno::ENETUNREACH => err
|
27
|
+
puts "WARNING: Cannot reach IP discovery service"
|
28
|
+
ip = "NOT_AVAILABLE"
|
29
|
+
end
|
30
|
+
|
31
|
+
local_uri = "http://localhost:#{port}/"
|
32
|
+
remote_uri = "http://#{ip}:#{port}/"
|
33
|
+
|
34
|
+
puts "Server starting... (CTRL-C to terminate)"
|
35
|
+
puts " local address: <#{local_uri}>"
|
36
|
+
puts " public address: <#{remote_uri}>"
|
37
|
+
puts
|
38
|
+
end
|
39
|
+
|
40
|
+
def start_server(dir, port)
|
41
|
+
config = {
|
42
|
+
:DocumentRoot => dir,
|
43
|
+
:Port => port,
|
44
|
+
}
|
45
|
+
|
46
|
+
server = WEBrick::HTTPServer.new(config)
|
47
|
+
|
48
|
+
['INT', 'TERM'].each { |signal|
|
49
|
+
trap(signal) {server.shutdown}
|
50
|
+
}
|
51
|
+
|
52
|
+
server.start
|
53
|
+
end
|
54
|
+
|
55
|
+
if ARGV.count < 2
|
56
|
+
puts "servedir [DIRECTORY] [PORT]"
|
57
|
+
exit
|
58
|
+
end
|
59
|
+
|
60
|
+
dir = ARGV[0] || Dir.pwd
|
61
|
+
port = ARGV[1].to_i || 8080
|
62
|
+
|
63
|
+
check_args(dir, port)
|
64
|
+
print_addresses(dir, port)
|
65
|
+
start_server(dir, port)
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: servedir
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Gioele Barabucci
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-02-11 00:00:00 Z
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description:
|
21
|
+
email:
|
22
|
+
- gioele@svario.it
|
23
|
+
executables:
|
24
|
+
- servedir
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- bin/servedir
|
31
|
+
- README.md
|
32
|
+
- UNLICENSE
|
33
|
+
homepage: http://github.com/gioele/servedir
|
34
|
+
licenses:
|
35
|
+
- UNLICENSE
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.16
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: servedir is a tiny Ruby program used to serve a directory over HTTP from boxes that are behind a NAT (most ADSL users).
|
66
|
+
test_files: []
|
67
|
+
|
68
|
+
has_rdoc:
|