93
by mattgiuca
New directory hierarchy. |
1 |
# IVLE
|
2 |
# Copyright (C) 2007-2008 The University of Melbourne
|
|
3 |
#
|
|
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.
|
|
8 |
#
|
|
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.
|
|
13 |
#
|
|
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
|
|
17 |
||
18 |
# App: debuginfo
|
|
19 |
# Author: Matt Giuca
|
|
20 |
# Date: 17/12/2007
|
|
21 |
||
22 |
# Displays lots of internal information about IVLE's running environment,
|
|
23 |
# a la phpinfo.
|
|
24 |
# Important: This application should be removed from a production system.
|
|
25 |
||
26 |
import os |
|
1080.1.9
by me at id
apps/debuginfo: Don't use req.user as a dict, and otherwise make it work |
27 |
import cgi |
93
by mattgiuca
New directory hierarchy. |
28 |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
29 |
from ivle import util |
30 |
import ivle.conf |
|
31 |
||
93
by mattgiuca
New directory hierarchy. |
32 |
def handle(req): |
33 |
"""Handler for the Debug Information application."""
|
|
34 |
||
35 |
# Set request attributes
|
|
36 |
req.content_type = "text/html" |
|
37 |
req.write_html_head_foot = True # Have dispatch print head and foot |
|
38 |
||
39 |
# Start writing data
|
|
345
by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none). |
40 |
req.write('<div id="ivle_padding">\n') |
93
by mattgiuca
New directory hierarchy. |
41 |
req.write("<h2>IVLE Debug Information</h2>\n") |
42 |
||
43 |
print_table(req, "System Constants", [ |
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
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), |
|
93
by mattgiuca
New directory hierarchy. |
54 |
])
|
55 |
||
109
by mattgiuca
debuginfo: User/group IDs are displayed in the printout. |
56 |
print_table(req, "Operating System Variables", [ |
57 |
("uid", os.getuid()), |
|
58 |
("euid", os.geteuid()), |
|
59 |
("gid", os.getgid()), |
|
60 |
("egid", os.getegid()), |
|
397
by drtomc
debuginfo: Added print of os.uname(). |
61 |
("uname", os.uname()), |
109
by mattgiuca
debuginfo: User/group IDs are displayed in the printout. |
62 |
])
|
63 |
||
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
64 |
print_table(req, "Available Applications", ivle.conf.apps.app_url.items()) |
93
by mattgiuca
New directory hierarchy. |
65 |
|
66 |
print_table(req, "Request Properties", [ |
|
124
by mattgiuca
dispatch/request: Added new fields: method and username. |
67 |
("method", req.method), |
93
by mattgiuca
New directory hierarchy. |
68 |
("uri", req.uri), |
69 |
("app", req.app), |
|
70 |
("path", req.path), |
|
506
by mattgiuca
dispatch.__init__, dispatch.request, cgirequest: |
71 |
("user", req.user), |
255
by mattgiuca
dispatch.request: Added "hostname" field. |
72 |
("hostname", req.hostname), |
93
by mattgiuca
New directory hierarchy. |
73 |
])
|
74 |
||
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), |
|
84 |
])
|
|
85 |
||
156
by mattgiuca
login: getlogin now gets the value out of the field instead of directly |
86 |
print_table(req, "Field Storage", |
87 |
getfieldvalues(req.get_fieldstorage().items())) |
|
504
by mattgiuca
Warning: Broken build, but rather unavoidable or this commit will spiral out |
88 |
session = req.get_session() |
89 |
print_table(req, "Session Variables", session.items()) |
|
124
by mattgiuca
dispatch/request: Added new fields: method and username. |
90 |
|
93
by mattgiuca
New directory hierarchy. |
91 |
print_table(req, "HTTP Request Headers", |
92 |
req.apache_req.headers_in.items()) |
|
93 |
print_table(req, "CGI Environment Variables", |
|
247
by mattgiuca
request.py: Added get_cgi_environ method. This asks Apache to emulate CGI |
94 |
req.get_cgi_environ().items()) |
93
by mattgiuca
New directory hierarchy. |
95 |
print_table(req, "Server Environment Variables", os.environ.items()) |
96 |
||
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
|
|
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
100 |
dictionary in ivle/conf/apps.py.</p>
|
93
by mattgiuca
New directory hierarchy. |
101 |
<p>For extra security, it may be removed completely by deleting the
|
345
by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none). |
102 |
apps/debuginfo directory.</p>
|
103 |
</div>
|
|
104 |
""") |
|
93
by mattgiuca
New directory hierarchy. |
105 |
|
156
by mattgiuca
login: getlogin now gets the value out of the field instead of directly |
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 |
|
110 |
newlist = [] |
|
111 |
for k,v in pairs: |
|
112 |
newlist.append((k,v.value)) |
|
113 |
return newlist |
|
114 |
||
504
by mattgiuca
Warning: Broken build, but rather unavoidable or this commit will spiral out |
115 |
def print_table(req, tablename, mapping, head_elem="h3"): |
93
by mattgiuca
New directory hierarchy. |
116 |
"""Prints an HTML table with a heading.
|
117 |
||
118 |
mapping: An associative list (a list of pairs). The pairs are printed
|
|
119 |
using (str, repr) respectively into the two-column table."""
|
|
504
by mattgiuca
Warning: Broken build, but rather unavoidable or this commit will spiral out |
120 |
req.write("<%s>%s</%s>\n" % (head_elem, tablename, head_elem)) |
93
by mattgiuca
New directory hierarchy. |
121 |
req.write('<table border="1">\n') |
122 |
for (k,v) in mapping: |
|
1080.1.9
by me at id
apps/debuginfo: Don't use req.user as a dict, and otherwise make it work |
123 |
req.write("<tr><th>%s</th><td>%s</td></tr>\n" % |
124 |
(cgi.escape(str(k)), cgi.escape(repr(v)))) |
|
93
by mattgiuca
New directory hierarchy. |
125 |
req.write("</table>\n") |
126 |