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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2007-12-20 03:14:17 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:93
New directory hierarchy.
Renamed src to www.
Added console, trampoline (currently empty).

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
 
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", [
42
 
        ("ivlepath", conf.ivlepath),
43
 
        ("root_dir", conf.root_dir),
44
 
        ("student_dir", conf.student_dir),
45
 
        ("default_app", conf.default_app),
46
 
    ])
47
 
 
48
 
    print_table(req, "Available Applications", conf.apps.app_url.items())
49
 
 
50
 
    print_table(req, "Request Properties", [
51
 
        ("uri", req.uri),
52
 
        ("app", req.app),
53
 
        ("path", req.path),
54
 
    ])
55
 
 
56
 
    # Violate encapsulation here to print out the hidden properties
57
 
    print_table(req, "Apache (Hidden) Request Properties", [
58
 
        ("hostname", req.apache_req.hostname),
59
 
        ("method", req.apache_req.method),
60
 
        ("unparsed_uri", req.apache_req.unparsed_uri),
61
 
        ("parsed_uri", req.apache_req.parsed_uri),
62
 
        ("uri", req.apache_req.uri),
63
 
        ("filename", req.apache_req.filename),
64
 
        ("path_info", req.apache_req.path_info),
65
 
    ])
66
 
 
67
 
    print_table(req, "HTTP Request Headers",
68
 
        req.apache_req.headers_in.items())
69
 
    req.apache_req.add_common_vars()
70
 
    print_table(req, "CGI Environment Variables",
71
 
        req.apache_req.subprocess_env.items())
72
 
    print_table(req, "Server Environment Variables", os.environ.items())
73
 
 
74
 
    req.write("<h3>Removal instructions</h3>\n")
75
 
    req.write("""<p>In a production environment, debuginfo should be disabled.
76
 
    To do this, comment out or remove the debuginfo line of the app_url
77
 
    dictionary in conf/apps.py.</p>
78
 
    <p>For extra security, it may be removed completely by deleting the
79
 
    apps/debuginfo directory.</p>\n""")
80
 
 
81
 
def print_table(req, tablename, mapping):
82
 
    """Prints an HTML table with a heading.
83
 
 
84
 
    mapping: An associative list (a list of pairs). The pairs are printed
85
 
    using (str, repr) respectively into the two-column table."""
86
 
    req.write("<h3>%s</h3>\n" % tablename)
87
 
    req.write('<table border="1">\n')
88
 
    for (k,v) in mapping:
89
 
        req.write("<tr><th>%s</th><td>%s</td></tr>\n" % (str(k), repr(v)))
90
 
    req.write("</table>\n")
91