diff --git a/html/includes/collectd/CollectdColor.php b/html/includes/collectd/CollectdColor.php deleted file mode 100644 index 1ea18d2e0d..0000000000 --- a/html/includes/collectd/CollectdColor.php +++ /dev/null @@ -1,109 +0,0 @@ -r = $value['r'] > 0 ? ($value['r'] > 1 ? 1 : $value['r']) : 0; - } - - if (isset($value['g'])) { - $this->g = $value['g'] > 0 ? ($value['g'] > 1 ? 1 : $value['g']) : 0; - } - - if (isset($value['b'])) { - $this->b = $value['b'] > 0 ? ($value['b'] > 1 ? 1 : $value['b']) : 0; - } - } else { - if (is_string($value)) { - $matches = array(); - if ($value == 'random') { - $this->randomize(); - } else { - if (preg_match('/([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/', - $value, $matches)) { - $this->r = (('0x' . $matches[1]) / 255.0); - $this->g = (('0x' . $matches[2]) / 255.0); - $this->b = (('0x' . $matches[3]) / 255.0); - } - } - } else { - if (is_a($value, 'CollectdColor')) { - $this->r = $value->r; - $this->g = $value->g; - $this->b = $value->b; - } - } - } - }//end if - - }//end __construct() - - - public function randomize() - { - $this->r = (rand(0, 255) / 255.0); - $this->g = (rand(0, 255) / 255.0); - $this->b = 0.0; - $min = 0.0; - $max = 1.0; - - if (($this->r + $this->g) < 1.0) { - $min = (1.0 - ($this->r + $this->g)); - } else { - $max = (2.0 - ($this->r + $this->g)); - } - - $this->b = ($min + ((rand(0, 255) / 255.0) * ($max - $min))); - - }//end randomize() - - - public function fade($bkgnd = null, $alpha = 0.25) - { - if (is_null($bkgnd) || !is_a($bkgnd, 'CollectdColor')) { - $bg_r = 1.0; - $bg_g = 1.0; - $bg_b = 1.0; - } else { - $bg_r = $bkgnd->r; - $bg_g = $bkgnd->g; - $bg_b = $bkgnd->b; - } - - $this->r = ($alpha * $this->r + ((1.0 - $alpha) * $bg_r)); - $this->g = ($alpha * $this->g + ((1.0 - $alpha) * $bg_g)); - $this->b = ($alpha * $this->b + ((1.0 - $alpha) * $bg_b)); - - }//end fade() - - - public function toArray() - { - return array( - 'r' => $this->r, - 'g' => $this->g, - 'b' => $this->b, - ); - - }//end as_array() - - - public function toString() - { - $r = (int)($this->r * 255); - $g = (int)($this->g * 255); - $b = (int)($this->b * 255); - return sprintf('%02x%02x%02x', $r > 255 ? 255 : $r, $g > 255 ? 255 : $g, $b > 255 ? 255 : $b); - - } -} diff --git a/html/includes/collectd/functions.php b/html/includes/collectd/functions.php index 7c945a4332..e0cad177b4 100644 --- a/html/includes/collectd/functions.php +++ b/html/includes/collectd/functions.php @@ -1,4 +1,5 @@ * @@ -16,10 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -require 'includes/collectd/CollectdColor.php'; - -use LibreNMS\CollectdColor; - define('REGEXP_HOST', '/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/'); define('REGEXP_PLUGIN', '/^[a-zA-Z0-9_.-]+$/'); @@ -371,6 +368,112 @@ function collectd_flush($identifier) { }//end collectd_flush() + +class CollectdColor { + + private $r = 0; + + private $g = 0; + + private $b = 0; + + + function __construct($value=null) { + if (is_null($value)) { + } + else if (is_array($value)) { + if (isset($value['r'])) { + $this->r = $value['r'] > 0 ? ($value['r'] > 1 ? 1 : $value['r']) : 0; + } + + if (isset($value['g'])) { + $this->g = $value['g'] > 0 ? ($value['g'] > 1 ? 1 : $value['g']) : 0; + } + + if (isset($value['b'])) { + $this->b = $value['b'] > 0 ? ($value['b'] > 1 ? 1 : $value['b']) : 0; + } + } + else if (is_string($value)) { + $matches = array(); + if ($value == 'random') { + $this->randomize(); + } + else if (preg_match('/([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/', $value, $matches)) { + $this->r = (('0x'.$matches[1]) / 255.0); + $this->g = (('0x'.$matches[2]) / 255.0); + $this->b = (('0x'.$matches[3]) / 255.0); + } + } + else if (is_a($value, 'CollectdColor')) { + $this->r = $value->r; + $this->g = $value->g; + $this->b = $value->b; + }//end if + + }//end __construct() + + + function randomize() { + $this->r = (rand(0, 255) / 255.0); + $this->g = (rand(0, 255) / 255.0); + $this->b = 0.0; + $min = 0.0; + $max = 1.0; + + if (($this->r + $this->g) < 1.0) { + $min = (1.0 - ($this->r + $this->g)); + } + else { + $max = (2.0 - ($this->r + $this->g)); + } + + $this->b = ($min + ((rand(0, 255) / 255.0) * ($max - $min))); + + }//end randomize() + + + function fade($bkgnd=null, $alpha=0.25) { + if (is_null($bkgnd) || !is_a($bkgnd, 'CollectdColor')) { + $bg_r = 1.0; + $bg_g = 1.0; + $bg_b = 1.0; + } + else { + $bg_r = $bkgnd->r; + $bg_g = $bkgnd->g; + $bg_b = $bkgnd->b; + } + + $this->r = ($alpha * $this->r + ((1.0 - $alpha) * $bg_r)); + $this->g = ($alpha * $this->g + ((1.0 - $alpha) * $bg_g)); + $this->b = ($alpha * $this->b + ((1.0 - $alpha) * $bg_b)); + + }//end fade() + + + function as_array() { + return array( + 'r' => $this->r, + 'g' => $this->g, + 'b' => $this->b, + ); + + }//end as_array() + + + function as_string() { + $r = (int) ($this->r * 255); + $g = (int) ($this->g * 255); + $b = (int) ($this->b * 255); + return sprintf('%02x%02x%02x', $r > 255 ? 255 : $r, $g > 255 ? 255 : $g, $b > 255 ? 255 : $b); + + }//end as_string() + + +}//end class + + /** * Helper function to strip quotes from RRD output * @str RRD-Info generated string @@ -461,8 +564,8 @@ function rrd_get_color($code, $line=true) { $c_f = new CollectdColor('random'); $c_h = new CollectdColor($c_f); $c_h->fade(); - $config['rrd_colors']['f_'.$code] = $c_f->toString(); - $config['rrd_colors']['h_'.$code] = $c_h->toString(); + $config['rrd_colors']['f_'.$code] = $c_f->as_string(); + $config['rrd_colors']['h_'.$code] = $c_h->as_string(); } return $config['rrd_colors'][$name]; @@ -849,8 +952,8 @@ function collectd_draw_meta_stack(&$opts, &$sources) { $area_color = new CollectdColor($line_color); $area_color->fade(); - $cmd[] = 'AREA:'.$inst_name.'_stk#'.$area_color->toString(); - $cmd[] = 'LINE1:'.$inst_name.'_stk#'.$line_color->toString().':'.$legend; + $cmd[] = 'AREA:'.$inst_name.'_stk#'.$area_color->as_string(); + $cmd[] = 'LINE1:'.$inst_name.'_stk#'.$line_color->as_string().':'.$legend; if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) { $cmd[] = 'GPRINT:'.$inst_name.'_avg:LAST:'.$number_format.''; $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.''; @@ -969,7 +1072,7 @@ function collectd_draw_meta_line(&$opts, &$sources) { $line_color = new CollectdColor('random'); } - $cmd[] = 'LINE1:'.$inst_name.'_avg#'.$line_color->toString().':'.$legend; + $cmd[] = 'LINE1:'.$inst_name.'_avg#'.$line_color->as_string().':'.$legend; if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) { $cmd[] = 'GPRINT:'.$inst_name.'_min:MIN:'.$number_format.''; $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.''; diff --git a/html/includes/plugins.inc.php b/html/includes/plugins.inc.php index e52015b199..a10762c5cf 100644 --- a/html/includes/plugins.inc.php +++ b/html/includes/plugins.inc.php @@ -1,7 +1,5 @@