feat(ssl): regenerate certificate and valid until UI
This commit is contained in:
@@ -4,7 +4,9 @@ namespace App\Livewire\Project\Database\Postgresql;
|
||||
|
||||
use App\Actions\Database\StartDatabaseProxy;
|
||||
use App\Actions\Database\StopDatabaseProxy;
|
||||
use App\Helpers\SslHelper;
|
||||
use App\Models\Server;
|
||||
use App\Models\SslCertificate;
|
||||
use App\Models\StandalonePostgresql;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
@@ -107,6 +109,45 @@ class General extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function regenerateSslCertificate()
|
||||
{
|
||||
try {
|
||||
if (! $this->database->enable_ssl) {
|
||||
$this->dispatch('error', 'SSL is not enabled for this database.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$server = $this->database->destination->server;
|
||||
|
||||
$existingCert = SslCertificate::where('resource_type', $this->database->getMorphClass())
|
||||
->where('resource_id', $this->database->id)
|
||||
->first();
|
||||
|
||||
if (! $existingCert) {
|
||||
$this->dispatch('error', 'No existing SSL certificate found for this database.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$caCert = SslCertificate::where('server_id', $server->id)->firstOrFail();
|
||||
|
||||
SslHelper::generateSslCertificate(
|
||||
commonName: $existingCert->common_name,
|
||||
subjectAlternativeNames: $existingCert->subject_alternative_names ?? [],
|
||||
resourceType: $existingCert->resource_type,
|
||||
resourceId: $existingCert->resource_id,
|
||||
serverId: $existingCert->server_id,
|
||||
caCert: $caCert->ssl_certificate,
|
||||
caKey: $caCert->ssl_private_key,
|
||||
);
|
||||
|
||||
$this->dispatch('success', 'SSL certificates have been regenerated. Please restart the database for changes to take effect.');
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
{
|
||||
try {
|
||||
|
@@ -74,7 +74,39 @@
|
||||
@endif
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<h3 class="py-2">SSL Configuration</h3>
|
||||
<div class="flex items-center justify-between py-2">
|
||||
<div class="flex flex-col gap-1">
|
||||
<h3>SSL Configuration</h3>
|
||||
@if($database->enable_ssl)
|
||||
@php
|
||||
$cert = \App\Models\SslCertificate::where('resource_type', $database->getMorphClass())
|
||||
->where('resource_id', $database->id)
|
||||
->first();
|
||||
@endphp
|
||||
@if($cert)
|
||||
<span class="text-sm">Valid until:
|
||||
@if(now()->gt($cert->valid_until))
|
||||
<span class="text-red-500">{{ $cert->valid_until->format('d.m.Y H:i:s') }} - Expired</span>
|
||||
@elseif(now()->addDays(30)->gt($cert->valid_until))
|
||||
<span class="text-red-500">{{ $cert->valid_until->format('d.m.Y H:i:s') }} - Expiring soon</span>
|
||||
@else
|
||||
<span>{{ $cert->valid_until->format('d.m.Y H:i:s') }}</span>
|
||||
@endif
|
||||
</span>
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
@if($database->enable_ssl)
|
||||
<x-modal-confirmation
|
||||
title="Regenerate SSL Certificates"
|
||||
buttonTitle="Regenerate SSL Certificates"
|
||||
:actions="['The SSL certificate of this database will be regenerated.','You must restart the database after regenerating the certificate to start using the new certificate.']"
|
||||
submitAction="regenerateSslCertificate"
|
||||
:confirmWithText="false"
|
||||
:confirmWithPassword="false"
|
||||
/>
|
||||
@endif
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<x-forms.checkbox id="database.enable_ssl" label="Enable SSL" wire:model.live="database.enable_ssl" instantSave="instantSaveSSL" />
|
||||
@if($database->enable_ssl)
|
||||
|
Reference in New Issue
Block a user