From a20136fa18dba7fd44812be235010a4517aef783 Mon Sep 17 00:00:00 2001 From: Laslo Hunhold Date: Mon, 5 Mar 2018 09:51:29 +0100 Subject: [PATCH] Update the documentation to reflect the new flag-centric usage --- http.c | 2 +- main.c | 8 ++-- quark.1 | 127 ++++++++++++++++++++++++++++++++++++++++---------------- util.h | 2 +- 4 files changed, 97 insertions(+), 42 deletions(-) diff --git a/http.c b/http.c index 118389b..12ebde8 100644 --- a/http.c +++ b/http.c @@ -336,7 +336,7 @@ http_send_response(int fd, struct request *r) return http_send_status(fd, (errno == EACCES) ? S_FORBIDDEN : S_NOT_FOUND); } - vhostmatch = s.vhost[i].name; + vhostmatch = s.vhost[i].chost; break; } } diff --git a/main.c b/main.c index bce74a0..9985d31 100644 --- a/main.c +++ b/main.c @@ -94,10 +94,10 @@ static void usage(void) { const char *opts = "[-u user] [-g group] [-n num] [-d dir] [-l] " - "[-i index] [-v vhost] ... [-m map] ..."; + "[-i file] [-v vhost] ... [-m map] ..."; - die("usage: %s -h host -p port %s\n" - " %s -U socket [-p port] %s", argv0, + die("usage: %s -h host -p port %s\n" + " %s -U file [-p port] %s", argv0, opts, argv0, opts); } @@ -170,7 +170,7 @@ main(int argc, char *argv[]) sizeof(struct vhost)))) { die("reallocarray:"); } - if (!(s.vhost[s.vhost_len - 1].name = strtok(tok, " ")) || + if (!(s.vhost[s.vhost_len - 1].chost = strtok(tok, " ")) || !(s.vhost[s.vhost_len - 1].regex = strtok(NULL, " ")) || !(s.vhost[s.vhost_len - 1].dir = strtok(NULL, " ")) || !(s.vhost[s.vhost_len - 1].prefix = strtok(NULL, " ")) || diff --git a/quark.1 b/quark.1 index 304dd0f..7179a86 100644 --- a/quark.1 +++ b/quark.1 @@ -1,65 +1,120 @@ -.Dd 2018-02-05 +.Dd 2018-03-05 .Dt QUARK 1 +.Os suckless.org .Sh NAME .Nm quark -.Nd simple web server +.Nd simple static web server .Sh SYNOPSIS .Nm -.Op Fl l | L -.Op Fl v | V -.Oo -.Oo -.Op Fl h Ar host -.Op Fl p Ar port -.Oc -| -.Op Fl U Ar sockfile -.Oc -.Op Fl d Ar dir +.Fl h Ar host +.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 ... +.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 only web server that can be multiplexed using -UNIX-domain sockets. +is a simple HTTP GET/HEAD-only web server for static content. .Sh OPTIONS .Bl -tag -width Ds .It Fl d Ar dir Serve .Ar dir after chrooting into it. -.It Fl l -Disable directory listing. -.It Fl L -Enable directory listing. +The default is ".". .It Fl g Ar group -Set group ID to the ID of -.Ar group -when dropping privileges. +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. +.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 target prefix mapping rule specified by +.Ar map , +which has the form +.Qq Pa chost from to , +where each element is separated with whitespace. +.Pp +The prefix +.Pa from +of all matching targets, especially only of those requests for the canonical +virtual host +.Pa chost +when virtual hosts are specified, is then replaced with +.Pa to . +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 -Listen on port +In host mode, listen on port .Ar port for incoming connections. -.It Fl u Ar user -Set user ID to the ID of -.Ar user -when dropping privileges. -.It Fl U Ar sockfile -Create the UNIX-domain socket file -.Ar sockfile , +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. -Its user and group owners are equal to the user and group IDs used for dropping -privileges to. -.It Fl v -Disable virtual hosts. -.It Fl V -Enable virtual hosts. +.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 whitespace. +.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 target 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 diff --git a/util.h b/util.h index 8408ce3..12b7bd8 100644 --- a/util.h +++ b/util.h @@ -10,7 +10,7 @@ /* main server struct */ struct vhost { - char *name; + char *chost; char *regex; char *dir; char *prefix;