+ trigger_error($this->rrd_file.' - rrd graph error: '.$return, E_USER_WARNING);
+ $return = 'command:'.$graph_cmd."\n\n".$return;
+ }
+ if (0) {
+ // debug output
+ $return = 'command:'.$graph_cmd."\n\n".$return;
+ }
+ $legendlines = '';
+ foreach ($graphrows as $grow) {
+ $legendline = isset($grow['desc'])?$grow['desc']:(isset($grow['legend'])?$grow['legend']:$grow['name']);
+ $legendline .= '|'.@$grow['color'];
+ $legendline .= '|'.(isset($grow['color_bg'])?$grow['color_bg']:'');
+ $legendline .= '|'.(isset($grow['legend_long'])?$grow['legend_long']:'');
+ $legendlines .= 'legend:'.$legendline."\n";
+ }
+ $return = 'file:'.$fname."\n".$legendlines.$return;
+ return $return;
+ }
+
+ public function graph_plus($timeframe = 'day', $sub = null, $extra = null) {
+ // create a RRD graph and return meta info as a ready-to-use array
+ $gmeta = array('filename'=>null,'legends_long'=>false,'default_colorize'=>false);
+ $ret = $this->graph($timeframe, $sub, $extra);
+ if (0) {
+ // debug output
+ $gmeta['ret'] = $ret;
+ }
+ $grout = explode("\n", $ret);
+ foreach ($grout as $gline) {
+ if (preg_match('/^command:(.+)$/', $gline, $regs)) {
+ $gmeta['graph_cmd'] = $regs[1];
+ }
+ elseif (preg_match('/^file:(.+)$/', $gline, $regs)) {
+ $gmeta['filename'] = $regs[1];
+ }
+ elseif (preg_match('/^legend:([^\|]+)\|([^|]*)\|([^\|]*)\|(.*)$/', $gline, $regs)) {
+ $gmeta['legend'][$regs[1]] = array('color'=>$regs[2], 'color_bg'=>$regs[3], 'desc_long'=>$regs[4]);
+ if (strlen($regs[4])) { $gmeta['legends_long'] = true; }
+ if (strlen($regs[3]) || strlen($regs[4])) { $gmeta['default_colorize'] = true; }
+ }
+ elseif (preg_match('/^(\d+)x(\d+)$/', $gline, $regs)) {
+ $gmeta['width'] = $regs[1]; $gmeta['height'] = $regs[2];
+ }
+ elseif (preg_match('/^([^\|]+)\|([^|]+)\|([^\|]*)$/', $gline, $regs)) {
+ $gmeta['data'][$regs[1]][$regs[2]] = $regs[3];
+ }
+ elseif (preg_match('/^([^\|]+)\|([^\|]*)$/', $gline, $regs)) {
+ $gmeta['var'][$regs[1]] = $regs[2];
+ }
+ elseif (strlen(trim($gline))) {
+ $gmeta['info'][] = $gline;
+ }
+ }
+ if (is_null($gmeta['filename'])) {
+ $gmeta['filename'] = $this->basename.(!is_null($sub)?'-'.$sub:'').'-'.$timeframe.'.png';
+ }
+ return $gmeta;
+ }
+
+ public function page($sub = null, $page_extras = null, $graph_extras = null) {
+ // create a (HTML) page and return it in a string
+
+ // assemble configuration
+ $pconf = (array)$page_extras;
+ if (!is_null($sub) && is_array($this->config_raw['page.'.$sub])) {
+ $pconf = $pconf + $this->config_raw['page.'.$sub];
+ }
+ $pconf = $pconf + (array)$this->config_page;
+
+ $return = null;
+ switch (@$pconf['type']) {
+ case 'index':
+ $return = $this->page_index($pconf);
+ break;
+ case 'overview':
+ $return = $this->page_overview($pconf, $graph_extras);
+ break;
+ case 'simple':
+ default:
+ $return = $this->page_simple($pconf, $graph_extras);
+ break;
+ }
+ return $return;
+ }
+
+ public function simple_html($sub = null, $page_extras = null, $graph_extras = null) {
+ // create a simple (MRTG-like) HTML page and return it in a string
+ // XXX: this is here temporarily for compat only, it's preferred to use page()!
+ trigger_error(__CLASS__.'::'.__METHOD__.' is deprecated, use page() instead.', E_USER_NOTICE);
+
+ // assemble configuration
+ $pconf = (array)$page_extras;
+ if (!is_null($sub) && is_array($this->config_raw['page.'.$sub])) {
+ $pconf = $pconf + $this->config_raw['page.'.$sub];
+ }
+ $pconf = $pconf + (array)$this->config_page;
+
+ return $this->page_simple($pconf, $graph_extras);
+ }
+
+ private function page_index($pconf) {
+ // create a bare, very simple index list HTML page and return it in a string
+ $td = $this->mod_textdomain;
+ $ptitle = isset($pconf['title_page'])?$pconf['title_page']:dgettext($td, 'RRD statistics index');
+
+ $out = '<html><head>'."\n";
+ $out .= '<title>'.$ptitle.'</title>'."\n";
+ $out .= '<style type="text/css">'."\n";
+ if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
+ else {
+ $out .= 'h1 { font-weight: bold; font-size: 1.5em; }'."\n";
+ $out .= '.footer { font-size: 0.75em; margin: 0.5em 0; }'."\n";
+ $out .= 'li.scanfile { font-style: italic; }'."\n";
+ }
+ if (isset($pconf['style'])) { $out .= $pconf['style']; }
+ $out .= '</style>'."\n";
+ $out .= '</head>'."\n";
+ $out .= '<body>'."\n";
+
+ $out .= '<h1>'.$ptitle.'</h1>'."\n";
+ if (isset($pconf['text_intro']) && strlen($pconf['text_intro'])) {
+ $out .= '<p class="intro">'.$pconf['text_intro'].'</p>'."\n";
+ }
+ elseif (!isset($pconf['text_intro'])) {
+ $out .= '<p class="intro">'.dgettext($td, 'The following RRD stats are available:').'</p>'."\n";
+ }
+
+ $stats = $this->h_page_statsArray($pconf);
+
+ if (isset($pconf['stats_url'])) { $sURL_base = $pconf['stats_url']; }
+ else { $sURL_base = '?stat=%i%a'; }
+
+ if (isset($pconf['stats_url_add'])) { $sURL_add = $pconf['stats_url_add']; }
+ else { $sURL_add = '&sub=%s'; }
+
+ $out .= '<ul class="indexlist">'."\n";
+ foreach ($stats as $stat) {
+ $out .= '<li'.(isset($stat['class'])?' class="'.$stat['class'].'"':'').'>';
+ $sURL = str_replace('%i', $stat['name'], $sURL_base);
+ $sURL = str_replace('%a', '', $sURL);
+ $sURL = str_replace('%s', '', $sURL);
+ $out .= '<a href="'.$sURL.'">'.$stat['name'].'</a>';
+ if (isset($stat['sub']) && count($stat['sub'])) {
+ $sprt = array();
+ foreach ($stat['sub'] as $ssub) {
+ $sURL = str_replace('%i', $stat['name'], $sURL_base);
+ $sURL = str_replace('%a', $sURL_add, $sURL);
+ $sURL = str_replace('%s', $ssub, $sURL);
+ $sprt[] = '<a href="'.$sURL.'">'.$ssub.'</a>';
+ }
+ $out .= ' <span="subs">('.implode(', ', $sprt).')</span>';
+ }
+ $out .= '</li>'."\n";
+ }
+ $out .= '</ul>'."\n";
+
+ $out .= $this->h_page_footer();
+ $out .= '</body></html>'."\n";
+ return $out;
+ }
+
+ private function page_overview($pconf, $graph_extras = null) {
+ // create an overview HTML page (including graphs) and return it in a string
+ $td = $this->mod_textdomain;
+ $ptitle = isset($pconf['title_page'])?$pconf['title_page']:dgettext($td, 'RRD statistics overview');
+
+ $out = '<html><head>'."\n";
+ $out .= '<title>'.$ptitle.'</title>'."\n";
+ $out .= '<style type="text/css">'."\n";
+ if (isset($pconf['style_base'])) { $out .= $pconf['style_base']; }
+ else {
+ $out .= 'h1 { font-weight: bold; font-size: 1.5em; }'."\n";
+ $out .= 'h2 { font-weight: bold; font-size: 1em; margin: 0.5em 0; }'."\n";
+ $out .= '.footer { font-size: 0.75em; margin: 0.5em 0; }'."\n";
+ $out .= 'img.rrdgraph { border: none; }'."\n";
+ }
+ if (isset($pconf['style'])) { $out .= $pconf['style']; }
+ $out .= '</style>'."\n";
+ $out .= '</head>'."\n";
+ $out .= '<body>'."\n";
+
+ $out .= '<h1>'.$ptitle.'</h1>'."\n";
+ if (isset($pconf['text_intro']) && strlen($pconf['text_intro'])) {
+ $out .= '<p class="intro">'.$pconf['text_intro'].'</p>';