~ubuntu-branches/ubuntu/hoary/moodle/hoary

« back to all changes in this revision

Viewing changes to file.php

  • Committer: Bazaar Package Importer
  • Author(s): Isaac Clerencia
  • Date: 2004-12-29 00:49:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041229004952-gliyqzpj2w3e7clx
Tags: 1.4.3-1
* Urgency high as upstream release fixes several security bugs
* New upstream release
* Write database creation errors and warn the user about it, 
closes: #285842, #285842

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?PHP // $Id: file.php,v 1.18 2004/05/28 01:17:37 moodler Exp $
 
1
<?PHP // $Id: file.php,v 1.22.2.4 2004/12/22 21:30:04 skodak Exp $
2
2
      // This function fetches files from the data directory
3
3
      // Syntax:   file.php/courseid/dir/.../dir/filename.ext
4
4
 
10
10
    }
11
11
 
12
12
    if (isset($file)) {     // workaround for situations where / syntax doesn't work
 
13
        if (strpos($file, '..') !== false) {
 
14
            error('File reference contains disallowed characters (double dots)');
 
15
        }
13
16
        $pathinfo = $file;
14
17
    } else {
15
18
        $pathinfo = get_slash_arguments("file.php");
32
35
 
33
36
    $courseid = (integer)$args[0];
34
37
 
35
 
    $course = get_record("course", "id", $courseid);
 
38
    if (!$course = get_record("course", "id", $courseid)) {  // Course ID must be specified
 
39
        error("Invalid course ID");
 
40
    }
36
41
 
37
42
    if ($course->category) {
38
43
        require_login($courseid);
40
45
        require_login();
41
46
    }
42
47
 
43
 
    // it's OK to get here if no course was specified
44
 
 
45
48
    $pathname = "$CFG->dataroot$pathinfo";
46
49
    if ($pathargs = explode("?",$pathname)) {
47
50
        $pathname = $pathargs[0];            // Only keep what's before the '?'
51
54
        $filename = $fileargs[0];            // Only keep what's before the '?'
52
55
    }
53
56
 
54
 
    if (file_exists($pathname)) {
 
57
    if (file_exists($pathname) and !is_dir($pathname)) {
55
58
        $lastmodified = filemtime($pathname);
56
59
        $mimetype = mimeinfo("type", $filename);
57
60
 
60
63
        header("Cache-control: max_age = $CFG->filelifetime");
61
64
        header("Pragma: ");
62
65
        header("Content-disposition: inline; filename=$filename");
 
66
        //header('Accept-Ranges: none');
63
67
 
64
68
 
65
69
        if (empty($CFG->filteruploadedfiles)) {
69
73
 
70
74
        } else {     /// Try and put the file through filters
71
75
            if ($mimetype == "text/html") {
72
 
                $output = format_text(implode('', file($pathname)), FORMAT_HTML, NULL, $courseid);
 
76
                $options->noclean = true;
 
77
                $output = format_text(implode('', file($pathname)), FORMAT_HTML, $options, $courseid);
73
78
 
74
79
                header("Content-length: ".strlen($output));
75
80
                header("Content-type: text/html");
77
82
    
78
83
            } else if ($mimetype == "text/plain") {
79
84
                $options->newlines = false;
 
85
                $options->noclean = true;
80
86
                $output = '<pre>'.format_text(implode('', file($pathname)), FORMAT_MOODLE, $options, $courseid).'</pre>';
81
87
                header("Content-length: ".strlen($output));
82
88
                header("Content-type: text/html");
89
95
            }
90
96
        }
91
97
    } else {
92
 
        error("Sorry, but the file you are looking for was not found ($pathname)", "course/view.php?id=$courseid");
 
98
        header("HTTP/1.0 404 not found");
 
99
        error(get_string("filenotfound", "error"), "$CFG->wwwroot/course/view.php?id=$courseid");
93
100
    }
94
101
 
95
102
    exit;