diff --git a/ChangeLog b/ChangeLog index a69b5c5ab9..562f093e4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -19,6 +19,7 @@ phpMyAdmin - ChangeLog - bug #3559925 [privileges] Incorrect updating of the list of users - bug #3561224 [edit] cell edit date field with empty date fills in current date - bug #3559955 [edit] current_date from function drop down fails on update +- add support for Solaris and FreeBSD system load and memory display in server status 3.5.2.2 (2012-08-12) - [security] Fixed XSS vulnerabilities, see PMASA-2012-4 diff --git a/libraries/Advisor.class.php b/libraries/Advisor.class.php index 62ba645d51..0c031405ba 100644 --- a/libraries/Advisor.class.php +++ b/libraries/Advisor.class.php @@ -33,7 +33,7 @@ class Advisor } // Add total memory to variables as well include_once 'libraries/sysinfo.lib.php'; - $sysinfo = getSysInfo(); + $sysinfo = PMA_getSysInfo(); $memory = $sysinfo->memory(); $this->variables['system_memory'] = $memory['MemTotal']; diff --git a/libraries/sysinfo.lib.php b/libraries/sysinfo.lib.php index c6408ff631..e825540e29 100644 --- a/libraries/sysinfo.lib.php +++ b/libraries/sysinfo.lib.php @@ -9,24 +9,43 @@ * @package PhpMyAdmin */ +/** + * Wrap the PHP_OS constant + * + * @return string + */ +function PMA_getSysInfoOs() +{ + $php_os = PHP_OS; + + // look for common UNIX-like systems + $unix_like = array('FreeBSD'); + if (in_array($php_os, $unix_like)) { + $php_os = 'Linux'; + } + + return ucfirst($php_os); +} + /** * @return array */ -function getSysInfo() +function PMA_getSysInfo() { - $supported = array('Linux', 'WINNT'); + $php_os = PMA_getSysInfoOs(); + $supported = array('Linux', 'WINNT', 'SunOS'); $sysinfo = array(); - if (in_array(PHP_OS, $supported)) { - return eval("return new ".PHP_OS."();"); + if (in_array($php_os, $supported)) { + return eval("return new PMA_sysinfo".$php_os."();"); } - return $sysinfo; + return new PMA_Sysinfo_Default; } -class WINNT +class PMA_sysinfoWinnt { private $_wmi; @@ -104,7 +123,7 @@ class WINNT } } -class Linux +class PMA_sysinfoLinux { public $os = 'Linux'; @@ -127,3 +146,54 @@ class Linux return $mem; } } + +class PMA_sysinfoSunos +{ + public $os = 'SunOS'; + + private function _kstat($key) + { + if ($m = shell_exec('kstat -p d '.$key)) { + list($key, $value) = preg_split("/\t/", trim($m), 2); + return $value; + } else { + return ''; + } + } + + public function loadavg() { + $load1 = $this->_kstat('unix:0:system_misc:avenrun_1min'); + + return array('loadavg' => $load1); + } + + public function memory() { + preg_match_all('/^(MemTotal|MemFree|Cached|Buffers|SwapCached|SwapTotal|SwapFree):\s+(.*)\s*kB/im', file_get_contents('/proc/meminfo'), $matches); + + $pagesize = $this->_kstat('unix:0:seg_cache:slab_size'); + $mem['MemTotal'] = $this->_kstat('unix:0:system_pages:pagestotal') * $pagesize; + $mem['MemUsed'] = $this->_kstat('unix:0:system_pages:pageslocked') * $pagesize; + $mem['MemFree'] = $this->_kstat('unix:0:system_pages:pagesfree') * $pagesize; + $mem['SwapTotal'] = $this->_kstat('unix:0:vminfo:swap_avail') * $pagesize; + $mem['SwapUsed'] = $this->_kstat('unix:0:vminfo:swap_alloc') * $pagesize; + $mem['SwapFree'] = $this->_kstat('unix:0:vminfo:swap_free') * $pagesize; + + foreach ($mem as $idx=>$value) + $mem[$idx] = intval($value); + + return $mem; + } +} + +class PMA_sysinfoDefault +{ + public $os = PHP_OS; + + public function loadavg() { + return array('loadavg' => 0); + } + + public function memory() { + return array(); + } +} diff --git a/server_status.php b/server_status.php index 0ebf32d7ec..fe701064a7 100644 --- a/server_status.php +++ b/server_status.php @@ -137,13 +137,13 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { case 'cpu': if (!$sysinfo) { include_once 'libraries/sysinfo.lib.php'; - $sysinfo = getSysInfo(); + $sysinfo = PMA_getSysInfo(); } if (!$cpuload) { $cpuload = $sysinfo->loadavg(); } - if (PHP_OS == 'Linux') { + if (PMA_getSysInfoOs() == 'Linux') { $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle']; $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy']; } else @@ -154,7 +154,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { case 'memory': if (!$sysinfo) { include_once 'libraries/sysinfo.lib.php'; - $sysinfo = getSysInfo(); + $sysinfo = PMA_getSysInfo(); } if (!$memory) { $memory = $sysinfo->memory();