~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()),
57
    ])
58
93 by mattgiuca
New directory hierarchy.
59
    print_table(req, "Available Applications", conf.apps.app_url.items())
60
61
    print_table(req, "Request Properties", [
124 by mattgiuca
dispatch/request: Added new fields: method and username.
62
        ("method", req.method),
93 by mattgiuca
New directory hierarchy.
63
        ("uri", req.uri),
64
        ("app", req.app),
65
        ("path", req.path),
124 by mattgiuca
dispatch/request: Added new fields: method and username.
66
        ("username", req.username),
255 by mattgiuca
dispatch.request: Added "hostname" field.
67
        ("hostname", req.hostname),
93 by mattgiuca
New directory hierarchy.
68
    ])
69
70
    # Violate encapsulation here to print out the hidden properties
71
    print_table(req, "Apache (Hidden) Request Properties", [
72
        ("hostname", req.apache_req.hostname),
73
        ("method", req.apache_req.method),
74
        ("unparsed_uri", req.apache_req.unparsed_uri),
75
        ("parsed_uri", req.apache_req.parsed_uri),
76
        ("uri", req.apache_req.uri),
77
        ("filename", req.apache_req.filename),
78
        ("path_info", req.apache_req.path_info),
79
    ])
80
156 by mattgiuca
login: getlogin now gets the value out of the field instead of directly
81
    print_table(req, "Field Storage",
82
        getfieldvalues(req.get_fieldstorage().items()))
161 by mattgiuca
dispatch.login: Correctly stores the username string (not argument field)
83
    print_table(req, "Session Variables", req.get_session().items())
124 by mattgiuca
dispatch/request: Added new fields: method and username.
84
93 by mattgiuca
New directory hierarchy.
85
    print_table(req, "HTTP Request Headers",
86
        req.apache_req.headers_in.items())
87
    print_table(req, "CGI Environment Variables",
247 by mattgiuca
request.py: Added get_cgi_environ method. This asks Apache to emulate CGI
88
        req.get_cgi_environ().items())
93 by mattgiuca
New directory hierarchy.
89
    print_table(req, "Server Environment Variables", os.environ.items())
90
91
    req.write("<h3>Removal instructions</h3>\n")
92
    req.write("""<p>In a production environment, debuginfo should be disabled.
93
    To do this, comment out or remove the debuginfo line of the app_url
94
    dictionary in conf/apps.py.</p>
95
    <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).
96
    apps/debuginfo directory.</p>
97
</div>
98
""")
93 by mattgiuca
New directory hierarchy.
99
156 by mattgiuca
login: getlogin now gets the value out of the field instead of directly
100
def getfieldvalues(pairs):
101
    """Given a list of pairs of strings and fields, returns a new list with
102
    the 2nd elements of each pair modified to be the field's value."""
103
    if pairs is None: return None
104
    newlist = []
105
    for k,v in pairs:
106
        newlist.append((k,v.value))
107
    return newlist
108
93 by mattgiuca
New directory hierarchy.
109
def print_table(req, tablename, mapping):
110
    """Prints an HTML table with a heading.
111
112
    mapping: An associative list (a list of pairs). The pairs are printed
113
    using (str, repr) respectively into the two-column table."""
114
    req.write("<h3>%s</h3>\n" % tablename)
115
    req.write('<table border="1">\n')
116
    for (k,v) in mapping:
117
        req.write("<tr><th>%s</th><td>%s</td></tr>\n" % (str(k), repr(v)))
118
    req.write("</table>\n")
119