diff --git a/web/Modules/LetsEncrypt/Database/migrations/2024_04_16_131552_create_lets_encrypt_certificates_table.php b/web/Modules/LetsEncrypt/Database/migrations/2024_04_16_131552_create_lets_encrypt_certificates_table.php index d91f7d3..b332e58 100644 --- a/web/Modules/LetsEncrypt/Database/migrations/2024_04_16_131552_create_lets_encrypt_certificates_table.php +++ b/web/Modules/LetsEncrypt/Database/migrations/2024_04_16_131552_create_lets_encrypt_certificates_table.php @@ -13,7 +13,16 @@ return new class extends Migration { Schema::create('lets_encrypt_certificates', function (Blueprint $table) { $table->id(); - $table->bigInteger('domain_ssl_certificate_id'); + $table->string('domain')->nullable(); + $table->string('email')->nullable(); + $table->longText('certificate')->nullable(); + $table->longText('private_key')->nullable(); + $table->longText('chain')->nullable(); + $table->longText('fullchain')->nullable(); + $table->string('expires_at')->nullable(); + $table->string('status')->nullable(); + $table->bigInteger('domain_id')->nullable(); + $table->bigInteger('domain_ssl_certificate_id')->nullable(); $table->timestamps(); }); } diff --git a/web/Modules/LetsEncrypt/Filament/Clusters/LetsEncrypt/Resources/LetsEncryptCertificateResource.php b/web/Modules/LetsEncrypt/Filament/Clusters/LetsEncrypt/Resources/LetsEncryptCertificateResource.php index 0c996a7..585e08c 100644 --- a/web/Modules/LetsEncrypt/Filament/Clusters/LetsEncrypt/Resources/LetsEncryptCertificateResource.php +++ b/web/Modules/LetsEncrypt/Filament/Clusters/LetsEncrypt/Resources/LetsEncryptCertificateResource.php @@ -33,7 +33,13 @@ class LetsEncryptCertificateResource extends Resource ->searchable() ->options( Domain::get()->pluck('domain', 'id')->toArray() - ), + )->columnSpanFull(), + + Forms\Components\TextInput::make('email') + ->label('Email') + ->required() + ->email() + ->columnSpanFull(), ]); } diff --git a/web/Modules/LetsEncrypt/Models/LetsEncryptCertificate.php b/web/Modules/LetsEncrypt/Models/LetsEncryptCertificate.php index 6bfc3b3..770268a 100644 --- a/web/Modules/LetsEncrypt/Models/LetsEncryptCertificate.php +++ b/web/Modules/LetsEncrypt/Models/LetsEncryptCertificate.php @@ -2,19 +2,57 @@ namespace Modules\LetsEncrypt\Models; +use App\Jobs\ApacheBuild; +use App\Models\Domain; +use App\Models\DomainSslCertificate; +use App\Models\HostingSubscription; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Modules\LetsEncrypt\Jobs\LetsEncryptSecureDomain; class LetsEncryptCertificate extends Model { use HasFactory; + protected $fillable = [ + 'domain_id', + 'email', + ]; + public static function boot() { parent::boot(); static::creating(function ($model) { - dd($model); + + $findDomain = Domain::where('id', $model->domain_id)->first(); + if (!$findDomain) { + throw new \Exception('Domain not found'); + } + + $findSSL = DomainSslCertificate::where('domain', $findDomain->domain)->first(); + if ($findSSL) { + throw new \Exception('SSL already exists'); + } + + $findHostingSubscription = HostingSubscription::where('id', $findDomain->hosting_subscription_id)->first(); + if (!$findHostingSubscription) { + throw new \Exception('Hosting subscription not found'); + } + + $secureDomain = new LetsEncryptSecureDomain($findDomain->id); + $secureDomain->handle(); + + ApacheBuild::dispatchSync(); + + $findSSL = DomainSslCertificate::where('domain', $findDomain->domain)->first(); + if ($findSSL) { + $model->domain_ssl_certificate_id = $findSSL->id; + $model->certificate = $findSSL->certificate; + $model->private_key = $findSSL->private_key; + $model->certificate_chain = $findSSL->certificate_chain; + $model->expires_at = $findSSL->expiration_date; + } }); } diff --git a/web/Modules/LetsEncrypt/PostInstall.php b/web/Modules/LetsEncrypt/PostInstall.php new file mode 100644 index 0000000..d5c1138 --- /dev/null +++ b/web/Modules/LetsEncrypt/PostInstall.php @@ -0,0 +1,18 @@ +> $this->logFile &"); + + } +} diff --git a/web/Modules/LetsEncrypt/shell/install-letsencrypt.sh b/web/Modules/LetsEncrypt/shell/install-letsencrypt.sh new file mode 100644 index 0000000..d135d93 --- /dev/null +++ b/web/Modules/LetsEncrypt/shell/install-letsencrypt.sh @@ -0,0 +1,2 @@ +# install certbot +sudo apt-get install certbot -y