2022-07-21 15:48:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2022-07-30 17:51:02 +02:00
|
|
|
use App\Facades\Settings;
|
2024-02-26 15:06:26 +01:00
|
|
|
use App\Notifications\TestEmailSettingNotification;
|
2022-11-22 15:15:52 +01:00
|
|
|
use App\Services\ReleaseRadarService;
|
2022-07-21 15:48:23 +02:00
|
|
|
use Illuminate\Http\Request;
|
2023-03-10 16:01:23 +01:00
|
|
|
use Illuminate\Support\Carbon;
|
2024-03-07 14:13:02 +01:00
|
|
|
use Illuminate\Support\Facades\Artisan;
|
2022-07-21 15:48:23 +02:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2024-02-26 15:06:26 +01:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2022-07-21 15:48:23 +02:00
|
|
|
|
|
|
|
class SystemController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Get detailed information about the current installation
|
2022-11-22 15:15:52 +01:00
|
|
|
*
|
2022-07-21 15:48:23 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function infos(Request $request)
|
|
|
|
{
|
2023-03-10 22:59:46 +01:00
|
|
|
$infos = [];
|
2023-03-10 16:01:23 +01:00
|
|
|
$infos['common']['Date'] = date(DATE_RFC2822);
|
|
|
|
$infos['common']['userAgent'] = $request->header('user-agent');
|
2022-07-21 15:48:23 +02:00
|
|
|
// App info
|
2023-03-10 16:01:23 +01:00
|
|
|
$infos['common']['Version'] = config('2fauth.version');
|
|
|
|
$infos['common']['Environment'] = config('app.env');
|
|
|
|
$infos['common']['Install path'] = '/' . config('2fauth.config.appSubdirectory');
|
|
|
|
$infos['common']['Debug'] = var_export(config('app.debug'), true);
|
|
|
|
$infos['common']['Cache driver'] = config('cache.default');
|
|
|
|
$infos['common']['Log channel'] = config('logging.default');
|
|
|
|
$infos['common']['Log level'] = env('LOG_LEVEL');
|
|
|
|
$infos['common']['DB driver'] = DB::getDriverName();
|
2022-07-21 15:48:23 +02:00
|
|
|
// PHP info
|
2023-03-10 16:01:23 +01:00
|
|
|
$infos['common']['PHP version'] = PHP_VERSION;
|
|
|
|
$infos['common']['Operating system'] = PHP_OS;
|
|
|
|
$infos['common']['interface'] = PHP_SAPI;
|
|
|
|
// Auth & Security infos
|
2024-02-22 14:12:47 +01:00
|
|
|
$infos['common']['Auth guard'] = config('auth.defaults.guard');
|
|
|
|
if ($infos['common']['Auth guard'] === 'reverse-proxy-guard') {
|
|
|
|
$infos['common']['Auth proxy logout url'] = config('2fauth.config.proxyLogoutUrl');
|
|
|
|
$infos['common']['Auth proxy header for user'] = config('auth.auth_proxy_headers.user');
|
|
|
|
$infos['common']['Auth proxy header for email'] = config('auth.auth_proxy_headers.email');
|
2022-07-21 15:48:23 +02:00
|
|
|
}
|
2024-02-22 14:12:47 +01:00
|
|
|
$infos['common']['webauthn user verification'] = config('webauthn.user_verification');
|
|
|
|
$infos['common']['Trusted proxies'] = config('2fauth.config.trustedProxies') ?: 'none';
|
|
|
|
$infos['common']['lastRadarScan'] = Carbon::parse(Settings::get('lastRadarScan'))->format('Y-m-d H:i:s');
|
2022-07-21 15:48:23 +02:00
|
|
|
|
|
|
|
return response()->json($infos);
|
|
|
|
}
|
2022-09-21 21:50:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get latest release
|
2022-11-22 15:15:52 +01:00
|
|
|
*
|
2022-09-21 21:50:41 +02:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
2022-10-12 11:10:51 +02:00
|
|
|
public function latestRelease(Request $request, ReleaseRadarService $releaseRadar)
|
2022-09-21 21:50:41 +02:00
|
|
|
{
|
2022-10-12 11:10:51 +02:00
|
|
|
$release = $releaseRadar->manualScan();
|
2022-09-21 21:50:41 +02:00
|
|
|
|
2022-10-12 11:10:51 +02:00
|
|
|
return response()->json(['newRelease' => $release]);
|
2022-09-21 21:50:41 +02:00
|
|
|
}
|
2024-02-26 15:06:26 +01:00
|
|
|
|
|
|
|
/**
|
2024-03-07 14:13:02 +01:00
|
|
|
* Send a test email
|
2024-02-26 15:06:26 +01:00
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function testEmail(Request $request)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$request->user()->notify(new TestEmailSettingNotification());
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
Log::error($th->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(['message' => 'Ok']);
|
|
|
|
}
|
2024-03-07 14:13:02 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears all app caches and rebuild them
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function optimize(Request $request)
|
|
|
|
{
|
|
|
|
$configCode = Artisan::call('config:cache');
|
|
|
|
$routeCode = Artisan::call('route:cache');
|
|
|
|
$eventCode = Artisan::call('event:cache');
|
|
|
|
$viewCode = Artisan::call('view:cache');
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
'config-exit-code' => $configCode,
|
|
|
|
'route-exit-code' => $routeCode,
|
|
|
|
'event-exit-code' => $eventCode,
|
|
|
|
'view-exit-code' => $viewCode,
|
|
|
|
], 200);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears application cache
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
*/
|
|
|
|
public function clear(Request $request)
|
|
|
|
{
|
|
|
|
$exitCode = Artisan::call('optimize:clear');
|
|
|
|
|
|
|
|
return response()->json(['exit-code' => $exitCode], 200);
|
|
|
|
}
|
2022-10-12 11:10:51 +02:00
|
|
|
}
|