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 92e66347 2020-11-06 op \[**-h**]
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 92e66347 2020-11-06 op \[**-l** *logfile*]
14 721e2325 2020-11-18 op \[**-p** *port*]
15 92e66347 2020-11-06 op \[**-x** *cgi-bin*]
16 3e4749f7 2020-10-02 op
17 3e4749f7 2020-10-02 op # DESCRIPTION
18 3e4749f7 2020-10-02 op
19 3e4749f7 2020-10-02 op **gmid**
20 92e66347 2020-11-06 op is a very simple and minimal gemini server that can serve static files
21 92e66347 2020-11-06 op and execute CGI scripts.
22 3e4749f7 2020-10-02 op
23 3e4749f7 2020-10-02 op **gmid**
24 3e4749f7 2020-10-02 op will strip any sequence of
25 3e4749f7 2020-10-02 op *../*
26 3e4749f7 2020-10-02 op or trailing
27 3e4749f7 2020-10-02 op *..*
28 a5d310bc 2020-11-10 op in the requests made by clients and will refuse to follow symlinks.
29 6980aad6 2020-10-02 op Furthermore, on
30 6980aad6 2020-10-02 op OpenBSD,
31 6980aad6 2020-10-02 op pledge(2)
32 3e4749f7 2020-10-02 op and
33 6980aad6 2020-10-02 op unveil(2)
34 3e4749f7 2020-10-02 op are used to ensure that
35 3e4749f7 2020-10-02 op **gmid**
36 92e66347 2020-11-06 op dosen't do anything else than read files from the given directory,
37 92e66347 2020-11-06 op accept network connections and, optionally, execute CGI scripts.
38 3e4749f7 2020-10-02 op
39 3e4749f7 2020-10-02 op It should be noted that
40 3e4749f7 2020-10-02 op **gmid**
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 92e66347 2020-11-06 op although it can handle multiple requests concurrently.
45 3e4749f7 2020-10-02 op
46 fab952e1 2020-10-03 op If a user request path is a directory,
47 fab952e1 2020-10-03 op **gmid**
48 fab952e1 2020-10-03 op will try to serve a
49 fab952e1 2020-10-03 op *index.gmi*
50 fab952e1 2020-10-03 op file inside that directory.
51 fab952e1 2020-10-03 op
52 3e4749f7 2020-10-02 op The options are as follows:
53 3e4749f7 2020-10-02 op
54 3e4749f7 2020-10-02 op **-c** *cert.pem*
55 3e4749f7 2020-10-02 op
56 3e4749f7 2020-10-02 op > The certificate to use, by default is
57 fab952e1 2020-10-03 op > *cert.pem*.
58 3e4749f7 2020-10-02 op
59 3e4749f7 2020-10-02 op **-d** *docs*
60 3e4749f7 2020-10-02 op
61 3e4749f7 2020-10-02 op > The root directory to serve.
62 3e4749f7 2020-10-02 op > **gmid**
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
65 92e66347 2020-11-06 op > *docs*.
66 3e4749f7 2020-10-02 op
67 3e4749f7 2020-10-02 op **-h**
68 3e4749f7 2020-10-02 op
69 fab952e1 2020-10-03 op > Print the usage and exit.
70 3e4749f7 2020-10-02 op
71 3e4749f7 2020-10-02 op **-k** *key.pem*
72 3e4749f7 2020-10-02 op
73 3e4749f7 2020-10-02 op > The key for the certificate, by default is
74 fab952e1 2020-10-03 op > *key.pem*.
75 3e4749f7 2020-10-02 op
76 92e66347 2020-11-06 op **-l** *logfile*
77 2c3a40fa 2020-11-06 op
78 2c3a40fa 2020-11-06 op > log to the given file instead of the standard error.
79 2c3a40fa 2020-11-06 op
80 721e2325 2020-11-18 op **-p** *port*
81 721e2325 2020-11-18 op
82 721e2325 2020-11-18 op > The port to bind to, by default 1965.
83 721e2325 2020-11-18 op
84 0ed56567 2020-11-06 op **-x** *dir*
85 72342dc9 2020-11-06 op
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.
88 72342dc9 2020-11-06 op
89 72342dc9 2020-11-06 op # CGI
90 72342dc9 2020-11-06 op
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.
93 72342dc9 2020-11-06 op
94 92e66347 2020-11-06 op The CGI scripts will inherit the environment from
95 92e66347 2020-11-06 op **gmid**
96 92e66347 2020-11-06 op with these additional variables set:
97 92e66347 2020-11-06 op
98 92e66347 2020-11-06 op `SERVER_SOFTWARE`
99 92e66347 2020-11-06 op
100 92e66347 2020-11-06 op > "gmid"
101 92e66347 2020-11-06 op
102 92e66347 2020-11-06 op `SERVER_PORT`
103 92e66347 2020-11-06 op
104 92e66347 2020-11-06 op > "1965"
105 92e66347 2020-11-06 op
106 a5d310bc 2020-11-10 op `SCRIPT_NAME`
107 92e66347 2020-11-06 op
108 a5d310bc 2020-11-10 op > The (public) path to the script.
109 92e66347 2020-11-06 op
110 a5d310bc 2020-11-10 op `SCRIPT_EXECUTABLE`
111 92e66347 2020-11-06 op
112 a5d310bc 2020-11-10 op > The full path to the executable.
113 92e66347 2020-11-06 op
114 a5d310bc 2020-11-10 op `REQUEST_URI`
115 a5d310bc 2020-11-10 op
116 a5d310bc 2020-11-10 op > The user request (without the query parameters.)
117 a5d310bc 2020-11-10 op
118 a5d310bc 2020-11-10 op `REQUEST_RELATIVE`
119 a5d310bc 2020-11-10 op
120 a5d310bc 2020-11-10 op > The request relative to the script.
121 a5d310bc 2020-11-10 op
122 92e66347 2020-11-06 op `QUERY_STRING`
123 92e66347 2020-11-06 op
124 a5d310bc 2020-11-10 op > The query parameters.
125 92e66347 2020-11-06 op
126 a5d310bc 2020-11-10 op `REMOTE_HOST`
127 92e66347 2020-11-06 op
128 a5d310bc 2020-11-10 op > The remote IP address.
129 92e66347 2020-11-06 op
130 a5d310bc 2020-11-10 op `DOCUMENT_ROOT`
131 a5d310bc 2020-11-10 op
132 a5d310bc 2020-11-10 op > The root directory being served, the one provided with the
133 a5d310bc 2020-11-10 op > *d*
134 a5d310bc 2020-11-10 op > parameter to
135 a5d310bc 2020-11-10 op > **gmid**
136 a5d310bc 2020-11-10 op
137 a5d310bc 2020-11-10 op Let's say you have a script in
138 a5d310bc 2020-11-10 op */cgi-bin/script*
139 a5d310bc 2020-11-10 op and the user request is
140 a5d310bc 2020-11-10 op */cgi-bin/script/foo/bar?quux*.
141 a5d310bc 2020-11-10 op Then
142 a5d310bc 2020-11-10 op `SCRIPT_NAME`
143 a5d310bc 2020-11-10 op will be
144 a5d310bc 2020-11-10 op */cgi-bin/script*,
145 a5d310bc 2020-11-10 op `SCRIPT_EXECUTABLE`
146 a5d310bc 2020-11-10 op will be
147 a5d310bc 2020-11-10 op *$DOCUMENT\_ROOT/cgi-bin/script*,
148 a5d310bc 2020-11-10 op `REQUEST_URI`
149 a5d310bc 2020-11-10 op will be
150 a5d310bc 2020-11-10 op */cgi-bin/script/foo/bar*,
151 a5d310bc 2020-11-10 op `REQUEST_RELATIVE`
152 a5d310bc 2020-11-10 op will be
153 a5d310bc 2020-11-10 op *foo/bar and*
154 a5d310bc 2020-11-10 op `QUERY_STRING`
155 a5d310bc 2020-11-10 op will be
156 a5d310bc 2020-11-10 op *quux*.
157 a5d310bc 2020-11-10 op
158 3e4749f7 2020-10-02 op # EXAMPLES
159 3e4749f7 2020-10-02 op
160 3e4749f7 2020-10-02 op To quickly getting started
161 3e4749f7 2020-10-02 op
162 3e4749f7 2020-10-02 op $ # generate a cert and a key
163 3e4749f7 2020-10-02 op $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \
164 3e4749f7 2020-10-02 op -out cert.pem -days 365 -nodes
165 3e4749f7 2020-10-02 op $ mkdir docs
166 3e4749f7 2020-10-02 op $ cat <<EOF > docs/index.gmi
167 3e4749f7 2020-10-02 op # Hello world
168 3e4749f7 2020-10-02 op test paragraph...
169 3e4749f7 2020-10-02 op EOF
170 3e4749f7 2020-10-02 op $ gmid -c cert.pem -k key.pem -d docs
171 3e4749f7 2020-10-02 op
172 92e66347 2020-11-06 op Now you can visit gemini://localhost/ with your preferred gemini
173 0ed56567 2020-11-06 op client.
174 3e4749f7 2020-10-02 op
175 0ed56567 2020-11-06 op To add some CGI scripts, assuming a setup similar to the previous
176 92e66347 2020-11-06 op example, you can
177 0ed56567 2020-11-06 op
178 0ed56567 2020-11-06 op $ mkdir docs/cgi-bin
179 0ed56567 2020-11-06 op $ cat <<EOF > docs/cgi-bin/hello-world
180 0ed56567 2020-11-06 op #!/bin/sh
181 92e66347 2020-11-06 op printf "20 text/plain\r\n"
182 0ed56567 2020-11-06 op echo "hello world!"
183 0ed56567 2020-11-06 op EOF
184 92e66347 2020-11-06 op $ gmid -x cgi-bin
185 0ed56567 2020-11-06 op
186 92e66347 2020-11-06 op Note that the argument to the
187 0ed56567 2020-11-06 op **-x**
188 0ed56567 2020-11-06 op option is
189 0ed56567 2020-11-06 op *cgi-bin*
190 0ed56567 2020-11-06 op and not
191 0ed56567 2020-11-06 op *docs/cgi-bin*,
192 a5d310bc 2020-11-10 op since it's relative to the document root.
193 0ed56567 2020-11-06 op
194 3e4749f7 2020-10-02 op # CAVEATS
195 3e4749f7 2020-10-02 op
196 fab952e1 2020-10-03 op * it doesn't support virtual hosts: the host part of the request URL is
197 3e4749f7 2020-10-02 op completely ignored.
198 3e4749f7 2020-10-02 op
199 3e4749f7 2020-10-02 op * it doesn't fork in the background or anything like that.
200 3e4749f7 2020-10-02 op