lasthourcloud/app/Livewire/Server/ConfigureCloudflareTunnels.php

51 lines
1.5 KiB
PHP
Raw Normal View History

2024-03-27 17:24:24 +00:00
<?php
namespace App\Livewire\Server;
use App\Actions\Server\ConfigureCloudflared;
use App\Models\Server;
use Livewire\Component;
class ConfigureCloudflareTunnels extends Component
{
public $server_id;
2024-06-10 20:43:34 +00:00
2024-03-27 17:24:24 +00:00
public string $cloudflare_token;
2024-06-10 20:43:34 +00:00
public string $ssh_domain;
2024-06-10 20:43:34 +00:00
2024-03-27 17:24:24 +00:00
public function alreadyConfigured()
{
try {
$server = Server::ownedByCurrentTeam()->where('id', $this->server_id)->firstOrFail();
$server->settings->is_cloudflare_tunnel = true;
$server->settings->save();
$this->dispatch('success', 'Cloudflare Tunnels configured successfully.');
$this->dispatch('serverInstalled');
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
2024-06-10 20:43:34 +00:00
2024-03-27 17:24:24 +00:00
public function submit()
{
try {
$server = Server::ownedByCurrentTeam()->where('id', $this->server_id)->firstOrFail();
ConfigureCloudflared::run($server, $this->cloudflare_token);
$server->settings->is_cloudflare_tunnel = true;
$server->ip = $this->ssh_domain;
$server->save();
2024-03-27 17:24:24 +00:00
$server->settings->save();
$this->dispatch('success', 'Cloudflare Tunnels configured successfully.');
$this->dispatch('serverInstalled');
2024-06-10 20:43:34 +00:00
} catch (\Throwable $e) {
2024-03-27 17:24:24 +00:00
return handleError($e, $this);
}
}
2024-06-10 20:43:34 +00:00
2024-03-27 17:24:24 +00:00
public function render()
{
return view('livewire.server.configure-cloudflare-tunnels');
}
}