1
0
mirror of https://github.com/laravel/valet.git synced 2026-02-07 09:10:03 +01:00

Merge pull request #1461 from adrum/feature/renew-certs

added the ability to renew certs and view their expiration dates
This commit is contained in:
Matt Stauffer
2023-12-20 22:44:43 -05:00
committed by GitHub
3 changed files with 84 additions and 7 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.
*