diff --git a/.gitignore b/.gitignore index ec60f71d5..0494974be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor/ composer.lock error.log +.idea/ diff --git a/bin/ngrok b/bin/ngrok index 5d2dba5ca..d91fa50cc 100755 Binary files a/bin/ngrok and b/bin/ngrok differ diff --git a/cli/Valet/Site.php b/cli/Valet/Site.php index 4d5b9a66f..3226ce937 100644 --- a/cli/Valet/Site.php +++ b/cli/Valet/Site.php @@ -121,6 +121,20 @@ function secured() })->unique()->values()->all(); } + /** + * Check if a given host has TLS. + * + * @param string $url + * @return bool + */ + function isSecured($url) + { + $secured = $this->secured(); + $site = $url.'.'.$this->config->read()['domain']; + + return in_array($site, $secured); + } + /** * Secure the given host with TLS. * diff --git a/cli/valet.php b/cli/valet.php index fe2671bb4..a5b3f8778 100755 --- a/cli/valet.php +++ b/cli/valet.php @@ -138,6 +138,19 @@ info('The ['.$url.'] site has been secured with a fresh TLS certificate.'); })->descriptions('Secure the given domain with a trusted TLS certificate'); +/** + * Check if a given domain has a trusted TLS certificate. + */ +$app->command('secured [domain]', function ($domain) { + $domain = $domain ?: Site::host(getcwd()); + + if (Site::isSecured($domain)) { + output('YES'); + } else { + warning('NO'); + } +})->descriptions('Check if a given domain has a trusted TLS certificate'); + /** * Stop serving the given domain over HTTPS and remove the trusted TLS certificate. */ diff --git a/valet b/valet index 18f05499f..ba4eec886 100755 --- a/valet +++ b/valet @@ -44,9 +44,21 @@ then fi done + COMMAND=$(php "$DIR/cli/valet.php" secured $HOST) + + if [ "$COMMAND" == 'YES' ]; then + HOST="valet.$HOST" + echo $(php "$DIR/cli/valet.php" link $HOST) + fi + # Fetch Ngrok URL In Background... bash "$DIR/cli/scripts/fetch-share-url.sh" & sudo -u $(logname) "$DIR/bin/ngrok" http "$HOST.$DOMAIN:80" -host-header=rewrite ${*:2} + + if [ "$COMMAND" == 'YES' ]; then + echo $(php "$DIR/cli/valet.php" unlink $HOST) + fi + exit # Finally, for every other command we will just proxy into the PHP tool