From 25a9535b95ae11b3b048071a12e630cdf1a1c79a Mon Sep 17 00:00:00 2001 From: f0o Date: Mon, 11 May 2015 11:22:13 +0000 Subject: [PATCH] Rewrite rrdtool_escape --- .../graphs/generic_multi_seperated.inc.php | 14 ++++++------ includes/rrdtool.inc.php | 22 ++++++++----------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/html/includes/graphs/generic_multi_seperated.inc.php b/html/includes/graphs/generic_multi_seperated.inc.php index 115afb2895..d6cf17271f 100644 --- a/html/includes/graphs/generic_multi_seperated.inc.php +++ b/html/includes/graphs/generic_multi_seperated.inc.php @@ -73,7 +73,7 @@ foreach ($rrd_list as $rrd) $rrd_options .= " COMMENT:'\\n'"; $rrd_optionsb .= " AREA:outbits".$i."_neg#" . $colour_out . "::$stack"; - $rrd_options .= " HRULE:999999999999999#" . $colour_out . ":'" . substr(str_pad('', 10),0,10) . "Out':"; + $rrd_options .= " HRULE:999999999999999#" . $colour_out . ":'" . str_pad('', 11) . "Out':"; $rrd_options .= " GPRINT:outbits".$i.":LAST:%6.2lf%s"; $rrd_options .= " GPRINT:outbits".$i.":AVERAGE:%6.2lf%s"; $rrd_options .= " GPRINT:outbits".$i.":MAX:%6.2lf%s"; @@ -128,21 +128,21 @@ if (!$args['nototal']) $rrd_options .= " COMMENT:' \\n'"; - $rrd_options .= " HRULE:999999999999999#FFFFFF:'" . substr(str_pad('Total', 10),0,10) . "In ':"; + $rrd_options .= " HRULE:999999999999999#FFFFFF:'" . str_pad('Total', 11) . "In ':"; $rrd_options .= " GPRINT:inbits:LAST:%6.2lf%s"; $rrd_options .= " GPRINT:inbits:AVERAGE:%6.2lf%s"; $rrd_options .= " GPRINT:inbits:MAX:%6.2lf%s"; $rrd_options .= " GPRINT:totin:%6.2lf%s$total_units"; $rrd_options .= " COMMENT:'\\n'"; - $rrd_options .= " HRULE:999999999999990#FFFFFF:'" . substr(str_pad('', 10),0,10) . "Out':"; + $rrd_options .= " HRULE:999999999999990#FFFFFF:'" . str_pad('', 11) . "Out':"; $rrd_options .= " GPRINT:outbits:LAST:%6.2lf%s"; $rrd_options .= " GPRINT:outbits:AVERAGE:%6.2lf%s"; $rrd_options .= " GPRINT:outbits:MAX:%6.2lf%s"; $rrd_options .= " GPRINT:totout:%6.2lf%s$total_units"; $rrd_options .= " COMMENT:'\\n'"; - $rrd_options .= " HRULE:999999999999990#FFFFFF:'" . substr(str_pad('', 10),0,10) . "Agg':"; + $rrd_options .= " HRULE:999999999999990#FFFFFF:'" . str_pad('', 11) . "Agg':"; $rrd_options .= " GPRINT:bits:LAST:%6.2lf%s"; $rrd_options .= " GPRINT:bits:AVERAGE:%6.2lf%s"; $rrd_options .= " GPRINT:bits:MAX:%6.2lf%s"; @@ -157,21 +157,21 @@ if (!$args['nototal'] && $_GET['previous'] == "yes") $rrd_options .= " VDEF:totX=octetsX,TOTAL"; $rrd_options .= " COMMENT:' \\n'"; - $rrd_options .= " HRULE:999999999999999#aaaaaa:'" . substr(str_pad('Total', 10),0,10) . "In ':"; + $rrd_options .= " HRULE:999999999999999#aaaaaa:'" . str_pad('Total', 11) . "In ':"; $rrd_options .= " GPRINT:inbitsX:LAST:%6.2lf%s"; $rrd_options .= " GPRINT:inbitsX:AVERAGE:%6.2lf%s"; $rrd_options .= " GPRINT:inbitsX:MAX:%6.2lf%s"; $rrd_options .= " GPRINT:totinX:%6.2lf%s$total_units"; $rrd_options .= " COMMENT:'\\n'"; - $rrd_options .= " HRULE:999999999999990#aaaaaa:'" . substr(str_pad('', 10),0,10) . "Out':"; + $rrd_options .= " HRULE:999999999999990#aaaaaa:'" . str_pad('', 11) . "Out':"; $rrd_options .= " GPRINT:outbitsX:LAST:%6.2lf%s"; $rrd_options .= " GPRINT:outbitsX:AVERAGE:%6.2lf%s"; $rrd_options .= " GPRINT:outbitsX:MAX:%6.2lf%s"; $rrd_options .= " GPRINT:totoutX:%6.2lf%s$total_units"; $rrd_options .= " COMMENT:'\\n'"; - $rrd_options .= " HRULE:999999999999990#aaaaaa:'" . substr(str_pad('', 10),0,10) . "Agg':"; + $rrd_options .= " HRULE:999999999999990#aaaaaa:'" . str_pad('', 11) . "Agg':"; $rrd_options .= " GPRINT:bitsX:LAST:%6.2lf%s"; $rrd_options .= " GPRINT:bitsX:AVERAGE:%6.2lf%s"; $rrd_options .= " GPRINT:bitsX:MAX:%6.2lf%s"; diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index 1fbe6e4dcb..5e5a9c0dd5 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -256,21 +256,17 @@ function rrdtool_lastupdate($filename, $options) function rrdtool_escape($string, $maxlength = NULL) { - $result = str_replace(':','\:',$string); - $result = str_replace('%','%%',$result); + $result = shorten_interface_type($string); - // FIXME: should maybe also probably escape these? # \ + ? [ ^ ] ( $ ) ' - - $result = shorten_interface_type($result); - - if ($maxlength != NULL) - { - return substr(str_pad($result, $maxlength),0,$maxlength+(strlen($result)-strlen($string))); - } - else - { - return $result; + if ( is_numeric($maxlength) ) { + $extra = substr_count($string,':',0,$maxlength); + $result = substr(str_pad($result, $maxlength),0,$maxlength+$extra); + $result = substr($result,0,(-1*$extra)); } + + $result = str_replace(':','\:',$result); + + return $result." "; } ?>