fsws 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +18 -0
- data/bin/fsws +7 -0
- data/lib/fsws/mime.types +110 -0
- data/lib/fsws/server.rb +97 -0
- data/lib/fsws/version.rb +3 -0
- data/lib/fsws/views/404.erb +11 -0
- data/lib/fsws/views/listing.erb +25 -0
- data/lib/fsws/views/style.css +31 -0
- data/lib/fsws.rb +2 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9861599f14c99abde894d207258f5664c1207289
|
4
|
+
data.tar.gz: 48820d3dd4e22f3f14d4844c0598fef8249f6fb9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0348b39e3707b215ea5840e8c287bbc1fd78bab7ddf9031aca488e0d6864b521347197713573b9b8cf531744a69601a2b9b369d93386949625e8743257eca28
|
7
|
+
data.tar.gz: 70e659ac30080eaed9abc458f5fd5518ce4e39c346c42642b5a3c91309ae14ec6565f82fdc09c677261b017b6cffc6de3ae7f2be855286b2a9dfc774ee24554e
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Chris Schmich
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# fsws
|
2
|
+
|
3
|
+
A simple Ruby-based file system web server for serving static files out of a directory.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
```
|
8
|
+
$ gem install fsws
|
9
|
+
$ fsws
|
10
|
+
```
|
11
|
+
|
12
|
+
This starts a web server for files in the current directory.
|
13
|
+
|
14
|
+
## License
|
15
|
+
|
16
|
+
Copyright © 2014 Chris Schmich
|
17
|
+
<br />
|
18
|
+
MIT License, See [LICENSE](LICENSE) for details.
|
data/bin/fsws
ADDED
data/lib/fsws/mime.types
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# From https://github.com/h5bp/server-configs-nginx/blob/master/mime.types
|
2
|
+
types {
|
3
|
+
|
4
|
+
# Audio
|
5
|
+
audio/midi mid midi kar;
|
6
|
+
audio/mp4 aac f4a f4b m4a;
|
7
|
+
audio/mpeg mp3;
|
8
|
+
audio/ogg oga ogg;
|
9
|
+
audio/x-realaudio ra;
|
10
|
+
audio/x-wav wav;
|
11
|
+
|
12
|
+
# Images
|
13
|
+
image/bmp bmp;
|
14
|
+
image/gif gif;
|
15
|
+
image/jpeg jpeg jpg;
|
16
|
+
image/png png;
|
17
|
+
image/tiff tif tiff;
|
18
|
+
image/vnd.wap.wbmp wbmp;
|
19
|
+
image/webp webp;
|
20
|
+
image/x-icon ico cur;
|
21
|
+
image/x-jng jng;
|
22
|
+
|
23
|
+
# JavaScript
|
24
|
+
application/javascript js;
|
25
|
+
application/json json;
|
26
|
+
|
27
|
+
# Manifest files
|
28
|
+
application/x-web-app-manifest+json webapp;
|
29
|
+
text/cache-manifest manifest appcache;
|
30
|
+
|
31
|
+
# Microsoft Office
|
32
|
+
application/msword doc;
|
33
|
+
application/vnd.ms-excel xls;
|
34
|
+
application/vnd.ms-powerpoint ppt;
|
35
|
+
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
|
36
|
+
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
|
37
|
+
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
|
38
|
+
|
39
|
+
# Video
|
40
|
+
video/3gpp 3gpp 3gp;
|
41
|
+
video/mp4 mp4 m4v f4v f4p;
|
42
|
+
video/mpeg mpeg mpg;
|
43
|
+
video/ogg ogv;
|
44
|
+
video/quicktime mov;
|
45
|
+
video/webm webm;
|
46
|
+
video/x-flv flv;
|
47
|
+
video/x-mng mng;
|
48
|
+
video/x-ms-asf asx asf;
|
49
|
+
video/x-ms-wmv wmv;
|
50
|
+
video/x-msvideo avi;
|
51
|
+
|
52
|
+
# Web feeds
|
53
|
+
application/xml atom rdf rss xml;
|
54
|
+
|
55
|
+
# Web fonts
|
56
|
+
application/font-woff woff;
|
57
|
+
application/font-woff2 woff2;
|
58
|
+
application/vnd.ms-fontobject eot;
|
59
|
+
application/x-font-ttf ttc ttf;
|
60
|
+
font/opentype otf;
|
61
|
+
image/svg+xml svg svgz;
|
62
|
+
|
63
|
+
# Other
|
64
|
+
application/java-archive jar war ear;
|
65
|
+
application/mac-binhex40 hqx;
|
66
|
+
application/pdf pdf;
|
67
|
+
application/postscript ps eps ai;
|
68
|
+
application/rtf rtf;
|
69
|
+
application/vnd.wap.wmlc wmlc;
|
70
|
+
application/xhtml+xml xhtml;
|
71
|
+
application/vnd.google-earth.kml+xml kml;
|
72
|
+
application/vnd.google-earth.kmz kmz;
|
73
|
+
application/x-7z-compressed 7z;
|
74
|
+
application/x-chrome-extension crx;
|
75
|
+
application/x-opera-extension oex;
|
76
|
+
application/x-xpinstall xpi;
|
77
|
+
application/x-cocoa cco;
|
78
|
+
application/x-java-archive-diff jardiff;
|
79
|
+
application/x-java-jnlp-file jnlp;
|
80
|
+
application/x-makeself run;
|
81
|
+
application/x-perl pl pm;
|
82
|
+
application/x-pilot prc pdb;
|
83
|
+
application/x-rar-compressed rar;
|
84
|
+
application/x-redhat-package-manager rpm;
|
85
|
+
application/x-sea sea;
|
86
|
+
application/x-shockwave-flash swf;
|
87
|
+
application/x-stuffit sit;
|
88
|
+
application/x-tcl tcl tk;
|
89
|
+
application/x-x509-ca-cert der pem crt;
|
90
|
+
application/x-bittorrent torrent;
|
91
|
+
application/zip zip;
|
92
|
+
|
93
|
+
application/octet-stream bin exe dll;
|
94
|
+
application/octet-stream deb;
|
95
|
+
application/octet-stream dmg;
|
96
|
+
application/octet-stream iso img;
|
97
|
+
application/octet-stream msi msp msm;
|
98
|
+
application/octet-stream safariextz;
|
99
|
+
|
100
|
+
text/css css;
|
101
|
+
text/html html htm shtml;
|
102
|
+
text/mathml mml;
|
103
|
+
text/plain txt;
|
104
|
+
text/vnd.sun.j2me.app-descriptor jad;
|
105
|
+
text/vnd.wap.wml wml;
|
106
|
+
text/vtt vtt;
|
107
|
+
text/x-component htc;
|
108
|
+
text/x-vcard vcf;
|
109
|
+
|
110
|
+
}
|
data/lib/fsws/server.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'erb'
|
3
|
+
require 'pathname'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
def mime_types
|
7
|
+
return @mime_types if @mime_types
|
8
|
+
|
9
|
+
@mime_types = {}
|
10
|
+
|
11
|
+
path = File.join(File.dirname(__FILE__), 'mime.types')
|
12
|
+
File.open(path, 'r') do |file|
|
13
|
+
file.each_line do |line|
|
14
|
+
if line =~ /^\s*([\w\/.-]+)\s*((\w+\s*)+);\s*$/
|
15
|
+
mime_type = $1.strip
|
16
|
+
extensions = $2.strip.split.map(&:strip).map(&:downcase)
|
17
|
+
for ext in extensions
|
18
|
+
@mime_types[ext] = mime_type.downcase
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@mime_types
|
25
|
+
end
|
26
|
+
|
27
|
+
def serve(env)
|
28
|
+
path = env['REQUEST_PATH'] || ''
|
29
|
+
path = '/' if path.empty?
|
30
|
+
path = '.' + path
|
31
|
+
|
32
|
+
return error(env) if !allowed?(path)
|
33
|
+
|
34
|
+
return serve_file(path) || serve_dir(path) || error(env)
|
35
|
+
end
|
36
|
+
|
37
|
+
def serve_file(path)
|
38
|
+
return nil if !File.file? path
|
39
|
+
|
40
|
+
ext = File.extname(path)
|
41
|
+
ext = ext[1...ext.length]
|
42
|
+
mime_type = mime_types[ext] || 'text/plain'
|
43
|
+
|
44
|
+
return 200, { 'Content-Type' => mime_type }, File.open(path, 'rb').read
|
45
|
+
end
|
46
|
+
|
47
|
+
def serve_dir(path)
|
48
|
+
return nil if !File.directory? path
|
49
|
+
|
50
|
+
for file in %w(index.html index.htm)
|
51
|
+
index = File.join(path, file)
|
52
|
+
page = serve_file(index)
|
53
|
+
return page if page
|
54
|
+
end
|
55
|
+
|
56
|
+
return redirect(path + '/') if !path.end_with?('/')
|
57
|
+
|
58
|
+
dirs, files = Dir.entries(path).partition { |e| File.directory?(File.join(path, e)) }
|
59
|
+
dirs.delete('.')
|
60
|
+
dirs.sort!
|
61
|
+
files.sort!
|
62
|
+
|
63
|
+
pwd = Pathname.new('/' + Pathname.new(File.absolute_path(path)).relative_path_from(Pathname.new(File.absolute_path(Dir.pwd))).to_s).cleanpath
|
64
|
+
|
65
|
+
return 200, { 'Content-Type' => 'text/html' }, erb('listing', dirs: dirs, files: files, pwd: pwd)
|
66
|
+
end
|
67
|
+
|
68
|
+
def erb(view, vars)
|
69
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), "views/#{view}.erb")))
|
70
|
+
.result(OpenStruct.new(vars).instance_eval { binding })
|
71
|
+
end
|
72
|
+
|
73
|
+
def error(env)
|
74
|
+
return 404, nil, erb('404', path: env['REQUEST_PATH'])
|
75
|
+
end
|
76
|
+
|
77
|
+
def redirect(path)
|
78
|
+
return 301, { 'Location' => path }, nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def allowed?(path)
|
82
|
+
target = File.absolute_path(path)
|
83
|
+
return target.start_with?(File.absolute_path(Dir.pwd))
|
84
|
+
end
|
85
|
+
|
86
|
+
def include(file)
|
87
|
+
File.read(File.join(File.dirname(__FILE__), file))
|
88
|
+
end
|
89
|
+
|
90
|
+
module Fsws
|
91
|
+
def self.server
|
92
|
+
Proc.new do |env|
|
93
|
+
code, headers, body = serve(env)
|
94
|
+
[code.to_s, headers, [body]]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/fsws/version.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>Index of <%= pwd %></title>
|
4
|
+
<style type="text/css">
|
5
|
+
<%= include 'views/style.css' %>
|
6
|
+
</style>
|
7
|
+
</head>
|
8
|
+
<body>
|
9
|
+
<h1>Index of <%= pwd %></h1>
|
10
|
+
<% if !dirs.empty? %>
|
11
|
+
<ul>
|
12
|
+
<% for dir in dirs %>
|
13
|
+
<li><a href="<%= dir %>/"><%= dir %>/</a></li>
|
14
|
+
<% end %>
|
15
|
+
</ul>
|
16
|
+
<% end %>
|
17
|
+
<% if !files.empty? %>
|
18
|
+
<ul>
|
19
|
+
<% for file in files %>
|
20
|
+
<li><a href="<%= file %>"><%= file %></a></li>
|
21
|
+
<% end %>
|
22
|
+
</ul>
|
23
|
+
<% end %>
|
24
|
+
</body>
|
25
|
+
</html>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
body {
|
2
|
+
font: 20px Consolas, Monaco, monospace;
|
3
|
+
}
|
4
|
+
a {
|
5
|
+
text-decoration: none;
|
6
|
+
color: #555;
|
7
|
+
padding: 15px;
|
8
|
+
}
|
9
|
+
a:hover {
|
10
|
+
background: #e7e7f3;
|
11
|
+
color: #048;
|
12
|
+
}
|
13
|
+
h1 {
|
14
|
+
margin-bottom: 10px;
|
15
|
+
}
|
16
|
+
body {
|
17
|
+
margin: 10px;
|
18
|
+
}
|
19
|
+
ul {
|
20
|
+
list-style-type: none;
|
21
|
+
margin: 0;
|
22
|
+
padding: 0;
|
23
|
+
}
|
24
|
+
li {
|
25
|
+
background: #f3f3f3;
|
26
|
+
margin-bottom: 5px;
|
27
|
+
padding: 0;
|
28
|
+
}
|
29
|
+
li a {
|
30
|
+
display: block;
|
31
|
+
}
|
data/lib/fsws.rb
ADDED
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fsws
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Schmich
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.3'
|
55
|
+
description: |2
|
56
|
+
A simple Ruby-based file system web server for serving
|
57
|
+
static files out of a directory.
|
58
|
+
email: schmch@gmail.com
|
59
|
+
executables:
|
60
|
+
- fsws
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- bin/fsws
|
67
|
+
- lib/fsws.rb
|
68
|
+
- lib/fsws/mime.types
|
69
|
+
- lib/fsws/server.rb
|
70
|
+
- lib/fsws/version.rb
|
71
|
+
- lib/fsws/views/404.erb
|
72
|
+
- lib/fsws/views/listing.erb
|
73
|
+
- lib/fsws/views/style.css
|
74
|
+
homepage: https://github.com/schmich/fsws
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.9.3
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.3.0
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Ruby file system web server.
|
98
|
+
test_files: []
|
99
|
+
has_rdoc:
|