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