fix string array access
[php-utility-classes.git] / classes / rrdstat.php-class
index 68b6d23902295dc0f9f9cdc6b527ced307ebcaca..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,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) {
@@ -778,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;
   }
 
@@ -868,7 +869,8 @@ class rrdstat {
     $td = $this->mod_textdomain;
     $ptitle = isset($pconf['title_page'])?$pconf['title_page']:dgettext($td, 'RRD statistics index');
 
-    $out = '<html><head>'."\n";
+    $out = '<!DOCTYPE html>'."\n";
+    $out .= '<html><head>'."\n";
     $out .= '<title>'.$ptitle.'</title>'."\n";
     $out .= '<style type="text/css">'."\n";
     if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
@@ -896,7 +898,7 @@ class rrdstat {
     else { $sURL_base = '?stat=%i%a'; }
 
     if (isset($pconf['stats_url_add'])) { $sURL_add = $pconf['stats_url_add']; }
-    else { $sURL_add = '&sub=%s'; }
+    else { $sURL_add = '&amp;sub=%s'; }
 
     $out .= '<ul class="indexlist">'."\n";
     foreach ($stats as $stat) {
@@ -913,7 +915,7 @@ class rrdstat {
           $sURL = str_replace('%s', $ssub, $sURL);
           $sprt[] = '<a href="'.$sURL.'">'.$ssub.'</a>';
         }
-        $out .= ' <span="subs">('.implode(', ', $sprt).')</span>';
+        $out .= ' <span class="subs">('.implode(', ', $sprt).')</span>';
       }
       $out .= '</li>'."\n";
     }
@@ -929,7 +931,8 @@ class rrdstat {
     $td = $this->mod_textdomain;
     $ptitle = isset($pconf['title_page'])?$pconf['title_page']:dgettext($td, 'RRD statistics overview');
 
-    $out = '<html><head>'."\n";
+    $out = '<!DOCTYPE html>'."\n";
+    $out .= '<html><head>'."\n";
     $out .= '<title>'.$ptitle.'</title>'."\n";
     $out .= '<style type="text/css">'."\n";
     if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
@@ -955,7 +958,7 @@ class rrdstat {
     else { $sURL_base = '?stat=%i%a'; }
 
     if (isset($pconf['stats_url_add'])) { $sURL_add = $pconf['stats_url_add']; }
-    else { $sURL_add = '&sub=%s'; }
+    else { $sURL_add = '&amp;sub=%s'; }
 
     $default_num_cols = $GLOBALS['ua']->isMobile()?1:2;
     $num_cols = is_numeric(@$pconf['num_rows'])?$pconf['num_rows']:$default_num_cols;
@@ -1041,7 +1044,8 @@ class rrdstat {
     $gtitle['year'] = isset($pconf['title_year'])?$pconf['title_year']:dgettext($td, 'Year overview (scaling 1 day)');
     $ltitle = isset($pconf['title_legend'])?$pconf['title_legend']:dgettext($td, 'Legend:');
 
-    $out = '<html><head>'."\n";
+    $out = '<!DOCTYPE html>'."\n";
+    $out .= '<html><head>'."\n";
     $out .= '<title>'.$ptitle.'</title>'."\n";
     $out .= '<style type="text/css">'."\n";
     if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
@@ -1174,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; }
       }
     }