From 1bce11aec73bcd6f90fe8e72877b4061ae8d45af Mon Sep 17 00:00:00 2001 From: Karol Nowacki Date: Thu, 21 Apr 2011 20:24:38 +0200 Subject: resolve php notices Including a lot of undefined $_GET values. --- detail.php | 16 ++++++++-------- graph.php | 4 ++-- host.php | 4 ++-- inc/functions.inc.php | 6 ++++++ inc/html.inc.php | 21 +++++++++++---------- plugin.php | 6 +++--- plugin/memcached.php | 2 +- plugin/swap.php | 2 +- type/Default.class.php | 26 +++++++++++++------------- 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/detail.php b/detail.php index d153768..e9e80a0 100644 --- a/detail.php +++ b/detail.php @@ -11,14 +11,14 @@ if (empty($_GET['x'])) if (empty($_GET['y'])) $_GET['y'] = $CONFIG['detail-heigth']; -$host = validate_get($_GET['h'], 'host'); -$plugin = validate_get($_GET['p'], 'plugin'); -$pinstance = validate_get($_GET['pi'], 'pinstance'); -$type = validate_get($_GET['t'], 'type'); -$tinstance = validate_get($_GET['ti'], 'tinstance'); -$width = $_GET['x']; -$heigth = $_GET['y']; -$seconds = $_GET['s']; +$host = validate_get(GET('h'), 'host'); +$plugin = validate_get(GET('p'), 'plugin'); +$pinstance = validate_get(GET('pi'), 'pinstance'); +$type = validate_get(GET('t'), 'type'); +$tinstance = validate_get(GET('ti'), 'tinstance'); +$width = GET('x'); +$heigth = GET('y'); +$seconds = GET('s'); html_start(); diff --git a/graph.php b/graph.php index e170598..31f697c 100644 --- a/graph.php +++ b/graph.php @@ -3,11 +3,11 @@ require_once 'conf/common.inc.php'; require_once 'inc/functions.inc.php'; -$plugin = validate_get($_GET['p'], 'plugin'); +$plugin = validate_get(GET('p'), 'plugin'); $width = empty($_GET['x']) ? $CONFIG['width'] : $_GET['x']; $heigth = empty($_GET['y']) ? $CONFIG['heigth'] : $_GET['y']; -if (validate_get($_GET['h'], 'host') === NULL) { +if (validate_get(GET('h'), 'host') === NULL) { error_log('CGP Error: plugin contains unknown characters'); error_image(); } diff --git a/host.php b/host.php index 7dd509a..8e3b695 100644 --- a/host.php +++ b/host.php @@ -4,8 +4,8 @@ require_once 'conf/common.inc.php'; require_once 'inc/html.inc.php'; require_once 'inc/collectd.inc.php'; -$host = validate_get($_GET['h'], 'host'); -$splugin = validate_get($_GET['p'], 'plugin'); +$host = validate_get(GET('h'), 'host'); +$splugin = validate_get(GET('p'), 'plugin'); html_start(); diff --git a/inc/functions.inc.php b/inc/functions.inc.php index 04e58e3..39f1cd0 100644 --- a/inc/functions.inc.php +++ b/inc/functions.inc.php @@ -2,6 +2,12 @@ # global functions +function GET($index) { + if (isset($_GET[$index])) + return $_GET[$index]; + return null; +} + function validate_get($value, $type) { switch($type) { case 'host': diff --git a/inc/html.inc.php b/inc/html.inc.php index 1dc3d2c..d4a31f2 100644 --- a/inc/html.inc.php +++ b/inc/html.inc.php @@ -118,16 +118,17 @@ function host_summary($hosts) { function breadcrumbs() { - if (validate_get($_GET['h'], 'host')) - $path = ' - '.ucfirst($_GET['h']); - if (validate_get($_GET['p'], 'plugin')) - $path .= ' - '.ucfirst($_GET['p']); - if (validate_get($_GET['pi'], 'pinstance')) - $path .= ' - '.$_GET['pi']; - if (validate_get($_GET['t'], 'type') && validate_get($_GET['p'], 'plugin') && $_GET['t'] != $_GET['p']) - $path .= ' - '.$_GET['t']; - if (validate_get($_GET['ti'], 'tinstance')) - $path .= ' - '.$_GET['ti']; + $path = ''; + if (validate_get(GET('h'), 'host')) + $path .= ' - '.ucfirst(GET('h')); + if (validate_get(GET('p'), 'plugin')) + $path .= ' - '.ucfirst(GET('p')); + if (validate_get(GET('pi'), 'pinstance')) + $path .= ' - '.GET('pi'); + if (validate_get(GET('t'), 'type') && validate_get(GET('p'), 'plugin') && GET('t') != GET('p')) + $path .= ' - '.GET('t'); + if (validate_get(GET('ti'), 'tinstance')) + $path .= ' - '.GET('ti'); return $path; } diff --git a/plugin.php b/plugin.php index 54f75fb..4e8384c 100644 --- a/plugin.php +++ b/plugin.php @@ -4,10 +4,10 @@ require_once 'conf/common.inc.php'; require_once 'inc/functions.inc.php'; require_once 'inc/html.inc.php'; -$host = validate_get($_GET['h'], 'host'); -$plugin = validate_get($_GET['p'], 'plugin'); +$host = validate_get(GET('h'), 'host'); +$plugin = validate_get(GET('p'), 'plugin'); -if ($_GET['a'] == 'del') { +if (GET('a') == 'del') { plugin_header($host, $plugin, 1); } else { plugin_header($host, $plugin, 0); diff --git a/plugin/memcached.php b/plugin/memcached.php index b30c27c..e011c9e 100644 --- a/plugin/memcached.php +++ b/plugin/memcached.php @@ -21,7 +21,7 @@ require_once 'inc/collectd.inc.php'; # ps_cputime.rrd -switch($_GET['t']) { +switch(GET('t')) { # df-cache.rrd case 'df': require_once 'type/Default.class.php'; diff --git a/plugin/swap.php b/plugin/swap.php index 9449b55..c24d90b 100644 --- a/plugin/swap.php +++ b/plugin/swap.php @@ -11,7 +11,7 @@ require_once 'inc/collectd.inc.php'; # swap/swap-free.rrd # swap/swap-used.rrd -switch($_GET['t']) { +switch(GET('t')) { case 'swap': require_once 'type/GenericStacked.class.php'; $obj = new Type_GenericStacked($CONFIG); diff --git a/type/Default.class.php b/type/Default.class.php index 45c4458..6429e5e 100644 --- a/type/Default.class.php +++ b/type/Default.class.php @@ -59,13 +59,13 @@ class Type_Default { # parse $_GET values function parse_get() { $this->args = array( - 'host' => $_GET['h'], - 'plugin' => $_GET['p'], - 'pinstance' => $_GET['pi'], - 'type' => $_GET['t'], - 'tinstance' => $_GET['ti'], + 'host' => GET('h'), + 'plugin' => GET('p'), + 'pinstance' => GET('pi'), + 'type' => GET('t'), + 'tinstance' => GET('ti'), ); - $this->seconds = $_GET['s']; + $this->seconds = GET('s'); } function validate_color($color) { @@ -82,12 +82,12 @@ class Type_Default { $rgb = array('r', 'g', 'b'); - $fg[r] = hexdec(substr($fgc,0,2)); - $fg[g] = hexdec(substr($fgc,2,2)); - $fg[b] = hexdec(substr($fgc,4,2)); - $bg[r] = hexdec(substr($bgc,0,2)); - $bg[g] = hexdec(substr($bgc,2,2)); - $bg[b] = hexdec(substr($bgc,4,2)); + $fg['r'] = hexdec(substr($fgc,0,2)); + $fg['g'] = hexdec(substr($fgc,2,2)); + $fg['b'] = hexdec(substr($fgc,4,2)); + $bg['r'] = hexdec(substr($bgc,0,2)); + $bg['g'] = hexdec(substr($bgc,2,2)); + $bg['b'] = hexdec(substr($bgc,4,2)); foreach ($rgb as $pri) { $c[$pri] = dechex(round($percent * $fg[$pri]) + ((1.0 - $percent) * $bg[$pri])); @@ -95,7 +95,7 @@ class Type_Default { $c[$pri] = '00'; } - return $c[r].$c[g].$c[b]; + return $c['r'].$c['g'].$c['b']; } function rrd_files() { -- cgit v1.1