2023-06-02 13:15:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Server\Proxy;
|
|
|
|
|
2023-10-13 12:25:30 +00:00
|
|
|
use App\Actions\Proxy\CheckProxy;
|
2023-07-14 11:38:24 +00:00
|
|
|
use App\Actions\Proxy\StartProxy;
|
2023-06-02 13:15:12 +00:00
|
|
|
use App\Models\Server;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Deploy extends Component
|
|
|
|
{
|
|
|
|
public Server $server;
|
2023-09-24 09:10:50 +00:00
|
|
|
public bool $traefikDashboardAvailable = false;
|
|
|
|
public ?string $currentRoute = null;
|
2023-10-13 12:35:02 +00:00
|
|
|
public ?string $serverIp = null;
|
|
|
|
|
2023-10-13 12:25:30 +00:00
|
|
|
protected $listeners = ['proxyStatusUpdated', 'traefikDashboardAvailable', 'serverRefresh' => 'proxyStatusUpdated', "checkProxy", "startProxy"];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-10-13 12:25:30 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-10-13 12:35:02 +00:00
|
|
|
if ($this->server->id === 0) {
|
|
|
|
$this->serverIp = base_ip();
|
|
|
|
} else {
|
|
|
|
$this->serverIp = $this->server->ip;
|
|
|
|
}
|
2023-09-24 09:10:50 +00:00
|
|
|
$this->currentRoute = request()->route()->getName();
|
|
|
|
}
|
2023-10-13 12:25:30 +00:00
|
|
|
public function traefikDashboardAvailable(bool $data)
|
|
|
|
{
|
2023-09-24 09:10:50 +00:00
|
|
|
$this->traefikDashboardAvailable = $data;
|
|
|
|
}
|
2023-09-18 10:18:45 +00:00
|
|
|
public function proxyStatusUpdated()
|
|
|
|
{
|
2023-09-11 20:29:34 +00:00
|
|
|
$this->server->refresh();
|
|
|
|
}
|
2023-10-13 12:35:02 +00:00
|
|
|
public function ip()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
public function checkProxy()
|
|
|
|
{
|
2023-10-13 12:25:30 +00:00
|
|
|
try {
|
2023-10-17 17:00:23 +00:00
|
|
|
CheckProxy::run($this->server, true);
|
2023-10-13 12:25:30 +00:00
|
|
|
$this->emit('startProxyPolling');
|
|
|
|
$this->emit('proxyChecked');
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
2023-09-11 20:29:34 +00:00
|
|
|
public function startProxy()
|
2023-06-02 13:15:12 +00:00
|
|
|
{
|
2023-09-18 10:18:45 +00:00
|
|
|
try {
|
2023-09-18 10:29:50 +00:00
|
|
|
$activity = StartProxy::run($this->server);
|
2023-09-18 10:18:45 +00:00
|
|
|
$this->emit('newMonitorActivity', $activity->id);
|
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 12:47:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-09-18 10:18:45 +00:00
|
|
|
}
|
2023-06-02 13:15:12 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-06-02 13:15:12 +00:00
|
|
|
public function stop()
|
|
|
|
{
|
|
|
|
instant_remote_process([
|
|
|
|
"docker rm -f coolify-proxy",
|
|
|
|
], $this->server);
|
2023-06-20 18:19:31 +00:00
|
|
|
$this->server->proxy->status = 'exited';
|
2023-06-02 13:15:12 +00:00
|
|
|
$this->server->save();
|
|
|
|
$this->emit('proxyStatusUpdated');
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
}
|