📄 class.linux.inc.php
字号:
<?php // phpSysInfo - A PHP System Information Script// http://phpsysinfo.sourceforge.net/// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.// $Id: class.Linux.inc.php,v 1.88 2007/02/25 20:50:52 bigmichi1 Exp $if (!defined('IN_PHPSYSINFO')) { die("No Hacking");}require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');class sysinfo { var $inifile = "distros.ini"; var $icon = "unknown.png"; var $distro = "unknown"; var $parser; // get the distro name and icon when create the sysinfo object function sysinfo() { $this->parser = new Parser(); $this->parser->df_param = 'P'; $list = @parse_ini_file(APP_ROOT . "/" . $this->inifile, true); if (!$list) { return; } $distro_info = execute_program('lsb_release','-a 2> /dev/null', false); // We have the '2> /dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown if ( $distro_info != 'ERROR') { $distro_tmp = split("\n",$distro_info); foreach( $distro_tmp as $info ) { $info_tmp = split(':', $info, 2); $distro[ $info_tmp[0] ] = trim($info_tmp[1]); } if( !isset( $list[$distro['Distributor ID']] ) ){ return; } $this->icon = isset($list[$distro['Distributor ID']]["Image"]) ? $list[$distro['Distributor ID']]["Image"] : $this->icon; $this->distro = $distro['Description']; } else { // Fall back in case 'lsb_release' does not exist ;) foreach ($list as $section => $distribution) { if (!isset($distribution["Files"])) { continue; } else { foreach (explode(";", $distribution["Files"]) as $filename) { if (file_exists($filename)) { $buf = rfts( $filename ); $this->icon = isset($distribution["Image"]) ? $distribution["Image"] : $this->icon; $this->distro = isset($distribution["Name"]) ? $distribution["Name"] . " " . trim($buf) : trim($buf); break 2; } } } } } } // get our apache SERVER_NAME or vhost function vhostname () { if (! ($result = getenv('SERVER_NAME'))) { $result = 'N.A.'; } return $result; } // get the IP address of our vhost name function vip_addr () { return gethostbyname($this->vhostname()); } // get our canonical hostname function chostname () { $result = rfts( '/proc/sys/kernel/hostname', 1 ); if ( $result == "ERROR" ) { $result = "N.A."; } else { $result = gethostbyaddr( gethostbyname( trim( $result ) ) ); } return $result; } // get the IP address of our canonical hostname function ip_addr () { if (!($result = getenv('SERVER_ADDR'))) { $result = gethostbyname($this->chostname()); } return $result; } function kernel () { $buf = rfts( '/proc/version', 1 ); if ( $buf == "ERROR" ) { $result = "N.A."; } else { if (preg_match('/version (.*?) /', $buf, $ar_buf)) { $result = $ar_buf[1]; if (preg_match('/SMP/', $buf)) { $result .= ' (SMP)'; } } } return $result; } function uptime () { $buf = rfts( '/proc/uptime', 1 ); $ar_buf = split( ' ', $buf ); $result = trim( $ar_buf[0] ); return $result; } function users () { $strResult = 0; $strBuf = execute_program('who', '-q'); if( $strBuf != "ERROR" ) { $arrWho = split( '=', $strBuf ); $strResult = $arrWho[1]; } return $strResult; } function loadavg ($bar = false) { $buf = rfts( '/proc/loadavg' ); if( $buf == "ERROR" ) { $results['avg'] = array('N.A.', 'N.A.', 'N.A.'); } else { $results['avg'] = preg_split("/\s/", $buf, 4); unset($results['avg'][3]); // don't need the extra values, only first three } if ($bar) { $buf = rfts( '/proc/stat', 1 ); if( $buf != "ERROR" ) { sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae); // Find out the CPU load // user + sys = load // total = total $load = $ab + $ac + $ad; // cpu.user + cpu.sys $total = $ab + $ac + $ad + $ae; // cpu.total // we need a second value, wait 1 second befor getting (< 1 second no good value will occour) sleep(1); $buf = rfts( '/proc/stat', 1 ); sscanf($buf, "%*s %Ld %Ld %Ld %Ld", $ab, $ac, $ad, $ae); $load2 = $ab + $ac + $ad; $total2 = $ab + $ac + $ad + $ae; $results['cpupercent'] = (100*($load2 - $load)) / ($total2 - $total); } } return $results; } function cpu_info () { $bufr = rfts( '/proc/cpuinfo' ); $results = array("cpus" => 0); if ( $bufr != "ERROR" ) { $bufe = explode("\n", $bufr); $results = array('cpus' => 0, 'bogomips' => 0); $ar_buf = array(); foreach( $bufe as $buf ) { $arrBuff = preg_split('/\s+:\s+/', trim($buf)); if( count( $arrBuff ) == 2 ) { $key = $arrBuff[0]; $value = $arrBuff[1]; // All of the tags here are highly architecture dependant. // the only way I could reconstruct them for machines I don't // have is to browse the kernel source. So if your arch isn't // supported, tell me you want it written in. switch ($key) { case 'model name': $results['model'] = $value; break; case 'cpu MHz': $results['cpuspeed'] = sprintf('%.2f', $value); break; case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x $results['cpuspeed'] = sprintf('%.2f', $value / 1000000); break; case 'clock': // For PPC arch (damn borked POS) $results['cpuspeed'] = sprintf('%.2f', $value); break; case 'cpu': // For PPC arch (damn borked POS) $results['model'] = $value; break; case 'L2 cache': // More for PPC $results['cache'] = $value; break; case 'revision': // For PPC arch (damn borked POS) $results['model'] .= ' ( rev: ' . $value . ')'; break; case 'cpu model': // For Alpha arch - 2.2.x $results['model'] .= ' (' . $value . ')'; break; case 'cache size': $results['cache'] = $value; break; case 'bogomips': $results['bogomips'] += $value; break; case 'BogoMIPS': // For alpha arch - 2.2.x $results['bogomips'] += $value; break; case 'BogoMips': // For sparc arch $results['bogomips'] += $value; break; case 'cpus detected': // For Alpha arch - 2.2.x $results['cpus'] += $value; break; case 'system type': // Alpha arch - 2.2.x $results['model'] .= ', ' . $value . ' '; break; case 'platform string': // Alpha arch - 2.2.x $results['model'] .= ' (' . $value . ')'; break; case 'processor': $results['cpus'] += 1; break; case 'Cpu0ClkTck': // Linux sparc64 $results['cpuspeed'] = sprintf('%.2f', hexdec($value) / 1000000); break; case 'Cpu0Bogo': // Linux sparc64 & sparc32 $results['bogomips'] = $value; break; case 'ncpus probed': // Linux sparc64 & sparc32 $results['cpus'] = $value; break; } } } // sparc64 specific code follows // This adds the ability to display the cache that a CPU has // Originally made by Sven Blumenstein <bazik@gentoo.org> in 2004 // Modified by Tom Weustink <freshy98@gmx.net> in 2004 $sparclist = array('SUNW,UltraSPARC@0,0', 'SUNW,UltraSPARC-II@0,0', 'SUNW,UltraSPARC@1c,0', 'SUNW,UltraSPARC-IIi@1c,0', 'SUNW,UltraSPARC-II@1c,0', 'SUNW,UltraSPARC-IIe@0,0'); foreach ($sparclist as $name) { $buf = rfts( '/proc/openprom/' . $name . '/ecache-size',1 , 32, false ); if( $buf != "ERROR" ) { $results['cache'] = base_convert($buf, 16, 10)/1024 . ' KB'; } } // sparc64 specific code ends // XScale detection code if ( $results['cpus'] == 0 ) { foreach( $bufe as $buf ) { $fields = preg_split('/\s*:\s*/', trim($buf), 2); if (sizeof($fields) == 2) { list($key, $value) = $fields; switch($key) { case 'Processor': $results['cpus'] += 1; $results['model'] = $value; break; case 'BogoMIPS': //BogoMIPS are not BogoMIPS on this CPU, it's the speed, no BogoMIPS available $results['cpuspeed'] = $value; break; case 'I size': $results['cache'] = $value; break; case 'D size': $results['cache'] += $value; break; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -