gmid/gmid.1

209 lines
5.2 KiB
Groff
Raw Normal View History

2020-10-02 19:39:00 +02:00
.\" Copyright (c) 2020 Omar Polo <op@omarpolo.com>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.Dd $Mdocdate: October 2 2020$
.Dt GMIND 1
.Os
.Sh NAME
.Nm gmid
2020-10-03 17:49:09 +02:00
.Nd dead simple zero configuration gemini server
2020-10-02 19:39:00 +02:00
.Sh SYNOPSIS
.Nm
.Bk -words
.Op Fl n
.Op Fl c Ar config
|
.Op Fl 6fh
.Op Fl C Ar cert
.Op Fl d Ar root
.Op Fl K Ar key
2020-11-18 09:12:27 +01:00
.Op Fl p Ar port
2020-11-06 18:11:45 +01:00
.Op Fl x Ar cgi-bin
2020-10-02 19:39:00 +02:00
.Ek
.Sh DESCRIPTION
.Nm
2021-01-11 13:51:25 +01:00
is a simple and minimal gemini server that can serve static files and
execute CGI scripts.
2020-10-02 19:39:00 +02:00
.Pp
.Nm
won't serve files outside the given directory and won't follow
symlinks.
Furthermore, on
.Ox ,
.Xr pledge 2
2020-10-02 19:39:00 +02:00
and
.Xr unveil 2
2020-10-02 19:39:00 +02:00
are used to ensure that
.Nm
2020-11-06 18:11:45 +01:00
dosen't do anything else than read files from the given directory,
accept network connections and, optionally, execute CGI scripts.
2020-10-02 19:39:00 +02:00
.Pp
.Nm
fully supports IRIs (Internationalized Resource Identifiers, see
RFC3987).
.Pp
2020-10-02 19:39:00 +02:00
It should be noted that
.Nm
is very simple in its implementation, and so it may not be appropriate
2020-11-06 18:11:45 +01:00
for serving sites with lots of users.
After all, the code is single threaded and use a single process,
although it can handle multiple clients at the same time.
2020-10-02 19:39:00 +02:00
.Pp
2020-10-03 17:49:09 +02:00
If a user request path is a directory,
.Nm
will try to serve a
.Pa index.gmi
file inside that directory.
.Pp
2020-10-02 19:39:00 +02:00
The options are as follows:
.Bl -tag -width 12m
.It Fl 6
Enable IPv6.
2020-10-02 19:39:00 +02:00
.It Fl c Ar cert.pem
The certificate to use, by default is
2020-10-03 17:49:09 +02:00
.Pa cert.pem .
2020-10-02 19:39:00 +02:00
.It Fl d Ar docs
The root directory to serve.
.Nm
won't serve any file that is outside that directory.
By default is
2020-11-06 18:11:45 +01:00
.Pa docs .
.It Fl f
stays and log in the foreground, do not daemonize the process.
2020-10-02 19:39:00 +02:00
.It Fl h
2020-10-03 17:49:09 +02:00
Print the usage and exit.
2020-10-02 19:39:00 +02:00
.It Fl k Ar key.pem
The key for the certificate, by default is
2020-10-03 17:49:09 +02:00
.Pa key.pem .
2020-11-18 09:12:27 +01:00
.It Fl p Ar port
The port to bind to, by default 1965.
2020-11-06 18:11:45 +01:00
.It Fl x Ar dir
Enable execution of CGI scripts inside the given directory (relative
to the document root.) Cannot be provided more than once.
2020-10-02 19:39:00 +02:00
.El
.Sh CGI
2020-11-06 18:11:45 +01:00
When CGI scripts are enabled for a directory, a request for an
executable file will execute it and fed its output to the client.
.Pp
2020-11-06 18:11:45 +01:00
The CGI scripts will inherit the environment from
.Nm
with these additional variables set:
.Bl -tag -width 18m
2020-11-06 18:11:45 +01:00
.It Ev SERVER_SOFTWARE
"gmid"
.It Ev SERVER_PORT
"1965"
.It Ev SCRIPT_NAME
The (public) path to the script.
.It Ev SCRIPT_EXECUTABLE
The full path to the executable.
.It Ev REQUEST_URI
The user request (without the query parameters.)
.It Ev REQUEST_RELATIVE
The request relative to the script.
2020-11-06 18:11:45 +01:00
.It Ev QUERY_STRING
The query parameters.
.It Ev REMOTE_HOST
The remote IP address.
.It Ev REMOTE_ADDR
The remote IP address.
.It Ev DOCUMENT_ROOT
The root directory being served, the one provided with the
.Ar d
parameter to
.Nm
.It Ev AUTH_TYPE
The string "Certificate" if the client used a certificate, otherwise unset.
.It Ev REMOTE_USER
The subject of the client certificate if provided, otherwise unset.
.It Ev TLS_CLIENT_ISSUER
The is the issuer of the client certificate if provided, otherwise unset.
.It Ev TLS_CLIENT_HASH
The hash of the client certificate if provided, otherwise unset.
The format is "ALGO:HASH".
2020-11-06 18:11:45 +01:00
.El
.Pp
Let's say you have a script in
.Pa /cgi-bin/script
and the user request is
.Pa /cgi-bin/script/foo/bar?quux .
Then
.Ev SCRIPT_NAME
will be
2021-01-11 13:51:25 +01:00
.Pa cgi-bin/script ,
.Ev SCRIPT_EXECUTABLE
will be
.Pa $DOCUMENT_ROOT/cgi-bin/script ,
.Ev REQUEST_URI
will be
2021-01-11 13:51:25 +01:00
.Pa cgi-bin/script/foo/bar ,
.Ev REQUEST_RELATIVE
will be
2021-01-11 13:51:25 +01:00
.Pa foo/bar
and
.Ev QUERY_STRING
will be
.Ar quux .
2020-10-02 19:39:00 +02:00
.Sh EXAMPLES
To quickly getting started
.Bd -literal -offset indent
2020-10-02 19:39:00 +02:00
$ # generate a cert and a key
$ openssl req -x509 -newkey rsa:4096 -keyout key.pem \\
-out cert.pem -days 365 -nodes
$ mkdir docs
$ cat <<EOF > docs/index.gmi
# Hello world
test paragraph...
EOF
$ gmid -c cert.pem -k key.pem -d docs
.Ed
2020-10-02 19:39:00 +02:00
.Pp
2020-11-06 18:11:45 +01:00
Now you can visit gemini://localhost/ with your preferred gemini
client.
.Pp
To add some CGI scripts, assuming a setup similar to the previous
example, you can
.Bd -literal -offset indent
$ mkdir docs/cgi-bin
$ cat <<EOF > docs/cgi-bin/hello-world
#!/bin/sh
printf "20 text/plain\\r\\n"
echo "hello world!"
EOF
$ gmid -x cgi-bin
.Ed
.Pp
Note that the argument to the
.Fl x
option is
.Pa cgi-bin
and not
.Pa docs/cgi-bin ,
since it's relative to the document root.
.Sh ACKNOWLEDGEMENTS
.Nm
uses the "Flexible and Economical" UTF-8 decoder written by
.An Bjoern Hoehrmann .
2020-10-02 19:39:00 +02:00
.Sh CAVEATS
.Bl -bullet
.It
2020-10-03 17:49:09 +02:00
it doesn't support virtual hosts: the host part of the request URL is
2020-10-02 19:39:00 +02:00
completely ignored.
2020-12-25 13:15:15 +01:00
.It
a %2F sequence in the path part is indistinguishable from a literal
slash: this is not RFC3986-compliant.
2020-12-26 00:37:43 +01:00
.It
a %00 sequence either in the path or in the query part is treated as
invalid character and thus rejected.
2020-10-02 19:39:00 +02:00
.El