| 325 | 
           richard | 
           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.Darwin.inc.php,v 1.33 2006/06/14 16:36:34 bigmichi1 Exp $
  | 
        
        
            | 
            | 
           21 | 
           if (!defined('IN_PHPSYSINFO')) {
  | 
        
        
            | 
            | 
           22 | 
               die("No Hacking");
  | 
        
        
            | 
            | 
           23 | 
           }
  | 
        
        
            | 
            | 
           24 | 
              | 
        
        
            | 
            | 
           25 | 
           require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
  | 
        
        
            | 
            | 
           26 | 
              | 
        
        
            | 
            | 
           27 | 
           $error->addWarning("The Darwin version of phpSysInfo is work in progress, some things currently don't work");
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           class sysinfo extends bsd_common {
  | 
        
        
            | 
            | 
           30 | 
             var $cpu_regexp;
  | 
        
        
            | 
            | 
           31 | 
             var $scsi_regexp; 
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
             var $parser;
  | 
        
        
            | 
            | 
           34 | 
             // Our contstructor
  | 
        
        
            | 
            | 
           35 | 
             // this function is run on the initialization of this class
  | 
        
        
            | 
            | 
           36 | 
             function sysinfo () {
  | 
        
        
            | 
            | 
           37 | 
               // $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
  | 
        
        
            | 
            | 
           38 | 
               // $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
  | 
        
        
            | 
            | 
           39 | 
               $this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
  | 
        
        
            | 
            | 
           40 | 
               $this->parser = new Parser();
  | 
        
        
            | 
            | 
           41 | 
             } 
  | 
        
        
            | 
            | 
           42 | 
              | 
        
        
            | 
            | 
           43 | 
             function grab_key ($key) {
  | 
        
        
            | 
            | 
           44 | 
               $s = execute_program('sysctl', $key);
  | 
        
        
            | 
            | 
           45 | 
               $s = ereg_replace($key . ': ', '', $s);
  | 
        
        
            | 
            | 
           46 | 
               $s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys
  | 
        
        
            | 
            | 
           47 | 
              | 
        
        
            | 
            | 
           48 | 
               return $s;
  | 
        
        
            | 
            | 
           49 | 
             } 
  | 
        
        
            | 
            | 
           50 | 
              | 
        
        
            | 
            | 
           51 | 
             function grab_ioreg ($key) {
  | 
        
        
            | 
            | 
           52 | 
               $s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"'); //ioreg -cls "$key" | grep "$key"
  | 
        
        
            | 
            | 
           53 | 
               $s = ereg_replace('\|', '', $s);
  | 
        
        
            | 
            | 
           54 | 
               $s = ereg_replace('\+\-\o', '', $s);
  | 
        
        
            | 
            | 
           55 | 
               $s = ereg_replace('[ ]+', '', $s);
  | 
        
        
            | 
            | 
           56 | 
               $s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts
  | 
        
        
            | 
            | 
           57 | 
              | 
        
        
            | 
            | 
           58 | 
               return $s;
  | 
        
        
            | 
            | 
           59 | 
             } 
  | 
        
        
            | 
            | 
           60 | 
              | 
        
        
            | 
            | 
           61 | 
             function get_sys_ticks () {
  | 
        
        
            | 
            | 
           62 | 
               $a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value in seconds) 
  | 
        
        
            | 
            | 
           63 | 
               $sys_ticks = time() - $a;
  | 
        
        
            | 
            | 
           64 | 
              | 
        
        
            | 
            | 
           65 | 
               return $sys_ticks;
  | 
        
        
            | 
            | 
           66 | 
             } 
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
             function cpu_info () {
  | 
        
        
            | 
            | 
           69 | 
               $results = array(); 
  | 
        
        
            | 
            | 
           70 | 
               // $results['model'] = $this->grab_key('hw.model'); // need to expand this somehow...
  | 
        
        
            | 
            | 
           71 | 
               // $results['model'] = $this->grab_key('hw.machine');
  | 
        
        
            | 
            | 
           72 | 
               $results['model'] = ereg_replace('Processor type: ', '', execute_program('hostinfo', '| grep "Processor type"')); // get processor type
  | 
        
        
            | 
            | 
           73 | 
               $results['cpus'] = $this->grab_key('hw.ncpu');
  | 
        
        
            | 
            | 
           74 | 
               $results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000); // return cpu speed - Mhz
  | 
        
        
            | 
            | 
           75 | 
               $results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000); // return bus speed - Mhz
  | 
        
        
            | 
            | 
           76 | 
               $results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); // return l2 cache
  | 
        
        
            | 
            | 
           77 | 
              | 
        
        
            | 
            | 
           78 | 
               if (($this->grab_key('hw.model') == "PowerMac3,6") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G4 - (PowerPC 7450)';} // is Dual G4
  | 
        
        
            | 
            | 
           79 | 
               if (($this->grab_key('hw.model') == "PowerMac7,2") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G5 - (PowerPC 970)';} // is Dual G5
  | 
        
        
            | 
            | 
           80 | 
               if (($this->grab_key('hw.model') == "PowerMac1,1") && ($results['cpus'] == "1")) { $results['model'] = 'B&W G3 - (PowerPC 750)';} // is B&W G3
  | 
        
        
            | 
            | 
           81 | 
              | 
        
        
            | 
            | 
           82 | 
               return $results;
  | 
        
        
            | 
            | 
           83 | 
             } 
  | 
        
        
            | 
            | 
           84 | 
             // get the pci device information out of ioreg
  | 
        
        
            | 
            | 
           85 | 
             function pci () {
  | 
        
        
            | 
            | 
           86 | 
               $results = array();
  | 
        
        
            | 
            | 
           87 | 
               $s = $this->grab_ioreg('IOPCIDevice');
  | 
        
        
            | 
            | 
           88 | 
              | 
        
        
            | 
            | 
           89 | 
               $lines = explode("\n", $s);
  | 
        
        
            | 
            | 
           90 | 
               for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  | 
        
        
            | 
            | 
           91 | 
                 $ar_buf = preg_split("/\s+/", $lines[$i], 19);
  | 
        
        
            | 
            | 
           92 | 
                 $results[$i] = $ar_buf[0];
  | 
        
        
            | 
            | 
           93 | 
               } 
  | 
        
        
            | 
            | 
           94 | 
               asort($results);
  | 
        
        
            | 
            | 
           95 | 
               return array_values(array_unique($results));
  | 
        
        
            | 
            | 
           96 | 
             } 
  | 
        
        
            | 
            | 
           97 | 
             // get the ide device information out of ioreg
  | 
        
        
            | 
            | 
           98 | 
             function ide () {
  | 
        
        
            | 
            | 
           99 | 
               $results = array(); 
  | 
        
        
            | 
            | 
           100 | 
               // ioreg | grep "Media  <class IOMedia>"
  | 
        
        
            | 
            | 
           101 | 
               $s = $this->grab_ioreg('IOATABlockStorageDevice'); 
  | 
        
        
            | 
            | 
           102 | 
              | 
        
        
            | 
            | 
           103 | 
               $lines = explode("\n", $s);
  | 
        
        
            | 
            | 
           104 | 
               $j = 0;
  | 
        
        
            | 
            | 
           105 | 
               for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  | 
        
        
            | 
            | 
           106 | 
                 $ar_buf = preg_split("/\/\//", $lines[$i], 19);
  | 
        
        
            | 
            | 
           107 | 
              | 
        
        
            | 
            | 
           108 | 
                 if ( isset( $ar_buf[1] ) && $ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
  | 
        
        
            | 
            | 
           109 | 
                   $results[$j++]['model'] = $ar_buf[0];
  | 
        
        
            | 
            | 
           110 | 
                 } 
  | 
        
        
            | 
            | 
           111 | 
               } 
  | 
        
        
            | 
            | 
           112 | 
               asort($results);
  | 
        
        
            | 
            | 
           113 | 
               return array_values(array_unique($results));
  | 
        
        
            | 
            | 
           114 | 
             } 
  | 
        
        
            | 
            | 
           115 | 
              | 
        
        
            | 
            | 
           116 | 
             function memory () {
  | 
        
        
            | 
            | 
           117 | 
               $s = $this->grab_key('hw.memsize');
  | 
        
        
            | 
            | 
           118 | 
              | 
        
        
            | 
            | 
           119 | 
               $results['ram'] = array();
  | 
        
        
            | 
            | 
           120 | 
               $results['swap'] = array();
  | 
        
        
            | 
            | 
           121 | 
               $results['devswap'] = array();
  | 
        
        
            | 
            | 
           122 | 
              | 
        
        
            | 
            | 
           123 | 
               $pstat = execute_program('vm_stat'); // use darwin's vm_stat
  | 
        
        
            | 
            | 
           124 | 
               $lines = explode("\n", $pstat);
  | 
        
        
            | 
            | 
           125 | 
               for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  | 
        
        
            | 
            | 
           126 | 
                 $ar_buf = preg_split("/\s+/", $lines[$i], 19);
  | 
        
        
            | 
            | 
           127 | 
              | 
        
        
            | 
            | 
           128 | 
                 if ($i == 1) {
  | 
        
        
            | 
            | 
           129 | 
                   $results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from page sizes (each page = 4MB)
  | 
        
        
            | 
            | 
           130 | 
                 } 
  | 
        
        
            | 
            | 
           131 | 
               } 
  | 
        
        
            | 
            | 
           132 | 
              | 
        
        
            | 
            | 
           133 | 
               $results['ram']['total'] = $s / 1024;
  | 
        
        
            | 
            | 
           134 | 
               $results['ram']['shared'] = 0;
  | 
        
        
            | 
            | 
           135 | 
               $results['ram']['buffers'] = 0;
  | 
        
        
            | 
            | 
           136 | 
               $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
  | 
        
        
            | 
            | 
           137 | 
               $results['ram']['cached'] = 0;
  | 
        
        
            | 
            | 
           138 | 
              | 
        
        
            | 
            | 
           139 | 
               $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']); 
  | 
        
        
            | 
            | 
           140 | 
               // need to fix the swap info...
  | 
        
        
            | 
            | 
           141 | 
               // meanwhile silence and / or disable the swap information
  | 
        
        
            | 
            | 
           142 | 
               $pstat = execute_program('swapinfo', '-k', false);
  | 
        
        
            | 
            | 
           143 | 
               if( $pstat != "ERROR" ) {
  | 
        
        
            | 
            | 
           144 | 
                   $lines = explode("\n", $pstat);
  | 
        
        
            | 
            | 
           145 | 
              | 
        
        
            | 
            | 
           146 | 
                   for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  | 
        
        
            | 
            | 
           147 | 
                     $ar_buf = preg_split("/\s+/", $lines[$i], 6);
  | 
        
        
            | 
            | 
           148 | 
              | 
        
        
            | 
            | 
           149 | 
                     if ($i == 0) {
  | 
        
        
            | 
            | 
           150 | 
                       $results['swap']['total'] = 0;
  | 
        
        
            | 
            | 
           151 | 
                       $results['swap']['used'] = 0;
  | 
        
        
            | 
            | 
           152 | 
                       $results['swap']['free'] = 0;
  | 
        
        
            | 
            | 
           153 | 
                     } else {
  | 
        
        
            | 
            | 
           154 | 
                       $results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
  | 
        
        
            | 
            | 
           155 | 
                       $results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
  | 
        
        
            | 
            | 
           156 | 
                       $results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
  | 
        
        
            | 
            | 
           157 | 
                     } 
  | 
        
        
            | 
            | 
           158 | 
                   } 
  | 
        
        
            | 
            | 
           159 | 
                   $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
  | 
        
        
            | 
            | 
           160 | 
               }
  | 
        
        
            | 
            | 
           161 | 
              | 
        
        
            | 
            | 
           162 | 
               return $results;
  | 
        
        
            | 
            | 
           163 | 
             } 
  | 
        
        
            | 
            | 
           164 | 
              | 
        
        
            | 
            | 
           165 | 
             function network () {
  | 
        
        
            | 
            | 
           166 | 
               $netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link');
  | 
        
        
            | 
            | 
           167 | 
               $lines = explode("\n", $netstat);
  | 
        
        
            | 
            | 
           168 | 
               $results = array();
  | 
        
        
            | 
            | 
           169 | 
               for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
  | 
        
        
            | 
            | 
           170 | 
                 $ar_buf = preg_split("/\s+/", $lines[$i], 10);
  | 
        
        
            | 
            | 
           171 | 
                 if (!empty($ar_buf[0])) {
  | 
        
        
            | 
            | 
           172 | 
                   $results[$ar_buf[0]] = array();
  | 
        
        
            | 
            | 
           173 | 
              | 
        
        
            | 
            | 
           174 | 
                   $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
  | 
        
        
            | 
            | 
           175 | 
                   $results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
  | 
        
        
            | 
            | 
           176 | 
                   $results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
  | 
        
        
            | 
            | 
           177 | 
                   $results[$ar_buf[0]]['rx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
  | 
        
        
            | 
            | 
           178 | 
              | 
        
        
            | 
            | 
           179 | 
                   $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
  | 
        
        
            | 
            | 
           180 | 
                   $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
  | 
        
        
            | 
            | 
           181 | 
                   $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
  | 
        
        
            | 
            | 
           182 | 
                   $results[$ar_buf[0]]['tx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
  | 
        
        
            | 
            | 
           183 | 
              | 
        
        
            | 
            | 
           184 | 
                   $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
  | 
        
        
            | 
            | 
           185 | 
                   $results[$ar_buf[0]]['drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
  | 
        
        
            | 
            | 
           186 | 
                 } 
  | 
        
        
            | 
            | 
           187 | 
               } 
  | 
        
        
            | 
            | 
           188 | 
               return $results;
  | 
        
        
            | 
            | 
           189 | 
             } 
  | 
        
        
            | 
            | 
           190 | 
              | 
        
        
            | 
            | 
           191 | 
             function distroicon () {
  | 
        
        
            | 
            | 
           192 | 
               $result = 'Darwin.png';
  | 
        
        
            | 
            | 
           193 | 
               return($result);
  | 
        
        
            | 
            | 
           194 | 
             }
  | 
        
        
            | 
            | 
           195 | 
              | 
        
        
            | 
            | 
           196 | 
           } 
  | 
        
        
            | 
            | 
           197 | 
              | 
        
        
            | 
            | 
           198 | 
           ?>
  |