From 5f8c1ccd366c89236c21cbed682ce729970142f6 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 24 Mar 2019 14:09:53 +0100 Subject: [PATCH] init --- .drone.yml | 13 ++++++++++++ Dockerfile | 13 ++++++++++++ assets/listing.css | 48 ++++++++++++++++++++++++++++++++++++++++++ assets/listing.js | 27 ++++++++++++++++++++++++ entrypoint.sh | 9 ++++++++ lighttpd.conf | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 162 insertions(+) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 assets/listing.css create mode 100644 assets/listing.js create mode 100755 entrypoint.sh create mode 100644 lighttpd.conf diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..46a4bdd --- /dev/null +++ b/.drone.yml @@ -0,0 +1,13 @@ +kind: pipeline +name: default + +steps: +- name: docker + image: plugins/docker + settings: + registry: r.sbruder.de + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: r.sbruder.de/lighttpd diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e2fc8fb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine + +RUN apk add --no-cache \ + ca-certificates \ + lighttpd \ + lighttpd-mod_auth \ + lighttpd-mod_webdav + +COPY lighttpd.conf /etc/lighttpd/lighttpd.conf +COPY assets /etc/lighttpd/assets +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/assets/listing.css b/assets/listing.css new file mode 100644 index 0000000..60a5bb8 --- /dev/null +++ b/assets/listing.css @@ -0,0 +1,48 @@ +body,html { + background-color: #fdf6e3; + color: #657b83; + font-family: "TeX Gyre Heros", "Roboto", "Helvetica", "Arial", sans-serif; +} + +tr:nth-child(even) { + background: #eee8d5; +} + +th,td { + padding: 0.1em 0.5em; +} + +th { + text-align: left; + font-weight: bold; + background: #eee8d5; + border-bottom: 1px solid #657b83; +} + +a { + color: #586e75; +} + +a:hover { + color: #073642; +} + +.m, .t { + display: none; +} + +table { + width: 100%; +} + +.foot { + display: none; +} + +#search-field { + width: 100%; + border: none; + margin-bottom: 15px; + background: #eee8d5; + color: inherit; +} diff --git a/assets/listing.js b/assets/listing.js new file mode 100644 index 0000000..fac38fd --- /dev/null +++ b/assets/listing.js @@ -0,0 +1,27 @@ +let searchField = document.createElement('input') +searchField.id = 'search-field' +searchField.autofocus = true +document.querySelector('.list').insertBefore(searchField, document.querySelector('table')) + +try { + document.querySelector('a[href="../"]').innerText = '..' +} catch (e) {} + +const rows = [...document.querySelectorAll('tbody tr')] + +document.querySelector('#search-field').addEventListener("input", e => { + const searchValue = e.target.value.toLowerCase() + rows.forEach(row => { + const file = row.querySelector('td').innerText + if (!file.toLowerCase().startsWith(searchValue)) { + row.style.display = 'none' + } else { + row.style.display = 'table-row' + } + }) + + const visibleRows = [...document.querySelectorAll('tr[style="display: table-row;"]')] + if (visibleRows.length === 1) { + window.location = visibleRows[0].querySelector('td a').href + } +}) diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..cf738cb --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/ash +sed -i \ + -e "s/@@LDAP_SERVER@@/$LDAP_SERVER/" \ + -e "s/@@LDAP_BASE@@/$LDAP_BASE/" \ + -e "s/@@LDAP_USER@@/$LDAP_USER/" \ + -e "s/@@LDAP_PASSWORD@@/$LDAP_PASSWORD/" \ + /etc/lighttpd/lighttpd.conf + +lighttpd -D -f /etc/lighttpd/lighttpd.conf diff --git a/lighttpd.conf b/lighttpd.conf new file mode 100644 index 0000000..6047c1c --- /dev/null +++ b/lighttpd.conf @@ -0,0 +1,52 @@ +server.modules = ( + "mod_alias", + "mod_webdav", + "mod_auth", + "mod_authn_ldap", +) + +include "mime-types.conf" + +server.username = "lighttpd" +server.groupname = "lighttpd" + +server.document-root = "/srv/www" + +server.indexfiles = ("index.html", "index.htm") + +server.follow-symlink = "enable" + +alias.url = ("/directory-listing-assets/" => "/etc/lighttpd/assets/") + +dir-listing.activate = "enable" +dir-listing.encoding = "utf-8" +dir-listing.external-css = "/directory-listing-assets/listing.css" +dir-listing.external-js = "/directory-listing-assets/listing.js" + +webdav.activate = "enable" +webdav.is-readonly = "enable" + +auth.backend = "ldap" +auth.backend.ldap.hostname = "@@LDAP_SERVER@@" +auth.backend.ldap.base-dn = "@@LDAP_BASE@@" +auth.backend.ldap.filter = "(uid=$)" +auth.backend.ldap.starttls = "enable" +auth.backend.ldap.bind-dn = "@@LDAP_USER@@" +auth.backend.ldap.bind-pw = "@@LDAP_PASSWORD@@" + +#auth.require = ( "/" => +# ( +# "method" => "basic", +# "realm" => "media", +# "require" => "valid-user" +# ) +# ) +$HTTP["url"] !~ "^/directory-listing-assets/" { + auth.require = ( "" => + ( + "method" => "basic", + "realm" => "media", + "require" => "valid-user" + ) + ) +}