2023-05-03 05:23:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Server;
|
2023-05-03 05:23:45 +00:00
|
|
|
|
2025-09-09 10:52:19 +00:00
|
|
|
use App\Actions\Proxy\GetProxyConfiguration;
|
|
|
|
|
use App\Actions\Proxy\SaveProxyConfiguration;
|
2023-05-03 05:23:45 +00:00
|
|
|
use App\Models\Server;
|
2025-08-22 11:02:11 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2024-06-10 20:43:34 +00:00
|
|
|
use Livewire\Component;
|
2023-05-03 05:23:45 +00:00
|
|
|
|
|
|
|
|
class Proxy extends Component
|
|
|
|
|
{
|
2025-08-22 11:02:11 +00:00
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
2023-05-03 05:23:45 +00:00
|
|
|
public Server $server;
|
|
|
|
|
|
2023-09-06 13:00:56 +00:00
|
|
|
public ?string $selectedProxy = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-09-09 10:52:19 +00:00
|
|
|
public $proxySettings = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2025-09-09 10:52:19 +00:00
|
|
|
public bool $redirectEnabled = true;
|
2024-12-06 13:08:34 +00:00
|
|
|
|
2025-09-09 10:52:19 +00:00
|
|
|
public ?string $redirectUrl = null;
|
2023-05-03 05:23:45 +00:00
|
|
|
|
2025-06-24 11:34:56 +00:00
|
|
|
public function getListeners()
|
|
|
|
|
{
|
|
|
|
|
$teamId = auth()->user()->currentTeam()->id;
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'saveConfiguration' => 'submit',
|
|
|
|
|
"echo-private:team.{$teamId},ProxyStatusChangedUI" => '$refresh',
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-08-07 16:27:50 +00:00
|
|
|
protected $rules = [
|
|
|
|
|
'server.settings.generate_exact_labels' => 'required|boolean',
|
|
|
|
|
];
|
|
|
|
|
|
2023-06-22 12:18:17 +00:00
|
|
|
public function mount()
|
|
|
|
|
{
|
2024-03-12 11:45:55 +00:00
|
|
|
$this->selectedProxy = $this->server->proxyType();
|
2025-09-09 10:52:19 +00:00
|
|
|
$this->redirectEnabled = data_get($this->server, 'proxy.redirect_enabled', true);
|
|
|
|
|
$this->redirectUrl = data_get($this->server, 'proxy.redirect_url');
|
2023-06-22 12:18:17 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2025-09-09 10:52:19 +00:00
|
|
|
public function getConfigurationFilePathProperty()
|
|
|
|
|
{
|
2025-09-21 14:50:32 +00:00
|
|
|
return $this->server->proxyPath().'docker-compose.yml';
|
2025-09-09 10:52:19 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-08-07 16:27:50 +00:00
|
|
|
public function changeProxy()
|
2023-06-08 06:39:00 +00:00
|
|
|
{
|
2025-08-22 11:02:11 +00:00
|
|
|
$this->authorize('update', $this->server);
|
2023-07-14 11:38:24 +00:00
|
|
|
$this->server->proxy = null;
|
2023-06-08 06:39:00 +00:00
|
|
|
$this->server->save();
|
2025-06-06 17:18:32 +00:00
|
|
|
|
2024-12-06 13:08:34 +00:00
|
|
|
$this->dispatch('reloadWindow');
|
2023-06-08 06:39:00 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-08-07 16:27:50 +00:00
|
|
|
public function selectProxy($proxy_type)
|
2023-05-15 11:45:37 +00:00
|
|
|
{
|
2024-11-12 13:30:05 +00:00
|
|
|
try {
|
2025-08-22 11:02:11 +00:00
|
|
|
$this->authorize('update', $this->server);
|
2024-11-12 13:30:05 +00:00
|
|
|
$this->server->changeProxy($proxy_type, async: false);
|
|
|
|
|
$this->selectedProxy = $this->server->proxy->type;
|
2025-06-06 17:18:32 +00:00
|
|
|
|
2024-12-06 13:08:34 +00:00
|
|
|
$this->dispatch('reloadWindow');
|
2024-11-12 13:30:05 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
2024-03-04 09:42:54 +00:00
|
|
|
}
|
2023-05-15 11:45:37 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2024-08-07 16:27:50 +00:00
|
|
|
public function instantSave()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-08-22 11:02:11 +00:00
|
|
|
$this->authorize('update', $this->server);
|
2024-08-07 16:27:50 +00:00
|
|
|
$this->validate();
|
|
|
|
|
$this->server->settings->save();
|
|
|
|
|
$this->dispatch('success', 'Settings saved.');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-10 15:44:52 +00:00
|
|
|
public function instantSaveRedirect()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-08-22 11:02:11 +00:00
|
|
|
$this->authorize('update', $this->server);
|
2025-09-09 10:52:19 +00:00
|
|
|
$this->server->proxy->redirect_enabled = $this->redirectEnabled;
|
2024-10-10 15:44:52 +00:00
|
|
|
$this->server->save();
|
|
|
|
|
$this->server->setupDefaultRedirect();
|
|
|
|
|
$this->dispatch('success', 'Proxy configuration saved.');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-28 12:44:26 +00:00
|
|
|
public function submit()
|
2023-05-15 11:45:37 +00:00
|
|
|
{
|
|
|
|
|
try {
|
2025-08-22 11:02:11 +00:00
|
|
|
$this->authorize('update', $this->server);
|
2025-09-09 10:52:19 +00:00
|
|
|
SaveProxyConfiguration::run($this->server, $this->proxySettings);
|
|
|
|
|
$this->server->proxy->redirect_url = $this->redirectUrl;
|
2023-06-22 12:18:17 +00:00
|
|
|
$this->server->save();
|
2024-10-10 15:44:52 +00:00
|
|
|
$this->server->setupDefaultRedirect();
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('success', 'Proxy configuration saved.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 12:47:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-15 11:45:37 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2025-09-09 10:52:19 +00:00
|
|
|
public function resetProxyConfiguration()
|
2023-05-03 05:23:45 +00:00
|
|
|
{
|
2023-05-15 11:45:37 +00:00
|
|
|
try {
|
2025-08-22 11:02:11 +00:00
|
|
|
$this->authorize('update', $this->server);
|
2025-09-09 10:52:19 +00:00
|
|
|
// Explicitly regenerate default configuration
|
|
|
|
|
$this->proxySettings = GetProxyConfiguration::run($this->server, forceRegenerate: true);
|
|
|
|
|
SaveProxyConfiguration::run($this->server, $this->proxySettings);
|
2024-03-12 09:42:56 +00:00
|
|
|
$this->server->save();
|
2025-09-09 10:52:19 +00:00
|
|
|
$this->dispatch('success', 'Proxy configuration reset to default.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 12:47:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-15 11:45:37 +00:00
|
|
|
}
|
2023-05-03 05:23:45 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-09-11 20:29:34 +00:00
|
|
|
public function loadProxyConfiguration()
|
2023-05-15 20:17:31 +00:00
|
|
|
{
|
|
|
|
|
try {
|
2025-09-09 10:52:19 +00:00
|
|
|
$this->proxySettings = GetProxyConfiguration::run($this->server);
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 12:47:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-15 20:17:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|