firefly-iii/app/Http/Controllers/DebugController.php

171 lines
6.1 KiB
PHP
Raw Normal View History

2017-12-31 04:38:21 -06:00
<?php
/**
* DebugController.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use DB;
use Exception;
use FireflyIII\Http\Middleware\IsDemoUser;
2017-12-31 04:38:21 -06:00
use Illuminate\Http\Request;
use Log;
use Monolog\Handler\RotatingFileHandler;
/**
* Class DebugController
*/
class DebugController extends Controller
{
/**
* HomeController constructor.
*/
public function __construct()
{
parent::__construct();
$this->middleware(IsDemoUser::class);
}
2017-12-31 04:38:21 -06:00
/**
* @param Request $request
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request)
{
$search = ['~', '#'];
$replace = ['\~', '# '];
$phpVersion = str_replace($search, $replace, PHP_VERSION);
2018-03-27 12:29:58 -05:00
$phpOs = str_replace($search, $replace, PHP_OS);
2017-12-31 04:38:21 -06:00
$interface = PHP_SAPI;
$now = Carbon::create()->format('Y-m-d H:i:s e');
2018-03-27 12:29:58 -05:00
$extensions = implode(', ', get_loaded_extensions());
$drivers = implode(', ', DB::availableDrivers());
2017-12-31 04:38:21 -06:00
$currentDriver = DB::getDriverName();
$userAgent = $request->header('user-agent');
$isSandstorm = var_export(env('IS_SANDSTORM', 'unknown'), true);
$isDocker = var_export(env('IS_DOCKER', 'unknown'), true);
2018-06-01 15:04:52 -05:00
$toSandbox = var_export(env('BUNQ_USE_SANDBOX', 'unknown'), true);
2017-12-31 04:38:21 -06:00
$trustedProxies = env('TRUSTED_PROXIES', '(none)');
$displayErrors = ini_get('display_errors');
2018-04-02 08:10:40 -05:00
$errorReporting = $this->errorReporting((int)ini_get('error_reporting'));
2017-12-31 04:38:21 -06:00
$appEnv = env('APP_ENV', '');
$appDebug = var_export(env('APP_DEBUG', false), true);
$appLog = env('APP_LOG', '');
$appLogLevel = env('APP_LOG_LEVEL', '');
$packages = $this->collectPackages();
2018-01-06 02:33:06 -06:00
$cacheDriver = env('CACHE_DRIVER', 'unknown');
2017-12-31 04:38:21 -06:00
// set languages, see what happens:
$original = setlocale(LC_ALL, 0);
$localeAttempts = [];
$parts = explode(',', trans('config.locale'));
foreach ($parts as $code) {
$code = trim($code);
$localeAttempts[$code] = var_export(setlocale(LC_ALL, $code), true);
}
setlocale(LC_ALL, $original);
2017-12-31 04:38:21 -06:00
// get latest log file:
2018-03-08 14:08:26 -06:00
$logger = Log::driver();
2017-12-31 04:38:21 -06:00
$handlers = $logger->getHandlers();
$logContent = '';
foreach ($handlers as $handler) {
if ($handler instanceof RotatingFileHandler) {
$logFile = $handler->getUrl();
if (null !== $logFile) {
try {
2018-01-28 13:59:26 -06:00
$logContent = file_get_contents($logFile);
2018-06-01 15:04:52 -05:00
// @codeCoverageIgnoreStart
2018-01-28 13:59:26 -06:00
} catch (Exception $e) {
// don't care
2018-03-27 12:29:58 -05:00
Log::debug(sprintf('Could not read log file. %s', $e->getMessage()));
}
2018-06-01 15:04:52 -05:00
// @codeCoverageIgnoreEnd
2017-12-31 04:38:21 -06:00
}
}
}
// last few lines
2018-06-01 15:04:52 -05:00
$logContent = 'Truncated from this point <----|' . substr($logContent, -8192);
2017-12-31 04:38:21 -06:00
return view(
2018-06-01 15:04:52 -05:00
'debug', compact(
2018-06-06 14:23:00 -05:00
'phpVersion', 'extensions', 'localeAttempts', 'appEnv', 'appDebug', 'appLog', 'appLogLevel', 'now', 'packages', 'drivers',
'currentDriver',
'userAgent', 'displayErrors', 'errorReporting', 'phpOs', 'interface', 'logContent', 'cacheDriver', 'isDocker', 'isSandstorm',
'trustedProxies',
'toSandbox'
)
2017-12-31 04:38:21 -06:00
);
}
/**
2018-01-05 00:54:10 -06:00
* Some common combinations.
*
2017-12-31 04:38:21 -06:00
* @param int $value
*
* @return string
*/
protected function errorReporting(int $value): string
{
$array = [
2018-01-05 00:54:10 -06:00
-1 => 'ALL errors',
E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED => 'E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED',
E_ALL => 'E_ALL',
E_ALL & ~E_DEPRECATED & ~E_STRICT => 'E_ALL & ~E_DEPRECATED & ~E_STRICT',
E_ALL & ~E_NOTICE => 'E_ALL & ~E_NOTICE',
E_ALL & ~E_NOTICE & ~E_STRICT => 'E_ALL & ~E_NOTICE & ~E_STRICT',
E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR => 'E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR',
2017-12-31 04:38:21 -06:00
];
if (isset($array[$value])) {
return $array[$value];
}
2018-04-02 08:10:40 -05:00
return (string)$value; // @codeCoverageIgnore
2017-12-31 04:38:21 -06:00
}
/**
* @return array
*/
private function collectPackages(): array
{
$packages = [];
$file = realpath(__DIR__ . '/../../../vendor/composer/installed.json');
if (!($file === false) && file_exists($file)) {
// file exists!
$content = file_get_contents($file);
$json = json_decode($content, true);
foreach ($json as $package) {
$packages[]
= [
'name' => $package['name'],
'version' => $package['version'],
];
}
}
return $packages;
}
2018-03-05 12:35:58 -06:00
}