diff options
| author | Vincent Douillet <vincent@vdouillet.fr> | 2026-07-10 22:15:00 +0200 |
|---|---|---|
| committer | Vincent Douillet <vincent@vdouillet.fr> | 2026-07-10 22:15:00 +0200 |
| commit | 9669adeceb9cc6ac41ca4ea9b9bc3f89036fc569 (patch) | |
| tree | cfae231b3b4b937fd4e42fa1b5e0f8a95132cec1 | |
| parent | c5c9cc569178e732ff3fb81d74050c18667bdec4 (diff) | |
| -rw-r--r-- | Makefile | 35 | ||||
| -rw-r--r-- | README.md | 24 | ||||
| -rw-r--r-- | browse.c | 5 | ||||
| -rw-r--r-- | browse.h | 4 | ||||
| -rw-r--r-- | cgi.h | 4 | ||||
| -rw-r--r-- | config.h | 4 | ||||
| -rw-r--r-- | create.c | 4 | ||||
| -rw-r--r-- | delete.c | 5 | ||||
| -rw-r--r-- | http.h | 4 | ||||
| -rw-r--r-- | main.c | 2 | ||||
| -rw-r--r-- | upload.c | 6 |
11 files changed, 78 insertions, 19 deletions
@@ -26,11 +26,18 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +# OpenBSD +CHROOT=/var/www +WWW_USER=www +# Linux +#CHROOT= +#WWW_USER=www-data + CC=cc CFLAGS_DEPS != pkg-config --cflags kcgi kcgi-html LDFLAGS_DEPS != pkg-config --libs kcgi kcgi-html -CFLAGS=-DLOG_INFO -std=c89 $(CFLAGS_DEPS) +CFLAGS=-DLOG_INFO -D_POSIX_C_SOURCE=200809L -std=c89 $(CFLAGS_DEPS) LDFLAGS=-static $(LDFLAGS_DEPS) .if make(debug) || make(test) @@ -60,22 +67,22 @@ kcgienv: kcgienv.o $(CC) -o $@ $> $(LDFLAGS) install: - install -D -o www -g www -m 0500 main /var/www/cgi-bin/vault - install -D -o www -g www -m 0440 template/head.html /var/www/usr/share/vault/template/head.html - install -D -o www -g www -m 0440 template/foot.html /var/www/usr/share/vault/template/foot.html - install -D -o www -g www -m 0440 template/browse_head.html /var/www/usr/share/vault/template/browse_head.html - install -D -o www -g www -m 0440 template/browse_foot.html /var/www/usr/share/vault/template/browse_foot.html - install -D -o www -g www -m 0440 template/browse_item.html /var/www/usr/share/vault/template/browse_item.html - install -D -o www -g www -m 0440 template/upload_head.html /var/www/usr/share/vault/template/upload_head.html - install -D -o www -g www -m 0440 template/delete_head.html /var/www/usr/share/vault/template/delete_head.html - install -D -o www -g www -m 0440 template/create_head.html /var/www/usr/share/vault/template/create_head.html - install -D -o www -g www -m 0440 fontawesome-6.5.1/css/fontawesome.css /var/www/vault-static/fontawesome-6.5.1/css/fontawesome.css + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0500 main /var/www/cgi-bin/vault + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/head.html $(CHROOT)/usr/share/vault/template/head.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/foot.html $(CHROOT)/usr/share/vault/template/foot.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/browse_head.html $(CHROOT)/usr/share/vault/template/browse_head.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/browse_foot.html $(CHROOT)/usr/share/vault/template/browse_foot.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/browse_item.html $(CHROOT)/usr/share/vault/template/browse_item.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/upload_head.html $(CHROOT)/usr/share/vault/template/upload_head.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/delete_head.html $(CHROOT)/usr/share/vault/template/delete_head.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 template/create_head.html $(CHROOT)/usr/share/vault/template/create_head.html + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 fontawesome-6.5.1/css/fontawesome.css /var/www/vault-static/fontawesome-6.5.1/css/fontawesome.css gzip -fk /var/www/vault-static/fontawesome-6.5.1/css/fontawesome.css - install -D -o www -g www -m 0440 fontawesome-6.5.1/css/solid.css /var/www/vault-static/fontawesome-6.5.1/css/solid.css + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 fontawesome-6.5.1/css/solid.css /var/www/vault-static/fontawesome-6.5.1/css/solid.css gzip -fk /var/www/vault-static/fontawesome-6.5.1/css/solid.css - install -D -o www -g www -m 0440 fontawesome-6.5.1/webfonts/fa-solid-900.ttf /var/www/vault-static/fontawesome-6.5.1/webfonts/fa-solid-900.ttf + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 fontawesome-6.5.1/webfonts/fa-solid-900.ttf /var/www/vault-static/fontawesome-6.5.1/webfonts/fa-solid-900.ttf gzip -fk /var/www/vault-static/fontawesome-6.5.1/webfonts/fa-solid-900.ttf - install -D -o www -g www -m 0440 fontawesome-6.5.1/webfonts/fa-solid-900.woff2 /var/www/vault-static/fontawesome-6.5.1/webfonts/fa-solid-900.woff2 + install -D -o $(WWW_USER) -g $(WWW_USER) -m 0440 fontawesome-6.5.1/webfonts/fa-solid-900.woff2 /var/www/vault-static/fontawesome-6.5.1/webfonts/fa-solid-900.woff2 gzip -fk /var/www/vault-static/fontawesome-6.5.1/webfonts/fa-solid-900.woff2 clean: @@ -7,7 +7,7 @@ Vault is an opinionated web-based file manager. It is built in C for OpenBSD aro * __simple__: browse, create and delete folders; download and upload files. JavaScript support is optional on the client side and its absence should be handled gracefully. Everything should work from a terminal-based web browser * __fast__: with the server running on an ARM SBC, there should not be any noticeable delay when loading a page -It should also compile and run on any POSIX OS with minor modifications, although this has not been tested (yet). +It should also compile and run on any POSIX OS with minor modifications. On Linux, `bmake(1)` should be used instead of `make(1)`, and configuration should be adjusted in the `Makefile`. Please note that sandboxing is implemented for OpenBSD _only_. ## Configure @@ -20,11 +20,13 @@ Vault comes with a Makefile: $ make # make install -The vault binary will be installed as `/var/www/cgi-bin/vault`. Static resources will be installed in `/var/www/vault-static` and should be served from `/static`. You need to configure your web server accordingly, see below for a sample file. If the log file does not exist, you need to create it. Here is how to do it for a default installation: +The vault binary will be installed as `/var/www/cgi-bin/vault`. Static resources will be installed in `/var/www/vault-static` and should be served from `/static`. You need to configure your web server accordingly, see below for sample files. If the log file does not exist, you need to create it. Here is how to do it for a chrooted web server, like OpenBSD's `httpd(8)`: # touch /var/www/logs/vault.log # chown www /var/www/logs/vault.log +On other operating systems, assuming a web server that is _not_ chrooted, `config.h` sets the log path to `/var/log/vault.log` instead. + By default on OpenBSD, the `slowcgi(8)` daemon allows a timeout of 2 minutes for CGI programs. This might not be enough if you want to allow users to download large files. This timeout can be increased by changing the `slowcgi(8)` parameters in `/etc/rc.conf.local`, for example to allow up to 10 minutes : slowcgi_flags="-t 600" @@ -48,3 +50,21 @@ By default on OpenBSD, the `slowcgi(8)` daemon allows a timeout of 2 minutes for gzip-static } } + +## Sample lighttpd.conf + + server.modules+=("mod_alias", "mod_cgi", "mod_setenv") + server.port=80 + server.document-root="/var/www/html" + server.errorlog="/var/log/lighttpd/error.log" + server.pid-file="/run/lighttpd.pid" + server.username="www-data" + server.groupname="www-data" + index-file.names=("index.html") + + setenv.set-environment=("VAULT_DATA_DIR" => "/var/www/vault-data") + alias.url = ("/static" => "/var/www/vault-static") + $HTTP["url"] =~ "^/vault(?:/|$)" { + alias.url = ("/vault" => "/var/www/cgi-bin/vault") + cgi.assign = ("" => "") + } @@ -28,10 +28,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include <sys/types.h> #include <sys/queue.h> -#include <dirent.h> +#include <stdarg.h> +#include <stdint.h> #include <kcgi.h> +#include <dirent.h> #include <kcgihtml.h> #include <limits.h> #include <stdbool.h> @@ -31,6 +31,10 @@ #ifndef BROWSE_H #define BROWSE_H +#include <sys/types.h> + +#include <stdarg.h> +#include <stdint.h> #include <kcgi.h> #include "file.h" @@ -31,6 +31,10 @@ #ifndef CGI_H #define CGI_H +#include <sys/types.h> + +#include <stdarg.h> +#include <stdint.h> #include <kcgi.h> #define K_OK(kcgi_call, r) \ @@ -36,7 +36,11 @@ * otherwise it will quit with an error. */ #ifndef LOG_FILE +#ifdef __OpenBSD__ #define LOG_FILE "/logs/vault.log" +#else +#define LOG_FILE "/var/log/vault.log" +#endif #endif /* The directory that contains the HTML template files */ @@ -28,6 +28,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include <sys/types.h> + +#include <stdarg.h> +#include <stdint.h> #include <stdlib.h> #include <kcgi.h> #include <kcgihtml.h> @@ -30,9 +30,12 @@ #include <sys/types.h> #include <sys/stat.h> -#include <fts.h> + +#include <stdarg.h> +#include <stdint.h> #include <kcgi.h> #include <kcgihtml.h> +#include <fts.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -31,6 +31,10 @@ #ifndef HTTP_H #define HTTP_H +#include <sys/types.h> + +#include <stdint.h> +#include <stdarg.h> #include <kcgi.h> #include "file.h" @@ -85,6 +85,7 @@ main(void) } /* A bit of security cannot hurt */ +#ifdef __OpenBSD__ if (-1 == unveil(data_dir, "rwc") || -1 == unveil(TEMPLATE_DIR, "r") || -1 == unveil(NULL, NULL)) { @@ -95,6 +96,7 @@ main(void) http_exit(&r, KHTTP_500, "Pledge failed: %s", strerror(errno)); goto end; } +#endif /* __OpenBSD__ */ /* * Make sure basic request parameters are as expected : GET or POST, @@ -28,9 +28,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include <stdlib.h> +#include <sys/types.h> + +#include <stdarg.h> +#include <stdint.h> #include <kcgi.h> #include <kcgihtml.h> +#include <stdlib.h> #include <limits.h> #include <stdio.h> #include <string.h> |
