Issues (2963)

includes/html/graphs/common.inc.php (2 issues)

1
<?php
2
3
use LibreNMS\Config;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Config. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
use LibreNMS\Util\Clean;
5
6
if ($_GET['from']) {
7
    $from = parse_at_time($_GET['from']);
8
}
9
10
if ($_GET['to']) {
11
    $to = parse_at_time($_GET['to']);
12
}
13
14
if ($_GET['width']) {
15
    $width = (int) $_GET['width'];
16
}
17
18
if ($_GET['height']) {
19
    $height = (int) $_GET['height'];
20
}
21
22
if ($_GET['inverse']) {
23
    $in = 'out';
24
    $out = 'in';
25
    $inverse = true;
26
} else {
27
    $in = 'in';
28
    $out = 'out';
29
}
30
31
if ($_GET['legend'] == 'no') {
32
    $rrd_options .= ' -g';
33
}
34
35
if (isset($_GET['nototal'])) {
36
    $nototal = ((bool) $_GET['nototal']);
37
} else {
38
    $nototal = true;
39
}
40
41
if (isset($_GET['nodetails'])) {
42
    $nodetails = ((bool) $_GET['nodetails']);
43
} else {
44
    $nodetails = false;
45
}
46
47
if (isset($_GET['noagg'])) {
48
    $noagg = ((bool) $_GET['noagg']);
49
} else {
50
    $noagg = true;
51
}
52
53
if ($_GET['title'] == 'yes') {
54
    $rrd_options .= " --title='" . $graph_title . "' ";
55
}
56
57
if (isset($_GET['graph_title'])) {
58
    $rrd_options .= " --title='" . Clean::alphaDashSpace($_GET['graph_title']) . "' ";
59
}
60
61
if (! isset($scale_min) && ! isset($scale_max)) {
62
    $rrd_options .= ' --alt-autoscale-max';
63
}
64
65
if (! isset($scale_min) && ! isset($scale_max) && ! isset($norigid)) {
66
    $rrd_options .= ' --rigid';
67
}
68
69
if (isset($scale_min)) {
70
    $rrd_options .= " -l $scale_min";
71
}
72
73
if (isset($scale_max)) {
74
    $rrd_options .= " -u $scale_max";
75
}
76
77
if (isset($scale_rigid)) {
78
    $rrd_options .= ' -r';
79
}
80
81
if (! isset($float_precision)) {
82
    $float_precision = 2;
83
}
84
85
$rrd_options .= ' -E --start ' . $from . ' --end ' . $to . ' --width ' . $width . ' --height ' . $height . ' ';
86
87
if (Config::get('applied_site_style') == 'dark') {
88
    $rrd_options .= \LibreNMS\Config::get('rrdgraph_def_text_dark') . ' -c FONT#' . ltrim(\LibreNMS\Config::get('rrdgraph_def_text_color_dark'), '#');
0 ignored issues
show
It seems like LibreNMS\Config::get('rr...h_def_text_color_dark') can also be of type null; however, parameter $string of ltrim() 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 ignore-type  annotation

88
    $rrd_options .= \LibreNMS\Config::get('rrdgraph_def_text_dark') . ' -c FONT#' . ltrim(/** @scrutinizer ignore-type */ \LibreNMS\Config::get('rrdgraph_def_text_color_dark'), '#');
Loading history...
89
} else {
90
    $rrd_options .= \LibreNMS\Config::get('rrdgraph_def_text') . ' -c FONT#' . ltrim(\LibreNMS\Config::get('rrdgraph_def_text_color'), '#');
91
}
92
93
if ($_GET['bg']) {
94
    $rrd_options .= ' -c CANVAS#' . Clean::alphaDash($_GET['bg']) . ' ';
95
}
96
97
if ($_GET['font']) {
98
    $rrd_options .= ' -c FONT#' . Clean::alphaDash($_GET['font']) . ' ';
99
}
100
101
// $rrd_options .= " -c BACK#FFFFFF";
102
if ($height < '99') {
103
    $rrd_options .= ' --only-graph';
104
}
105
106
if ($width <= '300') {
107
    $rrd_options .= ' --font LEGEND:7:' . \LibreNMS\Config::get('mono_font') . ' --font AXIS:6:' . \LibreNMS\Config::get('mono_font');
108
} else {
109
    $rrd_options .= ' --font LEGEND:8:' . \LibreNMS\Config::get('mono_font') . ' --font AXIS:7:' . \LibreNMS\Config::get('mono_font');
110
}
111
112
$rrd_options .= ' --font-render-mode normal';
113
114
if (isset($_GET['absolute']) && $_GET['absolute'] == '1') {
115
    $rrd_options .= ' --full-size-mode';
116
}
117