1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-06 16:50:09 +01:00

Merge branch 'master' of github.com:laravel/valet

This commit is contained in:
Matt Stauffer
2023-12-20 22:45:41 -05:00
4 changed files with 85 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
namespace Valet;
use DateTime;
use DomainException;
use Illuminate\Support\Collection;
use PhpFpm;
@@ -435,6 +436,26 @@ public function secured(): array
})->unique()->values()->all();
}
/**
* Get all of the URLs with expiration dates that are currently secured.
*/
public function securedWithDates(): array
{
return collect($this->secured())->map(function ($site) {
$filePath = $this->certificatesPath().'/'.$site.'.crt';
$expiration = $this->cli->run("openssl x509 -enddate -noout -in $filePath");
$expiration = str_replace('notAfter=', '', $expiration);
return [
'site' => $site,
'exp' => new DateTime($expiration),
];
})->unique()->values()->all();
}
public function isSecured(string $site): bool
{
$tld = $this->config->read()['tld'];
@@ -480,6 +501,20 @@ public function secure(string $url, ?string $siteConf = null, int $certificateEx
$this->files->putAsUser($this->nginxPath($url), $siteConf);
}
/**
* Renews all domains with a trusted TLS certificate.
*/
public function renew($expireIn): void
{
collect($this->securedWithDates())->each(function ($row) use ($expireIn) {
$url = $this->domain($row['site']);
$this->secure($url, null, $expireIn);
info('The ['.$url.'] site has been secured with a fresh TLS certificate.');
});
}
/**
* If CA and root certificates are nonexistent, create them and trust the root cert.
*