2
# Copyright (C) 2007-2008 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
# Displays lots of internal information about IVLE's running environment,
24
# Important: This application should be removed from a production system.
33
"""Handler for the Debug Information application."""
35
# Set request attributes
36
req.content_type = "text/html"
37
req.write_html_head_foot = True # Have dispatch print head and foot
40
req.write('<div id="ivle_padding">\n')
41
req.write("<h2>IVLE Debug Information</h2>\n")
43
print_table(req, "System Constants", [
44
("ivle_version", ivle.conf.ivle_version),
45
("prefix", ivle.conf.prefix),
46
("python_site_packages", ivle.conf.python_site_packages),
47
("data_path", ivle.conf.data_path),
48
("log_path", ivle.conf.log_path),
49
("root_dir", ivle.conf.root_dir),
50
("public_host", ivle.conf.public_host),
51
("jail_base", ivle.conf.jail_base),
52
("default_app", ivle.conf.apps.default_app),
53
("public_app", ivle.conf.apps.public_app),
56
print_table(req, "Operating System Variables", [
58
("euid", os.geteuid()),
60
("egid", os.getegid()),
61
("uname", os.uname()),
64
print_table(req, "Available Applications", ivle.conf.apps.app_url.items())
66
print_table(req, "Request Properties", [
67
("method", req.method),
72
("hostname", req.hostname),
75
# Violate encapsulation here to print out the hidden properties
76
print_table(req, "Apache (Hidden) Request Properties", [
77
("hostname", req.apache_req.hostname),
78
("method", req.apache_req.method),
79
("unparsed_uri", req.apache_req.unparsed_uri),
80
("parsed_uri", req.apache_req.parsed_uri),
81
("uri", req.apache_req.uri),
82
("filename", req.apache_req.filename),
83
("path_info", req.apache_req.path_info),
86
print_table(req, "Field Storage",
87
getfieldvalues(req.get_fieldstorage().items()))
88
session = req.get_session()
89
print_table(req, "Session Variables", session.items())
91
print_table(req, "HTTP Request Headers",
92
req.apache_req.headers_in.items())
93
print_table(req, "CGI Environment Variables",
94
req.get_cgi_environ().items())
95
print_table(req, "Server Environment Variables", os.environ.items())
97
req.write("<h3>Removal instructions</h3>\n")
98
req.write("""<p>In a production environment, debuginfo should be disabled.
99
To do this, comment out or remove the debuginfo line of the app_url
100
dictionary in ivle/conf/apps.py.</p>
101
<p>For extra security, it may be removed completely by deleting the
102
apps/debuginfo directory.</p>
106
def getfieldvalues(pairs):
107
"""Given a list of pairs of strings and fields, returns a new list with
108
the 2nd elements of each pair modified to be the field's value."""
109
if pairs is None: return None
112
newlist.append((k,v.value))
115
def print_table(req, tablename, mapping, head_elem="h3"):
116
"""Prints an HTML table with a heading.
118
mapping: An associative list (a list of pairs). The pairs are printed
119
using (str, repr) respectively into the two-column table."""
120
req.write("<%s>%s</%s>\n" % (head_elem, tablename, head_elem))
121
req.write('<table border="1">\n')
122
for (k,v) in mapping:
123
req.write("<tr><th>%s</th><td>%s</td></tr>\n" %
124
(cgi.escape(str(k)), cgi.escape(repr(v))))
125
req.write("</table>\n")