1 | <?php |
||||||
2 | |||||||
3 | use LibreNMS\Config; |
||||||
0 ignored issues
–
show
|
|||||||
4 | |||||||
5 | global $debug; |
||||||
6 | |||||||
7 | // Push $_GET into $vars to be compatible with web interface naming |
||||||
8 | foreach ($_GET as $name => $value) { |
||||||
9 | $vars[$name] = $value; |
||||||
10 | } |
||||||
11 | |||||||
12 | [$type, $subtype] = extract_graph_type($vars['type']); |
||||||
13 | |||||||
14 | if (is_numeric($vars['device'])) { |
||||||
15 | $device = device_by_id_cache($vars['device']); |
||||||
16 | } elseif (! empty($vars['device'])) { |
||||||
17 | $device = device_by_name($vars['device']); |
||||||
18 | } |
||||||
19 | |||||||
20 | // FIXME -- remove these |
||||||
21 | $width = $vars['width']; |
||||||
22 | $height = $vars['height']; |
||||||
23 | $title = $vars['title']; |
||||||
24 | $vertical = $vars['vertical']; |
||||||
25 | $legend = $vars['legend']; |
||||||
26 | $output = (! empty($vars['output']) ? $vars['output'] : 'default'); |
||||||
27 | $from = parse_at_time($_GET['from']) ?: Config::get('time.day'); |
||||||
28 | $to = parse_at_time($_GET['to']) ?: Config::get('time.now'); |
||||||
29 | $period = ($to - $from); |
||||||
30 | $prev_from = ($from - $period); |
||||||
31 | |||||||
32 | $graph_image_type = $vars['graph_type'] ?? Config::get('webui.graph_type'); |
||||||
33 | $rrd_options = ''; |
||||||
34 | |||||||
35 | require Config::get('install_dir') . "/includes/html/graphs/$type/auth.inc.php"; |
||||||
36 | |||||||
37 | //set default graph title |
||||||
38 | $graph_title = format_hostname($device); |
||||||
39 | |||||||
40 | if ($auth && is_customoid_graph($type, $subtype)) { |
||||||
41 | $unit = $vars['unit']; |
||||||
42 | include Config::get('install_dir') . '/includes/html/graphs/customoid/customoid.inc.php'; |
||||||
43 | } elseif ($auth && is_file(Config::get('install_dir') . "/includes/html/graphs/$type/$subtype.inc.php")) { |
||||||
44 | include Config::get('install_dir') . "/includes/html/graphs/$type/$subtype.inc.php"; |
||||||
45 | } else { |
||||||
46 | graph_error("$type*$subtype "); |
||||||
47 | // Graph Template Missing"); |
||||||
48 | } |
||||||
49 | |||||||
50 | if (! empty($error_msg)) { |
||||||
51 | // We have an error :( |
||||||
52 | graph_error($error_msg); |
||||||
53 | |||||||
54 | return; |
||||||
55 | } |
||||||
56 | |||||||
57 | if ($auth === null) { |
||||||
58 | // We are unauthenticated :( |
||||||
59 | graph_error($width < 200 ? 'No Auth' : 'No Authorization'); |
||||||
60 | |||||||
61 | return; |
||||||
62 | } |
||||||
63 | |||||||
64 | if ($graph_image_type === 'svg') { |
||||||
65 | $rrd_options .= ' --imgformat=SVG'; |
||||||
66 | if ($width < 350) { |
||||||
67 | $rrd_options .= ' -m 0.75 -R light'; |
||||||
68 | } |
||||||
69 | } |
||||||
70 | |||||||
71 | // command output requested |
||||||
72 | if (! empty($command_only)) { |
||||||
73 | echo "<div class='infobox'>"; |
||||||
74 | echo "<p style='font-size: 16px; font-weight: bold;'>RRDTool Command</p>"; |
||||||
75 | echo "<pre class='rrd-pre'>"; |
||||||
76 | echo escapeshellcmd('rrdtool ' . Rrd::buildCommand('graph', Config::get('temp_dir') . '/' . strgen(), $rrd_options)); |
||||||
0 ignored issues
–
show
The method
buildCommand() does not exist on App\Facades\Rrd . Since you implemented __callStatic , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
77 | echo '</pre>'; |
||||||
78 | try { |
||||||
79 | Rrd::graph($rrd_options); |
||||||
0 ignored issues
–
show
The method
graph() does not exist on App\Facades\Rrd . Since you implemented __callStatic , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
80 | } catch (\LibreNMS\Exceptions\RrdGraphException $e) { |
||||||
81 | echo "<p style='font-size: 16px; font-weight: bold;'>RRDTool Output</p>"; |
||||||
82 | echo "<pre class='rrd-pre'>"; |
||||||
83 | echo $e->getMessage(); |
||||||
84 | echo '</pre>'; |
||||||
85 | } |
||||||
86 | echo '</div>'; |
||||||
87 | |||||||
88 | return; |
||||||
89 | } |
||||||
90 | |||||||
91 | // graph sent file not found flag |
||||||
92 | if (! empty($no_file)) { |
||||||
93 | graph_error($width < 200 ? 'No Data' : 'No Data file ' . $no_file); |
||||||
94 | |||||||
95 | return; |
||||||
96 | } |
||||||
97 | |||||||
98 | if (empty($rrd_options)) { |
||||||
99 | graph_error($width < 200 ? 'Def Error' : 'Graph Definition Error'); |
||||||
100 | |||||||
101 | return; |
||||||
102 | } |
||||||
103 | |||||||
104 | // Generating the graph! |
||||||
105 | try { |
||||||
106 | $image_data = Rrd::graph($rrd_options); |
||||||
107 | |||||||
108 | // output the graph |
||||||
109 | if (\LibreNMS\Util\Debug::isEnabled()) { |
||||||
110 | echo '<img src="data:' . get_image_type($graph_image_type) . ';base64,' . base64_encode($image_data) . '" alt="graph" />'; |
||||||
111 | } else { |
||||||
112 | header('Content-type: ' . get_image_type(Config::get('webui.graph_type'))); |
||||||
0 ignored issues
–
show
It seems like
LibreNMS\Config::get('webui.graph_type') can also be of type null ; however, parameter $type of get_image_type() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
113 | echo $output === 'base64' ? base64_encode($image_data) : $image_data; |
||||||
114 | } |
||||||
115 | } catch (\LibreNMS\Exceptions\RrdGraphException $e) { |
||||||
116 | if (isset($rrd_filename) && ! Rrd::checkRrdExists($rrd_filename)) { |
||||||
0 ignored issues
–
show
The method
checkRrdExists() does not exist on App\Facades\Rrd . Since you implemented __callStatic , consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
117 | graph_error($width < 200 ? 'No Data' : 'No Data file ' . basename($rrd_filename)); |
||||||
118 | } else { |
||||||
119 | graph_error($width < 200 ? 'Draw Error' : 'Error Drawing Graph: ' . $e->getMessage()); |
||||||
120 | } |
||||||
121 | } |
||||||
122 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: