diff --git a/dist/prober.php b/dist/prober.php index 3fb88200..a724c835 100644 --- a/dist/prober.php +++ b/dist/prober.php @@ -85,16 +85,16 @@ HTML; } return $content; } private function getLoadedExtensions($sorted = false) { $exts = \get_loaded_extensions(); if ($sorted) { \sort($exts); } return $exts; } private function isOpcEnabled() { $isOpcEnabled = \function_exists('\\opcache_get_configuration'); if ($isOpcEnabled) { $isOpcEnabled = \opcache_get_configuration(); $isOpcEnabled = isset($isOpcEnabled['directives']['opcache.enable']) && true === $isOpcEnabled['directives']['opcache.enable']; } return $isOpcEnabled; } } -namespace InnStudio\Prober\Helper; use InnStudio\Prober\I18n\I18nApi; class Api { public static function dieJson($data) { \header('Content-Type: application/json'); die(\json_encode($data)); } public static function isAction($action) { return \filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING) === $action; } public static function getWinCpuUsage() { $cpus = array(); if (\class_exists('\\COM')) { $wmi = new \COM('Winmgmts://'); $server = $wmi->execquery('SELECT LoadPercentage FROM Win32_Processor'); $cpus = array(); foreach ($server as $cpu) { $total += (int) $cpu->loadpercentage; } $total = (int) $total / \count($server); $cpus['idle'] = 100 - $total; $cpus['user'] = $total; } else { \exec('wmic cpu get LoadPercentage', $p); if (isset($p[1])) { $percent = (int) $p[1]; $cpus['idle'] = 100 - $percent; $cpus['user'] = $percent; } } return $cpus; } public static function getNetworkStats() { $filePath = '/proc/net/dev'; if ( ! \is_readable($filePath)) { return I18nApi::_('Unavailable'); } static $eths = null; if (null !== $eths) { return $eths; } $lines = \file($filePath); unset($lines[0], $lines[1]); $eths = array(); foreach ($lines as $line) { $line = \preg_replace('/\s+/', ' ', \trim($line)); $lineArr = \explode(':', $line); $numberArr = \explode(' ', \trim($lineArr[1])); $eths[$lineArr[0]] = array( 'rx' => (int) $numberArr[0], 'tx' => (int) $numberArr[8], ); } return $eths; } public static function getBtn($tx, $url) { return <<execquery('SELECT LoadPercentage FROM Win32_Processor'); $cpus = array(); foreach ($server as $cpu) { $total += (int) $cpu->loadpercentage; } $total = (int) $total / \count($server); $cpus['idle'] = 100 - $total; $cpus['user'] = $total; } else { \exec('wmic cpu get LoadPercentage', $p); if (isset($p[1])) { $percent = (int) $p[1]; $cpus['idle'] = 100 - $percent; $cpus['user'] = $percent; } } return $cpus; } public static function getNetworkStats() { $filePath = '/proc/net/dev'; if ( ! \is_readable($filePath)) { return I18nApi::_('Unavailable'); } static $eths = null; if (null !== $eths) { return $eths; } $lines = \file($filePath); unset($lines[0], $lines[1]); $eths = array(); foreach ($lines as $line) { $line = \preg_replace('/\s+/', ' ', \trim($line)); $lineArr = \explode(':', $line); $numberArr = \explode(' ', \trim($lineArr[1])); $eths[$lineArr[0]] = array( 'rx' => (int) $numberArr[0], 'tx' => (int) $numberArr[8], ); } return $eths; } public static function getBtn($tx, $url) { return <<{$tx} HTML; -} public static function getDiskTotalSpace($human = false) { static $space = null; if (null === $space) { $dir = self::isWin() ? 'C:' : '/'; if ( ! \is_readable($dir)) { $space = 0; return 0; } $space = \disk_total_space($dir); } if ( ! $space) { return 0; } if (true === $human) { return self::formatBytes($space); } return $space; } public static function getDiskFreeSpace($human = false) { static $space = null; if (null === $space) { try { $space = \disk_free_space('/'); } catch (\Exception $e) { $space = 0; } } if ( ! $space) { return 0; } if (true === $human) { return self::formatBytes($space); } return $space; } public static function getCpuModel() { $filePath = '/proc/cpuinfo'; if ( ! \is_readable($filePath)) { return I18nApi::_('Unavailable'); } $content = \file_get_contents($filePath); $cores = \substr_count($content, 'cache size'); $lines = \explode("\n", $content); $modelName = \explode(':', $lines[4]); $modelName = \trim($modelName[1]); $cacheSize = \explode(':', $lines[8]); $cacheSize = \trim($cacheSize[1]); return "{$cores} x {$modelName} / " . \sprintf(I18nApi::_('%s cache'), $cacheSize); } public static function getServerTime() { return \date('Y-m-d H:i:s'); } public static function getServerUpTime() { $filePath = '/proc/uptime'; if ( ! \is_readable($filePath)) { return I18nApi::_('Unavailable'); } $str = \file_get_contents($filePath); $num = (float) $str; $secs = \fmod($num, 60); $num = (int) ($num / 60); $mins = $num % 60; $num = (int) ($num / 60); $hours = $num % 24; $num = (int) ($num / 24); $days = $num; return \sprintf( I18nApi::_('%1$dd %2$dh %3$dm %4$ds'), $days, $hours, $mins, $secs ); } public static function getErrNameByCode($code) { $levels = array( \E_ALL => 'E_ALL', \E_USER_DEPRECATED => 'E_USER_DEPRECATED', \E_DEPRECATED => 'E_DEPRECATED', \E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', \E_STRICT => 'E_STRICT', \E_USER_NOTICE => 'E_USER_NOTICE', \E_USER_WARNING => 'E_USER_WARNING', \E_USER_ERROR => 'E_USER_ERROR', \E_COMPILE_WARNING => 'E_COMPILE_WARNING', \E_COMPILE_ERROR => 'E_COMPILE_ERROR', \E_CORE_WARNING => 'E_CORE_WARNING', \E_CORE_ERROR => 'E_CORE_ERROR', \E_NOTICE => 'E_NOTICE', \E_PARSE => 'E_PARSE', \E_WARNING => 'E_WARNING', \E_ERROR => 'E_ERROR', ); $result = ''; foreach ($levels as $number => $name) { if (($code & $number) == $number) { $result .= ('' != $result ? ', ' : '') . $name; } } return $result; } public static function getIni($id, $forceSet = null) { if (true === $forceSet) { $ini = 1; } elseif (false === $forceSet) { $ini = 0; } else { $ini = \ini_get($id); } if ( ! \is_numeric($ini) && '' !== (string) $ini) { return $ini; } if (1 === (int) $ini) { return << 'E_ALL', \E_USER_DEPRECATED => 'E_USER_DEPRECATED', \E_DEPRECATED => 'E_DEPRECATED', \E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', \E_STRICT => 'E_STRICT', \E_USER_NOTICE => 'E_USER_NOTICE', \E_USER_WARNING => 'E_USER_WARNING', \E_USER_ERROR => 'E_USER_ERROR', \E_COMPILE_WARNING => 'E_COMPILE_WARNING', \E_COMPILE_ERROR => 'E_COMPILE_ERROR', \E_CORE_WARNING => 'E_CORE_WARNING', \E_CORE_ERROR => 'E_CORE_ERROR', \E_NOTICE => 'E_NOTICE', \E_PARSE => 'E_PARSE', \E_WARNING => 'E_WARNING', \E_ERROR => 'E_ERROR', ); $result = ''; foreach ($levels as $number => $name) { if (($code & $number) == $number) { $result .= ('' != $result ? ', ' : '') . $name; } } return $result; } public static function getIni($id, $forceSet = null) { if (true === $forceSet) { $ini = 1; } elseif (false === $forceSet) { $ini = 0; } else { $ini = \ini_get($id); } if ( ! \is_numeric($ini) && '' !== (string) $ini) { return $ini; } if (1 === (int) $ini) { return <<✓ HTML; -} elseif (0 === (int) $ini) { return <<× HTML; -} return $ini; } public static function isWin() { return PHP_OS === 'WINNT'; } public static function htmlMinify($buffer) { \preg_match_all('#\.*\<\/textarea\>#Uis', $buffer, $foundTxt); \preg_match_all('#\.*\<\/pre\>#Uis', $buffer, $foundPre); $textareas = array(); foreach (\array_keys($foundTxt[0]) as $item) { $textareas[] = ''; } $pres = array(); foreach (\array_keys($foundPre[0]) as $item) { $pres[] = '
' . $item . '
'; } $buffer = \str_replace($foundTxt[0], $textareas, $buffer); $buffer = \str_replace($foundPre[0], $pres, $buffer); $search = array( '/\>[^\S ]+/s', '/[^\S ]+\', '<', '\\1', ); $buffer = \preg_replace($search, $replace, $buffer); $textareas = array(); foreach (\array_keys($foundTxt[0]) as $item) { $textareas[] = ''; } $pres = array(); foreach (\array_keys($foundPre[0]) as $item) { $pres[] = '
' . $item . '
'; } $buffer = \str_replace($textareas, $foundTxt[0], $buffer); $buffer = \str_replace($pres, $foundPre[0], $buffer); return $buffer; } public static function getClientIp() { $keys = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR'); foreach ($keys as $key) { if ( ! isset($_SERVER[$key])) { continue; } $ip = \array_filter(\explode(',', $_SERVER[$key])); $ip = \filter_var(\end($ip), FILTER_VALIDATE_IP); if ($ip) { return $ip; } } return ''; } public static function getCpuUsage() { static $cpu = null; if (null !== $cpu) { return $cpu; } if (self::isWin()) { $cpu = self::getWinCpuUsage(); return $cpu; } $filePath = ('/proc/stat'); if ( ! \is_readable($filePath)) { $cpu = array(); return $cpu; } $stat1 = \file($filePath); \sleep(1); $stat2 = \file($filePath); $info1 = \explode(' ', \preg_replace('!cpu +!', '', $stat1[0])); $info2 = \explode(' ', \preg_replace('!cpu +!', '', $stat2[0])); $dif = array(); $dif['user'] = $info2[0] - $info1[0]; $dif['nice'] = $info2[1] - $info1[1]; $dif['sys'] = $info2[2] - $info1[2]; $dif['idle'] = $info2[3] - $info1[3]; $total = \array_sum($dif); $cpu = array(); foreach ($dif as $x => $y) { $cpu[$x] = \round($y / $total * 100, 1); } return $cpu; } public static function getHumanCpuUsageDetail() { $cpu = self::getCpuUsage(); if ( ! $cpu) { return ''; } $html = ''; foreach ($cpu as $k => $v) { $html .= <<.*\<\/textarea\>#Uis', $buffer, $foundTxt); \preg_match_all('#\.*\<\/pre\>#Uis', $buffer, $foundPre); $textareas = array(); foreach (\array_keys($foundTxt[0]) as $item) { $textareas[] = ''; } $pres = array(); foreach (\array_keys($foundPre[0]) as $item) { $pres[] = '
' . $item . '
'; } $buffer = \str_replace($foundTxt[0], $textareas, $buffer); $buffer = \str_replace($foundPre[0], $pres, $buffer); $search = array( '/\>[^\S ]+/s', '/[^\S ]+\', '<', '\\1', ); $buffer = \preg_replace($search, $replace, $buffer); $textareas = array(); foreach (\array_keys($foundTxt[0]) as $item) { $textareas[] = ''; } $pres = array(); foreach (\array_keys($foundPre[0]) as $item) { $pres[] = '
' . $item . '
'; } $buffer = \str_replace($textareas, $foundTxt[0], $buffer); $buffer = \str_replace($pres, $foundPre[0], $buffer); return $buffer; } public static function getClientIp() { $keys = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR'); foreach ($keys as $key) { if ( ! isset($_SERVER[$key])) { continue; } $ip = \array_filter(\explode(',', $_SERVER[$key])); $ip = \filter_var(\end($ip), \FILTER_VALIDATE_IP); if ($ip) { return $ip; } } return ''; } public static function getCpuUsage() { static $cpu = null; if (null !== $cpu) { return $cpu; } if (self::isWin()) { $cpu = self::getWinCpuUsage(); return $cpu; } $filePath = ('/proc/stat'); if ( ! \is_readable($filePath)) { $cpu = array(); return $cpu; } $stat1 = \file($filePath); \sleep(1); $stat2 = \file($filePath); $info1 = \explode(' ', \preg_replace('!cpu +!', '', $stat1[0])); $info2 = \explode(' ', \preg_replace('!cpu +!', '', $stat2[0])); $dif = array(); $dif['user'] = $info2[0] - $info1[0]; $dif['nice'] = $info2[1] - $info1[1]; $dif['sys'] = $info2[2] - $info1[2]; $dif['idle'] = $info2[3] - $info1[3]; $total = \array_sum($dif); $cpu = array(); foreach ($dif as $x => $y) { $cpu[$x] = \round($y / $total * 100, 1); } return $cpu; } public static function getHumanCpuUsageDetail() { $cpu = self::getCpuUsage(); if ( ! $cpu) { return ''; } $html = ''; foreach ($cpu as $k => $v) { $html .= <<{$k} {$v} HTML; @@ -155,7 +155,7 @@ getContent(); ?> $this->_('PHP info detail'), 'content' => Helper::getBtn("👆 {$this->_('Click to check')}", '?action=phpInfo'), ), array( 'label' => $this->_('Version'), 'content' => PHP_VERSION, ), array( 'label' => $this->_('SAPI interface'), 'content' => PHP_SAPI, ), array( 'label' => $this->_('Error reporting'), 'title' => "error_reporting: {$errLevels}", 'content' => Helper::strcut($errLevels), ), array( 'label' => $this->_('Max memory limit'), 'title' => 'memory_limit', 'content' => \ini_get('memory_limit'), ), array( 'label' => $this->_('Max POST size'), 'title' => 'post_max_size', 'content' => \ini_get('post_max_size'), ), array( 'label' => $this->_('Max upload size'), 'title' => 'upload_max_filesize', 'content' => \ini_get('upload_max_filesize'), ), array( 'label' => $this->_('Max input variables'), 'title' => 'max_input_vars', 'content' => \ini_get('max_input_vars'), ), array( 'label' => $this->_('Max execution time'), 'title' => 'max_execution_time', 'content' => \ini_get('max_execution_time'), ), array( 'label' => $this->_('Timeout for socket'), 'title' => 'default_socket_timeout', 'content' => \ini_get('default_socket_timeout'), ), array( 'label' => $this->_('Display errors'), 'title' => 'display_errors', 'content' => Helper::getIni('display_errors'), ), array( 'label' => $this->_('Treatment URLs file'), 'title' => 'allow_url_fopen', 'content' => Helper::getIni('allow_url_fopen'), ), array( 'label' => $this->_('SMTP support'), 'title' => 'SMTP', 'content' => Helper::getIni('SMTP') ?: Helper::getIni(0, false), ), array( 'col' => '1-1', 'label' => $this->_('Disabled functions'), 'title' => 'disable_functions', 'content' => \implode(', ', \explode(',', Helper::getIni('disable_functions'))) ?: '-', ), ); $content = ''; foreach ($items as $item) { $title = isset($item['title']) ? "title=\"{$item['title']}\"" : ''; $col = isset($item['col']) ? $item['col'] : '1-3'; $id = isset($item['id']) ? "id=\"{$item['id']}\"" : ''; $content .= << $this->_('PHP info detail'), 'content' => Helper::getBtn("👆 {$this->_('Click to check')}", '?action=phpInfo'), ), array( 'label' => $this->_('Version'), 'content' => \PHP_VERSION, ), array( 'label' => $this->_('SAPI interface'), 'content' => \PHP_SAPI, ), array( 'label' => $this->_('Error reporting'), 'title' => "error_reporting: {$errLevels}", 'content' => Helper::strcut($errLevels), ), array( 'label' => $this->_('Max memory limit'), 'title' => 'memory_limit', 'content' => \ini_get('memory_limit'), ), array( 'label' => $this->_('Max POST size'), 'title' => 'post_max_size', 'content' => \ini_get('post_max_size'), ), array( 'label' => $this->_('Max upload size'), 'title' => 'upload_max_filesize', 'content' => \ini_get('upload_max_filesize'), ), array( 'label' => $this->_('Max input variables'), 'title' => 'max_input_vars', 'content' => \ini_get('max_input_vars'), ), array( 'label' => $this->_('Max execution time'), 'title' => 'max_execution_time', 'content' => \ini_get('max_execution_time'), ), array( 'label' => $this->_('Timeout for socket'), 'title' => 'default_socket_timeout', 'content' => \ini_get('default_socket_timeout'), ), array( 'label' => $this->_('Display errors'), 'title' => 'display_errors', 'content' => Helper::getIni('display_errors'), ), array( 'label' => $this->_('Treatment URLs file'), 'title' => 'allow_url_fopen', 'content' => Helper::getIni('allow_url_fopen'), ), array( 'label' => $this->_('SMTP support'), 'title' => 'SMTP', 'content' => Helper::getIni('SMTP') ?: Helper::getIni(0, false), ), array( 'col' => '1-1', 'label' => $this->_('Disabled functions'), 'title' => 'disable_functions', 'content' => \implode(', ', \explode(',', Helper::getIni('disable_functions'))) ?: '-', ), ); $content = ''; foreach ($items as $item) { $title = isset($item['title']) ? "title=\"{$item['title']}\"" : ''; $col = isset($item['col']) ? $item['col'] : '1-3'; $id = isset($item['id']) ? "id=\"{$item['id']}\"" : ''; $content .= <<
{$item['label']}
@@ -534,7 +534,7 @@ function getVersionInfo(data){
HTML; } return $content; } } -namespace InnStudio\Prober\Config; class Api { public static $APP_VERSION = '1.7.1'; public static $APP_NAME = 'X Prober'; public static $APP_URL = 'https://github.com/kmvan/x-prober'; public static $AUTHOR_URL = 'https://inn-studio.com/prober'; public static $UPDATE_PHP_URL = 'https://raw.githubusercontent.com/kmvan/x-prober/master/dist/prober.php'; public static $AUTHOR_NAME = 'INN STUDIO'; public static $CHANGELOG_URL = 'https://raw.githubusercontent.com/kmvan/x-prober/master/CHANGELOG.md'; } +namespace InnStudio\Prober\Config; class Api { public static $APP_VERSION = '1.7.2'; public static $APP_NAME = 'X Prober'; public static $APP_URL = 'https://github.com/kmvan/x-prober'; public static $AUTHOR_URL = 'https://inn-studio.com/prober'; public static $UPDATE_PHP_URL = 'https://raw.githubusercontent.com/kmvan/x-prober/master/dist/prober.php'; public static $AUTHOR_NAME = 'INN STUDIO'; public static $CHANGELOG_URL = 'https://raw.githubusercontent.com/kmvan/x-prober/master/CHANGELOG.md'; } namespace InnStudio\Prober\Style; use InnStudio\Prober\Events\Api as Events; class Style { private $ID = 'style'; public function __construct() { Events::on('style', array($this, 'filter')); } public function filter() { $this->styleProgress(); $this->styleGlobal(); $this->stylePoiContainer(); $this->stylePoiGrid(); $this->styleTitle(); } private function styleTitle() { ?>