71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use App\Actions\StartHostOnboarding;
|
|
use App\Support\HostEnrolment;
|
|
use App\Support\HostTakeoverCommand;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('layouts.admin')]
|
|
class HostCreate extends Component
|
|
{
|
|
/**
|
|
* Die fertige Befehlszeile — gesetzt, sobald der Host angelegt ist.
|
|
*
|
|
* Sie wird GENAU EINMAL gezeigt. In der Datenbank steht nur der Hash des
|
|
* Codes, und der private Schlüssel steht dort überhaupt nicht; wer die Seite
|
|
* neu lädt, bekommt sie nicht wieder, sondern legt einen neuen Code an. Das
|
|
* ist kein Versehen, sondern der Grund, warum ein abgefangener Blick auf
|
|
* einen Bildschirm später nichts mehr wert ist.
|
|
*/
|
|
public ?string $command = null;
|
|
|
|
public ?string $createdUuid = null;
|
|
|
|
public ?string $createdName = null;
|
|
|
|
#[Validate('required|string|max:255')]
|
|
public string $name = '';
|
|
|
|
#[Validate('required|string|exists:datacenters,code,active,1')]
|
|
public string $datacenter = '';
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->datacenter = (string) \App\Models\Datacenter::query()->active()->orderBy('name')->value('code');
|
|
}
|
|
|
|
#[Validate('required|ip|unique:hosts,public_ip')]
|
|
public string $public_ip = '';
|
|
|
|
#[Validate('required|string|min:8')]
|
|
public string $root_password = '';
|
|
|
|
public function save(StartHostOnboarding $action)
|
|
{
|
|
$this->authorize('hosts.manage');
|
|
$data = $this->validate();
|
|
|
|
$host = $action->run($data);
|
|
|
|
// Kein Weiterleiten mehr. Die Befehlszeile gibt es nur hier und nur
|
|
// jetzt — wer den Betreiber auf eine andere Seite schickt, schickt ihn
|
|
// von dem einzigen Wert weg, den er braucht.
|
|
$this->command = HostTakeoverCommand::for($host, HostEnrolment::issueWithKeys($host));
|
|
$this->createdUuid = $host->uuid;
|
|
$this->createdName = $host->name;
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.admin.host-create', [
|
|
'datacenters' => \App\Models\Datacenter::query()->active()->orderBy('name')->get(),
|
|
'archiveUrl' => HostTakeoverCommand::archiveUrl(),
|
|
'missingSettings' => HostTakeoverCommand::missingSettings(),
|
|
]);
|
|
}
|
|
}
|