fix string array access
[php-utility-classes.git] / classes / rrdstat.php-class
index 9226d564f5f70c2059b340bfdeca81ea39b0e509..a6b8e9c48fcf166319b8f1783e56b77b4ce26d05 100644 (file)
@@ -206,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 {
@@ -509,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;
@@ -760,7 +760,8 @@ class rrdstat {
     }
 
     $graph_cmd = $this->rrdtool_bin.' graph '.str_replace('*', '\*', $fname.$gOpts.$gDefs.$gGraphs.$addSpecial);
-    if (!is_writable($fname)) {
+    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;
     }
@@ -1177,7 +1178,7 @@ class rrdstat {
     $snames = array(); $s_exclude = array(); $sfiles = array();
     if (isset($pconf['index_ids'])) {
       foreach (explode(',', $pconf['index_ids']) as $iid) {
-        if ($iid{0} == '-') { $s_exclude[] = substr($iid, 1); }
+        if ($iid[0] == '-') { $s_exclude[] = substr($iid, 1); }
         else { $snames[] = $iid; }
       }
     }