[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpsysinfo/ -> index.php (source)

   1  <?php 
   2  // phpSysInfo - A PHP System Information Script
   3  // http://phpsysinfo.sourceforge.net/
   4  // This program is free software; you can redistribute it and/or
   5  // modify it under the terms of the GNU General Public License
   6  // as published by the Free Software Foundation; either version 2
   7  // of the License, or (at your option) any later version.
   8  // This program is distributed in the hope that it will be useful,
   9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11  // GNU General Public License for more details.
  12  // You should have received a copy of the GNU General Public License
  13  // along with this program; if not, write to the Free Software
  14  // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  15  // $Id: index.php 21228 2006-04-06 13:52:08Z ralfbecker $
  16  // phpsysinfo release version number
  17  
  18  
  19  $GLOBALS['egw_info'] = array(
  20      'flags' => array(
  21          'currentapp' => 'phpsysinfo',
  22          'noheader' => true,
  23  ));
  24  include('../header.inc.php');
  25  
  26  $VERSION = "2.5.2_rc1";
  27  $startTime = array_sum( explode( " ", microtime() ) );
  28  
  29  define('APP_ROOT', dirname(__FILE__));
  30  define('IN_PHPSYSINFO', true);
  31  
  32  ini_set('magic_quotes_runtime', 'off');
  33  ini_set('register_globals', 'off');
  34  // ini_set('display_errors','on');
  35  
  36  require_once (APP_ROOT . '/includes/class.error.inc.php');
  37  $error = new phpsysinfo_Error;
  38  
  39  // Figure out which OS where running on, and detect support
  40  if ( file_exists( APP_ROOT . '/includes/os/class.' . PHP_OS . '.inc.php' ) ) {
  41  } else {
  42    $error->addError('include(class.' . PHP_OS . '.php.inc)' , PHP_OS . ' is not currently supported', __LINE__, __FILE__ );
  43  }
  44  
  45  if (!extension_loaded('xml')) {
  46    $error->addError('extension_loaded(xml)', 'phpsysinfo requires the xml module for php to work', __LINE__, __FILE__);
  47  } 
  48  if (!extension_loaded('pcre')) {
  49    $error->addError('extension_loaded(pcre)', 'phpsysinfo requires the pcre module for php to work', __LINE__, __FILE__);
  50  } 
  51  
  52  if (!file_exists(APP_ROOT . '/config.php')) {
  53    $error->addError('file_exists(config.php)', 'config.php does not exist in the phpsysinfo directory.', __LINE__, __FILE__);
  54  } else { 
  55    require_once (APP_ROOT . '/config.php');             // get the config file
  56  }
  57  
  58  if ( !empty( $sensor_program ) ) {
  59    $sensor_program = basename( $sensor_program );
  60    if( !file_exists( APP_ROOT . '/includes/mb/class.' . $sensor_program . '.inc.php' ) ) {
  61      $error->addError('include(class.' . htmlspecialchars($sensor_program, ENT_QUOTES) . '.inc.php)', 'specified sensor programm is not supported', __LINE__, __FILE__ );
  62    } 
  63  } 
  64  
  65  if ( !empty( $hddtemp_avail ) && $hddtemp_avail != "tcp" && $hddtemp_avail != "suid" ) {
  66    $error->addError('include(class.hddtemp.inc.php)', 'bad configuration in config.php for $hddtemp_avail', __LINE__, __FILE__ );
  67  }
  68  
  69  if( $error->ErrorsExist() ) {
  70    echo $error->ErrorsAsHTML();
  71    exit;
  72  }
  73  
  74  require_once (APP_ROOT . '/includes/common_functions.php');     // Set of common functions used through out the app
  75  
  76  // DEFINE TEMPLATE_SET
  77  if (isset($_POST['template'])) {
  78    $template = $_POST['template'];
  79  } elseif (isset($_GET['template'])) {
  80    $template = $_GET['template'];
  81  } elseif (isset($_COOKIE['template'])) {
  82    $template = $_COOKIE['template'];
  83  } else {
  84    $template = $default_template; 
  85  }
  86  
  87  // check to see if we have a random
  88  if ($template == 'random') {
  89    $buf = gdc( APP_ROOT . "/templates/" );
  90    $template = $buf[array_rand($buf, 1)];
  91  }
  92  
  93  if ($template != 'xml' && $template != 'wml') {
  94    // figure out if the template exists
  95    $template = basename($template);
  96    if (!file_exists(APP_ROOT . "/templates/" . $template)) {
  97      // use default if not exists.
  98      $template = $default_template;
  99    }
 100    // Store the current template name in a cookie, set expire date to 30 days later
 101    // if template is xml then skip
 102  //RB-disable  setcookie("template", $template, (time() + 60 * 60 * 24 * 30));
 103    $_COOKIE['template'] = $template; //update COOKIE Var
 104  }
 105  
 106  // get our current language
 107  // default to english, but this is negotiable.
 108  if ($template == "wml") {
 109    $lng = "en";
 110  } elseif (isset($_POST['lng'])) {
 111    $lng = $_POST['lng'];
 112  } elseif (isset($_GET['lng'])) {
 113    $lng = $_GET['lng'];
 114  } elseif (isset($_COOKIE['lng'])) {
 115    $lng = $_COOKIE['lng'];
 116  } else {
 117    $lng = $default_lng;
 118  } 
 119  
 120  if ($lng == 'browser') {
 121    // see if the browser knows the right languange.
 122    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
 123      $plng = split(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
 124      if (count($plng) > 0) {
 125        while (list($k, $v) = each($plng)) {
 126          $k = split(';', $v, 1);
 127          $k = split('-', $k[0]);
 128          if (file_exists(APP_ROOT . '/includes/lang/' . $k[0] . '.php')) {
 129            $lng = $k[0];
 130            break;
 131          }
 132        }
 133      }
 134    }
 135  }
 136  
 137  $lng = basename($lng);
 138  if (file_exists(APP_ROOT . '/includes/lang/' . $lng . '.php')) {
 139    $charset = 'iso-8859-1';
 140    require_once(APP_ROOT . '/includes/lang/' . $lng . '.php'); // get our language include
 141    // Store the current language selection in a cookie, set expire date to 30 days later
 142  //RB-disable  setcookie("lng", $lng, (time() + 60 * 60 * 24 * 30));
 143    $_COOKIE['lng'] = $lng; //update COOKIE Var
 144  } else {
 145    $error->addError('include(' . $lng . ')', 'we do not support this language', __LINE__, __FILE__ );
 146    $lng = $default_lng;
 147  }
 148  
 149  // include the files and create the instances
 150  define('TEMPLATE_SET', $template);
 151  require_once( APP_ROOT . '/includes/os/class.' . PHP_OS . '.inc.php' );
 152  $sysinfo = new sysinfo;
 153  if( !empty( $sensor_program ) ) {
 154    require_once(APP_ROOT . '/includes/mb/class.' . $sensor_program . '.inc.php');
 155    $mbinfo = new mbinfo;
 156  }
 157  if ( !empty($hddtemp_avail ) ) {
 158    require_once (APP_ROOT . '/includes/mb/class.hddtemp.inc.php');
 159  }
 160  
 161  require_once (APP_ROOT . '/includes/xml/vitals.php');
 162  require_once (APP_ROOT . '/includes/xml/network.php');
 163  require_once (APP_ROOT . '/includes/xml/hardware.php');
 164  require_once (APP_ROOT . '/includes/xml/memory.php');
 165  require_once (APP_ROOT . '/includes/xml/filesystems.php');
 166  require_once (APP_ROOT . '/includes/xml/mbinfo.php');
 167  require_once (APP_ROOT . '/includes/xml/hddtemp.php');
 168  
 169  // build the xml
 170  $xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
 171  $xml .= "<!DOCTYPE phpsysinfo SYSTEM \"phpsysinfo.dtd\">\n\n";
 172  $xml .= created_by();
 173  $xml .= "<phpsysinfo>\n";
 174  $xml .= "  <Generation version=\"$VERSION\" timestamp=\"" . time() . "\"/>\n";
 175  $xml .= xml_vitals();
 176  $xml .= xml_network();
 177  $xml .= xml_hardware($hddtemp_devices);
 178  $xml .= xml_memory();
 179  $xml .= xml_filesystems();
 180  if ( !empty( $sensor_program ) ) {
 181    $xml .= xml_mbtemp();
 182    $xml .= xml_mbfans();
 183    $xml .= xml_mbvoltage();
 184  };
 185  if ( !empty($hddtemp_avail ) ) {
 186    $hddtemp = new hddtemp($hddtemp_devices);
 187    $xml .= xml_hddtemp($hddtemp);
 188  }
 189  $xml .= "</phpsysinfo>";
 190  replace_specialchars($xml);
 191  
 192  // output
 193  if (TEMPLATE_SET == 'xml') {
 194    // just printout the XML and exit
 195    header("Content-Type: text/xml\n\n");
 196    print $xml;
 197  } elseif (TEMPLATE_SET == 'wml') {
 198    require_once (APP_ROOT . '/includes/XPath.class.php');
 199    $XPath = new XPath();
 200    $XPath->importFromString($xml); 
 201  
 202    header("Content-type: text/vnd.wap.wml; charset=iso-8859-1");
 203    header("");
 204    header("Cache-Control: no-cache, must-revalidate");
 205    header("Pragma: no-cache");
 206  
 207    echo "<?xml version='1.0' encoding='iso-8859-1'?>\n";
 208    echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\" >\n";
 209    echo "<wml>\n";
 210    echo "<card id=\"start\" title=\"phpSysInfo - Menu\">\n";
 211    echo "<p><a href=\"#vitals\">" . $text['vitals'] . "</a></p>\n";
 212    echo "<p><a href=\"#network\">" . $text['netusage'] . "</a></p>\n";
 213    echo "<p><a href=\"#memory\">" . $text['memusage'] . "</a></p>\n";
 214    echo "<p><a href=\"#filesystem\">" . $text['fs'] . "</a></p>\n";
 215    if (!empty($sensor_program) || (isset($hddtemp_avail) && $hddtemp_avail)) {
 216      echo "<p><a href=\"#temp\">" . $text['temperature'] . "</a></p>\n";
 217    }
 218    if (!empty($sensor_program)) {
 219      echo "<p><a href=\"#fans\">" . $text['fans'] . "</a></p>\n";
 220      echo "<p><a href=\"#volt\">" . $text['voltage'] . "</a></p>\n";
 221    }
 222    echo "</card>\n";
 223    echo wml_vitals();
 224    echo wml_network();
 225    echo wml_memory();
 226    echo wml_filesystem();
 227    
 228    $temp = "";
 229    if (!empty($sensor_program)) {
 230      echo wml_mbfans();
 231      echo wml_mbvoltage();
 232      $temp .= wml_mbtemp();
 233    }
 234    if (isset($hddtemp_avail) && $hddtemp_avail)
 235      if ($XPath->match("/phpsysinfo/HDDTemp/Item"))
 236        $temp .= wml_hddtemp();
 237    if(strlen($temp) > 0)
 238      echo "<card id=\"temp\" title=\"" . $text['temperature'] . "\">" . $temp . "</card>";
 239    echo "</wml>\n";
 240  
 241  } else {
 242    $image_height = get_gif_image_height(APP_ROOT . '/templates/' . TEMPLATE_SET . '/images/bar_middle.gif');
 243    define('BAR_HEIGHT', $image_height);
 244  
 245    if (!is_object($GLOBALS['egw'])) {
 246      require_once (APP_ROOT . '/includes/class.Template.inc.php'); // template library
 247    } 
 248    // fire up the template engine
 249    $tpl = new Template(APP_ROOT . '/templates/' . TEMPLATE_SET);
 250    $tpl->set_file(array('form' => 'form.tpl')); 
 251    // print out a box of information
 252    function makebox ($title, $content)
 253    {
 254      if (empty($content)) {
 255        return "";
 256      } else {
 257        global $webpath;
 258        $textdir = direction();
 259        $t = new Template(APP_ROOT . '/templates/' . TEMPLATE_SET);
 260        $t->set_file(array('box' => 'box.tpl'));
 261        $t->set_var('title', $title);
 262        $t->set_var('content', $content);
 263        $t->set_var('webpath', $webpath);
 264        $t->set_var('text_dir', $textdir['direction']);
 265        return $t->parse('out', 'box');
 266      } 
 267    } 
 268    // Fire off the XPath class
 269    require_once (APP_ROOT . '/includes/XPath.class.php');
 270    $XPath = new XPath();
 271    $XPath->importFromString($xml); 
 272    // let the page begin.
 273    if (!is_object($GLOBALS['egw'])) {
 274      require_once (APP_ROOT . '/includes/system_header.php');
 275    } else {
 276      $GLOBALS['egw']->common->egw_header();
 277    } 
 278  
 279    if ( $error->ErrorsExist() && isset($showerrors) && $showerrors ) {
 280      $tpl->set_var('errors', makebox("ERRORS", $error->ErrorsAsHTML() ));
 281    }
 282  
 283    $tpl->set_var('title', $text['title'] . ': ' . $XPath->getData('/phpsysinfo/Vitals/Hostname') . ' (' . $XPath->getData('/phpsysinfo/Vitals/IPAddr') . ')');
 284    $tpl->set_var('vitals', makebox($text['vitals'], html_vitals()));
 285    $tpl->set_var('network', makebox($text['netusage'], html_network()));
 286    $tpl->set_var('hardware', makebox($text['hardware'], html_hardware()));
 287    $tpl->set_var('memory', makebox($text['memusage'], html_memory()));
 288    $tpl->set_var('filesystems', makebox($text['fs'], html_filesystems()));
 289    // Timo van Roermund: change the condition for showing the temperature, voltage and fans section
 290    $html_temp = "";
 291    if (!empty($sensor_program)) {
 292      if ($XPath->match("/phpsysinfo/MBinfo/Temperature/Item")) {
 293        $html_temp = html_mbtemp();
 294      }
 295      if ($XPath->match("/phpsysinfo/MBinfo/Fans/Item")) {
 296        $tpl->set_var('mbfans', makebox($text['fans'], html_mbfans()));
 297      } else {
 298        $tpl->set_var('mbfans', '');
 299      };
 300      if ($XPath->match("/phpsysinfo/MBinfo/Voltage/Item")) {
 301        $tpl->set_var('mbvoltage', makebox($text['voltage'], html_mbvoltage()));
 302      } else {
 303        $tpl->set_var('mbvoltage', '');
 304      };
 305    }
 306    if (isset($hddtemp_avail) && $hddtemp_avail) {
 307      if ($XPath->match("/phpsysinfo/HDDTemp/Item")) {
 308        $html_temp .= html_hddtemp();
 309      };
 310    }
 311    if (strlen($html_temp) > 0) {
 312      $tpl->set_var('mbtemp', makebox($text['temperature'], "\n<table width=\"100%\">\n" . $html_temp . "</table>\n"));
 313    }
 314    
 315    // parse our the template
 316    $tpl->pfp('out', 'form'); 
 317   
 318    // finally our print our footer
 319    if (is_object($GLOBALS['egw'])) {
 320      $GLOBALS['egw']->common->egw_footer();
 321    } else {
 322      require_once (APP_ROOT . '/includes/system_footer.php');
 323    } 
 324  } 
 325  
 326  ?>


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7