Next / Previous / Contents / TCC Help System / NM Tech homepage

4.4. Manifest constants

Next we'll define constants used by the script.

4.4.1. MAN_BASE

The absolute path to the root of the structure containing the man pages.

manweb.cgi
#================================================================
# Manifest constants
#----------------------------------------------------------------

MAN_BASE  =  "/usr/share/man/man"

4.4.2. PAGENAME_RE

Regular expressions are used to check the format of the script's arguments. The PAGENAME_RE regular expression is used to check the pagename.

Important

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.

manweb.cgi
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

4.4.3. SECTION_RE

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.

manweb.cgi
SECTION_RE  =  re.compile (
    r'[0-9ln]'           # Starts with one digit, letter l, or n
    r'[px]?'             # Optional suffix
    r'$' )               # Match the entire string

4.4.4. SUFFIX_RE

This is the regular expression used to validate the suffix argument: it may contain only letters.

manweb.cgi
SUFFIX_RE  =  re.compile (
    r'[a-z]+'           # One or more letters
    r'$' )              # Match the entire string

4.4.5. GATEWAY

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.

manweb.cgi
GATEWAY  =  "GATEWAY_INTERFACE"

4.4.6. CGI_VERSION

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.

manweb.cgi
CGI_VERSION  =  "CGI/1.1"

4.4.7. PAGE_NAME_ARG

This is the name of the argument, passed in the URL, that defines what page the user wants to see.

manweb.cgi
PAGE_NAME_ARG  =  "p"

4.4.8. SECTION_ARG

This is the name of the optional argument, passed in the URL, that defines which section contains the desired man page.

manweb.cgi
SECTION_ARG  =  "s"

4.4.9. DEFAULT_SECTION

This constant is the default section number when one is not supplied.

manweb.cgi
DEFAULT_SECTION  =  "1"

4.4.10. SUFFIX_ARG

This is the name of the optional suffix argument, passed in via the URL, that is appended before the terminal “.gz” of the man file name. The default value is an empty string.

manweb.cgi
SUFFIX_ARG  =  "x"