2023-04-26 13:38:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Server\New;
|
|
|
|
|
|
|
|
use App\Models\PrivateKey;
|
|
|
|
use App\Models\Server;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class ByIp extends Component
|
|
|
|
{
|
|
|
|
public $private_keys;
|
2023-05-12 13:39:07 +00:00
|
|
|
public int|null $private_key_id = null;
|
2023-04-26 13:38:50 +00:00
|
|
|
public $new_private_key_name;
|
|
|
|
public $new_private_key_description;
|
|
|
|
public $new_private_key_value;
|
|
|
|
|
2023-05-02 07:20:08 +00:00
|
|
|
public string $name;
|
2023-05-03 10:38:57 +00:00
|
|
|
public string|null $description = null;
|
2023-04-26 13:38:50 +00:00
|
|
|
public string $ip;
|
|
|
|
public string $user = 'root';
|
|
|
|
public int $port = 22;
|
|
|
|
|
2023-05-12 13:39:07 +00:00
|
|
|
protected $rules = [
|
|
|
|
'name' => 'required',
|
|
|
|
'ip' => 'required',
|
|
|
|
'user' => 'required',
|
|
|
|
'port' => 'required|integer',
|
|
|
|
];
|
2023-04-26 13:38:50 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-05-02 10:47:52 +00:00
|
|
|
$this->name = generateRandomName();
|
2023-05-16 08:03:34 +00:00
|
|
|
if ($this->private_keys->count() > 0) {
|
|
|
|
$this->private_key_id = $this->private_keys->first()->id;
|
|
|
|
}
|
2023-04-26 13:38:50 +00:00
|
|
|
}
|
2023-05-12 13:39:07 +00:00
|
|
|
public function setPrivateKey(string $private_key_id)
|
2023-04-26 13:38:50 +00:00
|
|
|
{
|
|
|
|
$this->private_key_id = $private_key_id;
|
|
|
|
}
|
|
|
|
public function submit()
|
|
|
|
{
|
2023-05-12 13:39:07 +00:00
|
|
|
try {
|
|
|
|
if (!$this->private_key_id) {
|
|
|
|
return $this->emit('error', 'You must select a private key');
|
|
|
|
}
|
|
|
|
$this->validate();
|
|
|
|
$server = Server::create([
|
|
|
|
'name' => $this->name,
|
|
|
|
'description' => $this->description,
|
|
|
|
'ip' => $this->ip,
|
|
|
|
'user' => $this->user,
|
|
|
|
'port' => $this->port,
|
|
|
|
'team_id' => session('currentTeam')->id,
|
|
|
|
'private_key_id' => $this->private_key_id
|
|
|
|
]);
|
|
|
|
return redirect()->route('server.show', $server->uuid);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return generalErrorHandler($e);
|
2023-05-03 08:25:44 +00:00
|
|
|
}
|
2023-04-26 13:38:50 +00:00
|
|
|
}
|
|
|
|
}
|