Blob


2 # NAME
4 **gmid** - dead simple zero configuration gemini server
6 # SYNOPSIS
8 **gmid**
9 \[**-fh**]
10 \[**-c** *cert.pem*]
11 \[**-d** *docs*]
12 \[**-k** *key.pem*]
13 \[**-p** *port*]
14 \[**-x** *cgi-bin*]
16 # DESCRIPTION
18 **gmid**
19 is a very simple and minimal gemini server that can serve static files
20 and execute CGI scripts.
22 **gmid**
23 won't serve files outside the given directory and won't follow
24 symlinks.
25 Furthermore, on
26 OpenBSD,
27 pledge(2)
28 and
29 unveil(2)
30 are used to ensure that
31 **gmid**
32 dosen't do anything else than read files from the given directory,
33 accept network connections and, optionally, execute CGI scripts.
35 **gmid**
36 fully supports IRIs (Internationalized Resource Identifiers, see
37 RFC3987).
39 It should be noted that
40 **gmid**
41 is very simple in its implementation, and so it may not be appropriate
42 for serving sites with lots of users.
43 After all, the code is single threaded and use a single process,
44 although it can handle multiple clients at the same time.
46 If a user request path is a directory,
47 **gmid**
48 will try to serve a
49 *index.gmi*
50 file inside that directory.
52 The options are as follows:
54 **-c** *cert.pem*
56 > The certificate to use, by default is
57 > *cert.pem*.
59 **-d** *docs*
61 > The root directory to serve.
62 > **gmid**
63 > won't serve any file that is outside that directory.
64 > By default is
65 > *docs*.
67 **-f**
69 > stays and log in the foreground, do not daemonize the process.
71 **-h**
73 > Print the usage and exit.
75 **-k** *key.pem*
77 > The key for the certificate, by default is
78 > *key.pem*.
80 **-p** *port*
82 > The port to bind to, by default 1965.
84 **-x** *dir*
86 > Enable execution of CGI scripts inside the given directory (relative
87 > to the document root.) Cannot be provided more than once.
89 # CGI
91 When CGI scripts are enabled for a directory, a request for an
92 executable file will execute it and fed its output to the client.
94 The CGI scripts will inherit the environment from
95 **gmid**
96 with these additional variables set:
98 `SERVER_SOFTWARE`
100 > "gmid"
102 `SERVER_PORT`
104 > "1965"
106 `SCRIPT_NAME`
108 > The (public) path to the script.
110 `SCRIPT_EXECUTABLE`
112 > The full path to the executable.
114 `REQUEST_URI`
116 > The user request (without the query parameters.)
118 `REQUEST_RELATIVE`
120 > The request relative to the script.
122 `QUERY_STRING`
124 > The query parameters.
126 `REMOTE_HOST`
128 > The remote IP address.
130 `REMOTE_ADDR`
132 > The remote IP address.
134 `DOCUMENT_ROOT`
136 > The root directory being served, the one provided with the
137 > *d*
138 > parameter to
139 > **gmid**
141 `AUTH_TYPE`
143 > The string "Certificate" if the client used a certificate, otherwise unset.
145 `REMOTE_USER`
147 > The subject of the client certificate if provided, otherwise unset.
149 `TLS_CLIENT_ISSUER`
151 > The is the issuer of the client certificate if provided, otherwise unset.
153 `TLS_CLIENT_HASH`
155 > The hash of the client certificate if provided, otherwise unset.
156 > The format is "ALGO:HASH".
158 Let's say you have a script in
159 */cgi-bin/script*
160 and the user request is
161 */cgi-bin/script/foo/bar?quux*.
162 Then
163 `SCRIPT_NAME`
164 will be
165 */cgi-bin/script*,
166 `SCRIPT_EXECUTABLE`
167 will be
168 *$DOCUMENT\_ROOT/cgi-bin/script*,
169 `REQUEST_URI`
170 will be
171 */cgi-bin/script/foo/bar*,
172 `REQUEST_RELATIVE`
173 will be
174 *foo/bar and*
175 `QUERY_STRING`
176 will be
177 *quux*.
179 # EXAMPLES
181 To quickly getting started
183 $ # generate a cert and a key
184 $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \
185 -out cert.pem -days 365 -nodes
186 $ mkdir docs
187 $ cat <<EOF > docs/index.gmi
188 # Hello world
189 test paragraph...
190 EOF
191 $ gmid -c cert.pem -k key.pem -d docs
193 Now you can visit gemini://localhost/ with your preferred gemini
194 client.
196 To add some CGI scripts, assuming a setup similar to the previous
197 example, you can
199 $ mkdir docs/cgi-bin
200 $ cat <<EOF > docs/cgi-bin/hello-world
201 #!/bin/sh
202 printf "20 text/plain\r\n"
203 echo "hello world!"
204 EOF
205 $ gmid -x cgi-bin
207 Note that the argument to the
208 **-x**
209 option is
210 *cgi-bin*
211 and not
212 *docs/cgi-bin*,
213 since it's relative to the document root.
215 # ACKNOWLEDGEMENTS
217 **gmid**
218 uses the "Flexible and Economical" UTF-8 decoder written by
219 Bjoern Hoehrmann.
221 # CAVEATS
223 * it doesn't support virtual hosts: the host part of the request URL is
224 completely ignored.
226 * a %2F sequence in the path part is indistinguishable from a literal
227 slash: this is not RFC3986-compliant.
229 * a %00 sequence either in the path or in the query part is treated as
230 invalid character and thus rejected.