1.\" $OpenBSD: man.cgi.8,v 1.15 2016/03/18 17:31:20 jmc 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: March 18 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 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 . 163.Pp 164To compile 165.Nm , 166first copy 167.Pa cgi.h.example 168to 169.Pa cgi.h 170and edit it according to your needs. 171It contains the following compile-time definitions: 172.Bl -tag -width Ds 173.It Ev COMPAT_OLDURI 174Only useful for running on www.openbsd.org to deal with old URIs containing 175.Qq "manpath=OpenBSD " 176where the blank character has to be translated to a hyphen. 177When compiling for other sites, this definition can be deleted. 178.It Dv CSS_DIR 179An optional file system path to the directory containing the file 180.Pa mandoc.css , 181to be specified relative to the server's document root, 182and to be specified without a trailing slash. 183When empty, the CSS file is assumed to be in the document root. 184Otherwise, a leading slash is needed. 185This is used in generated HTML code. 186.It Dv CUSTOMIZE_TITLE 187An ASCII string to be used for the HTML <TITLE> element. 188.It Dv HTTP_HOST 189The FQDN of the (possibly virtual) host the HTTP server is running on. 190This is used for 191.Ic Location: 192headers in HTTP 303 responses. 193.It Dv MAN_DIR 194A file system path to the 195.Nm 196data directory relative to the web server 197.Xr chroot 2 198directory, to be specified with a leading slash and without a trailing slash. 199It needs to have at least one component; the root directory cannot be used 200for this purpose. 201The files 202.Pa manpath.conf , 203.Pa header.html , 204and 205.Pa footer.html 206are looked up in this directory. 207It is also prepended to the manpath when opening 208.Xr mandoc.db 5 209and manual page files. 210.It Dv SCRIPT_NAME 211The initial component of URIs, to be specified without leading 212and trailing slashes. 213It can be empty. 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. 241.It 242The 243.Dv SCRIPT_NAME , 244preceded by a slash unless empty. 245.It 246To show a single page, a slash, the manpath, another slash, 247and the name of the requested file, for example 248.Pa /OpenBSD-current/man1/mandoc.1 . 249This can be abbreviated according to the following syntax: 250.Sm off 251.Op / Ar manpath Oo / Cm man Ar sec Oc Op / Ar arch 252.Pf / Ar name Op \&. Ar sec 253.Sm on 254.It 255For searches, a query string starting with a question mark 256and consisting of 257.Ar key Ns = Ns Ar value 258pairs, separated by ampersands, for example 259.Pa ?manpath=OpenBSD-current&query=mandoc . 260Supported keys are 261.Cm manpath , 262.Cm query , 263.Cm sec , 264.Cm arch , 265corresponding to 266.Xr apropos 1 267.Fl M , 268.Ar expression , 269.Fl s , 270.Fl S , 271respectively, and 272.Cm apropos , 273which is a boolean parameter to select or deselect the 274.Xr apropos 1 275query mode. 276For backward compatibility with the traditional 277.Nm , 278.Cm sektion 279is supported as an alias for 280.Cm sec . 281.El 282.Ss Restricted character set 283For security reasons, in particular to prevent cross site scripting 284attacks, some strings used by 285.Nm 286can only contain the following characters: 287.Pp 288.Bl -dash -compact -offset indent 289.It 290lower case and upper case ASCII letters 291.It 292the ten decimal digits 293.It 294the dash 295.Pq Sq - 296.It 297the dot 298.Pq Sq \&. 299.It 300the slash 301.Pq Sq / 302.It 303the underscore 304.Pq Sq _ 305.El 306.Pp 307In particular, this applies to all manpaths and architecture names. 308.Sh ENVIRONMENT 309The web server may pass the following CGI variables to 310.Nm : 311.Bl -tag -width Ds 312.It Ev SCRIPT_NAME 313The initial part of the URI passed from the client to the server, 314starting after the server's host name and ending before 315.Ev PATH_INFO . 316This is ignored by 317.Nm . 318When constructing URIs for links and redirections, the 319.Dv SCRIPT_NAME 320preprocessor constant is used instead. 321.It Ev PATH_INFO 322The final part of the URI path passed from the client to the server, 323starting after the 324.Ev SCRIPT_NAME 325and ending before the 326.Ev QUERY_STRING . 327It is used by the 328.Cm show 329page to acquire the manpath and filename it needs. 330.It Ev QUERY_STRING 331The HTTP query string passed from the client to the server. 332It is the final part of the URI, after the question mark. 333It is used by the 334.Cm search 335page to acquire the named parameters it needs. 336.El 337.Sh FILES 338.Bl -tag -width Ds 339.It Pa /var/www 340Default web server 341.Xr chroot 2 342directory. 343All the following paths are specified relative to this directory. 344.It Pa /cgi-bin/man.cgi 345The usual file system path to the 346.Nm 347program inside the web server 348.Xr chroot 2 349directory. 350A different name can be chosen, but in any case, it needs to be configured in 351.Xr httpd.conf 5 . 352.It Pa /htdocs 353The file system path to the server document root directory 354relative to the server 355.Xr chroot 2 356directory. 357This is part of the web server configuration and not specific to 358.Nm . 359.It Pa /htdocs/mandoc.css 360A style sheet for 361.Xr mandoc 1 362HTML styling, referenced from each generated HTML page. 363.It Pa /man 364Default 365.Nm 366data directory containing all the manual trees. 367Can be overridden by 368.Dv MAN_DIR . 369.It Pa /man/mandoc/man1/apropos.1 , /man/mandoc/man8/man.cgi.8 370Manual pages documenting 371.Nm 372itself, linked from the index page. 373.It Pa /man/manpath.conf 374The list of available manpaths, one per line. 375If any of the lines in this file contains a slash 376.Pq Sq / 377or any character not contained in the 378.Sx Restricted character set , 379.Nm 380reports an internal server error and exits without doing anything. 381.It Pa /man/header.html 382An optional file containing static HTML code to be inserted right 383after opening the <BODY> element. 384.It Pa /man/footer.html 385An optional file containing static HTML code to be inserted right 386before closing the <BODY> element. 387.It Pa /man/OpenBSD-current/man1/mandoc.1 388An example 389.Xr mdoc 7 390source file located below the 391.Dq OpenBSD-current 392manpath. 393.El 394.Sh COMPATIBILITY 395The 396.Nm 397CGI program is call-compatible with queries from the traditional 398.Pa man.cgi 399script by Wolfram Schneider. 400However, the output may not be quite the same. 401.Sh SEE ALSO 402.Xr apropos 1 , 403.Xr mandoc.db 5 , 404.Xr makewhatis 8 , 405.Xr slowcgi 8 406.Sh HISTORY 407A version of 408.Nm 409based on 410.Xr mandoc 1 411first appeared in mdocml-1.12.1 (March 2012). 412The current SQLite3-based version first appeared in 413.Ox 5.6 . 414.Sh AUTHORS 415.An -nosplit 416The 417.Nm 418program was written by 419.An Kristaps Dzonsons Aq Mt kristaps@bsd.lv 420and ported to the SQLite3-based 421.Xr mandoc.db 5 422backend by 423.An Ingo Schwarze Aq Mt schwarze@openbsd.org . 424