diff --git a/app/Http/Livewire/PrivateKey/Create.php b/app/Http/Livewire/PrivateKey/Create.php index 37363195d..c48b4490e 100644 --- a/app/Http/Livewire/PrivateKey/Create.php +++ b/app/Http/Livewire/PrivateKey/Create.php @@ -4,13 +4,15 @@ namespace App\Http\Livewire\PrivateKey; use App\Models\PrivateKey; use Livewire\Component; +use phpseclib3\Crypt\PublicKeyLoader; class Create extends Component { - public string|null $from = null; + public ?string $from = null; public string $name; - public string|null $description = null; + public ?string $description = null; public string $value; + public ?string $publicKey = null; protected $rules = [ 'name' => 'required|string', 'value' => 'required|string', @@ -20,6 +22,23 @@ class Create extends Component 'value' => 'private Key', ]; + public function generateNewKey() + { + $this->name = generate_random_name(); + $this->description = 'Created by Coolify'; + ['private' => $this->value, 'public' => $this->publicKey] = generateSSHKey(); + } + public function updated($updateProperty) + { + if ($updateProperty === 'value') { + try { + $this->publicKey = PublicKeyLoader::load($this->$updateProperty)->getPublicKey()->toString('OpenSSH',['comment' => '']); + } catch (\Throwable $e) { + $this->publicKey = "Invalid private key"; + } + } + $this->validateOnly($updateProperty); + } public function createPrivateKey() { $this->validate(); diff --git a/app/View/Components/Forms/Textarea.php b/app/View/Components/Forms/Textarea.php index c85c8b6f7..a34a08339 100644 --- a/app/View/Components/Forms/Textarea.php +++ b/app/View/Components/Forms/Textarea.php @@ -24,6 +24,7 @@ class Textarea extends Component public bool $disabled = false, public bool $readonly = false, public string|null $helper = null, + public bool $realtimeValidation = false, public string $defaultClass = "textarea bg-coolgray-200 rounded text-white scrollbar disabled:bg-coolgray-200/50 disabled:border-none placeholder:text-coolgray-500 read-only:text-neutral-500 read-only:bg-coolgray-200/50" ) { // diff --git a/resources/views/components/forms/textarea.blade.php b/resources/views/components/forms/textarea.blade.php index f00a0e1d7..be45629ab 100644 --- a/resources/views/components/forms/textarea.blade.php +++ b/resources/views/components/forms/textarea.blade.php @@ -30,9 +30,12 @@ @endif + @if ($realtimeValidation) wire:model.debounce.500ms="{{ $id }}" + @else + wire:model.defer={{ $value ?? $id }} + wire:dirty.class="input-warning"@endif + @disabled($disabled) @readonly($readonly) @required($required) id="{{ $id }}" name="{{ $name }}" + name={{ $id }} > @error($id)