feat: generate ssh key
This commit is contained in:
parent
019670d5d1
commit
cf28490acc
@ -4,13 +4,15 @@ namespace App\Http\Livewire\PrivateKey;
|
|||||||
|
|
||||||
use App\Models\PrivateKey;
|
use App\Models\PrivateKey;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use phpseclib3\Crypt\PublicKeyLoader;
|
||||||
|
|
||||||
class Create extends Component
|
class Create extends Component
|
||||||
{
|
{
|
||||||
public string|null $from = null;
|
public ?string $from = null;
|
||||||
public string $name;
|
public string $name;
|
||||||
public string|null $description = null;
|
public ?string $description = null;
|
||||||
public string $value;
|
public string $value;
|
||||||
|
public ?string $publicKey = null;
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
'name' => 'required|string',
|
'name' => 'required|string',
|
||||||
'value' => 'required|string',
|
'value' => 'required|string',
|
||||||
@ -20,6 +22,23 @@ class Create extends Component
|
|||||||
'value' => 'private Key',
|
'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()
|
public function createPrivateKey()
|
||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
@ -24,6 +24,7 @@ class Textarea extends Component
|
|||||||
public bool $disabled = false,
|
public bool $disabled = false,
|
||||||
public bool $readonly = false,
|
public bool $readonly = false,
|
||||||
public string|null $helper = null,
|
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"
|
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"
|
||||||
) {
|
) {
|
||||||
//
|
//
|
||||||
|
@ -30,9 +30,12 @@
|
|||||||
</label>
|
</label>
|
||||||
@endif
|
@endif
|
||||||
<textarea placeholder="{{ $placeholder }}" {{ $attributes->merge(['class' => $defaultClass]) }}
|
<textarea placeholder="{{ $placeholder }}" {{ $attributes->merge(['class' => $defaultClass]) }}
|
||||||
wire:model.defer={{ $id }} @disabled($disabled) @readonly($readonly) @required($required)
|
@if ($realtimeValidation) wire:model.debounce.500ms="{{ $id }}"
|
||||||
id="{{ $id }}" name="{{ $name }}" name={{ $id }} wire:model.defer={{ $value ?? $id }}
|
@else
|
||||||
wire:dirty.class="input-warning"></textarea>
|
wire:model.defer={{ $value ?? $id }}
|
||||||
|
wire:dirty.class="input-warning"@endif
|
||||||
|
@disabled($disabled) @readonly($readonly) @required($required) id="{{ $id }}" name="{{ $name }}"
|
||||||
|
name={{ $id }} ></textarea>
|
||||||
@error($id)
|
@error($id)
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span class="text-red-500 label-text-alt">{{ $message }}</span>
|
<span class="text-red-500 label-text-alt">{{ $message }}</span>
|
||||||
|
@ -4,8 +4,13 @@
|
|||||||
<x-forms.input id="name" label="Name" required />
|
<x-forms.input id="name" label="Name" required />
|
||||||
<x-forms.input id="description" label="Description" />
|
<x-forms.input id="description" label="Description" />
|
||||||
</div>
|
</div>
|
||||||
<x-forms.textarea id="value" rows="10" placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"
|
<x-forms.textarea realtimeValidation id="value" rows="10"
|
||||||
label="Private Key" required />
|
placeholder="-----BEGIN OPENSSH PRIVATE KEY-----" label="Private Key" required />
|
||||||
|
<x-forms.button wire:click="generateNewKey">Generate new SSH key for me</x-forms.button>
|
||||||
|
<x-forms.textarea id="publicKey" rows="6" readonly label="Public Key" />
|
||||||
|
<span class="font-bold text-warning">ACTION REQUIRED: Copy the 'Public Key' to your server's
|
||||||
|
~/.ssh/authorized_keys
|
||||||
|
file.</span>
|
||||||
<x-forms.button type="submit">
|
<x-forms.button type="submit">
|
||||||
Save Private Key
|
Save Private Key
|
||||||
</x-forms.button>
|
</x-forms.button>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user