2023-04-26 13:38:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Server\New;
|
|
|
|
|
2023-09-06 13:00:56 +00:00
|
|
|
use App\Enums\ProxyStatus;
|
|
|
|
use App\Enums\ProxyTypes;
|
2023-04-26 13:38:50 +00:00
|
|
|
use App\Models\Server;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class ByIp extends Component
|
|
|
|
{
|
|
|
|
public $private_keys;
|
2023-08-14 13:22:29 +00:00
|
|
|
public $limit_reached;
|
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-16 09:02:51 +00:00
|
|
|
public bool $is_part_of_swarm = false;
|
2023-04-26 13:38:50 +00:00
|
|
|
|
2023-05-12 13:39:07 +00:00
|
|
|
protected $rules = [
|
2023-06-16 10:35:40 +00:00
|
|
|
'name' => 'required|string',
|
|
|
|
'description' => 'nullable|string',
|
|
|
|
'ip' => 'required|ip',
|
|
|
|
'user' => 'required|string',
|
2023-05-12 13:39:07 +00:00
|
|
|
'port' => 'required|integer',
|
2023-06-16 10:35:40 +00:00
|
|
|
];
|
|
|
|
protected $validationAttributes = [
|
|
|
|
'name' => 'name',
|
|
|
|
'description' => 'description',
|
|
|
|
'ip' => 'ip',
|
|
|
|
'user' => 'user',
|
|
|
|
'port' => 'port',
|
2023-05-12 13:39:07 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-04-26 13:38:50 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-05-24 12:26:50 +00:00
|
|
|
$this->name = generate_random_name();
|
2023-05-16 09:02:51 +00:00
|
|
|
$this->private_key_id = $this->private_keys->first()->id;
|
2023-04-26 13:38:50 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +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;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-16 09:02:51 +00:00
|
|
|
public function instantSave()
|
|
|
|
{
|
2023-06-15 08:48:13 +00:00
|
|
|
$this->emit('success', 'Application settings updated!');
|
2023-05-16 09:02:51 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-04-26 13:38:50 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
2023-06-16 10:35:40 +00:00
|
|
|
$this->validate();
|
2023-05-12 13:39:07 +00:00
|
|
|
try {
|
2023-09-12 11:14:01 +00:00
|
|
|
if (is_null($this->private_key_id)) {
|
2023-05-12 13:39:07 +00:00
|
|
|
return $this->emit('error', 'You must select a private key');
|
|
|
|
}
|
|
|
|
$server = Server::create([
|
|
|
|
'name' => $this->name,
|
|
|
|
'description' => $this->description,
|
|
|
|
'ip' => $this->ip,
|
|
|
|
'user' => $this->user,
|
|
|
|
'port' => $this->port,
|
2023-08-22 15:44:49 +00:00
|
|
|
'team_id' => currentTeam()->id,
|
2023-05-16 09:02:51 +00:00
|
|
|
'private_key_id' => $this->private_key_id,
|
2023-09-06 13:00:56 +00:00
|
|
|
'proxy' => [
|
|
|
|
"type" => ProxyTypes::TRAEFIK_V2->value,
|
|
|
|
"status" => ProxyStatus::EXITED->value,
|
|
|
|
]
|
|
|
|
|
2023-05-12 13:39:07 +00:00
|
|
|
]);
|
2023-05-16 09:02:51 +00:00
|
|
|
$server->settings->is_part_of_swarm = $this->is_part_of_swarm;
|
|
|
|
$server->settings->save();
|
2023-05-12 13:39:07 +00:00
|
|
|
return redirect()->route('server.show', $server->uuid);
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-06-09 13:55:21 +00:00
|
|
|
return general_error_handler(err: $e);
|
2023-05-03 08:25:44 +00:00
|
|
|
}
|
2023-04-26 13:38:50 +00:00
|
|
|
}
|
|
|
|
}
|