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