Issues (1964)

html/user/get_output3.php (2 issues)

1
<?php
2
3
// This file is part of BOINC.
4
// https://boinc.berkeley.edu
5
// Copyright (C) 2024 University of California
6
//
7
// BOINC is free software; you can redistribute it and/or modify it
8
// under the terms of the GNU Lesser General Public License
9
// as published by the Free Software Foundation,
10
// either version 3 of the License, or (at your option) any later version.
11
//
12
// BOINC is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
// See the GNU Lesser General Public License for more details.
16
//
17
// You should have received a copy of the GNU Lesser General Public License
18
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
19
20
// get output files, individually or zipped groups
21
//
22
// args:
23
// action: get_file or get_batch
24
// get_file:
25
//      path: relative to project root dir
26
//      download: if set, download file; else show it in browser
27
// get_batch:
28
//      batch_id
29
//      downloads zip of batch's output files
30
//      Assumes the layout used by sample_assimilator.cpp
31
//      and sample_assimilate.py:
32
//      <project>/results/
33
//      <batchid>/   (0 if not in a batch)
34
//
35
36
require_once("../inc/util.inc");
37
38
// show or download a single output file,
39
// identified by result ID and file index
40
//
41
function get_file() {
42
    $path = get_str('path');
43
    if (strstr($path, '.')) error_page('bad path');
44
    $path = "../../$path";
45
46
    $download = get_str('download', true);
47
    if ($download) {
48
        do_download($path);
49
    } else {
50
        echo "<pre>\n";
51
        echo htmlspecialchars(file_get_contents($path));
52
        echo "</pre>\n";
53
    }
54
}
55
56
// download a zip of the given directory
57
//
58
function get_batch() {
59
    $batch_id = get_int('batch_id');
60
    $dir = "../../results/$batch_id";
61
    if (!is_dir($dir)) die('no batch dir');
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
62
    $name = "batch_$batch_id.zip";
63
    $cmd = "cd $dir; rm -f $name; zip -q $name *";
64
    system($cmd);
65
    do_download("$dir/$name");
66
}
67
68
$action = get_str('action');
69
switch ($action) {
70
case 'get_file': get_file(); break;
0 ignored issues
show
The call to get_file() has too few arguments starting with user. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
case 'get_file': /** @scrutinizer ignore-call */ get_file(); break;

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
71
case 'get_batch': get_batch(); break;
72
}
73
74
?>
75