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