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