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

« back to all changes in this revision

Viewing changes to services/serveservice

  • Committer: William Grant
  • Date: 2009-02-17 00:39:05 UTC
  • mto: (1099.1.143 new-dispatch)
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: grantw@unimelb.edu.au-20090217003905-f3aie9oqb9vrsfrn
Enable CGI path backtracking in serveservice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
         filetype = ivle.conf.mimetypes.default_mimetype
37
37
    return filetype
38
38
 
39
 
def throw_error(message):
40
 
    print cjson.encode({'error': message})
 
39
def throw_error(message, extra={}):
 
40
    error = {'error': message}
 
41
    error.update(extra)
 
42
    print cjson.encode(error)
41
43
    sys.exit(0)
42
44
 
43
45
parser = OptionParser()
78
80
    zipfilename = os.path.basename(zipbasepath)
79
81
else:
80
82
    filename = paths[0]
81
 
    if not os.access(filename, os.R_OK):
82
 
        throw_error('not-found')
 
83
    if not os.access(filename, os.F_OK):
 
84
        # The given path doesn't exist. CGI lets us backtrack and put the path
 
85
        # elements through which we pass into PATH_INFO, so we try that.
 
86
        while not os.access(filename, os.F_OK):
 
87
            filename, path_info_frag = os.path.split(filename)
 
88
 
 
89
        # We now have a file that exists, but is it something that we're allowed
 
90
        # to execute? If not, we should 404 anyway.
 
91
        if determine_file_type(filename) not in ivle.conf.app.server.interpreters:
 
92
            throw_error('not-found')
83
93
 
84
94
    # If it's a directory, serve as a zip file
85
95
    if os.path.isdir(filename):
102
112
    else:
103
113
        if not download and \
104
114
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
105
 
            throw_error('is-executable')
 
115
            throw_error('is-executable', {'path': filename})
106
116
 
107
117
        if (ivle.conf.app.server.blacklist_served_filetypes and \
108
118
                determine_file_type(filename) in \