Blob


1 .\" Copyright (c) 2020 Omar Polo <op@omarpolo.com>
2 .\"
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
6 .\"
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 .Dd $Mdocdate: October 2 2020$
15 .Dt GMIND 1
16 .Os
17 .Sh NAME
18 .Nm gmid
19 .Nd dead simple zero configuration gemini server
20 .Sh SYNOPSIS
21 .Nm
22 .Bk -words
23 .Op Fl h
24 .Op Fl c Ar cert.pem
25 .Op Fl d Ar docs
26 .Op Fl k Ar key.pem
27 .Op Fl l Ar logfile
28 .Op Fl x Ar cgi-bin
29 .Ek
30 .Sh DESCRIPTION
31 .Nm
32 is a very simple and minimal gemini server that can serve static files
33 and execute CGI scripts.
34 .Pp
35 .Nm
36 will strip any sequence of
37 .Pa ../
38 or trailing
39 .Pa ..
40 in the requests made by clients and will refuse to follow symlinks.
41 Furthermore, on
42 .Ox ,
43 .Xr pledge 2
44 and
45 .Xr unveil 2
46 are used to ensure that
47 .Nm
48 dosen't do anything else than read files from the given directory,
49 accept network connections and, optionally, execute CGI scripts.
50 .Pp
51 It should be noted that
52 .Nm
53 is very simple in its implementation, and so it may not be appropriate
54 for serving sites with lots of users.
55 After all, the code is single threaded and use a single process,
56 although it can handle multiple requests concurrently.
57 .Pp
58 If a user request path is a directory,
59 .Nm
60 will try to serve a
61 .Pa index.gmi
62 file inside that directory.
63 .Pp
64 The options are as follows:
65 .Bl -tag -width 12m
66 .It Fl c Ar cert.pem
67 The certificate to use, by default is
68 .Pa cert.pem .
69 .It Fl d Ar docs
70 The root directory to serve.
71 .Nm
72 won't serve any file that is outside that directory.
73 By default is
74 .Pa docs .
75 .It Fl h
76 Print the usage and exit.
77 .It Fl k Ar key.pem
78 The key for the certificate, by default is
79 .Pa key.pem .
80 .It Fl l Ar logfile
81 log to the given file instead of the standard error.
82 .It Fl x Ar dir
83 Enable execution of CGI scripts inside the given directory (relative
84 to the document root.) Cannot be provided more than once.
85 .El
86 .Sh CGI
87 When CGI scripts are enabled for a directory, a request for an
88 executable file will execute it and fed its output to the client.
89 .Pp
90 The CGI scripts will inherit the environment from
91 .Nm
92 with these additional variables set:
93 .Bl -tag -width 18m
94 .It Ev SERVER_SOFTWARE
95 "gmid"
96 .It Ev SERVER_PORT
97 "1965"
98 .It Ev SCRIPT_NAME
99 The (public) path to the script.
100 .It Ev SCRIPT_EXECUTABLE
101 The full path to the executable.
102 .It Ev REQUEST_URI
103 The user request (without the query parameters.)
104 .It Ev REQUEST_RELATIVE
105 The request relative to the script.
106 .It Ev QUERY_STRING
107 The query parameters.
108 .It Ev REMOTE_HOST
109 The remote IP address.
110 .It Ev DOCUMENT_ROOT
111 The root directory being served, the one provided with the
112 .Ar d
113 parameter to
114 .Nm
115 .El
116 .Pp
117 Let's say you have a script in
118 .Pa /cgi-bin/script
119 and the user request is
120 .Pa /cgi-bin/script/foo/bar?quux .
121 Then
122 .Ev SCRIPT_NAME
123 will be
124 .Pa /cgi-bin/script ,
125 .Ev SCRIPT_EXECUTABLE
126 will be
127 .Pa $DOCUMENT_ROOT/cgi-bin/script ,
128 .Ev REQUEST_URI
129 will be
130 .Pa /cgi-bin/script/foo/bar ,
131 .Ev REQUEST_RELATIVE
132 will be
133 .Pa foo/bar and
134 .Ev QUERY_STRING
135 will be
136 .Ar quux .
137 .Sh EXAMPLES
138 To quickly getting started
139 .Bd -literal -offset indent
140 $ # generate a cert and a key
141 $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \\
142 -out cert.pem -days 365 -nodes
143 $ mkdir docs
144 $ cat <<EOF > docs/index.gmi
145 # Hello world
146 test paragraph...
147 EOF
148 $ gmid -c cert.pem -k key.pem -d docs
149 .Ed
150 .Pp
151 Now you can visit gemini://localhost/ with your preferred gemini
152 client.
153 .Pp
154 To add some CGI scripts, assuming a setup similar to the previous
155 example, you can
156 .Bd -literal -offset indent
157 $ mkdir docs/cgi-bin
158 $ cat <<EOF > docs/cgi-bin/hello-world
159 #!/bin/sh
160 printf "20 text/plain\\r\\n"
161 echo "hello world!"
162 EOF
163 $ gmid -x cgi-bin
164 .Ed
165 .Pp
166 Note that the argument to the
167 .Fl x
168 option is
169 .Pa cgi-bin
170 and not
171 .Pa docs/cgi-bin ,
172 since it's relative to the document root.
173 .Sh CAVEATS
174 .Bl -bullet
175 .It
176 it doesn't support virtual hosts: the host part of the request URL is
177 completely ignored.
178 .It
179 it doesn't fork in the background or anything like that.
180 .El