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