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

moved renew command to site

This commit is contained in:
Austin Drummond
2023-12-20 00:35:19 -05:00
parent dce796ac01
commit cd198cb0c9
2 changed files with 25 additions and 17 deletions

View File

@@ -3,6 +3,7 @@
namespace Valet;
use DateTime;
use DateInterval;
use DomainException;
use Illuminate\Support\Collection;
use PhpFpm;
@@ -501,6 +502,29 @@ public function secure(string $url, string $siteConf = null, int $certificateExp
$this->files->putAsUser($this->nginxPath($url), $siteConf);
}
/**
* Renews expired or expiring (within 60 days) domains with a trusted TLS certificate.
*/
public function renew($expireIn = 368, $days = 60): void
{
$now = (new DateTime())->add(new DateInterval('P' . $days . 'D'));
// Update anything expiring in the next 60 days
$sites = collect(Site::securedWithDates())
->filter(fn ($row) => $row['exp'] < $now)
->values();
if ($sites->isEmpty()) {
info('No sites need renewing.');
exit;
}
$sites->each(function ($row) use ($expireIn) {
$url = Site::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.
*