diff --git a/examples/lighttpd/README.md b/examples/lighttpd/README.md new file mode 100644 index 0000000..e5c5aae --- /dev/null +++ b/examples/lighttpd/README.md @@ -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 WevDAV (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. diff --git a/examples/lighttpd/index.lua b/examples/lighttpd/index.lua new file mode 100644 index 0000000..9fdc678 --- /dev/null +++ b/examples/lighttpd/index.lua @@ -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({ [=[ + + + + + + + + + +]=] }) +r.resp_header["Content-Type"] = "text/html; charset=utf-8" +r.resp_header["Cache-Control"] = "max-age=3600" + +return 200 diff --git a/examples/lighttpd/webdav.conf b/examples/lighttpd/webdav.conf new file mode 100644 index 0000000..4b04aa1 --- /dev/null +++ b/examples/lighttpd/webdav.conf @@ -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"