rector: arrrrr

This commit is contained in:
Andras Bacsai
2025-01-07 14:52:08 +01:00
parent c702ebff6d
commit 16c0cd10d8
349 changed files with 4204 additions and 3712 deletions

View File

@@ -4,8 +4,10 @@ namespace App\Livewire\Server;
use App\Jobs\DockerCleanupJob;
use App\Models\Server;
use Exception;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Advanced extends Component
{
@@ -46,9 +48,11 @@ class Advanced extends Component
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
$this->parameters = get_route_parameters();
$this->syncData();
} catch (\Throwable) {
} catch (Throwable) {
return redirect()->route('server.show');
}
return null;
}
public function syncData(bool $toModel = false)
@@ -83,9 +87,11 @@ class Advanced extends Component
try {
$this->syncData(true);
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function manualCleanup()
@@ -93,9 +99,11 @@ class Advanced extends Component
try {
DockerCleanupJob::dispatch($this->server, true);
$this->dispatch('success', 'Manual cleanup job started. Depending on the amount of data, this might take a while.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -103,17 +111,19 @@ class Advanced extends Component
try {
if (! validate_cron_expression($this->dockerCleanupFrequency)) {
$this->dockerCleanupFrequency = $this->server->settings->getOriginal('docker_cleanup_frequency');
throw new \Exception('Invalid Cron / Human expression for Docker Cleanup Frequency.');
throw new Exception('Invalid Cron / Human expression for Docker Cleanup Frequency.');
}
if (! validate_cron_expression($this->serverDiskUsageCheckFrequency)) {
$this->serverDiskUsageCheckFrequency = $this->server->settings->getOriginal('server_disk_usage_check_frequency');
throw new \Exception('Invalid Cron / Human expression for Disk Usage Check Frequency.');
throw new Exception('Invalid Cron / Human expression for Disk Usage Check Frequency.');
}
$this->syncData(true);
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -4,6 +4,7 @@ namespace App\Livewire\Server;
use App\Models\Server;
use Livewire\Component;
use Throwable;
class Charts extends Component
{
@@ -23,9 +24,11 @@ class Charts extends Component
{
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function pollData()
@@ -49,9 +52,11 @@ class Charts extends Component
$this->dispatch("refreshChartData-{$this->chartId}-memory", [
'seriesData' => $memoryMetrics,
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function setInterval()

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Server;
use App\Models\Server;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class CloudflareTunnels extends Component
{
@@ -21,9 +22,11 @@ class CloudflareTunnels extends Component
return redirect()->route('server.show', ['server_uuid' => $server_uuid]);
}
$this->isCloudflareTunnelsEnabled = $this->server->settings->is_cloudflare_tunnel;
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function instantSave()
@@ -33,9 +36,11 @@ class CloudflareTunnels extends Component
$this->server->settings->is_cloudflare_tunnel = $this->isCloudflareTunnelsEnabled;
$this->server->settings->save();
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function manualCloudflareConfig()

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Server;
use App\Actions\Server\ConfigureCloudflared;
use App\Models\Server;
use Livewire\Component;
use Throwable;
class ConfigureCloudflareTunnels extends Component
{
@@ -22,9 +23,11 @@ class ConfigureCloudflareTunnels extends Component
$server->settings->save();
$this->dispatch('success', 'Cloudflare Tunnels configured successfully.');
$this->dispatch('refreshServerShow');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -42,9 +45,11 @@ class ConfigureCloudflareTunnels extends Component
$server->save();
$server->settings->save();
$this->dispatch('warning', 'Cloudflare Tunnels configuration started.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -9,6 +9,7 @@ use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
use Throwable;
class Delete extends Component
{
@@ -20,32 +21,32 @@ class Delete extends Component
{
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function delete($password)
{
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
if (! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return;
}
return null;
}
try {
$this->authorize('delete', $this->server);
if ($this->server->hasDefinedResources()) {
$this->dispatch('error', 'Server has defined resources. Please delete them first.');
return;
return null;
}
$this->server->delete();
DeleteServer::dispatch($this->server);
return redirect()->route('server.index');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -7,6 +7,7 @@ use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Illuminate\Support\Collection;
use Livewire\Component;
use Throwable;
class Destinations extends Component
{
@@ -19,9 +20,11 @@ class Destinations extends Component
try {
$this->networks = collect();
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
private function createNetworkAndAttachToProxy()
@@ -38,37 +41,31 @@ class Destinations extends Component
$this->dispatch('error', 'Network already added to this server.');
return;
} else {
SwarmDocker::create([
'name' => $this->server->name.'-'.$name,
'network' => $this->name,
'server_id' => $this->server->id,
]);
}
SwarmDocker::query()->create([
'name' => $this->server->name.'-'.$name,
'network' => $this->name,
'server_id' => $this->server->id,
]);
} else {
$found = $this->server->standaloneDockers()->where('network', $name)->first();
if ($found) {
$this->dispatch('error', 'Network already added to this server.');
return;
} else {
StandaloneDocker::create([
'name' => $this->server->name.'-'.$name,
'network' => $name,
'server_id' => $this->server->id,
]);
}
StandaloneDocker::query()->create([
'name' => $this->server->name.'-'.$name,
'network' => $name,
'server_id' => $this->server->id,
]);
$this->createNetworkAndAttachToProxy();
}
}
public function scan()
{
if ($this->server->isSwarm()) {
$alreadyAddedNetworks = $this->server->swarmDockers;
} else {
$alreadyAddedNetworks = $this->server->standaloneDockers;
}
$alreadyAddedNetworks = $this->server->isSwarm() ? $this->server->swarmDockers : $this->server->standaloneDockers;
$networks = instant_remote_process(['docker network ls --format "{{json .}}"'], $this->server, false);
$this->networks = format_docker_command_output_to_json($networks)->filter(function ($network) {
return $network['Name'] !== 'bridge' && $network['Name'] !== 'host' && $network['Name'] !== 'none';

View File

@@ -7,6 +7,7 @@ use App\Actions\Server\StopLogDrain;
use App\Models\Server;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class LogDrains extends Component
{
@@ -44,9 +45,11 @@ class LogDrains extends Component
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
$this->syncData();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function syncDataNewRelic(bool $toModel = false)
@@ -104,18 +107,16 @@ class LogDrains extends Component
$this->syncDataCustom($toModel);
}
$this->server->settings->save();
} elseif ($type === 'newrelic') {
$this->syncDataNewRelic($toModel);
} elseif ($type === 'axiom') {
$this->syncDataAxiom($toModel);
} elseif ($type === 'custom') {
$this->syncDataCustom($toModel);
} else {
if ($type === 'newrelic') {
$this->syncDataNewRelic($toModel);
} elseif ($type === 'axiom') {
$this->syncDataAxiom($toModel);
} elseif ($type === 'custom') {
$this->syncDataCustom($toModel);
} else {
$this->syncDataNewRelic($toModel);
$this->syncDataAxiom($toModel);
$this->syncDataCustom($toModel);
}
$this->syncDataNewRelic($toModel);
$this->syncDataAxiom($toModel);
$this->syncDataCustom($toModel);
}
}
@@ -127,7 +128,7 @@ class LogDrains extends Component
'logDrainNewRelicLicenseKey' => ['required'],
'logDrainNewRelicBaseUri' => ['required', 'url'],
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->isLogDrainNewRelicEnabled = false;
throw $e;
@@ -138,7 +139,7 @@ class LogDrains extends Component
'logDrainAxiomDatasetName' => ['required'],
'logDrainAxiomApiKey' => ['required'],
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->isLogDrainAxiomEnabled = false;
throw $e;
@@ -149,7 +150,7 @@ class LogDrains extends Component
'logDrainCustomConfig' => ['required'],
'logDrainCustomConfigParser' => ['string', 'nullable'],
]);
} catch (\Throwable $e) {
} catch (Throwable $e) {
$this->isLogDrainCustomEnabled = false;
throw $e;
@@ -168,9 +169,11 @@ class LogDrains extends Component
StopLogDrain::run($this->server);
$this->dispatch('success', 'Log drain service stopped.');
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit(string $type)
@@ -178,9 +181,11 @@ class LogDrains extends Component
try {
$this->syncData(true, $type);
$this->dispatch('success', 'Settings saved.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -9,6 +9,7 @@ use Illuminate\Support\Collection;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class ByIp extends Component
{
@@ -52,7 +53,7 @@ class ByIp extends Component
public bool $is_swarm_worker = false;
#[Validate('nullable|integer', as: 'Swarm Cluster')]
public $selected_swarm_cluster = null;
public $selected_swarm_cluster;
#[Validate('required|boolean', as: 'Build Server')]
public bool $is_build_server = false;
@@ -84,7 +85,7 @@ class ByIp extends Component
{
$this->validate();
try {
if (Server::where('team_id', currentTeam()->id)
if (Server::query()->where('team_id', currentTeam()->id)
->where('ip', $this->ip)
->exists()) {
return $this->dispatch('error', 'This IP/Domain is already in use by another server in your team.');
@@ -111,7 +112,7 @@ class ByIp extends Component
if ($this->is_build_server) {
data_forget($payload, 'proxy');
}
$server = Server::create($payload);
$server = Server::query()->create($payload);
$server->proxy->set('status', 'exited');
$server->proxy->set('type', ProxyTypes::TRAEFIK->value);
$server->save();
@@ -126,7 +127,7 @@ class ByIp extends Component
$server->settings->save();
return redirect()->route('server.show', $server->uuid);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
}

View File

@@ -4,7 +4,9 @@ namespace App\Livewire\Server\PrivateKey;
use App\Models\PrivateKey;
use App\Models\Server;
use Exception;
use Livewire\Component;
use Throwable;
class Show extends Component
{
@@ -19,9 +21,11 @@ class Show extends Component
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
$this->privateKeys = PrivateKey::ownedByCurrentTeam()->get()->where('is_git_related', false);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function setPrivateKey($privateKeyId)
@@ -40,9 +44,9 @@ class Show extends Component
if ($uptime) {
$this->dispatch('success', 'Private key updated successfully.');
} else {
throw new \Exception($error);
throw new Exception($error);
}
} catch (\Exception $e) {
} catch (Exception $e) {
$this->server->update(['private_key_id' => $originalPrivateKeyId]);
$this->server->validateConnection();
$this->dispatch('error', $e->getMessage());
@@ -58,11 +62,13 @@ class Show extends Component
} else {
$this->dispatch('error', 'Server is not reachable.<br><br>Check this <a target="_blank" class="underline" href="https://coolify.io/docs/knowledge-base/server/openssh">documentation</a> for further help.<br><br>Error: '.$error);
return;
return null;
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -6,6 +6,7 @@ use App\Actions\Proxy\CheckConfiguration;
use App\Actions\Proxy\SaveConfiguration;
use App\Models\Server;
use Livewire\Component;
use Throwable;
class Proxy extends Component
{
@@ -13,7 +14,7 @@ class Proxy extends Component
public ?string $selectedProxy = null;
public $proxy_settings = null;
public $proxy_settings;
public bool $redirect_enabled = true;
@@ -50,9 +51,11 @@ class Proxy extends Component
$this->server->changeProxy($proxy_type, async: false);
$this->selectedProxy = $this->server->proxy->type;
$this->dispatch('reloadWindow');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function instantSave()
@@ -61,9 +64,11 @@ class Proxy extends Component
$this->validate();
$this->server->settings->save();
$this->dispatch('success', 'Settings saved.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function instantSaveRedirect()
@@ -73,9 +78,11 @@ class Proxy extends Component
$this->server->save();
$this->server->setupDefaultRedirect();
$this->dispatch('success', 'Proxy configuration saved.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -86,9 +93,11 @@ class Proxy extends Component
$this->server->save();
$this->server->setupDefaultRedirect();
$this->dispatch('success', 'Proxy configuration saved.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function reset_proxy_configuration()
@@ -98,9 +107,11 @@ class Proxy extends Component
SaveConfiguration::run($this->server, $this->proxy_settings);
$this->server->save();
$this->dispatch('success', 'Proxy configuration saved.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function loadProxyConfiguration()
@@ -112,8 +123,10 @@ class Proxy extends Component
} else {
$this->dispatch('traefikDashboardAvailable', false);
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
}

View File

@@ -10,6 +10,7 @@ use Carbon\Carbon;
use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Facades\Process;
use Livewire\Component;
use Throwable;
class Deploy extends Component
{
@@ -38,11 +39,7 @@ class Deploy extends Component
public function mount()
{
if ($this->server->id === 0) {
$this->serverIp = base_ip();
} else {
$this->serverIp = $this->server->ip;
}
$this->serverIp = $this->server->id === 0 ? base_ip() : $this->server->ip;
$this->currentRoute = request()->route()->getName();
}
@@ -67,9 +64,11 @@ class Deploy extends Component
try {
$this->stop();
$this->dispatch('checkProxy');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function checkProxy()
@@ -78,9 +77,11 @@ class Deploy extends Component
CheckProxy::run($this->server, true);
$this->dispatch('startProxyPolling');
$this->dispatch('proxyChecked');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function startProxy()
@@ -90,9 +91,11 @@ class Deploy extends Component
$this->server->save();
$activity = StartProxy::run($this->server, force: true);
$this->dispatch('activityMonitor', $activity->id, ProxyStatusChanged::class);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function stop(bool $forceStop = true)
@@ -114,7 +117,7 @@ class Deploy extends Component
}
$this->removeContainer($containerName);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
} finally {
$this->server->proxy->force_stop = $forceStop;
@@ -122,6 +125,8 @@ class Deploy extends Component
$this->server->save();
$this->dispatch('proxyStatusUpdated');
}
return null;
}
private function stopContainer(string $containerName, int $timeout): InvokedProcess

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Server\Proxy;
use App\Models\Server;
use Illuminate\Support\Collection;
use Livewire\Component;
use Throwable;
class DynamicConfigurations extends Component
{
@@ -32,7 +33,7 @@ class DynamicConfigurations extends Component
{
$proxy_path = $this->server->proxyPath();
$files = instant_remote_process(["mkdir -p $proxy_path/dynamic && ls -1 {$proxy_path}/dynamic"], $this->server);
$files = collect(explode("\n", $files))->filter(fn ($file) => ! empty($file));
$files = collect(explode("\n", $files))->reject(fn ($file): bool => $file === '' || $file === '0');
$files = $files->map(fn ($file) => trim($file));
$files = $files->sort();
$contents = collect([]);
@@ -52,9 +53,11 @@ class DynamicConfigurations extends Component
if (is_null($this->server)) {
return redirect()->route('server.index');
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -4,6 +4,7 @@ namespace App\Livewire\Server\Proxy;
use App\Models\Server;
use Livewire\Component;
use Throwable;
class Logs extends Component
{
@@ -19,9 +20,11 @@ class Logs extends Component
if (is_null($this->server)) {
return redirect()->route('server.index');
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -6,6 +6,7 @@ use App\Enums\ProxyTypes;
use App\Models\Server;
use Livewire\Component;
use Symfony\Component\Yaml\Yaml;
use Throwable;
class NewDynamicConfiguration extends Component
{
@@ -53,7 +54,7 @@ class NewDynamicConfiguration extends Component
if ($this->fileName === 'coolify.yaml') {
$this->dispatch('error', 'File name is reserved.');
return;
return null;
}
} elseif ($proxy_type === 'CADDY') {
if (! str($this->fileName)->endsWith('.caddy')) {
@@ -67,7 +68,7 @@ class NewDynamicConfiguration extends Component
if ($exists == 1) {
$this->dispatch('error', 'File already exists');
return;
return null;
}
}
if ($proxy_type === ProxyTypes::TRAEFIK->value) {
@@ -85,9 +86,11 @@ class NewDynamicConfiguration extends Component
$this->dispatch('loadDynamicConfigurations');
$this->dispatch('dynamic-configuration-added');
$this->dispatch('success', 'Dynamic configuration saved.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -4,6 +4,7 @@ namespace App\Livewire\Server\Proxy;
use App\Models\Server;
use Livewire\Component;
use Throwable;
class Show extends Component
{
@@ -23,9 +24,11 @@ class Show extends Component
$this->parameters = get_route_parameters();
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->firstOrFail();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -7,6 +7,7 @@ use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy;
use App\Models\Server;
use Livewire\Component;
use Throwable;
class Status extends Component
{
@@ -38,9 +39,11 @@ class Status extends Component
if ($this->numberOfPolls >= 10) {
$this->polling = false;
$this->numberOfPolls = 0;
$notification && $this->dispatch('error', 'Proxy is not running.');
if ($notification) {
$this->dispatch('error', 'Proxy is not running.');
}
return;
return null;
}
$this->numberOfPolls++;
}
@@ -51,17 +54,25 @@ class Status extends Component
$this->dispatch('proxyStatusUpdated');
if ($this->server->proxy->status === 'running') {
$this->polling = false;
$notification && $this->dispatch('success', 'Proxy is running.');
} elseif ($this->server->proxy->status === 'exited' and ! $this->server->proxy->force_stop) {
$notification && $this->dispatch('error', 'Proxy has exited.');
if ($notification) {
$this->dispatch('success', 'Proxy is running.');
}
} elseif ($this->server->proxy->status === 'exited' && ! $this->server->proxy->force_stop) {
if ($notification) {
$this->dispatch('error', 'Proxy has exited.');
}
} elseif ($this->server->proxy->force_stop) {
$notification && $this->dispatch('error', 'Proxy is stopped manually.');
} else {
$notification && $this->dispatch('error', 'Proxy is not running.');
if ($notification) {
$this->dispatch('error', 'Proxy is stopped manually.');
}
} elseif ($notification) {
$this->dispatch('error', 'Proxy is not running.');
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function getProxyStatus()
@@ -70,8 +81,10 @@ class Status extends Component
GetContainersStatus::run($this->server);
// dispatch_sync(new ContainerStatusJob($this->server));
$this->dispatch('proxyStatusUpdated');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
}

View File

@@ -6,6 +6,7 @@ use App\Models\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Collection;
use Livewire\Component;
use Throwable;
class Resources extends Component
{
@@ -65,9 +66,11 @@ class Resources extends Component
try {
$this->activeTab = 'managed';
$this->containers = $this->server->refresh()->definedResources();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function loadUnmanagedContainers()
@@ -75,9 +78,11 @@ class Resources extends Component
$this->activeTab = 'unmanaged';
try {
$this->containers = $this->server->loadUnmanagedContainers();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function mount()
@@ -90,9 +95,11 @@ class Resources extends Component
return redirect()->route('server.index');
}
$this->loadManagedContainers();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -6,9 +6,11 @@ use App\Actions\Server\StartSentinel;
use App\Actions\Server\StopSentinel;
use App\Events\ServerReachabilityChanged;
use App\Models\Server;
use Exception;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class Show extends Component
{
@@ -95,9 +97,11 @@ class Show extends Component
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
$this->syncData();
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
#[Computed]
@@ -114,12 +118,12 @@ class Show extends Component
if ($toModel) {
$this->validate();
if (Server::where('team_id', currentTeam()->id)
if (Server::query()->where('team_id', currentTeam()->id)
->where('ip', $this->ip)
->where('id', '!=', $this->server->id)
->exists()) {
$this->ip = $this->server->ip;
throw new \Exception('This IP/Domain is already in use by another server in your team.');
throw new Exception('This IP/Domain is already in use by another server in your team.');
}
$this->server->name = $this->name;
@@ -145,10 +149,9 @@ class Show extends Component
if (! validate_timezone($this->serverTimezone)) {
$this->serverTimezone = config('app.timezone');
throw new \Exception('Invalid timezone.');
} else {
$this->server->settings->server_timezone = $this->serverTimezone;
throw new Exception('Invalid timezone.');
}
$this->server->settings->server_timezone = $this->serverTimezone;
$this->server->settings->save();
} else {
@@ -189,9 +192,11 @@ class Show extends Component
$this->validationLogs = $this->server->validation_logs = null;
$this->server->save();
$this->dispatch('init', $install);
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function checkLocalhostConnection()
@@ -248,9 +253,11 @@ class Show extends Component
try {
$this->server->settings->generateSentinelToken();
$this->dispatch('success', 'Token regenerated & Sentinel restarted.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function instantSave()
@@ -263,9 +270,11 @@ class Show extends Component
try {
$this->syncData(true);
$this->dispatch('success', 'Server updated.');
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function render()

View File

@@ -5,7 +5,9 @@ namespace App\Livewire\Server;
use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy;
use App\Models\Server;
use Exception;
use Livewire\Component;
use Throwable;
class ValidateAndInstall extends Component
{
@@ -17,19 +19,19 @@ class ValidateAndInstall extends Component
public bool $install = true;
public $uptime = null;
public $uptime;
public $supported_os_type = null;
public $supported_os_type;
public $docker_installed = null;
public $docker_installed;
public $docker_compose_installed = null;
public $docker_compose_installed;
public $docker_version = null;
public $docker_version;
public $proxy_started = false;
public $error = null;
public $error;
public bool $ask = false;
@@ -73,14 +75,16 @@ class ValidateAndInstall extends Component
if ($proxy === 'OK') {
$this->proxy_started = true;
} else {
throw new \Exception('Proxy could not be started.');
throw new Exception('Proxy could not be started.');
}
} else {
$this->proxy_started = true;
}
} catch (\Throwable $e) {
} catch (Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function validateConnection()
@@ -117,30 +121,28 @@ class ValidateAndInstall extends Component
$this->docker_compose_installed = $this->server->validateDockerCompose();
if (! $this->docker_installed || ! $this->docker_compose_installed) {
if ($this->install) {
if ($this->number_of_tries == $this->max_tries) {
if ($this->number_of_tries === $this->max_tries) {
$this->error = 'Docker Engine could not be installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
$this->server->update([
'validation_logs' => $this->error,
]);
return;
} else {
if ($this->number_of_tries <= $this->max_tries) {
$activity = $this->server->installDocker();
$this->number_of_tries++;
$this->dispatch('newActivityMonitor', $activity->id, 'init', $this->number_of_tries);
}
return;
}
} else {
$this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
$this->server->update([
'validation_logs' => $this->error,
]);
if ($this->number_of_tries <= $this->max_tries) {
$activity = $this->server->installDocker();
$this->number_of_tries++;
$this->dispatch('newActivityMonitor', $activity->id, 'init', $this->number_of_tries);
}
return;
}
$this->error = 'Docker Engine is not installed. Please install Docker manually before continuing: <a target="_blank" class="underline" href="https://docs.docker.com/engine/install/#server">documentation</a>.';
$this->server->update([
'validation_logs' => $this->error,
]);
return;
}
$this->dispatch('validateDockerVersion');
}