123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- /**
- * This file is part of the ForkBB <https://github.com/forkbb>.
- *
- * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
- * @license The MIT License (MIT)
- */
- declare(strict_types=1);
- namespace ForkBB\Models\Pages\Admin;
- use ForkBB\Models\Page;
- use ForkBB\Models\Pages\Admin;
- use function \ForkBB\{__, num};
- class Statistics extends Admin
- {
- /**
- * phpinfo
- */
- public function info(): Page
- {
- $this->c->Lang->load('admin_index');
- // Is phpinfo() a disabled function?
- if (! \function_exists('\\phpinfo')) {
- return $this->c->Message->message('PHPinfo disabled message', true, 200);
- }
- \ob_start();
- \phpinfo();
- $page = \ob_get_clean();
- if (\preg_match('%<body[^>]*>(.*)</body[^>]*>%is', $page, $matches)) {
- $phpinfo = $matches[1];
- if (\preg_match('%<style[^>]*>(.*?)</style[^>]*>%is', $page, $matches)) {
- $style = \preg_replace_callback(
- '%(\S[^{]*)({[^}]+})%',
- function ($match) {
- $result = \array_map(
- function ($val) {
- $val = \str_replace('body', '#id-phpinfo-div', $val, $count);
- return $count ? $val : '#id-phpinfo-div ' . $val;
- },
- \explode(',', $match[1])
- );
- return \implode(', ', $result) . $match[2];
- },
- $matches[1]
- );
- $this->c->Cache->set('phpinfoCSS', $style);
- $this->pageHeader('phpinfoStyle', 'link', 0, [
- 'rel' => 'stylesheet',
- 'type' => 'text/css',
- 'href' => $this->c->Router->link('AdminInfoCSS', ['time' => \time()] ),
- ]);
- }
- } else {
- $phpinfo = '- - -';
- }
- $this->nameTpl = 'admin/phpinfo';
- $this->mainSuffix = '-one-column';
- $this->aCrumbs[] = [$this->c->Router->link('AdminInfo'), ['%s', 'phpinfo()']];
- $this->aCrumbs[] = [$this->c->Router->link('AdminStatistics'), 'Server statistics'];
- $this->phpinfo = $phpinfo;
- return $this;
- }
- /**
- * Возврат css из phpinfo() как файл
- */
- public function infoCSS(): Page
- {
- $this->c->DEBUG = 0;
- $this->nameTpl = 'layouts/plain';
- $this->plainText = $this->c->Cache->get('phpinfoCSS', '');
- $this->header('Content-type', 'text/css; charset=utf-8');
- return $this;
- }
- /**
- * Подготавливает данные для шаблона
- */
- public function statistics(): Page
- {
- $this->c->Lang->load('admin_index');
- $this->nameTpl = 'admin/statistics';
- $this->aCrumbs[] = [$this->c->Router->link('AdminStatistics'), 'Server statistics'];
- $this->linkInfo = $this->c->Router->link('AdminInfo');
- // Get the server load averages (if possible)
- $this->serverLoad = __('Not available');
- switch (\PHP_OS_FAMILY) {
- case 'Windows':
- if (\function_exists('\\exec')) {
- \exec('wmic cpu get loadpercentage /all', $output);
- if (
- \is_array($output)
- && \preg_match('%(?:^|==)(\d+)(?:$|==)%', \implode('==', $output), $load)
- ) {
- $this->serverLoad = $load[1] . ' %';
- }
- }
- break;
- default:
- if (
- \function_exists('\\sys_getloadavg')
- && \is_array($load = \sys_getloadavg())
- ) {
- $this->serverLoad = num($load[0], 2) . ' ' . num($load[1], 2) . ' ' . num($load[2], 2);
- } elseif (\function_exists('\\exec')) {
- \exec('uptime', $output);
- if (
- \is_array($output)
- && \preg_match(
- '%averages?: ([0-9\.]+),?\s+([0-9\.]+),?\s+([0-9\.]+)%i',
- \implode(' ', $output),
- $load
- )
- ) {
- $this->serverLoad = num($load[1], 2) . ' ' . num($load[2], 2) . ' ' . num($load[3], 2);
- }
- }
- break;
- }
- // Get number of current visitors
- $this->onlineDetail = false;
- $this->numOnline = $this->c->Online->calc($this)->all;
- $stat = $this->c->DB->statistics();
- $this->dbVersion = $stat['db'];
- $this->tSize = $stat['size'];
- $this->tRecords = $stat['records'];
- $this->tTables = $stat['tables'];
- unset($stat['db'], $stat['size'], $stat['records'], $stat['tables']);
- $this->tOther = $stat;
- // Check for the existence of various PHP opcode caches/optimizers
- if (
- \ini_get('opcache.enable')
- && \function_exists('\\opcache_invalidate')
- ) {
- $this->accelerator = 'Zend OPcache';
- $this->linkAcc = 'https://www.php.net/opcache/';
- } elseif (\ini_get('wincache.fcenabled')) {
- $this->accelerator = 'Windows Cache for PHP';
- $this->linkAcc = 'https://www.php.net/wincache/';
- } else {
- $this->accelerator = __('NA');
- $this->linkAcc = null;
- }
- return $this;
- }
- }
|