mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 14:36:17 +00:00
Force SSL and Multi SSL (#456)
This commit is contained in:
54
database/migrations/2025_01_31_155828_update_ssls_table.php
Normal file
54
database/migrations/2025_01_31_155828_update_ssls_table.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\SslType;
|
||||
use App\Models\Site;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('ssls', function (Blueprint $table) {
|
||||
$table->boolean('is_active')->default(false);
|
||||
$table->string('certificate_path')->nullable();
|
||||
$table->string('pk_path')->nullable();
|
||||
$table->string('ca_path')->nullable();
|
||||
});
|
||||
Site::query()->chunk(100, function ($sites) {
|
||||
foreach ($sites as $site) {
|
||||
foreach ($site->ssls as $ssl) {
|
||||
if ($ssl->type === SslType::LETSENCRYPT) {
|
||||
$ssl->certificate_path = $ssl->certificate;
|
||||
$ssl->pk_path = $ssl->pk;
|
||||
$ssl->ca_path = $ssl->ca;
|
||||
$ssl->certificate = null;
|
||||
$ssl->pk = null;
|
||||
$ssl->ca = null;
|
||||
}
|
||||
if ($ssl->type === SslType::CUSTOM) {
|
||||
$ssl->certificate_path = '/etc/ssl/'.$ssl->site->domain.'/cert.pem';
|
||||
$ssl->pk_path = '/etc/ssl/'.$ssl->site->domain.'/privkey.pem';
|
||||
$ssl->ca_path = '/etc/ssl/'.$ssl->site->domain.'/fullchain.pem';
|
||||
}
|
||||
$ssl->save();
|
||||
}
|
||||
$activeSSL = $site->ssls()->where('expires_at', '>=', now())->latest()->first();
|
||||
if ($activeSSL) {
|
||||
$activeSSL->update(['is_active' => true]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('ssls', function (Blueprint $table) {
|
||||
$table->dropColumn('is_active');
|
||||
$table->dropColumn('certificate_path');
|
||||
$table->dropColumn('pk_path');
|
||||
$table->dropColumn('ca_path');
|
||||
});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user