fix: proxy status

This commit is contained in:
Andras Bacsai
2024-09-19 12:32:56 +02:00
parent 9518040d23
commit f65789bdbb
9 changed files with 43 additions and 46 deletions

View File

@@ -39,6 +39,7 @@ class Proxy extends Component
{ {
$this->server->proxy = null; $this->server->proxy = null;
$this->server->save(); $this->server->save();
$this->dispatch('proxyChanged');
} }
public function selectProxy($proxy_type) public function selectProxy($proxy_type)
@@ -47,7 +48,7 @@ class Proxy extends Component
$this->server->proxy->set('type', $proxy_type); $this->server->proxy->set('type', $proxy_type);
$this->server->save(); $this->server->save();
$this->selectedProxy = $this->server->proxy->type; $this->selectedProxy = $this->server->proxy->type;
if ($this->selectedProxy !== 'NONE') { if ($this->server->proxySet()) {
StartProxy::run($this->server, false); StartProxy::run($this->server, false);
} }
$this->dispatch('proxyStatusUpdated'); $this->dispatch('proxyStatusUpdated');

View File

@@ -29,6 +29,7 @@ class Deploy extends Component
'serverRefresh' => 'proxyStatusUpdated', 'serverRefresh' => 'proxyStatusUpdated',
'checkProxy', 'checkProxy',
'startProxy', 'startProxy',
'proxyChanged' => 'proxyStatusUpdated',
]; ];
} }

View File

@@ -11,7 +11,7 @@ class Show extends Component
public $parameters = []; public $parameters = [];
protected $listeners = ['proxyStatusUpdated']; protected $listeners = ['proxyStatusUpdated', 'proxyChanged' => 'proxyStatusUpdated'];
public function proxyStatusUpdated() public function proxyStatusUpdated()
{ {

View File

@@ -5,7 +5,6 @@ namespace App\Models;
use App\Actions\Server\InstallDocker; use App\Actions\Server\InstallDocker;
use App\Enums\ProxyTypes; use App\Enums\ProxyTypes;
use App\Jobs\PullSentinelImageJob; use App\Jobs\PullSentinelImageJob;
use App\Notifications\Server\Revived;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@@ -156,11 +155,17 @@ class Server extends BaseModel
return $this->hasOne(ServerSetting::class); return $this->hasOne(ServerSetting::class);
} }
public function proxySet()
{
return $this->proxyType() && $this->proxyType() !== 'NONE' && $this->isFunctional() && ! $this->isSwarmWorker() && ! $this->settings->is_build_server;
}
public function setupDefault404Redirect() public function setupDefault404Redirect()
{ {
$dynamic_conf_path = $this->proxyPath().'/dynamic'; $dynamic_conf_path = $this->proxyPath().'/dynamic';
$proxy_type = $this->proxyType(); $proxy_type = $this->proxyType();
$redirect_url = $this->proxy->redirect_url; $redirect_url = $this->proxy->redirect_url;
ray($proxy_type);
if ($proxy_type === ProxyTypes::TRAEFIK->value) { if ($proxy_type === ProxyTypes::TRAEFIK->value) {
$default_redirect_file = "$dynamic_conf_path/default_redirect_404.yaml"; $default_redirect_file = "$dynamic_conf_path/default_redirect_404.yaml";
} elseif ($proxy_type === 'CADDY') { } elseif ($proxy_type === 'CADDY') {
@@ -950,9 +955,9 @@ $schema://$host {
public function isFunctional() public function isFunctional()
{ {
$isFunctional = $this->settings->is_reachable && $this->settings->is_usable && !$this->settings->force_disabled; $isFunctional = $this->settings->is_reachable && $this->settings->is_usable && ! $this->settings->force_disabled;
if (!$isFunctional) { if (! $isFunctional) {
Storage::disk('ssh-mux')->delete($this->muxFilename()); Storage::disk('ssh-mux')->delete($this->muxFilename());
} }
@@ -1007,7 +1012,7 @@ $schema://$host {
public function validateConnection($isManualCheck = true) public function validateConnection($isManualCheck = true)
{ {
config()->set('constants.ssh.mux_enabled', !$isManualCheck); config()->set('constants.ssh.mux_enabled', ! $isManualCheck);
// ray('Manual Check: ' . ($isManualCheck ? 'true' : 'false')); // ray('Manual Check: ' . ($isManualCheck ? 'true' : 'false'));
$server = Server::find($this->id); $server = Server::find($this->id);
@@ -1160,16 +1165,18 @@ $schema://$host {
$server = new self($data); $server = new self($data);
$server->privateKey()->associate($privateKey); $server->privateKey()->associate($privateKey);
$server->save(); $server->save();
return $server; return $server;
} }
public function updateWithPrivateKey(array $data, PrivateKey $privateKey = null) public function updateWithPrivateKey(array $data, ?PrivateKey $privateKey = null)
{ {
$this->update($data); $this->update($data);
if ($privateKey) { if ($privateKey) {
$this->privateKey()->associate($privateKey); $this->privateKey()->associate($privateKey);
$this->save(); $this->save();
} }
return $this; return $this;
} }
} }

View File

@@ -2,7 +2,9 @@
<livewire:server.proxy.modal :server="$server" /> <livewire:server.proxy.modal :server="$server" />
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<h1>Server</h1> <h1>Server</h1>
<livewire:server.proxy.status :server="$server" /> @if ($server->proxySet())
<livewire:server.proxy.status :server="$server" />
@endif
</div> </div>
<div class="subtitle">{{ data_get($server, 'name') }}.</div> <div class="subtitle">{{ data_get($server, 'name') }}.</div>
<div class="navbar-main"> <div class="navbar-main">

View File

@@ -1,20 +1,18 @@
<div class="flex h-full pr-4"> @if ($server->proxySet())
<div class="flex flex-col w-48 gap-4 min-w-fit"> <div class="flex h-full pr-4">
<a class="{{ request()->routeIs('server.proxy') ? 'dark:text-white' : '' }}" <div class="flex flex-col w-48 gap-4 min-w-fit">
href="{{ route('server.proxy', $parameters) }}"> <a class="{{ request()->routeIs('server.proxy') ? 'dark:text-white' : '' }}"
<button>Configuration</button> href="{{ route('server.proxy', $parameters) }}">
</a> <button>Configuration</button>
@if ($server->proxyType() !== 'NONE') </a>
{{-- @if ($server->proxyType() === 'TRAEFIK') --}}
<a class="{{ request()->routeIs('server.proxy.dynamic-confs') ? 'dark:text-white' : '' }}" <a class="{{ request()->routeIs('server.proxy.dynamic-confs') ? 'dark:text-white' : '' }}"
href="{{ route('server.proxy.dynamic-confs', $parameters) }}"> href="{{ route('server.proxy.dynamic-confs', $parameters) }}">
<button>Dynamic Configurations</button> <button>Dynamic Configurations</button>
</a> </a>
{{-- @endif --}}
<a class="{{ request()->routeIs('server.proxy.logs') ? 'dark:text-white' : '' }}" <a class="{{ request()->routeIs('server.proxy.logs') ? 'dark:text-white' : '' }}"
href="{{ route('server.proxy.logs', $parameters) }}"> href="{{ route('server.proxy.logs', $parameters) }}">
<button>Logs</button> <button>Logs</button>
</a> </a>
@endif </div>
</div> </div>
</div> @endif

View File

@@ -83,9 +83,9 @@
<x-forms.button class="box" wire:click="selectProxy('CADDY')"> <x-forms.button class="box" wire:click="selectProxy('CADDY')">
Caddy Caddy
</x-forms.button> </x-forms.button>
<x-forms.button disabled class="box"> {{-- <x-forms.button disabled class="box">
Nginx Nginx
</x-forms.button> </x-forms.button> --}}
</div> </div>
</div> </div>
@endif @endif

View File

@@ -1,10 +1,6 @@
@php use App\Enums\ProxyTypes; @endphp @php use App\Enums\ProxyTypes; @endphp
<div> <div>
@if ( @if ($server->proxySet())
$server->proxyType() !== 'NONE' &&
$server->isFunctional() &&
!$server->isSwarmWorker() &&
!$server->settings->is_build_server)
<x-slide-over closeWithX fullScreen @startproxy.window="slideOverOpen = true"> <x-slide-over closeWithX fullScreen @startproxy.window="slideOverOpen = true">
<x-slot:title>Proxy Status</x-slot:title> <x-slot:title>Proxy Status</x-slot:title>
<x-slot:content> <x-slot:content>

View File

@@ -1,20 +1,12 @@
<div x-init="$wire.checkProxy()"> <div x-init="$wire.checkProxy()" class="flex gap-2">
@if ( @if (data_get($server, 'proxy.status') === 'running')
$server->proxyType() !== 'NONE' && <x-status.running status="Proxy Running" />
$server->isFunctional() && @elseif (data_get($server, 'proxy.status') === 'restarting')
!$server->isSwarmWorker() && <x-status.restarting status="Proxy Restarting" />
!$server->settings->is_build_server) @else
<div class="flex gap-2"> <x-status.stopped status="Proxy Stopped" />
@if (data_get($server, 'proxy.status') === 'running') @endif
<x-status.running status="Proxy Running" /> @if (data_get($server, 'proxy.status') === 'running')
@elseif (data_get($server, 'proxy.status') === 'restarting') <x-forms.button wire:click='checkProxy(true)'>Refresh</x-forms.button>
<x-status.restarting status="Proxy Restarting" />
@else
<x-status.stopped status="Proxy Stopped" />
@endif
@if (data_get($server, 'proxy.status') === 'running')
<x-forms.button wire:click='checkProxy(true)'>Refresh</x-forms.button>
@endif
</div>
@endif @endif
</div> </div>