X-Git-Url: https://git-public.kairo.at/?a=blobdiff_plain;f=classes%2Frrdstat.php-class;h=a6b8e9c48fcf166319b8f1783e56b77b4ce26d05;hb=cb2420c657c2856403afada65712063542b145c0;hp=1443ec6fa427929d064fc6d1571d4520442f6949;hpb=7b9ebce7d25e4eaa557e8a64f8b1ed15aad1a9bb;p=php-utility-classes.git diff --git a/classes/rrdstat.php-class b/classes/rrdstat.php-class index 1443ec6..a6b8e9c 100644 --- a/classes/rrdstat.php-class +++ b/classes/rrdstat.php-class @@ -1,23 +1,7 @@ - * - * ***** END LICENSE BLOCK ***** */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ class rrdstat { // rrdstat PHP class @@ -222,11 +206,11 @@ class rrdstat { $this->status = 'graphonly'; } elseif (isset($iinfo['file'])) { - $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$iinfo['file']; + $this->rrd_file = (($iinfo['file'][0] != '/')?$this->basedir:'').$iinfo['file']; $this->basename = basename((substr($this->rrd_file, -4) == '.rrd')?substr($this->rrd_file, 0, -4):$this->rrd_file); } elseif (!is_null($conf_id) && file_exists($conf_id.'.rrd')) { - $this->rrd_file = (($iinfo['file']{0} != '/')?$this->basedir:'').$conf_id.'.rrd'; + $this->rrd_file = (($iinfo['file'][0] != '/')?$this->basedir:'').$conf_id.'.rrd'; $this->basename = $conf_id; } else { @@ -525,8 +509,8 @@ class rrdstat { $fname = str_replace('%t', $timeframe, $fname); $fname = str_replace('%f', $fmt_ext, $fname); if (substr($fname, -strlen($fmt_ext)) != $fmt_ext) { $fname .= $fmt_ext; } - if (isset($gconf['path']) && ($fname{0} != '/')) { $fname = $gconf['path'].'/'.$fname; } - if ($fname{0} != '/') { $fname = $this->basedir.$fname; } + if (isset($gconf['path']) && ($fname[0] != '/')) { $fname = $gconf['path'].'/'.$fname; } + if ($fname[0] != '/') { $fname = $this->basedir.$fname; } $fname = str_replace('//', '/', $fname); $graphrows = array(); $specialrows = array(); $gC = 0; @@ -776,15 +760,16 @@ class rrdstat { } $graph_cmd = $this->rrdtool_bin.' graph '.str_replace('*', '\*', $fname.$gOpts.$gDefs.$gGraphs.$addSpecial); - $return = `$graph_cmd 2>&1`; - - if (strpos($return, 'ERROR') !== false) { - trigger_error($this->rrd_file.' - rrd graph error: '.$return, E_USER_WARNING); - $return = 'command:'.$graph_cmd."\n\n".$return; + if ((file_exists($fname) && !is_writable($fname)) || + (!file_exists($fname) && !is_writable(dirname($fname)))) { + trigger_error($this->rrd_file.' - graph file not writable: '.$fname, E_USER_WARNING); + return 'command:'.$graph_cmd."\n\n".'unwritable file: '.$fname; } - if (0) { - // debug output - $return = 'command:'.$graph_cmd."\n\n".$return; + $graph_out = `$graph_cmd 2>&1`; + + if (strpos($graph_out, 'ERROR') !== false) { + trigger_error($this->rrd_file.' - rrd graph error: '.$graph_out, E_USER_WARNING); + return 'command:'.$graph_cmd."\n\n".$graph_out; } $legendlines = ''; foreach ($graphrows as $grow) { @@ -794,7 +779,7 @@ class rrdstat { $legendline .= '|'.(isset($grow['legend_long'])?$grow['legend_long']:''); $legendlines .= 'legend:'.$legendline."\n"; } - $return = 'file:'.$fname."\n".$legendlines.$return; + $return = 'file:'.$fname."\n".$legendlines.$graph_out; return $return; } @@ -884,7 +869,8 @@ class rrdstat { $td = $this->mod_textdomain; $ptitle = isset($pconf['title_page'])?$pconf['title_page']:dgettext($td, 'RRD statistics index'); - $out = ''."\n"; + $out = ''."\n"; + $out .= ''."\n"; $out .= ''.$ptitle.''."\n"; $out .= '