~azzar1/unity/add-show-desktop-key

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
from common import util
27
import conf
28
from conf import apps
29
import os
30
31
def handle(req):
32
    """Handler for the Debug Information application."""
33
34
    # Set request attributes
35
    req.content_type = "text/html"
36
    req.write_html_head_foot = True     # Have dispatch print head and foot
37
38
    # Start writing data
345 by mattgiuca
Global CSS change: ivlebody no longer has 1em of padding (it has none).
39
    req.write('<div id="ivle_padding">\n')
93 by mattgiuca
New directory hierarchy.
40
    req.write("<h2>IVLE Debug Information</h2>\n")
41
42
    print_table(req, "System Constants", [
248 by mattgiuca
Added variable "ivle_version" to conf/__init__.py. This stores the version
43
        ("ivle_version", conf.ivle_version),
105 by mattgiuca
Removed all use of ivlepath variable. It is no longer set.
44
        ("ivle_install_dir", conf.ivle_install_dir),
93 by mattgiuca
New directory hierarchy.
45
        ("root_dir", conf.root_dir),
260 by mattgiuca
debuginfo: Added & fixed up display of server config vars.
46
        ("public_host", conf.public_host),
106 by mattgiuca
Renamed "student_dir" to "jail_base" across the suite.
47
        ("jail_base", conf.jail_base),
260 by mattgiuca
debuginfo: Added & fixed up display of server config vars.
48
        ("default_app", conf.apps.default_app),
49
        ("public_app", conf.apps.public_app),
93 by mattgiuca
New directory hierarchy.
50
    ])
51
109 by mattgiuca
debuginfo: User/group IDs are displayed in the printout.
52
    print_table(req, "Operating System Variables", [
53
        ("uid", os.getuid()),
54
        ("euid", os.geteuid()),
55
        ("gid", os.getgid()),
56
        ("egid", os.getegid()),
397 by drtomc
debuginfo: Added print of os.uname().
57
        ("uname", os.uname()),
109 by mattgiuca
debuginfo: User/group IDs are displayed in the printout.
58
    ])
59
93 by mattgiuca
New directory hierarchy.
60
    print_table(req, "Available Applications", conf.apps.app_url.items())
61
62
    print_table(req, "Request Properties", [
124 by mattgiuca
dispatch/request: Added new fields: method and username.
63
        ("method", req.method),
93 by mattgiuca
New directory hierarchy.
64
        ("uri", req.uri),
65
        ("app", req.app),
66
        ("path", req.path),
124 by mattgiuca
dispatch/request: Added new fields: method and username.
67
        ("username", req.username),
255 by mattgiuca
dispatch.request: Added "hostname" field.
68
        ("hostname", req.hostname),
93 by mattgiuca
New directory hierarchy.
69
    ])
70
71
    # Violate encapsulation here to print out the hidden properties
72
    print_table(req, "Apache (Hidden) Request Properties", [
73
        ("hostname", req.apache_req.hostname),
74
        ("method", req.apache_req.method),
75
        ("unparsed_uri", req.apache_req.unparsed_uri),
76
        ("parsed_uri", req.apache_req.parsed_uri),
77
        ("uri", req.apache_req.uri),
78
        ("filename", req.apache_req.filename),
79
        ("path_info", req.apache_req.path_info),
80
    ])
81
156 by mattgiuca
login: getlogin now gets the value out of the field instead of directly
82
    print_table(req, "Field Storage",
83
        getfieldvalues(req.get_fieldstorage().items()))
161 by mattgiuca
dispatch.login: Correctly stores the username string (not argument field)
84
    print_table(req, "Session Variables", req.get_session().items())
124 by mattgiuca
dispatch/request: Added new fields: method and username.
85
93 by mattgiuca
New directory hierarchy.
86
    print_table(req, "HTTP Request Headers",
87
        req.apache_req.headers_in.items())
88
    print_table(req, "CGI Environment Variables",
247 by mattgiuca
request.py: Added get_cgi_environ method. This asks Apache to emulate CGI
89
        req.get_cgi_environ().items())
93 by mattgiuca
New directory hierarchy.
90
    print_table(req, "Server Environment Variables", os.environ.items())
91
92
    req.write("<h3>Removal instructions</h3>\n")
93
    req.write("""<p>In a production environment, debuginfo should be disabled.
94
    To do this, comment out or remove the debuginfo line of the app_url
95
    dictionary in conf/apps.py.</p>
96
    <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).
97
    apps/debuginfo directory.</p>
98
</div>
99
""")
93 by mattgiuca
New directory hierarchy.
100
156 by mattgiuca
login: getlogin now gets the value out of the field instead of directly
101
def getfieldvalues(pairs):
102
    """Given a list of pairs of strings and fields, returns a new list with
103
    the 2nd elements of each pair modified to be the field's value."""
104
    if pairs is None: return None
105
    newlist = []
106
    for k,v in pairs:
107
        newlist.append((k,v.value))
108
    return newlist
109
93 by mattgiuca
New directory hierarchy.
110
def print_table(req, tablename, mapping):
111
    """Prints an HTML table with a heading.
112
113
    mapping: An associative list (a list of pairs). The pairs are printed
114
    using (str, repr) respectively into the two-column table."""
115
    req.write("<h3>%s</h3>\n" % tablename)
116
    req.write('<table border="1">\n')
117
    for (k,v) in mapping:
118
        req.write("<tr><th>%s</th><td>%s</td></tr>\n" % (str(k), repr(v)))
119
    req.write("</table>\n")
120