Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix valet share over TLS secure #156

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
error.log
.idea/
Binary file modified bin/ngrok
Binary file not shown.
14 changes: 14 additions & 0 deletions cli/Valet/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions cli/valet.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
12 changes: 12 additions & 0 deletions valet
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down