Issues (2963)

includes/html/pages/device/capture.inc.php (1 issue)

1
<?php
2
/**
3
 * capture.inc.php
4
 *
5
 * View and download troubleshooting information
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
$no_refresh = true;
26
$pagetitle[] = 'Capture';
27
28
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

28
if (! Auth::user()->/** @scrutinizer ignore-call */ hasGlobalAdmin()) {
Loading history...
29
    print_error('Insufficient Privileges');
30
} else {
31
    ?>
32
    <h2>Capture Debug Information</h2>
33
    <ul class="nav nav-tabs">
34
        <li role="presentation" class="active"><a data-toggle="tab" href="#discovery">Discovery</a></li>
35
        <li role="presentation"><a data-toggle="tab" href="#poller">Poller</a></li>
36
        <li role="presentation"><a data-toggle="tab" href="#snmp">SNMP</a></li>
37
        <li role="presentation"><a data-toggle="tab" href="#alerts">Alerts</a></li>
38
    </ul>
39
    <div class="tab-content">
40
    <?php
41
    $tabs = [
42
        'discovery' => 'ajax_output.php?id=capture&format=text&type=discovery&hostname=' . $device['hostname'],
43
        'poller'    => 'ajax_output.php?id=capture&format=text&type=poller&hostname=' . $device['hostname'],
44
        'snmp'      => 'ajax_output.php?id=capture&format=text&type=snmpwalk&hostname=' . $device['hostname'],
45
        'alerts'    => 'ajax_output.php?id=query&format=text&type=alerts&hostname=' . $device['hostname'],
46
    ];
47
48
    foreach ($tabs as $tab => $url) {
49
        ?>
50
        <div id="<?php echo $tab ?>" class="tab-pane fade <?php echo $tab == 'discovery' ? ' in active' : '' ?>">
51
        <div class="row"><div class="col-md-12">
52
        <div class="btn-toolbar" role="toolbar" style="margin:5px 0 5px 0">
53
        <button type="button" class="btn btn-success" id="run-<?php echo $tab ?>"><i class="fa fa-play fa-lg"></i> Run</button>
54
        <button type="button" class="btn btn-primary" id="copy-<?php echo $tab ?>"><i class="fa fa-clipboard fa-lg"></i> Copy</button>
55
        <a class="btn btn-warning" href="<?php echo str_replace('text', 'download', $url) ?>"><i class="fa fa-download fa-lg"></i> Download</a>
56
        </div></div></div>
57
        <div class="row"><div class="col-md-12">
58
        <textarea readonly id="output-<?php echo $tab ?>" class="form-control" rows="30" placeholder="Output" style="resize:vertical;"></textarea>
59
        </div></div>
60
        </div>
61
        <script type="text/javascript">
62
63
            document.getElementById('copy-<?php echo $tab ?>').onclick = function() {
64
                output = document.getElementById("output-<?php echo $tab ?>");
65
                output.select();
66
                try {
67
                    document.execCommand('copy');
68
                } catch (err) {
69
                    alert('Unsupported Browser!');
70
                }
71
            };
72
73
            document.getElementById('run-<?php echo $tab ?>').onclick = function () {
74
                output = document.getElementById("output-<?php echo $tab ?>");
75
                xhr = new XMLHttpRequest();
76
                xhr.open("GET", "<?php echo $url ?>", true);
77
                xhr.onprogress = function (e) {
78
                    output.innerHTML = e.currentTarget.responseText;
79
                    output.scrollTop = output.scrollHeight - output.clientHeight; // scrolls the output area
80
                };
81
                xhr.onreadystatechange = function () {
82
                    if (xhr.readyState == 4) {
83
                        console.log("Complete");
84
                    }
85
                };
86
                xhr.send();
87
            };
88
        </script>
89
        <?php
90
    }
91
    echo '</div>';
92
}
93