Merge branch 'origin' of hirsch
authorRobert Kaiser <kairo@kairo.at>
Thu, 3 Apr 2008 00:04:11 +0000 (02:04 +0200)
committerRobert Kaiser <kairo@kairo.at>
Thu, 3 Apr 2008 00:04:11 +0000 (02:04 +0200)
12 files changed:
include/classes/email.php-class [new file with mode: 0644]
include/classes/rrdstat.php-class [new file with mode: 0644]
include/classes/useragent.php-class [new file with mode: 0755]
testbed/rrd/.gitignore [new file with mode: 0644]
testbed/rrd/rrd-config.inc.php [new file with mode: 0644]
testbed/rrd/rrd-stat.php [new file with mode: 0644]
testbed/rrd/rrd-test.php [new file with mode: 0644]
testbed/rrd/rrd-update.php [new file with mode: 0644]
testbed/rrd/rrdstat.php-class [new symlink]
testbed/ua_list.php [new file with mode: 0644]
testbed/ua_list_raw.txt [new file with mode: 0755]
testbed/ua_test.php [new file with mode: 0644]

diff --git a/include/classes/email.php-class b/include/classes/email.php-class
new file mode 100644 (file)
index 0000000..2de9ca4
--- /dev/null
@@ -0,0 +1,342 @@
+<?php
+/* ***** BEGIN LICENSE BLOCK *****
+ *
+ * The contents of this file are subject to Austrian copyright reegulations
+ * ("Urheberrecht"); you may not use this file except in compliance with
+ * those laws.
+ * This contents and any derived work, if it gets distributed in any way,
+ * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
+ * either express or implied.
+ *
+ * The Original Code is KaiRo's E-Mail module.
+ *
+ * The Initial Developer of the Original Code is
+ * KaiRo - Robert Kaiser.
+ * Portions created by the Initial Developer are Copyright (C) 2003-2006
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Robert Kaiser <kairo@kairo.at>
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+class email {
+  // email PHP class
+  // class/object for creating a new mail and send it
+  //
+  // function __construct()
+  //   CONSTRUCTOR
+  //
+  // private $debug_toSingleAddress
+  //   address to send mail to in debug mode
+  //
+  // private $subject
+  //   the mail's subject line
+  //
+  // private $sender
+  //   the mail's sender (array; fields see recipients)
+  //
+  // private $replyto
+  //   Reply-to address (array; fields see recipients)
+  //
+  // private $recipients
+  //   array of recipients (To: line)
+  //   fields: name - real name
+  //           mail - email address
+  //
+  // private $cc
+  //   array of CC recipients (fields like recipients)
+  //
+  // private $bcc
+  //   array of BCC recipients (fields like recipients)
+  //
+  // private $headers
+  //   array containing all additional headers
+  //   fields: name - headers name
+  //           content - header content
+  //
+  // private $content_type
+  //   the mail's content type (MIME-type) [default: text/plain]
+  //
+  // private $charset
+  //   the mail's charset [default: iso-8859-15]
+  //
+  // private $mailtext
+  //   the main mail body
+  //
+  // private $attachments
+  //   array containing all attachments
+  //   fields: name - attachment name
+  //           content - attachment content
+  //           type - MIME type of that attachment
+  //
+  // public function setDebugAddress($debug_email)
+  //   debug mode: send only to this address
+  //
+  // public function setSubject($newsubject)
+  //   set subject of mail
+  //
+  // public function setSender($email, [$name])
+  //   set sender of mail
+  //
+  // public function setReplyTo($email, [$name])
+  //   set reply-to address
+  //
+  // public function addRecipient($email, [$name])
+  //   add a recipient to the mail
+  //
+  // public function addCC($email, [$name])
+  //   add a CC recipient to the mail
+  //
+  // public function addBCC($email, [$name])
+  //   add a BCC recipient to the mail
+  //
+  // public function addHeader($hname, [$hcontent])
+  //   add a header to the mail
+  //
+  // public function addHeaderAddress($hname, $email, [$name])
+  //   add an address header to the mail, possibly with both name and mail parts
+  //
+  // public function addMailText($textpart)
+  //   add some text to the mail
+  //
+  // public function addAttachment($aname, $acontent, [$atype])
+  //   add an attachment to the mail, use given file name, content and MIME type (defaults to application/octet-stream)
+  //
+  // public function getAddresses([$addrtype])
+  //   returns an array of all addresses this mail gets sent to
+  //     fields: email, name, addrtype
+  //       addrtype is one of to/cc/bcc
+  //       the $addrtype parameter is a comma-separated list of such types, default: all of them
+  //
+  // public function send()
+  //   really send the mail
+  //
+  // private function mimeencode($fieldtext, [$stringescape])
+  //   helper function:
+  //     encode given field text, ready to be placed into an e-mail MIME header
+  //     if the boolean $stringescape is true, make sure this is sent as a single word in RFC2822 context (e.g. for names)
+  //     see http://www.ietf.org/rfc/rfc2822.txt for the RFC in question
+
+  private $debug_toSingleAddress = '';
+  private $subject;
+  private $sender = array();
+  private $replyto = array();
+  private $recipients = array();
+  private $cc = array();
+  private $bcc = array();
+  private $headers = array();
+  private $content_type = 'text/plain';
+  private $charset = 'iso-8859-15';
+  private $mailtext = '';
+  private $attachments = array();
+
+  function __construct() {
+    // *** constructor ***
+  }
+
+  public function setDebugAddress($debug_email) { $this->debug_toSingleAddress = $debug_email; }
+
+  public function setSubject($newsubject) { $this->subject = $newsubject; }
+
+  public function setSender($email, $name = '') { $this->sender = array('mail' => $email, 'name' => $name); }
+
+  public function setReplyTo($email, $name = '') { $this->replyto = array('mail' => $email, 'name' => $name); }
+
+  public function addRecipient($email, $name = '') {
+    $this->recipients[] = array('mail' => $email, 'name' => $name);
+  }
+
+  public function addCC($email, $name = '') {
+    $this->cc[] = array('mail' => $email, 'name' => $name);
+  }
+
+  public function addBCC($email, $name = '') {
+    $this->bcc[] = array('mail' => $email, 'name' => $name);
+  }
+
+  public function addHeader($hname, $hcontent = '') {
+    $this->headers[] = array('name' => $hname, 'content' => $hcontent);
+  }
+
+  public function addHeaderAddress($hname, $email, $name = '') {
+    if (strlen($name)) { $hcontent = $this->mimeencode($name, true).' <'.$email.'>'; }
+    else { $hcontent = $email; }
+    $this->headers[] = array('name' => $hname, 'content' => $hcontent);
+  }
+
+  public function addMailText($textpart) { $this->mailtext .= $textpart; }
+
+  public function addAttachment($aname, $acontent, $atype = 'application/octet-stream') {
+    $this->attachments[] = array('name' => $aname, 'content' => $acontent, 'type' => $atype);
+  }
+
+  public function getAddresses($addrtype = null) {
+    // returns all addresses this mail gets sent to
+    if (!is_array($addrtype)) {
+      if (strlen($addrtype)) { $addrtype = explode(',', strtolower($addrtype)); }
+      else { $addrtype = array('to','cc','bcc'); }
+    }
+    $mailaddresses = array();
+
+    if (in_array('to', $addrtype)) {
+      foreach ($this->recipients as $address) {
+        if (strlen(@$address['mail'])) {
+          $mailaddresses[] = array('mail'=>$address['mail'],
+                                   'name'=>strlen($address['name'])?$address['name']:'',
+                                   'addrtype'=>'to');
+        }
+      }
+    }
+    if (in_array('cc', $addrtype)) {
+      foreach ($this->cc as $address) {
+        if (strlen(@$address['mail'])) {
+          $mailaddresses[] = array('mail'=>$address['mail'],
+                                   'name'=>strlen($address['name'])?$address['name']:'',
+                                   'addrtype'=>'cc');
+        }
+      }
+    }
+    if (in_array('bcc', $addrtype)) {
+      foreach ($this->bcc as $address) {
+        if (strlen(@$address['mail'])) {
+          $mailaddresses[] = array('mail'=>$address['mail'],
+                                   'name'=>strlen($address['name'])?$address['name']:'',
+                                   'addrtype'=>'bcc');
+        }
+      }
+    }
+
+    return $mailaddresses;
+  }
+
+  public function send() {
+    global $util;
+    $mtxt = '';
+    $hdrs = 'MIME-Version: 1.0'."\n";
+    $subj = $this->mimeencode($this->subject);
+    if (strlen($this->sender['name'])) {
+      $hdrs .= 'From: '.$this->mimeencode($this->sender['name'], true).' <'.$this->sender['mail'].'>'."\n";
+    }
+    else { $hdrs .= 'From: '.$this->sender['mail']."\n"; }
+    if (count($this->replyto)) {
+      if (strlen($this->replyto['name'])) {
+        $hdrs .= 'Reply-to: '.$this->mimeencode($this->replyto['name'], true).' <'.$this->replyto['mail'].'>'."\n";
+      }
+      else { $hdrs .= 'Reply-to: '.$this->replyto['mail']."\n"; }
+    }
+    if (count($this->recipients)) {
+      $recpt = '';
+      foreach ($this->recipients as $address) {
+        if (strlen(@$address['mail'])) {
+          if (strlen($address['name'])) { $recpt .= $this->mimeencode($address['name'], true).' <'.$address['mail'].'>,'; }
+          else { $recpt .= $address['mail'].','; }
+        }
+      }
+      $recpt = preg_replace('/,$/', '', $recpt);
+    }
+    if (!strlen($recpt)) {
+      return null;
+    }
+    if (count($this->cc)) {
+      $adrs = '';
+      foreach ($this->cc as $address) {
+        if (strlen($address['name'])) { $adrs .= $this->mimeencode($address['name'], true).' <'.$address['mail'].'>,'; }
+        else { $adrs .= $address['mail'].','; }
+      }
+      $adrs = preg_replace('/,$/', '', $adrs);
+      $hdrs .= (strlen($this->debug_toSingleAddress)?'X-Real-':'').'Cc: '.$adrs."\n";
+    }
+    if (count($this->bcc)) {
+      $adrs = '';
+      foreach ($this->bcc as $address) {
+        if (strlen($address['name'])) { $adrs .= $this->mimeencode($address['name'], true).' <'.$address['mail'].'>,'; }
+        else { $adrs .= $address['mail'].','; }
+      }
+      $adrs = preg_replace('/,$/', '', $adrs);
+      $hdrs .= (strlen($this->debug_toSingleAddress)?'X-Real-':'').'Bcc: '.$adrs."\n";
+    }
+    if (count($this->headers)) {
+      foreach ($this->headers as $header) {
+        $hdrs .= $header['name'].': '.$header['content']."\n";
+      }
+    }
+    if (count($this->attachments)) {
+      // create random boundary, 20 chars, always beginning with KaiRo ;-)
+      $boundary = 'KaiRo';
+      for ($i = 1; $i <= 15; $i++)     {
+        $r = rand(0, 61);
+        if ($r < 10) { $boundary .= chr($r + 48); }
+        elseif ($r < 36) { $boundary .= chr($r + 55); }
+        elseif ($r < 62) { $boundary .= chr($r + 61); }
+      }
+      $hdrs .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'";'."\n";
+      $hdrs .= 'Content-Transfer-Encoding: 7bit'."\n";
+      $mtxt .= 'This part of the E-mail should never be seen. If'."\n";
+      $mtxt .= 'you are reading this, consider upgrading your e-mail'."\n";
+      $mtxt .= 'client to a MIME-compatible client.'."\n";
+      $mtxt .= "\n".'--'.$boundary."\n";
+      if (preg_match('|^text/|', $this->content_type)) {
+        $mtxt .= 'Content-Type: '.$this->content_type.'; charset="'.$this->charset.'"'."\n";
+      }
+      else {
+        $mtxt .= 'Content-Type: '.$this->content_type."\n";
+      }
+      $mtxt .= 'Content-Transfer-Encoding: 8bit'."\n\n";
+    }
+    else {
+      if (preg_match('|^text/|', $this->content_type)) {
+        $hdrs .= 'Content-Type: '.$this->content_type.'; charset="'.$this->charset.'"'."\n";
+      }
+      else {
+        $hdrs .= 'Content-Type: '.$this->content_type."\n";
+      }
+      $hdrs .= 'Content-Transfer-Encoding: 8bit'."\n";
+    }
+    $mtxt .= stripslashes($this->mailtext);
+    if (count($this->attachments)) {
+      foreach ($this->attachments as $attach) {
+        $mtxt .= "\n".'--'.$boundary."\n";
+        $mtxt .= 'Content-Type: '.$attach['type'].'; name="'.$attach['name'].'";'."\n";
+        if (preg_match('/^(text|message)\//', $attach['type'])) {
+          $mtxt .= 'Content-Transfer-Encoding: 8bit'."\n";
+          $mtxt .= 'Content-Disposition: attachment'."\n\n";
+          $mtxt .= $attach['content'];
+          $mtxt .= "\n";
+        }
+        else {
+          $mtxt .= 'Content-Transfer-Encoding: base64'."\n";
+          $mtxt .= 'Content-Disposition: attachment'."\n\n";
+          $mtxt .= rtrim(chunk_split(base64_encode($attach['content']), 76)); ;
+          $mtxt .= "\n";
+        }
+      }
+      $mtxt .= '--'.$boundary.'--'."\n";
+    }
+
+    if (strlen($this->debug_toSingleAddress)) {
+      $hdrs .= 'X-Real-To: '.$recpt."\n";
+      $recpt = $this->debug_toSingleAddress;
+    }
+
+    //print('Subject: '.$util->htmlify($subj).'<br>'."\n");
+    //print('To: '.$util->htmlify($recpt).'<br>'."\n");
+    //print(nl2br($util->htmlify($hdrs)));
+    //print(nl2br($util->htmlify($mtxt)));
+    return mail($recpt, $subj, $mtxt, $hdrs);
+  }
+
+  private function mimeencode($fieldtext, $stringescape = false) {
+    $mText = imap_8bit($fieldtext);
+    $is_qpformat = ($mText != $fieldtext);
+    if ($stringescape && preg_match('/[^\w !#$%&\'*+\/=?^`{|}~-]/', $mText)) {
+      // if needed, make this a quoted-string instead of an atom (to speak in RFC2822 language)
+      $mText = '"'.strtr($mText, array('"' => '\"', '\\' => '\\\\')).'"';
+    }
+    if ($is_qpformat) {
+      $mText = strtr($mText, array('_' => '=5F', ' ' => '_', '?' => '=3F'));
+      $mText = '=?'.strtoupper($this->charset).'?Q?'.$mText.'?=';
+    }
+  return $mText;
+  }
+}
+?>
diff --git a/include/classes/rrdstat.php-class b/include/classes/rrdstat.php-class
new file mode 100644 (file)
index 0000000..d38df2d
--- /dev/null
@@ -0,0 +1,1228 @@
+<?php
+/* ***** BEGIN LICENSE BLOCK *****
+ *
+ * The contents of this file are subject to Austrian copyright reegulations
+ * ("Urheberrecht"); you may not use this file except in compliance with
+ * those laws.
+ * This contents and any derived work, if it gets distributed in any way,
+ * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
+ * either express or implied.
+ *
+ * The Original Code is KaiRo's RRD statistics class.
+ *
+ * The Initial Developer of the Original Code is
+ * KaiRo - Robert Kaiser.
+ * Portions created by the Initial Developer are Copyright (C) 2005-2006
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Robert Kaiser <kairo@kairo.at>
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+class rrdstat {
+  // rrdstat PHP class
+  // rrdtool statistics functions
+  //
+  // function __construct($rrdconfig, [$conf_id])
+  //   CONSTRUCTOR
+  //     if $conf_id is set, $rrdconfig is a total configuration set
+  //     else it's the configuration for this one RRD
+  //     currently only a config array is supported, XML config is planned
+  //
+  // private $rrd_file
+  // RRD file name
+  //
+  // private $basename
+  // base name for this RRD (usually file name without .rrd)
+  //
+  // private $basedir
+  // base directory for this RRD (with a trailing slash)
+  //   note that $rrd_file usually includes that path as well, but graph directory gets based on this value
+  //
+  // private $config_all
+  // complete, raw configuration array set
+  //
+  // private $config_raw
+  // configuration array set for current RRD
+  //
+  // private $config_graph
+  // configuration array set for default graph in this RRD
+  //
+  // private $config_page
+  // configuration array set for default page in this RRD
+  //
+  // private $rrd_fields
+  // definition of this RRD's fields
+  //
+  // private $rra_base
+  // definition of this RRD's base RRAs
+  //
+  // private $rrd_step
+  // basic stepping of this RRD in seconds (default: 300)
+  //
+  // private $rra_add_max
+  // should RRAs for MAX be added for every base RRA? (bool, default: true)
+  //
+  // private $status
+  // status of the RRD (unused/ok/readonly/graphonly)
+  //   note that most functions require certain status values
+  //   (e.g. update only works if status is ok, graph for ok/readonly/graphonly)
+  //
+  // private $mod_textdomain
+  //   GNU gettext domain for this module
+  //
+  // private function set_def($rrdconfig, [$conf_id])
+  //   set definitions based on given configuration
+  //   [intended for internal use, called by the constructor]
+  //
+  // public function rrd_version() {
+  //   get RRDtool version string
+  //
+  // public function create()
+  //   create RRD file according to set config
+  //
+  // public function update([$upArray])
+  //   feed new data into RRD (either use given array of values or use auto-update info from config)
+  //
+  // public function fetch([$cf] = 'AVERAGE', $resolution = null, $start = null, $end = null)
+  //   fetch data from the defined RRD
+  //     using given consolidation function [default is AVERAGE],
+  //     resolution (seconds, default is the RRD's stepping),
+  //     start and end times (unix epoch, defaults are the RRD's last update time)
+  //
+  // public function last_update()
+  //   fetch time of last update in this RRD file
+  //
+  // public function graph([$timeframe], [$sub], [$extra])
+  //   create a RRD graph (and return all meta info in a flat string)
+  //     for given timeframe (day [default]/week/month/year),
+  //     sub-graph ID (if given) and extra config options (if given)
+  //
+  // public function graph_plus([$timeframe], [$sub], [$extra])
+  //   create a RRD graph (see above) and return meta info as a ready-to-use array
+  //
+  // public function page([$sub], [$page_extras], [$graph_extras])
+  //   create a (HTML) page and return it in a string
+  //     for given sub-page ID (if given, default is a simple HTML page)
+  //     and extra page and graph config options (if given)
+  //
+  // public function simple_html([$sub], [$page_extras], [$graph_extras])
+  //   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()!
+  //
+  // private function page_index($pconf)
+  //   create a bare, very simple index list HTML page and return it in a string
+  //   using given page config options
+  //   [intended for internal use, called by page()]
+  //
+  // private function page_overview($pconf, [$graph_extras])
+  //   create an overview HTML page (including graphs) and return it in a string
+  //   using given page config options and extra graph options (if given)
+  //   [intended for internal use, called by page()]
+  //
+  // private function page_simple($pconf, [$graph_extras])
+  //   create a simple (MRTG-like) HTML page and return it in a string
+  //   using given page config options and extra graph options (if given)
+  //   [intended for internal use, called by page()]
+  //
+  // private function h_page_statsArray($pconf)
+  //   return array of stats to list on a page, using given page config options
+  //   [intended for internal use, called by page_*()]
+  //
+  // private function h_page_footer()
+  //   return generic page footer
+  //   [intended for internal use, called by page_*()]
+  //
+  // private function text_quote($text)
+  //   return a quoted/escaped text for use in rrdtool commandline text fields
+
+  private $rrd_file = null;
+  private $basename = null;
+  private $basedir = null;
+
+  private $config_all = null;
+  private $config_raw = null;
+  private $config_graph = null;
+  private $config_page = null;
+
+  private $rrd_fields = array();
+  private $rra_base = array();
+  private $rrd_step = 300;
+  private $rra_add_max = true;
+
+  private $status = 'unused';
+
+  private $mod_textdomain;
+
+  function __construct($rrdconfig, $conf_id = null) {
+    // ***** init RRD stat module *****
+    $this->mod_textdomain = 'class_rrdstat';
+    $mod_charset = 'iso-8859-15';
+
+    bindtextdomain($this->mod_textdomain, class_exists('baseutils')?baseutils::getDir('locale'):'locale/');
+    bind_textdomain_codeset($this->mod_textdomain, $mod_charset);
+
+    $this->set_def($rrdconfig, $conf_id);
+
+    if (($this->status == 'unused') && !is_null($this->rrd_file)) {
+      if (!is_writeable($this->rrd_file)) {
+        if (!file_exists($this->rrd_file)) {
+          if (@touch($this->rrd_file)) { $this->create(); }
+          else { trigger_error('RRD file can not be created', E_USER_WARNING); }
+        }
+        else {
+          if (is_readable($this->rrd_file)) { $this->status = 'readonly'; }
+          else { trigger_error('RRD file is not readable', E_USER_WARNING); }
+        }
+      }
+      else {
+        $this->status = 'ok';
+      }
+    }
+  }
+
+  private function set_def($rrdconfig, $conf_id = null) {
+    if (is_array($rrdconfig)) {
+      // we have an array in the format we like to have
+      $complete_conf =& $rrdconfig;
+    }
+    else {
+      // we have something else (XML data?), try to generate the iinfo aray from it
+      $complete_conf =& $rrdconfig;
+    }
+
+    if (!is_null($conf_id)) {
+      $iinfo = isset($complete_conf[$conf_id])?$complete_conf[$conf_id]:array();
+      if (isset($complete_conf['*'])) {
+        $iinfo = (array)$iinfo + (array)$complete_conf['*'];
+        if (isset($complete_conf['*']['graph'])) {
+          $iinfo['graph'] = (array)$iinfo['graph'] + (array)$complete_conf['*']['graph'];
+        }
+        if (isset($complete_conf['*']['page'])) {
+          $iinfo['page'] = (array)$iinfo['page'] + (array)$complete_conf['*']['page'];
+        }
+      }
+    }
+    else {
+      $iinfo = $complete_conf;
+    }
+
+    if (isset($iinfo['path']) && strlen($iinfo['path'])) {
+      $this->basedir = $iinfo['path'];
+      if (substr($this->basedir, -1) != '/') { $this->basedir .= '/'; }
+    }
+
+    if (isset($iinfo['graph-only']) && $iinfo['graph-only'] && !is_null($conf_id)) {
+      $this->basename = $conf_id;
+      $this->status = 'graphonly';
+    }
+    elseif (isset($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->basename = $conf_id;
+    }
+    else {
+      $this->basename = !is_null($conf_id)?$conf_id:'xxx.unknown';
+    }
+
+    if (!is_null($this->rrd_file)) {
+      // fields (data sources, DS)
+      //  name - DS name
+      //  type - one of COUNTER, GAUGE, DERIVE, ABSOLUTE
+      //  heartbeat - if no sample recieved for that time, store UNKNOWN
+      //  min - U (unconstrained) or minimum value
+      //  max - U (unconstrained) or maximum value
+      //  update - this string will be fed into eval() for updating this field
+      if (isset($iinfo['fields']) && is_array($iinfo['fields'])) {
+        $this->rrd_fields = $iinfo['fields'];
+      }
+      else {
+        $this->rrd_fields[] = array('name' => 'ds0', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+        $this->rrd_fields[] = array('name' => 'ds1', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+      }
+
+
+      // MRTG-style RRD "database", see http://oss.oetiker.ch/rrdtool/tut/rrdtutorial.en.html
+      //
+      // archives (RRAs):
+      // 600 samples of 5 minutes  (2 days and 2 hours)
+      // 700 samples of 30 minutes (2 days and 2 hours, plus 12.5 days)
+      // 775 samples of 2 hours    (above + 50 days)
+      // 797 samples of 1 day      (above + 732 days, rounded up to 797)
+
+      $this->rrd_step = isset($iinfo['rrd_step'])?$iinfo['rrd_step']:300;
+
+      if (isset($iinfo['rra_base']) && is_array($iinfo['rra_base'])) {
+        $this->rra_base = $iinfo['rra_base'];
+      }
+      else {
+        $this->rra_base[] = array('step' => 1, 'rows' => 600);
+        $this->rra_base[] = array('step' => 6, 'rows' => 700);
+        $this->rra_base[] = array('step' => 24, 'rows' => 775);
+        $this->rra_base[] = array('step' => 288, 'rows' => 797);
+      }
+
+      $this->rra_add_max = isset($iinfo['rra_add_max'])?$iinfo['rra_add_max']:true;
+    }
+
+    if (isset($iinfo['graph'])) { $this->config_graph = $iinfo['graph']; }
+    if (isset($iinfo['page'])) { $this->config_page = $iinfo['page']; }
+    $this->config_raw = $iinfo;
+    $this->config_all = $complete_conf;
+  }
+
+  public function rrd_version() {
+    // return RRDtool version
+    static $version;
+    if (!isset($version)) {
+      $create_cmd = 'rrdtool --version';
+      $return = `$create_cmd 2>&1`;
+      if (strpos($return, 'ERROR') !== false) {
+        trigger_error($this->rrd_file.' - rrd version error: '.$return, E_USER_WARNING);
+      }
+
+      if (preg_match('/^\s*RRDtool ([\d\.]+)\s+/', $return, $regs)) {
+        $version = $regs[1];
+      }
+      else {
+        $version = '0.0';
+      }
+    }
+  return $version;
+  }
+
+  public function create() {
+    // create RRD file
+
+    // compose create command
+    $create_cmd = 'rrdtool create '.$this->rrd_file.' --step '.$this->rrd_step;
+    foreach ($this->rrd_fields as $ds) {
+      if (!isset($ds['type'])) { $ds['type'] = 'COUNTER'; }
+      if (!isset($ds['heartbeat'])) { $ds['heartbeat'] = 2*$this->rrd_step; }
+      if (!isset($ds['min'])) { $ds['min'] = 'U'; }
+      if (!isset($ds['max'])) { $ds['max'] = 'U'; }
+      $create_cmd .= ' DS:'.$ds['name'].':'.$ds['type'].':'.$ds['heartbeat'].':'.$ds['min'].':'.$ds['max'];
+    }
+    foreach ($this->rra_base as $rra) {
+      if (!isset($rra['cf'])) { $rra['cf'] = 'AVERAGE'; }
+      if (!isset($rra['xff'])) { $rra['xff'] = 0.5; }
+      if (!isset($rra['step'])) { $rra['step'] = 1; }
+      if (!isset($rra['rows'])) { $rra['rows'] = 600; }
+      $create_cmd .= ' RRA:'.$rra['cf'].':'.$rra['xff'].':'.$rra['step'].':'.$rra['rows'];
+    }
+    if ($this->rra_add_max) {
+      foreach ($this->rra_base as $rra) {
+        if (!isset($rra['cf'])) {
+          // only rows that have no CF set will be looked at here
+          $rra['cf'] = 'MAX';
+          if (!isset($rra['xff'])) { $rra['xff'] = 0.5; }
+          if (!isset($rra['step'])) { $rra['step'] = 1; }
+          if (!isset($rra['rows'])) { $rra['rows'] = 600; }
+          $create_cmd .= ' RRA:'.$rra['cf'].':'.$rra['xff'].':'.$rra['step'].':'.$rra['rows'];
+        }
+      }
+    }
+    $return = `$create_cmd 2>&1`;
+    if (strpos($return, 'ERROR') !== false) {
+      trigger_error($this->rrd_file.' - rrd create error: '.$return, E_USER_WARNING);
+    }
+    else { $this->status = 'ok'; }
+  }
+
+  public function update($upArray = null) {
+    // feed new data into RRD
+    if ($this->status != 'ok') { trigger_error('Cannot update non-writeable file', E_USER_WARNING); return false; }
+    $upvals = array();
+    if (isset($this->config_raw['update'])) {
+      if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $this->config_raw['update'], $regs)) {
+        $upfunc = create_function('', $regs[1]);
+        $upvals = $upfunc();
+      }
+      else {
+        $evalcode = $this->config_raw['update'];
+        if (!is_null($evalcode)) {
+          ob_start();
+          eval($evalcode);
+          $ret = ob_get_contents();
+          if (strlen($ret)) { $upvals = explode("\n", $ret); }
+          ob_end_clean();
+        }
+      }
+    }
+    else {
+      foreach ($this->rrd_fields as $ds) {
+        if (is_array($upArray) && isset($upArray[$ds['name']])) { $val = $upArray[$ds['name']]; }
+        elseif (isset($ds['update'])) {
+          $val = null; $evalcode = null;
+          if (substr($ds['update'], 0, 4) == 'val:') {
+            $evalcode = 'function { return trim('.substr($ds['update'], 4).')); }';
+          }
+          elseif (substr($ds['update'], 0, 8) == 'snmp-if:') {
+            $snmphost = 'localhost'; $snmpcomm = 'public';
+            list($nix, $ifname, $valtype) = explode(':', $ds['update'], 3);
+            $iflist = explode("\n", `snmpwalk -v2c -c $snmpcomm $snmphost interfaces.ifTable.ifEntry.ifDescr`);
+            $ifnr = null;
+            foreach ($iflist as $ifdesc) {
+              if (preg_match('/ifDescr\.(\d+) = STRING: '.$ifname.'/', $ifdesc, $regs)) { $ifnr = $regs[1]; }
+            }
+            $oid = null;
+            if ($valtype == 'in') { $oid = '1.3.6.1.2.1.2.2.1.10.'.$ifnr; }
+            elseif ($valtype == 'out') { $oid = '1.3.6.1.2.1.2.2.1.16.'.$ifnr; }
+            if (!is_null($ifnr) && !is_null($oid)) {
+              $evalcode = 'function { return trim(substr(strrchr(`snmpget -v2c -c '.$snmpcomm.' '.$snmphost.' '.$oid.'`,":"),1)); }';
+            }
+          }
+          else { $evalcode = $ds['update']; }
+          if (preg_match('/^\s*function\s+{(.*)}\s*$/is', $evalcode, $regs)) {
+            $upfunc = create_function('', $regs[1]);
+            $val = $upfunc();
+          }
+          elseif (!is_null($evalcode)) {
+            ob_start();
+            eval($evalcode);
+            $val = ob_get_contents();
+            ob_end_clean();
+          }
+        }
+        else { $val = null; }
+        $upvals[$ds['name']] = $val;
+      }
+    }
+    $key_names = (!is_numeric(array_shift(array_keys($upvals))));
+    if (in_array('L', $upvals, true)) {
+      // for at least one value, we need to set the same as the last recorded value
+      $fvals = $this->fetch();
+      $rowids = array_shift($fvals);
+      $lastvals = array_shift($fvals);
+      foreach (array_keys($upvals, 'L') as $akey) {
+        $upvals[$akey] = $key_names?$lastvals[$akey]:$lastvals[$rowids[$akey]];
+      }
+    }
+    $walkfunc = create_function('&$val,$key', '$val = is_numeric(trim($val))?trim($val):"U";');
+    array_walk($upvals, $walkfunc);
+    $return = null;
+    if (count($upvals)) {
+      $update_cmd = 'rrdtool update '.$this->rrd_file
+                    .($key_names?' --template '.implode(':', array_keys($upvals)):'').' N:'.implode(':', $upvals);
+      $return = `$update_cmd 2>&1`;
+    }
+
+    if (strpos($return, 'ERROR') !== false) {
+      trigger_error($this->rrd_file.' - rrd update error: '.$return, E_USER_WARNING);
+      $success = false;
+    }
+    else { $success = true; }
+  return $success;
+  }
+
+  public function fetch($cf = 'AVERAGE', $resolution = null, $start = null, $end = null) {
+    // fetch data from a RRD
+    if (!in_array($this->status, array('ok','readonly'))) {
+      trigger_error('Error: rrd status is '.$this->status, E_USER_WARNING); return false;
+    }
+
+    if (!in_array($cf, array('AVERAGE','MIN','MAX','LAST'))) { $cf = 'AVERAGE'; }
+    if (!is_numeric($resolution)) { $resolution = $this->rrd_step; }
+    if (!is_numeric($end)) { $end = $this->last_update(); }
+    elseif ($end < 0) { $end += $this->last_update(); }
+    $end = intval($end/$resolution)*$resolution;
+    if (!is_numeric($start)) { $start = $end; }
+    elseif ($start < 0) { $start += $end; }
+    $start = intval($start/$resolution)*$resolution;
+
+    $fetch_cmd = 'rrdtool fetch '.$this->rrd_file.' '.$cf.' --resolution '.$resolution.' --start '.$start.' --end '.$end;
+    $return = `$fetch_cmd 2>&1`;
+
+    if (strpos($return, 'ERROR') !== false) {
+      trigger_error($this->rrd_file.' - rrd fetch error: '.$return, E_USER_WARNING);
+      $fresult = false;
+    }
+    else {
+      $fresult = array();
+      $rows = explode("\n", $return);
+      $fields = preg_split('/\s+/', array_shift($rows));
+      if (array_shift($fields) == 'timestamp') {
+        $fresult[0] = $fields;
+        foreach ($rows as $row) {
+          if (strlen(trim($row))) {
+            $rvals = preg_split('/\s+/', $row);
+            $rtime = str_replace(':', '', array_shift($rvals));
+            $rv_array = array();
+            foreach ($rvals as $key=>$rval) {
+              $rv_array[$fields[$key]] = ($rval=='nan')?null:floatval($rval);
+            }
+            $fresult[$rtime] = $rv_array;
+          }
+        }
+      }
+    }
+  return $fresult;
+  }
+
+  public function last_update() {
+    // fetch time of last update in this RRD file
+    static $last_update;
+    if (!isset($last_update) && in_array($this->status, array('ok','readonly'))) {
+      $last_cmd = 'rrdtool last '.$this->rrd_file;
+      $return = trim(`$last_cmd 2>&1`);
+      $last_update = is_numeric($return)?$return:null;
+    }
+  return isset($last_update)?$last_update:null;
+  }
+
+  public function graph($timeframe = 'day', $sub = null, $extra = null) {
+    // create a RRD graph
+    static $gColors;
+    if (!isset($gColors)) {
+      $gColors = array('#00CC00','#0000FF','#000000','#FF0000','#00FF00','#FFFF00','#FF00FF','#00FFFF',
+                       '#808080','#800000','#008000','#000080','#808000','#800080','#008080','#C0C0C0');
+    }
+
+    if (!in_array($this->status, array('ok','readonly','graphonly'))) {
+      trigger_error('Error: rrd status is '.$this->status, E_USER_WARNING); return false;
+    }
+
+    // assemble configuration
+    $gconf = (array)$extra;
+    if (!is_null($sub) && is_array($this->config_raw['graph.'.$sub])) {
+      $gconf = $gconf + $this->config_raw['graph.'.$sub];
+    }
+    $gconf = $gconf + (array)$this->config_graph;
+
+    if (isset($gconf['format']) && ($gconf['format'] == 'SVG')) {
+      $format = $gconf['format']; $fmt_ext = '.svg';
+    }
+    elseif (isset($gconf['format']) && ($gconf['format'] == 'EPS')) {
+      $format = $gconf['format']; $fmt_ext = '.eps';
+    }
+    elseif (isset($gconf['format']) && ($gconf['format'] == 'PDF')) {
+      $format = $gconf['format']; $fmt_ext = '.pdf';
+    }
+    else {
+      $format = 'PNG'; $fmt_ext = '.png';
+    }
+
+    if (isset($gconf['filename'])) { $fname = $gconf['filename']; }
+    else { $fname = $this->basename.(is_null($sub)?'':'-%s').'-%t%f'; }
+    $fname = str_replace('%s', strval($sub), $fname);
+    $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; }
+    $fname = str_replace('//', '/', $fname);
+
+    $graphrows = array(); $specialrows = array(); $gC = 0;
+    $gDefs = ''; $gGraphs = ''; $addSpecial = '';
+
+    // the default size for the graph area has a width of 400px, so use 400 slices by default
+    if ($timeframe == 'day') {
+      $slice = isset($gconf['slice'])?$gconf['slice']:300; // 5 minutes
+      $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 33.33 hours
+      // vertical lines at day borders
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d')).'#FF0000';
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' -1 day').'#FF0000';
+      if (!isset($gconf['grid_x'])) { $gconf['grid_x'] = 'HOUR:1:HOUR:6:HOUR:2:0:%-H'; }
+    }
+    elseif ($timeframe == 'week') {
+      $slice = isset($gconf['slice'])?$gconf['slice']:1800; // 30 minutes
+      $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 8.33 days
+      // vertical lines at week borders
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' '.(-date('w')+1).' day').'#FF0000';
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-m-d').' '.(-date('w')-6).' day').'#FF0000';
+    }
+    elseif ($timeframe == 'month') {
+      $slice = isset($gconf['slice'])?$gconf['slice']:7200; // 2 hours
+      $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 33.33 days
+      // vertical lines at month borders
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-m-01')).'#FF0000';
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-m-01').' -1 month').'#FF0000';
+    }
+    elseif ($timeframe == 'year') {
+      $slice = isset($gconf['slice'])?$gconf['slice']:86400; // 1 day
+      $duration = isset($gconf['duration'])?$gconf['duration']:400*$slice; // 400 days
+      // vertical lines at month borders
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-01-01 12:00:00')).'#FF0000';
+      $addSpecial .= ' VRULE:'.strtotime(date('Y-01-01 12:00:00').' -1 year').'#FF0000';
+    }
+    else {
+      $duration = isset($gconf['duration'])?$gconf['duration']:$this->rrd_step*500; // 500 steps
+      $slice = isset($gconf['slice'])?$gconf['slice']:$this->rrd_step; // whatever our step is
+    }
+
+    $use_gcrows = (isset($gconf['rows']) && count($gconf['rows']));
+    if ($use_gcrows) { $grow_def =& $gconf['rows']; }
+    else { $grow_def =& $this->rrd_fields; }
+    foreach ($grow_def as $key=>$erow) {
+      if (isset($erow['name']) && strlen($erow['name'])) {
+        if (!isset($erow['scale']) && isset($gconf['scale'])) { $erow['scale'] = $gconf['scale']; }
+        if (!isset($erow['scale_time_src']) && isset($gconf['scale_time_src'])) {
+          $erow['scale_time_src'] = $gconf['scale_time_src'];
+        }
+        if (!isset($erow['scale_time_tgt']) && isset($gconf['scale_time_tgt'])) {
+          $erow['scale_time_tgt'] = $gconf['scale_time_tgt'];
+        }
+        foreach (array('scale_time_src','scale_time_tgt') as $st) {
+          if (!isset($erow[$st]) || !is_numeric($erow[$st])) {
+            switch (@$erow[$st]) {
+              case 'dyn':
+              case 'auto':
+                $erow[$st] = $slice;
+                break;
+              case 'day':
+                $erow[$st] = 24*3600;
+                break;
+              case '2hr':
+              case '2hours':
+                $erow[$st] = 7200;
+                break;
+              case 'hr':
+              case 'hour':
+                $erow[$st] = 3600;
+                break;
+              case '30min':
+                $erow[$st] = 1800;
+                break;
+              case '5min':
+                $erow[$st] = 300;
+                break;
+              case 'min':
+                $erow[$st] = 60;
+                break;
+              case 's':
+              case 'sec':
+              default:
+                $erow[$st] = 1;
+                break;
+            }
+          }
+        }
+        $scale_time_factor = $erow['scale_time_tgt']/$erow['scale_time_src'];
+        if ($scale_time_factor != 1) { $erow['scale'] = (isset($erow['scale'])?$erow['scale']:1)*$scale_time_factor; }
+        $grow = array();
+        $grow['dType'] = ($use_gcrows && isset($erow['dType']))?$erow['dType']:'DEF';
+        $grow['name'] = $erow['name'].(isset($erow['scale'])?'_tmp':'');
+        if ($grow['dType'] == 'DEF') {
+          $grow['dsname'] = ($use_gcrows && isset($erow['dsname']))?$erow['dsname']:$erow['name'];
+          if ($use_gcrows && isset($erow['dsfile'])) { $grow['dsfile'] = $erow['dsfile']; }
+          $grow['cf'] = ($use_gcrows && isset($erow['cf']))?$erow['cf']:'AVERAGE';
+        }
+        else {
+          $grow['rpn_expr'] = isset($erow['rpn_expr'])?$erow['rpn_expr']:'0';
+        }
+        if (isset($erow['scale'])) {
+          $graphrows[] = $grow;
+          $grow = array();
+          $grow['dType'] = 'CDEF';
+          $grow['name'] = $erow['name'];
+          $grow['rpn_expr'] = $erow['name'].'_tmp,'.$erow['scale'].',*';
+        }
+        if ($use_gcrows) { $grow['gType'] = isset($erow['gType'])?$erow['gType']:'LINE1'; }
+        else { $grow['gType'] = ((count($grow_def)==2) && ($key==0))?'AREA':'LINE1'; }
+        $grow['color'] = isset($erow['color'])?$erow['color']:$gColors[$gC++];
+        $grow['color_bg'] = isset($erow['color_bg'])?$erow['color_bg']:'';
+        if ($gC >= count($gColors)) { $gC = 0; }
+        if (isset($erow['legend'])) {
+          $grow['legend'] = $erow['legend'];
+          if (!isset($gconf['show_legend'])) { $gconf['show_legend'] = true; }
+        }
+        if (isset($erow['stack'])) { $grow['stack'] = ($erow['stack'] == true); }
+        if (isset($erow['desc'])) { $grow['desc'] = $erow['desc']; }
+        if (isset($erow['legend_long'])) { $grow['legend_long'] = $erow['legend_long']; }
+        $graphrows[] = $grow;
+      }
+    }
+
+    if (isset($gconf['special']) && count($gconf['special'])) {
+      foreach ($gconf['special'] as $crow) {
+        $srow = array();
+        $srow['sType'] = isset($crow['sType'])?$crow['sType']:'COMMENT';
+        if ($grow['sType'] != 'COMMENT') {
+          // XXX: use line below and remove cf var once we have rrdtol 1.2
+          if ($this->rrd_version() >= '1.2') {
+            $srow['name'] = $crow['name'].(isset($crow['cf'])?'_'.$crow['cf']:'');
+          }
+          else {
+            $srow['name'] = $crow['name'];
+            $srow['cf'] = isset($crow['cf'])?$crow['cf']:'AVERAGE';
+          }
+          if (isset($crow['cf'])) {
+            if ($this->rrd_version() >= '1.2') {
+              $graphrows[] = array('dType'=>'VDEF', 'name'=>$srow['name'].'_'.$crow['cf'],
+                                   'rpn_expr'=>$srow['name'].','.$crow['cf']);
+            }
+          }
+          elseif (isset($crow['rpn_expr'])) {
+            if ($this->rrd_version() >= '1.2') {
+              $graphrows[] = array('dType'=>'VDEF', 'name'=>$srow['name'], 'rpn_expr'=>$crow['rpn_expr']);
+            }
+          }
+        }
+        $srow['text'] = isset($crow['text'])?$crow['text']:'';
+        $specialrows[] = $srow;
+      }
+    }
+    else {
+      $td = $this->mod_textdomain;
+      foreach ($graphrows as $grow) {
+        if (isset($grow['gType']) && strlen($grow['gType'])) {
+          $textprefix = isset($grow['desc'])?$grow['desc']:(isset($grow['legend'])?$grow['legend']:$grow['name']);
+          if ($this->rrd_version() >= '1.2') {
+            $graphrows[] = array('dType'=>'VDEF', 'name'=>'_'.$grow['name'].'__max', 'rpn_expr'=>$grow['name'].',MAXIMUM');
+            $specialrows[] = array('sType'=>'PRINT', 'name'=>'_'.$grow['name'].'__max',
+                                   'text'=>$textprefix.'|'.dgettext($td, 'Maximum').'|%.2lf%s');
+            $graphrows[] = array('dType'=>'VDEF', 'name'=>'_'.$grow['name'].'__avg', 'rpn_expr'=>$grow['name'].',AVERAGE');
+            $specialrows[] = array('sType'=>'PRINT', 'name'=>'_'.$grow['name'].'__avg',
+                                   'text'=>$textprefix.'|'.dgettext($td, 'Average').'|%.2lf%s');
+            $graphrows[] = array('dType'=>'VDEF', 'name'=>'_'.$grow['name'].'__last', 'rpn_expr'=>$grow['name'].',LAST');
+            $specialrows[] = array('sType'=>'PRINT', 'name'=>'_'.$grow['name'].'__last',
+                                   'text'=>$textprefix.'|'.dgettext($td, 'Current').'|%.2lf%s');
+          }
+          else {
+            $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'MAX',
+                                   'text'=>$textprefix.'|'.dgettext($td, 'Maximum').'|%.2lf%s');
+            $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'AVERAGE',
+                                   'text'=>$textprefix.'|'.dgettext($td, 'Average').'|%.2lf%s');
+            $specialrows[] = array('sType'=>'PRINT', 'name'=>$grow['name'], 'cf'=>'LAST',
+                                   'text'=>$textprefix.'|'.dgettext($td, 'Current').'|%.2lf%s');
+          }
+        }
+      }
+    }
+
+    $endtime = isset($gconf['time_end'])?$gconf['time_end']:(is_numeric($this->last_update())?$this->last_update():time());
+    $gOpts = ' --start '.($endtime-$duration).' --end '.$endtime.' --step '.$slice;
+    if (isset($gconf['label_top'])) { $gOpts .= ' --title '.$this->text_quote($gconf['label_top']); }
+    if (isset($gconf['label_y'])) { $gOpts .= ' --vertical-label '.$this->text_quote($gconf['label_y']); }
+    if (isset($gconf['width'])) { $gOpts .= ' --width '.$gconf['width']; }
+    if (isset($gconf['height'])) { $gOpts .= ' --height '.$gconf['height'];
+      if (($gconf['height'] <= 32) && isset($gconf['thumb']) && ($gconf['thumb'])) { $gOpts .= ' --only-graph'; }
+    }
+    if (!isset($gconf['show_legend']) || (!$gconf['show_legend'])) { $gOpts .= ' --no-legend'; }
+    if (isset($gconf['logarithmic']) && $gconf['logarithmic']) { $gOpts .= ' --logarithmic'; }
+    if (isset($gconf['min_y'])) { $gOpts .= ' --lower-limit '.$gconf['min_y']; }
+    if (isset($gconf['max_y'])) { $gOpts .= ' --upper-limit '.$gconf['max_y']; }
+    if (isset($gconf['fix_scale_y']) && $gconf['fix_scale_y']) { $gOpts .= ' --rigid'; }
+    if (isset($gconf['grid_x'])) { $gOpts .= ' --x-grid '.$gconf['grid_x']; }
+    if (isset($gconf['grid_y'])) { $gOpts .= ' --y-grid '.$gconf['grid_y']; }
+    if (isset($gconf['gridfit']) && (!$gconf['gridfit'])) { $gOpts .= ' --no-gridfit'; }
+    if (isset($gconf['calc_scale_y']) && $gconf['calc_scale_y']) { $gOpts .= ' --alt-autoscale'; }
+    if (isset($gconf['calc_max_y']) && $gconf['calc_max_y']) { $gOpts .= ' --alt-autoscale-max'; }
+    if (isset($gconf['units_exponent'])) { $gOpts .= ' --units-exponent '.$gconf['units_exponent']; }
+    if (isset($gconf['units_length'])) { $gOpts .= ' --units-length '.$gconf['units_length']; }
+    if (($this->rrd_version() < '1.2') || !count($specialrows)) {
+      // lazy graphics omit all print reporting in RRDtool 1.2!
+      // --> so don't use them there when we want to print stuff
+      if (!isset($gconf['force_recreate']) || (!$gconf['force_recreate'])) { $gOpts .= ' --lazy'; }
+    }
+    if (isset($gconf['force_color']) && is_array($gconf['force_color'])) {
+      foreach ($gconf['force_color'] as $ctag=>$cval) { $gOpts .= ' --color '.$ctag.$cval; }
+    }
+    if (isset($gconf['force_font']) && is_array($gconf['force_font'])) {
+      foreach ($gconf['force_font'] as $ctag=>$cval) { $gOpts .= ' --font '.$ctag.$cval; }
+    }
+    if (isset($gconf['units_binary']) && $gconf['units_binary']) { $gOpts .= ' --base 1024'; }
+
+    foreach ($graphrows as $grow) {
+      if (isset($grow['dType']) && strlen($grow['dType'])) {
+        $gDefs .= ' '.$grow['dType'].':'.$grow['name'].'=';
+        if ($grow['dType'] == 'DEF') {
+          $gDefs .= isset($grow['dsfile'])?$grow['dsfile']:$this->rrd_file;
+          $gDefs .= ':'.$grow['dsname'].':'.$grow['cf'];
+        }
+        else { $gDefs .= $grow['rpn_expr']; }
+      }
+      if (isset($grow['gType']) && strlen($grow['gType'])) {
+        // XXX: change from STACK type to STACK flag once we have rrdtool 1.2
+        if ($this->rrd_version() < '1.2') {
+          // rrdtool 1.0 only know STACK type
+          if (isset($grow['stack']) && $grow['stack']) { $grow['gType'] = 'STACK'; }
+        }
+        $gGraphs .= ' '.$grow['gType'].':'.$grow['name'].$grow['color'];
+        if (isset($grow['legend'])) { $gGraphs .= ':'.$this->text_quote($grow['legend']); }
+        if ($this->rrd_version() >= '1.2') {
+          // rrdtool 1.2 and above have STACK flag
+          if (isset($grow['stack']) && $grow['stack']) { $gGraphs .= ':STACK'; }
+        }
+      }
+    }
+
+    foreach ($specialrows as $srow) {
+      $addSpecial .= ' '.$srow['sType'];
+      if ($this->rrd_version() >= '1.2') {
+        $addSpecial .= (($srow['sType']!='COMMENT')?':'.$srow['name']:'');
+      }
+      else {
+        $addSpecial .= (($srow['sType']!='COMMENT')?':'.$srow['name'].':'.$srow['cf']:'');
+      }
+      $addSpecial .= ':'.$this->text_quote($srow['text']);
+    }
+
+    $graph_cmd = 'rrdtool 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 (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>';
+    }
+
+    $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'; }
+
+    $num_rows = is_numeric($pconf['num_rows'])?$pconf['num_rows']:2;
+    $num_cols = ceil(count($stats)/$num_rows);
+
+    $out .= '<table class="overview">'."\n";
+    for ($col = 0; $col < $num_cols; $col++) {
+      $out .= '<tr>'."\n";
+      for ($row = 0; $row < $num_rows; $row++) {
+        $idx = $col * $num_rows + $row;
+        $out .= '<td>'."\n";
+        if ($idx < count($stats)) {
+          @list($sname, $s_psub) = explode('|', $stats[$idx]['name'], 2);
+          $s_psname = 'page'.(isset($s_psub)?'.'.$s_psub:'');
+          $g_sub = @$this->config_all[$sname][$s_psname]['graph_sub'];
+
+          if (isset($this->config_all[$sname][$s_psname]['title_page'])) {
+            $s_ptitle = $this->config_all[$sname][$s_psname]['title_page'];
+          }
+          elseif (isset($this->config_all[$sname]['page']['title_page'])) {
+            $s_ptitle = $this->config_all[$sname]['page']['title_page'];
+          }
+          else {
+            $s_ptitle = isset($s_psub)
+                        ?sprintf(dgettext($td, '%s (%s) statistics'), $sname, $s_psub)
+                        :sprintf(dgettext($td, '%s statistics'), $sname);
+          }
+          if (!isset($pconf['hide_titles']) || !$pconf['hide_titles']) {
+            $out .= '<h2>'.$s_ptitle.'</h2>'."\n";
+          }
+
+          $s_rrd = new rrdstat($this->config_all, $sname);
+          if (in_array($s_rrd->status, array('ok','readonly','graphonly'))) {
+            $tframe = isset($pconf['graph_timeframe'])?$pconf['graph_timeframe']:'day';
+            $gmeta = $s_rrd->graph_plus($tframe, $g_sub);
+            if (isset($pconf['graph_url'])) {
+              $gURL = $pconf['graph_url'];
+              $gURL = str_replace('%f', basename($gmeta['filename']), $gURL);
+              $gURL = str_replace('%p', $gmeta['filename'], $gURL);
+              if (substr($gURL, -1) == '/') { $gURL .= $gmeta['filename']; }
+            }
+            else {
+              $gURL = $gmeta['filename'];
+            }
+            $sURL = str_replace('%i', $sname, $sURL_base);
+            $sURL = str_replace('%a', isset($s_psub)?$sURL_add:'', $sURL);
+            $sURL = str_replace('%s', isset($s_psub)?$s_psub:'', $sURL);
+            $out .= '<a href="'.$sURL.'">';
+            $out .= '<img src="'.$gURL.'"';
+            $out .= ' alt="'.$s_rrd->basename.(!is_null($g_sub)?' - '.$g_sub:'').' - '.$tframe.'" class="rrdgraph"';
+            if (isset($gmeta['width']) && isset($gmeta['height'])) {
+              $out .= ' style="width:'.$gmeta['width'].'px;height:'.$gmeta['height'].'px;"';
+            }
+            $out .= '></a>'."\n";
+          }
+          else {
+            $out .= sprintf(dgettext($td, 'RRD error: status is "%s"'), $s_rrd->status)."\n";
+          }
+        }
+        else {
+          $out .= '&nbsp;';
+        }
+        $out .= '</td>'."\n";
+      }
+      $out .= '</tr>'."\n";
+    }
+    $out .= '</table>'."\n";
+
+    $out .= $this->h_page_footer();
+    $out .= '</body></html>'."\n";
+  return $out;
+  }
+
+  private function page_simple($pconf, $graph_extras = null) {
+    // create a simple (MRTG-like) HTML page and return it in a string
+    $td = $this->mod_textdomain;
+
+    $ptitle = isset($pconf['title_page'])?$pconf['title_page']:sprintf(dgettext($td, '%s - RRD statistics'),$this->basename);
+    $gtitle = array();
+    $gtitle['day'] = isset($pconf['title_day'])?$pconf['title_day']:dgettext($td, 'Day overview (scaling 5 minutes)');
+    $gtitle['week'] = isset($pconf['title_week'])?$pconf['title_week']:dgettext($td, 'Week overview (scaling 30 minutes)');
+    $gtitle['month'] = isset($pconf['title_month'])?$pconf['title_month']:dgettext($td, 'Month overview (scaling 2 hours)');
+    $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 .= '<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; }'."\n";
+      $out .= '.gdata, .gvar, .ginfo { font-size: 0.75em; margin: 0.5em 0; }'."\n";
+      $out .= 'table.gdata, table.legend  { border: 1px solid gray; border-collapse: collapse; }'."\n";
+      $out .= 'table.gdata td, table.gdata th, '."\n";
+      $out .= 'table.legend td, table.legend th { border: 1px solid gray; padding: 0.1em 0.2em; }'."\n";
+      $out .= 'div.legend { font-size: 0.75em; margin: 0.5em 0; }'."\n";
+      $out .= 'div.legend p { margin: 0; }'."\n";
+      $out .= '.footer { font-size: 0.75em; margin: 0.5em 0; }'."\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";
+    }
+    if (!isset($pconf['show_update']) || $pconf['show_update']) {
+      $out .= '<p class="last_up">';
+      if (is_null($this->last_update())) { $up_time = dgettext($td, 'unknown'); }
+      elseif (class_exists('baseutils')) { $up_time = baseutils::dateFormat($this->last_update(), 'short'); }
+      else { $up_time = date('Y-m-d H:i:s', $this->last_update()); }
+      $out .= sprintf(dgettext($td, 'Last Update: %s'), $up_time);
+      $out .= '</p>'."\n";
+    }
+
+    $g_sub = isset($pconf['graph_sub'])?$pconf['graph_sub']:null;
+    if (in_array($this->status, array('ok','readonly','graphonly'))) {
+      foreach (array('day','week','month','year') as $tframe) {
+        $gmeta = $this->graph_plus($tframe, $g_sub, $graph_extras);
+        if (isset($pconf['graph_url'])) {
+          $gURL = $pconf['graph_url'];
+          $gURL = str_replace('%f', basename($gmeta['filename']), $gURL);
+          $gURL = str_replace('%p', $gmeta['filename'], $gURL);
+          if (substr($gURL, -1) == '/') { $gURL .= $gmeta['filename']; }
+        }
+        else {
+          $gURL = $gmeta['filename'];
+        }
+        $out .= '<div class="'.$tframe.'">'."\n";
+        if (0) {
+          // debug output
+          ob_start();
+          print_r($gmeta);
+          $buffer = ob_get_contents();
+          ob_end_clean();
+          $out .= '<p>'.nl2br($buffer).'</p>';
+        }
+        $out .= '<h2>'.$gtitle[$tframe].'</h2>'."\n";
+        $out .= '<img src="'.$gURL.'"';
+        $out .= ' alt="'.$this->basename.(!is_null($g_sub)?' - '.$g_sub:'').' - '.$tframe.'" class="rrdgraph"';
+        if (isset($gmeta['width']) && isset($gmeta['height'])) {
+          $out .= ' style="width:'.$gmeta['width'].'px;height:'.$gmeta['height'].'px;"';
+        }
+        $out .= '>'."\n";
+        $colorize_data = (isset($pconf['data_colorize']) && $pconf['data_colorize']) ||
+                         (!isset($pconf['data_colorize']) && $gmeta['default_colorize']);
+        if (isset($gmeta['data']) && count($gmeta['data'])) {
+          $out .= '<table class="gdata">'."\n";
+          foreach ($gmeta['data'] as $field=>$gdata) {
+            $out .= '<tr><th';
+            if ($colorize_data && isset($gmeta['legend'][$field])) {
+              $out .= ' style="color:'.$gmeta['legend'][$field]['color'].';';
+              if (strlen($gmeta['legend'][$field]['color_bg'])) {
+                $out .= 'background-color:'.$gmeta['legend'][$field]['color_bg'].';';
+              }
+              $out .= '"';
+            }
+            $out .= '>'.$field.'</th>';
+            foreach ($gdata as $gkey=>$gval) {
+              $out .= '<td><span class="gkey">'.$gkey.': </span>'.$gval.'</td>';
+            }
+            $out .= '</tr>'."\n";
+          }
+          $out .= '</table>'."\n";
+        }
+        if (isset($gmeta['var']) && count($gmeta['var'])) {
+          foreach ($gmeta['var'] as $gkey=>$gval) {
+            $out .= '<p class="gvar"><span class="gkey">'.$gkey.': </span>'.$gval.'</p>'."\n";
+          }
+        }
+        if (isset($gmeta['info']) && count($gmeta['info'])) {
+          foreach ($gmeta['info'] as $gval) {
+            $out .= '<p class="ginfo">'.$gval.'</p>'."\n";
+          }
+        }
+        $out .= '</div>'."\n";
+      }
+      if ($gmeta['legends_long'] && (!isset($pconf['show_legend']) || $pconf['show_legend'])) {
+        $out .= '<div class="legend">'."\n";
+        $out .= '<p>'.$ltitle.'</p>'."\n";
+        $out .= '<table class="legend">'."\n";
+        foreach ($gmeta['legend'] as $field=>$legend) {
+          if (strlen($legend['desc_long'])) {
+            $out .= '<tr><th';
+            if ($colorize_data && isset($gmeta['legend'][$field])) {
+              $out .= ' style="color:'.$gmeta['legend'][$field]['color'].';';
+              if (strlen($gmeta['legend'][$field]['color_bg'])) {
+                $out .= 'background-color:'.$gmeta['legend'][$field]['color_bg'].';';
+              }
+              $out .= '"';
+            }
+            $out .= '>'.$field.'</th>';
+            $out .= '<td>'.$legend['desc_long'].'</td>';
+            $out .= '</tr>'."\n";
+          }
+        }
+        $out .= '</table>'."\n";
+        $out .= '</div>'."\n";
+      }
+    }
+    else {
+      $out .= sprintf(dgettext($td, 'RRD error: status is "%s"'), $this->status)."\n";
+    }
+
+    $out .= $this->h_page_footer();
+    $out .= '</body></html>'."\n";
+  return $out;
+  }
+
+  private function h_page_statsArray($pconf) {
+    // return array of stats to list on a page
+    $stats = array();
+    $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); }
+        else { $snames[] = $iid; }
+      }
+    }
+    if (!isset($pconf['scan_config']) || $pconf['scan_config']) {
+      foreach ($this->config_all as $iname=>$rinfo) {
+        if (($iname != '*') && !(isset($rinfo['hidden']) && $rinfo['hidden']) &&
+            !(in_array($iname, $snames)) && !(in_array($iname, $s_exclude))) {
+          $snames[] = $iname;
+        }
+      }
+    }
+    foreach ($snames as $iname) {
+      $newstat = array('name'=>$iname);
+      $sfiles[] = isset($this->config_all[$iname]['file'])?$this->config_all[$iname]['file']:$iname.'.rrd';
+      if (is_array($this->config_all[$iname])) {
+        foreach ($this->config_all[$iname] as $key=>$val) {
+          if (substr($key, 0, 5) == 'page.') { $newstat['sub'][] = substr($key, 5); }
+        }
+      }
+      $stats[] = $newstat;
+    }
+    if (isset($pconf['scan_files']) && $pconf['scan_files']) {
+      $rrdfiles = glob('*.rrd');
+      foreach ($rrdfiles as $rrdfile) {
+        $iname = (substr($rrdfile, -4) == '.rrd')?substr($rrdfile, 0, -4):$rrdfile;
+        if (!in_array($rrdfile, $sfiles) && !(in_array($iname, $s_exclude))) {
+          $stats[] = array('name'=>$iname, 'class'=>'scanfile');
+        }
+      }
+    }
+  return $stats;
+  }
+
+  private function h_page_footer() {
+    // return generic page footer
+    $out = '<p class="footer">';
+    $out .= sprintf(dgettext($this->mod_textdomain, 'Statistics created with %s using a library created by %s.'),
+                    '<a href="http://oss.oetiker.ch/rrdtool/">RRDtool</a>',
+                    '<a href="http://www.kairo.at/">KaiRo.at</a>');
+    $out .= '</p>'."\n";
+  return $out;
+  }
+
+  private function text_quote($text) {
+    $trans = array('"' => '\"', ':' => '\:');
+    $qtext = '"'.strtr($text, $trans).'"';
+  return $qtext;
+  }
+}
+?>
diff --git a/include/classes/useragent.php-class b/include/classes/useragent.php-class
new file mode 100755 (executable)
index 0000000..49184a9
--- /dev/null
@@ -0,0 +1,1155 @@
+<?php
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is KaiRo's userAgent detection.
+ *
+ * The Initial Developer of the Original Code is
+ * KaiRo - Robert Kaiser.
+ * Portions created by the Initial Developer are Copyright (C) 2003-2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Robert Kaiser <kairo@kairo.at>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+class userAgent {
+  // userAgent PHP class
+  // get user agent and tell us what Browser is accessing
+  //
+  // function __construct([$ua_string])
+  //   CONSTRUCTOR; reads UA string (or takes the optional given UA string) and gets info from that into our variables.
+  //
+  // private $uastring
+  //   the plain User Agent string
+  // private $brand
+  //   the User Agent brand name
+  // private $version
+  //   the User Agent version
+  // private $bot
+  //   bool: true if this agent is a bot
+  // private $uadata
+  //   array of static user agent data (static vars in functions are set for all objects of this class!)
+  //
+  // public function getBrand()
+  //   returns the User Agent Brand Name
+  //
+  // public function getVersion()
+  //   returns the User Agent version
+  //
+  // public function getAcceptLanguages()
+  //   returns an associated array with the accepted languages of this UA
+  //     keys are language codes, values are q factors (weights)
+  //
+  // public function getUAString()
+  //   returns the full User Agent string
+  //
+  // public function getEngine()
+  //   returns a string telling the detected rendering engine, null if we can't detect
+  //     one of gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|unknown
+  //
+  // public function hasEngine($rnd_engine)
+  //   returns true if the given rendering engine was detected
+  //
+  // public function getEngineVersion()
+  //   returns a the version number for the rendering engine
+  //     this may be the same as getVersion() for many engines, or null if we don't know
+  //
+  // public function getOS()
+  //   returns a string telling the detected operating system, null if we can't detect
+  //     might be very verbose, uses no abbreviations for most names
+  //
+  // public function getPlatform()
+  //   returns a string telling the detected OS platform, null if we can't detect
+  //     one of windows|linux|mac|solaris|unknown
+  //
+  // public function getLanguage() {
+  //   returns a string telling the detected browser UI language, null if we can't detect
+  //     should be an ISO code
+  //
+  // public function isBot()
+  //   returns true if User Agent seems to be a bot
+  //
+  // *** functions that only return useable info for some agents ***
+  //
+  // public function getGeckoDate()
+  //   returns the Gecko date for Gecko-based browsers, null for others
+  //
+  // public function getGeckoTime()
+  //   returns the Gecko build date/time as a unix epoch time number for Gecko-based browsers, null for others
+  //
+  // *** functions for compat to older versions of this class ***
+  //
+  // public function isns()
+  //   returns true if User Agent seems to be Netscape brand, false if not
+  // public function isns4()
+  //   returns true if User Agent seems to be Netscape Communicator 4.x, false if not
+  // public function isie()
+  //   returns true if User Agent seems to be a version of Internet Exploder, false if not
+  // public function geckobased()
+  //   returns true if User Agent seems to be a Gecko-based browser, false if not
+  // public function geckodate()
+  //   returns the Gecko date when it's a Gecko-based browser, 0 if not
+  // public function khtmlbased()
+  //   returns true if User Agent seems to be a KHTML-based browser, false if not
+
+  // collection of some known User Agent Strings:
+  // *** see testbed/ua_list_raw.txt ***
+  // *** see also http://www.pgts.com.au/pgtsj/pgtsj0208c.html ***
+
+  private $uastring;
+  private $brand;
+  private $version;
+  private $bot = false;
+  private $uadata = array();
+
+  function __construct($ua_string = '') {
+    // *** constructor ***
+    if (strlen($ua_string)) {
+      $this->uastring = $ua_string;
+    }
+    else {
+      // read raw UA string
+      $this->uastring = $_SERVER['HTTP_USER_AGENT'];
+    }
+
+    // get UA brand and version
+    $this->brand = 'Unknown'; $this->version = null;
+    // find reasonable defaults
+    if (preg_match('|([0-9a-zA-Z\.:()_ -]+)/(\d[0-9a-zA-Z\._+-]*)|', $this->uastring, $regs)) {
+      $this->brand = trim($regs[1]);
+      $this->version = $regs[2];
+    }
+    elseif (preg_match('|^([a-zA-Z\._ -]+)[_ -][vV]?(\d[0-9a-zA-Z\.+]*)|', $this->uastring, $regs)) {
+      $this->brand = trim($regs[1]);
+      $this->version = $regs[2];
+    }
+    elseif (preg_match('|^([0-9a-zA-Z\._ -]+)|', $this->uastring, $regs)) {
+      $this->brand = trim($regs[1]);
+      $this->version = null;
+    }
+    $this->bot = (strpos(strtolower($this->brand), 'bot') !== false)
+                 || (strpos(strtolower($this->brand), 'crawler') !== false)
+                 || (strpos(strtolower($this->brand), 'spider') !== false)
+                 || (strpos(strtolower($this->brand), 'search') !== false)
+                 || (strpos(strtolower($this->brand), 'seek') !== false);
+
+    // search for any real and/or special UAs
+    if (preg_match('|Netscape6/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Netscape';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Netscape/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Netscape';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Navigator/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Netscape';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Chimera/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Chimera';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Camino/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Camino';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Phoenix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Phoenix';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Mozilla Firebird/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Mozilla Firebird';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Flock/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Flock';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|SeaMonkey/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'SeaMonkey';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Iceape/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'IceApe';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Iceweasel/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'IceWeasel';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Minefield/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'Minefield';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Minimo/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'Minimo';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Galeon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Galeon';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Epiphany/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Epiphany';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|K-Meleon/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'K-Meleon';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|AOL[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'AOL';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Tablet browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'microB';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Opera\/([^\(]+) \(.*; Opera Mini; |', $this->uastring, $regs)) {
+      $this->brand = 'Opera Mini';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('/Opera\/[^\(]+ \(.*; Opera Mini\/([^;]+); /i', $this->uastring, $regs)) {
+      $this->brand = 'Opera Mini';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Opera[ /]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Opera';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|OmniWeb/([0-9a-zA-Z\.+-]+)|', $this->uastring, $regs)) {
+      $this->brand = 'OmniWeb';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Konqueror/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Konqueror';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Shiira/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Shiira';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Safari/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Safari';
+      if (preg_match('|Version/([0-9a-zA-Z\.+]+)|', $this->uastring, $vregs)) {
+        $this->version = $vregs[1];
+      }
+      else {
+        $this->version = '('.$regs[1].')';
+      }
+      $this->bot = false;
+    }
+    elseif (preg_match('|AppleWebKit/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'AppleWebKit';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Firefox/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Firefox';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|rv:([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
+            strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
+      $this->brand = 'Mozilla';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|m([0-9]+)\)|', $this->uastring, $regs) &&
+            strstr($this->uastring, "Mozilla/") && strstr($this->uastring, "Gecko/")) {
+      $this->brand = 'Mozilla';
+      $this->version = 'M'.$regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|MSFrontPage/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Microsoft FrontPage';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|iCab[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'iCab';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|IBrowse[/ ]([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'IBrowse';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|ICEbrowser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'ICEbrowser';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|ICE Browser/v([0-9a-zA-Z\._+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'ICEbrowser';
+      $this->version = str_replace('_', '.', $regs[1]);
+      $this->bot = false;
+    }
+    elseif (preg_match('|NetPositive/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'NetPositive';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|WebPro/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'WebPro (Novarra)';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|; OffByOne;|', $this->uastring, $regs)) {
+      $this->brand = 'Off By One';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|PSP \(PlayStation Portable\); ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'PlayStation Portable';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|PLAYSTATION 3; ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'PlayStation 3';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|NetFront/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'NetFront';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|UP.Browser/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'UP.Browser';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|UP.Link/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'UP.Link';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|AU-MIC-([0-9A-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Obigo';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Nokia([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Nokia';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|SonyEricsson([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'SonyEricsson';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|SIE-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Siemens';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|MOT-([0-9a-zA-Z]+/[0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Motorola';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|IXI/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'IXI';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|IBM-WebExplorer-DLL/v([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'WebExplorer';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|ELinks \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
+      $this->brand = 'ELinks';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Links \(([0-9a-zA-Z\.+]+);|', $this->uastring, $regs)) {
+      $this->brand = 'Links';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|WinHttp.WinHttpRequest.([0-9\.]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'WinHttpRequest';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|alpha[/ ]06; AmigaOS|i', $this->uastring, $regs)) {
+      $this->brand = 'Alpha 06';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|; arexx[\);]|i', $this->uastring, $regs)) {
+      $this->brand = 'ARexx';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|; Voyager; AmigaOS[\);]|i', $this->uastring, $regs)) {
+      $this->brand = 'AmigaVoyager';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|AWEB ([0-9a-zA-Z\.+ ]+)|', $this->uastring, $regs)) {
+      $this->brand = 'AWEB';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|X ([0-9a-zA-Z\.+ ]+); Commodore 64|', $this->uastring, $regs)) {
+      $this->brand = 'X';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|DB Browse ([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'DB Browse';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|ZyBorg/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'ZyBorg';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|Ask Jeeves/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Ask Jeeves';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|heritrix/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Heritrix';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|([0-9a-zA-Z\.+]+bot)/([0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = $regs[1];
+      $this->version = $regs[2];
+      $this->bot = true;
+    }
+    elseif (preg_match('|VoilaBot ((BETA )?[0-9a-zA-Z\.+]+)|i', $this->uastring, $regs)) {
+      $this->brand = 'VoilaBot';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|Slurp|', $this->uastring, $regs)) {
+      $this->brand = 'Slurp';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Check&amp;Get ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Check&Get';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|WebCapture ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'WebCapture';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|WebMon ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'WebMon';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|Powermarks/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Powermarks';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|Gulper Web Bot ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Gulper Web Bot';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|HTTrack ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'HTTrack';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|Twiceler-([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Twiceler';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|Microsoft URL Control - ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Microsoft URL Control';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|([0-9a-zA-Z\.+]+)_AC-Plug|', $this->uastring, $regs)) {
+      $this->brand = 'AC-Plug';
+      $this->version = $regs[1];
+      $this->bot = true;
+    }
+    elseif (preg_match('|^Internet Explorer 5.5|', $this->uastring)) {
+      $this->brand = 'Unknown bot (IE5.5)';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|^Mozilla[\s ]*$|', $this->uastring)) {
+      $this->brand = 'Unknown bot (Mozilla)';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|http://www.livedir.net|', $this->uastring, $regs)) {
+      $this->brand = 'livedir.net';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|WebClipping.com|', $this->uastring, $regs)) {
+      $this->brand = 'WebClipping.com';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|http://www.almaden.ibm.com/cs/crawler|', $this->uastring)) {
+      $this->brand = 'almaden crawler';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|B-l-i-t-z-B-O-T|', $this->uastring) ||
+            preg_match('|B l i t z B O T @ t r i c u s . n e t|', $this->uastring)) {
+      $this->brand = 'BlitzBOT';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Really Gmane.org\'s favicon grabber|', $this->uastring)) {
+      $this->brand = 'Really Gmane.org\'s favicon grabber';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Girafabot|', $this->uastring)) {
+      $this->brand = 'Girafabot';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Arachmo|', $this->uastring)) {
+      $this->brand = 'Arachmo';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|OsO|', $this->uastring)) {
+      $this->brand = 'OsO';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Yoono|', $this->uastring)) {
+      $this->brand = 'Yoono';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|efp@gmx.net|', $this->uastring)) {
+      $this->brand = 'efp';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Baiduspider|i', $this->uastring)) {
+      $this->brand = 'BaiDuSpider';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Indy Library|', $this->uastring)) {
+      $this->brand = 'Indy Library';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Linkman|', $this->uastring)) {
+      $this->brand = 'Linkman';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Sage|', $this->uastring, $regs)) {
+      $this->brand = 'Sage';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|Google Desktop|', $this->uastring)) {
+      $this->brand = 'Google Desktop';
+      $this->version = null;
+      $this->bot = true;
+    }
+    elseif (preg_match('|^Firefly|', $this->uastring)) {
+      // comes here with correct value but would be detected as MSIE
+    }
+    elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
+      $this->brand = 'Steganos Internet Anonym';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Steganos Internet Anonym([0-9a-zA-Z\. +]*)|', $this->uastring, $regs)) {
+      $this->brand = 'Steganos Internet Anonym';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|BorderManager ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'BorderManager';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|WebWasher ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'WebWasher';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|SaferSurf|', $this->uastring, $regs)) {
+      $this->brand = 'SaferSurf';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|Avant Browser[^/]|', $this->uastring)) {
+      $this->brand = 'Avant Browser';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|Browser[^/]+(http://www.avantbrowser.com)|', $this->uastring)) {
+      $this->brand = 'Avant Browser';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|Maxthon|', $this->uastring)) {
+      $this->brand = 'Maxthon';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|MyIE2|', $this->uastring)) {
+      $this->brand = 'MyIE2';
+      $this->version = null;
+      $this->bot = false;
+    }
+    elseif (preg_match('|Crazy Browser ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Crazy Browser';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|AvantGo ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'AvantGo';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|MSN ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'MSN';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|America Online Browser [0-9a-zA-Z\.+]+; rev([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'AOL Browser';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|MS FrontPage ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Microsoft FrontPage';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Microsoft Internet Explorer/4.0b1|', $this->uastring, $regs)) {
+      $this->brand = 'Microsoft Internet Explorer';
+      $this->version = '1.0';
+      $this->bot = false;
+    }
+    elseif (preg_match('|MSIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Microsoft Internet Explorer';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|MSPIE ([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = 'Microsoft Pocket Internet Explorer';
+      $this->version = $regs[1];
+      $this->bot = false;
+    }
+    elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs) &&
+            (strpos($this->uastring, 'compatible') === false) && (strpos($this->uastring, 'Gecko/') === false) &&
+            (intval($regs[1]) < 5)) {
+      $this->brand = 'Netscape';
+      $this->version = $regs[1];
+      if (intval($this->version) == 4) { $this->brand .= ' Communicator'; }
+      $this->bot = false;
+    }
+    elseif (preg_match('|Mozilla/([0-9a-zA-Z\.+]+)|', $this->uastring, $regs)) {
+      $this->brand = (strpos($this->uastring, 'compatible') !== false)?'Mozilla-compatible (unknown)':'Mozilla (unknown)';
+      $this->version = null;
+      $this->bot = false;
+    }
+
+    $botArray = array('Scooter','Spinne','Vagabondo','Firefly','Scrubby','NG','Pompos','Szukacz','Schmozilla','42_HAL',
+                      'NetResearchServer','LinkWalker','Zeus','W3C_Validator','ZyBorg','Ask Jeeves','ia_archiver',
+                      'PingALink Monitoring Services','IlTrovatore-Setaccio','Nutch','Mercator','search.ch',
+                      'appie','larbin','NutchCVS','Webchat','Mediapartners-Google','sitecheck.internetseer.com',
+                      'FavOrg','findlinks','DataCha0s','ichiro','Francis','','','','','');
+
+    if (in_array($this->brand, $botArray)) {
+      $this->bot = true;
+    }
+  }
+
+  public function getBrand() { return $this->brand; }
+  public function getVersion() { return $this->version; }
+
+  public function getAcceptLanguages() {
+    if (!isset($this->uadata['accept-languages'])) {
+      $headers = getAllHeaders();
+      $accLcomp = explode(',', $headers['Accept-Language']);
+      $accLang = array();
+      foreach ($accLcomp as $lcomp) {
+        if (strlen($lcomp)) {
+          $ldef = explode(';', $lcomp);
+          $accLang[$ldef[0]] = (float)((strpos(@$ldef[1],'q=')===0)?substr($ldef[1],2):1);
+        }
+      }
+      $this->uadata['accept-languages'] = $accLang;
+    }
+  return $this->uadata['accept-languages'];
+  }
+
+  public function getUAString() { return $this->uastring; }
+
+  public function getEngine() {
+    // return gecko|khtml|trident|tasman|nscp|presto|gzilla|gtkhtml|links|icestorm|netfront|unknown
+    if (!isset($this->uadata['engine'])) {
+      $this->uadata['engine'] = 'unknown';
+      $this->uadata['geckodate'] = null;
+      if (preg_match('|Gecko/([0-9]+)|', $this->uastring, $regs) && (strpos($this->brand, 'Opera') === false)) {
+        $this->uadata['engine'] = 'gecko';
+        $this->uadata['geckodate'] = $regs[1];
+      }
+      elseif ((strpos($this->brand, 'Internet Explorer') !== false) ||  (strpos($this->brand, 'FrontPage') !== false)) {
+        if ((strpos(strtolower($this->uastring), 'mac') !== false) && (intval($this->getVersion()) >= 5)) {
+          $this->uadata['engine'] = 'tasman';
+        }
+        else {
+          $this->uadata['engine'] = 'trident';
+        }
+      }
+      elseif ((strpos($this->brand, 'Konqueror') !== false) || (strpos($this->brand, 'Safari') !== false) ||
+              (strpos($this->brand, 'Shiira') !== false) ||
+              (strpos($this->brand, 'AppleWebKit') !== false) || (strpos($this->brand, 'OmniWeb') !== false)) {
+        $this->uadata['engine'] = 'khtml';
+      }
+      elseif (strpos($this->brand, 'Netscape') !== false) {
+        // non-Gecko Netscape browsers
+        if (intval($this->version) <= 4) {
+          $this->uadata['engine'] = 'nscp';
+        }
+        elseif (strpos($this->uastring, 'MSIE') !== false) {
+          $this->uadata['engine'] = 'trident';
+        }
+      }
+      elseif (strpos($this->brand, 'Opera') !== false) {
+        $this->uadata['engine'] = 'presto';
+      }
+      elseif (strpos($this->brand, 'Dillo') !== false) {
+        $this->uadata['engine'] = 'gzilla';
+      }
+      elseif ((strpos($this->brand, 'ELinks') !== false) || (strpos($this->brand, 'Links') !== false)) {
+        $this->uadata['engine'] = 'links';
+      }
+      elseif ((strpos($this->brand, 'ICEbrowser') !== false) || (strpos($this->brand, 'ICE Browser') !== false)) {
+        $this->uadata['engine'] = 'icestorm';
+      }
+      elseif ((strpos($this->brand, 'PlayStation') !== false) || (strpos($this->brand, 'NetFront') !== false)) {
+        $this->uadata['engine'] = 'netfront';
+      }
+      elseif ((strpos($this->brand, 'Avant') !== false) || (strpos($this->brand, 'Crazy Browser') !== false) ||
+              (strpos($this->brand, 'AOL') !== false) || (strpos($this->brand, 'MSN') !== false) ||
+              (strpos($this->brand, 'MyIE2') !== false) || (strpos($this->brand, 'Maxthon') !== false)) {
+        $this->uadata['engine'] = 'trident';
+      }
+      elseif (strpos($this->brand, 'Galeon') !== false) {
+        $this->uadata['engine'] = 'gecko';
+      }
+      elseif (strpos($this->brand, 'WebPro') !== false) {
+        $this->uadata['engine'] = 'nscp';
+      }
+    }
+  return $this->uadata['engine'];
+  }
+
+  public function hasEngine($rnd_engine) { return ($this->getEngine() == $rnd_engine); }
+
+  public function getEngineVersion() {
+    if (!isset($this->uadata['eng_version'])) {
+      $this->uadata['eng_version'] = null;
+      // getOS() should get the date for us
+      $this->getOS();
+    }
+  return $this->uadata['eng_version'];
+  }
+
+  public function getOS() {
+    if (!isset($this->uadata['os'])) {
+      $this->uadata['os'] = null;
+      if ($this->hasEngine('gecko')) {
+        if (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = (strpos($regs[3],'chrome://')===false)?$regs[3]:null;
+          $this->uadata['eng_version'] = $regs[4];
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); rv:([^\);]+)(; [^\)]+)?\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+          $this->uadata['eng_version'] = $regs[3];
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = $regs[3];
+          $this->uadata['eng_version'] = 'M'.$regs[4];
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); m([^\);]+)\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+          $this->uadata['eng_version'] = 'M'.$regs[3];
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = $regs[3];
+          $this->uadata['eng_version'] = null;
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); ([^;]+); rv:([^\);]+)\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+          $this->uadata['eng_version'] = $regs[3];
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); [^;]+; ([^\);]+)\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+          $this->uadata['eng_version'] = null;
+        }
+        elseif (preg_match('|Mozilla/5.0 Galeon/[^\(]+ \(([^;]+); ([^;]+);[^\)]+\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+          $this->uadata['eng_version'] = null;
+        }
+        elseif (preg_match('|Debian/|', $this->uastring, $regs)) {
+          $this->uadata['os'] = 'Debian Linux';
+          $this->uadata['lang'] = null;
+          $this->uadata['eng_version'] = null;
+        }
+      }
+      elseif ($this->hasEngine('trident') || $this->hasEngine('tasman')) {
+        if (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSP?IE ([^;]+)[^\)]*; ?((?:Mac|Win)[^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = (strpos($this->uastring,'MSPIE')!==false)?null:$regs[1];
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \(compatible *; MSIE ([^;]+)[^\)]*\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $regs[1];
+          $this->uadata['os'] = null;
+          $this->uadata['lang'] = null;
+        }
+        elseif (preg_match('/Microsoft Internet Explorer\/[^\s]+ \(((?:Mac|Win)[^;\)]+)\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = null;
+        }
+        elseif (preg_match('/Microsoft Pocket Internet Explorer\/[^\s]+/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = null;
+          $this->uadata['os'] = 'Windows CE';
+          $this->uadata['lang'] = null;
+        }
+      }
+      elseif ($this->hasEngine('khtml')) {
+        if (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^;]+); ([^;]+); ([^;]+); ([^\);]+)\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = strlen($regs[6])?$regs[6]:$regs[1];
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = $regs[5];
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; Konqueror\/([^;]+); ([^\);]+)[^\)]*\)(?: KHTML\/([0-9a-zA-Z\.+]+))?/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = strlen($regs[3])?$regs[3]:$regs[1];
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^;]+); ([^\);]+)\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = $regs[3];
+          $this->uadata['eng_version'] = null;
+        }
+        elseif (preg_match('|Mozilla/5.0 \(([^;]+); U; ([^\);]+)\)|', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+          $this->uadata['eng_version'] = null;
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; [^;]+; ([^\);]+)\)/i', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = null;
+          $this->uadata['eng_version'] = null;
+        }
+      }
+      elseif ($this->hasEngine('presto')) {
+        // Opera < 8
+        if (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+)[^\)]+\) +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;\)]+)[^\)]*\) Opera [^ ]+ +\[([a-z_-]+)\]/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+\) Opera [^ ]+ \[([a-z_-]+)\]/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+        // Opera mini
+        elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini; ([a-z_-]+); /i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = null;
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = $regs[3];
+        }
+        elseif (preg_match('/Opera\/([^\(]+) \((?:X11; )?([^;]+); Opera Mini\/[^;]+; ([a-z_-]+); /i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $regs[1];
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = $regs[3];
+        }
+        // Opera >= 8
+        elseif (preg_match('/Opera\/[^\(]+ \((?:X11; )?([^;]+); [^\)]+; ([a-z_-]+)\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \(compatible; MSIE [^;]+; (?:X11; )?([^;]+); ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\) Opera [^ ]+/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+        // Opera 9 Firefox-spoofing
+        elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+); rv:([^\);]+)\) Gecko\/\d+ Firefox\/[0-9a-zA-Z\.+]+ Opera [^ ]+/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $this->getVersion();
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+      }
+      elseif ($this->hasEngine('nscp')) {
+        if (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(X11; [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $regs[1];
+          $this->uadata['os'] = $regs[3];
+          $this->uadata['lang'] = $regs[2];
+        }
+        elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+) (?:\[([a-z_-]+)\][^\(]+)?\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $regs[1];
+          $this->uadata['os'] = $regs[3];
+          $this->uadata['lang'] = $regs[2];
+        }
+        elseif (preg_match('/Mozilla\/([0-9a-zA-Z\.+]+)[^\(]+\(([^;]+);[^\)]+\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $regs[1];
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+        }
+      }
+      elseif ($this->hasEngine('gzilla')) {
+        $this->uadata['eng_version'] = $this->getVersion();
+        $this->uadata['os'] = null;
+        $this->uadata['lang'] = null;
+      }
+      elseif ($this->hasEngine('links')) {
+        if (preg_match('/E?Links[^\(]+\([^;]+; ([^;]+)[^\)]+\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = null;
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = null;
+        }
+      }
+      elseif ($this->hasEngine('icestorm')) {
+        if (preg_match('/ICE Browser\/v?([0-9a-zA-Z\._+]+) \(Java [^;]+; ([^\)]+)\)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = str_replace('_', '.', $regs[1]);
+          $this->uadata['os'] = $regs[2];
+          $this->uadata['lang'] = null;
+        }
+        elseif (preg_match('/Mozilla\/[^\(]+ \((?:X11; )?([^;]+);.+; ([a-z_-]+)\).* ICEbrowser\/([0-9a-zA-Z\._+]+)/i', $this->uastring, $regs)) {
+          $this->uadata['eng_version'] = $regs[3];
+          $this->uadata['os'] = $regs[1];
+          $this->uadata['lang'] = $regs[2];
+        }
+      }
+      else {
+        $this->uadata['eng_version'] = null;
+        $this->uadata['lang'] = null;
+        if (preg_match('/AmigaOS/i', $this->uastring, $regs)) {
+          $this->uadata['os'] = 'AmigaOS';
+        }
+        if (preg_match('/Commodore 64/i', $this->uastring, $regs)) {
+          $this->uadata['os'] = 'Commodore 64';
+        }
+        elseif (preg_match('/curl\/[^\(]+\(([^\);]+)/i', $this->uastring, $regs)) {
+          $this->uadata['os'] = $regs[1];
+        }
+        elseif (preg_match('/NCSA[_ ]Mosaic\/[^\(]+\((?:.*;)?([^\);]+)/i', $this->uastring, $regs)) {
+          $this->uadata['os'] = trim($regs[1]);
+        }
+        elseif (preg_match('/iCab.*(Mac[^\);]+).*?\)/i', $this->uastring, $regs)) {
+          $this->uadata['os'] = trim($regs[1]);
+        }
+        elseif (preg_match('/SymbianOS\/([^ ]+)/i', $this->uastring, $regs)) {
+          $this->uadata['os'] = 'SymbianOS '.$regs[1];
+        }
+      }
+      if ($this->uadata['os'] == 'Win 9x 4.90') { $this->uadata['os'] = 'Windows ME'; }
+      elseif ($this->uadata['os'] == 'WinNT4.0') { $this->uadata['os'] = 'Windows NT 4.0'; }
+      elseif ($this->uadata['os'] == 'Windows NT 5.0') { $this->uadata['os'] = 'Windows 2000'; }
+      elseif ($this->uadata['os'] == 'Windows NT 5.1') { $this->uadata['os'] = 'Windows XP'; }
+      elseif ($this->uadata['os'] == 'Windows NT 5.2') { $this->uadata['os'] = 'Windows 2003'; }
+      elseif ($this->uadata['os'] == 'Windows NT 5.2 x64') { $this->uadata['os'] = 'Windows 2003 (64bit)'; }
+      elseif ($this->uadata['os'] == 'Windows NT 6.0') { $this->uadata['os'] = 'Windows Vista'; }
+      elseif ($this->uadata['os'] == 'Win95') { $this->uadata['os'] = 'Windows 95'; }
+      elseif ($this->uadata['os'] == 'Win98') { $this->uadata['os'] = 'Windows 98'; }
+      elseif ($this->uadata['os'] == 'WinNT') { $this->uadata['os'] = 'Windows NT'; }
+      elseif ($this->uadata['os'] == 'Win32') { $this->uadata['os'] = 'Windows (32bit)'; }
+      elseif ($this->uadata['os'] == 'Win64') { $this->uadata['os'] = 'Windows (64bit)'; }
+      elseif (preg_match('/Mac ?OS ?X/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS X'; }
+      elseif (preg_match('/Mac_P(ower|)PC/i',$this->uadata['os'])) { $this->uadata['os'] = 'MacOS'; }
+      elseif (strpos($this->uadata['os'], 'darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
+      elseif (strpos($this->uadata['os'], 'Darwin') !== false) { $this->uadata['os'] = 'MacOS X'; }
+      elseif (strpos($this->uadata['os'], 'apple') !== false) { $this->uadata['os'] = 'MacOS'; }
+      elseif (strpos($this->uadata['os'], 'Macintosh') !== false) { $this->uadata['os'] = 'MacOS'; }
+      elseif (strpos($this->uadata['os'], 'linux') !== false) { $this->uadata['os'] = 'Linux'; }
+      elseif (preg_match('/Symbian ?OS/i',$this->uadata['os'])) { $this->uadata['os'] = 'SymbianOS'; }
+
+      if (strpos($this->uadata['os'], 'Win') !== false) { $this->uadata['platform'] = 'Windows'; }
+      elseif (strpos($this->uadata['os'], 'Mac') !== false) { $this->uadata['platform'] = 'Macintosh'; }
+      elseif (strpos($this->uadata['os'], 'Linux') !== false) { $this->uadata['platform'] = 'Linux'; }
+      elseif (strpos($this->uadata['os'], 'Solaris') !== false) { $this->uadata['platform'] = 'Solaris'; }
+      elseif (strpos($this->uadata['os'], 'SunOS') !== false) { $this->uadata['platform'] = 'Solaris'; }
+      elseif (strpos($this->uadata['os'], 'BeOS') !== false) { $this->uadata['platform'] = 'BeOS'; }
+      elseif (strpos($this->uadata['os'], 'FreeBSD') !== false) { $this->uadata['platform'] = 'FreeBSD'; }
+      elseif (strpos($this->uadata['os'], 'OpenBSD') !== false) { $this->uadata['platform'] = 'OpenBSD'; }
+      elseif (strpos($this->uadata['os'], 'NetBSD') !== false) { $this->uadata['platform'] = 'NetBSD'; }
+      elseif (strpos($this->uadata['os'], 'AIX') !== false) { $this->uadata['platform'] = 'AIX'; }
+      elseif (strpos($this->uadata['os'], 'IRIX') !== false) { $this->uadata['platform'] = 'IRIX'; }
+      elseif (strpos($this->uadata['os'], 'HP-UX') !== false) { $this->uadata['platform'] = 'HP-UX'; }
+      elseif (strpos($this->uadata['os'], 'AmigaOS') !== false) { $this->uadata['platform'] = 'Amiga'; }
+      elseif (strpos($this->uadata['os'], 'Commodore 64') !== false) { $this->uadata['platform'] = 'C64'; }
+      elseif (strpos($this->uadata['os'], 'OpenVMS') !== false) { $this->uadata['platform'] = 'OpenVMS'; }
+      elseif (strpos($this->uadata['os'], 'Warp') !== false) { $this->uadata['platform'] = 'OS/2'; }
+      elseif (strpos($this->uadata['os'], 'SymbianOS') !== false) { $this->uadata['platform'] = 'SymbianOS'; }
+      elseif (strpos($this->uadata['os'], 'CYGWIN') !== false) { $this->uadata['platform'] = 'Windows'; }
+      else { $this->uadata['platform'] = $this->uadata['os']; }
+
+      $this->uadata['lang'] = str_replace('_', '-', $this->uadata['lang']);
+    }
+  return $this->uadata['os'];
+  }
+
+  public function getPlatform() {
+    if (!isset($this->uadata['platform'])) {
+      $this->uadata['platform'] = null;
+      // getOS() should get the date for us
+      $this->getOS();
+    }
+  return $this->uadata['platform'];
+  }
+
+  public function getLanguage() {
+    if (!isset($this->uadata['lang'])) {
+      $this->uadata['lang'] = null;
+      // getOS() should get the date for us
+      $this->getOS();
+    }
+  return $this->uadata['lang'];
+  }
+
+  public function getGeckoDate() {
+    if (!isset($this->uadata['geckodate'])) {
+      $this->uadata['geckodate'] = null;
+      // getEngine() should get the date for us
+      $this->getEngine();
+    }
+  return $this->uadata['geckodate'];
+  }
+
+  public function getGeckoTime() {
+    if (!isset($this->uadata['geckotime'])) {
+      $this->uadata['geckotime'] = null;
+      if (!is_null($this->getGeckoDate())) {
+        $use_time = (strlen($this->getGeckoDate()) > 8);
+        $gd_str = substr($this->getGeckoDate(),0,4).'-'.substr($this->getGeckoDate(),4,2).'-'.substr($this->getGeckoDate(),6,2);
+        if ($use_time) {
+          $gd_str .= substr($this->getGeckoDate(),8,2).':00';
+          $old_tz = date_default_timezone_get();
+          date_default_timezone_set("America/Los_Angeles");
+        }
+        $this->uadata['geckotime'] = strtotime($gd_str);
+        if ($use_time) { date_default_timezone_set($old_tz); }
+      }
+    }
+  return $this->uadata['geckotime'];
+  }
+
+  public function isBot() { return $this->bot; }
+
+  public function isns() {
+    trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
+    return (strpos($this->brand, 'Netscape') !== false);
+  }
+  public function isns4() {
+    trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
+    return ((strpos($this->brand, 'Netscape') !== false) && (intval($this->version) == 4));
+  }
+  public function isie() {
+    trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
+    return $this->hasEngine('trident');
+  }
+  public function geckodate() {
+    trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
+    return (!is_null($this->getGeckoDate())?$this->getGeckoDate():0);
+  }
+  public function geckobased() {
+    trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
+    return $this->hasEngine('gecko');
+  }
+  public function khtmlbased() {
+    trigger_error(__CLASS__.'::'.__FUNCTION__.' is a deprecated function', E_USER_NOTICE);
+    return $this->hasEngine('khtml');
+  }
+}
+?>
diff --git a/testbed/rrd/.gitignore b/testbed/rrd/.gitignore
new file mode 100644 (file)
index 0000000..43a89a5
--- /dev/null
@@ -0,0 +1,2 @@
+*.rrd
+graphs
diff --git a/testbed/rrd/rrd-config.inc.php b/testbed/rrd/rrd-config.inc.php
new file mode 100644 (file)
index 0000000..87e32cb
--- /dev/null
@@ -0,0 +1,150 @@
+<?php
+// RRD info for CPU info
+$rrd_info = array();
+$rrd_info['*']['graph']['path'] = 'graphs';
+// $rrd_info['*']['page']['graph_url'] = 'http://127.0.0.1/testbed/rrd/';
+$rrd_info['*']['graph']['units_length'] = 6;
+// $rrd_info['*']['graph']['force_recreate'] = true;
+
+$rrd_info['index']['page']['type'] = 'index';
+// $rrd_info['index']['page']['index_ids'] = 'hd,-hd.root';
+// $rrd_info['index']['page']['scan_config'] = false;
+$rrd_info['index']['page']['scan_files'] = true;
+$rrd_info['index']['hidden'] = true;
+
+$rrd_info['overview']['page']['type'] = 'overview';
+$rrd_info['overview']['page']['index_ids'] = 'cpu,load,mem,rrdup';
+$rrd_info['overview']['page']['scan_config'] = false;
+$rrd_info['overview']['page']['text_intro'] = 'Go to the <a href="?stat=index">index page</a> for a full list of all available statistics';
+// $rrd_info['overview']['hidden'] = true;
+
+$rrd_info['cpu']['file'] = 'system.cpu.rrd';
+$rrd_info['cpu']['auto-update'] = true;
+$rrd_info['cpu']['fields'][] = array('name' => 'user', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['fields'][] = array('name' => 'nice', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['fields'][] = array('name' => 'system', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['fields'][] = array('name' => 'idle', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['fields'][] = array('name' => 'iowait', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['fields'][] = array('name' => 'irq', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['fields'][] = array('name' => 'softirq', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['fields'][] = array('name' => 'total', 'type' => 'COUNTER', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['cpu']['update'] =
+ 'function {
+    $sdata = file("/proc/stat"); $udata = array();
+    foreach ($sdata as $sline) {
+      if (preg_match("/^\s*cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $sline, $regs)) {
+        $udata = array("user"=>$regs[1],"nice"=>$regs[2],"system"=>$regs[3],"idle"=>$regs[4],
+                       "iowait"=>$regs[5],"irq"=>$regs[6],"softirq"=>$regs[7],"total"=>array_sum($regs));
+      }
+    }
+    return $udata;
+  }';
+$rrd_info['cpu']['graph']['rows'][] = array('name'=>'total', 'gType'=>'');
+$rrd_info['cpu']['graph']['rows'][] = array('name'=>'softirq_tmp', 'dsname'=>'softirq', 'gType'=>'');
+$rrd_info['cpu']['graph']['rows'][] = array('name'=>'irq_tmp', 'dsname'=>'irq', 'gType'=>'');
+$rrd_info['cpu']['graph']['rows'][] = array('name'=>'iowait_tmp', 'dsname'=>'iowait', 'gType'=>'');
+$rrd_info['cpu']['graph']['rows'][] = array('name'=>'system_tmp', 'dsname'=>'system', 'gType'=>'');
+$rrd_info['cpu']['graph']['rows'][] = array('name'=>'nice_tmp', 'dsname'=>'nice', 'gType'=>'');
+$rrd_info['cpu']['graph']['rows'][] = array('name'=>'user_tmp', 'dsname'=>'user', 'gType'=>'');
+$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'softirq', 'rpn_expr'=>'softirq_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#CCCCCC', 'color_bg'=>'#808080', 'legend'=>'softIRQ');
+$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'irq', 'rpn_expr'=>'irq_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#808080', 'legend'=>'IRQ', 'stack'=>true);
+$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'iowait', 'rpn_expr'=>'iowait_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FF00FF', 'legend'=>'I/O wait', 'stack'=>true);
+$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'system', 'rpn_expr'=>'system_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FF0000', 'legend'=>'System', 'stack'=>true);
+$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'nice', 'rpn_expr'=>'nice_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FFFF00', 'color_bg'=>'#808080', 'legend'=>'Nice', 'stack'=>true);
+$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'user', 'rpn_expr'=>'user_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'User', 'stack'=>true);
+$rrd_info['cpu']['graph']['units_length'] = 4;
+$rrd_info['cpu']['graph']['label_y'] = '% CPU-Auslastung';
+$rrd_info['cpu']['graph']['min_y'] = 0;
+$rrd_info['cpu']['graph']['max_y'] = 100;
+$rrd_info['cpu']['graph']['fix_scale_y'] = true;
+// $rrd_info['cpu']['graph']['force_recreate'] = true;
+
+$rrd_info['mem']['file'] = 'system.mem.rrd';
+$rrd_info['mem']['auto-update'] = true;
+$rrd_info['mem']['fields'][] = array('name' => 'total', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['mem']['fields'][] = array('name' => 'used', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['mem']['fields'][] = array('name' => 'buffers', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['mem']['fields'][] = array('name' => 'cached', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['mem']['fields'][] = array('name' => 'swap_total', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['mem']['fields'][] = array('name' => 'swap_used', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['mem']['update'] =
+ 'function {
+    $sdata = explode("\n", `/usr/bin/free -b -o`);
+    $udata = array("total"=>null,"used"=>null,"buffers"=>null,"cached"=>null,
+                   "swap_total"=>null,"swap_used"=>null);
+    foreach ($sdata as $sline) {
+      if (preg_match("/Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $sline, $regs)) {
+        $udata["total"] = $regs[1]; $udata["used"] = $regs[2]-$regs[5]-$regs[6];
+        $udata["buffers"] = $regs[5]; $udata["cached"] = $regs[6];
+      }
+      elseif (preg_match("/Swap:\s+(\d+)\s+(\d+)\s+(\d+)/", $sline, $regs)) {
+        $udata["swap_total"] = $regs[1]; $udata["swap_used"] = $regs[2];
+      }
+    }
+    return $udata;
+  }';
+$rrd_info['mem']['graph']['rows'][] = array('name'=>'total', 'gType'=>'LINE1', 'color'=>'#000000', 'legend'=>'Available');
+$rrd_info['mem']['graph']['rows'][] = array('name'=>'used', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'Used');
+$rrd_info['mem']['graph']['rows'][] = array('name'=>'buffers', 'gType'=>'AREA', 'color'=>'#FFFF00', 'legend'=>'Buffers', 'stack'=>true);
+$rrd_info['mem']['graph']['rows'][] = array('name'=>'cached', 'gType'=>'AREA', 'color'=>'#008000', 'legend'=>'Cache', 'stack'=>true);
+$rrd_info['mem']['graph']['rows'][] = array('name'=>'swap_total', 'gType'=>'LINE1', 'color'=>'#CCCCCC', 'legend'=>'Swap avail.');
+$rrd_info['mem']['graph']['rows'][] = array('name'=>'swap_used', 'gType'=>'LINE2', 'color'=>'#00FFFF', 'legend'=>'Swap used');
+$rrd_info['mem']['graph']['units_binary'] = true;
+$rrd_info['mem']['graph']['units_exponent'] = 6;
+$rrd_info['mem']['graph']['units_length'] = 6;
+$rrd_info['mem']['graph']['label_y'] = 'Memory';
+$rrd_info['mem']['graph']['min_y'] = 0;
+// $rrd_info['mem']['graph']['max_y'] = 100;
+// $rrd_info['mem']['graph']['fix_scale_y'] = true;
+// $rrd_info['mem']['graph']['force_recreate'] = true;
+$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'total', 'gType'=>'');
+$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'swap_total', 'gType'=>'');
+$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'used_tmp', 'dsname'=>'used', 'gType'=>'');
+$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'buffers_tmp', 'dsname'=>'buffers', 'gType'=>'');
+$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'cached_tmp', 'dsname'=>'cached', 'gType'=>'');
+$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'swap_tmp', 'dsname'=>'swap_used', 'gType'=>'');
+$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'used', 'rpn_expr'=>'used_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'Used');
+$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'buffers', 'rpn_expr'=>'buffers_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FFFF00', 'legend'=>'Buffers', 'stack'=>true);
+$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'cached', 'rpn_expr'=>'cached_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#008000', 'legend'=>'Cache', 'stack'=>true);
+$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'swap_used', 'rpn_expr'=>'swap_tmp,swap_total,/,100,*', 'gType'=>'LINE2', 'color'=>'#00FFFF', 'legend'=>'Swap');
+$rrd_info['mem']['graph.pct']['units_exponent'] = 0;
+$rrd_info['mem']['graph.pct']['units_length'] = 4;
+$rrd_info['mem']['graph.pct']['label_y'] = '% Memory';
+$rrd_info['mem']['graph.pct']['min_y'] = 0;
+$rrd_info['mem']['graph.pct']['max_y'] = 100;
+$rrd_info['mem']['graph.pct']['fix_scale_y'] = true;
+// $rrd_info['mem']['graph.pct']['force_recreate'] = true;
+$rrd_info['mem']['page.pct']['graph_sub'] = 'pct';
+
+$rrd_info['load']['file'] = 'system.load.rrd';
+$rrd_info['load']['auto-update'] = true;
+$rrd_info['load']['fields'][] = array('name' => 'load1', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['load']['fields'][] = array('name' => 'load5', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['load']['fields'][] = array('name' => 'load15', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['load']['update'] = 'function { $sdata = explode(" ",file_get_contents("/proc/loadavg")); return array("load1"=>$sdata[0],"load5"=>$sdata[1],"load15"=>$sdata[2]); }';
+$rrd_info['load']['graph']['rows'][] = array('name'=>'load1', 'gType'=>'AREA', 'color'=>'#00CC00', 'legend'=>'1 Min.');
+$rrd_info['load']['graph']['rows'][] = array('name'=>'load5', 'gType'=>'LINE1', 'color'=>'#FF4000', 'legend'=>'5 Min.');
+$rrd_info['load']['graph']['rows'][] = array('name'=>'load15', 'gType'=>'LINE1', 'color'=>'#0000FF', 'legend'=>'15 Min.');
+$rrd_info['load']['graph']['units_length'] = 4;
+$rrd_info['load']['graph']['units_exponent'] = 0;
+$rrd_info['load']['graph']['label_y'] = 'Load average';
+$rrd_info['load']['graph']['min_y'] = 0;
+// $rrd_info['load']['graph']['force_recreate'] = true;
+$rrd_info['load']['page']['data_colorize'] = true;
+
+/* !!! be sure to call this one _last_ of all auto-update rrd stats */
+$rrd_info['rrdup']['file'] = 'test.rrdup.rrd';
+// $rrd_info['rrdup']['auto-update'] = true;
+$rrd_info['rrdup']['fields'][] = array('name' => 'usertime', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['rrdup']['fields'][] = array('name' => 'systime', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
+$rrd_info['rrdup']['update'] = 'function { $sdata = posix_times(); return array("usertime"=>$sdata["cutime"],"systime"=>$sdata["cstime"]); }';
+$rrd_info['rrdup']['graph']['rows'][] = array('name'=>'systime', 'gType'=>'AREA', 'color'=>'#FF0000', 'legend'=>'System CPU time');
+$rrd_info['rrdup']['graph']['rows'][] = array('name'=>'usertime', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'User CPU time', 'stack'=>true);
+$rrd_info['rrdup']['graph']['scale'] = 0.01;
+$rrd_info['rrdup']['graph']['units_length'] = 4;
+$rrd_info['rrdup']['graph']['units_exponent'] = 0;
+$rrd_info['rrdup']['graph']['label_y'] = 'RRD update (seconds)';
+$rrd_info['rrdup']['graph']['min_y'] = 0;
+// $rrd_info['rrdup']['graph']['force_recreate'] = true;
+
+?>
diff --git a/testbed/rrd/rrd-stat.php b/testbed/rrd/rrd-stat.php
new file mode 100644 (file)
index 0000000..9ef9598
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+$myfile = $_SERVER['SCRIPT_FILENAME'];
+while (is_link($myfile)) { $myfile = readlink($myfile); }
+if (getcwd() != dirname($myfile)) {
+  // change to directory of the script if called from different directory
+  $orig_workingdir = getcwd();
+  chdir(dirname($myfile));
+}
+
+include_once('rrdstat.php-class');
+
+$rrd_config_file = 'rrd-config/'.php_uname('n').'.inc.php';
+if (!file_exists($rrd_config_file)) { $rrd_config_file = 'rrd-config.inc.php'; }
+include_once($rrd_config_file);
+
+// view stats
+$sname = isset($_GET['stat'])?$_GET['stat']:null;
+if (is_null($sname) || !strlen($sname)) { $sname = 'index'; }
+
+// call RRD module
+$rrds = new rrdstat($rrd_info, $sname);
+
+$psub = isset($_GET['sub'])?$_GET['sub']:null;
+print($rrds->page($psub));
+?>
diff --git a/testbed/rrd/rrd-test.php b/testbed/rrd/rrd-test.php
new file mode 100644 (file)
index 0000000..4cd7705
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+$myfile = $_SERVER['SCRIPT_FILENAME'];
+while (is_link($myfile)) { $myfile = readlink($myfile); }
+if (getcwd() != dirname($myfile)) {
+  // change to directory of the script if called from different directory
+  $orig_workingdir = getcwd();
+  chdir(dirname($myfile));
+}
+
+include_once('rrdstat.php-class');
+
+$rrd_config_file = 'rrd-config/'.php_uname('n').'.inc.php';
+if (!file_exists($rrd_config_file)) { $rrd_config_file = 'rrd-config.inc.php'; }
+include_once($rrd_config_file);
+
+if (php_sapi_name() == 'cli') {
+  // automated updates
+  $rrd = new rrdstat($rrd_info, 'video.temp');
+  $rrd->update();
+}
+else {
+  print('this is a commandline app.');
+}
+?>
diff --git a/testbed/rrd/rrd-update.php b/testbed/rrd/rrd-update.php
new file mode 100644 (file)
index 0000000..159763b
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+$myfile = $_SERVER['SCRIPT_FILENAME'];
+while (is_link($myfile)) { $myfile = readlink($myfile); }
+if (getcwd() != dirname($myfile)) {
+  // change to directory of the script if called from different directory
+  $orig_workingdir = getcwd();
+  chdir(dirname($myfile));
+}
+
+include_once('rrdstat.php-class');
+
+$rrd_config_file = 'rrd-config/'.php_uname('n').'.inc.php';
+if (!file_exists($rrd_config_file)) { $rrd_config_file = 'rrd-config.inc.php'; }
+include_once($rrd_config_file);
+
+if (php_sapi_name() == 'cli') {
+  // automated updates
+  $autoupdate = array();
+  foreach ($rrd_info as $iname=>$rinfo) {
+    if (isset($rinfo['auto-update']) && $rinfo['auto-update']) {
+      $autoupdate[] = $iname;
+    }
+  }
+  $autoupdate[] = 'rrdup';
+  foreach ($autoupdate as $rrdname) {
+    $rrd = new rrdstat($rrd_info, $rrdname);
+    $rrd->update();
+  }
+}
+else {
+  print('this is a commandline app.');
+}
+?>
diff --git a/testbed/rrd/rrdstat.php-class b/testbed/rrd/rrdstat.php-class
new file mode 120000 (symlink)
index 0000000..9f52251
--- /dev/null
@@ -0,0 +1 @@
+../../include/classes/rrdstat.php-class
\ No newline at end of file
diff --git a/testbed/ua_list.php b/testbed/ua_list.php
new file mode 100644 (file)
index 0000000..9781fbf
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+$inc_class_util = true;
+$inc_class_ua = true;
+include('inchandler.inc');
+
+// read string from this file
+$uafile = 'ua_list_raw.txt';
+
+$mycss = "th { font-size: 0.75em; }\n";
+$mycss .= "td.comment { font-size: 0.75em; text-align: center; font-weight: bold; }\n";
+$mycss .= "td.ua { font-size: 0.75em; }\n";
+
+$wrapper->pgtop('User Agents', $mycss);
+
+print('<h1>User Agents</h1>'."\n");
+
+$ualist = is_readable($uafile)?file($uafile):array();
+
+if (count($ualist)) {
+  print('<table class="border">'."\n");
+  print(' <tr>'."\n");
+  print('  <th>User Agent string</th>'."\n");
+  print('  <th>Brand</th>'."\n");
+  print('  <th>Version</th>'."\n");
+  print('  <th>Bot</th>'."\n");
+  print('  <th>Engine</th>'."\n");
+  print('  <th>eVer</th>'."\n");
+  print('  <th>OS</th>'."\n");
+  print('  <th>Platform</th>'."\n");
+  print('  <th>Lang</th>'."\n");
+  print(' </tr>'."\n");
+
+  foreach ($ualist as $uastring) {
+    $uastring = trim($uastring);
+    if (substr($uastring, 0, 1) == '#') {
+      // comment
+      print(' <tr>'."\n");
+      print('  <td colspan="9" class="comment">'.substr($uastring, 1).'</td>'."\n");
+      print(' </tr>'."\n");
+    }
+    else {
+      $ua = new userAgent($uastring);
+      print(' <tr>'."\n");
+      print('  <td class="ua">'.$ua->getUAString().'</td>'."\n");
+      print('  <td>'.$ua->getBrand().'</td>'."\n");
+      print('  <td>'.$ua->getVersion().'</td>'."\n");
+      print('  <td>'.($ua->isBot()?'x':'-').'</td>'."\n");
+      print('  <td>'.$ua->getEngine().'</td>'."\n");
+      print('  <td>'.$ua->getEngineVersion().'</td>'."\n");
+      print('  <td>'.$ua->getOS().'</td>'."\n");
+      print('  <td>'.$ua->getPlatform().'</td>'."\n");
+      print('  <td>'.$ua->getLanguage().'</td>'."\n");
+      print(' </tr>'."\n");
+    }
+  }
+  print('</table>'."\n");
+}
+else {
+  print('No User Agent strings found in file "'.$uafile.'".'."\n");
+}
+
+$wrapper->pgbottom();
+?>
diff --git a/testbed/ua_list_raw.txt b/testbed/ua_list_raw.txt
new file mode 100755 (executable)
index 0000000..af4c66a
--- /dev/null
@@ -0,0 +1,302 @@
+# collection of some known User Agent Strings:
+# see also:
+# http://www.pgts.com.au/pgtsj/pgtsj0208c.html http://www.psychedelix.com/agents/index.shtml http://en.wikipedia.org/wiki/User_agent http://useragentstring.com/pages/useragentstring.php
+Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.3b) Gecko/20030114
+Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.0rc3) Gecko/20020523
+Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.1) Gecko/20021005
+Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.0.0) Gecko/20020622 Debian/1.0.0-0.woody.1
+Mozilla/5.0 (X11; U; Linux sparc64; en-US; rv:0.9.4) Gecko/20011029
+Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.5) Gecko/20031016
+Mozilla/5.0 (X11; U; NetBSD i386; en-US; rv:1.6) Gecko/20040315
+Mozilla/5.0 (X11; U; AIX 0006FADF4C00; en-US; rv:1.7b) Gecko/20040318
+Mozilla/5.0 (OS/2; U; Warp 4.5; de-AT; rv:1.7a) Gecko/20040225
+Mozilla/5.0 (X11; U; OpenVMS AlphaServer_ES40; en-US; rv:1.4) Gecko/20030826 SWB/V1.4 (HP)
+Mozilla/5.0 (X11; U; HP-UX 9000/785; en-US; rv:1.4) Gecko/20030730
+Mozilla/5.0 (X11; Slackware; Linux i686; en-US; rv:1.7) Gecko/20040618
+Mozilla/5.0 (X11; U; Linux i686; rv:1.7.7) Gecko/20050414
+Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.6; f33eed1469017fe8b64dc7f3261eb135;) Gecko/20040113
+Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040618 MultiZilla/1.6.2.1d
+Mozilla/5.0 (Linux; U; de, DE, de_DE@euro; m18) Gecko/20001010
+Mozilla/5.0 (Windows; U; Win 9x 4.90; de-DE; m18) Gecko/20010131 Netscape6/6.01
+Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.0.1) Gecko/20020823 Netscape/7.0
+Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.8.1.5pre) Gecko/20070604 Firefox/2.0.0.4 Navigator/9.0b1
+Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5
+Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4b) Gecko/20030516 Mozilla Firebird/0.6
+Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:1.5a) Gecko/20030728 Mozilla Firebird/0.6.1
+Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.5a) Gecko/20030728 Mozilla Firebird/0.6.1
+Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7a) Gecko/20040216 Firefox/0.8.0+
+Mozilla/5.0 (BeOS; U; BeOS BePC; en-US; rv:1.7b) Gecko/20040228 Firefox/0.8.0+ (Mozilla/4.7 [en] (Win95; I))
+Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1
+Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.7.5) Gecko/20050101 Firefox/1.0
+Mozilla/5.0 (Gameboy Color; U; Gameboy OS 2005; de-DE) Gecko/20041107 Firefox/1.0
+Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.5) Gecko/20041111 Firefox/1.0
+Mozilla/5.0 (X11; Linux i686; rv:1.7.5) Gecko/20041108 Firefox/1.0
+Mozilla/5.0 (X11; U; Linux i686; chrome://navigator/locale/navigator.properties; rv:1.7.5) Gecko/20041107 Firefox/1.0
+Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.5) Gecko/20041217 Firefox/1.0.4
+Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a6pre) Gecko/20070702 Minefield/3.0a6pre
+Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.8b2) Gecko/20050324 SeaMonkey/1.0a
+Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9a6pre) Gecko/20070628 Firefox/2.0.0.4 SeaMonkey/2.0a1pre PrivatelyFakedUA/0.0
+Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20021109 Chimera/0.6+
+Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7b) Gecko/20040302 Camino/0.7+
+Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en; rv:1.8.1.5) Gecko/20070614 Camino/1.6 (like Firefox/2.0.0.4)
+Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031016 K-Meleon/0.8.1
+Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.7.13) Gecko/20050610 K-Meleon/0.9
+Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US; rv:1.0.1) Gecko/20020730 AOL/7.0
+Mozilla/5.0 (Windows; U; Windows CE 4.21; rv:1.8b4) Gecko/20050720 Minimo/0.007
+Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20061031 Firefox/1.5.0.7 Flock/0.7.7
+Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Iceweasel/2.0 (Debian-2.0+dfsg-1)
+Mozilla/5.0 (X11; U; Linux armv6l; en-GB; rv:1.9a6pre) Gecko/20071128 Firefox/3.0a1 Tablet browser 0.2.2 RX-34+RX-44_2008SE_2.2007.48-9
+Mozilla/5.0 (X11; U; Linux armv6l; en-US; rv:1.9a6pre) Gecko/20070926 Firefox/3.0a1 Tablet browser 0.1.22 RX-34+RX-44_OSSO1.1_0.2007.39-13
+Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031019 Epiphany/1.0.6
+Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050317 Firefox/1.0.4 Epiphany/1.6.3
+Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.8.0.4) Gecko/20060608 Ubuntu/dapper-security Epiphany/2.14
+Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20060410 Firefox/1.0.8 Galeon/1.3.21
+Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.6) Gecko/20040402 Galeon/1.3.14
+Mozilla/5.0 (X11; U; Linux i686) Gecko/20040319 Galeon/1.3.7
+Mozilla/5.0 Galeon/1.2.7 (X11; Linux i686; U;) Gecko/20021204
+Galeon/1.3.7 (IE4 compatible; I; Windows XP) Galeon/1.3.7 Debian/1.3.7.20030803-1
+Microsoft Internet Explorer/4.0b1 (Windows 95)
+Mozilla/1.22 (compatible; MSIE 1.5; Windows NT)
+Mozilla/2.0 (compatible; MSIE 3.01; Windows 95)
+Mozilla/4.0 (compatible; MSIE 5.0; Windows 95; DigExt)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
+Mozilla/4.0 (compatible; MSIE 6.02; Windows 98)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; IE5.x/Winxx/EZN/xx; .NET CLR 1.1.4322)
+Mozilla/4.0 (compatible ; MSIE 6.0; Windows NT 5.1)
+Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461)
+Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
+Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Smartphone; 176x220)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Hotbar 4.5.1.0; MSN 6.1; MSNbMSFT; MSNmen-au; MSNc00; v5m)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; MSN 9.0;MSN 9.1; MSNbVZ02; MSNmen-us; MSNcOTH; MPLUS)
+Mozilla/4.0 (compatible; MSIE 6.0; MSN 2.5; Windows 98)
+Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC)
+Mozilla/4.0 (compatible; MSIE 4.01; AOL 5.0; Mac_PPC)
+Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 95; Toshiba Corporation)
+Mozilla/4.0 (compatible; MSIE 5.5; AOL 6.0;TargetAOL6.0; Windows 98)
+Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; {D2F65954-6A14-43B5-86BE-42556275B763})
+Mozilla/4.0 (compatible; MSIE 6.0; America Online Browser 1.1; rev1.5; Windows NT 5.1;)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.1.4322) Netscape/8.0.1
+Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Crazy Browser 1.0.5)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; MyIE2; iRider 2.10.0008)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; MyIE2; Maxthon; .NET CLR 1.0.3705; .NET CLR 1.1.4322)
+Microsoft Pocket Internet Explorer/0.6
+Mozilla/1.1 (compatible; MSPIE 2.0; Windows CE)
+Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; PPC; 240x320)
+Advanced Browser (http://www.avantbrowser.com)
+Avant Browser/1.2.789rel1 (http://www.avantbrowser.com)
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Avant Browser [avantbrowser.com])
+AOL 8.0 (compatible; AOL 8.0; DOS; .NET CLR 1.1.4322)
+MSFrontPage/6.0
+Mozilla/4.0 (compatible; MS FrontPage 6.0)
+Mozilla/5.0 (compatible; Konqueror/3; Linux 2.4.18; X11; i686)
+Mozilla/5.0 (compatible; Konqueror/3.1; Linux 2.4.22-10mdk; X11; i686; fr, fr_FR)
+Mozilla/5.0 (compatible; Konqueror/3.2; Linux 2.6.5; X11; i686; en_US, es, fr, it, en_US.UTF-8, en) (KHTML, like Gecko)
+Mozilla/5.0 (compatible; Konqueror/2.0.1; X11); Supports MD5-Digest; Supports gzip encoding
+Mozilla/5.0 (compatible; Konqueror/3.2; Darwin) (KHTML, like Gecko)
+Mozilla/5.0 (compatible; Konqueror/3.1; CYGWIN_NT-5.1)
+Mozilla/5.0 (compatible; Konqueror/3.2; OpenBSD) (KHTML, like Gecko)
+Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.0 (like Gecko)
+Mozilla/5.0 (compatible; Konqueror/3.3; Linux; X11; i686; es, en_US) KHTML/3.3.2 (like Gecko)
+Mozilla/5.0 (Windows; U; Windows NT 5.1; de) AppleWebKit/522.13.1 (KHTML, like Gecko) Version/3.0.2 Safari/522.13.1
+Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51
+Mozilla/4.0 (compatible; MSIE 5.12; Mac_PowerPC) OmniWeb/4.1.1-v424.6
+Mozilla/4.5 (compatible; OmniWeb/4.1.1-v423; Mac_PowerPC)
+Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/85 (KHTML, like Gecko) OmniWeb/v540
+Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/125.4 (KHTML, like Gecko, Safari) OmniWeb/v563.51
+Mozilla/5.0 (Macintosh; U; PPC Mac OS X; de-de) AppleWebKit/418 (KHTML, like Gecko) Shiira/1.2.2 Safari/125
+Mozilla/5.0 (SymbianOS/9.1; U; en-us) AppleWebKit/413 (KHTML, like Gecko) Safari/413
+Opera/5.12 (Windows 2000; U)  [de]
+Mozilla/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.05 [ja]
+Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i586) Opera 7.23 [en]
+Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.54  [de]
+Mozilla/4.78 (Windows NT 5.1; U) Opera 7.21 [en]
+Mozilla/5.0 (Windows NT 5.0; U; en) Opera 8.0
+Mozilla/4.0 (compatible; MSIE 6.0; Mac_PowerPC Mac OS X; en) Opera 8.0
+Opera/8.00 (Windows NT 5.1; U; en)
+Opera/8.01 (X11; Linux i686; U; de)
+Mozilla/5.0 (X11; Linux i686; U; en) Opera 8.01
+Mozilla/5.0 (Windows NT 5.2; U; cs; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20
+Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC) Opera 6.0  [de]
+Mozilla/4.1 (compatible; MSIE 5.0; Symbian OS; Nokia 6600;423) Opera 6.10 [de]
+Mozilla/4.0 (compatible; MSIE 6.0; Symbian OS; Nokia 6630/4.03.38; 6937) Opera 8.50 [es]
+Mozilla/4.0 (compatible; MSIE 6.0; ; Linux armv5tejl; U) Opera 8.02 [en_US] Maemo browser 0.4.31 N770/SU-18
+Mozilla/4.0 (compatible; MSIE 6.0; Nitro) Opera 8.50 [ja]
+Opera/9.00 (Wii; U; ; 1038-58; Wii Shop Channel/1.0; en)
+Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr)
+Opera/2.0.3920 (J2ME/MIDP; Opera Mini; en; U; ssr)
+Mozilla/4.75 [de] (Win98; U)
+Mozilla/1.6 [en] (Windows NT 5.1; U)
+Mozilla/1.0 (CP/M; 8-bit .NET)
+Mozilla/3.01Gold (Win95; I)
+Mozilla/4.08 (Macintosh; U; 68K)
+Mozilla/4.76 [en]C-CCK-MCD cf476 (Windows NT 5.0; U)
+Mozilla/4.8 [de] (X11; U; Linux 2.4.20-4GB i686)
+Mozilla/4.61 [ja] (X11; I; Linux 2.2.13-33cmc1 i686)
+Mozilla/4.7C-CCK-MCD {C-UDP; EBM-APPLE} (Macintosh; I; PPC)
+Dillo/0.8.5-pre
+ELinks/0.9.3 (textmode; Linux 2.6.8.1 i686; 118x82)
+ELinks (0.4pre18; Linux 2.2.22 i686; 80x25)
+Links (2.1pre11; Linux 2.4.20-20.7asp i686; 80x24)
+Links (0.92; Linux 2.2.14-5.0 i586)
+Links (2.1pre14; FreeBSD 4.9-RELEASE i386; x)
+Links (2.1pre15; CYGWIN_NT-5.0 1.3.1(0.38/3/2) i686; x)
+Links (1.00pre12; Linux 2.6.10-grsec i686; 139x54) (Debian pkg 0.99+1.00pre12-1)
+Mozilla/5.0 (compatible; iCab 2.9.8; Macintosh; U, PPC; Mac OS X)
+iCab/2.9.8 (Macintosh; U; PPC)
+Mozilla/4.5 (compatible; iCab 2.9.8; Macintosh; U; PPC)
+Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6g
+NCSA_Mosaic/2.0 (Windows 3.1)
+NCSA_Mosaic/1.0 (X11; FreeBSD 1.2.0 i286) via proxy gateway CERN-HTTPD/1.0
+NCSA Mosaic/2-7-6 (X11;OpenVMS V7.2 VAX)
+NCSA_Mosaic/2.6 (X11;IRIX 4.0.5F IP12)
+Mozilla/4.0 (compatible; Voyager; AmigaOS)
+Arexx (compatible; AmigaVoyager/2.95; AmigaOS
+Mozilla/4.0 (compatible; ARexx; AmigaOS)
+Mozilla/4.0 (compatible; MSIE 5.5; arexx)
+Mozilla/4.0 (compatible; alpha 06; AmigaOS)
+Mozilla/4.0 (compatible; AWEB 3.4 SE; AmigaOS)
+IBrowse/2.3 (AmigaOS 3.9)
+Mozilla/4.0 (compatible; MSIE 5.5; AmigaOS4.0) IBrowse 2.3
+Mozilla/4.0 (compatible; IBrowse 3.0; AmigaOS4.0)
+Mozilla/4.0 (compatible; X 10.0; Commodore 64)
+ICE Browser/v5_4_3_1 (Java 1.4.2_01; Windows XP 5.1 x86)
+Mozilla/5.0 (NetWare; U; NetWare 6.0.04; en-PL) ICEbrowser/5.4.3 NovellViewPort/3.4.0
+Mozilla/3.0 (compatible; NetPositive/2.2)
+Mozilla/4.76 [en] (PalmOS; U; WebPro/3.0.1a; Palm-Arz1)
+Mozilla/4.7 (compatible; OffByOne; Windows 2000)
+Mozilla/4.0 (PSP (PlayStation Portable); 2.00)
+Mozilla/5.0 (PLAYSTATION 3; 1.00)
+Mozilla/4.0 (compatible; DB Browse 4.3; DB OS 6.0)
+Mozilla/4.75 compatible
+Mozilla/5.0
+Mozilla/5.0 ( ; ; ; de; ) Firefox
+Mozilla/5.0 (000000000; 0; 000 000 00 0 000000; 00000; 000000000) 00000000000000
+IBM-WebExplorer-DLL/v1.1h
+Java/1.4.1_02
+LWP::Simple/5.79
+PHP/4.2.3
+w3m/0.5.1
+SonyEricssonK700i/R2AE SEMC-Browser/4.0.3 Profile/MIDP-2.0 Configuration/CLDC-1.1 UP.Link/6.2.3.15.0 (Google WAP Proxy/1.0)
+SonyEricssonT610/R201 Profile/MIDP-1.0 Configuration/CLDC-1.0 (Google WAP Proxy/1.0)
+Nokia3510i/1.0 (04.01) Profile/MIDP-1.0 Configuration/CLDC-1.0 UP.Link/5.1.1.5a (Google WAP Proxy/1.0)
+Nokia7650/1.0 SymbianOS/6.1 Series60/0.9 Profile/MIDP-1.0 Configuration/CLDC-1.0 (Google WAP Proxy/1.0)
+Nokia6630/1.0 (3.45.113) SymbianOS/8.0 Series60/2.6 Profile/MIDP-2.0 Configuration/CLDC-1.1 (Google WAP Proxy/1.0)
+SIE-C60/12 UP.Browser/6.1.0.5.c.6 (GUI) MMP/1.0 (Google WAP Proxy/1.0)
+OPWV-SDK/62 UP.Browser/6.2.2.1.208 (GUI) MMP/2.0
+Mozilla/4.0 (MobilePhone MM-8300/US/1.0) NetFront/3.1 MMP/2.0
+Mozilla/4.0 (MobilePhone SCP-5500/US/1.0) NetFront/3.0 MMP/2.0 FAKE (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
+Samsung-SPHA920 AU-MIC-A920/2.0 MMP/2.0
+MOT-E398/0E.20.59R MIB/2.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.0
+Mozilla/4.0 (compatible; 240x320) IXI/Q05A2.4
+Mozilla/4.0 (compatible; AvantGo 6.0; FreeBSD)
+curl/7.7.2 (powerpc-apple-darwin6.0) libcurl 7.7.2 (OpenSSL 0.9.6b)
+curl/7.10.6 (i386-redhat-linux-gnu) libcurl/7.10.6 OpenSSL/0.9.7a ipv6 zlib/1.2.0.7
+amaya/8.3 libwww/5.4.0
+Python-urllib/1.15
+w3m/0.3.1
+Wget/1.8.2 modified
+wget 1.1
+Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)
+GetRight/5.0.2
+FlashGet
+Watchcat 2.3 Linux
+Space Bison/0.02 [fu] (Win67; X; SK)
+Anonymisiert durch Steganos Internet Anonym
+Anonymisiert durch Steganos Internet Anonym Pro 6
+Mozilla/4.0 (compatible; BorderManager 3.0)
+Mozilla/5.0 WebWasher 3.4
+Mozilla/5.0 (SaferSurf) Firefox 1.5
+# search bots:
+W3C_Validator/1.305.2.12 libwww-perl/5.64
+Scooter/3.3
+Spinne/2.0 med_AH
+Vagabondo/2.0 MT (webagent at wise-guys dot nl)
+TurnitinBot/1.5 ( ">http://www.turnitin.com/robot/crawlerinfo.html)
+FAST-WebCrawler/3.x Multimedia (mm dash crawler at fast dot no)
+Firefly/1.0 (compatible; Mozilla 4.0; MSIE 5.5)
+Googlebot/2.1 (+ ">http://www.googlebot.com/bot.html)
+Googlebot (+http://www.google.com/bot.html)
+Scrubby/2.2 ( ">http://www.scrubtheweb.com/)
+psbot/0.1 (+ ">http://www.picsearch.com/bot.html)
+NutchCVS/0.06-dev (Nutch; http://www.nutch.org/docs/en/bot.html; nutch-agent@lists.sourceforge.net)
+ObjectsSearch/0.06 (ObjectsSearch; http://www.ObjectsSearch.com/bot.html; support@thesoftwareobjects.com)
+NG/1.0
+URL_Spider_Pro/3.0 ( ">http://www.innerprise.net/usp-spider.asp)"
+Pompos/1.3 ">http://dir.com/pompos.html
+Szukacz/1.5 (robot; www.szukacz.pl/jakdzialarobot.html; info@szukacz.pl)
+ASPseek/1.2.10
+NPBot-1/2.0
+NetResearchServer/2.7(loopimprovements.com/robot.html)
+dloader(NaverRobot)/1.0
+Webchat/2.0 (www.webchat.de user crawler)
+msnbot/1.0 (+http://search.msn.com/msnbot.htm)
+Gigabot/2.0
+Mediapartners-Google/2.1
+Schmozilla/v9.14 Platinum
+OmniExplorer_Bot/1.07 (+http://www.omni-explorer.com) Internet Categorizer
+findlinks/0.926 (+http://wortschatz.uni-leipzig.de/findlinks/)
+DataCha0s/2.0
+Amfibibot/0.07 (Amfibi Robot; http://www.amfibi.com; agent@amfibi.com)
+aipbot/1.0 (aipbot; http://www.aipbot.com; aipbot@aipbot.com)
+Mozilla/4.0 compatible ZyBorg/1.0 Daily Refresh Beta-d03 (wn.zyborg@looksmart.net;
+Mozilla/2.0 (compatible; Ask Jeeves/Teoma)
+Mozilla/5.0 (Slurp/si; slurp@inktomi.com; ">http://www.inktomi.com/slurp.html)
+Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)"
+Mozilla/5.0 (compatible; Synoobot/0.9; http://www.synoo.com/search/bot.html)
+Mozilla/5.0 [en] (compatible; Gulper Web Bot 0.2.4 www.ecsl.cs.sunysb.edu/~maxim/cgi-bin/Link/GulperBot)
+Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; Girafabot; girafabot at girafa dot com;
+Mozilla/5.0 (compatible; Exabot/3.0; +http://www.exabot.com/go/robot)
+Mozilla/5.0 (compatible; GalaxyBot/2.0; +http://www.galaxy.com/)
+Mozilla/4.0 (compatible; NaverBot/1.0; http://help.naver.com/delete_main.asp)
+Mozilla/5.0 (compatible;FindITAnswersbot/1.0;  http://search.it-influentials.com/bot.htm)
+Mozilla/5.0 (compatible: Nebullabot/2.2)
+Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) VoilaBot BETA 1.2 (http://www.voila.com/)
+Mozilla/4.0 (efp@gmx.net)
+Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98)
+Mozilla/5.0 (Twiceler-0.9 http://www.cuill.com/twiceler/robot.html)
+Mozilla/4.0 (compatible; Arachmo)
+Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.)
+Mozilla/5.0 (compatible; heritrix/1.12.0 +http://www.accelobot.com)
+Mozilla/2.0 compatible; Check&amp;Get 1.14 (Windows NT)
+Mozilla/3.0 (compatible; WebCapture 2.0; Auto; Windows)
+Mozilla/3.0 (compatible; WebMon 1.0.11; Windows XP)
+Mozilla/4.0 (compatible; Powermarks/3.5; Windows 95/98/2000/NT)
+Mozilla/3.0 (compatible; Linkman)
+Mozilla/5.0 (Sage)
+Mozilla/5.0 (compatible; http://www.livedir.net)
+Mozilla/4.0 (WebClipping.com)
+Mozilla/5.0 (compatible; OsO; http://oso.octopodus.com/abot.html)
+Mozilla/5.0 (compatible; Yoono; http://www.yoono.com/)
+Mozilla/3.0 (compatible; Indy Library)
+Mozilla/5.0 (compatible; Google Desktop)
+PingALink Monitoring Services 1.0 (http://www.pingalink.com)
+IlTrovatore-Setaccio (+ ">http://www.iltrovatore.it)
+Mercator-2.0
+appie 1.1 (www.walhello.com)
+larbin_2.6.2 (larbin2.6.2@unspecified.mail)
+OWR_Crawler 0.1
+ISC Systems iRc Search 2.1
+NASA Search 1.0
+search.ch V1.4.2 (spiderman@search.ch;
+WebFilter Robot 1.0
+WWWeasel Robot v1.00 (http://wwweasel.de)
+2.0_AC-Plug - http://www.iOpus.com
+Openfind data gatherer, Openbot/3.0+(robot-response@openfind.com.tw;+
+MSRBOT (http://research.microsoft.com/research/sv/msrbot)
+ICCrawler - ICjobs (http://www.icjobs.de/bot.htm)
+Baiduspider+(+http://www.baidu.com/search/spider.htm)
+BaiDuSpider
+LinkWalker
+Internet Explorer 5.5
+Mozilla/4.0 (compatible; B-l-i-t-z-B-O-T)
+B l i t z B O T @ t r i c u s . n e t (Mozilla compatible)
+sitecheck.internetseer.com (For more info see: ">http://sitecheck.internetseer.com)
+http://www.almaden.ibm.com/cs/crawler   [c01]
+ia_archiver
+Nutch
+NutchCVS
+Mozilla
+HeinrichderMiragoRobot
+dumbBot
+42_HAL
diff --git a/testbed/ua_test.php b/testbed/ua_test.php
new file mode 100644 (file)
index 0000000..4bcbd05
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+$inc_class_util = true;
+$inc_class_ua = true;
+include("inchandler.inc");
+
+$wrapper->pgtop("KaiRo's Browser-Test");
+
+$httpvars = $util->getHTTPvars();
+if (strlen($httpvars["ua"])) {
+  $ua = new userAgent($httpvars["ua"]);
+}
+else {
+  $ua = new userAgent;
+}
+
+print("<h1>KaiRo's Browser-Test</h1>\n");
+
+print("I read the following user agent string from ".(strlen($httpvars["ua"])?"your input":"your browser").":\n<br>");
+print("<b>".$ua->getUAString()."</b>\n");
+
+print("<br><br>The browser brand is reported as &quot;<b>".$ua->getBrand()."</b>&quot;\n");
+print("<br>The browser version is reported as &quot;<b>".$ua->getVersion()."</b>&quot;\n");
+print("<br>The browser engine is reported as &quot;<b>".$ua->getEngine()."</b>&quot;\n");
+print("<br>The engine version is reported as &quot;<b>".$ua->getEngineVersion()."</b>&quot;\n");
+print("<br>The operating system is reported as &quot;<b>".$ua->getOS()."</b>&quot;\n");
+print("<br>The system platform is reported as &quot;<b>".$ua->getPlatform()."</b>&quot;\n");
+print("<br>The browser language is reported as &quot;<b>".$ua->getLanguage()."</b>&quot;\n");
+if ($ua->hasEngine('gecko')) {
+  print("<br>The Gecko date is reported as &quot;<b>".$ua->getGeckoDate()."</b>&quot;\n");
+  print("<br>The full Gecko date/time is reported as &quot;<b>".date('r',$ua->getGeckoTime())."</b>&quot;\n");
+}
+print("<br><br>I conclude this must be <b>".$ua->getBrand()." ".$ua->getVersion()."</b>\n");
+print("<br>This is <b>".($ua->isBot()?"an":"no")."</b> automated robot.\n");
+
+$acclang = $ua->getAcceptLanguages();
+print("<br><br>Accepted Languages: ");
+foreach ($acclang as $lang=>$q) { print($lang."(".$q.") "); }
+print("\n");
+
+print("<br><br>Test the following UA string (leave empty to read it from your browser):\n");
+print("<form method=\"POST\" action=\"\"><p>\n");
+print("<input type=\"text\" name=\"ua\" value=\"".htmlentities($ua->getUAString())."\" size=\"80\" maxlength=\"150\">\n");
+print("<br><input type=\"submit\" value=\"Test\"></p></form>\n");
+$wrapper->pgbottom();
+?>