This commit is contained in:
Bozhidar 2024-09-10 16:21:30 +03:00
parent 02da12b234
commit 0c699059f5
5 changed files with 76 additions and 3 deletions

View file

@ -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();
});
}

View file

@ -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(),
]);
}

View file

@ -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;
}
});
}

View file

@ -0,0 +1,18 @@
<?php
namespace Modules\LetsEncrypt;
use App\ModulePostInstall;
class PostInstall extends ModulePostInstall
{
public $supportLog = true;
public function run()
{
$installDockerShellFile = base_path('Modules/LetsEncrypt/shell/install-letsencrypt.sh');
shell_exec("chmod +x $installDockerShellFile");
shell_exec("bash $installDockerShellFile >> $this->logFile &");
}
}

View file

@ -0,0 +1,2 @@
# install certbot
sudo apt-get install certbot -y