2023-05-03 06:23:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Server;
|
|
|
|
|
2023-07-28 16:42:28 +02:00
|
|
|
use App\Actions\Proxy\CheckConfigurationSync;
|
|
|
|
use App\Actions\Proxy\SaveConfigurationSync;
|
2023-05-15 13:45:37 +02:00
|
|
|
use App\Enums\ProxyTypes;
|
2023-05-03 06:23:45 +01:00
|
|
|
use App\Models\Server;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Proxy extends Component
|
|
|
|
{
|
|
|
|
public Server $server;
|
|
|
|
|
2023-05-15 13:45:37 +02:00
|
|
|
public ProxyTypes $selectedProxy = ProxyTypes::TRAEFIK_V2;
|
|
|
|
public $proxy_settings = null;
|
2023-06-22 14:18:17 +02:00
|
|
|
public string|null $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()
|
|
|
|
{
|
|
|
|
$this->redirect_url = $this->server->proxy->redirect_url;
|
|
|
|
}
|
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-07-14 13:38:24 +02:00
|
|
|
$this->emit('proxyStatusUpdated');
|
2023-06-08 08:39:00 +02:00
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-07-28 14:44:26 +02:00
|
|
|
public function select_proxy(string $proxy_type)
|
2023-05-15 13:45:37 +02:00
|
|
|
{
|
2023-06-20 20:19:31 +02:00
|
|
|
$this->server->proxy->type = $proxy_type;
|
|
|
|
$this->server->proxy->status = 'exited';
|
2023-05-15 13:45:37 +02:00
|
|
|
$this->server->save();
|
2023-07-14 13:38:24 +02:00
|
|
|
$this->emit('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-07-28 16:42:28 +02:00
|
|
|
resolve(SaveConfigurationSync::class)($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-06-22 10:04:39 +02:00
|
|
|
$this->emit('success', 'Proxy configuration saved.');
|
2023-05-15 13:45:37 +02:00
|
|
|
} catch (\Exception $e) {
|
2023-06-09 15:55:21 +02:00
|
|
|
return general_error_handler(err: $e);
|
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-07-28 16:42:28 +02:00
|
|
|
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server, true);
|
2023-05-15 13:45:37 +02:00
|
|
|
} catch (\Exception $e) {
|
2023-06-09 15:55:21 +02:00
|
|
|
return general_error_handler(err: $e);
|
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-07-28 14:44:26 +02:00
|
|
|
public function load_proxy_configuration()
|
2023-05-15 22:17:31 +02:00
|
|
|
{
|
|
|
|
try {
|
2023-07-28 16:42:28 +02:00
|
|
|
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server);
|
2023-05-15 22:17:31 +02:00
|
|
|
} catch (\Exception $e) {
|
2023-06-09 15:55:21 +02:00
|
|
|
return general_error_handler(err: $e);
|
2023-05-15 22:17:31 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
}
|