2023-05-03 06:23:45 +01:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 19:06:32 +01:00
|
|
|
namespace App\Livewire\Server;
|
2023-05-03 06:23:45 +01:00
|
|
|
|
2023-09-18 12:18:45 +02:00
|
|
|
use App\Actions\Proxy\CheckConfiguration;
|
|
|
|
use App\Actions\Proxy\SaveConfiguration;
|
2023-05-03 06:23:45 +01:00
|
|
|
use App\Models\Server;
|
|
|
|
use Livewire\Component;
|
2023-09-24 11:10:50 +02:00
|
|
|
use Illuminate\Support\Str;
|
2023-05-03 06:23:45 +01:00
|
|
|
|
|
|
|
class Proxy extends Component
|
|
|
|
{
|
|
|
|
public Server $server;
|
|
|
|
|
2023-09-06 15:00:56 +02:00
|
|
|
public ?string $selectedProxy = null;
|
2023-05-15 13:45:37 +02:00
|
|
|
public $proxy_settings = null;
|
2023-09-11 22:29:34 +02:00
|
|
|
public ?string $redirect_url = null;
|
2023-05-03 06:23:45 +01:00
|
|
|
|
2023-08-08 11:51:36 +02:00
|
|
|
protected $listeners = ['proxyStatusUpdated', 'saveConfiguration' => 'submit'];
|
|
|
|
|
2023-06-22 14:18:17 +02:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-09-11 22:29:34 +02:00
|
|
|
$this->selectedProxy = data_get($this->server, 'proxy.type');
|
|
|
|
$this->redirect_url = data_get($this->server, 'proxy.redirect_url');
|
2023-06-22 14:18:17 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-07-14 13:01:55 +02:00
|
|
|
public function proxyStatusUpdated()
|
2023-05-15 21:14:45 +02:00
|
|
|
{
|
2023-06-02 15:15:12 +02:00
|
|
|
$this->server->refresh();
|
2023-05-15 21:14:45 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-07-28 14:44:26 +02:00
|
|
|
public function change_proxy()
|
2023-06-08 08:39:00 +02:00
|
|
|
{
|
2023-07-14 13:38:24 +02:00
|
|
|
$this->server->proxy = null;
|
2023-06-08 08:39:00 +02:00
|
|
|
$this->server->save();
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-09-06 15:00:56 +02:00
|
|
|
public function select_proxy($proxy_type)
|
2023-05-15 13:45:37 +02:00
|
|
|
{
|
2023-09-25 09:17:42 +02:00
|
|
|
$this->server->proxy->set('status', 'exited');
|
|
|
|
$this->server->proxy->set('type', $proxy_type);
|
2023-05-15 13:45:37 +02:00
|
|
|
$this->server->save();
|
2023-09-06 15:00:56 +02:00
|
|
|
$this->selectedProxy = $this->server->proxy->type;
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->dispatch('proxyStatusUpdated');
|
2023-05-15 13:45:37 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-07-28 14:44:26 +02:00
|
|
|
public function submit()
|
2023-05-15 13:45:37 +02:00
|
|
|
{
|
|
|
|
try {
|
2023-09-21 11:03:52 +02:00
|
|
|
SaveConfiguration::run($this->server, $this->proxy_settings);
|
2023-06-22 14:18:17 +02:00
|
|
|
$this->server->proxy->redirect_url = $this->redirect_url;
|
|
|
|
$this->server->save();
|
2023-06-22 21:17:53 +02:00
|
|
|
|
2023-06-22 14:18:17 +02:00
|
|
|
setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server);
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->dispatch('success', 'Proxy configuration saved.');
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 14:47:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-05-15 13:45:37 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-07-28 14:44:26 +02:00
|
|
|
public function reset_proxy_configuration()
|
2023-05-03 06:23:45 +01:00
|
|
|
{
|
2023-05-15 13:45:37 +02:00
|
|
|
try {
|
2023-09-18 12:18:45 +02:00
|
|
|
$this->proxy_settings = CheckConfiguration::run($this->server, true);
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 14:47:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-05-15 13:45:37 +02:00
|
|
|
}
|
2023-05-03 06:23:45 +01:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-09-11 22:29:34 +02:00
|
|
|
public function loadProxyConfiguration()
|
2023-05-15 22:17:31 +02:00
|
|
|
{
|
|
|
|
try {
|
2023-09-18 12:18:45 +02:00
|
|
|
$this->proxy_settings = CheckConfiguration::run($this->server);
|
2023-09-24 11:10:50 +02:00
|
|
|
if (Str::of($this->proxy_settings)->contains('--api.dashboard=true') && Str::of($this->proxy_settings)->contains('--api.insecure=true')) {
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->dispatch('traefikDashboardAvailable', true);
|
2023-09-24 11:10:50 +02:00
|
|
|
} else {
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->dispatch('traefikDashboardAvailable', false);
|
2023-09-24 11:10:50 +02:00
|
|
|
}
|
|
|
|
|
2023-09-11 17:36:30 +02:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 14:47:25 +02:00
|
|
|
return handleError($e, $this);
|
2023-05-15 22:17:31 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
}
|