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
|
|
|
|
2023-09-18 10:18:45 +00:00
|
|
|
use App\Actions\Proxy\CheckConfiguration;
|
|
|
|
use App\Actions\Proxy\SaveConfiguration;
|
2024-03-04 09:42:54 +00:00
|
|
|
use App\Actions\Proxy\StartProxy;
|
2023-05-03 05:23:45 +00:00
|
|
|
use App\Models\Server;
|
2023-09-24 09:10:50 +00:00
|
|
|
use Illuminate\Support\Str;
|
2024-06-10 20:43:34 +00:00
|
|
|
use Livewire\Component;
|
2023-05-03 05:23:45 +00:00
|
|
|
|
|
|
|
class Proxy extends Component
|
|
|
|
{
|
|
|
|
public Server $server;
|
|
|
|
|
2023-09-06 13:00:56 +00:00
|
|
|
public ?string $selectedProxy = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-05-15 11:45:37 +00:00
|
|
|
public $proxy_settings = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-09-11 20:29:34 +00:00
|
|
|
public ?string $redirect_url = null;
|
2023-05-03 05:23:45 +00:00
|
|
|
|
2023-08-08 09:51:36 +00:00
|
|
|
protected $listeners = ['proxyStatusUpdated', 'saveConfiguration' => 'submit'];
|
|
|
|
|
2023-06-22 12:18:17 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2024-03-12 11:45:55 +00:00
|
|
|
$this->selectedProxy = $this->server->proxyType();
|
2023-09-11 20:29:34 +00:00
|
|
|
$this->redirect_url = data_get($this->server, 'proxy.redirect_url');
|
2023-06-22 12:18:17 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-14 11:01:55 +00:00
|
|
|
public function proxyStatusUpdated()
|
2023-05-15 19:14:45 +00:00
|
|
|
{
|
2024-03-04 08:12:23 +00:00
|
|
|
$this->dispatch('refresh')->self();
|
2023-05-15 19:14:45 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-28 12:44:26 +00:00
|
|
|
public function change_proxy()
|
2023-06-08 06:39:00 +00:00
|
|
|
{
|
2023-07-14 11:38:24 +00:00
|
|
|
$this->server->proxy = null;
|
2023-06-08 06:39:00 +00:00
|
|
|
$this->server->save();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-09-06 13:00:56 +00:00
|
|
|
public function select_proxy($proxy_type)
|
2023-05-15 11:45:37 +00:00
|
|
|
{
|
2023-09-25 07:17:42 +00:00
|
|
|
$this->server->proxy->set('status', 'exited');
|
|
|
|
$this->server->proxy->set('type', $proxy_type);
|
2023-05-15 11:45:37 +00:00
|
|
|
$this->server->save();
|
2023-09-06 13:00:56 +00:00
|
|
|
$this->selectedProxy = $this->server->proxy->type;
|
2024-03-04 09:42:54 +00:00
|
|
|
if ($this->selectedProxy !== 'NONE') {
|
|
|
|
StartProxy::run($this->server, false);
|
|
|
|
}
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('proxyStatusUpdated');
|
2023-05-15 11:45:37 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-28 12:44:26 +00:00
|
|
|
public function submit()
|
2023-05-15 11:45:37 +00:00
|
|
|
{
|
|
|
|
try {
|
2023-09-21 09:03:52 +00:00
|
|
|
SaveConfiguration::run($this->server, $this->proxy_settings);
|
2023-06-22 12:18:17 +00:00
|
|
|
$this->server->proxy->redirect_url = $this->redirect_url;
|
|
|
|
$this->server->save();
|
2024-03-12 09:42:56 +00:00
|
|
|
$this->server->setupDefault404Redirect();
|
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
|
|
|
|
2023-07-28 12:44:26 +00:00
|
|
|
public function reset_proxy_configuration()
|
2023-05-03 05:23:45 +00:00
|
|
|
{
|
2023-05-15 11:45:37 +00:00
|
|
|
try {
|
2023-09-18 10:18:45 +00:00
|
|
|
$this->proxy_settings = CheckConfiguration::run($this->server, true);
|
2024-03-12 09:42:56 +00:00
|
|
|
SaveConfiguration::run($this->server, $this->proxy_settings);
|
|
|
|
$this->server->save();
|
|
|
|
$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-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 {
|
2023-09-18 10:18:45 +00:00
|
|
|
$this->proxy_settings = CheckConfiguration::run($this->server);
|
2023-09-24 09:10:50 +00:00
|
|
|
if (Str::of($this->proxy_settings)->contains('--api.dashboard=true') && Str::of($this->proxy_settings)->contains('--api.insecure=true')) {
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('traefikDashboardAvailable', true);
|
2023-09-24 09:10:50 +00:00
|
|
|
} else {
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('traefikDashboardAvailable', false);
|
2023-09-24 09:10:50 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|