diff --git a/web/Modules/LetsEncrypt/Actions/acmephp.phar b/web/Modules/LetsEncrypt/Actions/acmephp.phar deleted file mode 100644 index 2f694c6..0000000 Binary files a/web/Modules/LetsEncrypt/Actions/acmephp.phar and /dev/null differ diff --git a/web/Modules/LetsEncrypt/Actions/acmephp.phar.pubkey b/web/Modules/LetsEncrypt/Actions/acmephp.phar.pubkey deleted file mode 100644 index c0f84e4..0000000 --- a/web/Modules/LetsEncrypt/Actions/acmephp.phar.pubkey +++ /dev/null @@ -1,9 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArRmu5WOZsz50RBvtUU05 -wZ66jQrAjmJ4t9Kj2+iaynX5OY05d9dH9v+JF9x6dCo+D6dSJLcAyA4/Cosq3TW/ -rDVSY9eIUsuxr4OlmguFLfHa9vML9Ot1f/z/4uxXhUuG1w15TkqhIvxbHdMes0mH -5nA54uHVki5RSQrN08ebawBkxRbp/gG7qvMPxNhBdyTwZ6T7TUJSDWqZYzS6XcjR -F1qzOhucAo1lqT7B2XBGYdsEHngZNTVlc4VAdj2ZajOSJdEYsOoxXGV20JFS22lr -I1a4Sp6jm9stBuagttfsI5c2kTplfpMbGEDsj+jeNwY7rFfghy4d0G1xZQKarcBO -iQIDAQAB ------END PUBLIC KEY----- diff --git a/web/Modules/LetsEncrypt/resources/views/actions/certbot-http-secure-command.blade.php b/web/Modules/LetsEncrypt/resources/views/actions/certbot-http-secure-command.blade.php new file mode 100644 index 0000000..9c8ee8f --- /dev/null +++ b/web/Modules/LetsEncrypt/resources/views/actions/certbot-http-secure-command.blade.php @@ -0,0 +1,9 @@ +sudo certbot certonly \ + --non-interactive \ + --agree-tos \ + --manual \ + --preferred-challenges=http \ + -d {{$domain}} \ + --email {{$email}} \ + --manual-auth-hook /usr/local/phyre/web/Modules/LetsEncrypt/shell/hooks/pre/http-authenticator.sh \ + --force-renewal diff --git a/web/Modules/LetsEncrypt/routes/api.php b/web/Modules/LetsEncrypt/routes/api.php index 1e1d1dc..f56dab8 100644 --- a/web/Modules/LetsEncrypt/routes/api.php +++ b/web/Modules/LetsEncrypt/routes/api.php @@ -37,9 +37,18 @@ Route::post('letsencrypt/secure', function () { return response()->json(['error' => 'Domain already secured'], 400); } + $findHostingSubscription = \App\Models\HostingSubscription::where('id', $findDomain->hosting_subscription_id)->first(); + if (! $findHostingSubscription) { + return response()->json(['error' => 'Domain not hosted'], 400); + } + $generalSettings = Settings::general(); - $acmeConfigYaml = view('letsencrypt::actions.acme-config-yaml', [ + $sslCertificateFilePath = '/etc/letsencrypt/live/'.$findDomain->domain.'/cert.pem'; + $sslCertificateKeyFilePath = '/etc/letsencrypt/live/'.$findDomain->domain.'/privkey.pem'; + $sslCertificateChainFilePath = '/etc/letsencrypt/live/'.$findDomain->domain.'/fullchain.pem'; + + $certbotHttpSecureCommand = view('letsencrypt::actions.certbot-http-secure-command', [ 'domain' => $findDomain->domain, 'domainRoot' => $findDomain->domain_root, 'domainPublic' => $findDomain->domain_public, @@ -49,26 +58,15 @@ Route::post('letsencrypt/secure', function () { 'organization' => $generalSettings['organization_name'], ])->render(); - file_put_contents($findDomain->domain_root.'/acme-config.yaml', $acmeConfigYaml); - - $amePHPPharFile = base_path().'/Modules/LetsEncrypt/Actions/acmephp.phar'; - - $phyrePHP = ApiClient::getPhyrePHP(); - - $command = $phyrePHP.' '.$amePHPPharFile.' run '.$findDomain->domain_root.'/acme-config.yaml'; - - $execSSL = shell_exec($command); + $exec = shell_exec($certbotHttpSecureCommand); $validateCertificates = []; - $sslCertificateFilePath = '/root/.acmephp/master/certs/'.$findDomain->domain.'/public/cert.pem'; - $sslCertificateKeyFilePath = '/root/.acmephp/master/certs/'.$findDomain->domain.'/private/key.private.pem'; - $sslCertificateChainFilePath = '/root/.acmephp/master/certs/'.$findDomain->domain.'/public/fullchain.pem'; if (! file_exists($sslCertificateFilePath) || ! file_exists($sslCertificateKeyFilePath) || ! file_exists($sslCertificateChainFilePath)) { // Cant get all certificates - return; + return response()->json(['error' => 'Cant get all certificates'], 400); } $sslCertificateFileContent = file_get_contents($sslCertificateFilePath);