8000 add lighttpd example by gstrauss · Pull Request #130 · dom111/webdav-js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add lighttpd example #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/lighttpd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# lighttpd Directory List Example

To utilise this lighttpd directory list replacement, you'll need to have your
own server set up and configured with WebDAV (hopefully that's a given!).

Clone this repository to a desirable location (e.g. `/var/www/webdav-js`) then
modify the example `webdav.conf` file to your liking, updating the references
to the `webdav-js` repo if you've checked it out elsewhere.

Include `webdav.conf` in your lighttpd.conf or symlink in /etc/lighttpd/conf.d/
(or similar directory, depending on the convention used by the lighttpd package
in your OS distribution).

From then on you should be able to upload and browse at your leisure.
41 changes: 41 additions & 0 deletions examples/lighttpd/index.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--
-- serve page with webdav-js for GET and HEAD requests for collection
--

local r = lighty.r

local method = r.req_attr["request.method"]
if (method ~= "GET" and method ~= "HEAD") then
return 0
end

local path = r.req_attr["physical.path"]
-- check that path ends in '/'
if (not path or not string.match(path, "/$")) then
return 0
end
-- check that path exists and is a directory
local st = lighty.c.stat(path)
if (not st or not st.is_dir) then
return 0
end

-- Use webdav-js to generate index page for WebDAV collection
-- If not self-hosting webdav-js git checkout, could use these URLs below:
-- https://cdn.jsdelivr.net/gh/dom111/webdav-js/assets/css/style-min.css
-- https://cdn.jsdelivr.net/gh/dom111/webdav-js/src/webdav-min.js
r.resp_body:set({ [=[
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/webdav-js/assets/css/style-min.css">
</head>
<body>
<script src="/webdav-js/src/webdav-min.js"></script>
</body>
</html>
]=] })
r.resp_header["Content-Type"] = "text/html; charset=utf-8"
r.resp_header["Cache-Control"] = "max-age=3600"

return 200
47 changes: 47 additions & 0 deletions examples/lighttpd/webdav.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
server.modules += (
#"mod_access",# optional
"mod_alias",
"mod_magnet",
"mod_webdav",
"mod_setenv", # optional
"mod_deflate" # optional
)

# TODO: modify to set webdav-js git repository checkout location
var.webdav_js = "/var/www/webdav-js"

# TODO: modify to set host name
$HTTP["host"] == "webdav.example.com" {
# TODO: modify to set document root for WebDAV collections
server.document-root = "/var/www/html"
webdav.activate = "enable"
webdav.is-readonly = "disable"
webdav.opts += ("propfind-depth-infinity" => "enable")
# TODO: uncomment to enable WebDAV LOCK,UNLOCK and WebDAV PROPPATCH
# Prefer to change path to a persistent location,
# e.g. under /var/cache/lighttpd/webdav
#webdav.sqlite-db-name = "/var/tmp/webdav.example.com.db"

magnet.attract-physical-path-to = (
var.webdav_js + "/examples/lighttpd/index.lua"
)

$HTTP["url"] =^ "/webdav-js" {
alias.url = ("/webdav-js" => var.webdav_js)

# (choose any one or more lines of the following from this group)
webdav.activate = "disable"
webdav.is-readonly = "enable"
# (url.access-deny requires uncommenting "mod_access" in server.modules)
#$HTTP["method"] != "GET" { url.access-deny = ("") }

# (optional) enable caching of static assets for 1 hour
setenv.set-response-header = ("Cache-Control" => "max-age=3600")
}
}

# (optional) compress responses
deflate.mimetypes = ("text/")
deflate.allowed-encodings = ( "br", "gzip", "deflate" )
# TODO: uncomment and modify to path to cache compressed resources
#deflate.cache-dir = "/var/cache/lighttpd/compress"
0