diff --git a/web/Modules/LetsEncrypt/App/Providers/LetsEncryptServiceProvider.php b/web/Modules/LetsEncrypt/App/Providers/LetsEncryptServiceProvider.php index a7095f2..481f047 100644 --- a/web/Modules/LetsEncrypt/App/Providers/LetsEncryptServiceProvider.php +++ b/web/Modules/LetsEncrypt/App/Providers/LetsEncryptServiceProvider.php @@ -7,6 +7,7 @@ use BladeUI\Icons\Factory; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; +use Modules\LetsEncrypt\Console\Commands\LetsEncryptHttpAuthenticatorHook; use Modules\LetsEncrypt\LetsEncryptApacheVirtualHostConfig; use Modules\LetsEncrypt\Listeners\DomainIsCreatedListener; @@ -54,7 +55,9 @@ class LetsEncryptServiceProvider extends ServiceProvider */ protected function registerCommands(): void { - // $this->commands([]); + $this->commands([ + LetsEncryptHttpAuthenticatorHook::class, + ]); } /** diff --git a/web/Modules/LetsEncrypt/Console/Commands/LetsencryptHttpAuthenticatorHook.php b/web/Modules/LetsEncrypt/Console/Commands/LetsEncryptHttpAuthenticatorHook.php similarity index 51% rename from web/Modules/LetsEncrypt/Console/Commands/LetsencryptHttpAuthenticatorHook.php rename to web/Modules/LetsEncrypt/Console/Commands/LetsEncryptHttpAuthenticatorHook.php index 272be37..6ee2589 100644 --- a/web/Modules/LetsEncrypt/Console/Commands/LetsencryptHttpAuthenticatorHook.php +++ b/web/Modules/LetsEncrypt/Console/Commands/LetsEncryptHttpAuthenticatorHook.php @@ -2,10 +2,11 @@ namespace Modules\LetsEncrypt\Console\Commands; +use App\Models\Domain; use Illuminate\Console\Command; use Illuminate\Support\Str; -class LetsencryptAuthenticatorHook extends Command +class LetsEncryptHttpAuthenticatorHook extends Command { /** * The name and signature of the console command. @@ -33,8 +34,24 @@ class LetsencryptAuthenticatorHook extends Command $certbotValidation = $this->option('certbot-validation'); $certbotDomain = $this->option('certbot-domain'); + $findDomain = Domain::where('domain', $certbotDomain)->first(); + if (!$findDomain) { + $this->error('Domain not found'); + return; + } + if (!is_dir($findDomain->domain_public)) { + $this->error('Domain public directory not found'); + return; + } - // .well-known/acme-challenge + $acmeChallangePath = $findDomain->domain_public . '/.well-known/acme-challenge'; + if (!is_dir($acmeChallangePath)) { + shell_exec('mkdir -p ' . $acmeChallangePath); + } + $authFilePath = $acmeChallangePath . '/' . $certbotToken; + file_put_contents($authFilePath, $certbotValidation); + + $this->info('Auth file created: ' . $authFilePath); } } diff --git a/web/Modules/LetsEncrypt/shell/hooks/pre/http-authenticator.sh b/web/Modules/LetsEncrypt/shell/hooks/pre/http-authenticator.sh old mode 100644 new mode 100755