2020-06-29 23:26:48 +02:00
|
|
|
<?php
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2020-06-29 23:26:48 +02:00
|
|
|
namespace App\Radio;
|
|
|
|
|
|
|
|
use App\Settings;
|
|
|
|
|
|
|
|
class CertificateLocator
|
|
|
|
{
|
|
|
|
public static function findCertificate(): Certificate
|
|
|
|
{
|
|
|
|
$settings = Settings::getInstance();
|
|
|
|
|
|
|
|
if (!empty($_ENV['VIRTUAL_HOST']) && $settings->isDockerRevisionNewerThan(10)) {
|
|
|
|
$vhost = $_ENV['VIRTUAL_HOST'];
|
|
|
|
|
|
|
|
// Check environment variable for a virtual host.
|
|
|
|
$certBase = '/etc/nginx/certs';
|
|
|
|
|
|
|
|
if (is_dir($certBase)) {
|
|
|
|
$domainKey = $certBase . '/' . $vhost . '.key';
|
|
|
|
$domainCert = $certBase . '/' . $vhost . '.crt';
|
|
|
|
|
|
|
|
if (file_exists($domainKey) && file_exists($domainCert)) {
|
|
|
|
return new Certificate($domainKey, $domainCert);
|
|
|
|
}
|
|
|
|
|
|
|
|
$defaultKey = $certBase . '/default.key';
|
|
|
|
$defaultCert = $certBase . '/default.crt';
|
|
|
|
|
|
|
|
if (file_exists($defaultKey) && file_exists($defaultCert)) {
|
|
|
|
return new Certificate($defaultKey, $defaultCert);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return self::getDefaultCertificates();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getDefaultCertificates(): Certificate
|
|
|
|
{
|
|
|
|
$settings = Settings::getInstance();
|
|
|
|
|
|
|
|
if ($settings->isDocker()) {
|
|
|
|
return new Certificate('/etc/nginx/ssl.key', '/etc/nginx/ssl.crt');
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Certificate('/etc/nginx/ssl/server.key', '/etc/nginx/ssl/server.crt');
|
|
|
|
}
|
2020-10-15 00:19:31 +02:00
|
|
|
}
|