2020-06-29 21:26:48 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-29 21:26:48 +00:00
|
|
|
namespace App\Radio;
|
|
|
|
|
2020-12-03 04:18:06 +00:00
|
|
|
use App\Environment;
|
2020-06-29 21:26:48 +00:00
|
|
|
|
|
|
|
class CertificateLocator
|
|
|
|
{
|
|
|
|
public static function findCertificate(): Certificate
|
|
|
|
{
|
2020-12-03 04:18:06 +00:00
|
|
|
$environment = Environment::getInstance();
|
2020-06-29 21:26:48 +00:00
|
|
|
|
2022-01-18 08:49:08 +00:00
|
|
|
if ($environment->isDockerRevisionAtLeast(10)) {
|
2020-06-29 21:26:48 +00:00
|
|
|
// Check environment variable for a virtual host.
|
|
|
|
$certBase = '/etc/nginx/certs';
|
|
|
|
|
|
|
|
if (is_dir($certBase)) {
|
2022-01-18 08:49:08 +00:00
|
|
|
if (!empty($_ENV['VIRTUAL_HOST'])) {
|
|
|
|
$vhost = $_ENV['VIRTUAL_HOST'];
|
|
|
|
$domainKey = $certBase . '/' . $vhost . '.key';
|
|
|
|
$domainCert = $certBase . '/' . $vhost . '.crt';
|
|
|
|
|
|
|
|
if (file_exists($domainKey) && file_exists($domainCert)) {
|
|
|
|
return new Certificate($domainKey, $domainCert);
|
|
|
|
}
|
2020-06-29 21:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
|
{
|
2020-12-03 04:18:06 +00:00
|
|
|
$environment = Environment::getInstance();
|
2020-06-29 21:26:48 +00:00
|
|
|
|
2020-12-03 04:18:06 +00:00
|
|
|
if ($environment->isDocker()) {
|
2020-06-29 21:26:48 +00:00
|
|
|
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-14 22:19:31 +00:00
|
|
|
}
|