Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle 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 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle 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 Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Library file for report_allbackups
19
 *
20
 * @package    report_allbackups
21
 * @copyright  2020 Catalyst IT
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
/**
26
 * Plugin file handler to allow backups to be downloaded on autobackups report.
27
 *
28
 * @param stdClass $course the course object
29
 * @param stdClass $cm the course module object
30
 * @param context $context the newmodule's context
31
 * @param string $filearea the name of the file area
32
 * @param array $args extra arguments (itemid, path)
33
 * @param bool $forcedownload whether or not force download
34
 * @param array $options additional options affecting the file serving
35
 * @return false
36
 * @throws coding_exception
37
 * @throws dml_exception
38
 * @throws moodle_exception
39
 * @throws require_login_exception
40
 */
41
function report_allbackups_pluginfile($course,
42
                           $cm,
43
                           context $context,
44
                           $filearea,
45
                           $args,
46
                           $forcedownload,
47
                           array $options = array()) {
48
 
49
    if ($context->contextlevel != CONTEXT_SYSTEM) {
50
        return false;
51
    }
52
 
53
    require_login($course, false, $cm);
54
    if (!has_capability('report/allbackups:view', $context)) {
55
        return false;
56
    }
57
    // Make sure backup dir is set.
58
    $backupdest = get_config('backup', 'backup_auto_destination');
59
    if (empty($backupdest)) {
60
        return false;
61
    }
62
    $filename = implode('/', $args);
63
 
64
    // Check nothing weird passed in filename - protect against directory traversal etc.
65
    if ($filename != clean_param($filename, PARAM_FILE)) {
66
        return false;
67
    }
68
 
69
    // Check to make sure this is an mbz file.
70
    if (pathinfo($filename, PATHINFO_EXTENSION) != 'mbz') {
71
        return false;
72
    }
73
    $file = $backupdest .'/'. $filename;
74
    if (is_readable($file)) {
75
        $dontdie = ($options && isset($options['dontdie']));
76
        send_file($file, $filename, null , 0, false, $forcedownload, '', $dontdie);
77
    } else {
78
        send_file_not_found();
79
    }
80
}
81