mirror of
https://github.com/laravel/valet.git
synced 2026-02-04 16:10:08 +01:00
added the ability to renew certs and view their expiration dates
This commit is contained in:
48
cli/app.php
48
cli/app.php
@@ -278,13 +278,51 @@ function (ConsoleCommandEvent $event) {
|
||||
/**
|
||||
* Display all of the currently secured sites.
|
||||
*/
|
||||
$app->command('secured', function (OutputInterface $output) {
|
||||
$sites = collect(Site::secured())->map(function ($url) {
|
||||
return ['Site' => $url];
|
||||
$app->command('secured [--expiring] [--days=]', function (OutputInterface $output, $expiring = null, $days = 60) {
|
||||
$now = (new Datetime())->add(new DateInterval('P' . $days . 'D'));
|
||||
$sites = collect(Site::secured())
|
||||
->when($expiring, fn ($collection) => $collection->filter(fn ($row) => $row['exp'] < $now))
|
||||
->map(function ($row) {
|
||||
return [
|
||||
'Site' => $row['host'],
|
||||
'Valid Until' => $row['exp']->format('Y-m-d H:i:s T'),
|
||||
];
|
||||
})
|
||||
->when($expiring, fn ($collection) => $collection->sortBy('Valid Until'));
|
||||
|
||||
return table(['Site', 'Valid Until'], $sites->all());
|
||||
})->descriptions('Display all of the currently secured sites', [
|
||||
'--expiring' => 'Limits the results to only sites expiring within the next 60 days.',
|
||||
'--days' => 'To be used with --expiring. Limits the results to only sites expiring within the next X days. Default is set to 60.',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Renews expired or expiring (within 60 days) domains with a trusted TLS certificate.
|
||||
*/
|
||||
$app->command('renew [--expireIn=] [--days=]', function (OutputInterface $output, $expireIn = 368, $days = 60) {
|
||||
$now = (new DateTime())->add(new DateInterval('P' . $days . 'D'));
|
||||
// Update anything expiring in the next 60 days
|
||||
$sites = collect(Site::secured())
|
||||
->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['host']);
|
||||
|
||||
Site::unsecure($url);
|
||||
Site::secure($url, null, $expireIn);
|
||||
|
||||
info('The [' . $url . '] site has been secured with a fresh TLS certificate.');
|
||||
});
|
||||
|
||||
table(['Site'], $sites->all());
|
||||
})->descriptions('Display all of the currently secured sites');
|
||||
Nginx::restart();
|
||||
})->descriptions('Renews expired or expiring (within 60 days) domains with a trusted TLS certificate.', [
|
||||
'--expireIn' => 'The amount of days the self signed certificate is valid for. Default is set to "368"',
|
||||
'--days' => 'Renews sites expiring within the next X days. Default is set to 60.',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Create an Nginx proxy config for the specified domain.
|
||||
|
||||
Reference in New Issue
Block a user