ID)) { return $conf; } $conf[$this->ID] = array( 'networks' => HelperApi::getNetworkStats(), 'timestamp' => \time(), ); return $conf; } } namespace InnStudio\Prober\Components\NetworkStats; use InnStudio\Prober\Components\Events\EventsApi; use InnStudio\Prober\Components\Helper\HelperApi; use InnStudio\Prober\Components\Xconfig\XconfigApi; class Fetch extends NetworkStatsConstants { public function __construct() { if ( ! HelperApi::isWin()) { EventsApi::on('fetch', array($this, 'filter')); EventsApi::on('nodes', array($this, 'filter')); } } public function filter(array $items) { if (XconfigApi::isDisabled($this->ID)) { return $items; } $items[$this->ID] = array( 'networks' => HelperApi::getNetworkStats(), 'timestamp' => \time(), ); return $items; } } namespace InnStudio\Prober\Components\NetworkStats; class NetworkStats { public function __construct() { new Conf(); new Fetch(); } } namespace InnStudio\Prober\Components\NetworkStats; class NetworkStatsConstants { protected $ID = 'networkStats'; } namespace InnStudio\Prober\Components\Fetch; use InnStudio\Prober\Components\Events\EventsApi; use InnStudio\Prober\Components\Restful\RestfulResponse; class Fetch { public function __construct() { EventsApi::on('init', array($this, 'filter'), 100); } public function filter($action) { if ('fetch' === $action) { EventsApi::emit('fetchBefore'); $response = new RestfulResponse(EventsApi::emit('fetch', array())); $response->dieJson(); } return $action; } } namespace InnStudio\Prober\Components\ServerInfo; class ServerInfo { public function __construct() { new Conf(); new Fetch(); } } namespace InnStudio\Prober\Components\ServerInfo; class ServerInfoConstants { protected $ID = 'serverInfo'; } namespace InnStudio\Prober\Components\ServerInfo; use InnStudio\Prober\Components\Events\EventsApi; use InnStudio\Prober\Components\Helper\HelperApi; use InnStudio\Prober\Components\Xconfig\XconfigApi; class Conf extends ServerInfoConstants { public function __construct() { EventsApi::on('conf', array($this, 'conf')); } public function conf(array $conf) { if (XconfigApi::isDisabled($this->ID)) { return $conf; } $conf[$this->ID] = array( 'serverName' => $this->getServerInfo('SERVER_NAME'), 'serverUtcTime' => HelperApi::getServerUtcTime(), 'serverTime' => HelperApi::getServerTime(), 'serverUptime' => HelperApi::getServerUptime(), 'serverIp' => XconfigApi::isDisabled('serverIp') ? '-' : $this->getServerInfo('SERVER_ADDR'), 'serverSoftware' => $this->getServerInfo('SERVER_SOFTWARE'), 'phpVersion' => \PHP_VERSION, 'cpuModel' => HelperApi::getCpuModel(), 'serverOs' => \php_uname(), 'scriptPath' => __FILE__, 'diskUsage' => array( 'value' => HelperApi::getDiskTotalSpace() - HelperApi::getDiskFreeSpace(), 'max' => HelperApi::getDiskTotalSpace(), ), ); return $conf; } private function getServerInfo($key) { return isset($_SERVER[$key]) ? $_SERVER[$key] : ''; } } namespace InnStudio\Prober\Components\ServerInfo; use InnStudio\Prober\Components\Events\EventsApi; use InnStudio\Prober\Components\Helper\HelperApi; use InnStudio\Prober\Components\Xconfig\XconfigApi; class Fetch extends ServerInfoConstants { public function __construct() { EventsApi::on('fetch', array($this, 'filter')); EventsApi::on('nodes', array($this, 'filter')); } public function filter(array $items) { if (XconfigApi::isDisabled($this->ID)) { return $items; } $items[$this->ID] = array( 'serverTime' => HelperApi::getServerTime(), 'serverUptime' => HelperApi::getServerUptime(), 'serverUtcTime' => HelperApi::getServerUtcTime(), 'diskUsage' => array( 'value' => HelperApi::getDiskTotalSpace() - HelperApi::getDiskFreeSpace(), 'max' => HelperApi::getDiskTotalSpace(), ), ); return $items; } } namespace InnStudio\Prober\Components\Events; class EventsApi { private static $events = array(); private static $PRIORITY_ID = 'priority'; private static $CALLBACK_ID = 'callback'; public static function on($name, $callback, $priority = 10) { if ( ! isset(self::$events[$name])) { self::$events[$name] = array(); } self::$events[$name][] = array( self::$PRIORITY_ID => $priority, self::$CALLBACK_ID => $callback, ); } public static function emit() { $args = \func_get_args(); $name = $args[0]; $return = isset($args[1]) ? $args[1] : null; unset($args[0], $args[1]); $events = isset(self::$events[$name]) ? self::$events[$name] : false; if ( ! $events) { return $return; } $sortArr = array(); foreach ($events as $k => $filter) { $sortArr[$k] = $filter[self::$PRIORITY_ID]; } \array_multisort($sortArr, $events); foreach ($events as $filter) { $return = \call_user_func_array($filter[self::$CALLBACK_ID], array($return, $args)); } return $return; } } namespace InnStudio\Prober\Components\Helper; class HelperApi { public static function jsonDecode($json, $depth = 512, $options = 0) { $json = \preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $json); if (\PHP_VERSION_ID >= 50400) { return \json_decode($json, true, $depth, $options); } if (\PHP_VERSION_ID >= 50300) { return \json_decode($json, true, $depth); } return \json_decode($json, true); } public static function setFileCacheHeader() { $seconds = 3600 * 24 * 30 * 12; $ts = \gmdate('D, d M Y H:i:s', (int) $_SERVER['REQUEST_TIME'] + $seconds) . ' GMT'; \header("Expires: {$ts}"); \header('Pragma: cache'); \header("Cache-Control: public, max-age={$seconds}"); } public static function getWinCpuUsage() { $usage = array( 'idle' => 100, 'user' => 0, 'sys' => 0, 'nice' => 0, ); if (\class_exists('\\COM')) { $wmi = new \COM('Winmgmts://'); $server = $wmi->execquery('SELECT LoadPercentage FROM Win32_Processor'); $total = 0; foreach ($server as $cpu) { $total += (int) $cpu->loadpercentage; } $total = (float) $total / \count($server); $usage['idle'] = 100 - $total; $usage['user'] = $total; } else { if ( ! \function_exists('\exec')) { return $usage; } $p = array(); \exec('wmic cpu get LoadPercentage', $p); if (isset($p[1])) { $percent = (int) $p[1]; $usage['idle'] = 100 - $percent; $usage['user'] = $percent; } } return $usage; } public static function getNetworkStats() { $filePath = '/proc/net/dev'; if ( ! @\is_readable($filePath)) { return null; } 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])); $rx = (float) $numberArr[0]; $tx = (float) $numberArr[8]; if ( ! $rx && ! $tx) { continue; } $eths[] = array( 'id' => $lineArr[0], 'rx' => $rx, 'tx' => $tx, ); } return $eths; } public static function getDiskTotalSpace() { if ( ! \function_exists('\disk_total_space')) { return 0; } static $space = null; if (null === $space) { $space = (float) \disk_total_space(__DIR__); } return $space; } public static function getDiskFreeSpace() { if ( ! \function_exists('\disk_total_space')) { return 0; } static $space = null; if (null === $space) { $space = (float) \disk_free_space(__DIR__); } return $space; } public static function getCpuModel() { $filePath = '/proc/cpuinfo'; if ( ! @\is_readable($filePath)) { return ''; } $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('%s cache', $cacheSize); } public static function getServerTime() { return \date('Y-m-d H:i:s'); } public static function getServerUtcTime() { return \gmdate('Y/m/d H:i:s'); } public static function getServerUptime() { $filePath = '/proc/uptime'; if ( ! @\is_file($filePath)) { return array( 'days' => 0, 'hours' => 0, 'mins' => 0, 'secs' => 0, ); } $str = \file_get_contents($filePath); $num = (float) $str; $secs = (int) \fmod($num, 60); $num = (int) ($num / 60); $mins = (int) $num % 60; $num = (int) ($num / 60); $hours = (int) $num % 24; $num = (int) ($num / 24); $days = (int) $num; return array( 'days' => $days, 'hours' => $hours, 'mins' => $mins, 'secs' => $secs, ); } public static function getErrNameByCode($code) { if (0 === (int) $code) { return ''; } $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 isWin() { return \PHP_OS === 'WINNT'; } 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 array( 'user' => 0, 'nice' => 0, 'sys' => 0, 'idle' => 100, ); } $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 getHumanCpuUsage() { $cpu = self::getCpuUsage(); return $cpu ?: array(); } public static function getSysLoadAvg() { if (self::isWin()) { return array(0, 0, 0); } return \array_map(function ($load) { return (float) \sprintf('%.2f', $load); }, \sys_getloadavg()); } public static function getMemoryUsage($key) { $key = \ucfirst($key); if (self::isWin()) { return 0; } static $memInfo = null; if (null === $memInfo) { $memInfoFile = '/proc/meminfo'; if ( ! @\is_readable($memInfoFile)) { $memInfo = 0; return 0; } $memInfo = \file_get_contents($memInfoFile); $memInfo = \str_replace(array( ' kB', ' ', ), '', $memInfo); $lines = array(); foreach (\explode("\n", $memInfo) as $line) { if ( ! $line) { continue; } $line = \explode(':', $line); $lines[$line[0]] = (float) $line[1] * 1024; } $memInfo = $lines; } if ( ! isset($memInfo['MemTotal'])) { return 0; } switch ($key) { case 'MemRealUsage': if (isset($memInfo['MemAvailable'])) { return $memInfo['MemTotal'] - $memInfo['MemAvailable']; } if (isset($memInfo['MemFree'])) { if (isset($memInfo['Buffers'], $memInfo['Cached'])) { return $memInfo['MemTotal'] - $memInfo['MemFree'] - $memInfo['Buffers'] - $memInfo['Cached']; } return $memInfo['MemTotal'] - $memInfo['Buffers']; } return 0; case 'MemUsage': return isset($memInfo['MemFree']) ? $memInfo['MemTotal'] - $memInfo['MemFree'] : 0; case 'SwapUsage': if ( ! isset($memInfo['SwapTotal']) || ! isset($memInfo['SwapFree'])) { return 0; } return $memInfo['SwapTotal'] - $memInfo['SwapFree']; } return isset($memInfo[$key]) ? $memInfo[$key] : 0; } public static function formatBytes($bytes, $precision = 2) { if ( ! $bytes) { return 0; } $base = \log($bytes, 1024); $suffixes = array('', ' K', ' M', ' G', ' T'); return \round(\pow(1024, ($base - \floor($base))), $precision) . $suffixes[\floor($base)]; } public static function getHumamMemUsage($key) { return self::formatBytes(self::getMemoryUsage($key)); } public static function strcut($str, $len = 20) { if (\strlen($str) > $len) { return \mb_strcut($str, 0, $len) . '...'; } return $str; } } namespace InnStudio\Prober\Components\PhpInfoDetail; use InnStudio\Prober\Components\Events\EventsApi; use InnStudio\Prober\Components\Xconfig\XconfigApi; class PhpInfoDetail extends PhpInfoDetailConstants { public function __construct() { EventsApi::on('init', array($this, 'filter')); } public function filter($action) { if (XconfigApi::isDisabled($this->ID)) { return $action; } if ($this->ID !== $action) { return $action; } \phpinfo(); die; } } namespace InnStudio\Prober\Components\PhpInfoDetail; class PhpInfoDetailConstants { protected $ID = 'phpInfoDetail'; } namespace InnStudio\Prober\Components\MyInfo; class MyInfoConstants { protected $ID = 'myInfo'; } namespace InnStudio\Prober\Components\MyInfo; use InnStudio\Prober\Components\Events\EventsApi; use InnStudio\Prober\Components\Helper\HelperApi; use InnStudio\Prober\Components\Xconfig\XconfigApi; class Conf extends MyInfoConstants { public function __construct() { EventsApi::on('conf', array($this, 'conf')); } public function conf(array $conf) { if (XconfigApi::isDisabled($this->ID)) { return $conf; } $conf[$this->ID] = array( 'ip' => HelperApi::getClientIp(), 'phpLanguage' => isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '-', ); return $conf; } } namespace InnStudio\Prober\Components\MyInfo; class MyInfo { public function __construct() { new Conf(); } } namespace InnStudio\Prober\Components\Script; use InnStudio\Prober\Components\Events\EventsApi; use InnStudio\Prober\Components\Helper\HelperApi; class Script { private $ID = 'script'; public function __construct() { EventsApi::on('init', array($this, 'filter')); } public function filter($action) { if ('script' !== $action) { return $action; } $this->output(); } private function output() { HelperApi::setFileCacheHeader(); \header('Content-type: application/javascript'); echo <<<'HTML' /*! For license information please see app.js.LICENSE.txt */ !function(){var e={679:function(e,t,n){"use strict";var r=n(864),a={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},o={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},i={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},l={};function s(e){return r.isMemo(e)?i:l[e.$$typeof]||a}l[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},l[r.Memo]=i;var u=Object.defineProperty,c=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,f=Object.getOwnPropertyDescriptor,p=Object.getPrototypeOf,h=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(h){var a=p(n);a&&a!==h&&e(t,a,r)}var i=c(n);d&&(i=i.concat(d(n)));for(var l=s(t),m=s(n),v=0;v