#!/usr/bin/python # # File: Environment.py # Author: Angus McIntyre # Date: 23.08.2000 # Updated: 28.08.2000 # # A Python script to display the values of environment variables set by the # server. These variables provide information about the user, the software # they are using, the context of execution etc. This script is intended as # an aid to debugging. The script was originally written in Perl. # # --------------------------------------------------------------------------- # REVISION HISTORY # # 23.08.2000 SLAM First implementation. # # --------------------------------------------------------------------------- # LEGAL NOTICE # # This script may be freely copied, distributed and modified. Use of the # script is at the risk of the user. The script is presented "as-is" without # any warranty, and the author is not liable for any loss or damages arising # out of the use of or failure to use this script. This notice must appear # in any modified copy of the script in which the name of the original # author also appears. # --------------------------------------------------------------------------- # --------------------------------------------------------------------------- # IMPORTS # --------------------------------------------------------------------------- import os import re # --------------------------------------------------------------------------- # CONSTANTS # --------------------------------------------------------------------------- # table_header_color - color used to print the table header background table_header_color = "#9999FF" # table_cell_color - color used to print the background of table cells table_cell_color = "#DDDDFF"; # allowable_variables_pattern - pattern used to determine which variables # should be printed. This can be used to restrict the amount of (potentially # sensitive) information returned by the script. The pattern below lists the # key Web-related variables. # # The regular expression is precompiled at the moment of definition for # efficiency purposes. allowable_variables_pattern = re.compile("HTTP|SERVER|REQUEST_METHOD|QUERY_STRING") # --------------------------------------------------------------------------- # FUNCTIONS # --------------------------------------------------------------------------- # allowed_to_print # # Determine if the script is allowed to print the value for a particular # variable. The variable is checked against a (compiled) regular expression: # if it matches, the function returns true. def allowed_to_print(varname): match = allowable_variables_pattern.match(varname) return match # --------------------------------------------------------------------------- # MAIN # --------------------------------------------------------------------------- # Print the HTTP response header and then the first part of the HTML text # making up the page. print 'Content-type: text/html\n\n\ \n\ \n\
\n\| Variable | \n\Value | \n\
|---|---|
| ' print e[0] + ': | '
print e[1] + ' |