You've already forked Atomcms-edit
refactor: integrate diagnostics into Commandocentrum and split EmulatorUpdateService
- Add DiagnosticRunner integration to Commandocentrum for system health display - Refactor EmulatorUpdateService from 2524 lines to 395 lines (facade pattern) - Extract EmulatorStatusService, EmulatorJarService, EmulatorSourceService - Extract EmulatorBuildService, EmulatorSqlService, EmulatorBackupService - Add shared EmulatorConfiguration trait for dependency injection - Preserve backward compatibility on all public methods
This commit is contained in:
Executable
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Diagnostics;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class HttpDiagnostic
|
||||
{
|
||||
/**
|
||||
* @return array<DiagnosticResult>
|
||||
*/
|
||||
public function runAll(): array
|
||||
{
|
||||
return [
|
||||
$this->checkAppUrl(),
|
||||
$this->checkSslCertificate(),
|
||||
$this->checkHttpRedirect(),
|
||||
];
|
||||
}
|
||||
|
||||
public function checkAppUrl(): DiagnosticResult
|
||||
{
|
||||
$appUrl = config('app.url');
|
||||
|
||||
if (empty($appUrl) || $appUrl === 'http://localhost') {
|
||||
return DiagnosticResult::warning(
|
||||
'App URL',
|
||||
'APP_URL not configured properly',
|
||||
'Set APP_URL in .env to your domain'
|
||||
);
|
||||
}
|
||||
|
||||
if (! str_starts_with($appUrl, 'https://') && app()->environment('production')) {
|
||||
return DiagnosticResult::warning(
|
||||
'App URL',
|
||||
'Not using HTTPS in production',
|
||||
'Configure SSL and update APP_URL'
|
||||
);
|
||||
}
|
||||
|
||||
return DiagnosticResult::ok('App URL', $appUrl);
|
||||
}
|
||||
|
||||
public function checkSslCertificate(): DiagnosticResult
|
||||
{
|
||||
$appUrl = config('app.url');
|
||||
|
||||
if (! str_starts_with($appUrl, 'https://')) {
|
||||
return DiagnosticResult::warning('SSL', 'Not using HTTPS');
|
||||
}
|
||||
|
||||
$host = parse_url($appUrl, PHP_URL_HOST);
|
||||
if (! $host) {
|
||||
return DiagnosticResult::warning('SSL', 'Could not parse host from APP_URL');
|
||||
}
|
||||
|
||||
try {
|
||||
$response = Http::timeout(5)->get($appUrl);
|
||||
|
||||
if ($response->successful()) {
|
||||
return DiagnosticResult::ok('SSL', 'Certificate valid');
|
||||
}
|
||||
|
||||
return DiagnosticResult::warning('SSL', 'HTTPS endpoint returned ' . $response->status());
|
||||
} catch (\Exception $e) {
|
||||
return DiagnosticResult::error('SSL', $e->getMessage(), 'Check SSL certificate configuration');
|
||||
}
|
||||
}
|
||||
|
||||
public function checkHttpRedirect(): DiagnosticResult
|
||||
{
|
||||
$appUrl = config('app.url');
|
||||
|
||||
if (! str_starts_with($appUrl, 'https://')) {
|
||||
return DiagnosticResult::ok('HTTP Redirect', 'Not applicable (no HTTPS)');
|
||||
}
|
||||
|
||||
$httpUrl = str_replace('https://', 'http://', $appUrl);
|
||||
|
||||
try {
|
||||
$response = Http::timeout(5)->withoutRedirecting()->get($httpUrl);
|
||||
|
||||
if (in_array($response->status(), [301, 302])) {
|
||||
return DiagnosticResult::ok('HTTP Redirect', 'HTTP redirects to HTTPS');
|
||||
}
|
||||
|
||||
return DiagnosticResult::warning(
|
||||
'HTTP Redirect',
|
||||
"HTTP returns {$response->status()} instead of redirect",
|
||||
'Configure web server to redirect HTTP to HTTPS'
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
return DiagnosticResult::warning('HTTP Redirect', 'Could not test: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user