This commit is contained in:
Saeed Vaziry
2024-09-27 20:36:03 +02:00
committed by GitHub
parent b62c40c97d
commit f6bc04763b
122 changed files with 6609 additions and 807 deletions

View File

@ -3,12 +3,14 @@
namespace App\Models;
use App\Actions\Server\CheckConnection;
use App\Enums\ServerStatus;
use App\Enums\ServiceStatus;
use App\Facades\SSH;
use App\ServerTypes\ServerType;
use App\SSH\Cron\Cron;
use App\SSH\OS\OS;
use App\SSH\Systemd\Systemd;
use App\Support\Testing\SSHFake;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -56,6 +58,7 @@
* @property Backup[] $backups
* @property Queue[] $daemons
* @property SshKey[] $sshKeys
* @property Tag[] $tags
* @property string $hostname
* @property int $updates
* @property Carbon $last_update_check
@ -138,6 +141,29 @@ public static function boot(): void
});
}
public static array $statusColors = [
ServerStatus::READY => 'success',
ServerStatus::INSTALLING => 'warning',
ServerStatus::DISCONNECTED => 'gray',
ServerStatus::INSTALLATION_FAILED => 'danger',
ServerStatus::UPDATING => 'warning',
];
public function isReady(): bool
{
return $this->status === ServerStatus::READY;
}
public function isInstalling(): bool
{
return in_array($this->status, [ServerStatus::INSTALLING, ServerStatus::INSTALLATION_FAILED]);
}
public function isInstallationFailed(): bool
{
return $this->status === ServerStatus::INSTALLATION_FAILED;
}
public function project(): BelongsTo
{
return $this->belongsTo(Project::class, 'project_id');
@ -268,7 +294,7 @@ public function defaultService($type): ?Service
return $service;
}
public function ssh(?string $user = null): mixed
public function ssh(?string $user = null): \App\Helpers\SSH|SSHFake
{
return SSH::init($this, $user);
}
@ -295,7 +321,7 @@ public function provider(): \App\ServerProviders\ServerProvider
{
$providerClass = config('core.server_providers_class')[$this->provider];
return new $providerClass($this);
return new $providerClass($this->serverProvider, $this);
}
public function webserver(?string $version = null): ?Service
@ -404,4 +430,13 @@ public function checkForUpdates(): void
$this->last_update_check = now();
$this->save();
}
public function getAvailableUpdatesAttribute(?int $value): int
{
if (! $value) {
return 0;
}
return $value;
}
}