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

279 lines
9.5 KiB
PHP
Raw Normal View History

2017-12-31 11:38:21 +01:00
<?php
/**
* DebugController.php
2020-01-31 07:32:04 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2017-12-31 11:38:21 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-12-31 11:38:21 +01: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 11:38:21 +01:00
*
* This program is distributed in the hope that it will be useful,
2017-12-31 11:38:21 +01: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 11:38:21 +01: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 11:38:21 +01:00
*/
declare(strict_types=1);
namespace FireflyIII\Http\Controllers;
use DB;
use Exception;
2021-03-28 11:46:23 +02:00
use FireflyConfig;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Middleware\IsDemoUser;
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
2021-03-28 11:46:23 +02:00
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse;
2017-12-31 11:38:21 +01:00
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
2023-07-09 18:45:44 +02:00
use Illuminate\Support\Facades\Artisan;
2023-04-01 07:04:42 +02:00
use Illuminate\Support\Facades\Log;
2023-04-29 11:15:30 +02:00
use Illuminate\View\View;
2017-12-31 11:38:21 +01:00
use Monolog\Handler\RotatingFileHandler;
/**
* Class DebugController
2018-07-17 22:21:03 +02:00
*
2017-12-31 11:38:21 +01:00
*/
class DebugController extends Controller
{
use GetConfigurationData;
/**
2019-07-21 17:15:06 +02:00
* DebugController constructor.
*
*/
public function __construct()
{
parent::__construct();
2020-02-06 22:01:59 +01:00
$this->middleware(IsDemoUser::class)->except(['displayError']);
}
/**
2018-07-22 08:10:16 +02:00
* Show all possible errors.
*
* @throws FireflyException
*/
2018-07-08 12:28:42 +02: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.');
2022-10-30 14:44:49 +01:00
app('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 08:10:16 +02:00
* Clear log and session.
*
2023-06-21 12:34:58 +02:00
* @param Request $request
*
* @return RedirectResponse|Redirector
2023-02-22 18:03:31 +01:00
* @throws FireflyException
*/
public function flush(Request $request)
{
2018-07-08 12:08:53 +02:00
app('preferences')->mark();
2022-12-29 19:41:57 +01:00
$request->session()->forget(['start', 'end', '_previous', 'viewRange', 'range', 'is_custom_range', 'temp-mfa-secret', 'temp-mfa-codes']);
Log::debug('Call cache:clear...');
2023-07-09 18:45:44 +02:00
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');
2022-12-30 20:25:04 +01:00
} catch (Exception $e) { // intentional generic exception
throw new FireflyException($e->getMessage(), 0, $e);
}
2021-04-07 07:28:43 +02:00
Log::debug('Call view:clear...');
Artisan::call('view:clear');
return redirect(route('index'));
}
2017-12-31 11:38:21 +01:00
/**
2018-07-22 08:10:16 +02:00
* Show debug info.
*
2023-06-21 12:34:58 +02:00
* @param Request $request
2017-12-31 11:38:21 +01:00
*
2021-03-28 11:46:23 +02:00
* @return Factory|View
2021-05-24 08:50:17 +02:00
* @throws FireflyException
2017-12-31 11:38:21 +01:00
*/
public function index(Request $request)
{
2022-03-10 17:59:30 +01:00
// basic scope information:
$now = now(config('app.timezone'))->format('Y-m-d H:i:s e');
2022-03-10 17:59:30 +01:00
$buildNr = '(unknown)';
$buildDate = '(unknown)';
2023-04-29 11:15:30 +02:00
$baseBuildNr = '(unknown)';
$baseBuildDate = '(unknown)';
2022-03-10 17:59:30 +01:00
$expectedDBversion = config('firefly.db_version');
$foundDBversion = FireflyConfig::get('db_version', 1)->data;
2023-05-27 06:40:23 +02:00
try {
if (file_exists('/var/www/counter-main.txt')) {
$buildNr = trim(file_get_contents('/var/www/counter-main.txt'));
}
} catch (Exception $e) { // generic catch for open basedir.
Log::debug('Could not check counter.');
Log::warning($e->getMessage());
2021-12-24 10:51:08 +01:00
}
2023-05-27 06:40:23 +02:00
try {
if (file_exists('/var/www/build-date-main.txt')) {
$buildDate = trim(file_get_contents('/var/www/build-date-main.txt'));
}
} catch (Exception $e) { // generic catch for open basedir.
Log::debug('Could not check date.');
Log::warning($e->getMessage());
2021-12-24 10:51:08 +01:00
}
2023-05-27 06:40:23 +02:00
if ('' !== (string)env('BASE_IMAGE_BUILD')) {
2023-04-29 11:15:30 +02:00
$baseBuildNr = env('BASE_IMAGE_BUILD');
}
2023-05-27 06:40:23 +02:00
if ('' !== (string)env('BASE_IMAGE_DATE')) {
2023-04-29 11:15:30 +02:00
$baseBuildDate = env('BASE_IMAGE_DATE');
}
2022-03-10 17:59:30 +01: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');
2023-02-19 08:02:13 +01:00
$maxFileSize = app('steam')->phpBytes(ini_get('upload_max_filesize'));
$maxPostSize = app('steam')->phpBytes(ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
2022-03-10 17:59:30 +01:00
$displayErrors = ini_get('display_errors');
2022-12-29 19:41:57 +01:00
$errorReporting = $this->errorReporting((int)ini_get('error_reporting'));
2022-03-10 17:59:30 +01:00
$interface = PHP_SAPI;
2022-12-29 19:41:57 +01:00
$defaultLanguage = (string)config('firefly.default_language');
$defaultLocale = (string)config('firefly.default_locale');
2022-03-10 17:59:30 +01:00
$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 07:14:20 +01:00
$stateful = join(', ', config('sanctum.stateful'));
2022-03-10 17:59:30 +01:00
2020-05-26 06:28:42 +02:00
2020-09-21 15:39:03 +02:00
// expected + found DB version:
2020-05-26 06:28:42 +02:00
// some new vars.
2022-03-10 17:59:30 +01:00
$isDocker = env('IS_DOCKER', false);
2017-12-31 11:38:21 +01:00
// set languages, see what happens:
$original = setlocale(LC_ALL, 0);
$localeAttempts = [];
2020-04-22 09:28:20 +02:00
$parts = app('steam')->getLocaleArray(app('steam')->getLocale());
foreach ($parts as $code) {
2020-05-26 06:28:42 +02: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 11:38:21 +01:00
// get latest log file:
2023-02-19 08:02:13 +01:00
$logger = Log::driver();
2022-12-31 06:57:05 +01:00
// PHPstan doesn't recognize the method because of its polymorphic nature.
$handlers = $logger->getHandlers(); // @phpstan-ignore-line
2017-12-31 11:38:21 +01:00
$logContent = '';
foreach ($handlers as $handler) {
if ($handler instanceof RotatingFileHandler) {
$logFile = $handler->getUrl();
2023-03-05 19:26:33 +01:00
if (null !== $logFile && file_exists($logFile)) {
2022-12-30 20:25:04 +01:00
$logContent = file_get_contents($logFile);
2017-12-31 11:38:21 +01:00
}
}
}
2019-02-13 17:38:41 +01:00
if ('' !== $logContent) {
2018-11-02 21:17:07 +01:00
// last few lines
2023-06-21 12:34:58 +02:00
$logContent = 'Truncated from this point <----|' . substr($logContent, -8192);
2018-11-02 21:17:07 +01:00
}
2017-12-31 11:38:21 +01:00
2021-04-04 17:57:46 +02:00
return view(
'debug',
compact(
'phpVersion',
'localeAttempts',
2020-09-21 15:39:03 +02:00
'expectedDBversion',
'foundDBversion',
'appEnv',
'appDebug',
'logChannel',
2022-03-19 07:14:20 +01:00
'stateful',
2021-04-01 06:47:33 +02:00
'tz',
2023-02-19 08:02:13 +01:00
'uploadSize',
'appLogLevel',
2022-03-10 17:59:30 +01:00
'remoteHeader',
'remoteMailHeader',
'now',
'drivers',
'currentDriver',
2022-03-10 17:59:30 +01:00
'userGuard',
'loginProvider',
2021-12-24 10:51:08 +01:00
'buildNr',
'buildDate',
2023-04-29 11:15:30 +02:00
'baseBuildNr',
'baseBuildDate',
2020-06-17 07:05:33 +02:00
'bcscale',
'userAgent',
'displayErrors',
'errorReporting',
'phpOs',
'interface',
'logContent',
'cacheDriver',
2020-05-26 06:28:42 +02:00
'trustedProxies',
'userLanguage',
'userLocale',
'defaultLanguage',
'defaultLocale',
'isDocker'
)
2017-12-31 11:38:21 +01:00
);
}
/**
2018-07-22 08:10:16 +02:00
* Flash all types of messages.
*
2023-06-21 12:34:58 +02:00
* @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 19:35:58 +01:00
}