Blame


1 3e4749f7 2020-10-02 op
2 3e4749f7 2020-10-02 op # NAME
3 3e4749f7 2020-10-02 op
4 fab952e1 2020-10-03 op **gmid** - dead simple zero configuration gemini server
5 3e4749f7 2020-10-02 op
6 3e4749f7 2020-10-02 op # SYNOPSIS
7 3e4749f7 2020-10-02 op
8 3e4749f7 2020-10-02 op **gmid**
9 d7802bb4 2020-12-02 op \[**-fh**]
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*]
15 3e4749f7 2020-10-02 op
16 3e4749f7 2020-10-02 op # DESCRIPTION
17 3e4749f7 2020-10-02 op
18 3e4749f7 2020-10-02 op **gmid**
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.
21 3e4749f7 2020-10-02 op
22 3e4749f7 2020-10-02 op **gmid**
23 3e4749f7 2020-10-02 op will strip any sequence of
24 3e4749f7 2020-10-02 op *../*
25 3e4749f7 2020-10-02 op or trailing
26 3e4749f7 2020-10-02 op *..*
27 a5d310bc 2020-11-10 op in the requests made by clients and will refuse to follow symlinks.
28 6980aad6 2020-10-02 op Furthermore, on
29 6980aad6 2020-10-02 op OpenBSD,
30 6980aad6 2020-10-02 op pledge(2)
31 3e4749f7 2020-10-02 op and
32 6980aad6 2020-10-02 op unveil(2)
33 3e4749f7 2020-10-02 op are used to ensure that
34 3e4749f7 2020-10-02 op **gmid**
35 92e66347 2020-11-06 op dosen't do anything else than read files from the given directory,
36 92e66347 2020-11-06 op accept network connections and, optionally, execute CGI scripts.
37 3e4749f7 2020-10-02 op
38 3e4749f7 2020-10-02 op It should be noted that
39 3e4749f7 2020-10-02 op **gmid**
40 3e4749f7 2020-10-02 op is very simple in its implementation, and so it may not be appropriate
41 92e66347 2020-11-06 op for serving sites with lots of users.
42 92e66347 2020-11-06 op After all, the code is single threaded and use a single process,
43 83000e2d 2020-12-21 op although it can handle multiple clients at the same time.
44 3e4749f7 2020-10-02 op
45 fab952e1 2020-10-03 op If a user request path is a directory,
46 fab952e1 2020-10-03 op **gmid**
47 fab952e1 2020-10-03 op will try to serve a
48 fab952e1 2020-10-03 op *index.gmi*
49 fab952e1 2020-10-03 op file inside that directory.
50 fab952e1 2020-10-03 op
51 3e4749f7 2020-10-02 op The options are as follows:
52 3e4749f7 2020-10-02 op
53 3e4749f7 2020-10-02 op **-c** *cert.pem*
54 3e4749f7 2020-10-02 op
55 3e4749f7 2020-10-02 op > The certificate to use, by default is
56 fab952e1 2020-10-03 op > *cert.pem*.
57 3e4749f7 2020-10-02 op
58 3e4749f7 2020-10-02 op **-d** *docs*
59 3e4749f7 2020-10-02 op
60 3e4749f7 2020-10-02 op > The root directory to serve.
61 3e4749f7 2020-10-02 op > **gmid**
62 a5d310bc 2020-11-10 op > won't serve any file that is outside that directory.
63 a5d310bc 2020-11-10 op > By default is
64 92e66347 2020-11-06 op > *docs*.
65 3e4749f7 2020-10-02 op
66 d7802bb4 2020-12-02 op **-f**
67 d7802bb4 2020-12-02 op
68 d7802bb4 2020-12-02 op > stays and log in the foreground, do not daemonize the process.
69 d7802bb4 2020-12-02 op
70 3e4749f7 2020-10-02 op **-h**
71 3e4749f7 2020-10-02 op
72 fab952e1 2020-10-03 op > Print the usage and exit.
73 3e4749f7 2020-10-02 op
74 3e4749f7 2020-10-02 op **-k** *key.pem*
75 3e4749f7 2020-10-02 op
76 3e4749f7 2020-10-02 op > The key for the certificate, by default is
77 fab952e1 2020-10-03 op > *key.pem*.
78 3e4749f7 2020-10-02 op
79 721e2325 2020-11-18 op **-p** *port*
80 721e2325 2020-11-18 op
81 721e2325 2020-11-18 op > The port to bind to, by default 1965.
82 721e2325 2020-11-18 op
83 0ed56567 2020-11-06 op **-x** *dir*
84 72342dc9 2020-11-06 op
85 0ed56567 2020-11-06 op > Enable execution of CGI scripts inside the given directory (relative
86 0ed56567 2020-11-06 op > to the document root.) Cannot be provided more than once.
87 72342dc9 2020-11-06 op
88 72342dc9 2020-11-06 op # CGI
89 72342dc9 2020-11-06 op
90 0ed56567 2020-11-06 op When CGI scripts are enabled for a directory, a request for an
91 0ed56567 2020-11-06 op executable file will execute it and fed its output to the client.
92 72342dc9 2020-11-06 op
93 92e66347 2020-11-06 op The CGI scripts will inherit the environment from
94 92e66347 2020-11-06 op **gmid**
95 92e66347 2020-11-06 op with these additional variables set:
96 92e66347 2020-11-06 op
97 92e66347 2020-11-06 op `SERVER_SOFTWARE`
98 92e66347 2020-11-06 op
99 92e66347 2020-11-06 op > "gmid"
100 92e66347 2020-11-06 op
101 92e66347 2020-11-06 op `SERVER_PORT`
102 92e66347 2020-11-06 op
103 92e66347 2020-11-06 op > "1965"
104 92e66347 2020-11-06 op
105 a5d310bc 2020-11-10 op `SCRIPT_NAME`
106 92e66347 2020-11-06 op
107 a5d310bc 2020-11-10 op > The (public) path to the script.
108 92e66347 2020-11-06 op
109 a5d310bc 2020-11-10 op `SCRIPT_EXECUTABLE`
110 92e66347 2020-11-06 op
111 a5d310bc 2020-11-10 op > The full path to the executable.
112 92e66347 2020-11-06 op
113 a5d310bc 2020-11-10 op `REQUEST_URI`
114 a5d310bc 2020-11-10 op
115 a5d310bc 2020-11-10 op > The user request (without the query parameters.)
116 a5d310bc 2020-11-10 op
117 a5d310bc 2020-11-10 op `REQUEST_RELATIVE`
118 a5d310bc 2020-11-10 op
119 a5d310bc 2020-11-10 op > The request relative to the script.
120 a5d310bc 2020-11-10 op
121 92e66347 2020-11-06 op `QUERY_STRING`
122 92e66347 2020-11-06 op
123 a5d310bc 2020-11-10 op > The query parameters.
124 92e66347 2020-11-06 op
125 a5d310bc 2020-11-10 op `REMOTE_HOST`
126 92e66347 2020-11-06 op
127 a5d310bc 2020-11-10 op > The remote IP address.
128 92e66347 2020-11-06 op
129 677afbd3 2020-12-02 op `REMOTE_ADDR`
130 677afbd3 2020-12-02 op
131 677afbd3 2020-12-02 op > The remote IP address.
132 677afbd3 2020-12-02 op
133 a5d310bc 2020-11-10 op `DOCUMENT_ROOT`
134 a5d310bc 2020-11-10 op
135 a5d310bc 2020-11-10 op > The root directory being served, the one provided with the
136 a5d310bc 2020-11-10 op > *d*
137 a5d310bc 2020-11-10 op > parameter to
138 a5d310bc 2020-11-10 op > **gmid**
139 a5d310bc 2020-11-10 op
140 677afbd3 2020-12-02 op `AUTH_TYPE`
141 677afbd3 2020-12-02 op
142 677afbd3 2020-12-02 op > The string "Certificate" if the client used a certificate, otherwise unset.
143 677afbd3 2020-12-02 op
144 677afbd3 2020-12-02 op `REMOTE_USER`
145 677afbd3 2020-12-02 op
146 677afbd3 2020-12-02 op > The subject of the client certificate if provided, otherwise unset.
147 677afbd3 2020-12-02 op
148 677afbd3 2020-12-02 op `TLS_CLIENT_ISSUER`
149 677afbd3 2020-12-02 op
150 677afbd3 2020-12-02 op > The is the issuer of the client certificate if provided, otherwise unset.
151 677afbd3 2020-12-02 op
152 677afbd3 2020-12-02 op `TLS_CLIENT_HASH`
153 677afbd3 2020-12-02 op
154 677afbd3 2020-12-02 op > The hash of the client certificate if provided, otherwise unset.
155 677afbd3 2020-12-02 op > The format is "ALGO:HASH".
156 677afbd3 2020-12-02 op
157 a5d310bc 2020-11-10 op Let's say you have a script in
158 a5d310bc 2020-11-10 op */cgi-bin/script*
159 a5d310bc 2020-11-10 op and the user request is
160 a5d310bc 2020-11-10 op */cgi-bin/script/foo/bar?quux*.
161 a5d310bc 2020-11-10 op Then
162 a5d310bc 2020-11-10 op `SCRIPT_NAME`
163 a5d310bc 2020-11-10 op will be
164 a5d310bc 2020-11-10 op */cgi-bin/script*,
165 a5d310bc 2020-11-10 op `SCRIPT_EXECUTABLE`
166 a5d310bc 2020-11-10 op will be
167 a5d310bc 2020-11-10 op *$DOCUMENT\_ROOT/cgi-bin/script*,
168 a5d310bc 2020-11-10 op `REQUEST_URI`
169 a5d310bc 2020-11-10 op will be
170 a5d310bc 2020-11-10 op */cgi-bin/script/foo/bar*,
171 a5d310bc 2020-11-10 op `REQUEST_RELATIVE`
172 a5d310bc 2020-11-10 op will be
173 a5d310bc 2020-11-10 op *foo/bar and*
174 a5d310bc 2020-11-10 op `QUERY_STRING`
175 a5d310bc 2020-11-10 op will be
176 a5d310bc 2020-11-10 op *quux*.
177 a5d310bc 2020-11-10 op
178 3e4749f7 2020-10-02 op # EXAMPLES
179 3e4749f7 2020-10-02 op
180 3e4749f7 2020-10-02 op To quickly getting started
181 3e4749f7 2020-10-02 op
182 3e4749f7 2020-10-02 op $ # generate a cert and a key
183 3e4749f7 2020-10-02 op $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \
184 3e4749f7 2020-10-02 op -out cert.pem -days 365 -nodes
185 3e4749f7 2020-10-02 op $ mkdir docs
186 3e4749f7 2020-10-02 op $ cat <<EOF > docs/index.gmi
187 3e4749f7 2020-10-02 op # Hello world
188 3e4749f7 2020-10-02 op test paragraph...
189 3e4749f7 2020-10-02 op EOF
190 3e4749f7 2020-10-02 op $ gmid -c cert.pem -k key.pem -d docs
191 3e4749f7 2020-10-02 op
192 92e66347 2020-11-06 op Now you can visit gemini://localhost/ with your preferred gemini
193 0ed56567 2020-11-06 op client.
194 3e4749f7 2020-10-02 op
195 0ed56567 2020-11-06 op To add some CGI scripts, assuming a setup similar to the previous
196 92e66347 2020-11-06 op example, you can
197 0ed56567 2020-11-06 op
198 0ed56567 2020-11-06 op $ mkdir docs/cgi-bin
199 0ed56567 2020-11-06 op $ cat <<EOF > docs/cgi-bin/hello-world
200 0ed56567 2020-11-06 op #!/bin/sh
201 92e66347 2020-11-06 op printf "20 text/plain\r\n"
202 0ed56567 2020-11-06 op echo "hello world!"
203 0ed56567 2020-11-06 op EOF
204 92e66347 2020-11-06 op $ gmid -x cgi-bin
205 0ed56567 2020-11-06 op
206 92e66347 2020-11-06 op Note that the argument to the
207 0ed56567 2020-11-06 op **-x**
208 0ed56567 2020-11-06 op option is
209 0ed56567 2020-11-06 op *cgi-bin*
210 0ed56567 2020-11-06 op and not
211 0ed56567 2020-11-06 op *docs/cgi-bin*,
212 a5d310bc 2020-11-10 op since it's relative to the document root.
213 0ed56567 2020-11-06 op
214 3e4749f7 2020-10-02 op # CAVEATS
215 3e4749f7 2020-10-02 op
216 fab952e1 2020-10-03 op * it doesn't support virtual hosts: the host part of the request URL is
217 3e4749f7 2020-10-02 op completely ignored.
218 3e4749f7 2020-10-02 op
219 043acc97 2020-12-25 op * a %2F sequence in the path part is indistinguishable from a literal
220 043acc97 2020-12-25 op slash: this is not RFC3986-compliant.
221 043acc97 2020-12-25 op