xref: /netbsd-src/external/bsd/mdocml/dist/man.cgi.8 (revision 63aea4bd5b445e491ff0389fe27ec78b3099dba3)
1.\"     $Id: man.cgi.8,v 1.1.1.1 2015/12/17 21:58:48 christos Exp $
2.\"
3.\" Copyright (c) 2014 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: September 14 2014 $
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 apropos 1
30and
31.Xr man 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.Dq Submit
55button to send a search request from the client to the server.
56.It
57A
58.Dq Reset
59button to undo any changes to the input boxes and the dropdown menus
60and reset them to the values contained in the
61.Ev QUERY_STRING .
62.It
63Radio buttons to select pages either by name like in
64.Xr man 1
65or using
66.Xr apropos 1
67queries.
68.It
69A dropdown menu to optionally select a manual section.
70If one is provided, it has the same effect as the
71.Xr man 1
72and
73.Xr apropos 1
74.Fl s
75option.
76Otherwise, pages from all sections are shown.
77.It
78A dropdown menu to optionally select an architecture.
79If one is provided, it has the same effect as the
80.Xr man 1
81and
82.Xr apropos 1
83.Fl S
84option.
85By default, pages for all architectures are shown.
86.It
87A dropdown menu to select a manual tree.
88If the configuration file
89.Pa /var/www/man/manpath.conf
90contains only one manpath, the dropdown menu is not shown.
91By default, the first manpath given in the file is used.
92.El
93.Ss Program output
94The
95.Nm
96program generates five kinds of output pages:
97.Bl -tag -width Ds
98.It The index page.
99This is returned when calling
100.Nm
101without
102.Ev PATH_INFO
103and without a
104.Ev QUERY_STRING .
105It serves as a starting point for using the program
106and shows the search form only.
107.It A list page.
108Lists are returned when searches match more than one manual page.
109The first column shows the names and section numbers of manuals
110as clickable links.
111The second column shows the one-line descriptions of the manuals.
112.It A manual page.
113This output format is used when a search matches exactly one
114manual page, or when a link on a list page or an
115.Ic \&Xr
116link on another manual page is followed.
117.It A no-result page.
118This is shown when a search request returns no results -
119eiher because it violates the query syntax, or because
120the search does not match any manual pages.
121.It \&An error page.
122This cannot happen by merely clicking the
123.Dq Search
124button, but only by manually entering an invalid URI.
125It does not show the search form, but only an error message
126and a link back to the index page.
127.El
128.Ss Setup
129For each manual tree, create one first-level subdirectory below
130.Pa /var/www/man .
131The name of one of these directories is called a
132.Dq manpath
133in the context of
134.Nm .
135Create a single ASCII text file
136.Pa /var/www/man/manpath.conf
137containing the names of these directories, one per line.
138The directory given first is used as the default manpath.
139.Pp
140Inside each of these directories, use the same directory and file
141structure as found below
142.Pa /usr/share/man ,
143that is, second-level subdirectories
144.Pa /var/www/man/*/man1 , /var/www/man/*/man2
145etc. containing source
146.Xr mdoc 7
147and
148.Xr man 7
149manuals with file name extensions matching the section numbers,
150second-level subdirectories
151.Pa /var/www/man/*/cat1 , /var/www/man/*/cat2
152etc. containing preformatted manuals with the file name extension
153.Sq 0 ,
154and optional third-level subdirectories for architectures.
155Use
156.Xr makewhatis 8
157to create a
158.Xr mandoc.db 5
159database inside each manpath.
160.Pp
161Configure your web server to execute CGI programs located in
162.Pa /cgi-bin .
163When using
164.Xr nginx 8 ,
165the
166.Xr slowcgi 8
167proxy daemon is needed to translate FastCGI requests to plain old CGI.
168.Pp
169To compile
170.Nm ,
171first copy
172.Pa cgi.h.example
173to
174.Pa cgi.h
175and edit it according to your needs.
176It contains the following compile-time definitions:
177.Bl -tag -width Ds
178.It Ev COMPAT_OLDURI
179Only useful for running on www.openbsd.org to deal with old URIs containing
180.Qq "manpath=OpenBSD "
181where the blank character has to be translated to a hyphen.
182When compiling for other sites, this definition can be deleted.
183.It Ev CSS_DIR
184An optional path to the directory containing the CSS files,
185to be specified relative to the server's document root,
186and to be specified without a trailing slash.
187When not specified, the CSS files
188are assumed to be in the document root.
189This is used in generated HTML code.
190.It Ev CUSTOMIZE_BEGIN
191A HTML string to be inserted right after opening the
192.Aq BODY
193element.
194.It Ev CUSTOMIZE_TITLE
195An ASCII string to be used for the HTML
196.Aq TITLE
197element.
198.It Ev HTTP_HOST
199The FQDN of the (possibly virtual) host the HTTP server is running on.
200This is used for
201.Ic Location:
202headers in HTTP 303 responses.
203.It Ev MAN_DIR
204A path to the
205.Nm
206data directory to be used instead of
207.Pa /var/www/man ,
208relative to the web server
209.Xr chroot 2
210directory, to be specified without a trailing slash.
211This is prepended to the manpath when opening
212.Xr mandoc.db 5
213and manual page files.
214.El
215.Pp
216After editing
217.Pa cgi.h ,
218run
219.Pp
220.Dl make man.cgi
221.Pp
222and copy the files to the proper locations.
223Reading the
224.Cm installcgi
225target in the
226.Pa Makefile
227can help with that, but do not run it without carefully checking it
228because the directory layouts of web servers vary greatly.
229.Ss URI interface
230.Nm
231uniform resource identifiers are not needed for interactive use,
232but can be useful for deep linking.
233They consist of:
234.Bl -enum
235.It
236The
237.Cm http://
238protocol specifier.
239.It
240The host name and a following slash.
241.It
242The path to the program, normally
243.Pa cgi-bin/man.cgi/ .
244.It
245To show a single page, a slash, the manpath, another slash,
246and the name of the requested file, for example
247.Pa /OpenBSD-current/man1/mandoc.1 .
248.It
249For searches, a query string starting with a question mark
250and consisting of
251.Ar key Ns = Ns Ar value
252pairs, separated by ampersands, for example
253.Pa ?manpath=OpenBSD-current&query=mandoc .
254Supported keys are
255.Cm manpath ,
256.Cm query ,
257.Cm sec ,
258.Cm arch ,
259corresponding to
260.Xr apropos 1
261.Fl M ,
262.Ar expression ,
263.Fl s ,
264.Fl S ,
265respectively, and
266.Cm apropos ,
267which is a boolean parameter to select or deselect the
268.Xr apropos 1
269query mode.
270For backward compatibility with the traditional
271.Nm ,
272.Cm sektion
273is supported as an alias for
274.Cm sec .
275.El
276.Ss Restricted character set
277For security reasons, in particular to prevent cross site scripting
278attacks, some strings used by
279.Nm
280can only contain the following characters:
281.Pp
282.Bl -dash -compact -offset indent
283.It
284lower case and upper case ASCII letters
285.It
286the ten decimal digits
287.It
288the dash
289.Pq Sq -
290.It
291the dot
292.Pq Sq \&.
293.It
294the slash
295.Pq Sq /
296.It
297the underscore
298.Pq Sq _
299.El
300.Pp
301In particular, this applies to the
302.Ev SCRIPT_NAME ,
303to all manpaths, and to all architecture names.
304.Sh ENVIRONMENT
305The web server may pass the following CGI variables to
306.Nm :
307.Bl -tag -width Ds
308.It Ev PATH_INFO
309The final part of the URI path passed from the client to the server,
310starting after the
311.Ev SCRIPT_NAME
312and ending before the
313.Ev QUERY_STRING .
314It is used by the
315.Cm show
316page to acquire the manpath and filename it needs.
317.It Ev QUERY_STRING
318The HTTP query string passed from the client to the server.
319It is the final part of the URI, after the question mark.
320It is used by the
321.Cm search
322page to acquire the named parameters it needs.
323.It Ev SCRIPT_NAME
324The path to the
325.Nm
326binary relative to the server root, usually
327.Pa /cgi-bin/man.cgi .
328This is used for generating URIs to be embedded
329in generated HTML code and HTTP headers.
330If this contains any character not contained in the
331.Sx Restricted character set ,
332.Nm
333reports an internal server error and exits without doing anything.
334.El
335.Sh FILES
336.Bl -tag -width Ds
337.It Pa /var/www
338Default web server
339.Xr chroot 2
340directory.
341All the following paths are specified relative to this directory.
342.It Pa /cgi-bin/man.cgi
343The path to the
344.Nm
345program relative to the server root.
346Can be overridden by
347.Ev SCRIPT_NAME .
348.It Pa /htdocs
349The path to the server document root relative to the server root.
350This is part of the web server configuration and not specific to
351.Nm .
352.It Pa /htdocs/man-cgi.css
353A style sheet for general
354.Nm
355styling, referenced from each generated HTML page.
356.It Pa /htdocs/man.css
357A style sheet for
358.Xr mandoc 1
359HTML styling, referenced from each generated HTML page after
360.Pa man-cgi.css .
361.It Pa /man
362Default
363.Nm
364data directory containing all the manual trees.
365Can be overridden by
366.Ev MAN_DIR .
367.It Pa /man/mandoc/man1/apropos.1 , /man/mandoc/man8/man.cgi.8
368Manual pages documenting
369.Nm
370itself, linked from the index page.
371.It Pa /man/manpath.conf
372The list of available manpaths, one per line.
373If any of the lines in this file contains a slash
374.Pq Sq /
375or any character not contained in the
376.Sx Restricted character set ,
377.Nm
378reports an internal server error and exits without doing anything.
379.It Pa /man/OpenBSD-current/man1/mandoc.1
380An example
381.Xr mdoc 7
382source file located below the
383.Dq OpenBSD-current
384manpath.
385.El
386.Sh COMPATIBILITY
387The
388.Nm
389CGI program is call-compatible with queries from the traditional
390.Pa man.cgi
391script by Wolfram Schneider.
392However, the output may not be quite the same.
393.Sh SEE ALSO
394.Xr apropos 1 ,
395.Xr mandoc.db 5 ,
396.Xr makewhatis 8 ,
397.Xr slowcgi 8
398.Sh HISTORY
399A version of
400.Nm
401based on
402.Xr mandoc 1
403first appeared in mdocml-1.12.1 (March 2012).
404The current SQLite3-based version first appeared in
405.Ox 5.6 .
406.Sh AUTHORS
407.An -nosplit
408The
409.Nm
410program was written by
411.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
412and ported to the SQLite3-based
413.Xr mandoc.db 5
414backend by
415.An Ingo Schwarze Aq Mt schwarze@openbsd.org .
416