mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Expand debug controller.
This commit is contained in:
149
app/Http/Controllers/DebugController.php
Normal file
149
app/Http/Controllers/DebugController.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?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 Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
|
||||
/**
|
||||
* Class DebugController
|
||||
*/
|
||||
class DebugController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* @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);
|
||||
$phpOs = str_replace($search, $replace, php_uname());
|
||||
$interface = PHP_SAPI;
|
||||
$now = Carbon::create()->format('Y-m-d H:i:s e');
|
||||
$extensions = join(', ', get_loaded_extensions());
|
||||
$drivers = join(', ', DB::availableDrivers());
|
||||
$currentDriver = DB::getDriverName();
|
||||
$userAgent = $request->header('user-agent');
|
||||
$isSandstorm = var_export(env('IS_SANDSTORM', 'unknown'), true);
|
||||
$isDocker = var_export(env('IS_DOCKER', 'unknown'), true);
|
||||
$trustedProxies = env('TRUSTED_PROXIES', '(none)');
|
||||
$displayErrors = ini_get('display_errors');
|
||||
$errorReporting = $this->errorReporting(intval(ini_get('error_reporting')));
|
||||
$appEnv = env('APP_ENV', '');
|
||||
$appDebug = var_export(env('APP_DEBUG', false), true);
|
||||
$appLog = env('APP_LOG', '');
|
||||
$appLogLevel = env('APP_LOG_LEVEL', '');
|
||||
$packages = $this->collectPackages();
|
||||
|
||||
|
||||
// get latest log file:
|
||||
$logger = Log::getMonolog();
|
||||
$handlers = $logger->getHandlers();
|
||||
$logContent = '';
|
||||
foreach ($handlers as $handler) {
|
||||
if ($handler instanceof RotatingFileHandler) {
|
||||
$logFile = $handler->getUrl();
|
||||
if (null !== $logFile) {
|
||||
$logContent = file_get_contents($logFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
// last few lines
|
||||
$logContent = 'Truncated from this point <----|' . substr($logContent, -4096);
|
||||
|
||||
return view(
|
||||
'debug',
|
||||
compact(
|
||||
'phpVersion',
|
||||
'extensions',
|
||||
'carbon',
|
||||
'appEnv',
|
||||
'appDebug',
|
||||
'appLog',
|
||||
'appLogLevel',
|
||||
'now',
|
||||
'packages',
|
||||
'drivers',
|
||||
'currentDriver',
|
||||
'userAgent',
|
||||
'displayErrors',
|
||||
'errorReporting',
|
||||
'phpOs',
|
||||
'interface',
|
||||
'logContent',
|
||||
'isDocker',
|
||||
'isSandstorm',
|
||||
'trustedProxies'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function errorReporting(int $value): string
|
||||
{
|
||||
$array = [
|
||||
-1 => 'ALL errors',
|
||||
];
|
||||
if (isset($array[$value])) {
|
||||
return $array[$value];
|
||||
}
|
||||
|
||||
return strval($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
@@ -24,7 +24,6 @@ namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Artisan;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Events\RequestedVersionCheckStatus;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -38,7 +37,6 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Route;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Preferences;
|
||||
use Response;
|
||||
use Route as RouteFacade;
|
||||
@@ -98,59 +96,6 @@ class HomeController extends Controller
|
||||
return Response::json(['ok' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function displayDebug(Request $request)
|
||||
{
|
||||
$phpVersion = str_replace('~', '\~', PHP_VERSION);
|
||||
$phpOs = php_uname();
|
||||
$interface = PHP_SAPI;
|
||||
$now = Carbon::create()->format('Y-m-d H:i:s e');
|
||||
$extensions = join(', ', get_loaded_extensions());
|
||||
$drivers = join(', ', DB::availableDrivers());
|
||||
$currentDriver = DB::getDriverName();
|
||||
$userAgent = $request->header('user-agent');
|
||||
$isSandstorm = var_export(env('IS_SANDSTORM', 'unknown'), true);
|
||||
$isDocker = var_export(env('IS_DOCKER', 'unknown'), true);
|
||||
$trustedProxies = env('TRUSTED_PROXIES', '(none)');
|
||||
|
||||
// get latest log file:
|
||||
$logger = Log::getMonolog();
|
||||
$handlers = $logger->getHandlers();
|
||||
$logContent = '';
|
||||
foreach ($handlers as $handler) {
|
||||
if ($handler instanceof RotatingFileHandler) {
|
||||
$logFile = $handler->getUrl();
|
||||
if (null !== $logFile) {
|
||||
$logContent = file_get_contents($logFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
// last few lines
|
||||
$logContent = 'Truncated from this point <----|' . substr($logContent, -4096);
|
||||
|
||||
return view(
|
||||
'debug',
|
||||
compact(
|
||||
'phpVersion',
|
||||
'extensions',
|
||||
'carbon',
|
||||
'now',
|
||||
'drivers',
|
||||
'currentDriver',
|
||||
'userAgent',
|
||||
'phpOs',
|
||||
'interface',
|
||||
'logContent',
|
||||
'isDocker',
|
||||
'isSandstorm',
|
||||
'trustedProxies'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
|
Reference in New Issue
Block a user