class.linux.inc.php

来自「eGroupWare is a multi-user, web-based gr」· PHP 代码 · 共 440 行 · 第 1/2 页

PHP
440
字号
<?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.1 2004/01/20 20:51:36 reinerj Exp $//class sysinfo {    // get our apache SERVER_NAME or vhost    function vhostname () {        if (! ($result = getenv('SERVER_NAME'))) {            $result = 'N.A.';        }        return $result;    }    // get our canonical hostname    function chostname () {        if ($fp = fopen('/proc/sys/kernel/hostname','r')) {            $result = trim(fgets($fp, 4096));            fclose($fp);            $result = gethostbyaddr(gethostbyname($result));        } else {            $result = 'N.A.';        }        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 () {        if ($fd = fopen('/proc/version', 'r')) {            $buf = fgets($fd, 4096);            fclose($fd);            if (preg_match('/version (.*?) /', $buf, $ar_buf)) {                $result = $ar_buf[1];                if (preg_match('/SMP/', $buf)) {                    $result .= ' (SMP)';                }            } else {                $result = 'N.A.';            }        } else {            $result = 'N.A.';        }        return $result;    }    function uptime () {        global $text;        $fd = fopen('/proc/uptime', 'r');        $ar_buf = split(' ', fgets($fd, 4096));        fclose($fd);        $sys_ticks = trim($ar_buf[0]);        $min   = $sys_ticks / 60;        $hours = $min / 60;        $days  = floor($hours / 24);        $hours = floor($hours - ($days * 24));        $min   = floor($min - ($days * 60 * 24) - ($hours * 60));        if ($days != 0) {            $result = "$days " . $text['days'] . " ";        }        if ($hours != 0) {            $result .= "$hours " . $text['hours'] . " ";        }        $result .= "$min " . $text['minutes'];        return $result;    }    function users () {        $who = split('=', execute_program('who', '-q'));        $result = $who[1];        return $result;    }    function loadavg () {        if ($fd = fopen('/proc/loadavg', 'r')) {            $results = split(' ', fgets($fd, 4096));            fclose($fd);        } else {            $results = array('N.A.','N.A.','N.A.');        }        return $results;    }    function cpu_info () {        $results = array();        $ar_buf = array();        if ($fd = fopen('/proc/cpuinfo', 'r')) {            while ($buf = fgets($fd, 4096)) {                list($key, $value) = preg_split('/\s+:\s+/', trim($buf), 2);                // 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['mhz'] = sprintf('%.2f', $value);                        break;                    case 'cycle frequency [Hz]': // For Alpha arch - 2.2.x                        $results['mhz'] = sprintf('%.2f', $value/1000000);                        break;                    case 'clock': // For PPC arch (damn borked POS)                        $results['mhz'] = sprintf('%.2f', $value);                        break;                    case 'cpu': // For PPC arch (damn borked POS)                        $results['model'] = $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'] += 1;                        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;                }            }            fclose($fd);        }        $keys = array_keys($results);        $keys2be = array('model', 'mhz', 'cache', 'bogomips', 'cpus');        while ($ar_buf = each($keys2be)) {            if (! in_array($ar_buf[1], $keys)) {                $results[$ar_buf[1]] = 'N.A.';            }        }        return $results;    }    function pci () {        $results = array();        if ($fd = fopen('/proc/pci', 'r')) {            while ($buf = fgets($fd, 4096)) {                if (preg_match('/Bus/', $buf)) {                    $device = 1;                    continue;                }                if ($device) {                    list($key, $value) = split(': ', $buf, 2);                    if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) {                        $results[] = preg_replace('/\([^\)]+\)\.$/', '', trim($value));                    }                    $device = 0;                }            }        }        return $results;    }    function ide () {        $results = array();        $handle = opendir('/proc/ide');        while ($file = readdir($handle)) {            if (preg_match('/^hd/', $file)) {                $results[$file] = array();

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?