Issues (2963)

includes/html/output/capture.inc.php (1 issue)

1
<?php
2
/**
3
 * output.php
4
 *
5
 * runs the requested command and outputs as a file or json
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program 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.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 *
20
 * @link       https://www.librenms.org
21
 *
22
 * @copyright  2016 Tony Murray
23
 * @author     Tony Murray <[email protected]>
24
 */
25
if (! Auth::user()->hasGlobalAdmin()) {
0 ignored issues
show
The method hasGlobalAdmin() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

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

25
if (! Auth::user()->/** @scrutinizer ignore-call */ hasGlobalAdmin()) {
Loading history...
26
    echo 'Insufficient Privileges';
27
    exit();
28
}
29
30
$hostname = escapeshellcmd($_REQUEST['hostname']);
31
$type = $_REQUEST['type'];
32
33
switch ($type) {
34
    case 'poller':
35
        $cmd = ['php', \LibreNMS\Config::get('install_dir') . '/poller.php', '-h', $hostname, '-r', '-f', '-d'];
36
        $filename = "poller-$hostname.txt";
37
        break;
38
    case 'snmpwalk':
39
        $device = device_by_name($hostname);
40
41
        $cmd = gen_snmpwalk_cmd($device, '.', '-OUneb');
42
43
        $filename = $device['os'] . '-' . $device['hostname'] . '.snmpwalk';
44
        break;
45
    case 'discovery':
46
        $cmd = ['php', \LibreNMS\Config::get('install_dir') . '/discovery.php', '-h', $hostname, '-d'];
47
        $filename = "discovery-$hostname.txt";
48
        break;
49
    default:
50
        echo 'You must specify a valid type';
51
        exit;
52
}
53
54
// ---- Output ----
55
$proc = new \Symfony\Component\Process\Process($cmd);
56
$proc->setTimeout(Config::get('snmp.exec_timeout', 1200));
57
58
if ($_GET['format'] == 'text') {
59
    header('Content-type: text/plain');
60
    header('X-Accel-Buffering: no');
61
62
    $proc->run(function ($type, $buffer) {
63
        echo preg_replace('/\033\[[\d;]+m/', '', $buffer) . PHP_EOL;
64
        ob_flush();
65
        flush(); // you have to flush buffer
66
    });
67
} elseif ($_GET['format'] == 'download') {
68
    $proc->run();
69
    $output = $proc->getOutput();
70
71
    $output = preg_replace('/\033\[[\d;]+m/', '', $output);
72
73
    file_download($filename, $output);
74
}
75