diff --git a/app/Actions/SSL/CreateSSL.php b/app/Actions/SSL/CreateSSL.php index 5a41232..849dc93 100644 --- a/app/Actions/SSL/CreateSSL.php +++ b/app/Actions/SSL/CreateSSL.php @@ -6,6 +6,7 @@ use App\Enums\SslType; use App\Models\Site; use App\Models\Ssl; +use App\SSH\Services\Webserver\Webserver; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationException; @@ -30,11 +31,16 @@ public function create(Site $site, array $input): void $ssl->save(); dispatch(function () use ($site, $ssl) { - $site->server->webserver()->handler()->setupSSL($ssl); + /** @var Webserver $webserver */ + $webserver = $site->server->webserver()->handler(); + $webserver->setupSSL($ssl); $ssl->status = SslStatus::CREATED; $ssl->save(); $site->type()->edit(); - }); + })->catch(function () use ($ssl) { + $ssl->status = SslStatus::FAILED; + $ssl->save(); + })->onConnection('ssh'); } /** diff --git a/app/Actions/Site/Deploy.php b/app/Actions/Site/Deploy.php index ab1487b..32ad742 100644 --- a/app/Actions/Site/Deploy.php +++ b/app/Actions/Site/Deploy.php @@ -30,7 +30,7 @@ public function run(Site $site): Deployment 'deployment_script_id' => $site->deploymentScript->id, 'status' => DeploymentStatus::DEPLOYING, ]); - $lastCommit = $site->sourceControl()->provider()->getLastCommit($site->repository, $site->branch); + $lastCommit = $site->sourceControl()?->provider()?->getLastCommit($site->repository, $site->branch); if ($lastCommit) { $deployment->commit_id = $lastCommit['commit_id']; $deployment->commit_data = $lastCommit['commit_data']; diff --git a/app/SSH/Services/Webserver/Nginx.php b/app/SSH/Services/Webserver/Nginx.php index 2efb9b8..aa086da 100755 --- a/app/SSH/Services/Webserver/Nginx.php +++ b/app/SSH/Services/Webserver/Nginx.php @@ -117,9 +117,16 @@ public function changePHPVersion(Site $site, $version): void */ public function setupSSL(Ssl $ssl): void { + $domains = '-d '.$ssl->site->domain; + if ($ssl->site->aliases) { + foreach ($ssl->site->aliases as $alias) { + $domains .= ' -d '.$alias; + } + } $command = $this->getScript('nginx/create-letsencrypt-ssl.sh', [ 'email' => $ssl->site->server->creator->email, 'domain' => $ssl->site->domain, + 'domains' => $domains, 'web_directory' => $ssl->site->getWebDirectoryPath(), ]); if ($ssl->type == 'custom') { diff --git a/app/SSH/Services/Webserver/scripts/nginx/create-letsencrypt-ssl.sh b/app/SSH/Services/Webserver/scripts/nginx/create-letsencrypt-ssl.sh index 45ba158..3f543d2 100644 --- a/app/SSH/Services/Webserver/scripts/nginx/create-letsencrypt-ssl.sh +++ b/app/SSH/Services/Webserver/scripts/nginx/create-letsencrypt-ssl.sh @@ -1,3 +1,3 @@ -if ! sudo certbot certonly --force-renewal --nginx --noninteractive --agree-tos --cert-name __domain__ -m __email__ -d __domain__ --verbose; then +if ! sudo certbot certonly --force-renewal --nginx --noninteractive --agree-tos --cert-name __domain__ -m __email__ __domains__ --verbose; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/app/SSH/Services/Webserver/scripts/nginx/php-vhost-ssl.conf b/app/SSH/Services/Webserver/scripts/nginx/php-vhost-ssl.conf index 64c741f..7e0186d 100755 --- a/app/SSH/Services/Webserver/scripts/nginx/php-vhost-ssl.conf +++ b/app/SSH/Services/Webserver/scripts/nginx/php-vhost-ssl.conf @@ -1,10 +1,9 @@ server { listen 80; listen 443 ssl; - server_name __domain__ www.__domain__; + server_name __domain__ __aliases__; root __path__/__web_directory__; - ssl on; ssl_certificate __certificate__; ssl_certificate_key __private_key__; diff --git a/app/SSH/Services/Webserver/scripts/nginx/php-vhost.conf b/app/SSH/Services/Webserver/scripts/nginx/php-vhost.conf index 5d26a40..ab89621 100755 --- a/app/SSH/Services/Webserver/scripts/nginx/php-vhost.conf +++ b/app/SSH/Services/Webserver/scripts/nginx/php-vhost.conf @@ -1,6 +1,6 @@ server { listen 80; - server_name __domain__ www.__domain__; + server_name __domain__ __aliases__; root __path__/__web_directory__; add_header X-Frame-Options "SAMEORIGIN"; diff --git a/app/SSH/Services/Webserver/scripts/nginx/phpmyadmin-vhost.conf b/app/SSH/Services/Webserver/scripts/nginx/phpmyadmin-vhost.conf deleted file mode 100755 index bd7050d..0000000 --- a/app/SSH/Services/Webserver/scripts/nginx/phpmyadmin-vhost.conf +++ /dev/null @@ -1,31 +0,0 @@ -server { - listen __port__; - server_name _; - root /home/vito/phpmyadmin; - - add_header X-Frame-Options "SAMEORIGIN"; - add_header X-Content-Type-Options "nosniff"; - - index index.php; - - charset utf-8; - - location / { - try_files $uri $uri/ /index.php?$query_string; - } - - location = /favicon.ico { access_log off; log_not_found off; } - location = /robots.txt { access_log off; log_not_found off; } - - error_page 404 /index.php; - - location ~ \.php$ { - fastcgi_pass unix:/var/run/php/php__php_version__-fpm.sock; - fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; - include fastcgi_params; - } - - location ~ /\.(?!well-known).* { - deny all; - } -} diff --git a/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost-ssl.conf b/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost-ssl.conf index 92127bc..070bdd4 100755 --- a/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost-ssl.conf +++ b/app/SSH/Services/Webserver/scripts/nginx/reverse-vhost-ssl.conf @@ -4,7 +4,6 @@ server { server_name __domain__ __aliases__; root __path__; - ssl on; ssl_certificate __certificate__; ssl_certificate_key __private_key__; diff --git a/app/SSH/Services/Webserver/scripts/nginx/vhost-ssl.conf b/app/SSH/Services/Webserver/scripts/nginx/vhost-ssl.conf index 3dc7dec..1cf8334 100755 --- a/app/SSH/Services/Webserver/scripts/nginx/vhost-ssl.conf +++ b/app/SSH/Services/Webserver/scripts/nginx/vhost-ssl.conf @@ -4,7 +4,6 @@ server { server_name __domain__ __aliases__; root __path__/__web_directory__; - ssl on; ssl_certificate __certificate__; ssl_certificate_key __private_key__;