diff --git a/.drone.yml b/.drone.yml index 174b1f6..0cf50b1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,13 +3,20 @@ type: docker name: default steps: -- name: build +- name: glibc-x86_64 image: gcc commands: - make - - mv quark quark-dirl + - mv dirl dirl-glibc-x86_64 -- name: publish +- name: musl-x86_64 + image: alpine + commands: + - apk update && apk add make git build-base linux-headers musl-dev + - make STATIC="-static -fPIE" + - mv dirl dirl-musl-x86_64 + +- name: publish binaries image: appleboy/drone-scp settings: host: friedl.net @@ -18,5 +25,19 @@ steps: password: from_secret: deploy_password port: 22 - target: /var/services/dirlist/repo/bin/suckless/quark - source: quark-dirl + target: /var/services/dirlist/repo/bin/dirl + source: + - dirl-glibc-x86_64 + - dirl-musl-x86_64 + +- name: publish-container + image: plugins/docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + dockerfile: Dockerfile + purge: true + repo: arminfriedl/dirl + tags: latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5edcde5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine + +RUN adduser web --disabled-password --no-create-home --shell /sbin/nologin && \ + addgroup web web && \ + mkdir -p /var/www/html + +COPY dirl /usr/local/bin + +ENTRYPOINT ["dirl", "-p", "80", "-u", "web", "-g", "web", "-n", "4096", "-h", "0.0.0.0", "-l", "-d", "/var/www/html"] diff --git a/Makefile b/Makefile index 7573552..f682e6a 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,25 @@ # See LICENSE file for copyright and license details -# quark - simple web server +# dirl - customizable directory listings based on quark .POSIX: include config.mk COMPONENTS = data http sock util dirl -all: quark +all: dirl -data.o: data.c data.h util.h http.h dirl.h config.mk -dirl.o: dirl.c dirl.h util.h http.h config.mk -http.o: http.c http.h util.h http.h data.h config.h config.mk -main.o: main.c util.h sock.h http.h arg.h config.h config.mk -sock.o: sock.c sock.h util.h config.mk -util.o: util.c util.h config.mk +main.o: main.c util.h sock.h http.h arg.h config.h +http.o: http.c http.h util.h http.h data.h config.h +data.o: data.c data.h util.h http.h dirl.h +dirl.o: dirl.c dirl.h util.h http.h +sock.o: sock.c sock.h util.h +util.o: util.c util.h -quark: $(COMPONENTS:=.o) $(COMPONENTS:=.h) main.o config.mk +dirl: $(COMPONENTS:=.o) $(COMPONENTS:=.h) main.o config.mk $(CC) -o $@ $(CPPFLAGS) $(CFLAGS) $(COMPONENTS:=.o) main.o $(LDFLAGS) config.h: cp config.def.h $@ clean: - rm -f quark main.o $(COMPONENTS:=.o) - -dist: - rm -rf "quark-$(VERSION)" - mkdir -p "quark-$(VERSION)" - cp -R LICENSE Makefile arg.h config.def.h config.mk quark.1 \ - $(COMPONENTS:=.c) $(COMPONENTS:=.h) main.c "quark-$(VERSION)" - tar -cf - "quark-$(VERSION)" | gzip -c > "quark-$(VERSION).tar.gz" - rm -rf "quark-$(VERSION)" - -install: all - mkdir -p "$(DESTDIR)$(PREFIX)/bin" - cp -f quark "$(DESTDIR)$(PREFIX)/bin" - chmod 755 "$(DESTDIR)$(PREFIX)/bin/quark" - mkdir -p "$(DESTDIR)$(MANPREFIX)/man1" - cp quark.1 "$(DESTDIR)$(MANPREFIX)/man1/quark.1" - chmod 644 "$(DESTDIR)$(MANPREFIX)/man1/quark.1" - -uninstall: - rm -f "$(DESTDIR)$(PREFIX)/bin/quark" - rm -f "$(DESTDIR)$(MANPREFIX)/man1/quark.1" + rm -f dirl main.o $(COMPONENTS:=.o) diff --git a/README.md b/README.md index c2d1193..4431f36 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,20 @@ -[![Build Status](https://drone.friedl.net/api/badges/playground/suckless-quark/status.svg)](https://drone.friedl.net/playground/suckless-quark) +[![Build Status](https://drone.friedl.net/api/badges/incubator/dirl/status.svg)](https://drone.friedl.net/incubator/dirl) -This is my private tree of [quark](tools.suckless.org/quark/). Upstream can be -found at https://git.suckless.org/quark. +Dirl is a tiny server for customized directory listings. It is based on +[quark](tools.suckless.org/quark/). -Quark is a small http server. +# Getting Started +Pre-built binaries linked against glibc and musl can be downloaded from +[https://dirlist.friedl.net](https://dirlist.friedl.net/bin/dirl). -# DIRL +In addition alpine based docker images are provided at +[DockerHub](https://hub.docker.com/repository/docker/arminfriedl/dirl). -dirl is a quark extension for customized directory listings. +To start a directory listing just run the binary or start a container. -Per default dirl generates html for a directory listing like this: +# Defaults +Per default dirl generates standard compliant html for a directory listing like +this: ```html @@ -47,7 +52,7 @@ Per default dirl generates html for a directory listing like this: ``` -## Customize +# Customization The default listing can be styled by a `style.css` in the root directory. @@ -69,7 +74,7 @@ For each of these templates you can use placeholders that are replaced by their * `{modified}`: Date the entry was last modified * `{size}`: Size of the entry (if available) -### Subdirectory styling +## Subdirectory styling dirl tries to the closest template for the currently visited path. This gives you the opportunity to override templates in subdirectories. dirl walks the @@ -80,7 +85,7 @@ templates in that directory. In case no templates are found up until and including root, the default templates are used. -### Customize names +## Customize names The files defined as templates and style are ignored in the directory listing itself. In case you need to list one of these directories, or have any other diff --git a/config.mk b/config.mk index 7056241..ed33a27 100644 --- a/config.mk +++ b/config.mk @@ -1,4 +1,4 @@ -# quark version +# dirl version VERSION = 0 # Customize below to fit your system @@ -9,7 +9,7 @@ MANPREFIX = $(PREFIX)/share/man # flags CPPFLAGS = -DVERSION=\"$(VERSION)\" -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os +CFLAGS = -std=c99 -pedantic -Wall -Wextra -Os $(STATIC) LDFLAGS = -s # compiler and linker diff --git a/dirl b/dirl new file mode 100755 index 0000000..358f8fa Binary files /dev/null and b/dirl differ diff --git a/quark.1 b/quark.1 deleted file mode 100644 index 6e0e5f8..0000000 --- a/quark.1 +++ /dev/null @@ -1,131 +0,0 @@ -.Dd 2020-08-23 -.Dt QUARK 1 -.Os suckless.org -.Sh NAME -.Nm quark -.Nd simple static web server -.Sh SYNOPSIS -.Nm -.Fl p Ar port -.Op Fl h Ar host -.Op Fl u Ar user -.Op Fl g Ar group -.Op Fl n Ar num -.Op Fl d Ar dir -.Op Fl l -.Op Fl i Ar file -.Oo Fl v Ar vhost Oc ... -.Oo Fl m Ar map Oc ... -.Nm -.Fl U Ar file -.Op Fl p Ar port -.Op Fl u Ar user -.Op Fl g Ar group -.Op Fl n Ar num -.Op Fl d Ar dir -.Op Fl l -.Op Fl i Ar file -.Oo Fl v Ar vhost Oc ... -.Oo Fl m Ar map Oc ... -.Sh DESCRIPTION -.Nm -is a simple HTTP GET/HEAD-only web server for static content. -It supports virtual hosts (see -.Fl v ) , -explicit redirects (see -.Fl m ) , -directory listings (see -.Fl l ) , -conditional "If-Modified-Since"-requests (RFC 7232), range requests -(RFC 7233) and well-known URIs (RFC 8615), while refusing to serve -hidden files and directories. -.Sh OPTIONS -.Bl -tag -width Ds -.It Fl d Ar dir -Serve -.Ar dir -after chrooting into it. -The default is ".". -.It Fl g Ar group -Set group ID when dropping privileges, and in socket mode the group of the -socket file, to the ID of -.Ar group . -The default is "nogroup". -.It Fl h Ar host -Use -.Ar host -as the server hostname. -The default is the loopback interface (i.e. localhost). -.It Fl i Ar file -Set -.Ar file -as the directory index. -The default is "index.html". -.It Fl l -Enable directory listing. -.It Fl m Ar map -Add the URI prefix mapping rule specified by -.Ar map , -which has the form -.Qq Pa from to [chost] , -where each element is separated with spaces (0x20) that can be -escaped with '\\'. -.Pp -The prefix -.Pa from -of all matching URIs is replaced with -.Pa to , -optionally limited to the canonical virtual host -.Pa chost . -If no virtual hosts are given, -.Pa chost -is ignored. -.It Fl n Ar num -Set the maximum number of threads to -.Ar num . -The default is 512. -.It Fl p Ar port -In host mode, listen on port -.Ar port -for incoming connections. -In socket mode, use -.Ar port -for constructing proper virtual host -redirects on non-standard ports. -.It Fl U Ar file -Create the UNIX-domain socket -.Ar file , -listen on it for incoming connections and remove it on exit. -.It Fl u Ar user -Set user ID when dropping privileges, -and in socket mode the user of the socket file, -to the ID of -.Ar user . -The default is "nobody". -.It Fl v Ar vhost -Add the virtual host specified by -.Ar vhost , -which has the form -.Qq Pa chost regex dir [prefix] , -where each element is separated with spaces (0x20) that can be -escaped with '\\'. -.Pp -A request matching the virtual host regular expression -.Pa regex -(see -.Xr regex 3 ) -is redirected to the canonical host -.Pa chost , -if they differ, using the directory -.Pa dir -as the root directory, optionally prefixing the URI with -.Pa prefix . -If any virtual hosts are specified, all requests on non-matching -hosts are discarded. -.El -.Sh CUSTOMIZATION -.Nm -can be customized by creating a custom config.h from config.def.h and -(re)compiling the source code. This keeps it fast, secure and simple. -.Sh AUTHORS -.An Laslo Hunhold Aq Mt dev@frign.de