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 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 3e4749f7 2020-10-02 op in the requests made by clients, so it's impossible to serve content
28 3e4749f7 2020-10-02 op outside the
29 3e4749f7 2020-10-02 op *docs*
30 92e66347 2020-11-06 op directory by mistake, and will also refuse to follow symlinks.
31 6980aad6 2020-10-02 op Furthermore, on
32 6980aad6 2020-10-02 op OpenBSD,
33 6980aad6 2020-10-02 op pledge(2)
34 3e4749f7 2020-10-02 op and
35 6980aad6 2020-10-02 op unveil(2)
36 3e4749f7 2020-10-02 op are used to ensure that
37 3e4749f7 2020-10-02 op **gmid**
38 92e66347 2020-11-06 op dosen't do anything else than read files from the given directory,
39 92e66347 2020-11-06 op accept network connections and, optionally, execute CGI scripts.
40 3e4749f7 2020-10-02 op
41 3e4749f7 2020-10-02 op It should be noted that
42 3e4749f7 2020-10-02 op **gmid**
43 3e4749f7 2020-10-02 op is very simple in its implementation, and so it may not be appropriate
44 92e66347 2020-11-06 op for serving sites with lots of users.
45 92e66347 2020-11-06 op After all, the code is single threaded and use a single process,
46 92e66347 2020-11-06 op although it can handle multiple requests concurrently.
47 3e4749f7 2020-10-02 op
48 fab952e1 2020-10-03 op If a user request path is a directory,
49 fab952e1 2020-10-03 op **gmid**
50 fab952e1 2020-10-03 op will try to serve a
51 fab952e1 2020-10-03 op *index.gmi*
52 fab952e1 2020-10-03 op file inside that directory.
53 fab952e1 2020-10-03 op If not found, it will return an error 51 (not found) to the user.
54 fab952e1 2020-10-03 op
55 3e4749f7 2020-10-02 op The options are as follows:
56 3e4749f7 2020-10-02 op
57 3e4749f7 2020-10-02 op **-c** *cert.pem*
58 3e4749f7 2020-10-02 op
59 3e4749f7 2020-10-02 op > The certificate to use, by default is
60 fab952e1 2020-10-03 op > *cert.pem*.
61 3e4749f7 2020-10-02 op
62 3e4749f7 2020-10-02 op **-d** *docs*
63 3e4749f7 2020-10-02 op
64 3e4749f7 2020-10-02 op > The root directory to serve.
65 3e4749f7 2020-10-02 op > **gmid**
66 92e66347 2020-11-06 op > won't serve any file that is outside that directory, by default
67 92e66347 2020-11-06 op > *docs*.
68 3e4749f7 2020-10-02 op
69 3e4749f7 2020-10-02 op **-h**
70 3e4749f7 2020-10-02 op
71 fab952e1 2020-10-03 op > Print the usage and exit.
72 3e4749f7 2020-10-02 op
73 3e4749f7 2020-10-02 op **-k** *key.pem*
74 3e4749f7 2020-10-02 op
75 3e4749f7 2020-10-02 op > The key for the certificate, by default is
76 fab952e1 2020-10-03 op > *key.pem*.
77 3e4749f7 2020-10-02 op
78 92e66347 2020-11-06 op **-l** *logfile*
79 2c3a40fa 2020-11-06 op
80 2c3a40fa 2020-11-06 op > log to the given file instead of the standard error.
81 2c3a40fa 2020-11-06 op
82 0ed56567 2020-11-06 op **-x** *dir*
83 72342dc9 2020-11-06 op
84 0ed56567 2020-11-06 op > Enable execution of CGI scripts inside the given directory (relative
85 0ed56567 2020-11-06 op > to the document root.) Cannot be provided more than once.
86 72342dc9 2020-11-06 op
87 72342dc9 2020-11-06 op # CGI
88 72342dc9 2020-11-06 op
89 0ed56567 2020-11-06 op When CGI scripts are enabled for a directory, a request for an
90 0ed56567 2020-11-06 op executable file will execute it and fed its output to the client.
91 72342dc9 2020-11-06 op
92 92e66347 2020-11-06 op The CGI scripts will inherit the environment from
93 92e66347 2020-11-06 op **gmid**
94 92e66347 2020-11-06 op with these additional variables set:
95 92e66347 2020-11-06 op
96 92e66347 2020-11-06 op `SERVER_SOFTWARE`
97 92e66347 2020-11-06 op
98 92e66347 2020-11-06 op > "gmid"
99 92e66347 2020-11-06 op
100 92e66347 2020-11-06 op `SERVER_PROTOCOL`
101 92e66347 2020-11-06 op
102 92e66347 2020-11-06 op > "gemini"
103 92e66347 2020-11-06 op
104 92e66347 2020-11-06 op `SERVER_PORT`
105 92e66347 2020-11-06 op
106 92e66347 2020-11-06 op > "1965"
107 92e66347 2020-11-06 op
108 92e66347 2020-11-06 op `PATH_INFO`
109 92e66347 2020-11-06 op
110 92e66347 2020-11-06 op > the request path
111 92e66347 2020-11-06 op
112 92e66347 2020-11-06 op `PATH_TRANSLATED`
113 92e66347 2020-11-06 op
114 92e66347 2020-11-06 op > the full path: the concatenation of the document root and the request
115 92e66347 2020-11-06 op > path
116 92e66347 2020-11-06 op
117 92e66347 2020-11-06 op `QUERY_STRING`
118 92e66347 2020-11-06 op
119 92e66347 2020-11-06 op > the query string if present in the request URL, otherwise it
120 92e66347 2020-11-06 op > won't be set.
121 92e66347 2020-11-06 op
122 92e66347 2020-11-06 op `REMOTE_ADDR`
123 92e66347 2020-11-06 op
124 92e66347 2020-11-06 op > the IP address of the client in dot notation
125 92e66347 2020-11-06 op
126 3e4749f7 2020-10-02 op # EXAMPLES
127 3e4749f7 2020-10-02 op
128 3e4749f7 2020-10-02 op To quickly getting started
129 3e4749f7 2020-10-02 op
130 3e4749f7 2020-10-02 op $ # generate a cert and a key
131 3e4749f7 2020-10-02 op $ openssl req -x509 -newkey rsa:4096 -keyout key.pem \
132 3e4749f7 2020-10-02 op -out cert.pem -days 365 -nodes
133 3e4749f7 2020-10-02 op $ mkdir docs
134 3e4749f7 2020-10-02 op $ cat <<EOF > docs/index.gmi
135 3e4749f7 2020-10-02 op # Hello world
136 3e4749f7 2020-10-02 op test paragraph...
137 3e4749f7 2020-10-02 op EOF
138 3e4749f7 2020-10-02 op $ gmid -c cert.pem -k key.pem -d docs
139 3e4749f7 2020-10-02 op
140 92e66347 2020-11-06 op Now you can visit gemini://localhost/ with your preferred gemini
141 0ed56567 2020-11-06 op client.
142 3e4749f7 2020-10-02 op
143 0ed56567 2020-11-06 op To add some CGI scripts, assuming a setup similar to the previous
144 92e66347 2020-11-06 op example, you can
145 0ed56567 2020-11-06 op
146 0ed56567 2020-11-06 op $ mkdir docs/cgi-bin
147 0ed56567 2020-11-06 op $ cat <<EOF > docs/cgi-bin/hello-world
148 0ed56567 2020-11-06 op #!/bin/sh
149 92e66347 2020-11-06 op printf "20 text/plain\r\n"
150 0ed56567 2020-11-06 op echo "hello world!"
151 0ed56567 2020-11-06 op EOF
152 92e66347 2020-11-06 op $ gmid -x cgi-bin
153 0ed56567 2020-11-06 op
154 92e66347 2020-11-06 op Note that the argument to the
155 0ed56567 2020-11-06 op **-x**
156 0ed56567 2020-11-06 op option is
157 0ed56567 2020-11-06 op *cgi-bin*
158 0ed56567 2020-11-06 op and not
159 0ed56567 2020-11-06 op *docs/cgi-bin*,
160 0ed56567 2020-11-06 op since it&#8217;s relative to the document root.
161 0ed56567 2020-11-06 op
162 3e4749f7 2020-10-02 op # CAVEATS
163 3e4749f7 2020-10-02 op
164 fab952e1 2020-10-03 op * it doesn't support virtual hosts: the host part of the request URL is
165 3e4749f7 2020-10-02 op completely ignored.
166 3e4749f7 2020-10-02 op
167 3e4749f7 2020-10-02 op * it doesn't fork in the background or anything like that.
168 3e4749f7 2020-10-02 op