ui updates on server

This commit is contained in:
Andras Bacsai
2024-10-17 14:56:36 +02:00
parent 4c95647b96
commit 2315bdb93f
29 changed files with 614 additions and 373 deletions

View File

@@ -7,6 +7,7 @@ use App\Enums\ProxyTypes;
use App\Jobs\PullSentinelImageJob;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
@@ -17,7 +18,6 @@ use OpenApi\Attributes as OA;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
use Spatie\SchemalessAttributes\SchemalessAttributesTrait;
use Spatie\Url\Url;
use Illuminate\Support\Str;
use Symfony\Component\Yaml\Yaml;
#[OA\Schema(
@@ -45,7 +45,7 @@ use Symfony\Component\Yaml\Yaml;
class Server extends BaseModel
{
use SchemalessAttributesTrait;
use SchemalessAttributesTrait,SoftDeletes;
public static $batch_counter = 0;
@@ -97,7 +97,8 @@ class Server extends BaseModel
}
}
});
static::deleting(function ($server) {
static::forceDeleting(function ($server) {
$server->destinations()->each(function ($destination) {
$destination->delete();
});
@@ -527,34 +528,6 @@ $schema://$host {
Storage::disk('ssh-mux')->delete($this->muxFilename());
}
public function generateSentinelUrl() {
if ($this->isLocalhost()) {
return 'http://host.docker.internal:8000';
}
$settings = InstanceSettings::get();
if ($settings->fqdn) {
return $settings->fqdn;
}
if ($settings->ipv4) {
return $settings->ipv4 . ':8000';
}
if ($settings->ipv6) {
return $settings->ipv6 . ':8000';
}
return null;
}
public function generateSentinelToken()
{
$data = [
'server_uuid' => $this->uuid,
];
$token = json_encode($data);
$encrypted = encrypt($token);
$this->settings->sentinel_token = $encrypted;
$this->settings->save();
return $encrypted;
}
public function sentinelHeartbeat(bool $isReset = false)
{
@@ -568,7 +541,7 @@ $schema://$host {
public function isSentinelEnabled()
{
return $this->isMetricsEnabled() || $this->isServerApiEnabled() || !$this->isBuildServer();
return ($this->isMetricsEnabled() || $this->isServerApiEnabled()) && !$this->isBuildServer();
}
public function isMetricsEnabled()

View File

@@ -59,10 +59,59 @@ class ServerSetting extends Model
protected static function booted()
{
static::creating(function ($setting) {
$setting->is_sentinel_enabled = true;
try {
if (str($setting->sentinel_token)->isEmpty()) {
$setting->generateSentinelToken(save: false);
}
if (str($setting->sentinel_custom_url)->isEmpty()) {
$url = $setting->generateSentinelUrl(save: false);
if (str($url)->isEmpty()) {
$setting->is_sentinel_enabled = false;
} else {
$setting->is_sentinel_enabled = true;
}
}
} catch (\Throwable $e) {
loggy('Error creating server setting: ' . $e->getMessage());
}
});
}
public function generateSentinelToken(bool $save = true)
{
$data = [
'server_uuid' => $this->server->uuid,
];
$token = json_encode($data);
$encrypted = encrypt($token);
$this->sentinel_token = $encrypted;
if ($save) {
$this->save();
}
return $encrypted;
}
public function generateSentinelUrl(bool $save = true)
{
$domain = null;
$settings = InstanceSettings::get();
if ($this->server->isLocalhost()) {
$domain = 'http://host.docker.internal:8000';
} else if ($settings->fqdn) {
$domain = $settings->fqdn;
} else if ($settings->ipv4) {
$domain = $settings->ipv4 . ':8000';
} else if ($settings->ipv6) {
$domain = $settings->ipv6 . ':8000';
}
$this->sentinel_custom_url = $domain;
if ($save) {
$this->save();
}
return $domain;
}
public function server()
{
return $this->belongsTo(Server::class);