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

« back to all changes in this revision

Viewing changes to www/apps/debuginfo/__init__.py

  • Committer: William Grant
  • Date: 2009-02-23 23:47:02 UTC
  • mfrom: (1099.1.211 new-dispatch)
  • Revision ID: grantw@unimelb.edu.au-20090223234702-db4b1llly46ignwo
Merge from lp:~ivle-dev/ivle/new-dispatch.

Pretty much everything changes. Reread the setup docs. Backup your databases.
Every file is now in a different installed location, the configuration system
is rewritten, the dispatch system is rewritten, URLs are different, the
database is different, worksheets and exercises are no longer on the
filesystem, we use a templating engine, jail service protocols are rewritten,
we don't repeat ourselves, we have authorization rewritten, phpBB is gone,
and probably lots of other things that I cannot remember.

This is certainly the biggest commit I have ever made, and hopefully
the largest I ever will.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
27
 
import cgi
28
 
 
29
 
from ivle import util
30
 
import ivle.conf
31
 
 
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
40
 
    req.write('<div id="ivle_padding">\n')
41
 
    req.write("<h2>IVLE Debug Information</h2>\n")
42
 
 
43
 
    print_table(req, "System Constants", [
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),
54
 
    ])
55
 
 
56
 
    print_table(req, "Operating System Variables", [
57
 
        ("uid", os.getuid()),
58
 
        ("euid", os.geteuid()),
59
 
        ("gid", os.getgid()),
60
 
        ("egid", os.getegid()),
61
 
        ("uname", os.uname()),
62
 
    ])
63
 
 
64
 
    print_table(req, "Available Applications", ivle.conf.apps.app_url.items())
65
 
 
66
 
    print_table(req, "Request Properties", [
67
 
        ("method", req.method),
68
 
        ("uri", req.uri),
69
 
        ("app", req.app),
70
 
        ("path", req.path),
71
 
        ("user", req.user),
72
 
        ("hostname", req.hostname),
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
 
 
86
 
    print_table(req, "Field Storage",
87
 
        getfieldvalues(req.get_fieldstorage().items()))
88
 
    session = req.get_session()
89
 
    print_table(req, "Session Variables", session.items())
90
 
 
91
 
    print_table(req, "HTTP Request Headers",
92
 
        req.apache_req.headers_in.items())
93
 
    print_table(req, "CGI Environment Variables",
94
 
        req.get_cgi_environ().items())
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
100
 
    dictionary in ivle/conf/apps.py.</p>
101
 
    <p>For extra security, it may be removed completely by deleting the
102
 
    apps/debuginfo directory.</p>
103
 
</div>
104
 
""")
105
 
 
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
 
 
115
 
def print_table(req, tablename, mapping, head_elem="h3"):
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."""
120
 
    req.write("<%s>%s</%s>\n" % (head_elem, tablename, head_elem))
121
 
    req.write('<table border="1">\n')
122
 
    for (k,v) in mapping:
123
 
        req.write("<tr><th>%s</th><td>%s</td></tr>\n" %
124
 
                  (cgi.escape(str(k)), cgi.escape(repr(v))))
125
 
    req.write("</table>\n")
126