~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:23:06 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-20090217002306-kbynvai4eigb2d56
Move more stuff from interpretservice to serveservice.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
import cjson
30
30
 
31
 
from ivle import (cgirequest, studpath)
32
31
from ivle import zip as zipmod
 
32
import ivle.conf.app.server
 
33
 
 
34
def determine_file_type(filename):
 
35
    filetype = mimetypes.guess_type(filename)[0]
 
36
    if filetype is None:
 
37
         filetype = ivle.conf.mimetypes.default_mimetype
 
38
    return filetype
33
39
 
34
40
def throw_error(message):
35
41
    print cjson.encode({'error': message})
57
63
else:
58
64
    download = False
59
65
    paths = args
 
66
    assert len(paths) == 1
60
67
 
61
68
default_mimetype = "application/octet-stream"
62
69
zip_mimetype = "application/zip"
77
84
 
78
85
    # If it's a directory, serve as a zip file
79
86
    if os.path.isdir(filename):
 
87
        if not download:
 
88
            # Not giving a directory listing - this is visible to everyone.
 
89
            throw_error('is-directory')
80
90
        zipmode = True
81
91
        # Zip it from the perspective of its own parent.
82
92
        # That way it will be a directory in the top level of the zip
90
100
            zipbasepath = splitpath[0]
91
101
            paths = [splitpath[1]]
92
102
        zipfilename = filename
 
103
    else:
 
104
        if not download and \
 
105
           determine_file_type(filename) in ivle.conf.app.server.interpreters:
 
106
            throw_error('is-executable')
 
107
 
 
108
        if (ivle.conf.app.server.blacklist_served_filetypes and \
 
109
                determine_file_type(filename) in \
 
110
                ivle.conf.app.server.served_filetypes_blacklist) or \
 
111
            (ivle.conf.app.server.served_filetypes_whitelist and \
 
112
                determine_file_type(filename) not in \
 
113
                ivle.conf.app.server.served_filetypes_whitelist):
 
114
            throw_error('forbidden')
93
115
 
94
116
if zipmode:
95
117
    # zipfilename is some filename. Strip trailing slash or extension,