2023-05-03 05:23:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Server;
|
|
|
|
|
2023-07-28 14:42:28 +00:00
|
|
|
use App\Actions\Proxy\CheckConfigurationSync;
|
|
|
|
use App\Actions\Proxy\SaveConfigurationSync;
|
2023-05-15 11:45:37 +00:00
|
|
|
use App\Enums\ProxyTypes;
|
2023-05-03 05:23:45 +00:00
|
|
|
use App\Models\Server;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Proxy extends Component
|
|
|
|
{
|
|
|
|
public Server $server;
|
|
|
|
|
2023-09-06 13:00:56 +00:00
|
|
|
public ?string $selectedProxy = null;
|
2023-05-15 11:45:37 +00:00
|
|
|
public $proxy_settings = null;
|
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()
|
|
|
|
{
|
2023-09-11 20:29:34 +00:00
|
|
|
$this->selectedProxy = data_get($this->server, 'proxy.type');
|
|
|
|
$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
|
|
|
{
|
2023-06-02 13:15:12 +00:00
|
|
|
$this->server->refresh();
|
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-07-14 11:38:24 +00:00
|
|
|
$this->emit('proxyStatusUpdated');
|
2023-06-08 06:39:00 +00:00
|
|
|
}
|
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-06-20 18:19:31 +00:00
|
|
|
$this->server->proxy->type = $proxy_type;
|
|
|
|
$this->server->proxy->status = 'exited';
|
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;
|
2023-07-14 11:38:24 +00:00
|
|
|
$this->emit('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-14 15:10:37 +00:00
|
|
|
resolve(SaveConfigurationSync::class)($this->server);
|
2023-07-28 14:42:28 +00:00
|
|
|
|
2023-06-22 12:18:17 +00:00
|
|
|
$this->server->proxy->redirect_url = $this->redirect_url;
|
|
|
|
$this->server->save();
|
2023-06-22 19:17:53 +00:00
|
|
|
|
2023-06-22 12:18:17 +00:00
|
|
|
setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server);
|
2023-06-22 08:04:39 +00:00
|
|
|
$this->emit('success', 'Proxy configuration saved.');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e);
|
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-07-28 14:42:28 +00:00
|
|
|
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server, true);
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e);
|
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-11 20:29:34 +00:00
|
|
|
ray('loadProxyConfiguration');
|
2023-07-28 14:42:28 +00:00
|
|
|
$this->proxy_settings = resolve(CheckConfigurationSync::class)($this->server);
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e);
|
2023-05-15 20:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|