Next we'll define constants used by the script.
The absolute path to the root of the structure
containing the man pages.
#================================================================ # Manifest constants #---------------------------------------------------------------- MAN_BASE = "/usr/share/man/man"
Regular expressions are used to check the format of the
script's arguments. The PAGENAME_RE
regular expression is used to check the .
pagename
The pattern ends with the end-of-line anchor ($) to ensure that there are no stray
unmatched characters at the end of the string. This
is a security consideration. Since the page name
will become part of a shell command, we need to be
sure that no shell metacharacters such as pipe (|) are included—that can be a
penetration route for evildoers.
PAGENAME_RE = re.compile (
r'[_a-zA-Z]' # Starts with letter or underbar
r'[-+.:_a-zA-Z0-9]*' # Zero or more: + - . : _ letter digit
r'$' ) # Match the entire string
The SECTION_RE regular expression is
used to test the section number. This regular
expression covers all the currently known cases as well
as some unlikely combinations such as manlp or mannx; there is no
great downside to letting these through, since there
won't be any man pages at that path.
SECTION_RE = re.compile (
r'[0-9ln]' # Starts with one digit, letter l, or n
r'[px]?' # Optional suffix
r'$' ) # Match the entire string
This is the regular expression used to validate the suffix argument: it may contain only letters.
SUFFIX_RE = re.compile (
r'[a-z]+' # One or more letters
r'$' ) # Match the entire string
This is the name of the environmental variable that tells us what gateway interface standard is executing us; it is unset if we're not being called as a CGI script.
GATEWAY = "GATEWAY_INTERFACE"
This constant is used to check for the correct
environment: if we are being called as a CGI script,
the GATEWAY environmental variable should have this
value.
CGI_VERSION = "CGI/1.1"
This is the name of the argument, passed in the URL, that defines what page the user wants to see.
PAGE_NAME_ARG = "p"
This is the name of the optional argument, passed in the URL,
that defines which section contains the desired man page.
SECTION_ARG = "s"
This constant is the default section number when one is not supplied.
DEFAULT_SECTION = "1"