From cc7f01ee2612e772a439391880cbadb357d21cde Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Wed, 23 May 2012 10:37:23 +0000 Subject: [PATCH] more rrdtool_escape goodness git-svn-id: http://www.observium.org/svn/observer/trunk@3230 61d68cd4-352d-0410-923a-c4978735b2b8 --- .../application/shoutcast_multi_stats.inc.php | 4 +- html/includes/graphs/device/mempool.inc.php | 3 +- html/includes/graphs/device/sla.inc.php | 7 +-- .../device/smokeping_all_common.inc.php | 2 +- .../device/smokeping_all_common_avg.inc.php | 54 +++++++------------ html/includes/graphs/device/storage.inc.php | 3 +- html/includes/graphs/mempool/usage.inc.php | 3 +- html/includes/graphs/munin/graph.inc.php | 2 +- .../graphs/port/mac_acc_total.inc.php | 6 +-- html/includes/graphs/processor/usage.inc.php | 3 +- html/includes/graphs/sensor/fanspeed.inc.php | 4 +- html/includes/graphs/sensor/humidity.inc.php | 4 +- html/includes/graphs/sensor/power.inc.php | 5 +- .../graphs/sensor/temperature.inc.php | 11 +--- html/includes/graphs/sensor/voltage.inc.php | 5 +- html/includes/graphs/smokeping/in.inc.php | 2 +- html/includes/graphs/smokeping/out.inc.php | 2 +- html/includes/graphs/storage/usage.inc.php | 16 +++--- includes/rrdtool.inc.php | 11 ++++ 19 files changed, 54 insertions(+), 93 deletions(-) diff --git a/html/includes/graphs/application/shoutcast_multi_stats.inc.php b/html/includes/graphs/application/shoutcast_multi_stats.inc.php index 4f71b3caf..e0345a95b 100644 --- a/html/includes/graphs/application/shoutcast_multi_stats.inc.php +++ b/html/includes/graphs/application/shoutcast_multi_stats.inc.php @@ -59,7 +59,7 @@ foreach ($rrd_list as $rrd) { $colours = (isset($rrd['colour']) ? $rrd['colour'] : "default"); $strlen = ((strlen($rrd['descr'])<$descr_len) ? ($descr_len - strlen($rrd['descr'])) : "0"); - $descr = (isset($rrd['descr']) ? str_replace(":", "\:", substr(str_pad($rrd['descr'], $desc_len+$strlen), 0, $descr_len+$strlen)) : "Unkown"); + $descr = (isset($rrd['descr']) ? rrdtool_escape($rrd['descr'], $desc_len+$strlen) : "Unkown"); for ($z=0; $z<$strlen; $z++) { $descr .= " "; } if ($i) { $stack = "STACK"; } $colour = $config['graph_colours'][$colours][$x]; @@ -86,7 +86,7 @@ foreach ($rrd_list as $rrd) if (!$nototal) { $strlen = ((strlen($total_text)<$descr_len) ? ($descr_len - strlen($total_text)) : "0"); - $descr = (isset($total_text) ? str_replace(":", "\:", substr(str_pad($total_text, $desc_len+$strlen), 0, $descr_len+$strlen)) : "Total"); + $descr = (isset($total_text) ? rrdtool_escape($total_text, $desc_len+$strlen) : "Total"); $colour = $config['graph_colours'][$colours][$x]; for ($z=0; $z<$strlen; $z++) { $descr .= " "; } $rrd_options .= " CDEF:totcur=cur0".$totcur; diff --git a/html/includes/graphs/device/mempool.inc.php b/html/includes/graphs/device/mempool.inc.php index b84653a68..ded4c7531 100644 --- a/html/includes/graphs/device/mempool.inc.php +++ b/html/includes/graphs/device/mempool.inc.php @@ -14,8 +14,7 @@ foreach (dbFetchRows("SELECT * FROM `mempools` where `device_id` = ?", array($de elseif ($iter=="4") { $colour="73880A"; } elseif ($iter=="5") { $colour="D01F3C"; } elseif ($iter=="6") { $colour="36393D"; } elseif ($iter=="7") { $colour="FF0084"; unset($iter); } - $descr = substr(str_pad(short_hrDeviceDescr($mempool['mempool_descr']), 22),0,22); - $descr = str_replace(":", "\:", $descr); + $descr = rrdtool_escape(short_hrDeviceDescr($mempool['mempool_descr']), 22); $rrd_filename = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("mempool-".$mempool['mempool_type']."-".$mempool['mempool_index'].".rrd"); if (is_file($rrd_filename)) diff --git a/html/includes/graphs/device/sla.inc.php b/html/includes/graphs/device/sla.inc.php index b33a45b42..8ce8cf120 100644 --- a/html/includes/graphs/device/sla.inc.php +++ b/html/includes/graphs/device/sla.inc.php @@ -22,16 +22,13 @@ if ($sla['tag']) if ($sla['owner']) $name .= " (Owner: ". $sla['owner'] .")"; -$descr_fixed = substr(str_pad($name, $descr_len-3),0,$descr_len-3); -$avg_fixed = substr(str_pad('Average', $descr_len-3),0,$descr_len-3); - $rrd_file = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename("sla-" . $sla['sla_nr'] . ".rrd"); $rrd_options .= " DEF:rtt=$rrd_file:rtt:AVERAGE "; $rrd_options .= " VDEF:avg=rtt,AVERAGE "; -$rrd_options .= " LINE1:avg#CCCCFF:'".$avg_fixed."':dashes"; +$rrd_options .= " LINE1:avg#CCCCFF:'".str_pad('Average',$descr_len-3)."':dashes"; $rrd_options .= " GPRINT:rtt:AVERAGE:%4.1lf".$unit."\\\l "; -$rrd_options .= " LINE1:rtt#CC0000:'" . str_replace(':','\:',str_replace('\*','*',$descr_fixed)) . "'"; +$rrd_options .= " LINE1:rtt#CC0000:'" . rrdtool_escape($descr,$descr_len-3)) . "'"; $rrd_options .= " GPRINT:rtt:LAST:%4.1lf".$unit." "; $rrd_options .= " GPRINT:rtt:MIN:%4.1lf".$unit." "; $rrd_options .= " GPRINT:rtt:MAX:%4.1lf".$unit."\\\l "; diff --git a/html/includes/graphs/device/smokeping_all_common.inc.php b/html/includes/graphs/device/smokeping_all_common.inc.php index f2fbf9c9e..f11096450 100644 --- a/html/includes/graphs/device/smokeping_all_common.inc.php +++ b/html/includes/graphs/device/smokeping_all_common.inc.php @@ -36,7 +36,7 @@ foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filena $colour = $config['graph_colours'][$colourset][$iter]; $iter++; - $descr = str_replace(":", "\:", substr(str_pad($source, $descr_len),0,$descr_len)); + $descr = rrdtool_escape($source, $descr_len); $filename = $config['smokeping']['dir'] . $filename; $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; diff --git a/html/includes/graphs/device/smokeping_all_common_avg.inc.php b/html/includes/graphs/device/smokeping_all_common_avg.inc.php index ee46093ce..501b1c396 100644 --- a/html/includes/graphs/device/smokeping_all_common_avg.inc.php +++ b/html/includes/graphs/device/smokeping_all_common_avg.inc.php @@ -22,6 +22,7 @@ if($width > "500") $descr_len = 12 + round(($width - 275) / 8); } +# FIXME str_pad really needs a "limit to length" so we can rid of all the substrs all over the code to limit the length as below... if($width > "500") { $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)." RTT Loss SDev RTT\:SDev\l'"; @@ -36,7 +37,7 @@ foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filena $colour = $config['graph_colours'][$colourset][$iter]; $iter++; - $descr = str_replace(":", "\:", substr(str_pad($source, $descr_len),0,$descr_len)); + $descr = rrdtool_escape($source, $descr_len); $filename = $config['smokeping']['dir'] . $filename; $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; @@ -78,45 +79,26 @@ foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filena } -$descr = str_replace(":", "\:", substr(str_pad("Average", $descr_len),0,$descr_len)); +$descr = rrdtool_escape("Average", $descr_len); - $rrd_options .= " CDEF:ploss_all=0".$ploss_list.",$i,/"; - $rrd_options .= " CDEF:dm_all=0".$dm_list.",$i,/"; +$rrd_options .= " CDEF:ploss_all=0".$ploss_list.",$i,/"; +$rrd_options .= " CDEF:dm_all=0".$dm_list.",$i,/"; # $rrd_options .= " CDEF:dm_all_clean=dm_all,UN,NaN,dm_all,IF"; - $rrd_options .= " CDEF:sd_all=0".$sd_list.",$i,/"; - $rrd_options .= " CDEF:dmlow_all=dm_all,sd_all,2,/,-"; +$rrd_options .= " CDEF:sd_all=0".$sd_list.",$i,/"; +$rrd_options .= " CDEF:dmlow_all=dm_all,sd_all,2,/,-"; - $rrd_options .= " AREA:dmlow_all"; - $rrd_options .= " AREA:sd_all#AAAAAA::STACK"; - $rrd_options .= " LINE1:dm_all#CC0000:'$descr'"; +$rrd_options .= " AREA:dmlow_all"; +$rrd_options .= " AREA:sd_all#AAAAAA::STACK"; +$rrd_options .= " LINE1:dm_all#CC0000:'$descr'"; - $rrd_options .= " VDEF:avmed=dm_all,AVERAGE"; - $rrd_options .= " VDEF:avsd=sd_all,AVERAGE"; - $rrd_options .= " CDEF:msr=dm_all,POP,avmed,avsd,/"; - $rrd_options .= " VDEF:avmsr=msr,AVERAGE"; +$rrd_options .= " VDEF:avmed=dm_all,AVERAGE"; +$rrd_options .= " VDEF:avsd=sd_all,AVERAGE"; +$rrd_options .= " CDEF:msr=dm_all,POP,avmed,avsd,/"; +$rrd_options .= " VDEF:avmsr=msr,AVERAGE"; - $rrd_options .= " GPRINT:avmed:'%5.1lf%ss'"; - $rrd_options .= " GPRINT:ploss_all:AVERAGE:'%5.1lf%%'"; - $rrd_options .= " GPRINT:avsd:'%5.1lf%Ss'"; - $rrd_options .= " GPRINT:avmsr:'%5.1lf%s\\l'"; - -# $rrd_options .= " AREA:dmlow$i"; -# $rrd_options .= " AREA:s2d$i#".$colour."30::STACK"; -# $rrd_options .= " LINE1:dm$i#".$colour.":'$descr'"; -# $rrd_options .= " LINE1:sdev$i#000000:$descr"; - -# $rrd_options .= " VDEF:avmed$i=median$i,AVERAGE"; -# $rrd_options .= " VDEF:avsd$i=sdev$i,AVERAGE"; -# $rrd_options .= " CDEF:msr$i=median$i,POP,avmed$i,avsd$i,/"; -# $rrd_options .= " VDEF:avmsr$i=msr$i,AVERAGE"; - -# $rrd_options .= " GPRINT:avmed$i:'%5.1lf%ss'"; -# $rrd_options .= " GPRINT:ploss$i:AVERAGE:'%5.1lf%%'"; - -# $rrd_options .= " GPRINT:avsd$i:'%5.1lf%Ss'"; -# $rrd_options .= " GPRINT:avmsr$i:'%5.1lf%s\\l'"; - -# $i++; -#} +$rrd_options .= " GPRINT:avmed:'%5.1lf%ss'"; +$rrd_options .= " GPRINT:ploss_all:AVERAGE:'%5.1lf%%'"; +$rrd_options .= " GPRINT:avsd:'%5.1lf%Ss'"; +$rrd_options .= " GPRINT:avmsr:'%5.1lf%s\\l'"; ?> diff --git a/html/includes/graphs/device/storage.inc.php b/html/includes/graphs/device/storage.inc.php index be5c5f6ad..f3c1d1ac5 100644 --- a/html/includes/graphs/device/storage.inc.php +++ b/html/includes/graphs/device/storage.inc.php @@ -15,8 +15,7 @@ foreach (dbFetchRows("SELECT * FROM storage where device_id = ?", array($device[ elseif ($iter=="4") { $colour="73880A"; } elseif ($iter=="5") { $colour="D01F3C"; } elseif ($iter=="6") { $colour="36393D"; } elseif ($iter=="7") { $colour="FF0084"; $iter = "0"; } - $descr = substr(str_pad($storage[storage_descr], 12),0,12); - $descr = str_replace(":","\:",$descr); + $descr = rrdtool_escape($storage['storage_descr'], 12); $rrd = $config['rrd_dir'] . "/".$device['hostname']."/" . safename("storage-".$storage['storage_mib']."-".$storage['storage_descr'].".rrd"); $rrd_options .= " DEF:$storage[storage_id]used=$rrd:used:AVERAGE"; $rrd_options .= " DEF:$storage[storage_id]free=$rrd:free:AVERAGE"; diff --git a/html/includes/graphs/mempool/usage.inc.php b/html/includes/graphs/mempool/usage.inc.php index d05640d8d..6fec6aa98 100644 --- a/html/includes/graphs/mempool/usage.inc.php +++ b/html/includes/graphs/mempool/usage.inc.php @@ -25,8 +25,7 @@ if($width > "500") $rrd_options .= " COMMENT:'".substr(str_pad($unit_text, $descr_len+5),0,$descr_len+5)."Total Used Free\l'"; } -$descr = substr(str_pad(short_hrDeviceDescr($mempool['mempool_descr']), $descr_len),0,$descr_len); -$descr = str_replace(":", "\:", $descr); +$descr = rrdtool_escape(short_hrDeviceDescr($mempool['mempool_descr']), $descr_len); $perc = round($mempool['mempool_perc'], 0); $background = get_percentage_colours($perc); diff --git a/html/includes/graphs/munin/graph.inc.php b/html/includes/graphs/munin/graph.inc.php index 2484c3823..1d6be7dc9 100644 --- a/html/includes/graphs/munin/graph.inc.php +++ b/html/includes/graphs/munin/graph.inc.php @@ -48,7 +48,7 @@ foreach ($dbq as $ds) $colour = $ds['colour']; } - $descr = str_replace(":", "\:", substr(str_pad($ds['ds_label'], $descr_len),0,$descr_len)); + $descr = rrdtool_escape($ds['ds_label'], $descr_len); $cmd_graph .= ' '.$ds['ds_draw'].':'.$ds_name.'#'.$colour.':"'.$descr.'"'; $cmd_graph .= ' GPRINT:'.$ds_name.':LAST:"%6.2lf%s"'; diff --git a/html/includes/graphs/port/mac_acc_total.inc.php b/html/includes/graphs/port/mac_acc_total.inc.php index b5d76a038..c00d5ade7 100644 --- a/html/includes/graphs/port/mac_acc_total.inc.php +++ b/html/includes/graphs/port/mac_acc_total.inc.php @@ -78,11 +78,7 @@ foreach ($accs as $acc) $this_id = str_replace(".", "", $acc['mac']); if (!$config['graph_colours'][$colours][$iter]) { $iter = 0; } $colour=$config['graph_colours'][$colours][$iter]; - $descr = str_pad($name, 36); - $descr = substr($descr,0,36); - $descr = str_replace("(", "(", $descr); - $descr = str_replace(")", ")", $descr); - $descr = str_replace(":", "\\:", $descr); + $descr = rrdtool_escape($name, 36); $rrd_options .= " DEF:in".$this_id."=$this_rrd:".$prefix."IN:AVERAGE "; $rrd_options .= " DEF:out".$this_id."temp=$this_rrd:".$prefix."OUT:AVERAGE "; $rrd_options .= " CDEF:inB".$this_id."=in".$this_id.",$multiplier,* "; diff --git a/html/includes/graphs/processor/usage.inc.php b/html/includes/graphs/processor/usage.inc.php index fff084378..3812a1432 100755 --- a/html/includes/graphs/processor/usage.inc.php +++ b/html/includes/graphs/processor/usage.inc.php @@ -5,8 +5,7 @@ $scale_max = "100"; $ds = "usage"; -$descr = substr(str_pad(short_hrDeviceDescr($proc['processor_descr']), 28),0,28); -$descr = str_replace(":", "\:", $descr); +$descr = rrdtool_escape(short_hrDeviceDescr($proc['processor_descr']), 28); $colour_line = "cc0000"; $colour_area = "FFBBBB"; diff --git a/html/includes/graphs/sensor/fanspeed.inc.php b/html/includes/graphs/sensor/fanspeed.inc.php index d6cd7866f..82ec16cc9 100644 --- a/html/includes/graphs/sensor/fanspeed.inc.php +++ b/html/includes/graphs/sensor/fanspeed.inc.php @@ -6,10 +6,8 @@ include("includes/graphs/common.inc.php"); $rrd_options .= " COMMENT:' Last Max\\n'"; -$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 20),0,20); - $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE"; -$rrd_options .= " LINE1.5:sensor#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :( +$rrd_options .= " LINE1.5:sensor#cc0000:'" . rrdtool_escape($sensor['sensor_descr'],20)."'"; $rrd_options .= " GPRINT:sensor:LAST:%3.0lfrpm"; $rrd_options .= " GPRINT:sensor:MAX:%3.0lfrpm\\\\l"; diff --git a/html/includes/graphs/sensor/humidity.inc.php b/html/includes/graphs/sensor/humidity.inc.php index da099cdc9..153d435dd 100644 --- a/html/includes/graphs/sensor/humidity.inc.php +++ b/html/includes/graphs/sensor/humidity.inc.php @@ -7,8 +7,6 @@ include("includes/graphs/common.inc.php"); $rrd_options .= " COMMENT:' Last Max\\n'"; -$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 28),0,28); - $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE"; $rrd_options .= " DEF:sensor_max=$rrd_filename:sensor:MAX"; $rrd_options .= " DEF:sensor_min=$rrd_filename:sensor:MIN"; @@ -20,7 +18,7 @@ $rrd_options .= " AREA:sensor_min#ffffffff"; # $rrd_options .= " AREA:sensor#bbd392"; # $rrd_options .= " AREA:sensorwarm#FFCCCC"; # $rrd_options .= " AREA:sensorcold#CCCCFF"; -$rrd_options .= " LINE1:sensor#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :( +$rrd_options .= " LINE1:sensor#cc0000:'" . rrdtool_escape($sensor['sensor_descr'],28)."'"; $rrd_options .= " LINE1:sensorwarm#660000"; $rrd_options .= " GPRINT:sensor:LAST:%3.0lf%%"; $rrd_options .= " GPRINT:sensor:MAX:%3.0lf%%\\\\l"; diff --git a/html/includes/graphs/sensor/power.inc.php b/html/includes/graphs/sensor/power.inc.php index 948abdbca..1731a3d09 100644 --- a/html/includes/graphs/sensor/power.inc.php +++ b/html/includes/graphs/sensor/power.inc.php @@ -7,9 +7,6 @@ include("includes/graphs/common.inc.php"); $rrd_options .= " -A "; $rrd_options .= " COMMENT:' Last Max\\n'"; -$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 22),0,22); -$sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed'])); - $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE"; $rrd_options .= " DEF:sensor_max=$rrd_filename:sensor:MAX"; $rrd_options .= " DEF:sensor_min=$rrd_filename:sensor:MIN"; @@ -18,7 +15,7 @@ $rrd_options .= " AREA:sensor_max#c5c5c5"; $rrd_options .= " AREA:sensor_min#ffffffff"; #$rrd_options .= " AREA:sensor#FFFF99"; -$rrd_options .= " LINE1.5:sensor#cc0000:'" . $sensor['sensor_descr_fixed']."'"; +$rrd_options .= " LINE1.5:sensor#cc0000:'" . rrdtool_escape($sensor['sensor_descr'],22)."'"; $rrd_options .= " GPRINT:sensor:LAST:%6.2lfW"; $rrd_options .= " GPRINT:sensor:MAX:%6.2lfW\\\\l"; diff --git a/html/includes/graphs/sensor/temperature.inc.php b/html/includes/graphs/sensor/temperature.inc.php index bc05f830f..39b0381a5 100644 --- a/html/includes/graphs/sensor/temperature.inc.php +++ b/html/includes/graphs/sensor/temperature.inc.php @@ -7,9 +7,6 @@ include("includes/graphs/common.inc.php"); $rrd_options .= " COMMENT:' Min Last Max\\n'"; -$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 21),0,21); -$sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed'])); - $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE"; $rrd_options .= " DEF:sensor_max=$rrd_filename:sensor:MAX"; $rrd_options .= " DEF:sensor_min=$rrd_filename:sensor:MIN"; @@ -19,13 +16,7 @@ $rrd_options .= " CDEF:sensor_diff=sensor_max,sensor_min,-"; $rrd_options .= " AREA:sensor_min"; $rrd_options .= " AREA:sensor_diff#c5c5c5::STACK"; -# $rrd_options .= " AREA:sensor#bbd392"; -# $rrd_options .= " AREA:sensorwarm#FFCCCC"; -# $rrd_options .= " AREA:sensorcold#CCCCFF"; -# $rrd_options .= " LINE1:sensor#cc0000:'" . str_replace(':','\:',str_replace('\*','*',quotemeta($sensor['sensor_descr_fixed'])))."'"; # Ugly hack :( - -$rrd_options .= " LINE1.5:sensor#cc0000:'" . $sensor['sensor_descr_fixed']."'"; -# $rrd_options .= " LINE1.5:sensorwarm#660000"; +$rrd_options .= " LINE1.5:sensor#cc0000:'" . rrdtool_escape($sensor['sensor_descr'],21)."'"; $rrd_options .= " GPRINT:sensor_min:MIN:%4.1lfC"; $rrd_options .= " GPRINT:sensor:LAST:%4.1lfC"; $rrd_options .= " GPRINT:sensor_max:MAX:%4.1lfC\\\\l"; diff --git a/html/includes/graphs/sensor/voltage.inc.php b/html/includes/graphs/sensor/voltage.inc.php index 4722f04a7..ca3ea023d 100644 --- a/html/includes/graphs/sensor/voltage.inc.php +++ b/html/includes/graphs/sensor/voltage.inc.php @@ -7,9 +7,6 @@ include("includes/graphs/common.inc.php"); $rrd_options .= " -A "; $rrd_options .= " COMMENT:' Last Max\\n'"; -$sensor['sensor_descr_fixed'] = substr(str_pad($sensor['sensor_descr'], 22),0,22); -$sensor['sensor_descr_fixed'] = str_replace(':','\:',str_replace('\*','*',$sensor['sensor_descr_fixed'])); - $rrd_options .= " DEF:sensor=$rrd_filename:sensor:AVERAGE"; $rrd_options .= " DEF:sensor_max=$rrd_filename:sensor:MAX"; $rrd_options .= " DEF:sensor_min=$rrd_filename:sensor:MIN"; @@ -18,7 +15,7 @@ $rrd_options .= " AREA:sensor_max#c5c5c5"; $rrd_options .= " AREA:sensor_min#ffffffff"; #$rrd_options .= " AREA:sensor#FFFF99"; -$rrd_options .= " LINE1.5:sensor#cc0000:'" . $sensor['sensor_descr_fixed']."'"; +$rrd_options .= " LINE1.5:sensor#cc0000:'" . rrdtool_escape($sensor['sensor_descr'],22)."'"; $rrd_options .= " GPRINT:sensor:LAST:%6.2lfV"; $rrd_options .= " GPRINT:sensor:MAX:%6.2lfV\\\\l"; diff --git a/html/includes/graphs/smokeping/in.inc.php b/html/includes/graphs/smokeping/in.inc.php index 28ee28528..dcc3d123d 100644 --- a/html/includes/graphs/smokeping/in.inc.php +++ b/html/includes/graphs/smokeping/in.inc.php @@ -52,7 +52,7 @@ if($src['hostname'] == $config['own_hostname']) $colour = $config['graph_colours'][$colourset][$iter]; $iter++; - $descr = str_replace(":", "\:", substr(str_pad($source, $descr_len),0,$descr_len)); + $descr = rrdtool_escape($source,$descr_len); $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; $rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE"; diff --git a/html/includes/graphs/smokeping/out.inc.php b/html/includes/graphs/smokeping/out.inc.php index 9165da6c7..2e0bc51bc 100644 --- a/html/includes/graphs/smokeping/out.inc.php +++ b/html/includes/graphs/smokeping/out.inc.php @@ -52,7 +52,7 @@ if($device['hostname'] == $config['own_hostname']) $colour = $config['graph_colours'][$colourset][$iter]; $iter++; - $descr = str_replace(":", "\:", substr(str_pad($source, $descr_len),0,$descr_len)); + $descr = rrdtool_escape($source,$descr_len); $rrd_options .= " DEF:median$i=".$filename.":median:AVERAGE "; $rrd_options .= " DEF:loss$i=".$filename.":loss:AVERAGE"; diff --git a/html/includes/graphs/storage/usage.inc.php b/html/includes/graphs/storage/usage.inc.php index b92ef3c8f..c42d339e6 100644 --- a/html/includes/graphs/storage/usage.inc.php +++ b/html/includes/graphs/storage/usage.inc.php @@ -13,13 +13,12 @@ $rrd_options .= " COMMENT:' Size Free % Used\\n'"; $hostname = gethostbyid($storage['device_id']); -$colour="CC0000"; -$colour_area="ffaaaa"; +$colour = "CC0000"; +$colour_area = "ffaaaa"; -$descr = substr(str_pad($storage[storage_descr], 12),0,12); -$descr = str_replace(":","\:",$descr); +$descr = rrdtool_escape($storage['storage_descr'], 12); -$percentage = round($storage['storage_perc'], 0); +$percentage = round($storage['storage_perc'], 0); $background = get_percentage_colours($percentage); @@ -35,11 +34,10 @@ $rrd_options .= " GPRINT:perc:LAST:%5.2lf%%\\\\n"; if ($_GET['previous']) { - $descr = substr(str_pad("Prev ".$storage[storage_descr], 12),0,12); - $descr = str_replace(":","\:",$descr); + $descr = rrdtool_escape("Prev ".$storage['storage_descr'], 12); - $colour="99999999"; - $colour_area="66666666"; + $colour = "99999999"; + $colour_area = "66666666"; $rrd_options .= " DEF:usedX=$rrd_filename:used:AVERAGE:start=".$prev_from.":end=".$from; $rrd_options .= " DEF:freeX=$rrd_filename:free:AVERAGE:start=".$prev_from.":end=".$from; diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index f0fb833eb..3472883f8 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -224,10 +224,21 @@ function rrdtool_lastupdate($filename, $options) return rrdtool("lastupdate", $filename, $options); } +/** + * Escapes strings for RRDtool, + * + * @return string + * + * @param string string to escape + * @param integer if passed, string will be padded and trimmed to exactly this length (after rrdtool unescapes it) + */ + function rrdtool_escape($string, $maxlength = NULL) { $result = str_replace(':','\:',$string); $result = str_replace('%','%%',$result); + + # FIXME: should maybe also probably escape these? # \ + ? [ ^ ] ( $ ) ' if ($maxlength != NULL) {