Blob


1 .\" Copyright (c) 2020 Omar Polo <op@omarpolo.com>
2 .\"
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
6 .\"
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 .Dd $Mdocdate: October 2 2020$
15 .Dt GMIND 1
16 .Os
17 .Sh NAME
18 .Nm gmid
19 .Nd dead simple zero configuration gemini server
20 .Sh SYNOPSIS
21 .Nm
22 .Bk -words
23 .Op Fl h
24 .Op Fl c Ar cert.pem
25 .Op Fl d Ar docs
26 .Op Fl k Ar key.pem
27 .Op Fl l Ar logfile
28 .Op Fl x Ar cgi-bin
29 .Ek
30 .Sh DESCRIPTION
31 .Nm
32 is a very simple and minimal gemini server that can serve static files
33 and execute CGI scripts.
34 .Pp
35 .Nm
36 will strip any sequence of
37 .Pa ../
38 or trailing
39 .Pa ..
40 in the requests made by clients, so it's impossible to serve content
41 outside the
42 .Pa docs
43 directory by mistake, and will also refuse to follow symlinks.
44 Furthermore, on
45 .Ox ,
46 .Xr pledge 2
47 and
48 .Xr unveil 2
49 are used to ensure that
50 .Nm
51 dosen't do anything else than read files from the given directory,
52 accept network connections and, optionally, execute CGI scripts.
53 .Pp
54 It should be noted that
55 .Nm
56 is very simple in its implementation, and so it may not be appropriate
57 for serving sites with lots of users.
58 After all, the code is single threaded and use a single process,
59 although it can handle multiple requests concurrently.
60 .Pp
61 If a user request path is a directory,
62 .Nm
63 will try to serve a
64 .Pa index.gmi
65 file inside that directory.
66 If not found, it will return an error 51 (not found) to the user.
67 .Pp
68 The options are as follows:
69 .Bl -tag -width 12m
70 .It Fl c Ar cert.pem
71 The certificate to use, by default is
72 .Pa cert.pem .
73 .It Fl d Ar docs
74 The root directory to serve.
75 .Nm
76 won't serve any file that is outside that directory, by default
77 .Pa docs .
78 .It Fl h
79 Print the usage and exit.
80 .It Fl k Ar key.pem
81 The key for the certificate, by default is
82 .Pa key.pem .
83 .It Fl l Ar logfile
84 log to the given file instead of the standard error.
85 .It Fl x Ar dir
86 Enable execution of CGI scripts inside the given directory (relative
87 to the document root.) Cannot be provided more than once.
88 .El
89 .Sh CGI
90 When CGI scripts are enabled for a directory, a request for an
91 executable file will execute it and fed its output to the client.
92 .Pp
93 The CGI scripts will inherit the environment from
94 .Nm
95 with these additional variables set:
96 .Bl -tag -width 15m
97 .It Ev SERVER_SOFTWARE
98 "gmid"
99 .It Ev SERVER_PROTOCOL
100 "gemini"
101 .It Ev SERVER_PORT
102 "1965"
103 .It Ev PATH_INFO
104 the request path
105 .It Ev PATH_TRANSLATED
106 the full path: the concatenation of the document root and the request
107 path
108 .It Ev QUERY_STRING
109 the query string if present in the request URL, otherwise it
110 won't be set.
111 .It Ev REMOTE_ADDR
112 the IP address of the client in dot notation
113 .El
114 .Sh EXAMPLES
115 To quickly getting started
116 .Bd -literal -offset indent
117 $ # generate a cert and a key
118 $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \\
119 -out cert.pem -days 365 -nodes
120 $ mkdir docs
121 $ cat <<EOF > docs/index.gmi
122 # Hello world
123 test paragraph...
124 EOF
125 $ gmid -c cert.pem -k key.pem -d docs
126 .Ed
127 .Pp
128 Now you can visit gemini://localhost/ with your preferred gemini
129 client.
130 .Pp
131 To add some CGI scripts, assuming a setup similar to the previous
132 example, you can
133 .Bd -literal -offset indent
134 $ mkdir docs/cgi-bin
135 $ cat <<EOF > docs/cgi-bin/hello-world
136 #!/bin/sh
137 printf "20 text/plain\\r\\n"
138 echo "hello world!"
139 EOF
140 $ gmid -x cgi-bin
141 .Ed
142 .Pp
143 Note that the argument to the
144 .Fl x
145 option is
146 .Pa cgi-bin
147 and not
148 .Pa docs/cgi-bin ,
149 since it’s relative to the document root.
150 .Sh CAVEATS
151 .Bl -bullet
152 .It
153 it doesn't support virtual hosts: the host part of the request URL is
154 completely ignored.
155 .It
156 it doesn't fork in the background or anything like that.
157 .El