From d6f06045fc7c237b0c47d91bc523563fa7dae784 Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Sat, 30 Nov 2019 16:38:48 -0500 Subject: [PATCH] Add --all parameter to valet unsecure command This PR allows passing `--all` to `valet unsecure` to have it remove all certificates from all Valet configs AND from the MacOS Keychain. This effectively cleans up certificate fragments or broken configs, and can help with troubleshooting. --- cli/Valet/Site.php | 31 +++++++++++++++++++++++++++++++ cli/valet.php | 8 +++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index 5ef7311b7..f2b810776 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -484,6 +484,37 @@ function unsecure($url) )); } + function unsecureAll() + { + $tld = $this->config->read()['tld']; + + $secured = $this->parked() + ->merge($this->links()) + ->sort() + ->where('secured', ' X'); + + if ($secured->count() === 0) { + return info('No sites to unsecure. You may list all servable sites or links by running valet parked or valet links.'); + } + + info('Attempting to unsecure the following sites:'); + table(['Site', 'SSL', 'URL', 'Path'], $secured->toArray()); + + foreach ($secured->pluck('site') as $url) { + $this->unsecure($url . '.' . $tld); + } + + $remaining = $this->parked() + ->merge($this->links()) + ->sort() + ->where('secured', ' X'); + if ($remaining->count() > 0) { + warning('We were not succesful in unsecuring the following sites:'); + table(['Site', 'SSL', 'URL', 'Path'], $remaining->toArray()); + } + info('unsecure --all was successful.'); + } + /** * Get the path to the linked Valet sites. * diff --git a/cli/valet.php b/cli/valet.php index 57402cce0..62230f015 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -164,7 +164,13 @@ /** * Stop serving the given domain over HTTPS and remove the trusted TLS certificate. */ - $app->command('unsecure [domain]', function ($domain = null) { + $app->command('unsecure [domain] [--all]', function ($domain = null, $all) { + + if ($all) { + Site::unsecureAll(); + return; + } + $url = ($domain ?: Site::host(getcwd())).'.'.Configuration::read()['tld']; Site::unsecure($url);