xref: /netbsd-src/external/bsd/mdocml/dist/man.cgi.8 (revision c9bcef0391a5afc0280459d5c16c26ace267c496)
1*c9bcef03Schristos.\"	Id: man.cgi.8,v 1.23 2018/05/20 21:48:44 schwarze Exp
2fec65c98Schristos.\"
39ff1f2acSchristos.\" Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze@openbsd.org>
4fec65c98Schristos.\"
5fec65c98Schristos.\" Permission to use, copy, modify, and distribute this software for any
6fec65c98Schristos.\" purpose with or without fee is hereby granted, provided that the above
7fec65c98Schristos.\" copyright notice and this permission notice appear in all copies.
8fec65c98Schristos.\"
9fec65c98Schristos.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10fec65c98Schristos.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11fec65c98Schristos.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12fec65c98Schristos.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13fec65c98Schristos.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14fec65c98Schristos.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15fec65c98Schristos.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16fec65c98Schristos.\"
17*c9bcef03Schristos.Dd May 20, 2018
18fec65c98Schristos.Dt MAN.CGI 8
19fec65c98Schristos.Os
20fec65c98Schristos.Sh NAME
21fec65c98Schristos.Nm man.cgi
22fec65c98Schristos.Nd CGI program to search and display manual pages
23fec65c98Schristos.Sh DESCRIPTION
24fec65c98SchristosThe
25fec65c98Schristos.Nm
26fec65c98SchristosCGI program searches for manual pages on a WWW server
27fec65c98Schristosand displays them to HTTP clients,
28fec65c98Schristosproviding functionality equivalent to the
29fec65c98Schristos.Xr man 1
309ff1f2acSchristosand
319ff1f2acSchristos.Xr apropos 1
32fec65c98Schristosutilities.
33fec65c98SchristosIt can use multiple manual trees in parallel.
34fec65c98Schristos.Ss HTML search interface
35fec65c98SchristosAt the top of each generated HTML page,
36fec65c98Schristos.Nm
37fec65c98Schristosdisplays a search form containing these elements:
38fec65c98Schristos.Bl -enum
39fec65c98Schristos.It
40fec65c98SchristosAn input box for search queries, expecting
41fec65c98Schristoseither a name of a manual page or an
42fec65c98Schristos.Ar expression
43fec65c98Schristosusing the syntax described in the
44fec65c98Schristos.Xr apropos 1
45fec65c98Schristosmanual; filling this in is required for each search.
46fec65c98Schristos.Pp
47fec65c98SchristosThe expression is broken into words at whitespace.
48fec65c98SchristosWhitespace characters and backslashes can be escaped
49fec65c98Schristosby prepending a backslash.
50fec65c98SchristosThe effect of prepending a backslash to another character is undefined;
51fec65c98Schristosin the current implementation, it has no effect.
52fec65c98Schristos.It
53fec65c98SchristosA
54fec65c98Schristos.Xr man 1
559ff1f2acSchristossubmit button.
569ff1f2acSchristosThe string in the input box is interpreted as the name of a manual page.
579ff1f2acSchristos.It
589ff1f2acSchristosAn
59fec65c98Schristos.Xr apropos 1
609ff1f2acSchristossubmit button.
619ff1f2acSchristosThe string in the input box is interpreted as a search
629ff1f2acSchristos.Ar expression .
63fec65c98Schristos.It
64fec65c98SchristosA dropdown menu to optionally select a manual section.
65fec65c98SchristosIf one is provided, it has the same effect as the
66fec65c98Schristos.Xr man 1
67fec65c98Schristosand
68fec65c98Schristos.Xr apropos 1
69fec65c98Schristos.Fl s
70fec65c98Schristosoption.
71fec65c98SchristosOtherwise, pages from all sections are shown.
72fec65c98Schristos.It
73fec65c98SchristosA dropdown menu to optionally select an architecture.
74fec65c98SchristosIf one is provided, it has the same effect as the
75fec65c98Schristos.Xr man 1
76fec65c98Schristosand
77fec65c98Schristos.Xr apropos 1
78fec65c98Schristos.Fl S
79fec65c98Schristosoption.
80fec65c98SchristosBy default, pages for all architectures are shown.
81fec65c98Schristos.It
82fec65c98SchristosA dropdown menu to select a manual tree.
83fec65c98SchristosIf the configuration file
84fec65c98Schristos.Pa /var/www/man/manpath.conf
85fec65c98Schristoscontains only one manpath, the dropdown menu is not shown.
86fec65c98SchristosBy default, the first manpath given in the file is used.
87fec65c98Schristos.El
88fec65c98Schristos.Ss Program output
89fec65c98SchristosThe
90fec65c98Schristos.Nm
91fec65c98Schristosprogram generates five kinds of output pages:
92fec65c98Schristos.Bl -tag -width Ds
93fec65c98Schristos.It The index page.
94fec65c98SchristosThis is returned when calling
95fec65c98Schristos.Nm
96fec65c98Schristoswithout
97fec65c98Schristos.Ev PATH_INFO
98fec65c98Schristosand without a
99fec65c98Schristos.Ev QUERY_STRING .
100fec65c98SchristosIt serves as a starting point for using the program
101fec65c98Schristosand shows the search form only.
102fec65c98Schristos.It A list page.
103fec65c98SchristosLists are returned when searches match more than one manual page.
104fec65c98SchristosThe first column shows the names and section numbers of manuals
105fec65c98Schristosas clickable links.
106fec65c98SchristosThe second column shows the one-line descriptions of the manuals.
107*c9bcef03SchristosFor
108*c9bcef03Schristos.Xr man 1
109*c9bcef03Schristosstyle searches, the content of the first manual page follows the list.
110fec65c98Schristos.It A manual page.
111fec65c98SchristosThis output format is used when a search matches exactly one
112fec65c98Schristosmanual page, or when a link on a list page or an
113fec65c98Schristos.Ic \&Xr
114fec65c98Schristoslink on another manual page is followed.
115fec65c98Schristos.It A no-result page.
116fec65c98SchristosThis is shown when a search request returns no results -
117*c9bcef03Schristoseither because it violates the query syntax, or because
118fec65c98Schristosthe search does not match any manual pages.
119fec65c98Schristos.It \&An error page.
120fec65c98SchristosThis cannot happen by merely clicking the
121fec65c98Schristos.Dq Search
122fec65c98Schristosbutton, but only by manually entering an invalid URI.
123fec65c98SchristosIt does not show the search form, but only an error message
124fec65c98Schristosand a link back to the index page.
125fec65c98Schristos.El
126fec65c98Schristos.Ss Setup
127fec65c98SchristosFor each manual tree, create one first-level subdirectory below
128fec65c98Schristos.Pa /var/www/man .
129fec65c98SchristosThe name of one of these directories is called a
130fec65c98Schristos.Dq manpath
131fec65c98Schristosin the context of
132fec65c98Schristos.Nm .
133fec65c98SchristosCreate a single ASCII text file
134fec65c98Schristos.Pa /var/www/man/manpath.conf
135fec65c98Schristoscontaining the names of these directories, one per line.
136fec65c98SchristosThe directory given first is used as the default manpath.
137fec65c98Schristos.Pp
138fec65c98SchristosInside each of these directories, use the same directory and file
139fec65c98Schristosstructure as found below
140fec65c98Schristos.Pa /usr/share/man ,
141fec65c98Schristosthat is, second-level subdirectories
142fec65c98Schristos.Pa /var/www/man/*/man1 , /var/www/man/*/man2
143fec65c98Schristosetc. containing source
144fec65c98Schristos.Xr mdoc 7
145fec65c98Schristosand
146fec65c98Schristos.Xr man 7
147fec65c98Schristosmanuals with file name extensions matching the section numbers,
148fec65c98Schristossecond-level subdirectories
149fec65c98Schristos.Pa /var/www/man/*/cat1 , /var/www/man/*/cat2
150fec65c98Schristosetc. containing preformatted manuals with the file name extension
151fec65c98Schristos.Sq 0 ,
152fec65c98Schristosand optional third-level subdirectories for architectures.
153fec65c98SchristosUse
154fec65c98Schristos.Xr makewhatis 8
155fec65c98Schristosto create a
156fec65c98Schristos.Xr mandoc.db 5
157fec65c98Schristosdatabase inside each manpath.
158fec65c98Schristos.Pp
159fec65c98SchristosConfigure your web server to execute CGI programs located in
160fec65c98Schristos.Pa /cgi-bin .
161fec65c98SchristosWhen using
1629ff1f2acSchristos.Ox
1639ff1f2acSchristos.Xr httpd 8 ,
164fec65c98Schristosthe
165fec65c98Schristos.Xr slowcgi 8
166fec65c98Schristosproxy daemon is needed to translate FastCGI requests to plain old CGI.
167fec65c98Schristos.Pp
168fec65c98SchristosTo compile
169fec65c98Schristos.Nm ,
170fec65c98Schristosfirst copy
171fec65c98Schristos.Pa cgi.h.example
172fec65c98Schristosto
173fec65c98Schristos.Pa cgi.h
174fec65c98Schristosand edit it according to your needs.
175fec65c98SchristosIt contains the following compile-time definitions:
176fec65c98Schristos.Bl -tag -width Ds
177fec65c98Schristos.It Ev COMPAT_OLDURI
178fec65c98SchristosOnly useful for running on www.openbsd.org to deal with old URIs containing
179fec65c98Schristos.Qq "manpath=OpenBSD "
180fec65c98Schristoswhere the blank character has to be translated to a hyphen.
181fec65c98SchristosWhen compiling for other sites, this definition can be deleted.
1829ff1f2acSchristos.It Dv CSS_DIR
1839ff1f2acSchristosAn optional file system path to the directory containing the file
1849ff1f2acSchristos.Pa mandoc.css ,
185fec65c98Schristosto be specified relative to the server's document root,
186fec65c98Schristosand to be specified without a trailing slash.
1879ff1f2acSchristosWhen empty, the CSS file is assumed to be in the document root.
1889ff1f2acSchristosOtherwise, a leading slash is needed.
189fec65c98SchristosThis is used in generated HTML code.
1909ff1f2acSchristos.It Dv CUSTOMIZE_TITLE
1919ff1f2acSchristosAn ASCII string to be used for the HTML <TITLE> element.
1929ff1f2acSchristos.It Dv MAN_DIR
1939ff1f2acSchristosA file system path to the
194fec65c98Schristos.Nm
1959ff1f2acSchristosdata directory relative to the web server
196fec65c98Schristos.Xr chroot 2
1979ff1f2acSchristosdirectory, to be specified with a leading slash and without a trailing slash.
1989ff1f2acSchristosIt needs to have at least one component; the root directory cannot be used
1999ff1f2acSchristosfor this purpose.
2009ff1f2acSchristosThe files
2019ff1f2acSchristos.Pa manpath.conf ,
2029ff1f2acSchristos.Pa header.html ,
2039ff1f2acSchristosand
2049ff1f2acSchristos.Pa footer.html
2059ff1f2acSchristosare looked up in this directory.
2069ff1f2acSchristosIt is also prepended to the manpath when opening
207fec65c98Schristos.Xr mandoc.db 5
208fec65c98Schristosand manual page files.
2099ff1f2acSchristos.It Dv SCRIPT_NAME
2109ff1f2acSchristosThe initial component of URIs, to be specified without leading
2119ff1f2acSchristosand trailing slashes.
2129ff1f2acSchristosIt can be empty.
213fec65c98Schristos.El
214fec65c98Schristos.Pp
215fec65c98SchristosAfter editing
216fec65c98Schristos.Pa cgi.h ,
217fec65c98Schristosrun
218fec65c98Schristos.Pp
219fec65c98Schristos.Dl make man.cgi
220fec65c98Schristos.Pp
2219ff1f2acSchristosand copy the resulting binary to the proper location,
2229ff1f2acSchristosfor example using the command:
2239ff1f2acSchristos.Pp
2249ff1f2acSchristos.Dl make installcgi
2259ff1f2acSchristos.Pp
2269ff1f2acSchristosIn addition to that, make sure the default manpath contains the files
2279ff1f2acSchristos.Pa man1/apropos.1
2289ff1f2acSchristosand
2299ff1f2acSchristos.Pa man8/man.cgi.8 ,
2309ff1f2acSchristosor the documentation links at the bottom of the index page will not work.
231fec65c98Schristos.Ss URI interface
232fec65c98Schristos.Nm
233fec65c98Schristosuniform resource identifiers are not needed for interactive use,
234fec65c98Schristosbut can be useful for deep linking.
235fec65c98SchristosThey consist of:
236fec65c98Schristos.Bl -enum
237fec65c98Schristos.It
238fec65c98SchristosThe
239fec65c98Schristos.Cm http://
240*c9bcef03Schristosor
241*c9bcef03Schristos.Cm https://
242fec65c98Schristosprotocol specifier.
243fec65c98Schristos.It
2449ff1f2acSchristosThe host name.
245fec65c98Schristos.It
2469ff1f2acSchristosThe
2479ff1f2acSchristos.Dv SCRIPT_NAME ,
2489ff1f2acSchristospreceded by a slash unless empty.
249fec65c98Schristos.It
250fec65c98SchristosTo show a single page, a slash, the manpath, another slash,
251fec65c98Schristosand the name of the requested file, for example
252fec65c98Schristos.Pa /OpenBSD-current/man1/mandoc.1 .
2539ff1f2acSchristosThis can be abbreviated according to the following syntax:
2549ff1f2acSchristos.Sm off
2559ff1f2acSchristos.Op / Ar manpath
2569ff1f2acSchristos.Op / Cm man Ar sec
2579ff1f2acSchristos.Op / Ar arch
2589ff1f2acSchristos.Pf / Ar name Op \&. Ar sec
2599ff1f2acSchristos.Sm on
260fec65c98Schristos.It
261fec65c98SchristosFor searches, a query string starting with a question mark
262fec65c98Schristosand consisting of
263fec65c98Schristos.Ar key Ns = Ns Ar value
264fec65c98Schristospairs, separated by ampersands, for example
265fec65c98Schristos.Pa ?manpath=OpenBSD-current&query=mandoc .
266fec65c98SchristosSupported keys are
267fec65c98Schristos.Cm manpath ,
268fec65c98Schristos.Cm query ,
269fec65c98Schristos.Cm sec ,
270fec65c98Schristos.Cm arch ,
271fec65c98Schristoscorresponding to
272fec65c98Schristos.Xr apropos 1
273fec65c98Schristos.Fl M ,
274fec65c98Schristos.Ar expression ,
275fec65c98Schristos.Fl s ,
276fec65c98Schristos.Fl S ,
277fec65c98Schristosrespectively, and
278fec65c98Schristos.Cm apropos ,
279fec65c98Schristoswhich is a boolean parameter to select or deselect the
280fec65c98Schristos.Xr apropos 1
281fec65c98Schristosquery mode.
282fec65c98SchristosFor backward compatibility with the traditional
283fec65c98Schristos.Nm ,
284fec65c98Schristos.Cm sektion
285fec65c98Schristosis supported as an alias for
286fec65c98Schristos.Cm sec .
287fec65c98Schristos.El
288fec65c98Schristos.Ss Restricted character set
289fec65c98SchristosFor security reasons, in particular to prevent cross site scripting
290fec65c98Schristosattacks, some strings used by
291fec65c98Schristos.Nm
292fec65c98Schristoscan only contain the following characters:
293fec65c98Schristos.Pp
294fec65c98Schristos.Bl -dash -compact -offset indent
295fec65c98Schristos.It
296fec65c98Schristoslower case and upper case ASCII letters
297fec65c98Schristos.It
298fec65c98Schristosthe ten decimal digits
299fec65c98Schristos.It
300fec65c98Schristosthe dash
301fec65c98Schristos.Pq Sq -
302fec65c98Schristos.It
303fec65c98Schristosthe dot
304fec65c98Schristos.Pq Sq \&.
305fec65c98Schristos.It
306fec65c98Schristosthe slash
307fec65c98Schristos.Pq Sq /
308fec65c98Schristos.It
309fec65c98Schristosthe underscore
310fec65c98Schristos.Pq Sq _
311fec65c98Schristos.El
312fec65c98Schristos.Pp
3139ff1f2acSchristosIn particular, this applies to all manpaths and architecture names.
314fec65c98Schristos.Sh ENVIRONMENT
315fec65c98SchristosThe web server may pass the following CGI variables to
316fec65c98Schristos.Nm :
317fec65c98Schristos.Bl -tag -width Ds
3189ff1f2acSchristos.It Ev SCRIPT_NAME
3199ff1f2acSchristosThe initial part of the URI passed from the client to the server,
3209ff1f2acSchristosstarting after the server's host name and ending before
3219ff1f2acSchristos.Ev PATH_INFO .
3229ff1f2acSchristosThis is ignored by
3239ff1f2acSchristos.Nm .
3249ff1f2acSchristosWhen constructing URIs for links and redirections, the
3259ff1f2acSchristos.Dv SCRIPT_NAME
3269ff1f2acSchristospreprocessor constant is used instead.
327fec65c98Schristos.It Ev PATH_INFO
328fec65c98SchristosThe final part of the URI path passed from the client to the server,
329fec65c98Schristosstarting after the
330fec65c98Schristos.Ev SCRIPT_NAME
331fec65c98Schristosand ending before the
332fec65c98Schristos.Ev QUERY_STRING .
333fec65c98SchristosIt is used by the
334fec65c98Schristos.Cm show
335fec65c98Schristospage to acquire the manpath and filename it needs.
336fec65c98Schristos.It Ev QUERY_STRING
337fec65c98SchristosThe HTTP query string passed from the client to the server.
338fec65c98SchristosIt is the final part of the URI, after the question mark.
339fec65c98SchristosIt is used by the
340fec65c98Schristos.Cm search
341fec65c98Schristospage to acquire the named parameters it needs.
342fec65c98Schristos.El
343fec65c98Schristos.Sh FILES
344fec65c98Schristos.Bl -tag -width Ds
345fec65c98Schristos.It Pa /var/www
346fec65c98SchristosDefault web server
347fec65c98Schristos.Xr chroot 2
348fec65c98Schristosdirectory.
349fec65c98SchristosAll the following paths are specified relative to this directory.
350fec65c98Schristos.It Pa /cgi-bin/man.cgi
3519ff1f2acSchristosThe usual file system path to the
352fec65c98Schristos.Nm
3539ff1f2acSchristosprogram inside the web server
3549ff1f2acSchristos.Xr chroot 2
3559ff1f2acSchristosdirectory.
3569ff1f2acSchristosA different name can be chosen, but in any case, it needs to be configured in
3579ff1f2acSchristos.Xr httpd.conf 5 .
358fec65c98Schristos.It Pa /htdocs
3599ff1f2acSchristosThe file system path to the server document root directory
3609ff1f2acSchristosrelative to the server
3619ff1f2acSchristos.Xr chroot 2
3629ff1f2acSchristosdirectory.
363fec65c98SchristosThis is part of the web server configuration and not specific to
364fec65c98Schristos.Nm .
3659ff1f2acSchristos.It Pa /htdocs/mandoc.css
366fec65c98SchristosA style sheet for
367fec65c98Schristos.Xr mandoc 1
3689ff1f2acSchristosHTML styling, referenced from each generated HTML page.
369fec65c98Schristos.It Pa /man
370fec65c98SchristosDefault
371fec65c98Schristos.Nm
372fec65c98Schristosdata directory containing all the manual trees.
373fec65c98SchristosCan be overridden by
3749ff1f2acSchristos.Dv MAN_DIR .
375fec65c98Schristos.It Pa /man/manpath.conf
376fec65c98SchristosThe list of available manpaths, one per line.
377fec65c98SchristosIf any of the lines in this file contains a slash
378fec65c98Schristos.Pq Sq /
379fec65c98Schristosor any character not contained in the
380fec65c98Schristos.Sx Restricted character set ,
381fec65c98Schristos.Nm
382fec65c98Schristosreports an internal server error and exits without doing anything.
3839ff1f2acSchristos.It Pa /man/header.html
3849ff1f2acSchristosAn optional file containing static HTML code to be inserted right
3859ff1f2acSchristosafter opening the <BODY> element.
3869ff1f2acSchristos.It Pa /man/footer.html
3879ff1f2acSchristosAn optional file containing static HTML code to be inserted right
3889ff1f2acSchristosbefore closing the <BODY> element.
389fec65c98Schristos.It Pa /man/OpenBSD-current/man1/mandoc.1
390fec65c98SchristosAn example
391fec65c98Schristos.Xr mdoc 7
392fec65c98Schristossource file located below the
393fec65c98Schristos.Dq OpenBSD-current
394fec65c98Schristosmanpath.
395fec65c98Schristos.El
396fec65c98Schristos.Sh COMPATIBILITY
397fec65c98SchristosThe
398fec65c98Schristos.Nm
399fec65c98SchristosCGI program is call-compatible with queries from the traditional
400fec65c98Schristos.Pa man.cgi
401fec65c98Schristosscript by Wolfram Schneider.
402*c9bcef03SchristosHowever, the output looks quite different.
403fec65c98Schristos.Sh SEE ALSO
404fec65c98Schristos.Xr apropos 1 ,
405fec65c98Schristos.Xr mandoc.db 5 ,
406fec65c98Schristos.Xr makewhatis 8 ,
407fec65c98Schristos.Xr slowcgi 8
408fec65c98Schristos.Sh HISTORY
409fec65c98SchristosA version of
410fec65c98Schristos.Nm
411fec65c98Schristosbased on
412fec65c98Schristos.Xr mandoc 1
413fec65c98Schristosfirst appeared in mdocml-1.12.1 (March 2012).
414*c9bcef03SchristosThe current
415*c9bcef03Schristos.Xr mandoc.db 5
416*c9bcef03Schristosdatabase format first appeared in
417*c9bcef03Schristos.Ox 6.1 .
418fec65c98Schristos.Sh AUTHORS
419fec65c98Schristos.An -nosplit
420fec65c98SchristosThe
421fec65c98Schristos.Nm
422fec65c98Schristosprogram was written by
423fec65c98Schristos.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv
424*c9bcef03Schristosand is maintained by
425*c9bcef03Schristos.An Ingo Schwarze Aq Mt schwarze@openbsd.org ,
426*c9bcef03Schristoswho also designed and implemented the database format.
427