Fix: Scheme-Erkennung via APP_URL + nginx-Config statt letsencrypt-Pfad

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main v1.1.297
boban 2026-04-26 18:13:26 +02:00
parent 4fc31726be
commit 26eb3abdcd
1 changed files with 24 additions and 5 deletions

View File

@ -44,11 +44,8 @@ class MigrateEnvReverb extends Command
return self::SUCCESS;
}
$hasCert = file_exists("/etc/letsencrypt/renewal/{$appHost}.conf")
|| is_dir("/etc/letsencrypt/live/{$appHost}")
|| file_exists("/etc/letsencrypt/live/{$appHost}/fullchain.pem");
$scheme = $hasCert ? 'https' : 'http';
$port = $hasCert ? '443' : '80';
$scheme = $this->detectScheme($appHost, $content);
$port = $scheme === 'https' ? '443' : '80';
$fixes = [
'REVERB_HOST' => '${APP_HOST}',
@ -93,6 +90,28 @@ class MigrateEnvReverb extends Command
return self::SUCCESS;
}
private function detectScheme(string $host, string $envContent): string
{
// 1. APP_URL in .env bereits https?
$appUrl = $this->extractVar($envContent, 'APP_URL');
if (str_starts_with($appUrl, 'https://')) return 'https';
// 2. nginx-Konfiguration prüfen (world-readable)
foreach (glob('/etc/nginx/sites-enabled/*') ?: [] as $f) {
$c = @file_get_contents($f) ?: '';
if (str_contains($c, $host) && str_contains($c, 'ssl_certificate')) return 'https';
}
// 3. letsencrypt-Pfade (falls doch lesbar)
if (file_exists("/etc/letsencrypt/renewal/{$host}.conf")
|| is_dir("/etc/letsencrypt/live/{$host}")
|| file_exists("/etc/letsencrypt/live/{$host}/fullchain.pem")) {
return 'https';
}
return 'http';
}
private function extractVar(string $content, string $key): string
{
preg_match("/^{$key}=(.*)$/m", $content, $m);