[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
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 21228 2006-04-06 13:52:08Z ralfbecker $ 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->addError("WARN", "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 // Our contstructor 33 // this function is run on the initialization of this class 34 function sysinfo () { 35 // $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)"; 36 // $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device"; 37 } 38 39 function grab_key ($key) { 40 $s = execute_program('sysctl', $key); 41 $s = ereg_replace($key . ': ', '', $s); 42 $s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys 43 44 return $s; 45 } 46 47 function grab_ioreg ($key) { 48 $s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"'); //ioreg -cls "$key" | grep "$key" 49 $s = ereg_replace('\|', '', $s); 50 $s = ereg_replace('\+\-\o', '', $s); 51 $s = ereg_replace('[ ]+', '', $s); 52 $s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts 53 54 return $s; 55 } 56 57 function get_sys_ticks () { 58 $a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value in seconds) 59 $sys_ticks = time() - $a; 60 61 return $sys_ticks; 62 } 63 64 function cpu_info () { 65 $results = array(); 66 // $results['model'] = $this->grab_key('hw.model'); // need to expand this somehow... 67 // $results['model'] = $this->grab_key('hw.machine'); 68 $results['model'] = ereg_replace('Processor type: ', '', execute_program('hostinfo', '| grep "Processor type"')); // get processor type 69 $results['cpus'] = $this->grab_key('hw.ncpu'); 70 $results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000); // return cpu speed - Mhz 71 $results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000); // return bus speed - Mhz 72 $results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); // return l2 cache 73 74 if (($this->grab_key('hw.model') == "PowerMac3,6") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G4 - (PowerPC 7450)';} // is Dual G4 75 if (($this->grab_key('hw.model') == "PowerMac7,2") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G5 - (PowerPC 970)';} // is Dual G5 76 77 return $results; 78 } 79 // get the pci device information out of ioreg 80 function pci () { 81 $results = array(); 82 $s = $this->grab_ioreg('IOPCIDevice'); 83 84 $lines = split("\n", $s); 85 for ($i = 0, $max = sizeof($lines); $i < $max; $i++) { 86 $ar_buf = preg_split("/\s+/", $lines[$i], 19); 87 $results[$i] = $ar_buf[0]; 88 } 89 asort($results); 90 return array_values(array_unique($results)); 91 } 92 // get the ide device information out of ioreg 93 function ide () { 94 $results = array(); 95 // ioreg | grep "Media <class IOMedia>" 96 $s = $this->grab_ioreg('IOATABlockStorageDevice'); 97 98 $lines = split("\n", $s); 99 $j = 0; 100 for ($i = 0, $max = sizeof($lines); $i < $max; $i++) { 101 $ar_buf = preg_split("/\/\//", $lines[$i], 19); 102 103 if ($ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) { 104 $results[$j++]['model'] = $ar_buf[0]; 105 } 106 } 107 asort($results); 108 return array_values(array_unique($results)); 109 } 110 111 function memory () { 112 $s = $this->grab_key('hw.memsize'); 113 114 $results['ram'] = array(); 115 116 $pstat = execute_program('vm_stat'); // use darwin's vm_stat 117 $lines = split("\n", $pstat); 118 for ($i = 0, $max = sizeof($lines); $i < $max; $i++) { 119 $ar_buf = preg_split("/\s+/", $lines[$i], 19); 120 121 if ($i == 1) { 122 $results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from page sizes (each page = 4MB) 123 } 124 } 125 126 $results['ram']['total'] = $s / 1024; 127 $results['ram']['shared'] = 0; 128 $results['ram']['buffers'] = 0; 129 $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free']; 130 $results['ram']['cached'] = 0; 131 $results['ram']['t_used'] = $results['ram']['used']; 132 $results['ram']['t_free'] = $results['ram']['free']; 133 134 $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']); 135 // need to fix the swap info... 136 $pstat = execute_program('swapinfo', '-k'); 137 $lines = split("\n", $pstat); 138 139 for ($i = 0, $max = sizeof($lines); $i < $max; $i++) { 140 $ar_buf = preg_split("/\s+/", $lines[$i], 6); 141 142 if ($i == 0) { 143 $results['swap']['total'] = 0; 144 $results['swap']['used'] = 0; 145 $results['swap']['free'] = 0; 146 } else { 147 $results['swap']['total'] = $results['swap']['total'] + $ar_buf[1]; 148 $results['swap']['used'] = $results['swap']['used'] + $ar_buf[2]; 149 $results['swap']['free'] = $results['swap']['free'] + $ar_buf[3]; 150 } 151 } 152 $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']); 153 154 return $results; 155 } 156 157 function network () { 158 $netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link'); 159 $lines = split("\n", $netstat); 160 $results = array(); 161 for ($i = 0, $max = sizeof($lines); $i < $max; $i++) { 162 $ar_buf = preg_split("/\s+/", $lines[$i]); 163 if (!empty($ar_buf[0])) { 164 $results[$ar_buf[0]] = array(); 165 166 $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5]; 167 $results[$ar_buf[0]]['rx_packets'] = $ar_buf[3]; 168 $results[$ar_buf[0]]['rx_errs'] = $ar_buf[4]; 169 $results[$ar_buf[0]]['rx_drop'] = $ar_buf[10]; 170 171 $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8]; 172 $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6]; 173 $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7]; 174 $results[$ar_buf[0]]['tx_drop'] = $ar_buf[10]; 175 176 $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7]; 177 $results[$ar_buf[0]]['drop'] = $ar_buf[10]; 178 } 179 } 180 return $results; 181 } 182 183 function filesystems () { 184 $df = execute_program('df', '-k'); 185 $mounts = split("\n", $df); 186 $fstype = array(); 187 188 $s = execute_program('mount'); 189 $lines = explode("\n", $s); 190 191 $i = 0; 192 while (list(, $line) = each($lines)) { 193 ereg('(.*) \((.*)\)', $line, $a); 194 195 $m = explode(' ', $a[0]); 196 $fsdev[$m[0]] = $a[2]; 197 } 198 199 for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) { 200 $ar_buf = preg_split("/\s+/", $mounts[$i], 6); 201 202 switch ($ar_buf[0]) { 203 case 'automount': // skip the automount entries 204 case 'devfs': // skip the dev filesystem 205 case 'fdesc': // skip the fdesc 206 case 'procfs': // skip the proc filesystem 207 case '<volfs>': // skip the vol filesystem 208 continue 2; 209 break; 210 } 211 if (hide_mount($ar_buf[5])) { 212 continue; 213 } 214 215 $results[$j] = array(); 216 217 $results[$j]['disk'] = $ar_buf[0]; 218 $results[$j]['size'] = $ar_buf[1]; 219 $results[$j]['used'] = $ar_buf[2]; 220 $results[$j]['free'] = $ar_buf[3]; 221 $results[$j]['percent'] = $ar_buf[4]; 222 $results[$j]['mount'] = $ar_buf[5]; 223 ($fstype[$ar_buf[5]]) ? $results[$j]['fstype'] = $fstype[$ar_buf[5]] : $results[$j]['fstype'] = $fsdev[$ar_buf[0]]; 224 $j++; 225 } 226 return $results; 227 } 228 229 function distroicon () { 230 $result = 'Darwin.png'; 231 return($result); 232 } 233 234 } 235 236 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |