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

303 lines
10 KiB
PHP
Raw Normal View History

2017-12-31 04:38:21 -06:00
<?php
/**
* DebugController.php
2020-01-31 00:32:04 -06:00
* Copyright (c) 2019 james@firefly-iii.org
2017-12-31 04:38:21 -06:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-12-31 04:38:21 -06:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-12-31 04:38:21 -06:00
*
* This program is distributed in the hope that it will be useful,
2017-12-31 04:38:21 -06:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-12-31 04:38:21 -06:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-12-31 04:38:21 -06:00
*/
declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use Artisan;
2017-12-31 04:38:21 -06:00
use Carbon\Carbon;
use DB;
use Exception;
2021-03-28 04:46:23 -05:00
use FireflyConfig;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
2021-03-28 04:46:23 -05:00
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
2017-12-31 04:38:21 -06:00
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\Routing\Route;
2021-03-28 04:46:23 -05:00
use Illuminate\View\View;
2017-12-31 04:38:21 -06:00
use Log;
use Monolog\Handler\RotatingFileHandler;
use Route as RouteFacade;
2017-12-31 04:38:21 -06:00
/**
* Class DebugController
2018-07-17 15:21:03 -05:00
*
2017-12-31 04:38:21 -06:00
*/
class DebugController extends Controller
{
use GetConfigurationData;
/**
2019-07-21 10:15:06 -05:00
* DebugController constructor.
*
2019-07-21 10:15:06 -05:00
* @codeCoverageIgnore
*/
public function __construct()
{
parent::__construct();
2020-02-06 15:01:59 -06:00
$this->middleware(IsDemoUser::class)->except(['displayError']);
}
/**
2018-07-22 01:10:16 -05:00
* Show all possible errors.
*
* @throws FireflyException
*/
2018-07-08 05:28:42 -05:00
public function displayError(): void
{
Log::debug('This is a test message at the DEBUG level.');
Log::info('This is a test message at the INFO level.');
Log::notice('This is a test message at the NOTICE level.');
Log::warning('This is a test message at the WARNING level.');
Log::error('This is a test message at the ERROR level.');
Log::critical('This is a test message at the CRITICAL level.');
Log::alert('This is a test message at the ALERT level.');
Log::emergency('This is a test message at the EMERGENCY level.');
throw new FireflyException('A very simple test error.');
}
/**
2018-07-22 01:10:16 -05:00
* Clear log and session.
*
* @param Request $request
*
* @return RedirectResponse|Redirector
*/
public function flush(Request $request)
{
2018-07-08 05:08:53 -05:00
app('preferences')->mark();
$request->session()->forget(['start', 'end', '_previous', 'viewRange', 'range', 'is_custom_range']);
Log::debug('Call cache:clear...');
Artisan::call('cache:clear');
Log::debug('Call config:clear...');
Artisan::call('config:clear');
Log::debug('Call route:clear...');
Artisan::call('route:clear');
Log::debug('Call twig:clean...');
try {
Artisan::call('twig:clean');
2021-04-07 00:28:43 -05:00
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
2021-04-07 00:28:43 -05:00
Log::debug('Call view:clear...');
Artisan::call('view:clear');
Log::debug('Done! Redirecting...');
return redirect(route('index'));
}
2017-12-31 04:38:21 -06:00
/**
2018-07-22 01:10:16 -05:00
* Show debug info.
*
2017-12-31 04:38:21 -06:00
* @param Request $request
*
2021-03-28 04:46:23 -05:00
* @return Factory|View
2021-05-24 01:50:17 -05:00
* @throws FireflyException
2017-12-31 04:38:21 -06:00
*/
public function index(Request $request)
{
2022-03-10 10:59:30 -06:00
// basic scope information:
$now = Carbon::now()->format('Y-m-d H:i:s e');
$buildNr = '(unknown)';
$buildDate = '(unknown)';
$expectedDBversion = config('firefly.db_version');
$foundDBversion = FireflyConfig::get('db_version', 1)->data;
2021-12-24 03:51:08 -06:00
if (file_exists('/var/www/counter-main.txt')) {
2022-01-07 09:17:38 -06:00
$buildNr = trim(file_get_contents('/var/www/counter-main.txt'));
2021-12-24 03:51:08 -06:00
}
if (file_exists('/var/www/build-date-main.txt')) {
2022-01-07 09:17:38 -06:00
$buildDate = trim(file_get_contents('/var/www/build-date-main.txt'));
2021-12-24 03:51:08 -06:00
}
2022-03-10 10:59:30 -06:00
$phpVersion = PHP_VERSION;
$phpOs = PHP_OS;
// system information
$tz = env('TZ');
$appEnv = config('app.env');
$appDebug = var_export(config('app.debug'), true);
$cacheDriver = config('cache.default');
$logChannel = config('logging.default');
$appLogLevel = config('logging.level');
$displayErrors = ini_get('display_errors');
$errorReporting = $this->errorReporting((int) ini_get('error_reporting'));
$interface = PHP_SAPI;
$defaultLanguage = (string) config('firefly.default_language');
$defaultLocale = (string) config('firefly.default_locale');
$bcscale = bcscale();
$drivers = implode(', ', DB::availableDrivers());
$currentDriver = DB::getDriverName();
$trustedProxies = config('firefly.trusted_proxies');
// user info
$loginProvider = config('auth.providers.users.driver');
$userGuard = config('auth.defaults.guard');
$remoteHeader = $userGuard === 'remote_user_guard' ? config('auth.guard_header') : 'N/A';
$remoteMailHeader = $userGuard === 'remote_user_guard' ? config('auth.guard_email') : 'N/A';
$userLanguage = app('steam')->getLanguage();
$userLocale = app('steam')->getLocale();
$userAgent = $request->header('user-agent');
2022-03-19 01:14:20 -05:00
$stateful = join(', ', config('sanctum.stateful'));
2022-03-10 10:59:30 -06:00
2020-05-25 23:28:42 -05:00
2020-09-21 08:39:03 -05:00
// expected + found DB version:
2020-05-25 23:28:42 -05:00
// some new vars.
2022-03-10 10:59:30 -06:00
$isDocker = env('IS_DOCKER', false);
2017-12-31 04:38:21 -06:00
// set languages, see what happens:
$original = setlocale(LC_ALL, 0);
$localeAttempts = [];
2020-04-22 02:28:20 -05:00
$parts = app('steam')->getLocaleArray(app('steam')->getLocale());
foreach ($parts as $code) {
2020-05-25 23:28:42 -05:00
$code = trim($code);
Log::debug(sprintf('Trying to set %s', $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);
2021-04-07 00:28:43 -05:00
} catch (Exception $e) { // @phpstan-ignore-line
// @ignoreException
}
2021-04-07 00:28:43 -05:00
2017-12-31 04:38:21 -06:00
}
}
}
2019-02-13 10:38:41 -06:00
if ('' !== $logContent) {
2018-11-02 15:17:07 -05:00
// last few lines
$logContent = 'Truncated from this point <----|' . substr($logContent, -8192);
}
2017-12-31 04:38:21 -06:00
2021-04-04 10:57:46 -05:00
return view(
'debug',
compact(
'phpVersion',
'localeAttempts',
2020-09-21 08:39:03 -05:00
'expectedDBversion',
'foundDBversion',
'appEnv',
'appDebug',
'logChannel',
2022-03-19 01:14:20 -05:00
'stateful',
2021-03-31 23:47:33 -05:00
'tz',
'appLogLevel',
2022-03-10 10:59:30 -06:00
'remoteHeader',
'remoteMailHeader',
'now',
'drivers',
'currentDriver',
2022-03-10 10:59:30 -06:00
'userGuard',
'loginProvider',
2021-12-24 03:51:08 -06:00
'buildNr',
'buildDate',
2020-06-17 00:05:33 -05:00
'bcscale',
'userAgent',
'displayErrors',
'errorReporting',
'phpOs',
'interface',
'logContent',
'cacheDriver',
2020-05-25 23:28:42 -05:00
'trustedProxies',
'userLanguage',
'userLocale',
'defaultLanguage',
'defaultLocale',
'isDocker'
)
2017-12-31 04:38:21 -06:00
);
}
/**
2018-07-22 01:10:16 -05:00
* Return all possible routes.
*
* @return string
*/
public function routes(): string
{
$set = RouteFacade::getRoutes();
$ignore = ['chart.', 'javascript.', 'json.', 'report-data.', 'popup.', 'debugbar.', 'attachments.download', 'attachments.preview',
2020-06-06 14:23:26 -05:00
'bills.rescan', 'budgets.income', 'currencies.def', 'error', 'flush', 'help.show',
'login', 'logout', 'password.reset', 'profile.confirm-email-change', 'profile.undo-email-change',
'register', 'report.options', 'routes', 'rule-groups.down', 'rule-groups.up', 'rules.up', 'rules.down',
'rules.select', 'search.search', 'test-flash', 'transactions.link.delete', 'transactions.link.switch',
2020-06-06 14:23:26 -05:00
'two-factor.lost', 'reports.options', 'debug',
'preferences.delete-code', 'rules.test-triggers', 'piggy-banks.remove-money', 'piggy-banks.add-money',
2019-06-07 11:19:24 -05:00
'accounts.reconcile.transactions', 'accounts.reconcile.overview',
2020-06-06 14:23:26 -05:00
'transactions.clone', 'two-factor.index', 'api.v1', 'installer.', 'attachments.view', 'recurring.events',
2018-06-21 11:58:27 -05:00
'recurring.suggest',
];
$return = '&nbsp;';
/** @var Route $route */
foreach ($set as $route) {
2022-03-10 10:59:30 -06:00
$name = (string) $route->getName();
2019-06-21 12:10:02 -05:00
if (in_array('GET', $route->methods(), true)) {
$found = false;
foreach ($ignore as $string) {
2020-10-24 09:59:56 -05:00
if (false !== stripos($name, $string)) {
$found = true;
break;
}
}
2018-07-08 00:59:58 -05:00
if (false === $found) {
$return .= 'touch ' . $route->getName() . '.md;';
}
}
}
return $return;
}
/**
2018-07-22 01:10:16 -05:00
* Flash all types of messages.
*
* @param Request $request
*
* @return RedirectResponse|Redirector
*/
public function testFlash(Request $request)
{
$request->session()->flash('success', 'This is a success message.');
$request->session()->flash('info', 'This is an info message.');
$request->session()->flash('warning', 'This is a warning.');
$request->session()->flash('error', 'This is an error!');
return redirect(route('home'));
}
2018-03-05 12:35:58 -06:00
}