Update website
This commit is contained in:
parent
4413528994
commit
1d90fbf296
6865 changed files with 1091082 additions and 0 deletions
48
admin/phpMyAdmin/libraries/classes/Server/SysInfo/Base.php
Normal file
48
admin/phpMyAdmin/libraries/classes/Server/SysInfo/Base.php
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Server\SysInfo;
|
||||
|
||||
use const PHP_OS;
|
||||
|
||||
/**
|
||||
* Basic SysInfo class not providing any real data.
|
||||
*/
|
||||
class Base
|
||||
{
|
||||
/**
|
||||
* The OS name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $os = PHP_OS;
|
||||
|
||||
/**
|
||||
* Gets load information
|
||||
*
|
||||
* @return array with load data
|
||||
*/
|
||||
public function loadavg()
|
||||
{
|
||||
return ['loadavg' => 0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about memory usage
|
||||
*
|
||||
* @return array with memory usage data
|
||||
*/
|
||||
public function memory()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether class is supported in this environment
|
||||
*/
|
||||
public function supported(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
115
admin/phpMyAdmin/libraries/classes/Server/SysInfo/Linux.php
Normal file
115
admin/phpMyAdmin/libraries/classes/Server/SysInfo/Linux.php
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Server\SysInfo;
|
||||
|
||||
use function array_combine;
|
||||
use function array_merge;
|
||||
use function file_get_contents;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
use function is_readable;
|
||||
use function mb_strpos;
|
||||
use function mb_substr;
|
||||
use function preg_match_all;
|
||||
use function preg_split;
|
||||
|
||||
/**
|
||||
* Linux based SysInfo class
|
||||
*/
|
||||
class Linux extends Base
|
||||
{
|
||||
/**
|
||||
* The OS name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $os = 'Linux';
|
||||
|
||||
/**
|
||||
* Gets load information
|
||||
*
|
||||
* @return array<string, int> with load data
|
||||
*/
|
||||
public function loadavg()
|
||||
{
|
||||
$buf = file_get_contents('/proc/stat');
|
||||
if ($buf === false) {
|
||||
$buf = '';
|
||||
}
|
||||
|
||||
$pos = mb_strpos($buf, "\n");
|
||||
if ($pos === false) {
|
||||
$pos = 0;
|
||||
}
|
||||
|
||||
$nums = preg_split(
|
||||
'/\s+/',
|
||||
mb_substr(
|
||||
$buf,
|
||||
0,
|
||||
$pos
|
||||
)
|
||||
);
|
||||
|
||||
if (! is_array($nums)) {
|
||||
return ['busy' => 0, 'idle' => 0];
|
||||
}
|
||||
|
||||
return [
|
||||
'busy' => (int) $nums[1] + (int) $nums[2] + (int) $nums[3],
|
||||
'idle' => (int) $nums[4],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether class is supported in this environment
|
||||
*/
|
||||
public function supported(): bool
|
||||
{
|
||||
return @is_readable('/proc/meminfo') && @is_readable('/proc/stat');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about memory usage
|
||||
*
|
||||
* @return array with memory usage data
|
||||
*/
|
||||
public function memory()
|
||||
{
|
||||
$content = @file_get_contents('/proc/meminfo');
|
||||
if ($content === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
preg_match_all(SysInfo::MEMORY_REGEXP, $content, $matches);
|
||||
|
||||
/** @var array<string, int>|false $mem */
|
||||
$mem = array_combine($matches[1], $matches[2]);
|
||||
if ($mem === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$defaults = [
|
||||
'MemTotal' => 0,
|
||||
'MemFree' => 0,
|
||||
'Cached' => 0,
|
||||
'Buffers' => 0,
|
||||
'SwapTotal' => 0,
|
||||
'SwapFree' => 0,
|
||||
'SwapCached' => 0,
|
||||
];
|
||||
|
||||
$mem = array_merge($defaults, $mem);
|
||||
|
||||
foreach ($mem as $idx => $value) {
|
||||
$mem[$idx] = intval($value);
|
||||
}
|
||||
|
||||
$mem['MemUsed'] = $mem['MemTotal'] - $mem['MemFree'] - $mem['Cached'] - $mem['Buffers'];
|
||||
$mem['SwapUsed'] = $mem['SwapTotal'] - $mem['SwapFree'] - $mem['SwapCached'];
|
||||
|
||||
return $mem;
|
||||
}
|
||||
}
|
83
admin/phpMyAdmin/libraries/classes/Server/SysInfo/SunOs.php
Normal file
83
admin/phpMyAdmin/libraries/classes/Server/SysInfo/SunOs.php
Normal file
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Server\SysInfo;
|
||||
|
||||
use function explode;
|
||||
use function is_readable;
|
||||
use function shell_exec;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* SunOS based SysInfo class
|
||||
*/
|
||||
class SunOs extends Base
|
||||
{
|
||||
/**
|
||||
* The OS name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $os = 'SunOS';
|
||||
|
||||
/**
|
||||
* Read value from kstat
|
||||
*
|
||||
* @param string $key Key to read
|
||||
*
|
||||
* @return string with value
|
||||
*/
|
||||
private function kstat($key)
|
||||
{
|
||||
/** @psalm-suppress ForbiddenCode */
|
||||
$m = shell_exec('kstat -p d ' . $key);
|
||||
|
||||
if ($m) {
|
||||
[, $value] = explode("\t", trim($m), 2);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets load information
|
||||
*
|
||||
* @return array with load data
|
||||
*/
|
||||
public function loadavg()
|
||||
{
|
||||
$load1 = $this->kstat('unix:0:system_misc:avenrun_1min');
|
||||
|
||||
return ['loadavg' => $load1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether class is supported in this environment
|
||||
*/
|
||||
public function supported(): bool
|
||||
{
|
||||
return @is_readable('/proc/meminfo');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about memory usage
|
||||
*
|
||||
* @return array with memory usage data
|
||||
*/
|
||||
public function memory()
|
||||
{
|
||||
$pagesize = (int) $this->kstat('unix:0:seg_cache:slab_size');
|
||||
$mem = [];
|
||||
$mem['MemTotal'] = (int) $this->kstat('unix:0:system_pages:pagestotal') * $pagesize;
|
||||
$mem['MemUsed'] = (int) $this->kstat('unix:0:system_pages:pageslocked') * $pagesize;
|
||||
$mem['MemFree'] = (int) $this->kstat('unix:0:system_pages:pagesfree') * $pagesize;
|
||||
$mem['SwapTotal'] = (int) $this->kstat('unix:0:vminfo:swap_avail') / 1024;
|
||||
$mem['SwapUsed'] = (int) $this->kstat('unix:0:vminfo:swap_alloc') / 1024;
|
||||
$mem['SwapFree'] = (int) $this->kstat('unix:0:vminfo:swap_free') / 1024;
|
||||
|
||||
return $mem;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Server\SysInfo;
|
||||
|
||||
use function in_array;
|
||||
use function ucfirst;
|
||||
|
||||
use const PHP_OS;
|
||||
|
||||
/**
|
||||
* Library for extracting information about system memory and cpu.
|
||||
* Currently supports all Windows and Linux platforms
|
||||
*
|
||||
* This code is based on the OS Classes from the phpsysinfo project
|
||||
* (https://phpsysinfo.github.io/phpsysinfo/)
|
||||
*/
|
||||
class SysInfo
|
||||
{
|
||||
public const MEMORY_REGEXP = '/^(MemTotal|MemFree|Cached|Buffers|SwapCached|SwapTotal|SwapFree):\s+(.*)\s*kB/im';
|
||||
|
||||
/**
|
||||
* Returns OS type used for sysinfo class
|
||||
*
|
||||
* @param string $php_os PHP_OS constant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getOs($php_os = PHP_OS)
|
||||
{
|
||||
// look for common UNIX-like systems
|
||||
$unix_like = [
|
||||
'FreeBSD',
|
||||
'DragonFly',
|
||||
];
|
||||
if (in_array($php_os, $unix_like)) {
|
||||
$php_os = 'Linux';
|
||||
}
|
||||
|
||||
return ucfirst($php_os);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets SysInfo class matching current OS
|
||||
*
|
||||
* @return Base sysinfo class
|
||||
*/
|
||||
public static function get()
|
||||
{
|
||||
$php_os = self::getOs();
|
||||
|
||||
switch ($php_os) {
|
||||
case 'Linux':
|
||||
$sysInfo = new Linux();
|
||||
if ($sysInfo->supported()) {
|
||||
return $sysInfo;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'WINNT':
|
||||
$sysInfo = new WindowsNt();
|
||||
if ($sysInfo->supported()) {
|
||||
return $sysInfo;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'SunOS':
|
||||
$sysInfo = new SunOs();
|
||||
if ($sysInfo->supported()) {
|
||||
return $sysInfo;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return new Base();
|
||||
}
|
||||
}
|
147
admin/phpMyAdmin/libraries/classes/Server/SysInfo/WindowsNt.php
Normal file
147
admin/phpMyAdmin/libraries/classes/Server/SysInfo/WindowsNt.php
Normal file
|
@ -0,0 +1,147 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Server\SysInfo;
|
||||
|
||||
use COM;
|
||||
|
||||
use function class_exists;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function is_string;
|
||||
use function trim;
|
||||
|
||||
/**
|
||||
* Windows NT based SysInfo class
|
||||
*/
|
||||
class WindowsNt extends Base
|
||||
{
|
||||
/** @var COM|null */
|
||||
private $wmi;
|
||||
|
||||
/**
|
||||
* The OS name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $os = 'WINNT';
|
||||
|
||||
/**
|
||||
* Constructor to access to wmi database.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (! class_exists('COM')) {
|
||||
$this->wmi = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// initialize the wmi object
|
||||
$objLocator = new COM('WbemScripting.SWbemLocator');
|
||||
$this->wmi = $objLocator->ConnectServer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets load information
|
||||
*
|
||||
* @return array with load data
|
||||
*/
|
||||
public function loadavg()
|
||||
{
|
||||
$sum = 0;
|
||||
$buffer = $this->getWMI('Win32_Processor', ['LoadPercentage']);
|
||||
|
||||
foreach ($buffer as $load) {
|
||||
$value = $load['LoadPercentage'];
|
||||
$sum += $value;
|
||||
}
|
||||
|
||||
return ['loadavg' => $sum / count($buffer)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether class is supported in this environment
|
||||
*/
|
||||
public function supported(): bool
|
||||
{
|
||||
return $this->wmi !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads data from WMI
|
||||
*
|
||||
* @param string $strClass Class to read
|
||||
* @param array $strValue Values to read
|
||||
*
|
||||
* @return array with results
|
||||
*/
|
||||
private function getWMI($strClass, array $strValue = [])
|
||||
{
|
||||
$arrData = [];
|
||||
|
||||
$objWEBM = $this->wmi->Get($strClass);
|
||||
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
$arrProp = $objWEBM->Properties_;
|
||||
$arrWEBMCol = $objWEBM->Instances_();
|
||||
foreach ($arrWEBMCol as $objItem) {
|
||||
$arrInstance = [];
|
||||
foreach ($arrProp as $propItem) {
|
||||
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
|
||||
$name = $propItem->Name;
|
||||
if (! empty($strValue) && ! in_array($name, $strValue)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $objItem->$name;
|
||||
if (is_string($value)) {
|
||||
$arrInstance[$name] = trim($value);
|
||||
} else {
|
||||
$arrInstance[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$arrData[] = $arrInstance;
|
||||
}
|
||||
|
||||
return $arrData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information about memory usage
|
||||
*
|
||||
* @return array with memory usage data
|
||||
*/
|
||||
public function memory()
|
||||
{
|
||||
$buffer = $this->getWMI(
|
||||
'Win32_OperatingSystem',
|
||||
[
|
||||
'TotalVisibleMemorySize',
|
||||
'FreePhysicalMemory',
|
||||
]
|
||||
);
|
||||
$mem = [];
|
||||
$mem['MemTotal'] = $buffer[0]['TotalVisibleMemorySize'];
|
||||
$mem['MemFree'] = $buffer[0]['FreePhysicalMemory'];
|
||||
$mem['MemUsed'] = $mem['MemTotal'] - $mem['MemFree'];
|
||||
|
||||
$buffer = $this->getWMI('Win32_PageFileUsage');
|
||||
|
||||
$mem['SwapTotal'] = 0;
|
||||
$mem['SwapFree'] = 0;
|
||||
$mem['SwapUsed'] = 0;
|
||||
$mem['SwapPeak'] = 0;
|
||||
|
||||
foreach ($buffer as $swapdevice) {
|
||||
$mem['SwapTotal'] += $swapdevice['AllocatedBaseSize'] * 1024;
|
||||
$mem['SwapUsed'] += $swapdevice['CurrentUsage'] * 1024;
|
||||
$mem['SwapPeak'] += $swapdevice['PeakUsage'] * 1024;
|
||||
}
|
||||
|
||||
$mem['SwapFree'] = $mem['SwapTotal'] - $mem['SwapUsed'];
|
||||
|
||||
return $mem;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue