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

« back to all changes in this revision

Viewing changes to services/interpretservice

  • Committer: William Grant
  • Date: 2009-01-13 01:36:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1123
Merge setup-refactor branch. This completely breaks existing installations;
every path (both filesystem and Python) has changed. Do not upgrade without
knowing what you are doing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import urlparse
31
31
import subprocess
32
32
 
33
 
from common import (cgirequest, studpath)
34
 
import conf
35
 
import conf.mimetypes, conf.app, conf.app.server
 
33
from ivle import (cgirequest, studpath)
 
34
import ivle.conf
 
35
import ivle.conf.mimetypes
 
36
import ivle.conf.app
 
37
import ivle.conf.app.server
36
38
 
37
 
serveservice_path = "/opt/ivle/services/serveservice"
 
39
# XXX: using dirname because we don't have path config in the jailconf.
 
40
serveservice_path = os.path.join(os.path.dirname(__file__), 'serveservice')
38
41
 
39
42
def determine_file_type(filename):
40
43
    filetype = mimetypes.guess_type(filename)[0]
41
44
    if filetype is None:
42
 
         filetype = conf.mimetypes.default_mimetype
 
45
         filetype = ivle.conf.mimetypes.default_mimetype
43
46
    return filetype
44
47
 
45
48
req = cgirequest.CGIRequest()
73
76
 
74
77
    # We now have a file that exists, but is it something that we're allowed
75
78
    # to execute? If not, we should 404 anyway.
76
 
    if determine_file_type(filename) not in conf.app.server.interpreters:
 
79
    if determine_file_type(filename) not in ivle.conf.app.server.interpreters:
77
80
        req.throw_error(req.HTTP_NOT_FOUND,
78
81
            "The specified file (%s) does not exist." % urlpath)
79
82
 
111
114
    # the world at large. Directory contents are private).
112
115
    req.throw_error(req.HTTP_FORBIDDEN,
113
116
        "The path specified is a directory.")
114
 
elif determine_file_type(filename) in conf.app.server.interpreters:
 
117
elif determine_file_type(filename) in ivle.conf.app.server.interpreters:
115
118
    # We'll save on a fork and execute in this python process
116
119
    # Let exceptions blow up normally again
117
120
    sys.excepthook = sys.__excepthook__
121
124
else:
122
125
    # Otherwise, use the blacklist/whitelist to see if this file should be
123
126
    # served or disallowed
124
 
    if (conf.app.server.blacklist_served_filetypes and \
 
127
    if (ivle.conf.app.server.blacklist_served_filetypes and \
125
128
            determine_file_type(filename) in \
126
 
            conf.app.server.served_filetypes_blacklist) or \
127
 
        (conf.app.server.served_filetypes_whitelist and \
 
129
            ivle.conf.app.server.served_filetypes_blacklist) or \
 
130
        (ivle.conf.app.server.served_filetypes_whitelist and \
128
131
            determine_file_type(filename) not in \
129
 
            conf.app.server.served_filetypes_whitelist):
 
132
            ivle.conf.app.server.served_filetypes_whitelist):
130
133
        req.throw_error(req.HTTP_FORBIDDEN,
131
134
            "Files of this type are not allowed to be served.")
132
135