xref: /freebsd/contrib/mandoc/man.cgi.8 (revision 732a02b4e77866604a120a275c082bb6221bd2ff)
1.\"	$Id: man.cgi.8,v 1.23 2018/05/20 21:48:44 schwarze Exp $
2.\"
3.\" Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: May 20 2018 $
18.Dt MAN.CGI 8
19.Os
20.Sh NAME
21.Nm man.cgi
22.Nd CGI program to search and display manual pages
23.Sh DESCRIPTION
24The
25.Nm
26CGI program searches for manual pages on a WWW server
27and displays them to HTTP clients,
28providing functionality equivalent to the
29.Xr man 1
30and
31.Xr apropos 1
32utilities.
33It can use multiple manual trees in parallel.
34.Ss HTML search interface
35At the top of each generated HTML page,
36.Nm
37displays a search form containing these elements:
38.Bl -enum
39.It
40An input box for search queries, expecting
41either a name of a manual page or an
42.Ar expression
43using the syntax described in the
44.Xr apropos 1
45manual; filling this in is required for each search.
46.Pp
47The expression is broken into words at whitespace.
48Whitespace characters and backslashes can be escaped
49by prepending a backslash.
50The effect of prepending a backslash to another character is undefined;
51in the current implementation, it has no effect.
52.It
53A
54.Xr man 1
55submit button.
56The string in the input box is interpreted as the name of a manual page.
57.It
58An
59.Xr apropos 1
60submit button.
61The string in the input box is interpreted as a search
62.Ar expression .
63.It
64A dropdown menu to optionally select a manual section.
65If one is provided, it has the same effect as the
66.Xr man 1
67and
68.Xr apropos 1
69.Fl s
70option.
71Otherwise, pages from all sections are shown.
72.It
73A dropdown menu to optionally select an architecture.
74If one is provided, it has the same effect as the
75.Xr man 1
76and
77.Xr apropos 1
78.Fl S
79option.
80By default, pages for all architectures are shown.
81.It
82A dropdown menu to select a manual tree.
83If the configuration file
84.Pa /var/www/man/manpath.conf
85contains only one manpath, the dropdown menu is not shown.
86By default, the first manpath given in the file is used.
87.El
88.Ss Program output
89The
90.Nm
91program generates five kinds of output pages:
92.Bl -tag -width Ds
93.It The index page.
94This is returned when calling
95.Nm
96without
97.Ev PATH_INFO
98and without a
99.Ev QUERY_STRING .
100It serves as a starting point for using the program
101and shows the search form only.
102.It A list page.
103Lists are returned when searches match more than one manual page.
104The first column shows the names and section numbers of manuals
105as clickable links.
106The second column shows the one-line descriptions of the manuals.
107For
108.Xr man 1
109style searches, the content of the first manual page follows the list.
110.It A manual page.
111This output format is used when a search matches exactly one
112manual page, or when a link on a list page or an
113.Ic \&Xr
114link on another manual page is followed.
115.It A no-result page.
116This is shown when a search request returns no results -
117either because it violates the query syntax, or because
118the search does not match any manual pages.
119.It \&An error page.
120This cannot happen by merely clicking the
121.Dq Search
122button, but only by manually entering an invalid URI.
123It does not show the search form, but only an error message
124and a link back to the index page.
125.El
126.Ss Setup
127For each manual tree, create one first-level subdirectory below
128.Pa /var/www/man .
129The name of one of these directories is called a
130.Dq manpath
131in the context of
132.Nm .
133Create a single ASCII text file
134.Pa /var/www/man/manpath.conf
135containing the names of these directories, one per line.
136The directory given first is used as the default manpath.
137.Pp
138Inside each of these directories, use the same directory and file
139structure as found below
140.Pa /usr/share/man ,
141that is, second-level subdirectories
142.Pa /var/www/man/*/man1 , /var/www/man/*/man2
143etc. containing source
144.Xr mdoc 7
145and
146.Xr man 7
147manuals with file name extensions matching the section numbers,
148second-level subdirectories
149.Pa /var/www/man/*/cat1 , /var/www/man/*/cat2
150etc. containing preformatted manuals with the file name extension
151.Sq 0 ,
152and optional third-level subdirectories for architectures.
153Use
154.Xr makewhatis 8
155to create a
156.Xr mandoc.db 5
157database inside each manpath.
158.Pp
159Configure your web server to execute CGI programs located in
160.Pa /cgi-bin .
161When using
162.Ox
163.Xr httpd 8 ,
164the
165.Xr slowcgi 8
166proxy daemon is needed to translate FastCGI requests to plain old CGI.
167.Pp
168To compile
169.Nm ,
170first copy
171.Pa cgi.h.example
172to
173.Pa cgi.h
174and edit it according to your needs.
175It contains the following compile-time definitions:
176.Bl -tag -width Ds
177.It Ev COMPAT_OLDURI
178Only useful for running on www.openbsd.org to deal with old URIs containing
179.Qq "manpath=OpenBSD "
180where the blank character has to be translated to a hyphen.
181When compiling for other sites, this definition can be deleted.
182.It Dv CSS_DIR
183An optional file system path to the directory containing the file
184.Pa mandoc.css ,
185to be specified relative to the server's document root,
186and to be specified without a trailing slash.
187When empty, the CSS file is assumed to be in the document root.
188Otherwise, a leading slash is needed.
189This is used in generated HTML code.
190.It Dv CUSTOMIZE_TITLE
191An ASCII string to be used for the HTML <TITLE> element.
192.It Dv MAN_DIR
193A file system path to the
194.Nm
195data directory relative to the web server
196.Xr chroot 2
197directory, to be specified with a leading slash and without a trailing slash.
198It needs to have at least one component; the root directory cannot be used
199for this purpose.
200The files
201.Pa manpath.conf ,
202.Pa header.html ,
203and
204.Pa footer.html
205are looked up in this directory.
206It is also prepended to the manpath when opening
207.Xr mandoc.db 5
208and manual page files.
209.It Dv SCRIPT_NAME
210The initial component of URIs, to be specified without leading
211and trailing slashes.
212It can be empty.
213.El
214.Pp
215After editing
216.Pa cgi.h ,
217run
218.Pp
219.Dl make man.cgi
220.Pp
221and copy the resulting binary to the proper location,
222for example using the command:
223.Pp
224.Dl make installcgi
225.Pp
226In addition to that, make sure the default manpath contains the files
227.Pa man1/apropos.1
228and
229.Pa man8/man.cgi.8 ,
230or the documentation links at the bottom of the index page will not work.
231.Ss URI interface
232.Nm
233uniform resource identifiers are not needed for interactive use,
234but can be useful for deep linking.
235They consist of:
236.Bl -enum
237.It
238The
239.Cm http://
240or
241.Cm https://
242protocol specifier.
243.It
244The host name.
245.It
246The
247.Dv SCRIPT_NAME ,
248preceded by a slash unless empty.
249.It
250To show a single page, a slash, the manpath, another slash,
251and the name of the requested file, for example
252.Pa /OpenBSD-current/man1/mandoc.1 .
253This can be abbreviated according to the following syntax:
254.Sm off
255.Op / Ar manpath
256.Op / Cm man Ar sec
257.Op / Ar arch
258.Pf / Ar name Op \&. Ar sec
259.Sm on
260.It
261For searches, a query string starting with a question mark
262and consisting of
263.Ar key Ns = Ns Ar value
264pairs, separated by ampersands, for example
265.Pa ?manpath=OpenBSD-current&query=mandoc .
266Supported keys are
267.Cm manpath ,
268.Cm query ,
269.Cm sec ,
270.Cm arch ,
271corresponding to
272.Xr apropos 1
273.Fl M ,
274.Ar expression ,
275.Fl s ,
276.Fl S ,
277respectively, and
278.Cm apropos ,
279which is a boolean parameter to select or deselect the
280.Xr apropos 1
281query mode.
282For backward compatibility with the traditional
283.Nm ,
284.Cm sektion
285is supported as an alias for
286.Cm sec .
287.El
288.Ss Restricted character set
289For security reasons, in particular to prevent cross site scripting
290attacks, some strings used by
291.Nm
292can only contain the following characters:
293.Pp
294.Bl -dash -compact -offset indent
295.It
296lower case and upper case ASCII letters
297.It
298the ten decimal digits
299.It
300the dash
301.Pq Sq -
302.It
303the dot
304.Pq Sq \&.
305.It
306the slash
307.Pq Sq /
308.It
309the underscore
310.Pq Sq _
311.El
312.Pp
313In particular, this applies to all manpaths and architecture names.
314.Sh ENVIRONMENT
315The web server may pass the following CGI variables to
316.Nm :
317.Bl -tag -width Ds
318.It Ev SCRIPT_NAME
319The initial part of the URI passed from the client to the server,
320starting after the server's host name and ending before
321.Ev PATH_INFO .
322This is ignored by
323.Nm .
324When constructing URIs for links and redirections, the
325.Dv SCRIPT_NAME
326preprocessor constant is used instead.
327.It Ev PATH_INFO
328The final part of the URI path passed from the client to the server,
329starting after the
330.Ev SCRIPT_NAME
331and ending before the
332.Ev QUERY_STRING .
333It is used by the
334.Cm show
335page to acquire the manpath and filename it needs.
336.It Ev QUERY_STRING
337The HTTP query string passed from the client to the server.
338It is the final part of the URI, after the question mark.
339It is used by the
340.Cm search
341page to acquire the named parameters it needs.
342.El
343.Sh FILES
344.Bl -tag -width Ds
345.It Pa /var/www
346Default web server
347.Xr chroot 2
348directory.
349All the following paths are specified relative to this directory.
350.It Pa /cgi-bin/man.cgi
351The usual file system path to the
352.Nm
353program inside the web server
354.Xr chroot 2
355directory.
356A different name can be chosen, but in any case, it needs to be configured in
357.Xr httpd.conf 5 .
358.It Pa /htdocs
359The file system path to the server document root directory
360relative to the server
361.Xr chroot 2
362directory.
363This is part of the web server configuration and not specific to
364.Nm .
365.It Pa /htdocs/mandoc.css
366A style sheet for
367.Xr mandoc 1
368HTML styling, referenced from each generated HTML page.
369.It Pa /man
370Default
371.Nm
372data directory containing all the manual trees.
373Can be overridden by
374.Dv MAN_DIR .
375.It Pa /man/manpath.conf
376The list of available manpaths, one per line.
377If any of the lines in this file contains a slash
378.Pq Sq /
379or any character not contained in the
380.Sx Restricted character set ,
381.Nm
382reports an internal server error and exits without doing anything.
383.It Pa /man/header.html
384An optional file containing static HTML code to be inserted right
385after opening the <BODY> element.
386.It Pa /man/footer.html
387An optional file containing static HTML code to be inserted right
388before closing the <BODY> element.
389.It Pa /man/OpenBSD-current/man1/mandoc.1
390An example
391.Xr mdoc 7
392source file located below the
393.Dq OpenBSD-current
394manpath.
395.El
396.Sh COMPATIBILITY
397The
398.Nm
399CGI program is call-compatible with queries from the traditional
400.Pa man.cgi
401script by Wolfram Schneider.
402However, the output looks quite different.
403.Sh SEE ALSO
404.Xr apropos 1 ,
405.Xr mandoc.db 5 ,
406.Xr makewhatis 8 ,
407.Xr slowcgi 8
408.Sh HISTORY
409A version of
410.Nm
411based on
412.Xr mandoc 1
413first appeared in mdocml-1.12.1 (March 2012).
414The current
415.Xr mandoc.db 5
416database format first appeared in
417.Ox 6.1 .
418.Sh AUTHORS
419.An -nosplit
420The
421.Nm
422program was written by
423.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
424and is maintained by
425.An Ingo Schwarze Aq Mt schwarze@openbsd.org ,
426who also designed and implemented the database format.
427