[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/phpsysinfo/includes/mb/ -> class.hddtemp.inc.php (source)

   1  <?php
   2  
   3  // phpSysInfo - A PHP System Information Script
   4  // http://phpsysinfo.sourceforge.net/
   5  
   6  // This program is free software; you can redistribute it and/or
   7  // modify it under the terms of the GNU General Public License
   8  // as published by the Free Software Foundation; either version 2
   9  // of the License, or (at your option) any later version.
  10  
  11  // This program is distributed in the hope that it will be useful,
  12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  // GNU General Public License for more details.
  15  
  16  // You should have received a copy of the GNU General Public License
  17  // along with this program; if not, write to the Free Software
  18  // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19  
  20  // $Id: class.hddtemp.inc.php 21228 2006-04-06 13:52:08Z ralfbecker $
  21  
  22  class hddtemp {
  23  
  24    var $drives;
  25  
  26    function hddtemp($devices) {
  27      foreach( $devices as $drive) {
  28          $this->drives = $this->drives . '/dev/' . $drive . ' ';
  29      }
  30    }
  31  
  32    function temperature($hddtemp_avail) {
  33      $ar_buf = array();
  34      $results = array();
  35      switch ($hddtemp_avail) {
  36      case "tcp":
  37      {
  38          // Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
  39          $fp = fsockopen('localhost', 7634, $errno, $errstr, 5);
  40          // if connected, read the output of the hddtemp daemon
  41          if ($fp) {
  42          // read output of the daemon
  43          $lines = '';
  44          while (!feof($fp)) {
  45              $lines .= fread($fp, 1024);
  46          }
  47          // close the connection
  48          fclose($fp);
  49          } else {
  50          die("HDDTemp error: " . $errno . ", " . $errstr);
  51          }
  52          $lines = str_replace("||", "|\n|", $lines);
  53          $ar_buf = explode("\n", $lines);
  54          break;
  55      }
  56      case "suid":
  57      {
  58          $hddtemp_value = execute_program("hddtemp", "$this->drives");
  59          $hddtemp_value = explode("\n", $hddtemp_value);
  60          foreach($hddtemp_value as $line)
  61          {    
  62          $temp = preg_split("/:\s/", $line, 3);
  63          if (preg_match("/^[0-9]/", $temp[2])) {
  64              list($temp[2], $temp[3]) = (preg_split("/\s/", $temp[2]));
  65              array_push( $ar_buf, "|" . implode("|", $temp) . "|");
  66          }
  67          }
  68          break;
  69      }
  70      default:
  71      {
  72          die("Bad hddtemp configuration in config.php");
  73      }
  74      }
  75      
  76      // Timo van Roermund: parse the info from the hddtemp daemon.
  77      $i = 0;
  78      foreach($ar_buf as $line) {
  79        $data = array();
  80        if (ereg("\|(.*)\|(.*)\|(.*)\|(.*)\|", $line, $data))
  81        {
  82          if( trim($data[3]) != "ERR" ) {
  83            // get the info we need
  84            $results[$i]['label'] = $data[1];
  85            $results[$i]['value'] = $data[3];
  86            $results[$i]['model'] = $data[2];
  87            $i++;
  88      }
  89        };
  90      }
  91  
  92      return $results;
  93    }
  94  }
  95  ?>


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