mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-23 14:26:58 +00:00
Little debug page with routes.
This commit is contained in:
@@ -25,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@@ -34,14 +33,17 @@ use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\GetConfigurationData;
|
||||
use FireflyIII\Support\Models\AccountBalanceCalculator;
|
||||
use FireflyIII\User;
|
||||
use Http\Discovery\Exception\NotFoundException;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\View\View;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class DebugController
|
||||
@@ -59,6 +61,61 @@ class DebugController extends Controller
|
||||
$this->middleware(IsDemoUser::class)->except(['displayError']);
|
||||
}
|
||||
|
||||
public function routes(): never
|
||||
{
|
||||
if(!auth()->user()->hasRole('owner')) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
$routes = Route::getRoutes();
|
||||
$return = [];
|
||||
/** @var \Illuminate\Routing\Route $route */
|
||||
foreach ($routes as $route) {
|
||||
// skip API and other routes.
|
||||
if (
|
||||
str_starts_with($route->uri(), 'api') ||
|
||||
str_starts_with($route->uri(), '_debugbar') ||
|
||||
str_starts_with($route->uri(), '_ignition') ||
|
||||
str_starts_with($route->uri(), 'oauth') ||
|
||||
str_starts_with($route->uri(), 'sanctum')
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
// skip non GET routes
|
||||
if (!in_array('GET', $route->methods())) {
|
||||
continue;
|
||||
}
|
||||
// no name route:
|
||||
if (null === $route->getName()) {
|
||||
var_dump($route);
|
||||
exit;
|
||||
}
|
||||
if (!str_contains($route->uri(), '{')) {
|
||||
|
||||
$return[$route->getName()] = route($route->getName());
|
||||
continue;
|
||||
}
|
||||
$params = [];
|
||||
foreach ($route->parameterNames() as $name) {
|
||||
$params[] = $this->getParameter($name);
|
||||
}
|
||||
$return[$route->getName()] = route($route->getName(), $params);
|
||||
}
|
||||
$count = 0;
|
||||
echo '<hr>';
|
||||
echo '<h1>Routes</h1>';
|
||||
echo sprintf('<h2>%s</h2>', $count);
|
||||
foreach($return as $name => $path) {
|
||||
echo sprintf('<a href="%1$s">%2$s</a><br>', $path, $name) . PHP_EOL;
|
||||
$count++;
|
||||
if(0 === $count % 10) {
|
||||
echo '<hr>';
|
||||
echo sprintf('<h2>%s</h2>', $count);
|
||||
}
|
||||
}
|
||||
exit;
|
||||
var_dump($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all possible errors.
|
||||
*
|
||||
@@ -119,12 +176,12 @@ class DebugController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$table = $this->generateTable();
|
||||
$table = str_replace(["\n", "\t", ' '], '', $table);
|
||||
$now = now(config('app.timezone'))->format('Y-m-d H:i:s');
|
||||
$table = $this->generateTable();
|
||||
$table = str_replace(["\n", "\t", ' '], '', $table);
|
||||
$now = now(config('app.timezone'))->format('Y-m-d H:i:s');
|
||||
|
||||
// get latest log file:
|
||||
$logger = Log::driver();
|
||||
$logger = Log::driver();
|
||||
// PHPstan doesn't recognize the method because of its polymorphic nature.
|
||||
$handlers = $logger->getHandlers(); // @phpstan-ignore-line
|
||||
$logContent = '';
|
||||
@@ -138,7 +195,7 @@ class DebugController extends Controller
|
||||
}
|
||||
if ('' !== $logContent) {
|
||||
// last few lines
|
||||
$logContent = 'Truncated from this point <----|'.substr((string) $logContent, -16384);
|
||||
$logContent = 'Truncated from this point <----|' . substr((string) $logContent, -16384);
|
||||
}
|
||||
|
||||
return view('debug', compact('table', 'now', 'logContent'));
|
||||
@@ -218,7 +275,7 @@ class DebugController extends Controller
|
||||
|
||||
private function getAppInfo(): array
|
||||
{
|
||||
$userGuard = config('auth.defaults.guard');
|
||||
$userGuard = config('auth.defaults.guard');
|
||||
|
||||
$config = app('fireflyconfig')->get('last_rt_job', 0);
|
||||
$lastTime = (int) $config->data;
|
||||
@@ -243,24 +300,24 @@ class DebugController extends Controller
|
||||
// any of the cron jobs will do, they always run at the same time.
|
||||
// but this job is the oldest, so the biggest chance it ran once
|
||||
|
||||
'last_cronjob' => $lastCronjob,
|
||||
'last_cronjob_ago' => $lastCronjobAgo,
|
||||
'last_cronjob' => $lastCronjob,
|
||||
'last_cronjob_ago' => $lastCronjobAgo,
|
||||
];
|
||||
}
|
||||
|
||||
private function getuserInfo(): array
|
||||
{
|
||||
$userFlags = $this->getUserFlags();
|
||||
$userFlags = $this->getUserFlags();
|
||||
|
||||
// user info
|
||||
$userAgent = request()->header('user-agent');
|
||||
$userAgent = request()->header('user-agent');
|
||||
|
||||
// set languages, see what happens:
|
||||
$original = setlocale(LC_ALL, '0');
|
||||
$localeAttempts = [];
|
||||
$parts = app('steam')->getLocaleArray(app('steam')->getLocale());
|
||||
foreach ($parts as $code) {
|
||||
$code = trim($code);
|
||||
$code = trim($code);
|
||||
app('log')->debug(sprintf('Trying to set %s', $code));
|
||||
$result = setlocale(LC_ALL, $code);
|
||||
$localeAttempts[$code] = $result === $code;
|
||||
@@ -281,10 +338,10 @@ class DebugController extends Controller
|
||||
|
||||
private function getUserFlags(): string
|
||||
{
|
||||
$flags = [];
|
||||
$flags = [];
|
||||
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
$user = auth()->user();
|
||||
|
||||
// has liabilities
|
||||
if ($user->accounts()->accountTypeIn([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE])->count() > 0) {
|
||||
@@ -300,7 +357,7 @@ class DebugController extends Controller
|
||||
}
|
||||
|
||||
// has stored reconciliations
|
||||
$type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
|
||||
$type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
|
||||
if ($user->transactionJournals()->where('transaction_type_id', $type->id)->count() > 0) {
|
||||
$flags[] = '<span title="Has reconciled">:ledger:</span>';
|
||||
}
|
||||
@@ -344,4 +401,93 @@ class DebugController extends Controller
|
||||
|
||||
return redirect(route('home'));
|
||||
}
|
||||
|
||||
private function getParameter(string $name): string
|
||||
{
|
||||
switch ($name) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Unknown parameter "%s"', $name));
|
||||
case 'cliToken':
|
||||
case 'token':
|
||||
case 'code':
|
||||
case 'oldAddressHash':
|
||||
return 'fake-token';
|
||||
case 'objectType':
|
||||
return 'asset';
|
||||
case 'account':
|
||||
return '1';
|
||||
case 'start_date':
|
||||
return '20241201';
|
||||
case 'end_date':
|
||||
return '20241231';
|
||||
case 'attachment':
|
||||
return '1';
|
||||
case 'bill':
|
||||
return '1';
|
||||
case 'budget':
|
||||
return '1';
|
||||
case 'budgetLimit':
|
||||
return '1';
|
||||
case 'category':
|
||||
return '1';
|
||||
case 'currency':
|
||||
return '1';
|
||||
case 'fromCurrencyCode':
|
||||
return 'EUR';
|
||||
case 'toCurrencyCode':
|
||||
return 'USD';
|
||||
case 'accountList':
|
||||
return '1,6';
|
||||
case 'budgetList':
|
||||
return '1,2';
|
||||
case 'categoryList':
|
||||
return '1,2';
|
||||
case 'doubleList':
|
||||
return '1,2';
|
||||
case 'tagList':
|
||||
return '1,2';
|
||||
case 'tag':
|
||||
return '1';
|
||||
case 'piggyBank':
|
||||
return '1';
|
||||
case 'objectGroup':
|
||||
return '1';
|
||||
case 'route':
|
||||
return 'accounts';
|
||||
case 'specificPage':
|
||||
return 'show';
|
||||
case 'recurrence':
|
||||
return '1';
|
||||
case 'tj':
|
||||
return '1';
|
||||
case 'reportType':
|
||||
return 'default';
|
||||
case 'ruleGroup':
|
||||
return '1';
|
||||
case 'rule':
|
||||
return '1';
|
||||
case 'tagOrId':
|
||||
return '1';
|
||||
case 'transactionGroup':
|
||||
return '1';
|
||||
case 'journalList':
|
||||
return '1,2';
|
||||
case 'transactionType':
|
||||
return 'withdrawal';
|
||||
case 'journalLink':
|
||||
return '1';
|
||||
case 'webhook':
|
||||
return '1';
|
||||
case 'user':
|
||||
return '1';
|
||||
case 'linkType':
|
||||
return '1';
|
||||
case 'userGroup':
|
||||
return '1';
|
||||
|
||||
case 'date':
|
||||
return '20241201';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user