2025-06-06 12:47:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire\Server;
|
|
|
|
|
|
|
|
|
|
use App\Actions\Proxy\CheckProxy;
|
|
|
|
|
use App\Actions\Proxy\StartProxy;
|
|
|
|
|
use App\Actions\Proxy\StopProxy;
|
2025-11-17 13:53:28 +00:00
|
|
|
use App\Enums\ProxyTypes;
|
2025-06-06 12:47:54 +00:00
|
|
|
use App\Models\Server;
|
2025-06-06 17:18:32 +00:00
|
|
|
use App\Services\ProxyDashboardCacheService;
|
2025-08-22 12:04:25 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2025-06-06 12:47:54 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
|
|
class Navbar extends Component
|
|
|
|
|
{
|
2025-08-22 12:04:25 +00:00
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
2025-06-06 12:47:54 +00:00
|
|
|
public Server $server;
|
|
|
|
|
|
|
|
|
|
public bool $isChecking = false;
|
|
|
|
|
|
|
|
|
|
public ?string $currentRoute = null;
|
|
|
|
|
|
2025-06-06 16:50:32 +00:00
|
|
|
public bool $traefikDashboardAvailable = false;
|
|
|
|
|
|
|
|
|
|
public ?string $serverIp = null;
|
|
|
|
|
|
2025-06-11 10:02:39 +00:00
|
|
|
public ?string $proxyStatus = 'unknown';
|
|
|
|
|
|
2025-06-06 12:47:54 +00:00
|
|
|
public function getListeners()
|
|
|
|
|
{
|
|
|
|
|
$teamId = auth()->user()->currentTeam()->id;
|
|
|
|
|
|
|
|
|
|
return [
|
2025-09-16 08:33:32 +00:00
|
|
|
'refreshServerShow' => 'refreshServer',
|
2025-06-06 12:47:54 +00:00
|
|
|
"echo-private:team.{$teamId},ProxyStatusChangedUI" => 'showNotification',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function mount(Server $server)
|
|
|
|
|
{
|
|
|
|
|
$this->server = $server;
|
|
|
|
|
$this->currentRoute = request()->route()->getName();
|
2025-06-06 16:50:32 +00:00
|
|
|
$this->serverIp = $this->server->id === 0 ? base_ip() : $this->server->ip;
|
2025-06-11 10:02:39 +00:00
|
|
|
$this->proxyStatus = $this->server->proxy->status ?? 'unknown';
|
2025-06-06 17:18:32 +00:00
|
|
|
$this->loadProxyConfiguration();
|
2025-06-06 16:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function loadProxyConfiguration()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-06-11 10:02:39 +00:00
|
|
|
if ($this->proxyStatus === 'running') {
|
|
|
|
|
$this->traefikDashboardAvailable = ProxyDashboardCacheService::isTraefikDashboardAvailableFromCache($this->server);
|
|
|
|
|
}
|
2025-06-06 16:50:32 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
2025-06-06 12:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function restart()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-08-22 12:04:25 +00:00
|
|
|
$this->authorize('manageProxy', $this->server);
|
2025-11-13 12:38:57 +00:00
|
|
|
StopProxy::run($this->server, restarting: true);
|
|
|
|
|
|
|
|
|
|
$this->server->proxy->force_stop = false;
|
|
|
|
|
$this->server->save();
|
|
|
|
|
|
|
|
|
|
$activity = StartProxy::run($this->server, force: true, restarting: true);
|
|
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
2025-06-06 12:47:54 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function checkProxy()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-08-22 12:04:25 +00:00
|
|
|
$this->authorize('manageProxy', $this->server);
|
2025-06-06 12:47:54 +00:00
|
|
|
CheckProxy::run($this->server, true);
|
|
|
|
|
$this->dispatch('startProxy')->self();
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function startProxy()
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-08-22 12:04:25 +00:00
|
|
|
$this->authorize('manageProxy', $this->server);
|
2025-06-06 12:47:54 +00:00
|
|
|
$activity = StartProxy::run($this->server, force: true);
|
|
|
|
|
$this->dispatch('activityMonitor', $activity->id);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function stop(bool $forceStop = true)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2025-08-22 12:04:25 +00:00
|
|
|
$this->authorize('manageProxy', $this->server);
|
2025-06-06 12:47:54 +00:00
|
|
|
StopProxy::dispatch($this->server, $forceStop);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function checkProxyStatus()
|
|
|
|
|
{
|
|
|
|
|
if ($this->isChecking) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$this->isChecking = true;
|
|
|
|
|
CheckProxy::run($this->server, true);
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
} finally {
|
|
|
|
|
$this->isChecking = false;
|
2025-06-11 10:02:39 +00:00
|
|
|
$this->showNotification();
|
2025-06-06 12:47:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function showNotification()
|
|
|
|
|
{
|
2025-11-13 12:38:57 +00:00
|
|
|
$previousStatus = $this->proxyStatus;
|
2025-10-10 07:35:49 +00:00
|
|
|
$this->server->refresh();
|
2025-06-11 10:02:39 +00:00
|
|
|
$this->proxyStatus = $this->server->proxy->status ?? 'unknown';
|
2025-06-06 12:47:54 +00:00
|
|
|
|
2025-06-11 10:02:39 +00:00
|
|
|
switch ($this->proxyStatus) {
|
2025-06-06 12:47:54 +00:00
|
|
|
case 'running':
|
2025-06-11 10:02:39 +00:00
|
|
|
$this->loadProxyConfiguration();
|
2025-11-13 12:38:57 +00:00
|
|
|
// Only show "Proxy is running" notification when transitioning from a stopped/error state
|
|
|
|
|
// Don't show during normal start/restart flows (starting, restarting, stopping)
|
|
|
|
|
if (in_array($previousStatus, ['exited', 'stopped', 'unknown', null])) {
|
|
|
|
|
$this->dispatch('success', 'Proxy is running.');
|
|
|
|
|
}
|
2025-06-06 12:47:54 +00:00
|
|
|
break;
|
|
|
|
|
case 'restarting':
|
|
|
|
|
$this->dispatch('info', 'Initiating proxy restart.');
|
|
|
|
|
break;
|
2025-10-10 07:37:05 +00:00
|
|
|
case 'exited':
|
2025-11-13 12:38:57 +00:00
|
|
|
// Only show "Proxy has exited" notification when transitioning from running state
|
|
|
|
|
// Don't show during normal stop/restart flows (stopping, restarting)
|
|
|
|
|
if (in_array($previousStatus, ['running'])) {
|
|
|
|
|
$this->dispatch('info', 'Proxy has exited.');
|
|
|
|
|
}
|
2025-10-10 07:37:05 +00:00
|
|
|
break;
|
|
|
|
|
case 'stopping':
|
|
|
|
|
$this->dispatch('info', 'Proxy is stopping.');
|
|
|
|
|
break;
|
|
|
|
|
case 'starting':
|
|
|
|
|
$this->dispatch('info', 'Proxy is starting.');
|
|
|
|
|
break;
|
|
|
|
|
case 'unknown':
|
|
|
|
|
$this->dispatch('info', 'Proxy status is unknown.');
|
|
|
|
|
break;
|
2025-06-06 12:47:54 +00:00
|
|
|
default:
|
2025-10-10 07:37:05 +00:00
|
|
|
$this->dispatch('info', 'Proxy status updated.');
|
2025-06-06 12:47:54 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2025-06-11 10:02:39 +00:00
|
|
|
|
2025-06-06 12:47:54 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-16 08:33:32 +00:00
|
|
|
public function refreshServer()
|
|
|
|
|
{
|
|
|
|
|
$this->server->refresh();
|
|
|
|
|
$this->server->load('settings');
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-17 13:53:28 +00:00
|
|
|
/**
|
|
|
|
|
* Check if Traefik has any outdated version info (patch or minor upgrade).
|
|
|
|
|
* This shows a warning indicator in the navbar.
|
|
|
|
|
*/
|
|
|
|
|
public function getHasTraefikOutdatedProperty(): bool
|
|
|
|
|
{
|
|
|
|
|
if ($this->server->proxyType() !== ProxyTypes::TRAEFIK->value) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if server has outdated info stored
|
|
|
|
|
$outdatedInfo = $this->server->traefik_outdated_info;
|
|
|
|
|
|
|
|
|
|
return ! empty($outdatedInfo) && isset($outdatedInfo['type']);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-06 12:47:54 +00:00
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.server.navbar');
|
|
|
|
|
}
|
|
|
|
|
}
|