NAME
man.cgi
—
CGI program to search and display
manual pages
DESCRIPTION
The man.cgi
CGI program searches for
manual pages on a WWW server and displays them to HTTP clients, providing
functionality equivalent to the
man(1)
and apropos(1) utilities. It can use multiple manual trees in
parallel.
HTML search interface
At the top of each generated HTML page,
man.cgi
displays a search form containing these
elements:
- An input box for search queries, expecting either a name of a manual page
or an expression using the syntax described in the
apropos(1) manual; filling this in is required for each search.
The expression is broken into words at whitespace. Whitespace characters and backslashes can be escaped by prepending a backslash. The effect of prepending a backslash to another character is undefined; in the current implementation, it has no effect.
- A man(1) submit button. The string in the input box is interpreted as the name of a manual page.
- An apropos(1) submit button. The string in the input box is interpreted as a search expression.
- A dropdown menu to optionally select a manual section. If one is provided,
it has the same effect as the
man(1)
and apropos(1)
-s
option. Otherwise, pages from all sections are shown. - A dropdown menu to optionally select an architecture. If one is provided,
it has the same effect as the
man(1)
and apropos(1)
-S
option. By default, pages for all architectures are shown. - A dropdown menu to select a manual tree. If the configuration file /var/www/man/manpath.conf contains only one manpath, the dropdown menu is not shown. By default, the first manpath given in the file is used.
Program output
The man.cgi
program generates five kinds
of output pages:
- The index page.
- This is returned when calling
man.cgi
withoutPATH_INFO
and without aQUERY_STRING
. It serves as a starting point for using the program and shows the search form only. - A list page.
- Lists are returned when searches match more than one manual page. The first column shows the names and section numbers of manuals as clickable links. The second column shows the one-line descriptions of the manuals. For man(1) style searches, the content of the first manual page follows the list.
- A manual page.
- This output format is used when a search matches exactly one manual page,
or when a link on a list page or an
Xr
link on another manual page is followed. - A no-result page.
- This is shown when a search request returns no results - either because it violates the query syntax, or because the search does not match any manual pages.
- An error page.
- This cannot happen by merely clicking the “Search” button, but only by manually entering an invalid URI. It does not show the search form, but only an error message and a link back to the index page.
Setup
For each manual tree, create one first-level subdirectory below
/var/www/man. The name of one of these directories
is called a “manpath” in the context of
man.cgi
. Create a single ASCII text file
/var/www/man/manpath.conf containing the names of
these directories, one per line. The directory given first is used as the
default manpath.
Inside each of these directories, use the same directory and file structure as found below /usr/share/man, that is, second-level subdirectories /var/www/man/*/man1, /var/www/man/*/man2 etc. containing source mdoc(7) and man(7) manuals with file name extensions matching the section numbers, second-level subdirectories /var/www/man/*/cat1, /var/www/man/*/cat2 etc. containing preformatted manuals with the file name extension ‘0’, and optional third-level subdirectories for architectures. Use makewhatis(8) to create a mandoc.db(5) database inside each manpath.
Configure your web server to execute CGI programs located in /cgi-bin. When using OpenBSD httpd(8), the slowcgi(8) proxy daemon is needed to translate FastCGI requests to plain old CGI.
To compile man.cgi
, first copy
cgi.h.example to cgi.h and
edit it according to your needs. It contains the following compile-time
definitions:
COMPAT_OLDURI
- Only useful for running on www.openbsd.org to deal with old URIs containing "manpath=OpenBSD " where the blank character has to be translated to a hyphen. When compiling for other sites, this definition can be deleted.
CSS_DIR
- An optional file system path to the directory containing the file mandoc.css, to be specified relative to the server's document root, and to be specified without a trailing slash. When empty, the CSS file is assumed to be in the document root. Otherwise, a leading slash is needed. This is used in generated HTML code.
CUSTOMIZE_TITLE
- An ASCII string to be used for the HTML <TITLE> element.
MAN_DIR
- A file system path to the
man.cgi
data directory relative to the web server chroot(2) directory, to be specified with a leading slash and without a trailing slash. It needs to have at least one component; the root directory cannot be used for this purpose. The files manpath.conf, header.html, and footer.html are looked up in this directory. It is also prepended to the manpath when opening mandoc.db(5) and manual page files. SCRIPT_NAME
- The initial component of URIs, to be specified without leading and trailing slashes. It can be empty.
After editing cgi.h, run
make man.cgi
and copy the resulting binary to the proper location, for example using the command:
make installcgi
In addition to that, make sure the default manpath contains the files man1/apropos.1 and man8/man.cgi.8, or the documentation links at the bottom of the index page will not work.
URI interface
man.cgi
uniform resource identifiers are
not needed for interactive use, but can be useful for deep linking. They
consist of:
- The
http://
orhttps://
protocol specifier. - The host name.
- The
SCRIPT_NAME
, preceded by a slash unless empty. - To show a single page, a slash, the manpath, another slash, and the name
of the requested file, for example
/OpenBSD-current/man1/mandoc.1. This can be
abbreviated according to the following syntax:
[/manpath][/
man
sec][/arch]/name[.sec] - For searches, a query string starting with a question mark and consisting
of key=value pairs, separated
by ampersands, for example
?manpath=OpenBSD-current&query=mandoc.
Supported keys are
manpath
,query
,sec
,arch
, corresponding to apropos(1)-M
, expression,-s
,-S
, respectively, andapropos
, which is a boolean parameter to select or deselect the apropos(1) query mode. For backward compatibility with the traditionalman.cgi
,sektion
is supported as an alias forsec
.
Restricted character set
For security reasons, in particular to prevent cross site
scripting attacks, some strings used by man.cgi
can
only contain the following characters:
- lower case and upper case ASCII letters
- the ten decimal digits
- the dash (‘-’)
- the dot (‘.’)
- the slash (‘/’)
- the underscore (‘_’)
In particular, this applies to all manpaths and architecture names.
ENVIRONMENT
The web server may pass the following CGI variables to
man.cgi
:
SCRIPT_NAME
- The initial part of the URI passed from the client to the server, starting
after the server's host name and ending before
PATH_INFO
. This is ignored byman.cgi
. When constructing URIs for links and redirections, theSCRIPT_NAME
preprocessor constant is used instead. PATH_INFO
- The final part of the URI path passed from the client to the server,
starting after the
SCRIPT_NAME
and ending before theQUERY_STRING
. It is used by theshow
page to acquire the manpath and filename it needs. QUERY_STRING
- The HTTP query string passed from the client to the server. It is the
final part of the URI, after the question mark. It is used by the
search
page to acquire the named parameters it needs.
FILES
- /var/www
- Default web server chroot(2) directory. All the following paths are specified relative to this directory.
- /cgi-bin/man.cgi
- The usual file system path to the
man.cgi
program inside the web server chroot(2) directory. A different name can be chosen, but in any case, it needs to be configured in httpd.conf(5). - /htdocs
- The file system path to the server document root directory relative to the
server chroot(2) directory. This is part of the web server configuration
and not specific to
man.cgi
. - /htdocs/mandoc.css
- A style sheet for mandoc(1) HTML styling, referenced from each generated HTML page.
- /man
- Default
man.cgi
data directory containing all the manual trees. Can be overridden byMAN_DIR
. - /man/manpath.conf
- The list of available manpaths, one per line. If any of the lines in this
file contains a slash (‘/’) or any character not contained
in the Restricted character
set,
man.cgi
reports an internal server error and exits without doing anything. - /man/header.html
- An optional file containing static HTML code to be inserted right after opening the <BODY> element.
- /man/footer.html
- An optional file containing static HTML code to be inserted right before closing the <BODY> element.
- /man/OpenBSD-current/man1/mandoc.1
- An example mdoc(7) source file located below the “OpenBSD-current” manpath.
COMPATIBILITY
The man.cgi
CGI program is call-compatible
with queries from the traditional man.cgi script by
Wolfram Schneider. However, the output looks quite different.
SEE ALSO
HISTORY
A version of man.cgi
based on
mandoc(1) first appeared in mdocml-1.12.1 (March 2012). The current
mandoc.db(5) database format first appeared in
OpenBSD 6.1.
AUTHORS
The man.cgi
program was written by
Kristaps Dzonsons
<kristaps@bsd.lv> and
is maintained by Ingo Schwarze
<schwarze@openbsd.org>,
who also designed and implemented the database format.